Here is my code.
World creation:
Object loading:
Object adding to scene:
Camera setup:
It works fine for other models. Some of them were exported from Blender and some from 3Ds Max as this one.
World creation:
Code Select
CurrentWorld = new World();
CurrentWorld.setAmbientLight(20, 20, 20);
CurrentWorld.setClippingPlanes(1, 100000); //added after your recomendation
Object loading:
Code Select
Object3D[] subobjects = null;
try
{
subobjects = Loader.load3DS(stream, DefaultScale);
}
catch(Exception ex)
{
LogSystem.LogException(TAG, "Loading model raised an exception", ex);
}
if(subobjects != null)
{
Object3D wholeObject = new Object3D(0);
Object3D subobject = null;
for (int i = 0; i < subobjects.length; i++)
{
subobject = subobjects[i];
subobject.setCenter(SimpleVector.ORIGIN);
subobject.rotateX((float)( -.5 * Math.PI));
subobject.rotateMesh();
subobject.setRotationMatrix(new Matrix());
wholeObject = Object3D.mergeObjects(wholeObject, subobject);
}
wholeObject.calcBoundingBox();
wholeObject.calcNormals();
wholeObject.setName("myself");
wholeObject.build();
return wholeObject;
}
Object adding to scene:
Code Select
CurrentWorld.addObject(object);
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
object.setTransparency(-1); //added after your recomendation
Camera setup:
Code Select
float[] box = object.getMesh().getBoundingBox();
SimpleVector camPos = CurrentWorld.getCamera().getPosition();
float objectHeight = box[3] - box[2];
float newZPos = box[4] - objectHeight * 1.5f;
float halfHeightPos = box[3] - objectHeight * 0.5f;
SimpleVector newPos = new SimpleVector(camPos.x, halfHeightPos, newZPos); //trying to put camera at the half of objects height and in front of object by 1.5 of height
CurrentWorld.getCamera().setPosition(newPos);
SimpleVector lookPos = new SimpleVector(camPos.x, halfHeightPos, 0);
CurrentWorld.getCamera().lookAt(lookPos); //look at object transform center also been tried
It works fine for other models. Some of them were exported from Blender and some from 3Ds Max as this one.