Hey guys. I may have found a bug with the Apperance section of the sharedCopy method, but I’m not positive. This may be a known issue, but I havent seen anyone talk about it directly on the forums here…
Im loading my models using Kevs awesome 3DS loader.
Then Im making a clone of it, so that I can have multiple objects only having to load the model one time. Makes sense right.
The problem I’m having is that when I go to change the Appearance of one of the cloned nodes, it changes the appearance for all nodes. It seems like the Appearance is not getting cloned at all, and that they are using a shared Appearance.
This is my code:
This sets the material.
public void setMaterial(Group group, Material mat) {
java.util.List nodes = group.getChildren();
for (int i = 0; i < nodes.size(); i++) {
SceneGraphObject obj = (SceneGraphObject) nodes.get(i);
if (obj instanceof Shape3D) {
Shape3D sh = (Shape3D) obj;
sh.getAppearance().setMaterial(mat);
sh.getAppearance().setChanged(true); // for around for bug
} else if (obj instanceof Group) {
setMaterial( (Group) obj, mat);
}
}
}
Load the model from the model store and clone it into the characters branchgroup
TDSModel model = ModelStore.getModel(modelId);
// character is a branchgroup
character = (BranchGroup) model.sharedCopy(model);
Changing the appearance based on who “owns” the Character.
if (player == 1) {
setMaterial(TextureStore.redMat);
System.out.println("Color for: "+theName+" changed to red!");
} else
if (player == 2) {
setMaterial(TextureStore.blueMat);
System.out.println("Color for: "+theName+" changed to blue!");
}
A possible workaround for this is to create a new Appearance in my setMaterial method. I will test this out and see if it works. However, if its just something I’m doing wrong, or a bug, I’d like to know!
Thanks