Importing Blender Objects...
Subject says it all...How do you import objects created in Blender into OGL?
It is probably important to note that im using Python.
Thx in advance.
To make a long story short:
1. Save your model in Blender to a file format of your choice
2. Write code to load the model from the file format you chose in step 1
3. Write code to display the model data using OpenGL
1. Save your model in Blender to a file format of your choice
2. Write code to load the model from the file format you chose in step 1
3. Write code to display the model data using OpenGL
I dont think .raw exports texture coordinates (or normals either). You might want to check that, otherwise, the .x or .obj formats are simple.
here's what i use
it exports the vertices and faces; maybe would help.
import Blenderdef cb(filename): file=open(filename,"w") file.write("%d\n"%len(Blender.Object.Get())) for object in Blender.Object.Get(): matrix=object.getMatrix() mesh=Blender.NMesh.GetRawFromObject(object.name) file.write("%d\n"%len(mesh.verts)) for vertex in mesh.verts: #file.write("%f %f %f\n"%(mm(vertex,matrix)[0],mm(vertex,matrix)[1],mm(vertex,matrix)[2])) file.write("%f %f %f\n"%(vertex[0],vertex[1],vertex[2])) faces=0 for face in mesh.faces: if len(face.v)==3: faces+=1 else: faces+=2 file.write("%d\n"%faces) for face in mesh.faces: if len(face.v)==3: file.write("%d %d %d\n"%(face.v[0].index,face.v[1].index,face.v[2].index)) else: file.write("%d %d %d\n"%(face.v[0].index,face.v[1].index,face.v[2].index)) file.write("%d %d %d\n"%(face.v[2].index,face.v[3].index,face.v[0].index)) file.write("%f %f %f\n"%(matrix[3][0],matrix[3][1],matrix[3][2])) file.close Blender.Window.FileSelector(cb,"save as","this.3d")
it exports the vertices and faces; maybe would help.
I'm using the following for now. So far its working with everything:
filepointer = file('my_object.raw')
for line in filepointer.readlines():
coords = [float(x) for x in line.strip().split(' ')]
newcoord = []
for coord in coords:
newcoord.append(coord)
if len(newcoord) == 3:
glVertex3f(newcoord[0], newcoord[1], newcoord[2])
newcoord = []
Ugh...how do you do the code windows?
filepointer = file('my_object.raw')
for line in filepointer.readlines():
coords = [float(x) for x in line.strip().split(' ')]
newcoord = []
for coord in coords:
newcoord.append(coord)
if len(newcoord) == 3:
glVertex3f(newcoord[0], newcoord[1], newcoord[2])
newcoord = []
Ugh...how do you do the code windows?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement