Skip to content

Commit cb8e4b2

Browse files
authored
Merge pull request #190 from jMonkeyEngine/neph1-patch-2
Create instancednode.adoc
2 parents 86c593b + 8280ecf commit cb8e4b2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
= InstancedNode
2+
:revnumber: 1.0
3+
:revdate: 2026/01/29
4+
:keywords: spatial, node, geometry, optimization
5+
6+
7+
Using InstancedNode is a way to reduce drawcalls by optimizing the amount of objects being drawn at the same time. The amount of triangles will stay the same.
8+
9+
Example:
10+
[source,java]
11+
----
12+
InstancedNode instancedNode = new InstancedNode();
13+
14+
Geometry geometry = new Geometry("randomGeom", mesh);
15+
geometry.setLocalTranslation(2, 0, 0);
16+
17+
Geometry geometry2 = new Geometry("randomGeom2", mesh);
18+
geometry2.setLocalTranslation(-2, 0, 0);
19+
20+
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
21+
material.setBoolean("UseInstancing", true);
22+
geometry.setMaterial(material);
23+
geometry2.setMaterial(material);
24+
25+
instancedNode.attachChild(geometry);
26+
instancedNode.attachChild(geometry2);
27+
28+
instancedNode.instance();
29+
----
30+
31+
The important rows in the snippet that differs from a normal implementation are:
32+
[source,java]
33+
----
34+
material.setBoolean("UseInstancing", true);
35+
----
36+
and
37+
[source,java]
38+
----
39+
instancedNode.instance();
40+
----
41+
42+
Once instanced, you can still manipulate the spatials inside the node, as opposed to a BatchNode.
43+
44+
== See also
45+
https://wiki.jmonkeyengine.org/docs/3.4/tutorials/concepts/optimization.html
46+
47+
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/scene/BatchNode.java
48+
49+
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-examples/src/main/java/jme3test/scene/instancing/TestInstanceNode.java
50+
51+

0 commit comments

Comments
 (0)