Search in sources :

Example 51 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class AssetLinkNode method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule capsule = e.getCapsule(this);
    BinaryImporter importer = BinaryImporter.getInstance();
    AssetManager loaderManager = e.getAssetManager();
    assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>());
    for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext(); ) {
        ModelKey modelKey = it.next();
        AssetInfo info = loaderManager.locateAsset(modelKey);
        Spatial child = null;
        if (info != null) {
            child = (Spatial) importer.load(info);
        }
        if (child != null) {
            child.parent = this;
            children.add(child);
            assetChildren.put(modelKey, child);
        } else {
            Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", new Object[] { modelKey, key });
        }
    }
}
Also used : BinaryImporter(com.jme3.export.binary.BinaryImporter) ModelKey(com.jme3.asset.ModelKey) AssetManager(com.jme3.asset.AssetManager) InputCapsule(com.jme3.export.InputCapsule) AssetInfo(com.jme3.asset.AssetInfo)

Example 52 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class Geometry method computeWorldMatrix.

/**
     * Indicate that the transform of this spatial has changed and that
     * a refresh is required.
     */
// NOTE: Spatial has an identical implementation of this method,
// thus it was commented out.
//    @Override
//    protected void setTransformRefresh() {
//        refreshFlags |= RF_TRANSFORM;
//        setBoundRefresh();
//    }
/**
     * Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }.
     * This will require a localized transform update for this geometry.
     */
public void computeWorldMatrix() {
    // Force a local update of the geometry's transform
    checkDoTransformUpdate();
    // Compute the cached world matrix
    cachedWorldMat.loadIdentity();
    cachedWorldMat.setRotationQuaternion(worldTransform.getRotation());
    cachedWorldMat.setTranslation(worldTransform.getTranslation());
    TempVars vars = TempVars.get();
    Matrix4f scaleMat = vars.tempMat4;
    scaleMat.loadIdentity();
    scaleMat.scale(worldTransform.getScale());
    cachedWorldMat.multLocal(scaleMat);
    vars.release();
}
Also used : Matrix4f(com.jme3.math.Matrix4f) TempVars(com.jme3.util.TempVars)

Example 53 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class Spatial method rotate.

/**
     * Rotates the spatial by the xAngle, yAngle and zAngle angles (in radians),
     * (aka pitch, yaw, roll) in the local coordinate space.
     *
     * @return The spatial on which this method is called, e.g <code>this</code>.
     */
public Spatial rotate(float xAngle, float yAngle, float zAngle) {
    TempVars vars = TempVars.get();
    Quaternion q = vars.quat1;
    q.fromAngles(xAngle, yAngle, zAngle);
    rotate(q);
    vars.release();
    return this;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 54 with Spatial

use of com.jme3.scene.Spatial 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 55 with Spatial

use of com.jme3.scene.Spatial in project jmonkeyengine by jMonkeyEngine.

the class Spatial method lookAt.

/**
     * <code>lookAt</code> is a convenience method for auto-setting the local
     * rotation based on a position in world space and an up vector. It computes the rotation
     * to transform the z-axis to point onto 'position' and the y-axis to 'up'.
     * Unlike {@link Quaternion#lookAt(com.jme3.math.Vector3f, com.jme3.math.Vector3f) }
     * this method takes a world position to look at and not a relative direction.
     *
     * Note : 28/01/2013 this method has been fixed as it was not taking into account the parent rotation.
     * This was resulting in improper rotation when the spatial had rotated parent nodes.
     * This method is intended to work in world space, so no matter what parent graph the
     * spatial has, it will look at the given position in world space.
     *
     * @param position
     *            where to look at in terms of world coordinates
     * @param upVector
     *            a vector indicating the (local) up direction. (typically {0,
     *            1, 0} in jME.)
     */
public void lookAt(Vector3f position, Vector3f upVector) {
    Vector3f worldTranslation = getWorldTranslation();
    TempVars vars = TempVars.get();
    Vector3f compVecA = vars.vect4;
    compVecA.set(position).subtractLocal(worldTranslation);
    getLocalRotation().lookAt(compVecA, upVector);
    if (getParent() != null) {
        Quaternion rot = vars.quat1;
        rot = rot.set(parent.getWorldRotation()).inverseLocal().multLocal(getLocalRotation());
        rot.normalizeLocal();
        setLocalRotation(rot);
    }
    vars.release();
    setTransformRefresh();
}
Also used : TempVars(com.jme3.util.TempVars)

Aggregations

Spatial (com.jme3.scene.Spatial)123 Vector3f (com.jme3.math.Vector3f)74 Node (com.jme3.scene.Node)56 Geometry (com.jme3.scene.Geometry)50 DirectionalLight (com.jme3.light.DirectionalLight)46 Material (com.jme3.material.Material)39 Quaternion (com.jme3.math.Quaternion)34 FilterPostProcessor (com.jme3.post.FilterPostProcessor)17 Box (com.jme3.scene.shape.Box)17 KeyTrigger (com.jme3.input.controls.KeyTrigger)15 AmbientLight (com.jme3.light.AmbientLight)14 ColorRGBA (com.jme3.math.ColorRGBA)14 Camera (com.jme3.renderer.Camera)13 Sphere (com.jme3.scene.shape.Sphere)13 Texture (com.jme3.texture.Texture)12 TempVars (com.jme3.util.TempVars)12 InputCapsule (com.jme3.export.InputCapsule)11 ActionListener (com.jme3.input.controls.ActionListener)11 AnimControl (com.jme3.animation.AnimControl)10 OutputCapsule (com.jme3.export.OutputCapsule)9