Skip to content

Commit

Permalink
MeshCollisionShape: make BVH serialization optional
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Apr 30, 2024
1 parent a1ba1b8 commit 720c1ec
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public class MeshCollisionShape extends CollisionShape {
* if true, use quantized AABB compression (default=true)
*/
private boolean useCompression;
/**
* if true, serialize BVHs when serializing mesh collision shapes
* (default=true)
*/
private static boolean serializeBvh = true;
/**
* bounding-value hierarchy
*/
Expand Down Expand Up @@ -280,6 +285,16 @@ public IndexedMesh getSubmesh(int index) {
return result;
}

/**
* Test whether bounding-value hierarchies will be serialized when
* serializing mesh collision shapes.
*
* @return true if serializing hierarchies, otherwise false
*/
public static boolean isSerializingBvh() {
return serializeBvh;
}

/**
* Serialize the BVH to a byte array.
*
Expand All @@ -290,6 +305,17 @@ public byte[] serializeBvh() {
return result;
}

/**
* Alter whether bounding-value hierarchies will be included when
* serializing mesh collision shapes.
*
* @param setting true to serialize hierarchies, false to slip serializing
* them (default=true)
*/
public static void setSerializingBvh(boolean setting) {
serializeBvh = setting;
}

/**
* Attempt to divide this shape into 2 shapes.
*
Expand Down Expand Up @@ -430,7 +456,9 @@ public void write(JmeExporter exporter) throws IOException {
super.write(exporter);
OutputCapsule capsule = exporter.getCapsule(this);

capsule.write(bvh, tagBvh, null);
if (serializeBvh) {
capsule.write(bvh, tagBvh, null);
}

boolean doublePrecision = NativeLibrary.isDoublePrecision();
capsule.write(doublePrecision, tagDoublePrecision, false);
Expand Down

0 comments on commit 720c1ec

Please sign in to comment.