import com.jme3.gde.core.scene.SceneRequest;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
+import com.jme3.gde.core.util.TerrainUtils;
+import com.jme3.renderer.Camera;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
}
});
}
+ setTerrainLodCamera(node);
}
public boolean sceneClose(SceneRequest request) {
}
}
}
+
+ /**
+ * Terrain has a LOD control that requires the camera to function.
+ */
+ protected void setTerrainLodCamera(JmeNode jmeRootNode) {
+ Camera camera = SceneApplication.getApplication().getCamera();
+ com.jme3.scene.Node root = jmeRootNode.getLookup().lookup(com.jme3.scene.Node.class);
+ TerrainUtils.enableLodControl(camera, root);
+ }
}
--- /dev/null
+
+package com.jme3.gde.core.util;
+
+import com.jme3.renderer.Camera;
+import com.jme3.scene.Node;
+import com.jme3.scene.Spatial;
+import com.jme3.terrain.Terrain;
+import com.jme3.terrain.geomipmap.TerrainLodControl;
+
+/**
+ *
+ * @author Brent Owens
+ */
+public class TerrainUtils {
+
+ /**
+ * Re-attach the camera to the LOD control.
+ * Called when the scene is opened and will only
+ * update the control if there is already a terrain present in
+ * the scene.
+ */
+ public static void enableLodControl(Camera camera, Node rootNode) {
+
+ Terrain terrain = (Terrain) findTerrain(rootNode);
+ if (terrain == null)
+ return;
+
+ TerrainLodControl control = ((Spatial)terrain).getControl(TerrainLodControl.class);
+ if (control != null) {
+ control.setCamera(camera);
+ }
+ }
+
+ protected static Node findTerrain(Spatial root) {
+
+ // is this the terrain?
+ if (root instanceof Terrain && root instanceof Node) {
+ return (Node)root;
+ }
+
+ if (root instanceof Node) {
+ Node n = (Node) root;
+ for (Spatial c : n.getChildren()) {
+ if (c instanceof Node){
+ Node res = findTerrain(c);
+ if (res != null)
+ return res;
+ }
+ }
+ }
+
+ return null;
+ }
+
+}
editorController.setToolController(toolController);
toolController.refreshNonSpatialMarkers();
+
+ editorController.setTerrainLodCamera();
}/* else {
SceneApplication.getApplication().removeSceneListener(this);
currentRequest = null;
public void previewRequested(PreviewRequest request) {
}
+
}
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
+import com.jme3.gde.core.util.TerrainUtils;
import com.jme3.light.Light;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
+import com.jme3.renderer.Camera;
import com.jme3.scene.AssetLinkNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
selectedSpat.removePropertyChangeListener(this);
}
}
+
+ /**
+ * Terrain has a LOD control that requires the camera to function.
+ */
+ protected void setTerrainLodCamera() {
+ Camera camera = SceneApplication.getApplication().getCamera();
+ Node root = jmeRootNode.getLookup().lookup(Node.class);
+ TerrainUtils.enableLodControl(camera, root);
+ }
+
}
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
+import com.jme3.gde.core.util.TerrainUtils;
import com.jme3.material.MatParam;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
protected final int MAX_TEXTURES = 16-NUM_ALPHA_TEXTURES; // 16 max (diffuse and normal), minus the ones we are reserving
-
- protected SaveCookie terrainSaveCookie = new SaveCookie() {
- public void save() throws IOException {
- //TODO: On OpenGL thread? -- safest way.. with get()?
+ class TerrainSaveCookie implements SaveCookie {
+ JmeSpatial rootNode;
+
+ public void save() throws IOException {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
currentFileObject.saveAsset();
- doSaveAlphaImages((Terrain)getTerrain(null));
+ //TerrainSaveCookie sc = currentFileObject.getCookie(TerrainSaveCookie.class);
+ //if (sc != null) {
+ Node root = rootNode.getLookup().lookup(Node.class);
+ doSaveAlphaImages((Terrain)getTerrain(root));
+ //}
return null;
}
});
}
- };
+ }
+ protected TerrainSaveCookie terrainSaveCookie = new TerrainSaveCookie();
public TerrainEditorController(JmeSpatial jmeRootNode, AssetDataObject currentFileObject, TerrainEditorTopComponent topComponent) {
this.jmeRootNode = jmeRootNode;
rootNode = this.jmeRootNode.getLookup().lookup(Node.class);
this.currentFileObject = currentFileObject;
+ terrainSaveCookie.rootNode = jmeRootNode;
this.currentFileObject.setSaveCookie(terrainSaveCookie);
this.topComponent = topComponent;
}
*/
private synchronized void doSaveAlphaImages(Terrain terrain) {
+ if (terrain == null) {
+ getTerrain(rootNode);
+ return;
+ }
+
AssetManager manager = SceneApplication.getApplication().getAssetManager();
String assetFolder = null;
if (manager != null && manager instanceof ProjectAssetManager)
* update the control if there is already a terrain present in
* the scene.
*/
- protected void enableLodControl() {
- Terrain terrain = (Terrain) getTerrain(null);
- if (terrain == null)
- return;
-
- TerrainQuad t = (TerrainQuad)terrain;
- TerrainLodControl control = t.getControl(TerrainLodControl.class);
- if (control != null) {
- control.setCamera(SceneApplication.getApplication().getCamera());
- }
+ protected void setTerrainLodCamera() {
+ Camera camera = SceneApplication.getApplication().getCamera();
+ Node root = jmeRootNode.getLookup().lookup(Node.class);
+ TerrainUtils.enableLodControl(camera, root);
}
terrainDeletedNodeListener = new TerrainNodeListener();
editorController.enableTextureButtons();
- editorController.enableLodControl();
}
// run on GL thread
toolController.setHeightToolRadius((float) radiusSlider.getValue() / (float) radiusSlider.getMaximum());
toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum());
+ editorController.setTerrainLodCamera();
+
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
}
}
});
- //editorController.getAlphaSaveDataObject(this);
}
}
.put(float2byte(color.b))
.put(float2byte(color.a));
return;
+ case ABGR8:
+ buf.position( position );
+ buf.put(float2byte(color.a))
+ .put(float2byte(color.b))
+ .put(float2byte(color.g))
+ .put(float2byte(color.r));
+ return;
default:
throw new UnsupportedOperationException("Image format: "+image.getFormat());
}
buf.position( position );
color.set(byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()), byte2float(buf.get()));
return;
+ case ABGR8:
+ buf.position( position );
+ float a = byte2float(buf.get());
+ float b = byte2float(buf.get());
+ float g = byte2float(buf.get());
+ float r = byte2float(buf.get());
+ color.set(r,g,b,a);
+ return;
default:
throw new UnsupportedOperationException("Image format: "+image.getFormat());
}