Hey guys, i created some randomly spawning trees in my game but i cant get the cloned materials on all of them only the first one has the material.
[java]
if (this.app.getTimer().getTimeInSeconds() < 5) {
treeModel = (Spatial) assetManager.loadModel("Models/Trees/Tree.j3o");
material = assetManager.loadMaterial("Models/Trees/Tree.j3m");
treeModel.setMaterial(material);
tree = new Node();
trees = new Spatial[21];
treeMaterial = new Material[21];
for (int i = 0; i < 20; i++) {
treeMaterial[i] = material.clone();
trees[i] = treeModel.clone();
trees[i].setMaterial(treeMaterial[i]);
tree.attachChild(trees[i]);
CollisionShape treeShape =
CollisionShapeFactory.createMeshShape((Node) tree);
treePhysics = new RigidBodyControl(treeShape, 0);
trees[i].addControl(treePhysics);
trees[i].setLocalTranslation(i + random.nextInt(50) - 70, -0.6f, i + random.nextInt(50) - 70);
this.app.getRootNode()
.attachChild(tree);
this.bulletAppState.getPhysicsSpace()
.add(treePhysics);
}
}[/java]
@JacobAmaral said:
Hey guys, i created some randomly spawning trees in my game but i cant get the cloned materials on all of them only the first one has the material.
@pspeed said:
Can you describe why you think this?
Im attaching an array of Spatials which clone the original Spatial then im cloning an array of materials which attach to the array of Trees then eventually to a Node. I will try to make a Node for the array of materials.
@JacobAmaral said:
Im attaching an array of Spatials which clone the original Spatial then im cloning an array of materials which attach to the array of Trees then eventually to a Node. I will try to make a Node for the array of materials.
Yes, but what isn’t working? Help us help you by actually telling us what the problem is.
@pspeed said:
Yes, but what isn't working? Help us help you by actually telling us what the problem is.
Oh sorry for the false communication. The material is only being set on of the trees not all 20 of them. So it spawns 20 trees with physics (rigidbody control) but the material is only set on one of them (i presume the first) i want the material to be set on all the trees.
Picture for reference:
The tree on the right has the material but all the other ones dont.
They must have some material or the app would crash. Does the material get the textures from the j3m or do you set those later? Do you set them on all of the clones, too?
Is there a reason that you are cloning the material? It shouldn’t matter but it seems unnecessary.
Setting them on the clones isnt working as intended. I’ve tried
[java]
tree = new Node();
trees = new Spatial[21];
treeMaterial = new Material[21];
treeMaterials = new Node();
Something else is wrong. They definitely have some material or the app would crash. And anyway, they’d normally get the material from the original anyway.
So something else is going on. It’s almost acting like they aren’t even added to the scene. In theory, the physics debug shapes would show up whether the nodes were attached to the root or not. I don’t see anything obviously wrong with the code that you’ve posted.
You will probably need to make a simple test case the illustrates the issue. When that works, then you can figure out what is different about the more complicated code.
@pspeed said:
Something else is wrong. They definitely have some material or the app would crash. And anyway, they'd normally get the material from the original anyway.
So something else is going on. It’s almost acting like they aren’t even added to the scene. In theory, the physics debug shapes would show up whether the nodes were attached to the root or not. I don’t see anything obviously wrong with the code that you’ve posted.
You will probably need to make a simple test case the illustrates the issue. When that works, then you can figure out what is different about the more complicated code.
Yeah im trying, if set material for each index of the array like:
tree[1].setMaterial
tree[2].setMaterial it works but extremely inefficient, the for loops doesnt make it work which im trying to figure out why
@pspeed said:
Something else is wrong. They definitely have some material or the app would crash.
It’s actually possible to have a null material in the scene graph and not get an IllegalStateException from the RenderManager. For example, if the geometry is culled.