fixed add terrain bug, now they all use the same action
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8022 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
54b6974778
commit
9bd9e1dc08
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,11 @@
|
|||||||
build.xml.data.CRC32=52f8cb9e
|
build.xml.data.CRC32=52f8cb9e
|
||||||
build.xml.script.CRC32=34d4c2f2
|
build.xml.script.CRC32=34d4c2f2
|
||||||
build.xml.stylesheet.CRC32=958a1d3e
|
build.xml.stylesheet.CRC32=958a1d3e
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
nbproject/build-impl.xml.data.CRC32=8a1eda4b
|
nbproject/build-impl.xml.data.CRC32=8a1eda4b
|
||||||
nbproject/build-impl.xml.script.CRC32=047b53c9
|
nbproject/build-impl.xml.script.CRC32=fc0d2890
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=0c01fd8e@1.43.1.45
|
nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
|
||||||
nbproject/profiler-build-impl.xml.data.CRC32=aff514c1
|
nbproject/profiler-build-impl.xml.data.CRC32=aff514c1
|
||||||
nbproject/profiler-build-impl.xml.script.CRC32=abda56ed
|
nbproject/profiler-build-impl.xml.script.CRC32=abda56ed
|
||||||
nbproject/profiler-build-impl.xml.stylesheet.CRC32=f10cf54c@1.11.1
|
nbproject/profiler-build-impl.xml.stylesheet.CRC32=f10cf54c@1.11.1
|
||||||
|
@ -13,6 +13,7 @@ import com.jme3.gde.core.sceneexplorer.nodes.actions.NewSpatialAction;
|
|||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
|
import com.jme3.terrain.Terrain;
|
||||||
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
import com.jme3.terrain.geomipmap.TerrainLodControl;
|
||||||
import com.jme3.terrain.geomipmap.TerrainQuad;
|
import com.jme3.terrain.geomipmap.TerrainQuad;
|
||||||
import com.jme3.terrain.heightmap.AbstractHeightMap;
|
import com.jme3.terrain.heightmap.AbstractHeightMap;
|
||||||
@ -73,11 +74,11 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Spatial generateTerrain(Node parent, final WizardDescriptor wizardDescriptor) throws IOException {
|
protected Spatial generateTerrain(Node parent, final WizardDescriptor wizardDescriptor) throws IOException {
|
||||||
org.openide.nodes.Node selectedNode = (org.openide.nodes.Node) wizardDescriptor.getProperty("main_node");
|
org.openide.nodes.Node selectedNode = (org.openide.nodes.Node) wizardDescriptor.getProperty("main_node");
|
||||||
final Spatial spatial = selectedNode.getLookup().lookup(Spatial.class);
|
final Spatial spatial = selectedNode.getLookup().lookup(Spatial.class);
|
||||||
final ProjectAssetManager manager = selectedNode.getLookup().lookup(ProjectAssetManager.class);
|
|
||||||
|
|
||||||
String sceneName = selectedNode.getLookup().lookup(DataObject.class).getName();
|
String sceneName = selectedNode.getLookup().lookup(DataObject.class).getName();
|
||||||
|
|
||||||
@ -92,45 +93,51 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction {
|
|||||||
heightmapData = heightmap.getHeightMap();
|
heightmapData = heightmap.getHeightMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eg. Scenes/newScene1.j3o
|
return doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, selectedNode);
|
||||||
TerrainQuad terrain = null;
|
}
|
||||||
|
|
||||||
terrain = new TerrainQuad("terrain-" + sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
|
|
||||||
|
protected Spatial doCreateTerrain(Node parent,
|
||||||
|
int totalSize,
|
||||||
|
int patchSize,
|
||||||
|
int alphaTextureSize,
|
||||||
|
float[] heightmapData,
|
||||||
|
String sceneName,
|
||||||
|
org.openide.nodes.Node selectedNode) throws IOException
|
||||||
|
{
|
||||||
|
final ProjectAssetManager manager = selectedNode.getLookup().lookup(ProjectAssetManager.class);
|
||||||
|
|
||||||
|
Terrain terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
|
||||||
com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
|
com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
|
||||||
|
|
||||||
String assetFolder = "";
|
String assetFolder = "";
|
||||||
if (manager != null && manager instanceof ProjectAssetManager) {
|
if (manager != null && manager instanceof ProjectAssetManager)
|
||||||
assetFolder = ((ProjectAssetManager) manager).getAssetFolderName();
|
assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();
|
||||||
}
|
|
||||||
|
|
||||||
// write out 3 alpha blend images
|
// write out 3 alpha blend images
|
||||||
for (int i = 0; i < TerrainEditorController.NUM_ALPHA_TEXTURES; i++) {
|
for (int i=0; i<TerrainEditorController.NUM_ALPHA_TEXTURES; i++) {
|
||||||
BufferedImage alphaBlend = new BufferedImage(alphaTextureSize, alphaTextureSize, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage alphaBlend = new BufferedImage(alphaTextureSize, alphaTextureSize, BufferedImage.TYPE_INT_ARGB);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
// the first alpha level should be opaque so we see the first texture over the whole terrain
|
// the first alpha level should be opaque so we see the first texture over the whole terrain
|
||||||
for (int h = 0; h < alphaTextureSize; h++) {
|
for (int h=0; h<alphaTextureSize; h++)
|
||||||
for (int w = 0; w < alphaTextureSize; w++) {
|
for (int w=0; w<alphaTextureSize; w++)
|
||||||
alphaBlend.setRGB(w, h, 0x00FF0000);//argb
|
alphaBlend.setRGB(w, h, 0x00FF0000);//argb
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
File alphaFolder = new File(assetFolder + "/Textures/terrain-alpha/");
|
File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
|
||||||
if (!alphaFolder.exists()) {
|
if (!alphaFolder.exists())
|
||||||
alphaFolder.mkdir();
|
alphaFolder.mkdir();
|
||||||
}
|
String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+((Node)terrain).getName()+"-alphablend"+i+".png";
|
||||||
String alphaBlendFileName = "/Textures/terrain-alpha/" + sceneName + "-" + terrain.getName() + "-alphablend" + i + ".png";
|
File alphaImageFile = new File(assetFolder+alphaBlendFileName);
|
||||||
File alphaImageFile = new File(assetFolder + alphaBlendFileName);
|
|
||||||
ImageIO.write(alphaBlend, "png", alphaImageFile);
|
ImageIO.write(alphaBlend, "png", alphaImageFile);
|
||||||
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
|
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
|
||||||
if (i == 0) {
|
if (i == 0)
|
||||||
mat.setTexture("AlphaMap", tex);
|
mat.setTexture("AlphaMap", tex);
|
||||||
}
|
else if (i == 1)
|
||||||
/*else if (i == 1) // add these in when they are supported
|
mat.setTexture("AlphaMap_1", tex);
|
||||||
mat.setTexture("AlphaMap_1", tex);
|
|
||||||
else if (i == 2)
|
else if (i == 2)
|
||||||
mat.setTexture("AlphaMap_2", tex);*/
|
mat.setTexture("AlphaMap_2", tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// give the first layer default texture
|
// give the first layer default texture
|
||||||
Texture defaultTexture = manager.loadTexture(TerrainEditorController.DEFAULT_TERRAIN_TEXTURE);
|
Texture defaultTexture = manager.loadTexture(TerrainEditorController.DEFAULT_TERRAIN_TEXTURE);
|
||||||
defaultTexture.setWrap(WrapMode.Repeat);
|
defaultTexture.setWrap(WrapMode.Repeat);
|
||||||
@ -138,21 +145,22 @@ public class AddTerrainAction extends AbstractNewSpatialWizardAction {
|
|||||||
mat.setFloat("DiffuseMap_0_scale", TerrainEditorController.DEFAULT_TEXTURE_SCALE);
|
mat.setFloat("DiffuseMap_0_scale", TerrainEditorController.DEFAULT_TEXTURE_SCALE);
|
||||||
mat.setBoolean("WardIso", true);
|
mat.setBoolean("WardIso", true);
|
||||||
|
|
||||||
terrain.setMaterial(mat);
|
((Node)terrain).setMaterial(mat);
|
||||||
terrain.setModelBound(new BoundingBox());
|
((Node)terrain).setModelBound(new BoundingBox());
|
||||||
terrain.updateModelBound();
|
((Node)terrain).updateModelBound();
|
||||||
terrain.setLocalTranslation(0, 0, 0);
|
((Node)terrain).setLocalTranslation(0, 0, 0);
|
||||||
terrain.setLocalScale(1f, 1f, 1f);
|
((Node)terrain).setLocalScale(4f, 1f, 4f);
|
||||||
|
|
||||||
// add the lod control
|
// add the lod control
|
||||||
List<Camera> cameras = new ArrayList<Camera>();
|
TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
|
||||||
cameras.add(SceneApplication.getApplication().getCamera());
|
((Node)terrain).addControl(control);
|
||||||
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
|
|
||||||
//terrain.addControl(control); // removing this until we figure out a way to have it get the cameras when saved/loaded
|
|
||||||
|
|
||||||
return terrain;
|
parent.attachChild((Node)terrain);
|
||||||
//createTerrainButton.setEnabled(false); // only let the user add one terrain
|
|
||||||
|
|
||||||
|
//setNeedsSave(true);
|
||||||
|
//addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
|
||||||
|
|
||||||
|
return (Spatial)terrain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -629,7 +629,9 @@ public class TerrainEditorController {
|
|||||||
Terrain terrain =
|
Terrain terrain =
|
||||||
SceneApplication.getApplication().enqueue(new Callable<Terrain>() {
|
SceneApplication.getApplication().enqueue(new Callable<Terrain>() {
|
||||||
public Terrain call() throws Exception {
|
public Terrain call() throws Exception {
|
||||||
return doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeNodeParent);
|
//return doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeNodeParent);
|
||||||
|
AddTerrainAction a = new AddTerrainAction();
|
||||||
|
return (Terrain) a.doCreateTerrain(parent, totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, jmeRootNode);
|
||||||
}
|
}
|
||||||
}).get();
|
}).get();
|
||||||
return terrain;
|
return terrain;
|
||||||
@ -638,11 +640,11 @@ public class TerrainEditorController {
|
|||||||
} catch (ExecutionException ex) {
|
} catch (ExecutionException ex) {
|
||||||
Exceptions.printStackTrace(ex);
|
Exceptions.printStackTrace(ex);
|
||||||
}
|
}
|
||||||
//doCreateTerrain(totalSize, patchSize, alphaTextureSize, heightmapData, sceneName, defaultTextureScale);
|
|
||||||
return null; // if failed
|
return null; // if failed
|
||||||
}
|
}
|
||||||
|
|
||||||
private Terrain doCreateTerrain(Node parent,
|
/*private Terrain doCreateTerrain(Node parent,
|
||||||
int totalSize,
|
int totalSize,
|
||||||
int patchSize,
|
int patchSize,
|
||||||
int alphaTextureSize,
|
int alphaTextureSize,
|
||||||
@ -677,7 +679,7 @@ public class TerrainEditorController {
|
|||||||
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
|
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
mat.setTexture("AlphaMap", tex);
|
mat.setTexture("AlphaMap", tex);
|
||||||
else if (i == 1) // add these in when they are supported
|
else if (i == 1)
|
||||||
mat.setTexture("AlphaMap_1", tex);
|
mat.setTexture("AlphaMap_1", tex);
|
||||||
else if (i == 2)
|
else if (i == 2)
|
||||||
mat.setTexture("AlphaMap_2", tex);
|
mat.setTexture("AlphaMap_2", tex);
|
||||||
@ -707,7 +709,7 @@ public class TerrainEditorController {
|
|||||||
addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
|
addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
|
||||||
|
|
||||||
return terrain;
|
return terrain;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) {
|
private void addSpatialUndo(final Node undoParent, final Spatial undoSpatial, final AbstractSceneExplorerNode parentNode) {
|
||||||
//add undo
|
//add undo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user