Sign in to follow this  

Importing Blender Objects...

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
here's what i use


import Blender

def 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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 3591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this