Re: 3ds max tips

Started by mAlinka, November 19, 2015, 07:33:05 AM

Previous topic - Next topic

EgonOlsen


mAlinka

It returns false. So how can I configure my camera to make it capture the object? I mean what is the general practice of camera set up to be sure that the object will be visible?

EgonOlsen

lookAt() at the transformed center is usually ok...have you tried to increase the far plane even further? Like 20.000 or 100.000?

mAlinka

Yes, and it has no effect.

EgonOlsen

Can't you make sure that the object is located at the origin and that the camera looks straight to it? With your current scene setup, it's a bit more complicated than it needs to be...

mAlinka

I tried another way - make camera look at (0, 0, 0) and then translate my object to put its transformed center to (0, 0, 0). After that object.wasVisible() starts return true, but screen is still empty.

EgonOlsen

Maybe the object is so large that you are standing inside it? Try another scale.

EgonOlsen

...or maybe you are rendering a dark object in front of a dark background or something like that. It always helped me to clear the background in some color like blue or red in such cases.

mAlinka

#23
The scene has a transparent background and there is camera preview behind it.
I tried scaling. It did not help.

I asked our designer to scale down the model and now it has such properties:
bounding box : [-56.823803, 54.82773, -113.101685, -20.355627, -29.19638, 7.774193];
transformed center : (-0.74186236, -83.03801, -14.0675335);
origin : (0.0, 0.0, 0.0).

Camera position is (0.0,-66.72865,-168.31546) now ant it looks at (0.0,-66.72865,0.0).

Calling to wasVisible() returns true without any additional transformations (no scaling, no translation). And object is still invisible...

EgonOlsen

Have you tried to set the transparency to -1? Some files contain bogus alpha values for the model and jPCT-AE reads and uses those.

EgonOlsen

I just dropped the model in some basic HelloWorld example and it displayed just fine. Looks like as if the importer can't read its diffuse color information, so it ended up all black. But apart from that, all was well. How are you loading the model/adding it to the world?

mAlinka

Here is my code.
World creation:
CurrentWorld = new World();
CurrentWorld.setAmbientLight(20, 20, 20);
CurrentWorld.setClippingPlanes(1, 100000);    //added after your recomendation


Object loading:

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:

CurrentWorld.addObject(object);
object.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
object.setTransparency(-1);       //added after your recomendation


Camera setup:

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.

EgonOlsen

Looks ok at first glance. I would take a step back and use a modified HelloWorld example to see if the model actually renders at all. Maybe it's an entirely different issue than what you think it is...