In my application, I want to be able to change the material used on my Spatial when a user clicks on it. I’m doing the following right now, but I noticed that my Spatial never changes visually. It is always just using the _defaultMaterial.
I tested the _selectedMaterial by setting that material on a Spatial when I first create and add it to _myNode and that works fine, but it seems like I can’t change the material during run time. In my console window I do see that my selected Spatial prints out that it is selected, but yet the material used to render is not changing. What is wrong?
_myNode.depthFirstTraversal( new SceneGraphVisitor() {
@Override
public void visit( Spatial spat ) {
if( spat == selectedGeo ) {
spat.setMaterial( _selectedMaterial );
System.out.println( "geo: " + spat.getName() + " is Selected" );
} else {
spat.setMaterial( _defaultMaterial );
System.out.println( "geo: " + spat.getName() + " is NOT Selected" );
}
}
} );