/** * 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) { for (int i = 0; i < controls.size(); i++) { if (controlType.isAssignableFrom(controls.get(i).getClass())) { Control control = controls.remove(i); control.setSpatial(null); } } }
/** * Returns the first control that is an instance of the given class, or null if no such control * exists. * * @param controlType The superclass of the control to look for. * @return The first instance in the list of the controlType class, or null. * @see Spatial#addControl(com.jme3.scene.control.Control) */ public <T extends Control> T getControl(Class<T> controlType) { for (Control c : controls.getArray()) { if (controlType.isAssignableFrom(c.getClass())) { return (T) c; } } return null; }
/** * Called when the Spatial is about to be rendered, to notify controls attached to this Spatial * using the Control.render() method. * * @param rm The RenderManager rendering the Spatial. * @param vp The ViewPort to which the Spatial is being rendered to. * @see Spatial#addControl(com.jme3.scene.control.Control) * @see Spatial#getControl(java.lang.Class) */ public void runControlRender(RenderManager rm, ViewPort vp) { if (controls.isEmpty()) { return; } for (Control c : controls.getArray()) { c.render(rm, vp); } }
private void runControlUpdate(float tpf) { if (controls.isEmpty()) { return; } for (Control c : controls.getArray()) { c.update(tpf); } }
/** * @return A clone of this Spatial, the scene graph in its entirety is cloned and can be altered * independently of the original scene graph. * <p>Note that meshes of geometries are not cloned explicitly, they are shared if static, or * specially cloned if animated. * <p>All controls will be cloned using the Control.cloneForSpatial method on the clone. * @see Mesh#cloneForAnim() */ public Spatial clone(boolean cloneMaterial) { try { Spatial clone = (Spatial) super.clone(); if (worldBound != null) { clone.worldBound = worldBound.clone(); } clone.worldLights = worldLights.clone(); clone.localLights = localLights.clone(); // Set the new owner of the light lists clone.localLights.setOwner(clone); clone.worldLights.setOwner(clone); // No need to force cloned to update. // This node already has the refresh flags // set below so it will have to update anyway. clone.worldTransform = worldTransform.clone(); clone.localTransform = localTransform.clone(); if (clone instanceof Node) { Node node = (Node) this; Node nodeClone = (Node) clone; nodeClone.children = new SafeArrayList<Spatial>(Spatial.class); for (Spatial child : node.children) { Spatial childClone = child.clone(cloneMaterial); childClone.parent = nodeClone; nodeClone.children.add(childClone); } } clone.parent = null; clone.setBoundRefresh(); clone.setTransformRefresh(); clone.setLightListRefresh(); clone.controls = new SafeArrayList<Control>(Control.class); for (int i = 0; i < controls.size(); i++) { Control newControl = controls.get(i).cloneForSpatial(clone); newControl.setSpatial(clone); clone.controls.add(newControl); } if (userData != null) { clone.userData = (HashMap<String, Savable>) userData.clone(); } return clone; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } }
/** * Removes the given control from this spatial's controls. * * @param control The control to remove * @return True if the control was successfuly removed. False if the control is not assigned to * this spatial. * @see Spatial#addControl(com.jme3.scene.control.Control) */ public boolean removeControl(Control control) { boolean result = controls.remove(control); if (result) { control.setSpatial(null); } return result; }
/** * Add a control to the list of controls. * * @param control The control to add. * @see Spatial#removeControl(java.lang.Class) */ public void addControl(Control control) { controls.add(control); control.setSpatial(this); }