/** * * <code>getChild</code> returns a child at a given index. * * @param i * the index to retrieve the child from. * @return the child at a specified index. */ public Spatial getChild(int i) { return children.get(i); }
/** * Returns the control at the given index in the list. * * @param index The index of the control in the list to find. * @return The control at the given index. * * @throws IndexOutOfBoundsException * If the index is outside the range [0, getNumControls()-1] * * @see Spatial#addControl(com.jme3.scene.control.Control) */ public Control getControl(int index) { return controls.get(index); }
@Override public void setMaterial(Material mat){ for (int i = 0; i < children.size(); i++){ children.get(i).setMaterial(mat); } }
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; }
/** * 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 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(); } } }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); ShadowUtil.updateFrustumPoints2(shadowCam, points); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); ShadowUtil.updateFrustumPoints2(shadowCam, points); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); }
/** * 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(); } } } }
@Override protected void doDisplayFrustumDebug(int shadowMapIndex) { Vector3f[] points2 = points.clone(); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points, shadowMapIndex)); ShadowUtil.updateFrustumPoints2(shadowCam, points2); ((Node) viewPort.getScenes().get(0)).attachChild(createFrustum(points2, shadowMapIndex)); }
/** * More efficient than e.g detaching and attaching as no updates are needed. * * @param index1 The index of the first child to swap * @param index2 The index of the second child to swap */ public void swapChildren(int index1, int index2) { Spatial c2 = children.get(index2); Spatial c1 = children.remove(index1); children.add(index1, c2); children.remove(index2); children.add(index2, c1); }
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())); } } } }
@Override protected void initialize(Application app) { debugNode = new Node("Environment debug Node"); Sphere s = new Sphere(16, 16, 0.15f); debugGeom = new Geometry("debugEnvProbe", s); debugMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/reflect.j3md"); debugGeom.setMaterial(debugMaterial); debugBounds = BoundingSphereDebug.createDebugSphere(app.getAssetManager()); if (scene == null) { scene = app.getViewPort().getScenes().get(0); } }
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); } } }
@Test public void testOverrides_SaveAndLoad_KeepsMPOs() { MatParamOverride override = mpoInt("val", 5); Node scene = createDummyScene(); scene.getChild("A").addMatParamOverride(override); AssetManager assetManager = TestUtil.createAssetManager(); Node loadedScene = BinaryExporter.saveAndLoad(assetManager, scene); Node root = new Node("Root Node"); root.attachChild(loadedScene); validateScene(root); validateScene(scene); assertNotSame(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); assertEquals(override, loadedScene.getChild("A").getLocalMatParamOverrides().get(0)); }