Jump to content
  • Advertisement
Sign in to follow this  
Ahl

Importing Blender Objects...

This topic is 3803 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
Advertisement
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
Alright have a solution. .raw seems to be the way to go.

Thx for the suggestion.

Share this post


Link to post
Share on other sites
I dont think .raw exports texture coordinates (or normals either). You might want to check that, otherwise, the .x or .obj formats are simple.

Share this post


Link to post
Share on other sites
I'm not worried about textures and such just yet. Just loading an object works for me.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!