Search in sources :

Example 1 with Cloner

use of com.jme3.util.clone.Cloner in project jmonkeyengine by jMonkeyEngine.

the class SkeletonControl method cloneFields.

@Override
public void cloneFields(Cloner cloner, Object original) {
    super.cloneFields(cloner, original);
    this.skeleton = cloner.clone(skeleton);
    // If the targets were cloned then this will clone them.  If the targets
    // were shared then this will share them.
    this.targets = cloner.clone(targets);
    // Not automatic set cloning yet
    Set<Material> newMaterials = new HashSet<Material>();
    for (Material m : this.materials) {
        Material mClone = cloner.clone(m);
        newMaterials.add(mClone);
        if (mClone != m) {
            // Material was really cloned so clear the bone matrices in case
            // this is hardware skinned.  This allows a local version to be
            // used and will be reset on the material.  Really this just avoids
            // the 'safety' check in controlRenderHardware().  Right now material
            // doesn't clone itself with the cloner (and doesn't clone its parameters)
            // else this would be unnecessary.
            MatParam boneMatrices = mClone.getParam("BoneMatrices");
            // parameter.
            if (boneMatrices != null) {
                mClone.clearParam("BoneMatrices");
            }
        }
    }
    this.materials = newMaterials;
}
Also used : MatParam(com.jme3.material.MatParam) Material(com.jme3.material.Material) HashSet(java.util.HashSet)

Example 2 with Cloner

use of com.jme3.util.clone.Cloner in project jmonkeyengine by jMonkeyEngine.

the class Spatial method oldClone.

/**
     *  The old clone() method that did not use the new Cloner utility.
     */
public Spatial oldClone(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);
        clone.worldOverrides = new SafeArrayList<>(MatParamOverride.class);
        clone.localOverrides = new SafeArrayList<>(MatParamOverride.class);
        for (MatParamOverride override : localOverrides) {
            clone.localOverrides.add((MatParamOverride) override.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.setMatParamOverrideRefresh();
        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();
    }
}
Also used : Control(com.jme3.scene.control.Control) MatParamOverride(com.jme3.material.MatParamOverride)

Example 3 with Cloner

use of com.jme3.util.clone.Cloner in project jmonkeyengine by jMonkeyEngine.

the class VehicleControl method cloneFields.

@Override
public void cloneFields(Cloner cloner, Object original) {
    this.spatial = cloner.clone(spatial);
    for (VehicleWheel wheel : wheels) {
        Spatial spatial = cloner.clone(wheel.getWheelSpatial());
        wheel.setWheelSpatial(spatial);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Example 4 with Cloner

use of com.jme3.util.clone.Cloner in project jmonkeyengine by jMonkeyEngine.

the class J3MLoader method readTechnique.

private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);
    Cloner cloner = new Cloner();
    String name;
    if (split.length == 1) {
        name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
    } else if (split.length == 2) {
        name = split[1];
    } else {
        throw new IOException("Technique statement syntax incorrect");
    }
    String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
    technique = new TechniqueDef(name, techniqueUniqueName.hashCode());
    for (Statement statement : techStat.getContents()) {
        readTechniqueStatement(statement);
    }
    technique.setShaderPrologue(createShaderPrologue(presetDefines));
    switch(technique.getLightMode()) {
        case Disable:
            technique.setLogic(new DefaultTechniqueDefLogic(technique));
            break;
        case MultiPass:
            technique.setLogic(new MultiPassLightingLogic(technique));
            break;
        case SinglePass:
            technique.setLogic(new SinglePassLightingLogic(technique));
            break;
        case StaticPass:
            technique.setLogic(new StaticPassLightingLogic(technique));
            break;
        case SinglePassAndImageBased:
            technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
            break;
        default:
            throw new UnsupportedOperationException();
    }
    List<TechniqueDef> techniqueDefs = new ArrayList<>();
    if (isUseNodes) {
        nodesLoaderDelegate.computeConditions();
        //used for caching later, the shader here is not a file.
        // KIRILL 9/19/2015
        // Not sure if this is needed anymore, since shader caching
        // is now done by TechniqueDef.
        technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
        techniqueDefs.add(technique);
    } else if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
        if (shaderLanguages.size() > 1) {
            for (int i = 1; i < shaderLanguages.size(); i++) {
                cloner.clearIndex();
                TechniqueDef td = cloner.clone(technique);
                td.setShaderFile(shaderNames, shaderLanguages.get(i));
                techniqueDefs.add(td);
            }
        }
        technique.setShaderFile(shaderNames, shaderLanguages.get(0));
        techniqueDefs.add(technique);
    } else {
        technique = null;
        shaderLanguages.clear();
        shaderNames.clear();
        presetDefines.clear();
        langSize = 0;
        logger.log(Level.WARNING, "Fixed function technique was ignored");
        logger.log(Level.WARNING, "Fixed function technique ''{0}'' was ignored for material {1}", new Object[] { name, key });
        return;
    }
    for (TechniqueDef techniqueDef : techniqueDefs) {
        materialDef.addTechniqueDef(techniqueDef);
    }
    technique = null;
    langSize = 0;
    shaderLanguages.clear();
    shaderNames.clear();
    presetDefines.clear();
}
Also used : Statement(com.jme3.util.blockparser.Statement) IOException(java.io.IOException) StaticPassLightingLogic(com.jme3.material.logic.StaticPassLightingLogic) Cloner(com.jme3.util.clone.Cloner)

Example 5 with Cloner

use of com.jme3.util.clone.Cloner in project jmonkeyengine by jMonkeyEngine.

the class BitmapTextPage method cloneFields.

/**
     *  Called internally by com.jme3.util.clone.Cloner.  Do not call directly.
     */
@Override
public void cloneFields(Cloner cloner, Object original) {
    Mesh originalMesh = this.mesh;
    super.cloneFields(cloner, original);
    // want to do it again... so we'll check first.
    if (this.mesh == originalMesh) {
        this.mesh = mesh.deepClone();
    }
}
Also used : Mesh(com.jme3.scene.Mesh)

Aggregations

Cloner (com.jme3.util.clone.Cloner)3 Material (com.jme3.material.Material)2 Mesh (com.jme3.scene.Mesh)2 VehicleWheel (com.jme3.bullet.objects.VehicleWheel)1 MatParam (com.jme3.material.MatParam)1 MatParamOverride (com.jme3.material.MatParamOverride)1 StaticPassLightingLogic (com.jme3.material.logic.StaticPassLightingLogic)1 Vector3f (com.jme3.math.Vector3f)1 Spatial (com.jme3.scene.Spatial)1 Control (com.jme3.scene.control.Control)1 Statement (com.jme3.util.blockparser.Statement)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1