/** * * <code>getQuantity</code> returns the number of children this node * maintains. * * @return the number of children this node maintains. */ public int getQuantity() { return children.size(); }
/** * @return The number of controls attached to this Spatial. * @see Spatial#addControl(com.jme3.scene.control.Control) * @see Spatial#removeControl(java.lang.Class) */ public int getNumControls() { return controls.size(); }
/** * Enumerate the target meshes of this control. * * @return a new array */ public Mesh[] getTargets() { Mesh[] result = new Mesh[targets.size()]; int i = 0; for (Geometry geometry : targets) { Mesh mesh = geometry.getMesh(); result[i] = mesh; i++; } return result; }
/** * Enumerate the target meshes of this control. * * @return a new array */ public Mesh[] getTargets() { Mesh[] result = new Mesh[targets.size()]; int i = 0; for (Geometry geometry : targets) { Mesh mesh = geometry.getMesh(); result[i] = mesh; i++; } return result; }
/** * <code>attachChild</code> attaches a child to this node. This node * becomes the child's parent. The current number of children maintained is * returned. * <br> * If the child already had a parent it is detached from that former parent. * * @param child * the child to attach to this node. * @return the number of children maintained by this node. * @throws IllegalArgumentException if child is null. */ public int attachChild(Spatial child) { return attachChildAt(child, children.size()); } /**
private List<Vector3f> cloneVectorList(SafeArrayList<Vector3f> locations) { final List<Vector3f> cloned = new ArrayList<>(locations.size()); for (final Vector3f location : locations.getArray()) { cloned.add(location.clone()); } return cloned; }
/** * * <code>detachAllChildren</code> removes all children attached to this * node. */ public void detachAllChildren() { // Note: this could be a bit more efficient if it delegated // to a private method that avoided setBoundRefresh(), etc. // for every child and instead did one in here at the end. for ( int i = children.size() - 1; i >= 0; i-- ) { detachChildAt(i); } logger.log(Level.FINE, "{0}: All children removed.", this.toString()); }
@Override public void setMaterial(Material mat){ for (int i = 0; i < children.size(); i++){ children.get(i).setMaterial(mat); } }
/** * Retrieve all Terrain Patches from all children and store them * in the 'holder' list * @param holder must not be null, will be populated when returns */ public void getAllTerrainPatches(List<TerrainPatch> holder) { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).getAllTerrainPatches(holder); } else if (child instanceof TerrainPatch) { holder.add((TerrainPatch)child); } } } }
protected TerrainPatch getPatch(int quad) { if (children != null) for (int x = children.size(); --x >= 0;) { Spatial child = children.get(x); if (child instanceof TerrainPatch) { TerrainPatch tb = (TerrainPatch) child; if (tb.getQuadrant() == quad) return tb; } } return null; }
protected TerrainQuad getQuad(int quad) { if (quad == 0) return this; if (children != null) for (int x = children.size(); --x >= 0;) { Spatial child = children.get(x); if (child instanceof TerrainQuad) { TerrainQuad tq = (TerrainQuad) child; if (tq.getQuadrant() == quad) return tq; } } return null; }
/** * <code>getVertexCount</code> returns the number of vertices contained * in all sub-branches of this node that contain geometry. * * @return the vertex count of this branch. */ @Override public int getVertexCount() { int count = 0; if(children != null) { for(int i = 0; i < children.size(); i++) { count += children.get(i).getVertexCount(); } } return count; }
/** * <code>getTriangleCount</code> returns the number of triangles contained * in all sub-branches of this node that contain geometry. * * @return the triangle count of this branch. */ @Override public int getTriangleCount() { int count = 0; if(children != null) { for(int i = 0; i < children.size(); i++) { count += children.get(i).getTriangleCount(); } } return count; } /**
protected synchronized void reIndexPages(HashMap<String,UpdatedTerrainPatch> updated, boolean usesVariableLod) { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).reIndexPages(updated, usesVariableLod); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).reIndexGeometry(updated, usesVariableLod); } } } }
public Material getMaterial(Vector3f worldLocation) { // get the material from one of the children. They all share the same material if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { return ((TerrainQuad)child).getMaterial(worldLocation); } else if (child instanceof TerrainPatch) { return ((TerrainPatch)child).getMaterial(); } } } return null; }
/** * Caches the transforms (except rotation) so the LOD calculator, * which runs on a separate thread, can access them safely. */ protected void cacheTerrainTransforms() { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).cacheTerrainTransforms(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).cacheTerrainTransforms(); } } }
/** * Removes any cached references this terrain is holding, in particular * the TerrainPatch's neighbour references. * This is called automatically when the root terrainQuad is detached from * its parent or if setParent(null) is called. */ public void clearCaches() { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).clearCaches(); } else if (child instanceof TerrainPatch) { ((TerrainPatch) child).clearCaches(); } } } }
protected boolean calculateLod(List<Vector3f> location, HashMap<String,UpdatedTerrainPatch> updates, LodCalculator lodCalculator) { boolean lodChanged = false; if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { boolean b = ((TerrainQuad) child).calculateLod(location, updates, lodCalculator); if (b) lodChanged = true; } else if (child instanceof TerrainPatch) { boolean b = lodCalculator.calculateLod((TerrainPatch) child, location, updates); if (b) lodChanged = true; } } } return lodChanged; }
public void getAllTerrainPatchesWithTranslation(Map<TerrainPatch,Vector3f> holder, Vector3f translation) { if (children != null) { for (int i = children.size(); --i >= 0;) { Spatial child = children.get(i); if (child instanceof TerrainQuad) { ((TerrainQuad) child).getAllTerrainPatchesWithTranslation(holder, translation.clone().add(child.getLocalTranslation())); } else if (child instanceof TerrainPatch) { //if (holder.size() < 4) holder.put((TerrainPatch)child, translation.clone().add(child.getLocalTranslation())); } } } }
public void generateDebugTangents(Material mat) { for (int x = children.size(); --x >= 0;) { Spatial child = children.get(x); if (child instanceof TerrainQuad) { ((TerrainQuad)child).generateDebugTangents(mat); } else if (child instanceof TerrainPatch) { Geometry debug = new Geometry( "Debug " + name, TangentBinormalGenerator.genTbnLines( ((TerrainPatch)child).getMesh(), 0.8f)); attachChild(debug); debug.setLocalTranslation(child.getLocalTranslation()); debug.setCullHint(CullHint.Never); debug.setMaterial(mat); } } }