* Fix BillboardControl "Spatial was not updated before rendering" crash

* Add F5 key to hide FPS/stats

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7813 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent bffe191275
commit 87737f96e0
  1. 9
      engine/src/core/com/jme3/app/SimpleApplication.java
  2. 23
      engine/src/core/com/jme3/scene/control/BillboardControl.java

@ -68,6 +68,7 @@ public abstract class SimpleApplication extends Application {
public static final String INPUT_MAPPING_EXIT = "SIMPLEAPP_Exit"; public static final String INPUT_MAPPING_EXIT = "SIMPLEAPP_Exit";
public static final String INPUT_MAPPING_CAMERA_POS = "SIMPLEAPP_CameraPos"; public static final String INPUT_MAPPING_CAMERA_POS = "SIMPLEAPP_CameraPos";
public static final String INPUT_MAPPING_MEMORY = "SIMPLEAPP_Memory"; public static final String INPUT_MAPPING_MEMORY = "SIMPLEAPP_Memory";
public static final String INPUT_MAPPING_HIDE_STATS = "SIMPLEAPP_HideStats";
protected Node rootNode = new Node("Root Node"); protected Node rootNode = new Node("Root Node");
protected Node guiNode = new Node("Gui Node"); protected Node guiNode = new Node("Gui Node");
@ -100,6 +101,10 @@ public abstract class SimpleApplication extends Application {
} }
} else if (name.equals(INPUT_MAPPING_MEMORY)) { } else if (name.equals(INPUT_MAPPING_MEMORY)) {
BufferUtils.printCurrentDirectMemory(null); BufferUtils.printCurrentDirectMemory(null);
}else if (name.equals(INPUT_MAPPING_HIDE_STATS)){
boolean show = showFps;
setDisplayFps(!show);
setDisplayStatView(!show);
} }
} }
} }
@ -215,8 +220,10 @@ public abstract class SimpleApplication extends Application {
inputManager.addMapping(INPUT_MAPPING_CAMERA_POS, new KeyTrigger(KeyInput.KEY_C)); inputManager.addMapping(INPUT_MAPPING_CAMERA_POS, new KeyTrigger(KeyInput.KEY_C));
inputManager.addMapping(INPUT_MAPPING_MEMORY, new KeyTrigger(KeyInput.KEY_M)); inputManager.addMapping(INPUT_MAPPING_MEMORY, new KeyTrigger(KeyInput.KEY_M));
inputManager.addMapping(INPUT_MAPPING_HIDE_STATS, new KeyTrigger(KeyInput.KEY_F5));
inputManager.addListener(actionListener, INPUT_MAPPING_EXIT, inputManager.addListener(actionListener, INPUT_MAPPING_EXIT,
INPUT_MAPPING_CAMERA_POS, INPUT_MAPPING_MEMORY); INPUT_MAPPING_CAMERA_POS, INPUT_MAPPING_MEMORY, INPUT_MAPPING_HIDE_STATS);
} }
// call user code // call user code

@ -80,9 +80,6 @@ public class BillboardControl extends AbstractControl {
AxialZ; AxialZ;
} }
public BillboardControl() { public BillboardControl() {
super(); super();
orient = new Matrix3f(); orient = new Matrix3f();
@ -108,6 +105,18 @@ public class BillboardControl extends AbstractControl {
rotateBillboard(cam); rotateBillboard(cam);
} }
private void fixRefreshFlags(){
// force transforms to update below this node
spatial.updateGeometricState();
// force world bound to update
Spatial rootNode = spatial;
while (rootNode.getParent() != null){
rootNode = rootNode.getParent();
}
rootNode.getWorldBound();
}
/** /**
* rotate the billboard based on the type set * rotate the billboard based on the type set
* *
@ -168,7 +177,7 @@ public class BillboardControl extends AbstractControl {
// The billboard must be oriented to face the camera before it is // The billboard must be oriented to face the camera before it is
// transformed into the world. // transformed into the world.
spatial.setLocalRotation(orient); spatial.setLocalRotation(orient);
spatial.updateGeometricState(); fixRefreshFlags();
} }
/** /**
@ -188,10 +197,10 @@ public class BillboardControl extends AbstractControl {
Quaternion rot=new Quaternion().fromRotationMatrix(orient); Quaternion rot=new Quaternion().fromRotationMatrix(orient);
if ( parent != null ) { if ( parent != null ) {
rot = parent.getWorldRotation().inverse().multLocal(rot); rot = parent.getWorldRotation().inverse().multLocal(rot);
rot.normalize(); rot.normalizeLocal();
} }
spatial.setLocalRotation(rot); spatial.setLocalRotation(rot);
spatial.updateGeometricState(); fixRefreshFlags();
} }
/** /**
@ -256,7 +265,7 @@ public class BillboardControl extends AbstractControl {
// The billboard must be oriented to face the camera before it is // The billboard must be oriented to face the camera before it is
// transformed into the world. // transformed into the world.
spatial.setLocalRotation(orient); spatial.setLocalRotation(orient);
spatial.updateGeometricState(); fixRefreshFlags();
} }
/** /**

Loading…
Cancel
Save