fixed terrain scaling in navmesh generator

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9091 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent 2ff329f9de
commit 1625841c47
  1. 4
      sdk/jme3-navmesh-gen/src/com/jme3/gde/nmgen/NavMeshGenerator.java
  2. 25
      sdk/jme3-navmesh-gen/src/com/jme3/gde/nmgen/wizard/NewNavMeshWizardAction.java

@ -153,8 +153,8 @@ public class NavMeshGenerator implements Savable {
Vector3f trans = ((Node) terr).getWorldTranslation().clone(); Vector3f trans = ((Node) terr).getWorldTranslation().clone();
trans.x -= terr.getTerrainSize() / 2f; trans.x -= terr.getTerrainSize() / 2f;
trans.z -= terr.getTerrainSize() / 2f; trans.z -= terr.getTerrainSize() / 2f;
float offsetX = trans.x * scale.x; float offsetX = trans.x;// * scale.x;
float offsetZ = trans.z * scale.z; float offsetZ = trans.z;// * scale.z;
// do vertices // do vertices
int i = 0; int i = 0;

@ -10,6 +10,7 @@ import com.jme3.gde.core.sceneexplorer.nodes.actions.NewSpatialAction;
import com.jme3.gde.nmgen.NavMeshGenerator; import com.jme3.gde.nmgen.NavMeshGenerator;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -77,7 +78,7 @@ public final class NewNavMeshWizardAction extends AbstractNewSpatialWizardAction
Mesh mesh = new Mesh(); Mesh mesh = new Mesh();
GeometryBatchFactory.mergeGeometries(findGeometries(rootNode, new LinkedList<Geometry>(), generator), mesh); GeometryBatchFactory.mergeGeometries(findGeometries(rootNode, new LinkedList<Geometry>(), generator, rootNode), mesh);
Mesh optiMesh = generator.optimize(mesh); Mesh optiMesh = generator.optimize(mesh);
if(optiMesh == null) return null; if(optiMesh == null) return null;
@ -95,20 +96,24 @@ public final class NewNavMeshWizardAction extends AbstractNewSpatialWizardAction
return navMesh; return navMesh;
} }
private List<Geometry> findGeometries(Node node, List<Geometry> geoms, NavMeshGenerator generator) { private List<Geometry> findGeometries(Node node, List<Geometry> geoms, NavMeshGenerator generator, Node originalRoot) {
if (node instanceof Terrain) {
Terrain terr = (Terrain)node;
Mesh merged = generator.terrain2mesh(terr);
Geometry g = new Geometry("mergedTerrain");
g.setMesh(merged);
if (node != originalRoot)
g.setLocalScale(((Node)terr).getLocalScale());
geoms.add(g);
return geoms;
}
for (Iterator<Spatial> it = node.getChildren().iterator(); it.hasNext();) { for (Iterator<Spatial> it = node.getChildren().iterator(); it.hasNext();) {
Spatial spatial = it.next(); Spatial spatial = it.next();
if (spatial instanceof Geometry) { if (spatial instanceof Geometry) {
geoms.add((Geometry) spatial); geoms.add((Geometry) spatial);
} else if (spatial instanceof Node) { } else if (spatial instanceof Node) {
if (spatial instanceof Terrain) { findGeometries((Node) spatial, geoms, generator, originalRoot);
Mesh merged = generator.terrain2mesh((Terrain) spatial);
Geometry g = new Geometry("mergedTerrain");
g.setMesh(merged);
geoms.add(g);
} else {
findGeometries((Node) spatial, geoms, generator);
}
} }
} }
return geoms; return geoms;

Loading…
Cancel
Save