Hello. I’ve been having some issues with the model I loaded from a .obj file extension. I need to be able to reference the component parts of this model and manipulate these parts individually. This has been my struggle for the last several hours.
To load the model itself, I simply write:
[java]Model = (Node)assetManager.loadModel(“model.obj”);[/java]
To then reference the component parts, of the model, I initially tried to do this:
[java]Spatial part = model.getChild(“Part1”);[/java]
However, this doesn’t work as it does not seem possible to reference the different spatials by the same name that I gave them in 3DS, even if their individual meshes are correct. So instead, I devised this way of doing it:
[java]Spatial part = model.getChild(7);[/java]
The above successfully retrieves the part, with the drawback that I need to trial-and-error my way to which part goes with which index. On the way, I discovered that on calling model.getChild(int), that model seemed to be removed from the list of model children. Case in point, if before a cast to model.getChild(int) I do this:
[java]System.out.println(model.getChildren().size());[/java]
It might print, say, 12. If I then call model.getChild(7) and do the print of getChildren().size() again, it returns 11. Why is this?
Then, I need to take this spatial and apply transforms to it. In order to do this, I wrap it in a node, and attach it back to the model, as such:
[java]Node partNode= new Node();
partNode.attachChild(part);
model.attachChild(partNode);[/java]
In this way I attach the spatial back to my original model in its original location. When I now try to apply a transformation to it, nothing happens. Yes, this is done in the update thread.
[java]partNode.setLocalRotation(new Quaternion().fromAngleNormalAxis(FastMath.HALF_PI-(float)Math.random()*0.05f, Vector3f.UNIT_Y));[/java]
If I simply make myself some random box and do the same thing, it works perfectly. What’s so different about my partNode?
What I want to know is; is there a “best” way of referencing component parts of a .obj model, and applying transforms to only these parts? What am I doing wrong here?