Skip to content

Commit 13887ba

Browse files
committed
spatial lods
1 parent 0368453 commit 13887ba

14 files changed

Lines changed: 1138 additions & 37 deletions

File tree

jme3-core/src/main/java/com/jme3/scene/Geometry.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,19 @@ public void setIgnoreTransform(boolean ignoreTransform) {
180180
* levels [1, LodLevels + 1] represent the levels set on the mesh
181181
* with {@link Mesh#setLodLevels(com.jme3.scene.VertexBuffer[]) }.
182182
*
183-
* @param lod The lod level to set
183+
* @param lod The lod level to set. If the requested level is outside the
184+
* available range, the closest available level is used.
184185
*/
185186
@Override
186187
public void setLodLevel(int lod) {
187188
assert SceneGraphThreadWarden.assertOnCorrectThread(this);
188-
if (mesh.getNumLodLevels() == 0) {
189-
throw new IllegalStateException("LOD levels are not set on this mesh");
190-
}
191-
192-
if (lod < 0 || lod >= mesh.getNumLodLevels()) {
193-
throw new IllegalArgumentException("LOD level is out of range: " + lod);
189+
int numLodLevels = mesh.getNumLodLevels();
190+
if (numLodLevels == 0) {
191+
lodLevel = 0;
192+
} else {
193+
lodLevel = Math.max(0, Math.min(lod, numLodLevels - 1));
194194
}
195195

196-
lodLevel = lod;
197-
198196
if (isGrouped()) {
199197
groupNode.onMeshChange(this);
200198
}

jme3-core/src/main/java/com/jme3/scene/Node.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.jme3.light.Light;
4141
import com.jme3.light.LightList;
4242
import com.jme3.material.Material;
43+
import com.jme3.scene.control.SpatialLodControl;
4344
import com.jme3.scene.threadwarden.SceneGraphThreadWarden;
4445
import com.jme3.util.SafeArrayList;
4546
import com.jme3.util.clone.Cloner;
@@ -630,6 +631,11 @@ public void setMaterial(Material mat) {
630631
@Override
631632
public void setLodLevel(int lod) {
632633
super.setLodLevel(lod);
634+
SpatialLodControl lodControl = getControl(SpatialLodControl.class);
635+
if (lodControl != null) {
636+
lodControl.setSelectedLodLevel(lod);
637+
lodControl.applyLodLevel(lod);
638+
}
633639
for (Spatial child : children.getArray()) {
634640
child.setLodLevel(lod);
635641
}
@@ -815,8 +821,19 @@ public void cloneFields(Cloner cloner, Object original) {
815821
@Override
816822
@SuppressWarnings("unchecked")
817823
public void write(JmeExporter e) throws IOException {
818-
super.write(e);
819-
e.getCapsule(this).writeSavableArrayList(new ArrayList(children), "children", null);
824+
SpatialLodControl lodControl = getControl(SpatialLodControl.class);
825+
int previousActiveLodLevel = 0;
826+
if (lodControl != null) {
827+
previousActiveLodLevel = lodControl.prepareForSerialization();
828+
}
829+
try {
830+
super.write(e);
831+
e.getCapsule(this).writeSavableArrayList(new ArrayList(children), "children", null);
832+
} finally {
833+
if (lodControl != null) {
834+
lodControl.restoreAfterSerialization(previousActiveLodLevel);
835+
}
836+
}
820837
}
821838

822839
@Override

jme3-core/src/main/java/com/jme3/scene/control/LodControl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
* requires the camera to do this. The controlRender method is called each frame
5757
* and will update the spatial's LOD if the camera has moved by a specified
5858
* amount.
59+
*
60+
* @deprecated Use a node-level LOD control for scene-graph LOD switching. This
61+
* control only selects pre-existing mesh index-buffer LODs on a Geometry.
5962
*/
63+
@Deprecated
6064
public class LodControl extends AbstractControl implements Cloneable, JmeCloneable {
6165

6266
private float trisPerPixel = 1f;

0 commit comments

Comments
 (0)