Search in sources :

Example 1 with InstancedGeometry

use of com.jme3.scene.instancing.InstancedGeometry 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 InstancedGeometry

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

the class DefaultTechniqueDefLogic method renderMeshFromGeometry.

public static void renderMeshFromGeometry(Renderer renderer, Geometry geom) {
    Mesh mesh = geom.getMesh();
    int lodLevel = geom.getLodLevel();
    if (geom instanceof InstancedGeometry) {
        InstancedGeometry instGeom = (InstancedGeometry) geom;
        renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(), instGeom.getAllInstanceData());
    } else {
        renderer.renderMesh(mesh, lodLevel, 1, null);
    }
}
Also used : InstancedGeometry(com.jme3.scene.instancing.InstancedGeometry) Mesh(com.jme3.scene.Mesh)

Example 3 with InstancedGeometry

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

the class TestInstanceNode method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    time += tpf;
    if (time > 1f) {
        time = 0f;
        for (Spatial instance : instancedNode.getChildren()) {
            if (!(instance instanceof InstancedGeometry)) {
                Geometry geom = (Geometry) instance;
                geom.setMaterial(materials[FastMath.nextRandomInt(0, materials.length - 1)]);
                Mesh mesh;
                if (FastMath.nextRandomInt(0, 1) == 1)
                    mesh = mesh2;
                else
                    mesh = mesh1;
                geom.setMesh(mesh);
            }
        }
    }
    for (Spatial child : instancedNode.getChildren()) {
        if (!(child instanceof InstancedGeometry)) {
            float val = ((Float) child.getUserData("height")).floatValue();
            float dir = ((Float) child.getUserData("dir")).floatValue();
            val += (dir + ((FastMath.nextRandomFloat() * 0.5f) - 0.25f)) * tpf;
            if (val > 1f) {
                val = 1f;
                dir = -dir;
            } else if (val < 0f) {
                val = 0f;
                dir = -dir;
            }
            Vector3f translation = child.getLocalTranslation();
            translation.y = (smoothstep(0, 1, val) * 2.5f) - 1.25f;
            child.setUserData("height", val);
            child.setUserData("dir", dir);
            child.setLocalTranslation(translation);
        }
    }
}
Also used : InstancedGeometry(com.jme3.scene.instancing.InstancedGeometry) Geometry(com.jme3.scene.Geometry) InstancedGeometry(com.jme3.scene.instancing.InstancedGeometry) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh)

Aggregations

Mesh (com.jme3.scene.Mesh)2 InstancedGeometry (com.jme3.scene.instancing.InstancedGeometry)2 MatParam (com.jme3.material.MatParam)1 Material (com.jme3.material.Material)1 Vector3f (com.jme3.math.Vector3f)1 Geometry (com.jme3.scene.Geometry)1 Spatial (com.jme3.scene.Spatial)1