Light in imported obj files

Hello, I’m having some doubts understanding how openFrameworks is parsing the obj file and positioning the light from it.
I’ve the Cornell Box scene saved as .obj file, when I open it wit blender, I see that it contains the 2 boxes, the walls AND the light, as you can see from this screenshot.

When I import the file in openFrameworks, without setting any ofLight

void ofApp::setup(){

    model.loadModel("CornellBox-Original.obj", 20);
    model.setRotation(0, 180, 0, 0, 1);

void ofApp::draw(){
    ofDrawBitmapString(ofToString(ofGetFrameRate(),0), 20, 20);


My app shows this image:

I assume that a light it is present in the scene, otherwise I could not see the red and green wall, but it is not clear to me if openFrameworks create an istance of ofLight automatically, independently from the .obj file, or if the light that is there is the Lamp object that was visible in Blender.

I’ve the same doubt regarding the camera. In my openFrameworks app I’m creating an instance of ofEasyCam but a camera is already into the .obj file (in attachment the scene opened in blender using the perspective camera).
How can i set the camera position in my openFrameworks application to be the same as the camera position that I see in the blender file?

It looks like Assimp has a camera and a light struct

This means that there should be a way to get this information out of ofxAssimpModelLoader, and getAssimpScene is returning an aiScene

Inspecting the model object, that is an instance of ofxAssimpModelLoader, i do not see any light nor camera in it, although the scene struct is present. Could this be a bug in the ofxAssimpModelLoader?

yes ofxAssimpModelLoader only loads models as it’s names indicates :slight_smile: there’s no utilities yet to load lights or cameras from an scene

I see. Would it make sense to have camera and light position from this addon? In case I could take care of making a PR

yeah i think that would be useful


Just to be clear. The obj format is unfortunately for geometry only. Not even transforms are supported. Open it in a text editor and you’ll see how it works.
Other formats like fbx get real complicated really fast. There’s really no good middleground format that’s easy to work with.

If you just want to send things from blender it shouldn’t be too difficult to write a custom exporter/importer that supports lights and cameras. You get away with just the transform and the fov/multiplier.

Yes i was suspecting it, but when I’ve read this line:

## Object light 
v	-0.24  1.98   0.16
v	-0.24  1.98  -0.22
v	 0.23  1.98  -0.22
v	 0.23  1.98   0.16

g light
usemtl light
f -4 -3 -2 -1

in the obj file I’ve though that it should not be too complicated to have the light position back from the .obj file

I see. I guess it’s exporting the viewport representation of the light:) Kind of bad practice by the exporter imho.

But rather than hack around limitations in an old format if all you want is to easily move stuff over from blender to of. It wouldn’t be much work to do a custom solution.

It’s just a suggestion since this is under beginners. You might know a lot about meshes already but otherwise it’s a good exercise to learn :wink:

Suggestions are always appreciated :wink: I just wanted to find a way to have a way to have a scene defined in a data file, and as a scene I mean camera, lights and objects. For now I’m positioning scene and camera by myself, thanks for your hints

Unfortunately there’s no simple widely used format that supports those things together (that I know of atleast).
Obj is easy and works fine for meshes but that’s it.

The next step up is usually fbx, which “supports” everything in theory but is very complex and a pain to use in practice. And recently alembic has become popular. Check the ofxaddons.

Thank you koda, I will have a look

yes fbx is usually the most common, dae might work fine also with assimp and gltf is recently becoming pretty popular

you might also have luck directly importing the blender format using assimp if you don’t have very complex animations

1 Like