com.jme3.scene.control.Control Java Examples
The following examples show how to use
com.jme3.scene.control.Control.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCreateControlAction.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread protected void process() { super.process(); if (isRequiredDialog()) { return; } final TreeNode<?> treeNode = getNode(); final Spatial parent = (Spatial) treeNode.getElement(); final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree(); final Control control = createControl(parent); final ModelChangeConsumer consumer = notNull(nodeTree.getChangeConsumer()); consumer.execute(new AddControlOperation(control, parent)); }
Example #2
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #3
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Removes the given control from this spatial's controls. * * @param control The control to remove * @return True if the control was successfully 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 before = requiresUpdates(); boolean result = controls.remove(control); if (result) { control.setSpatial(null); } 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(); } return result; }
Example #4
Source File: TestGltfLoading.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private <T extends Control> T findControl(Spatial s, Class<T> controlClass) { T ctrl = s.getControl(controlClass); if (ctrl != null) { return ctrl; } if (s instanceof Node) { Node n = (Node) s; for (Spatial spatial : n.getChildren()) { ctrl = findControl(spatial, controlClass); if (ctrl != null) { return ctrl; } } } return null; }
Example #5
Source File: JmeGenericControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override protected Sheet createSheet() { //TODO: multithreading.. Sheet sheet = Sheet.createDefault(); Sheet.Set set = Sheet.createPropertiesSet(); set.setDisplayName("Control"); set.setName(Control.class.getName()); if (control == null) { return sheet; } createFields(control.getClass(), set, control); sheet.put(set); return sheet; }
Example #6
Source File: AnimControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Internal use only. */ public Control cloneForSpatial(Spatial spatial) { try { AnimControl clone = (AnimControl) super.clone(); clone.spatial = spatial; clone.channels = new ArrayList<AnimChannel>(); clone.listeners = new ArrayList<AnimEventListener>(); if (skeleton != null) { clone.skeleton = new Skeleton(skeleton); } // animationMap is cloned, but only ClonableTracks will be cloned as they need a reference to a cloned spatial for (Entry<String, Animation> animEntry : animationMap.entrySet()) { clone.animationMap.put(animEntry.getKey(), animEntry.getValue().cloneForSpatial(spatial)); } return clone; } catch (CloneNotSupportedException ex) { throw new AssertionError(); } }
Example #7
Source File: MotionTrack.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Clone this control for the given spatial * @param spatial * @return */ public Control cloneForSpatial(Spatial spatial) { MotionTrack control = new MotionTrack(spatial, path); control.playState = playState; control.currentWayPoint = currentWayPoint; control.currentValue = currentValue; control.direction = direction.clone(); control.lookAt = lookAt.clone(); control.upVector = upVector.clone(); control.rotation = rotation.clone(); control.initialDuration = initialDuration; control.speed = speed; control.loopMode = loopMode; control.directionType = directionType; return control; }
Example #8
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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(); } }
Example #9
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Removes the given control from this spatial's controls. * * @param control The control to remove * @return True if the control was successfully 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 before = requiresUpdates(); boolean result = controls.remove(control); if (result) { control.setSpatial(null); } 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(); } return result; }
Example #10
Source File: SpatialTreeNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @FxThread public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) { final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class); final Spatial element = getElement(); final LightList lightList = element.getLocalLightList(); lightList.forEach(light -> { if (!(light instanceof InvisibleObject)) { result.add(FACTORY_REGISTRY.createFor(light)); } }); final int numControls = element.getNumControls(); for (int i = 0; i < numControls; i++) { final Control control = element.getControl(i); result.add(FACTORY_REGISTRY.createFor(control)); } return result; }
Example #11
Source File: CharacterControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Control cloneForSpatial(Spatial spatial) { CharacterControl control = new CharacterControl(collisionShape, stepHeight); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setFallSpeed(getFallSpeed()); control.setGravity(getGravity()); control.setJumpSpeed(getJumpSpeed()); control.setMaxSlope(getMaxSlope()); control.setPhysicsLocation(getPhysicsLocation()); control.setUpAxis(getUpAxis()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
Example #12
Source File: RemoveElementsOperation.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread protected void undoImpl(@NotNull final ModelChangeConsumer editor) { EXECUTOR_MANAGER.addJmeTask(() -> { for (final Element element : elements) { final Object toRestore = element.getElement(); if (toRestore instanceof Spatial) { restoreSpatial(element, (Spatial) toRestore); } else if (toRestore instanceof Light) { restoreLight(element, (Light) toRestore); } else if (toRestore instanceof Animation) { restoreAnimation(element, (Animation) toRestore); } else if (toRestore instanceof Control) { restoreControl(element, (Control) toRestore); } } EXECUTOR_MANAGER.addFxTask(() -> { elements.forEach(editor, (element, consumer) -> consumer.notifyFxAddedChild(element.getParent(), element.getElement(), element.getIndex(), false)); }); }); }
Example #13
Source File: RemoveElementsOperation.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread protected void redoImpl(@NotNull final ModelChangeConsumer editor) { EXECUTOR_MANAGER.addJmeTask(() -> { for (final Element element : elements) { final Object toRemove = element.getElement(); if (toRemove instanceof Spatial) { removeSpatial(element, (Spatial) toRemove); } else if (toRemove instanceof Light) { removeLight(element, (Light) toRemove); } else if (toRemove instanceof Animation) { removeAnimation(element, (Animation) toRemove); } else if (toRemove instanceof Control) { removeControl(element, (Control) toRemove); } } EXECUTOR_MANAGER.addFxTask(() -> { elements.forEach(editor, (element, consumer) -> consumer.notifyFxRemovedChild(element.getParent(), element.getElement())); }); }); }
Example #14
Source File: CharacterControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Control cloneForSpatial(Spatial spatial) { CharacterControl control = new CharacterControl(collisionShape, stepHeight); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setFallSpeed(getFallSpeed()); control.setGravity(getGravity()); control.setJumpSpeed(getJumpSpeed()); control.setMaxSlope(getMaxSlope()); control.setPhysicsLocation(getPhysicsLocation()); control.setUpAxis(getUpAxis()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
Example #15
Source File: FocusManagerState.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static FocusTarget findFocusTarget( Spatial s ) { if( s == null ) return null; for( int i = 0; i < s.getNumControls(); i++ ) { Control c = s.getControl(i); if( c instanceof FocusTarget ) return (FocusTarget)c; } return null; }
Example #16
Source File: RagUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Find the index of the specified scene-graph control in the specified * spatial. * * @param spatial the spatial to search (not null, unaffected) * @param sgc the control to search for (not null, unaffected) * @return the index (≥0) or -1 if not found */ static int findIndex(Spatial spatial, Control sgc) { int numControls = spatial.getNumControls(); int result = -1; for (int controlIndex = 0; controlIndex < numControls; ++controlIndex) { Control control = spatial.getControl(controlIndex); if (control == sgc) { result = controlIndex; break; } } return result; }
Example #17
Source File: ControlUtils.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Change the enabled status of the control. * * @param control the control. * @param enabled true if the control should be enabled. */ @FromAnyThread public static void setEnabled(@NotNull Control control, boolean enabled) { if (control instanceof AbstractControl) { ((AbstractControl) control).setEnabled(enabled); } else if (control instanceof PhysicsControl) { ((PhysicsControl) control).setEnabled(enabled); } }
Example #18
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void runControlUpdate(float tpf) { if (controls.isEmpty()) { return; } for (Control c : controls.getArray()) { c.update(tpf); } }
Example #19
Source File: SceneEditorController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void addControlUndo(final Node undoParent, final Control undoControl, final AbstractSceneExplorerNode parentNode) { if (undoParent != null && undoControl != null) { Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, new AbstractUndoableSceneEdit() { @Override public void sceneUndo() throws CannotUndoException { //undo stuff here undoParent.removeControl(undoControl); } @Override public void sceneRedo() throws CannotRedoException { //redo stuff here undoParent.addControl(undoControl); } @Override public void awtRedo() { if (parentNode != null) { parentNode.refresh(true); } } @Override public void awtUndo() { if (parentNode != null) { parentNode.refresh(true); } } }); } }
Example #20
Source File: RigidBodyControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Control cloneForSpatial(Spatial spatial) { RigidBodyControl control = new RigidBodyControl(collisionShape, mass); control.setAngularFactor(getAngularFactor()); control.setAngularSleepingThreshold(getAngularSleepingThreshold()); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setDamping(getLinearDamping(), getAngularDamping()); control.setFriction(getFriction()); control.setGravity(getGravity()); control.setKinematic(isKinematic()); control.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution()); if (mass > 0) { control.setAngularVelocity(getAngularVelocity()); control.setLinearVelocity(getLinearVelocity()); } control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
Example #21
Source File: Spatial.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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); } } }
Example #22
Source File: RigidBodyControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Control cloneForSpatial(Spatial spatial) { RigidBodyControl control = new RigidBodyControl(collisionShape, mass); control.setAngularFactor(getAngularFactor()); control.setAngularSleepingThreshold(getAngularSleepingThreshold()); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setDamping(getLinearDamping(), getAngularDamping()); control.setFriction(getFriction()); control.setGravity(getGravity()); control.setKinematic(isKinematic()); control.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution()); if (mass > 0) { control.setAngularVelocity(getAngularVelocity()); control.setLinearVelocity(getLinearVelocity()); } control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }
Example #23
Source File: Spatial.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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) */ @SuppressWarnings("unchecked") public <T extends Control> T getControl(Class<T> controlType) { for (Control c : controls.getArray()) { if (controlType.isAssignableFrom(c.getClass())) { return (T) c; } } return null; }
Example #24
Source File: ChaseCamera.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * clone this camera for a spatial * @param spatial * @return */ public Control cloneForSpatial(Spatial spatial) { ChaseCamera cc = new ChaseCamera(cam, spatial, inputManager); cc.setMaxDistance(getMaxDistance()); cc.setMinDistance(getMinDistance()); return cc; }
Example #25
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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) { boolean before = requiresUpdates(); controls.add(control); control.setSpatial(this); 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(); } }
Example #26
Source File: DisableAllControlsAction.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void process() { final Array<Control> controls = NodeUtils.children((Spatial) getNode().getElement()) .flatMap(ControlUtils::controls) .filter(ControlUtils::isEnabled) .collect(toArray(Control.class)); final ModelChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new DisableControlsOperation(controls)); }
Example #27
Source File: EnableAllControlsAction.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
@Override @FxThread protected void process() { final Array<Control> controls = NodeUtils.children((Spatial) getNode().getElement()) .flatMap(ControlUtils::controls) .filter(control -> !ControlUtils.isEnabled(control)) .collect(toArray(Control.class)); final ModelChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); changeConsumer.execute(new EnableControlsOperation(controls)); }
Example #28
Source File: Spatial.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
private void runControlUpdate(float tpf) { if (controls.isEmpty()) { return; } for (Control c : controls.getArray()) { c.update(tpf); } }
Example #29
Source File: ControlUtils.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Check enabled status of the control. * * @param control the control. * @return true if this control is enabled. */ @FromAnyThread public static boolean isEnabled(@NotNull Control control) { if (control instanceof AbstractControl) { return ((AbstractControl) control).isEnabled(); } else if (control instanceof PhysicsControl) { return ((PhysicsControl) control).isEnabled(); } else { return true; } }
Example #30
Source File: GhostControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public Control cloneForSpatial(Spatial spatial) { GhostControl control = new GhostControl(collisionShape); control.setCcdMotionThreshold(getCcdMotionThreshold()); control.setCcdSweptSphereRadius(getCcdSweptSphereRadius()); control.setCollideWithGroups(getCollideWithGroups()); control.setCollisionGroup(getCollisionGroup()); control.setPhysicsLocation(getPhysicsLocation()); control.setPhysicsRotation(getPhysicsRotationMatrix()); control.setApplyPhysicsLocal(isApplyPhysicsLocal()); control.setSpatial(spatial); return control; }