Models and Nodes

My hard drive decided I should take a break from jME for a while, and now that I'm starting to work with it again I've got a question (surprise surprise).



Scenario:



2 models.  model1 has two cubes defined, CubeA, CubeB.  model2 is something simple - like a sphere for arguments sake.

The goal?  Place model2 on CubeB.



Psuedocode:



Node model1 = ModelLoader.loadModel( model1File );
Node model2 = ModelLoader.loadModel( model2File );

Spatial cubeB = model1.getChild("CubeB");

cubeB.setModelBound( new BoundingBox() );
cubeB.updateModelBound();
cubeB.updateWorldBound();

Vector3f center = cubeB.getWorldBound().getCenter();

model1.attachChild(model2);
model2.setLocalTranslation(center);



Is this the optimum way to accomplish this goal?

If you get the center, it will collision for half of the cube. Why don't put those 2 models in one? Else, try something like this:

Node model1 = ModelLoader.loadModel( model1File );
Node model2 = ModelLoader.loadModel( model2File );

Spatial cubeB = model1.getChild("CubeB");
Vector3f v = cubeB.getLocalTranslation();
v.y = cubeB.getHeight();
model2.setLocalTranslation(v);



Disclaimer: This is just a personal opinion and does not reflect the way recommended by the jMonkeyEngine Staff. I am not affiliated with jMonkeyEngine in any way.