Java Code Examples for com.jme3.scene.Spatial#clone()

The following examples show how to use com.jme3.scene.Spatial#clone() . 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: TestModelExportingCloning.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(10f, 3f, 40f));
    cam.lookAtDirection(Vector3f.UNIT_Z.negate(), Vector3f.UNIT_Y);

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    AnimComposer composer;

    Spatial originalModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    composer = originalModel.getControl(AnimComposer.class);
    composer.setCurrentAction("Walk");
    composer.setGlobalSpeed(1.5f);
    rootNode.attachChild(originalModel);
    
    Spatial clonedModel = originalModel.clone();
    clonedModel.move(10, 0, 0);
    composer = clonedModel.getControl(AnimComposer.class);
    composer.setCurrentAction("push");
    System.out.println("clonedModel: globalSpeed=" + composer.getGlobalSpeed());
    rootNode.attachChild(clonedModel);
    
    Spatial exportedModel = BinaryExporter.saveAndLoad(assetManager, originalModel);
    exportedModel.move(20, 0, 0);
    composer = exportedModel.getControl(AnimComposer.class);
    composer.setCurrentAction("pull");
    System.out.println("exportedModel: globalSpeed=" + composer.getGlobalSpeed());
    rootNode.attachChild(exportedModel);
}
 
Example 3
Source File: ModelKey.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Object createClonedInstance(Object asset){
    Spatial model = (Spatial) asset;
    return model.clone();
}