Java Code Examples for com.jme3.scene.Node#detachChild()

The following examples show how to use com.jme3.scene.Node#detachChild() . 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: AdvancedAbstractEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
public void cleanup() {
    super.cleanup();

    final RenderFilterExtension filterExtension = RenderFilterExtension.getInstance();
    filterExtension.disableFilters();

    final Node rootNode = EditorUtil.getGlobalRootNode();
    rootNode.detachChild(getStateNode());

    final EditorCamera editorCamera = getEditorCamera();
    final InputManager inputManager = EditorUtil.getInputManager();
    inputManager.removeListener(actionListener);
    inputManager.removeListener(analogListener);

    if (editorCamera != null) {
        editorCamera.setEnabled(false);
        editorCamera.unregisterInput(inputManager);
    }
}
 
Example 2
Source File: SceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process to change light showing.
 */
@JmeThread
private void updateLightShowedImpl(final boolean showed) {

    if (showed == isLightShowed()) {
        return;
    }

    final Node lightNode = getLightNode();
    final Node modelNode = getModelNode();

    if (showed) {
        modelNode.attachChild(lightNode);
    } else {
        modelNode.detachChild(lightNode);
    }

    setLightShowed(showed);
}
 
Example 3
Source File: SceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process to change audio showing.
 */
@JmeThread
private void updateAudioShowedImpl(final boolean showed) {

    if (showed == isAudioShowed()) {
        return;
    }

    final Node audioNode = getAudioNode();
    final Node modelNode = getModelNode();

    if (showed) {
        modelNode.attachChild(audioNode);
    } else {
        modelNode.detachChild(audioNode);
    }

    setAudioShowed(showed);
}
 
Example 4
Source File: ModelEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process of changing the fast sky.
 */
@JmeThread
private void changeFastSkyImpl(@Nullable final Spatial fastSky) {

    final Node stateNode = getStateNode();
    final Spatial currentFastSky = getCurrentFastSky();

    if (currentFastSky != null) {
        stateNode.detachChild(currentFastSky);
    }

    if (fastSky != null) {
        stateNode.attachChild(fastSky);
    }

    stateNode.detachChild(getModelNode());
    stateNode.detachChild(getToolNode());

    setCurrentFastSky(fastSky);

    frame = 0;
}
 
Example 5
Source File: AudioViewer3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the current audio node.
 */
@JmeThread
private void removeAudioNode() {

    final AudioNode currentAudioNode = getAudioNode();
    if (currentAudioNode == null) {
        return;
    }

    final Node stateNode = getStateNode();
    final Status status = currentAudioNode.getStatus();

    if (status == Status.Playing || status == Status.Paused) {
        currentAudioNode.stop();
    }

    stateNode.detachChild(currentAudioNode);

    setAudioNode(null);
    setPrevStatus(null);
}
 
Example 6
Source File: BulletCharacterDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    geom.setMaterial(debugAppState.DEBUG_PINK);

    body.getPhysicsLocation(location);
    applyPhysicsTransform(location, Quaternion.IDENTITY);
}
 
Example 7
Source File: BulletGhostObjectDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, ≥0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    geom.setMaterial(debugAppState.DEBUG_YELLOW);

    body.getPhysicsLocation(location);
    body.getPhysicsRotation(rotation);
    applyPhysicsTransform(location, rotation);
}
 
Example 8
Source File: AdvancedPbr3DEditorPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void cleanup() {
    super.cleanup();

    final Node modelNode = getModelNode();
    modelNode.detachAllChildren();

    final Node stateNode = getStateNode();
    stateNode.detachChild(modelNode);
}
 
Example 9
Source File: ModelEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void cleanup() {
    super.cleanup();

    final Node stateNode = getStateNode();
    stateNode.detachChild(getModelNode());
    stateNode.detachChild(getToolNode());
}
 
Example 10
Source File: NodeTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void remove(@NotNull final TreeNode<?> child) {
    super.remove(child);

    final Node node = getElement();
    final Object toRemove = child.getElement();

    if (toRemove instanceof Spatial) {
        node.detachChild((Spatial) toRemove);
    }
}
 
Example 11
Source File: BulletRigidBodyDebugControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update this control. Invoked once per frame during the logical-state
 * update, provided the control is enabled and added to a scene. Should be
 * invoked only by a subclass or by AbstractControl.
 *
 * @param tpf the time interval between frames (in seconds, &ge;0)
 */
@Override
protected void controlUpdate(float tpf) {
    CollisionShape newShape = body.getCollisionShape();
    Vector3f newScale = newShape.getScale();
    if (myShape != newShape || !oldScale.equals(newScale)) {
        myShape = newShape;
        oldScale.set(newScale);

        Node node = (Node) spatial;
        node.detachChild(geom);

        geom = DebugShapeFactory.getDebugShape(myShape);
        geom.setName(body.toString());

        node.attachChild(geom);
    }
    if(body.isActive()){
        geom.setMaterial(debugAppState.DEBUG_MAGENTA);
    }else{
        geom.setMaterial(debugAppState.DEBUG_BLUE);
    }

    body.getPhysicsLocation(location);
    body.getPhysicsRotation(rotation);
    applyPhysicsTransform(location, rotation);
}
 
Example 12
Source File: RemoveElementsOperation.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@JmeThread
private void removeSpatial(@NotNull final Element element, @NotNull final Spatial toRemove) {
    final Node parent = (Node) element.getParent();
    element.setIndex(parent.getChildIndex(toRemove));
    parent.detachChild(toRemove);
}
 
Example 13
Source File: AnimationEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initEvent(Application app, Cinematic cinematic) {
    super.initEvent(app, cinematic);
    this.cinematic = cinematic;
    if (channel == null) {
        Object s = cinematic.getEventData(MODEL_CHANNELS, model);
        if (s == null) {
            s = new HashMap<Integer, AnimChannel>();
            int numChannels = model.getControl(AnimControl.class).getNumChannels();
            for(int i = 0; i < numChannels; i++){
                ((HashMap<Integer, AnimChannel>)s).put(i, model.getControl(AnimControl.class).getChannel(i));
            }
            cinematic.putEventData(MODEL_CHANNELS, model, s);
        }

        Map<Integer, AnimChannel> map = (Map<Integer, AnimChannel>) s;
        this.channel = map.get(channelIndex);
        if (this.channel == null) {
            if (model == null) {
                //the model is null we try to find it according to the name
                //this should occur only when loading an old saved cinematic
                //othewise it's an error
                model = cinematic.getScene().getChild(modelName);
            }
            if (model != null) {
                if(cinematic.getScene() != null){
                    Spatial sceneModel = cinematic.getScene().getChild(model.getName());
                    if(sceneModel != null){
                        Node parent = sceneModel.getParent();
                        parent.detachChild(sceneModel);
                        sceneModel = model;
                        parent.attachChild(sceneModel);
                    } else {
                        cinematic.getScene().attachChild(model);
                    }
                }
                
                channel = model.getControl(AnimControl.class).createChannel();
                map.put(channelIndex, channel);
            } else {
                //it's an error
                throw new UnsupportedOperationException("model should not be null");
            }
        } 

    }
}
 
Example 14
Source File: AbstractPaintingControl.java    From jmonkeybuilder with Apache License 2.0 2 votes vote down vote up
/**
 * Notify about that this control was detached.
 *
 * @param node the node.
 */
@JmeThread
protected void onDetached(@NotNull final Node node) {
    node.detachChild(brush);
}