use of com.jme3.terrain.geomipmap.TerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method setHeight.
protected void setHeight(List<LocationHeight> locations, boolean overrideHeight) {
if (children == null)
return;
List<LocationHeight> quadLH1 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH2 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH3 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH4 = new ArrayList<LocationHeight>();
Spatial quad1 = null;
Spatial quad2 = null;
Spatial quad3 = null;
Spatial quad4 = null;
// get the child quadrants
for (int i = children.size(); --i >= 0; ) {
Spatial spat = children.get(i);
int childQuadrant = 0;
if (spat instanceof TerrainQuad) {
childQuadrant = ((TerrainQuad) spat).getQuadrant();
} else if (spat instanceof TerrainPatch) {
childQuadrant = ((TerrainPatch) spat).getQuadrant();
}
if (childQuadrant == 1)
quad1 = spat;
else if (childQuadrant == 2)
quad2 = spat;
else if (childQuadrant == 3)
quad3 = spat;
else if (childQuadrant == 4)
quad4 = spat;
}
int split = (size + 1) >> 1;
// distribute each locationHeight into the quadrant it intersects
for (LocationHeight lh : locations) {
int quad = findQuadrant(lh.x, lh.z);
int col = lh.x;
int row = lh.z;
if ((quad & 1) != 0) {
quadLH1.add(lh);
}
if ((quad & 2) != 0) {
row = lh.z - split + 1;
quadLH2.add(new LocationHeight(lh.x, row, lh.h));
}
if ((quad & 4) != 0) {
col = lh.x - split + 1;
quadLH3.add(new LocationHeight(col, lh.z, lh.h));
}
if ((quad & 8) != 0) {
col = lh.x - split + 1;
row = lh.z - split + 1;
quadLH4.add(new LocationHeight(col, row, lh.h));
}
}
// send the locations to the children
if (!quadLH1.isEmpty()) {
if (quad1 instanceof TerrainQuad)
((TerrainQuad) quad1).setHeight(quadLH1, overrideHeight);
else if (quad1 instanceof TerrainPatch)
((TerrainPatch) quad1).setHeight(quadLH1, overrideHeight);
}
if (!quadLH2.isEmpty()) {
if (quad2 instanceof TerrainQuad)
((TerrainQuad) quad2).setHeight(quadLH2, overrideHeight);
else if (quad2 instanceof TerrainPatch)
((TerrainPatch) quad2).setHeight(quadLH2, overrideHeight);
}
if (!quadLH3.isEmpty()) {
if (quad3 instanceof TerrainQuad)
((TerrainQuad) quad3).setHeight(quadLH3, overrideHeight);
else if (quad3 instanceof TerrainPatch)
((TerrainPatch) quad3).setHeight(quadLH3, overrideHeight);
}
if (!quadLH4.isEmpty()) {
if (quad4 instanceof TerrainQuad)
((TerrainQuad) quad4).setHeight(quadLH4, overrideHeight);
else if (quad4 instanceof TerrainPatch)
((TerrainPatch) quad4).setHeight(quadLH4, overrideHeight);
}
}
use of com.jme3.terrain.geomipmap.TerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class DistanceLodCalculator method getCenterLocation.
protected Vector3f getCenterLocation(TerrainPatch terrainPatch) {
Vector3f loc = terrainPatch.getWorldTranslationCached();
loc.x += terrainPatch.getSize() * terrainPatch.getWorldScaleCached().x / 2;
loc.z += terrainPatch.getSize() * terrainPatch.getWorldScaleCached().z / 2;
return loc;
}
use of com.jme3.terrain.geomipmap.TerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class CollisionShapeFactory method createCompoundShape.
private static CompoundCollisionShape createCompoundShape(Node realRootNode, Node rootNode, CompoundCollisionShape shape, boolean meshAccurate, boolean dynamic) {
for (Spatial spatial : rootNode.getChildren()) {
if (spatial instanceof TerrainQuad) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
TerrainQuad terrain = (TerrainQuad) spatial;
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), trans.getScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
} else if (spatial instanceof Node) {
createCompoundShape(realRootNode, (Node) spatial, shape, meshAccurate, dynamic);
} else if (spatial instanceof TerrainPatch) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
TerrainPatch terrain = (TerrainPatch) spatial;
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(new HeightfieldCollisionShape(terrain.getHeightMap(), terrain.getLocalScale()), trans.getTranslation(), trans.getRotation().toRotationMatrix());
} else if (spatial instanceof Geometry) {
Boolean bool = spatial.getUserData(UserData.JME_PHYSICSIGNORE);
if (bool != null && bool.booleanValue()) {
// go to the next child in the loop
continue;
}
if (meshAccurate) {
CollisionShape childShape = dynamic ? createSingleDynamicMeshShape((Geometry) spatial, realRootNode) : createSingleMeshShape((Geometry) spatial, realRootNode);
if (childShape != null) {
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(childShape, trans.getTranslation(), trans.getRotation().toRotationMatrix());
}
} else {
Transform trans = getTransform(spatial, realRootNode);
shape.addChildShape(createSingleBoxShape(spatial, realRootNode), trans.getTranslation(), trans.getRotation().toRotationMatrix());
}
}
}
return shape;
}
use of com.jme3.terrain.geomipmap.TerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method getHeightmapHeight.
/**
* This will just get the heightmap value at the supplied point,
* not an interpolated (actual) height value.
*/
protected float getHeightmapHeight(int x, int z) {
int quad = findQuadrant(x, z);
int split = (size + 1) >> 1;
if (children != null) {
for (int i = children.size(); --i >= 0; ) {
Spatial spat = children.get(i);
int col = x;
int row = z;
boolean match = false;
// get the childs quadrant
int childQuadrant = 0;
if (spat instanceof TerrainQuad) {
childQuadrant = ((TerrainQuad) spat).getQuadrant();
} else if (spat instanceof TerrainPatch) {
childQuadrant = ((TerrainPatch) spat).getQuadrant();
}
if (childQuadrant == 1 && (quad & 1) != 0) {
match = true;
} else if (childQuadrant == 2 && (quad & 2) != 0) {
row = z - split + 1;
match = true;
} else if (childQuadrant == 3 && (quad & 4) != 0) {
col = x - split + 1;
match = true;
} else if (childQuadrant == 4 && (quad & 8) != 0) {
col = x - split + 1;
row = z - split + 1;
match = true;
}
if (match) {
if (spat instanceof TerrainQuad) {
return ((TerrainQuad) spat).getHeightmapHeight(col, row);
} else if (spat instanceof TerrainPatch) {
return ((TerrainPatch) spat).getHeightmapHeight(col, row);
}
}
}
}
return Float.NaN;
}
use of com.jme3.terrain.geomipmap.TerrainPatch in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method findPick.
/**
* Gather the terrain patches that intersect the given ray (toTest).
* This only tests the bounding boxes
* @param toTest
* @param results
*/
public void findPick(Ray toTest, List<TerrainPickData> results) {
if (getWorldBound() != null) {
if (getWorldBound().intersects(toTest)) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
if (children.get(i) instanceof TerrainPatch) {
TerrainPatch tp = (TerrainPatch) children.get(i);
tp.ensurePositiveVolumeBBox();
if (tp.getWorldBound().intersects(toTest)) {
CollisionResults cr = new CollisionResults();
toTest.collideWith(tp.getWorldBound(), cr);
if (cr != null && cr.getClosestCollision() != null) {
cr.getClosestCollision().getDistance();
results.add(new TerrainPickData(tp, cr.getClosestCollision()));
}
}
} else if (children.get(i) instanceof TerrainQuad) {
((TerrainQuad) children.get(i)).findPick(toTest, results);
}
}
}
}
}
Aggregations