so everything is more or less how it's
supposed to look like so this is good that means i can already
start rendering this into an image which is at
the end of the day that's the goal right this is already rendered
but now i'm going to add some code to save this into an image so basically i'm
going to render an image and i'm going to save it into a png so
to do that i'm going to do syn dot render dot image settings
and then file format and then png and then i will specify a file path with
syn dot render dot file path and then you can
specify for example a tmp directory and then blender dot png for
example whatever right so and then there is bpy
dot ops dot render dot render and then
write still equal to one so this is all things i've copied from the
documentation so that's why i'm just typing it you need to make sure that you
have write still equal to one otherwise it will not save the file
okay so i'm going to run this oops we failed
so this is the time where i go into the scripting console
see what happened the scene is not defined so it seems like i didn't
initialize my variable to scene so it's quite
simple actually so scene is equal to bpy
dot context dot scene so i'm just going to delete everything
so it starts from the beginning okay so i'm going to run the script
again and this time did i get any error i think we
got another error so the error is we don't have the camera
i thought i created the camera i did create camera
so what i miss from my script the scene itself
needs a camera it needs to be told what camera to use yeah the scene is equal to
bpy dot context dot scene and then scene dot camera so if i put
cinder camera equal to the camera that i created earlier which
i haven't defined here so scene dot camera equal to can
okay so now seems like i'm getting another one
it's just a case of not having the variable define the right place
so i should now be able to run this script again
yeah no errors so there should be an image i'm going to open the image and
see if actually i don't think i define i'm on a
windows pc and i i use the tmb i don't think this file
path even exists okay so now it's it worked and let's see
if we have a file so you can see something very strange i
think the camera is not exactly in the right place is it
it's facing down but it should be an angle right so the
camera itself is actually doing more as the right
thing but you know we just we are facing straight down and of
course that's the only thing we see is that one of the faces of the
cube so i need to move this camera a little
bit rotated so we can see at an angle so
let's do that so i can actually do it here first let's
get the camera okay outside the camera and
then so active object becomes the camera cam
equal to active object and then com dot rotation ever so this takes
basically angles in as a radian so the first parameters is the angles
and i don't think you have to worry about other
options so let's see angles equal to zero so it seems
to rotate the camera i have to do rotation here
and then i'll specify the angles so in radians right so i'm just going to
put some files into it but then what you would
probably want to do here is to have a an angle in
degrees and then translate it to radians okay so now
camera should be rotated let's just try with this
value and see if it works delete start again
okay now let's take a look at our picture okay you can see it's an angle
now almost facing away the cube maybe there's a better solution
for this which is instead of me making up what i want
i'm just going to rotate it to the right place and then
just take that value so i can easily change this camera to point to the cube
and it will be okay i'll be able to see the
cube at an angle if i rotate it manually like
this yeah i can do that but when i rotate the camera around this
cube it's not going to be always so straight forward to rotate in a way that
it will always be looking at the cube with the
best view possible so to do that what i can actually do i
can add a tracking constraint to the actual camera itself so i can
click here object constraint track 2 then i can
specify here the cube yeah that's it so whenever even if i
change the cube uh the direction you'll see that the camera itself will point
at the queue okay so we know how to do it in ui now we have to repeat this and
do that in a script so we figure out how to add
the constraint to the camera so it looks at
the object uh at all times but we've only figured out how to do that
by the ui to do it through the python script then we need to do it in a
different way there's a constraints property
inside the camera and we're going to create a new constraint
so cam dot constraints dot new then i specify the type and then
track two and that's it i think i don't have the cam anymore so i need to
first initialize the camera so bpy dot operations let's make the camera
active object so active object epy.ops.context
bpy.context.activeobject that's my camera so camera dot
constraints dot new and then i have to specify the type and
the type should be track two and then it's actually quite simple to
do this so i forgot to initialize the constraint so
constraint equal to and then constraint dot target
for example equal to q i i don't have the cube anymore but
if i get the cube again let's see cube upy.context.activeobject
and then you can see that i can specify the target as the cube and that's it
done this way i should have constrained i've
added it twice because i did it once manually
so i can just remove all the constraints and then we can write it by the script
so it works so i'm just going to do copy and paste
the code block 2 then you have constraint target
equal to cube okay so this is it basically
i can just try again and hopefully i have everything i need
so now my camera should always be tracking the object as you can see here
yeah so let's just see how what kind of picture you produce this time
and you can see it's much better right so the next thing would be to try and
rotate the camera around the object at different angles and see how we can
basically take different pictures of the cube
instead of just doing one single picture here we would play with
the camera and then do a render every time
so four and go in range of to 360 then we can do something
like say [ __ ] go yeah it should work
something like this but of course i need to
move the camera it's not just cross an angle
so let's see how to do that okay so to rotate
an object around an axis we can use the rotation error property so for example
in this case i have cam dot rotation healer
and i can choose one of the axis to do it i'm going to do around the z-axis
yeah which is the vertical axis so i'm going to do 0 1 2 yeah and i'm
going to use a math function so i'm going to import
math just to convert a degree to radian it's
quite convenient method you can also do it by
by multiplying by pi number which is 3.14 approximate
and also divided by 180 you can do the same thing but
it's much easier to just do math dot radians and then you give it the angle
that you want to do in this case it's angle and then
this is going to do a rotation around the z axis for the camera so
every time we take a picture we rotate right now it by default it's the
step size is one so i don't want to do as
many as that so i'm going to do step equal to 10.
yeah let's run it okay there's no arguments so it
means that should be just typed just do it everything here
so instead of having one picture now i'm expecting to see
a few pictures at 2 36 so it takes a while as you can see
because it's taking like 36 pictures every single picture
should hopefully be of the cube within visibility as you can see it created
quite a few let's see if there's any difference
looks the same to me so i don't think it's working
it turns out that rotating the camera is not as straightforward as i thought
it seems like there is some functionality that was removed
that used to uh be part of the bpy.ops.transform.rotate
so because i what i need to do is to rotate the camera around
an axis which has the origin in the cube and the idea is that the camera goes
around the cube but because that functionality
has been removed i i need to come up with a function to do the rotation
myself i actually found a function in stack
overflow so i'm going to just use that i have here a method called rotation
matrix this is a it's derived from the euler
rodriguez formula which i've taken this from stack
overflow as is there is a mathematical formula if
you're curious you can go on wikipedia and you can
write this code by yourself if you want to and then i
i define this method auxiliary method which takes in this case i just need a
point so it takes one point it takes an angle
in degrees and then it takes an axis defaults this
one to the y axis and then it basically will rotate
that point around the axis that you gave it
simple as that so with this in mind all i have to do
here is i have this for loop and i need to do
cam.location i'm going to get the current location of the camera
and i'm going to update the location of the camera so i'm going to do
rotate so time location then i'm going to give it like an angle
in this case my step function is 10 and then and i'm going to give it an
axis which is going to be the z axis so zero zero one because i
wanted to rotate the camera around the s axis
which intersects the cube and then i get a new location new cam location
all i have to do is basically update the location of the camera with a new
location simple as that if i could even put this
to this if i wanted to so no point to create another variable basically this
will rotate the camera around the cube then i just
have to press play so let's see so it's running so now i
should have all the cubes i want so the first one then
the second one you see it's rotating it does not have shadows though anyway i
think i've got to a really good point i've been able to
take pictures of a 3d object and rotate the camera around it there's
still more work to do here i think i'll do this for a later
episode and i'm going to figure out why the shadow is not showing
up you know improve other things there's more things we can do in blender i could
even do some physics animation here but you know yeah there's a lot more to do
and i think that's all for now i thank you so much
i hope you enjoyed this video and you've found it useful
yeah don't forget to smash the like button and i'll see you again soon happy
coding