So, I have a .j3o object, where the actual geometry is not located at the coordinate origin (0/0/0) but rather far away from that (like 20/15/27). Between the actual geometry inside the j3o and the coordinate origin, there is void.
The problem now with rotating the Spatial on y-axis obviously: not only the model was rotated, but moved all along the scene.
I searched for a fix about an hour (some kind of calculating the hitbox of the object and then move it to the coordinate origin), but I found, that I only need to attach the Spatial to a Node:
Node n = new Node();
n.attachChild(loadedModel);
loadedModel.addControl(new C_Spinner());
rootNode.attachChild(loadedModel);
So, by just adding the Spatial to a Node, the Model appeared exactly at 0/0/0 and rotated accordingly.
My question is:
how is this achieved? Is this intended or just a side-effect?
I tried to dig deep into the āattachChild(Spatial)ā method, but couldnt find the answer.
Thanks for your answers in advance
Greetings from Germany!
In my project (an android application) a user can load ANY model for showing it augmented in the live-camera picture. The problem here is, that I have to fix the off-center coordinate-issue in code automaticaly.
But as I said in my first post, I found the solution by simply adding the Spatial (Model) to a Node, without any further adjustments or movements.
Iād like to understand, why this fixes the problem.
@Big bob
Please reread my first post.
When importing the Model, the scene looks like this:
The Model itself obtains empty space so the imported model is at 0/0/0, but the ārealā-Model (the chair) is not.
When using the code from post #1, the result looks like this:
This has nothing todo with the model being added to 0/0/0. There must be some line of code in the attachChild which trims the empty-space in the Modelā¦
Thats my question. How is this implemented?
The children of the loaded node must be offset. You canāt just get rid of this space because then all of the children might be on top of each other (ie: the back of the chair may be separate elevated from the chair, etc.) you donāt know which āspaceā is supposed to be there and which was a mistake when the model was made.
Putting it into a node and reoffsetting is all you can do, reallyā¦ other than making your users make good models to begin with.
But his question was, how comes that the model is chentered, even if you only wraps it in a parent node without adding a manual local translation? What magic does the node do with its children that the furniture piece suddenly rotates arount its correct center?
@simon.heinen said:
But his question was, how comes that the model is chentered, even if you only wraps it in a parent node without adding a manual local translation? What magic does the node do with its children that the furniture piece suddenly rotates arount its correct center?
Yeah, wellā¦ we donāt see enough code then. We donāt know where loadedModel comes from but the only way attaching it to a node effects anything is if it used to have a different parent, ie: it wasnāt the root of the model.