Ben Ford

benford.me

Exporting Models Out of Cinema 4D

This post is more for my reference than anything else, but it may come in useful to other people.

I’m slowly starting to incorporate 3D elements into UI elements of a few different iOS applications. For decent looking output in OpenGL ES2, you need three basic elements for a model: vertex data, normals, and texture coordinates. I’m happy using simple objects, a lot can be accomplished with a plane and cube, but manually creating the coordinates has been tedius to accomplish by hand.

Texture Coordinate Diagram

I’m lucky to have copy of Cinema 4D 11.5 lying around; eventually I hope to create some other primary shapes, perhaps a sphere and rounded corner box. Cinema 4D 11.5 does export models int the OBJ format, but it doesn’t include normals, so it’s useless for importing into OpenGL ES2.

The riptide plugin is a fully featured OBJ exporter that exports normals. The free version of riptide doesn’t work on Cinema 4D 11.5, but the pro version does, which costs only $50. I tried out the demo version and it did the job perfectly.

The last step in the process would be importing the OBJ format into my application code. I’ll post more once I get this far (but don’t hold your breath, it will be a while.)

Links

OBJ Parser writting in Obj-C:
http://code.google.com/p/iphonewavefrontloader/

OBJ Parser writtin in C:
http://www.kixor.net/dev/objloader/

Riptide Pro:
http://skinprops.com/riptidepro.php

Wavefront OBJ format:
http://www.eg-models.de/formats/Format_Obj.html

The Wavefront .obj format

a comment until the end of the line

# some text

A single vertex coordinate. The first vertex listed in the file has index 1, and subsequent vertices are numbered sequentially.

v float float float

A single normal. The first normal in the file is index 1, and subsequent normals are numbered sequentially.

vn float float float

A texture coordinate. The first texture coordinate in the file is index 1, and subsequent textures are numbered sequentially.

vt float float

A polygon face. The numbers are indexes into the arrays of vertex positions, texture coordinates, and normals respectively. A number may be omitted if, for example, texture coordinates are not being defined in the model.

f int int int ...
    or
f int/int int/int int/int...
    or
f int/int/int int/int/int int/int/int ...

There is no maximum number of vertices that a single polygon may contain. The .obj file specification says that each face must be flat and convex.

Example of an .obj cube:

v 1 1 1
v 1 1 -1
v 1 -1 1
v 1 -1 -1
v -1 1 1
v -1 1 -1
v -1 -1 1
v -1 -1 -1
f 1 3 4 2
f 5 7 8 6
f 1 5 6 2
f 3 7 8 4
f 1 5 7 3
f 2 6 8 4