Loading multiple 3D objects from an Obj file (min3D for Android)
Posted by Dennis on May 18, 2010 in 3D, Android • 5 commentsNOTE: This OpenGL ES 1.1 framework isn’t maintained anymore. Check out the OpenGL ES 2.0 Rajawali framework which also supports live wallpapers.
I just committed an update to min3D‘s .obj file parser. Yesterday’s tutorial showed how you can import an .obj file into min3D.
The latest commit adds support for multiple files in one .obj file. In this example, the car’s body and 4 wheels are separate objects.
This is the RendererActivity code that shows you how to get the separate objects from the parsed file:
package min3d.sampleProject1;
import min3d.core.Object3d;
import min3d.core.Object3dContainer;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
public class ExampleLoadObjFileMultiple extends RendererActivity {
private final float MAX_ROTATION = 40;
private final float MAX_CAM_X = 6f;
private Object3dContainer car;
private Object3d tireRR;
private Object3d tireRF;
private Object3d tireLR;
private Object3d tireLF;
private int rotationDirection;
private float camDirection;
@Override
public void initScene() {
IParser parser = Parser.createParser(Parser.Type.OBJ,
getResources(), "min3d.sampleProject1:raw/camaro2_obj");
parser.parse();
car = parser.getParsedObject();
scene.addChild(car);
tireRR = car.getChildByName("tire_rr");
tireRF = car.getChildByName("tire_rf");
tireLR = car.getChildByName("tire_lr");
tireLF = car.getChildByName("tire_lf");
tireLF.position().x = -.6f;
tireLF.position().y = 1.11f;
tireLF.position().z = .3f;
tireRF.position().x = .6f;
tireRF.position().y = 1.11f;
tireRF.position().z = .3f;
tireRR.position().x = .6f;
tireRR.position().y = -1.05f;
tireRR.position().z = .3f;
tireLR.position().x = -.6f;
tireLR.position().y = -1.05f;
tireLR.position().z = .3f;
car.rotation().x = -90;
car.rotation().z = 180;
scene.camera().position.x = MAX_CAM_X;
scene.camera().position.z = 3.5f;
scene.camera().position.y = 3.5f;
rotationDirection = 1;
camDirection = -.01f;
}
@Override
public void updateScene() {
tireRF.rotation().z += rotationDirection;
tireLF.rotation().z += rotationDirection;
if(Math.abs(tireRF.rotation().z) >= MAX_ROTATION)
rotationDirection = -rotationDirection;
scene.camera().position.x += camDirection;
if(Math.abs(scene.camera().position.x) >= MAX_CAM_X)
camDirection = -camDirection;
}
}
View the result here (click on the image to see the video):

This is great, I have it integrated in my code and it soooo almost works. Please don’t take this as being pushy but is there any kind of target date for adding group support?
@Michael: Hopefully soon. I just need some time to do it
I’m using min3d and it works fine. However the colors of my blender models are somehow not saved in the .obj files and are not loaded into min3d. The model is totally black.. how can i make it look nice?
I also have a model with textures however i dont know how to get those texture out of blender.. and i think it has two textures. Its this model file: http://www.blendswap.com/3D-models/weapons/colt/
Thanks for your hard work on min3d!
rather old post, but leaving answer
Blender OBJ export does not export the faces’ normals.
Without normals shading won’t work.
You can export from Blender as COLLADA .dae and import this to MeshLab.
MeshLab then exports .obj with normals.
The resulting text file has to be modified manually cause MeshLab uses “,” instead of “.” for float values. Min3d crashes if floats have “,”
Additionally you could add a light source in min3d like this:
_lightRed = new Light();
_lightRed.ambient.setAll(0×88110000);
_lightRed.diffuse.setAll(0xffff0000);
// _lightRed.diffuse.setAll(255, 0, 0, 0); // RGBA 0..255
_lightRed.type(LightType.POSITIONAL);
_lightRed.type(LightType.DIRECTIONAL);
_lightRed.position.setAll(0, 0, 0);
scene.lights().add(_lightRed);
EDIT: The export options for OBJ are now located in the Blender file selector window to the left. Did not find them on first look..
There you can have normals exported, too.