Light in imported obj files


#1

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(){
    ofBackground(255,255,255);
    ofSetVerticalSync(true);
    ofEnableDepthTest();

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

//--------------------------------------------------------------
void ofApp::draw(){
    cam.begin();
    model.drawFaces();
    cam.end();
    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.


#2

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?


#3

It looks like Assimp has a camera and a light struct
http://assimp.sourceforge.net/lib_html/structai_camera.html
http://assimp.sourceforge.net/lib_html/structai_light.html

This means that there should be a way to get this information out of ofxAssimpModelLoader, and getAssimpScene is returning an aiScene http://openframeworks.cc/documentation/ofxAssimpModelLoader/ofxAssimpModelLoader/#show_getAssimpScene


#4

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?


#5

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


#6

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


#7

yeah i think that would be useful


#8

Hi,

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.


#9

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


#10

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:


#11

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


#12

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.


#13

Thank you koda, I will have a look


#14

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