Can anyone talk me through the steps of reading all the objects in a blender scene and writing co-ordinates to a file? It will be v. helpful if I can use blender in conjunction with my game I’m writing.
I was at that point too, and it helped me to take a look at the scripts that do exporting for various formats, to learn how that works.
Here´s a big list of scripts (the “Script List Effort” Topic):
https://blenderartists.org/forum/viewtopic.php?t=8095
hmm… I’ll check the list. Also, can anyone run me through step-by-step?
hmm…the way to do it really depends on what the file type is…what is the layout of the file type you are using?
Dan.a
It goes as follows -
NUMTEXTURES (Number)
“c: exture
ameoftexture.jpg”
NUMPOLLIES (Number)
NUMVERTS (Number)
TEXTURE (ID no. of texture)
1.0(x co-ordinate) 1.0(y co-ordinate) 0.0(z co-ordinate) 1.0 1.0(x+y texture co-ordinates)
0.0(x co-ordinate) 1.0(y co-ordinate) 0.0(z co-ordinate) 0.0 1.0(x+y texture co-ordinates)
0.0(x co-ordinate) 0.0(y co-ordinate) 0.0(z co-ordinate) 0.0 0.0(x+y texture co-ordinates)
NUMLIGHTS (Number)
(Ambient light) 1.0(red) 1.0(green) 1.0(blue)
(Positional Light) 1.0(red) 1.0(green) 1.0(blue)
(Position of light) 1.0(x) 1.0(y) 1.0(z)
okay… I’m assuming you know at least the basics of python…
there are many ways to select objects…so I’ll leave that up to you by reading the api docs…
next step is to get the NMesh data from the object you want to export (here it is obj):
objmesh = NMesh.GetRawFromObject(obj.getName())
then you want to get a list of the faces:
objfaces = objmesh.faces
then, you can get the vertices for example from the first face by saying:
objfaces[0].v
– you can then get the actual coordinates for each vertice by running (for example)
objfaces[0].v[0].co – the second 0 just indexes the first vertex
and you can get the corresponding uv coordinates list (for the face) by running eg:
objfaces[0].uv
That should be enough to get you started…I haven’t done any of the light stuff before…but for the stuff I didn’t cover, just read the api docs (using what I said about the face/vert stuff to help you understand how they work)
also, sorry it took so long…twas inundated with uni work
Dan.a