protected AppState[] getInitializing() { synchronized (states){ return initializing.getArray(); } }
/** * 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); }
protected void updateMatParamOverrides() { refreshFlags &= ~RF_MATPARAM_OVERRIDE; worldOverrides.clear(); if (parent == null) { worldOverrides.addAll(localOverrides); } else { assert (parent.refreshFlags & RF_MATPARAM_OVERRIDE) == 0; worldOverrides.addAll(parent.worldOverrides); worldOverrides.addAll(localOverrides); } }
public void addMorphTarget(MorphTarget target) { if (morphTargets == null) { morphTargets = new SafeArrayList<>(MorphTarget.class); } morphTargets.add(target); }
@Override public Node clone(boolean cloneMaterials) { BatchNode clone = (BatchNode) super.clone(cloneMaterials); if (batches.size() > 0) { for (Batch b : batches) { for (int i = 0; i < clone.children.size(); i++) { if (clone.children.get(i).getName().equals(b.geometry.getName())) { clone.children.remove(i); break; } } } clone.needsFullRebatch = true; clone.batches = new SafeArrayList<Batch>(Batch.class); clone.batchesByGeom = new HashMap<Geometry, Batch>(); clone.batch(); } return clone; }
@Override protected void updateLOD(SafeArrayList<Vector3f> locations, LodCalculator lodCalculator) { TerrainGrid terrainGrid = (TerrainGrid)getSpatial(); // for now, only the first camera is handled. // to accept more, there are two ways: // 1: every camera has an associated grid, then the location is not enough to identify which camera location has changed // 2: grids are associated with locations, and no incremental update is done, we load new grids for new locations, and unload those that are not needed anymore Vector3f cam = locations.isEmpty() ? Vector3f.ZERO.clone() : locations.get(0); Vector3f camCell = terrainGrid.getCamCell(cam); // get the grid index value of where the camera is (ie. 2,1) if (terrainGrid.cellsLoaded > 1) { // Check if cells are updated before updating gridoffset. terrainGrid.gridOffset[0] = Math.round(camCell.x * (terrainGrid.size / 2)); terrainGrid.gridOffset[1] = Math.round(camCell.z * (terrainGrid.size / 2)); terrainGrid.cellsLoaded = 0; } if (camCell.x != terrainGrid.currentCamCell.x || camCell.z != terrainGrid.currentCamCell.z || !terrainGrid.runOnce) { // if the camera has moved into a new cell, load new terrain into the visible 4 center quads terrainGrid.updateChildren(camCell); for (TerrainGridListener l : terrainGrid.listeners) { l.gridMoved(camCell); } } terrainGrid.runOnce = true; super.updateLOD(locations, lodCalculator); } }
@Override protected void prepareTerrain() { if (!addedTerrains.isEmpty()) { for (TerrainQuad t : addedTerrains) { if (!terrains.contains(t)) { terrains.add(t); } } addedTerrains.clear(); } if (!removedTerrains.isEmpty()) { terrains.removeAll(removedTerrains); removedTerrains.clear(); } for (TerrainQuad terrain : terrains.getArray()) { // cache the terrain's world transforms so they can be accessed on the separate thread safely terrain.cacheTerrainTransforms(); } }
/** * * <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); }
/** * Removes the first control that is an instance of the given class. * * @see Spatial#addControl(com.jme3.scene.control.Control) */ public void removeControl(Class<? extends Control> controlType) { boolean before = requiresUpdates(); for (int i = 0; i < controls.size(); i++) { if (controlType.isAssignableFrom(controls.get(i).getClass())) { Control control = controls.remove(i); control.setSpatial(null); break; // added to match the javadoc -pspeed } } boolean after = requiresUpdates(); // If the requirement to be updated has changed // then we need to let the parent node know so it // can rebuild its update list. if( parent != null && before != after ) { parent.invalidateUpdateList(); } }
@Override public void read(JmeImporter e) throws IOException { // XXX: Load children before loading itself!! // This prevents empty children list if controls query // it in Control.setSpatial(). children = new SafeArrayList( Spatial.class, e.getCapsule(this).readSavableArrayList("children", null) ); // go through children and set parent to this node if (children != null) { for (Spatial child : children.getArray()) { child.parent = this; } } super.read(e); }
/** * Detaches the state from the AppStateManager. * * @param state The state to detach * @return True if the state was detached successfully, false * if the state was not attached in the first place. */ public boolean detach(AppState state){ synchronized (states){ if (states.contains(state)){ state.stateDetached(this); states.remove(state); terminating.add(state); return true; } else if(initializing.contains(state)){ state.stateDetached(this); initializing.remove(state); return true; }else{ return false; } } }
/** * determines if the provided Spatial is contained in the children list of * this node. * * @param spat * the child object to look for. * @return true if the object is contained, false otherwise. */ public boolean hasChild(Spatial spat) { if (children.contains(spat)) return true; for (Spatial child : children.getArray()) { if (child instanceof Node && ((Node) child).hasChild(spat)) return true; } return false; }
/** * Set the {@link Track}s to be used by this animation. * * @param tracksArray The tracks to set. */ public void setTracks(Track[] tracksArray) { for (Track track : tracksArray) { tracks.add(track); } }
/** * Completely rebuilds the component stack from the index, layer ordering, * and top list. This should be called whenever changes are made to these * data structures that cannot be reconciled with surgical changes to the * components list. */ protected void rebuildStack() { components.clear(); for( String s : layerOrder ) { GuiComponent layer = index.get(s); if( layer != null ) { components.add(layer); } } // Add the top components components.addAll(topList); }