* fixed error in terrain paint action with changes to png format
* scene explorer and composer will enable terrain lod control by adding camera in git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8253 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
8deba71f8d
commit
bb4a1d7961
@ -37,6 +37,8 @@ import com.jme3.gde.core.scene.SceneListener;
|
||||
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;
|
||||
@ -281,6 +283,7 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
|
||||
}
|
||||
});
|
||||
}
|
||||
setTerrainLodCamera(node);
|
||||
}
|
||||
|
||||
public boolean sceneClose(SceneRequest request) {
|
||||
@ -376,4 +379,13 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
55
sdk/jme3-core/src/com/jme3/gde/core/util/TerrainUtils.java
Normal file
55
sdk/jme3-core/src/com/jme3/gde/core/util/TerrainUtils.java
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -897,6 +897,8 @@ private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
|
||||
|
||||
editorController.setToolController(toolController);
|
||||
toolController.refreshNonSpatialMarkers();
|
||||
|
||||
editorController.setTerrainLodCamera();
|
||||
}/* else {
|
||||
SceneApplication.getApplication().removeSceneListener(this);
|
||||
currentRequest = null;
|
||||
@ -926,5 +928,6 @@ private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
|
||||
|
||||
public void previewRequested(PreviewRequest request) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,9 +17,11 @@ import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
||||
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;
|
||||
@ -781,4 +783,14 @@ public class SceneEditorController implements PropertyChangeListener, NodeListen
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
||||
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;
|
||||
@ -93,26 +94,32 @@ public class TerrainEditorController {
|
||||
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;
|
||||
}
|
||||
@ -751,6 +758,11 @@ public class TerrainEditorController {
|
||||
*/
|
||||
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)
|
||||
@ -1054,16 +1066,10 @@ public class TerrainEditorController {
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1013,7 +1013,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
|
||||
terrainDeletedNodeListener = new TerrainNodeListener();
|
||||
editorController.enableTextureButtons();
|
||||
|
||||
editorController.enableLodControl();
|
||||
}
|
||||
|
||||
// run on GL thread
|
||||
@ -1063,6 +1062,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
|
||||
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() {
|
||||
@ -1072,7 +1073,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
|
||||
}
|
||||
}
|
||||
});
|
||||
//editorController.getAlphaSaveDataObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,6 +246,13 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
|
||||
.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());
|
||||
}
|
||||
@ -255,6 +262,14 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
|
||||
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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user