Retreive size anf position from a loaded j3o ? --Solved

Hello,



I would like to retrieve something like a HeightMap from a model I’ve loaded.

I’m using for now the model town.zip given with the tutorial.

For that, I need to know the dimensions of the loaded object.



I load it with this method :

[java]

Spatial battlegroundModel = assetManager.load( “main.3jo” );

CompoundCollisionShape battlegroundShape = CollisionShapeFactory.createMeshCompoundShape((Node) battlegroundModel );

Node battlegroundNode = new PhysicsNode( battlegroundModel, battlegroundShape, 0); // 0 : The model is static an has no weight

rootNode.attachChild( backgroundNode );

[/java]



How can I retrieve dimensions from the looaded object ?



Thanks in advance!

Try

java.getExtent()[/java]

this way you should get a halfExtents vector describing the bounding box of the model.

Yess!!!



It works !



Thanks!



[java]

private void createBattlegroundModel( String fileName, float width, float depth )

{

//Create 3D model

battlegroundModel = ViewManager.getAssetManager().loadModel( fileName );

BoundingBox box = ((BoundingBox)battlegroundModel.getWorldBound());



float currentWidth = box.getXExtent();

float currentHeight = box.getYExtent();

float currentDepth = box.getZExtent();



//Scale

float scaleX = width / ( currentWidth * 2 );

float scaleZ = depth / ( currentDepth * 2 );

float scaleY = ( scaleX + scaleZ ) / 2 ;

battlegroundModel.scale( scaleX, scaleY, scaleZ );



//Translation

box = ((BoundingBox)battlegroundModel.getWorldBound());

currentWidth = box.getXExtent();

currentHeight = box.getYExtent();

currentDepth = box.getZExtent();



Vector3f translationVector = new Vector3f( currentWidth - box.getCenter().getX() ,

currentHeight - box.getCenter().getY(),

currentDepth - box.getCenter().getZ() );

battlegroundModel.move( translationVector );



//Retrieve maxHeight

box = ((BoundingBox)battlegroundModel.getWorldBound());

this.maxHeight = box.getYExtent() * 2 + 1;

}

[/java]