Importing Blender Objects...

Started by
5 comments, last by Ahl 16 years, 1 month ago
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.
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
Alright have a solution. .raw seems to be the way to go.

Thx for the suggestion.
I dont think .raw exports texture coordinates (or normals either). You might want to check that, otherwise, the .x or .obj formats are simple.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

I'm not worried about textures and such just yet. Just loading an object works for me.
here's what i use

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?

This topic is closed to new replies.

Advertisement