Search in sources :

Example 1 with AssetLinkNode

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

the class TestAssetLinkNode method simpleInitApp.

@Override
public void simpleInitApp() {
    AssetLinkNode loaderNode = new AssetLinkNode();
    loaderNode.addLinkedChild(new ModelKey("Models/MonkeyHead/MonkeyHead.mesh.xml"));
    //save and load the loaderNode
    try {
        //export to byte array
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        BinaryExporter.getInstance().save(loaderNode, bout);
        //import from byte array, automatically loads the monkeyhead from file
        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        BinaryImporter imp = BinaryImporter.getInstance();
        imp.setAssetManager(assetManager);
        Node newLoaderNode = (Node) imp.load(bin);
        //attach to rootNode
        rootNode.attachChild(newLoaderNode);
    } catch (IOException ex) {
        Logger.getLogger(TestAssetLinkNode.class.getName()).log(Level.SEVERE, null, ex);
    }
    rootNode.attachChild(loaderNode);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial((Material) assetManager.loadAsset(new AssetKey("Common/Materials/RedColor.j3m")));
    rootNode.attachChild(lightMdl);
    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    // sunset light
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.44f, 0.30f, 0.20f, 1.0f));
    rootNode.addLight(dl);
    // skylight
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.6f, -1, -0.6f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.10f, 0.22f, 0.44f, 1.0f));
    rootNode.addLight(dl);
    // white ambient light
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
    dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
    rootNode.addLight(dl);
}
Also used : ModelKey(com.jme3.asset.ModelKey) AssetLinkNode(com.jme3.scene.AssetLinkNode) Node(com.jme3.scene.Node) AssetLinkNode(com.jme3.scene.AssetLinkNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) BinaryImporter(com.jme3.export.binary.BinaryImporter) AssetKey(com.jme3.asset.AssetKey) ColorRGBA(com.jme3.math.ColorRGBA) ByteArrayInputStream(java.io.ByteArrayInputStream) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight)

Aggregations

AssetKey (com.jme3.asset.AssetKey)1 ModelKey (com.jme3.asset.ModelKey)1 BinaryImporter (com.jme3.export.binary.BinaryImporter)1 DirectionalLight (com.jme3.light.DirectionalLight)1 PointLight (com.jme3.light.PointLight)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Vector3f (com.jme3.math.Vector3f)1 AssetLinkNode (com.jme3.scene.AssetLinkNode)1 Geometry (com.jme3.scene.Geometry)1 Node (com.jme3.scene.Node)1 Sphere (com.jme3.scene.shape.Sphere)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1