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

The following examples show how to use com.jme3.scene.Node#getChildIndex() . 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: NodeTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
public void accept(@NotNull final ChangeConsumer changeConsumer, @NotNull final Object object,
                   final boolean isCopy) {

    final T newParent = getElement();

    if (object instanceof Spatial) {

        final Spatial spatial = (Spatial) object;

        if (isCopy) {

            final Spatial clone = spatial.clone();
            final SceneLayer layer = SceneLayer.getLayer(spatial);

            if (layer != null) {
                SceneLayer.setLayer(layer, clone);
            }

            changeConsumer.execute(new AddChildOperation(clone, newParent, true));

        } else {
            final Node parent = spatial.getParent();
            final int childIndex = parent.getChildIndex(spatial);
            changeConsumer.execute(new MoveChildOperation(spatial, parent, newParent, childIndex));
        }
    }

    super.accept(changeConsumer, object, isCopy);
}
 
Example 2
Source File: RemoveChildOperation.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public RemoveChildOperation(@NotNull final Spatial child, @NotNull final Node parent) {
    this.child = child;
    this.parent = parent;
    this.childIndex = parent.getChildIndex(child);
}