What is the best way to handle this.
If a create a Node and attached 2 Spatial to the node. I give the Node positional information and when I attach 1st children with 0,0,0 translation (no offset) and then 2nd one with (2,0,0) giving (offset of 2 x). and attach them to rootNode.
Everything works great.
Now 2 version.
If I do the same but this time I want to do the same thing but I need to give the 2 children physics and add them to physic space.
How do you do this. You can add the physics to the children and attach them to the Node, Because the physics appear to “ONLY” use the spatial translation and not use the main Node.
So what is the way to place certain spatial into a node so that you can handle the children correctly when they have physics?
I hope I"m clear.
Example 1: I try to add phsyics to Node and placement is correct but Spatial don’t have physics.
private Node addGrass(int model, int pos)
{
Node grassNode = new Node("grass");
grassNode.setLocalTranslation(0, 0, pos * terrianWidth);
Spatial spatial = this.getApplication().getAssetManager().loadModel("Models/environment/grass/model.obj");
Material mat = new Material(this.getApplication().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
Texture cube1Tex;
if (model == 0)
cube1Tex = this.getApplication().getAssetManager().loadTexture("Models/environment/grass/light-grass.png");
else
cube1Tex = this.getApplication().getAssetManager().loadTexture("Models/environment/grass/dark-grass.png");
mat.setTexture("DiffuseMap", cube1Tex);
spatial.setMaterial(mat);
spatial.setName("grass");
// spatial.setLocalTranslation(0, 0, pos * terrianWidth);
RigidBodyControl rigidControl = new RigidBodyControl(0);
grassNode.addControl(rigidControl);
bulletAppState.getPhysicsSpace().add(spatial);
addTrees(grassNode, pos);
grassNode.attachChild(spatial);
spatial.setShadowMode(ShadowMode.Receive);
return grassNode;
}
Example 2: I add physics to the Spatial and attach the Spatial to the Node. Physics are correct but placement is at 0,0,0 because Spatial has not translation and physics appear to work off the spatial and doesn’t take Node in.
private Node addGrass(int model, int pos)
{
Node grassNode = new Node("grass");
grassNode.setLocalTranslation(0, 0, pos * terrianWidth);
Spatial spatial = this.getApplication().getAssetManager().loadModel("Models/environment/grass/model.obj");
Material mat = new Material(this.getApplication().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
Texture cube1Tex;
if (model == 0)
cube1Tex = this.getApplication().getAssetManager().loadTexture("Models/environment/grass/light-grass.png");
else
cube1Tex = this.getApplication().getAssetManager().loadTexture("Models/environment/grass/dark-grass.png");
mat.setTexture("DiffuseMap", cube1Tex);
spatial.setMaterial(mat);
spatial.setName("grass");
// spatial.setLocalTranslation(0, 0, pos * terrianWidth);
RigidBodyControl rigidControl = new RigidBodyControl(0);
spatial.addControl(rigidControl);
bulletAppState.getPhysicsSpace().add(spatial);
addTrees(grassNode, pos);
grassNode.attachChild(spatial);
spatial.setShadowMode(ShadowMode.Receive);
return grassNode;
}
So can you add physics to items that are under a Node because I need to delete a entire group at once and it would be easier to just find the parent and delete that instead of finding all the physics and deleting them one by one.
Thanks.