Wednesday, August 11, 2010

Blender 2.5 Objective-C Export Script

Paul Horalek has taken my old Blender 2.49 script for exporting 3D objects to Objective-C header files and has ported it to the new Blender 2.5 Python API. I'd been meaning to do this for quite some time, as I've been using Blender 2.5 since the early alpha releases, but never found time. Now I don't have to.

You can find the new version of the script right here.

Thanks, Paul!


shgams said...

And how do we use it? When I run it says:

File "./", line 153
return {'FINISHED'}
SyntaxError: invalid syntax

I'm not at all familiar with Python so can't just fix myself.

淑梁梁梁娟 said...


Stela James said...

I like your information. I have been looking for this type of information that is interesting and good.

Brian said...

Blender is horribly documented so here is how to install the script.

Get the 2.5 version of blender (it's beta so it's not the first download link)

Once blender is in the right place (/Applications) copy the script here


note that /Applications/blender above is likely /Applications/blender-2.53-beta-OSX-10.5-x86_64/ or something.

Then the script is available from the file.export menu.

耿麗旺麗旺麗旺綺 said...


shgams said...

Will you be updating this for ES 2?

Paul Kite said...

I'm unable to get this to even show up in the export sub menu. And in the enable/disable add ons preferences I can't even get it to enable. Has anyone else had this issue or know a way to force it to enable?

Jigsaw said...

Im having the same issue, cannot enable this via the user preferences on Blender.

Igor said...

This is one great script. However, when I export Suzanne from blender, I always get something that looks like culling problem, no matter what I do.
For example, when I look at the head from behind, I can see the eyebrows "leaking" from the face to the back of the head. Can you please help me and tell me what I'm doing wrong? My render method goes like this (in its 50-th iteration :))

- (void) render
// Replace the implementation of this method to do your own custom drawing

// This application only creates a single context which is already set current at this point.
// This call is redundant, but needed if dealing with multiple contexts.
[EAGLContext setCurrentContext:context];

// This application only creates a single default framebuffer which is already bound at this point.
// This call is redundant, but needed if dealing with multiple framebuffers.
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);

static float transY = 0.0f;



glOrthof(-2.0f, 2.0f, -2.0f*((float)backingHeight/backingWidth), 2.0f*((float)backingHeight/backingWidth), -6.0f, 6.0f);
glViewport(0, 0, backingWidth, backingHeight);


glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
glRotatef(self.rotationX + rx0, 1.0, 0.0f, 0.0f);
glRotatef(self.rotationY + ry0, 0.0, 1.0f, 0.0f);
transY += 0.075f;

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
GLfloat ambientAndDiffuse[] = {0.4, 0.4, 0.4, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambientAndDiffuse);

float lightAmbient[] = { 0.2f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);

glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), &SuzanneVertexData[0].vertex);
glNormalPointer(GL_FLOAT, sizeof(VertexData3D), &SuzanneVertexData[0].normal);
glDrawArrays(GL_TRIANGLES, 0, kSuzanneNumberOfVertices);

// This application only creates a single color renderbuffer which is already bound at this point.
// This call is redundant, but needed if dealing with multiple renderbuffers.
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

lala said...

Thanks for your post and welcome to check: here

Volare said...

The reason you can't enable it is because there is a bug in the posted script and Blender doesn't let you enable a script that causes Python to throw exceptions etc. you can use Blender's console to debug the script but I think that's kind of hopeless because Blender docs clearly states that the Python API for 2.5 might change and don't rely on it.

So you have to also learn how it works actually because when the API changes you will have to go back and fix it...

SEO Services Consultants said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck! Web Design Company

drmattryan said...

This is a great script. however I have found that if the models are very large and you have a lot of them in your project, it takes a long time to compile. I have a project where the .h files are about 2Mb each and there are over 20 models. This takes about 30 minutes to compile on my machine!

To fix this, I modified the exported files slightly to create a .m and a .h All the data is now in the .m, so that the files containing all the data only need to be compiled once, and compiling is now very quick.

If anyone wants details on this, let me know and I will post some code...