Skip to content

Commit

Permalink
MeshCollisionShape: re-generate a BVH written with the wrong precision
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Apr 22, 2024
1 parent 57c69fc commit 7dd6e2c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.jme3.bullet.collision.shapes.infos.BoundingValueHierarchy;
import com.jme3.bullet.collision.shapes.infos.CompoundMesh;
import com.jme3.bullet.collision.shapes.infos.IndexedMesh;
import com.jme3.bullet.util.NativeLibrary;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class MeshCollisionShape extends CollisionShape {
* field names for serialization
*/
final private static String tagBvh = "bvh";
final private static String tagDoublePrecision = "doublePrecision";
final private static String tagNativePlatform = "nativePlatform";
final private static String tagNativeMesh = "nativeMesh";
final private static String tagUseCompression = "useCompression";
Expand Down Expand Up @@ -365,10 +367,16 @@ public void read(JmeImporter importer) throws IOException {
super.read(importer);
InputCapsule capsule = importer.getCapsule(this);

boolean writeDoublePrecision
= capsule.readBoolean(tagDoublePrecision, false);
Platform writePlatform
= capsule.readEnum(tagNativePlatform, Platform.class, null);
if (writePlatform == null || writePlatform != JmeSystem.getPlatform()) {
this.bvh = null; // will re-generate the BVH for the new platform
if (writeDoublePrecision != NativeLibrary.isDoublePrecision()
|| writePlatform == null
|| writePlatform != JmeSystem.getPlatform()) {
this.bvh = null;
// will re-generate the BVH for the new precision and/or platform

} else {
this.bvh = (BoundingValueHierarchy) capsule.readSavable(
tagBvh, null);
Expand Down Expand Up @@ -424,6 +432,9 @@ public void write(JmeExporter exporter) throws IOException {

capsule.write(bvh, tagBvh, null);

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

Platform nativePlatform = JmeSystem.getPlatform();
capsule.write(nativePlatform, tagNativePlatform, null);

Expand Down

0 comments on commit 7dd6e2c

Please sign in to comment.