Hi! I met a problem that seems noob, but I couldn't find any solution for hours now…
I loaded a file (a scene consisting of 5 boxes and 10 lights) and attached it to the rootNode (the file Szene.jpg is the scene binary). Right after loading a new box is spawned which is supposed to integrate in the new Node. The box is between the 2nd and 3rd box.
This new Box however remains black and is not being lighted. I guess I am missing something important… but I can't figure out what. I tried combinations of this.loaded, CopyOfTest.loaded, this.spawnBox(), CopyOfTest.loaded.this, box.setRenderState(ls).setEnabled(true) etc. trying to get it work but no success.
Also when I try to add a new Light => only the new Box is lighted, although I expected the other boxes to be lit-up too. It behaves as if the loaded file is a different node than the spawned box/light although SceneMonitor shows all of them in the same Node.
Any ideas :?
import javax.swing.JFileChooser;
//import com.acarter.scenemonitor.SceneMonitor;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.light.DirectionalLight;
import com.jme.light.LightControllerManager;
import com.jme.light.SimpleLightNode;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jme.util.export.binary.BinaryImporter;
public class CopyOfTest extends SimpleGame {
static Node loaded;
JFileChooser fileChooser;
public static void main(String[] args) {
CopyOfTest app = new CopyOfTest();
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
public void simpleInitGame() {
// clear first
rootNode.detachAllChildren();
lightState.detachAll();
LightControllerManager.reset();
fileChooser = new JFileChooser();
int returnVal = fileChooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION){
/*** Read File ***/
try {
//Select the file you want to load
loaded = (Node) BinaryImporter.getInstance().load(fileChooser.getSelectedFile());
rootNode.attachChild(loaded);
rootNode.updateGeometricState(0,false);
rootNode.updateRenderState();
// add a new Box to current scene
spawnBox();
// SceneMonitor.getMonitor().registerNode(rootNode, "Root Node");
// SceneMonitor.getMonitor().showViewer(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
else
System.out.println("Loading cancelled");
}
public void spawnBox()
{
Box box = new Box("Box",new Vector3f(0,0,0),10,10,10);
box.setLocalTranslation(0,0,0);
box.updateGeometricState(0,false);
box.setModelBound(new BoundingBox());
box.updateModelBound();
box.updateRenderState();
loaded.attachChild(box);
// make usable for more than 8 lights
LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
ls.setEnabled(true);
box.setRenderState(ls);
LightControllerManager.addSpatial(box);
box.setLightCombineMode(LightState.REPLACE);
// test adding a new light
// DirectionalLight dl = new DirectionalLight();
// dl.setDirection(new Vector3f(-0.5f,-1,-0.8f));
// dl.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
// dl.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
// dl.setSpecular(new ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f));
// dl.setEnabled(true);
// dl.setShadowCaster(true);
// LightControllerManager.addLight(dl);
// SimpleLightNode ln2 = new SimpleLightNode("ln2",dl);
// ln2.getLocalRotation().fromAngleAxis(60*FastMath.DEG_TO_RAD,new Vector3f(1,0,-1));
// loaded.attachChild(ln2);
loaded.updateRenderState();
loaded.updateGeometricState(0,false);
loaded.updateRenderState();
rootNode.updateGeometricState(0,false);
rootNode.updateRenderState();
}
// @Override
// protected void simpleUpdate() {
// super.simpleUpdate();
// SceneMonitor.getMonitor().updateViewer(tpf);
// }
// @Override
// protected void simpleRender() {
// super.simpleRender();
// SceneMonitor.getMonitor().renderViewer(display.getRenderer());
// }
// @Override
// protected void cleanup() {
// super.cleanup();
// SceneMonitor.getMonitor().unregisterNode(rootNode);
// }
}