so
i'm learning blender and the python
library that blender offers
i want to create a small object called
lithophane i'm going to create a 3d
model of a photo
and i'll be using the blender python api
and any other python wires
i might need along the way the first
thing i want to do
to make sure i know what i'm actually
doing is to create a very quick
hello world so i'm going to start from
scratch so the first thing i need to do
is to import the blender python library
which is uh conveniently named bpy
then i need to initialize a list of
vertices
and i'm going to create for now a single
vertex i'm just going to have one
vertice
for my example then i need to also have
a list of edges
but in this case i can have an empty
list of vertices
and then i also need to have a list of
faces and i can have
an empty list of faces so just so you
know so you understand
other concepts a vertex is a corner or
more precisely a point where two lines
intersect
of course this is assuming that we yeah
we have an object and all the words that
are connected but realistically if a
vertice is not actually connected to
anything else then it's it's kind of
useless
right you need to have a vertex
connected to something else to make
sense
otherwise it's just like a minute point
which has no use
so an edge is basically uh the line that
connects to
two vertices a face this is basically
when you connect uh three or more
vertices
it's a flat surface basically part of a
solid object normally you have
in computer graphics your faces are done
with triangles but you can also have
quadrilaterals and so on
as long as it's the surface flat then it
can be considered a face
so uh concepts aside uh i have
here my vertices my edges my faces
so i'm going to create a mesh new mesh
equal to bpy dot data dot
meshes dot new so i'm creating a new
mesh
then i can initialize the mesh using the
from pi
data method which takes a list of
vertices
a list of edges and a list of faces and
then
i need to call new mesh dot and this
will update
everything inside the mesh to reflect
what i've just added to the mesh
so i need to also create an object okay
so new object equal to
dot bpy.data.org dot new new object
and new mesh yeah and then once i have
the object i need to add it to the view
so ppy dot context
dot view underscore layer and then view
on school layer
dot active layer underscore collection
dot collections dot objects dot link
the new object okay so what i've just
done
i just copied some code i have created
before
i just typed it so that you get to
understand more or less
the basics of what i'm doing here so
here
i created a list of vertices edges and
faces
then i created the mesh and then i added
to the mesh
the vertices and the edges and the faces
simple enough and then i updated the
mesh
then i added a mesh to an object and
then the object added to the view
and that's about it so i just have to
run it and hopefully there will be no
errors
and failed so i have an error so no
attribute collections because it's
not called collections it's called
collection okay so simple enough
okay so i'm just going to run this and
then i have here
my object with a single vertice yeah you
can see here
that's the single vertice i created okay
so before we do any more
let's go and have a look at the
documentation okay so
you can see here it takes a list of
vertices edges
and faces and makes a mesh out of it
it's nice to see
until we have a better way this is how
you should do it the problem with this
representation is that it forces me
to basically create a list of verses and
then always refer to an index
so if i want to define the faces i need
to know exactly what's the index of the
vertices
and so on so anyway i've done one
vertice but just to give you an idea of
how this works
i'm going to try and define a cube yeah
the famous cube in
blender so but i'm going to do it by
hand so a cube will have
eight vertices right so i'm going to
find the eight vertices in one go
so i'm going to define everything so one
zero and zero anyway i think i need to
draw for this
otherwise i get lost okay right so this
is a cube
okay this is z x
and then y okay so for the horrible
representation of the cube okay anyway
so we have
eight corners one two three
four five six seven eight
one two three four five six seven
eight and then what i need to do is to
figure out
i'm going to use coordinates of one to
make it easier
and then one here as well one here
and so on okay so the first point i'm
going to define
is this one here so this is x
equal to one and y equal to one
and then z equal to zero right okay the
second point
i'm going to define is this one so this
is x equal to minus one
x equal to minus one y equal to one
and z equal to zero so i've defined this
one and this one
i'm going to define this one as well so
this one is
y equal to minus 1 and then x equal to 1
so i've just defined this one and now i
need to define this one
oh wait this is z equal to zero
okay x equal to minus one y equal to
minus one and z equal to zero okay
so i have defined four points okay so
the ones are below and then the other
ones i need to find are
above so i'm just going to copy and
paste and i'm just going to bump the set
for all the points and then
we should be able to get at least all
the points needed to define a cube
later on once i do the faces okay
so i've just run it you can see the
points here right
first of all i would i want to show you
what an edge is right so i'm going to
join these two points here zero and one
and see what happens we see the the
edges and the vertices
okay so i'm going to take away this from
here
so i have defined four points right
below
and then four points above i'm just
going to create a face with four points
zero one two three
and that's one face oops did i make a
mistake
so one of my points must be wrong so
this one is
x equal to one y equal to minus one and
this one is
minus one minus one as you can see i
have to really
get this uh order right otherwise it
gets very confusing
so i don't like this notation so much
okay so let's try this
so yeah okay so now i've i've managed to
define the bottom face and then i want
to do the top as well so i'm going to
copy and paste
the first four points again because i
know that the ones i defined before they
are wrong
and i just have to bump the z value to
one so the bottom and top face are the
easiest so i'm going to add another face
so four five six
seven okay so i have the bottom and top
face
another tricky part is this face here
because now i need these vertices this
vertices
the top vertices and this one as well
so the face itself it's going to be
something like
0 so this is 0 and this is
4 and then this is seven
and then one more and then three and
that's it run brackets not square
brackets
and you see i have one more face of the
cube so i need the other face here
this is one zero and one and then
basically is four and then five
so this is one more phase so let's run
it again
okay i made a mistake it has to be in
order so i need to specify this one
first
so i can't do five i need to do five
here
then four right so now i've defined it
already four faces so i need two more
so so one then you have
two and then so six
and then this one is five and hopefully
this should do
one more phase yeah it did so i'm just
missing one one
zero so zero one two three
so three okay so that should do it right
so i've managed to do something that
looks like a box let's make it a cube
the reason why i didn't make a cube is
because i
started with the index zero right so z
equal to zero and then zero z equal to
one
i'm going instead of zero i'm going to
make it minus one hopefully this is not
going to change much
it shouldn't yeah and then they should
do it
so now it should be a cube and now so i
have a cube now
easy wasn't it but you know i've kind of
went
brute force and this is not a
sustainable way of trying to
define a cube so how else to do it