Node vs TriMesh?

I have some code taken from the HelloModelLoading example source (loading maggie), and when importing my own model, it comes back as TriMesh instead of the expected type: Node. 



This seemed to be best solved by using a more abstract class, in this case Spatial seemed appropriate, however what I'm finding is if I cast it to a Spatial :



Spatial maggie = ( Spatial )BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));



Then when I do this the boundingbox and the spatial (maggie) fail to return the correct location for this object on the scene.  They always seem to return somewheres near 0,0,0 … I've tried updatingBoundingVolume, etc… but my question is if I'm throwing away something when downcasting to Spatial thats causing this?  Whats a reliable way to get the location of an object?

you don't loose any information when downcasting



you get the location with getLocalTranslation() or getWorldTranslation(). (world translation might not always be up to date).

with that matter… I'd like to ask what is the difference between LocalTranslation and WorldTranslation… should WorldTranslation have to be depracated since it only returns the same as LocalTranslation?

LocalTranslation is translation relative to the immediate parent. WorldTranslation is relative to the world (root).



They're only the same for objects that are attached directly to the root node.



Imagine you have a car attached to the root, and wheels attached to the car.



For the car, localTranslation = worldTranslation.

For the wheels, localTranslation is the offset of the wheel from the car.

worldTranslation is the position of the car in the world plus the offset of the wheel.

1 Like

Thanks for the info Alric… I've really learned a lesson with that… Guess I've taken that for granted since I've always been attaching objects to the root, so didn't really matter… I'll keep that in mind  XD

Just to also provide some more comments on what Alric posted about, nodes are really good for pivot points also.



E.g. the car mesh would be attached to a node, each wheel would be attached to a node, attached to the car node, and so on. This way, no matter where the car is in world space, it'll rotate appropiately (if you translate it and then rotate it, it'll orbit around the origin, rather than rotating in place). The actual wheel meshes would remain at local translation (0,0,0), but the wheel node's local translation would be the offset relative to the car.



In simple cases you don't really have to worry about this, but in complex cases where you have lots of components that need to rotate or pivot, it's a big deal.



I highly recommend doing some testing on your own and look at the differences, it can be very instructive. Can do something simple like a turret that rotates and a barrel that swivels. Other than the rendering capabilities, its the power of the scenegraph at work!