Search in sources :

Example 1 with InstancedNode

use of com.jme3.scene.instancing.InstancedNode in project jmonkeyengine by jMonkeyEngine.

the class InstancedNode method addToInstancedGeometry.

private void addToInstancedGeometry(Geometry geom) {
    Material material = geom.getMaterial();
    MatParam param = material.getParam("UseInstancing");
    if (param == null || !((Boolean) param.getValue()).booleanValue()) {
        throw new IllegalStateException("You must set the 'UseInstancing' " + "parameter to true on the material prior " + "to adding it to InstancedNode");
    }
    InstancedGeometry ig = lookUpByGeometry(geom);
    igByGeom.put(geom, ig);
    geom.associateWithGroupNode(this, 0);
    ig.addInstance(geom);
}
Also used : MatParam(com.jme3.material.MatParam) Material(com.jme3.material.Material)

Example 2 with InstancedNode

use of com.jme3.scene.instancing.InstancedNode in project jmonkeyengine by jMonkeyEngine.

the class TestInstanceNode method simpleInitApp.

@Override
public void simpleInitApp() {
    mesh1 = new Sphere(13, 13, 0.4f, true, false);
    mesh2 = new Box(0.4f, 0.4f, 0.4f);
    materials[0] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[0].setBoolean("UseInstancing", INSTANCING);
    materials[0].setColor("Color", ColorRGBA.Red);
    materials[1] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[1].setBoolean("UseInstancing", INSTANCING);
    materials[1].setColor("Color", ColorRGBA.Green);
    materials[2] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[2].setBoolean("UseInstancing", INSTANCING);
    materials[2].setColor("Color", ColorRGBA.Blue);
    materials[3] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[3].setBoolean("UseInstancing", INSTANCING);
    materials[3].setColor("Color", ColorRGBA.Cyan);
    materials[4] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[4].setBoolean("UseInstancing", INSTANCING);
    materials[4].setColor("Color", ColorRGBA.Magenta);
    materials[5] = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    materials[5].setBoolean("UseInstancing", INSTANCING);
    materials[5].setColor("Color", ColorRGBA.Yellow);
    instancedNode = new InstancedNode("instanced_node");
    rootNode.attachChild(instancedNode);
    int extent = 30;
    for (int y = -extent; y < extent; y++) {
        for (int x = -extent; x < extent; x++) {
            Geometry instance = createInstance(x, y);
            float height = (smoothstep(0, 1, FastMath.nextRandomFloat()) * 2.5f) - 1.25f;
            instance.setUserData("height", height);
            instance.setUserData("dir", 1f);
            instancedNode.attachChild(instance);
        }
    }
    if (INSTANCING) {
        ((InstancedNode) instancedNode).instance();
    }
    //instancedNode = (InstancedNode) instancedNode.clone();
    //instancedNode.move(0, 5, 0);
    //rootNode.attachChild(instancedNode);
    cam.setLocation(new Vector3f(38.373516f, 6.689055f, 38.482082f));
    cam.setRotation(new Quaternion(-0.04004206f, 0.918326f, -0.096310444f, -0.38183528f));
    flyCam.setMoveSpeed(15);
    flyCam.setEnabled(false);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) InstancedGeometry(com.jme3.scene.instancing.InstancedGeometry) Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) InstancedNode(com.jme3.scene.instancing.InstancedNode)

Aggregations

Material (com.jme3.material.Material)2 MatParam (com.jme3.material.MatParam)1 Quaternion (com.jme3.math.Quaternion)1 Vector3f (com.jme3.math.Vector3f)1 Geometry (com.jme3.scene.Geometry)1 InstancedGeometry (com.jme3.scene.instancing.InstancedGeometry)1 InstancedNode (com.jme3.scene.instancing.InstancedNode)1 Box (com.jme3.scene.shape.Box)1 Sphere (com.jme3.scene.shape.Sphere)1