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);
}
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);
}
}
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);
}
}
}