Search in sources :

Example 46 with Node

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

the class TerrainLodControl method write.

@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule oc = ex.getCapsule(this);
    oc.write((Node) terrain, "terrain", null);
    oc.write(lodCalculator, "lodCalculator", null);
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule)

Example 47 with Node

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

the class AssetLinkNode method attachLinkedChildren.

/**
     * Loads the linked children AssetKeys from the AssetManager and attaches them to the Node<br>
     * If they are already attached, they will be reloaded.
     * @param manager
     */
public void attachLinkedChildren(AssetManager manager) {
    detachLinkedChildren();
    for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext(); ) {
        ModelKey assetKey = it.next();
        Spatial curChild = assetChildren.get(assetKey);
        if (curChild != null) {
            curChild.removeFromParent();
        }
        Spatial child = manager.loadAsset(assetKey);
        attachChild(child);
        assetChildren.put(assetKey, child);
    }
}
Also used : ModelKey(com.jme3.asset.ModelKey)

Example 48 with Node

use of com.jme3.scene.Node 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 49 with Node

use of com.jme3.scene.Node 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 50 with Node

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

the class BillboardControl method rotateScreenAligned.

/**
     * Rotate the billboard so it points directly opposite the direction the
     * camera's facing
     *
     * @param camera
     *            Camera
     */
private void rotateScreenAligned(Camera camera) {
    // coopt diff for our in direction:
    look.set(camera.getDirection()).negateLocal();
    // coopt loc for our left direction:
    left.set(camera.getLeft()).negateLocal();
    orient.fromAxes(left, camera.getUp(), look);
    Node parent = spatial.getParent();
    Quaternion rot = new Quaternion().fromRotationMatrix(orient);
    if (parent != null) {
        rot = parent.getWorldRotation().inverse().multLocal(rot);
        rot.normalizeLocal();
    }
    spatial.setLocalRotation(rot);
    fixRefreshFlags();
}
Also used : Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node)

Aggregations

Node (com.jme3.scene.Node)135 Vector3f (com.jme3.math.Vector3f)81 Geometry (com.jme3.scene.Geometry)64 Spatial (com.jme3.scene.Spatial)53 Material (com.jme3.material.Material)51 DirectionalLight (com.jme3.light.DirectionalLight)35 Quaternion (com.jme3.math.Quaternion)32 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Box (com.jme3.scene.shape.Box)24 Sphere (com.jme3.scene.shape.Sphere)19 AmbientLight (com.jme3.light.AmbientLight)17 BulletAppState (com.jme3.bullet.BulletAppState)16 ColorRGBA (com.jme3.math.ColorRGBA)15 AnimControl (com.jme3.animation.AnimControl)14 KeyTrigger (com.jme3.input.controls.KeyTrigger)14 FilterPostProcessor (com.jme3.post.FilterPostProcessor)14 HashMap (java.util.HashMap)14 CameraNode (com.jme3.scene.CameraNode)13 ArrayList (java.util.ArrayList)13 ActionListener (com.jme3.input.controls.ActionListener)12