2
0
Эх сурвалжийг харах

fixed sparse object interactive (references)

Nicolas Cannasse 5 жил өмнө
parent
commit
73f22c35e6

+ 2 - 1
hide/tools/ChunkedScene.hx

@@ -88,7 +88,8 @@ class ChunkScene {
 					var chunks = getChunks(tmpBounds);
 					for( c in chunks )
 						c.addInteractive(i);
-				}
+				} else
+					global.addInteractive(i);
 			}
 		}
 	}

+ 22 - 2
hrt/prefab/Object3D.hx

@@ -156,7 +156,14 @@ class Object3D extends Prefab {
 		var invRootMat = local3d.getAbsPos().clone();
 		invRootMat.invert();
 		var bounds = new h3d.col.Bounds();
+		var localBounds = [];
+		var totalSeparateBounds = 0.;
 		var visibleMeshes = [];
+
+		inline function getVolume(b:h3d.col.Bounds) {
+			var c = b.getSize();
+			return c.x * c.y * c.z;
+		}
 		for(mesh in meshes) {
 			if(mesh.ignoreCollide)
 				continue;
@@ -174,6 +181,15 @@ class Object3D extends Prefab {
 			var lb = mesh.primitive.getBounds().clone();
 			lb.transform(localMat);
 			bounds.add(lb);
+
+			totalSeparateBounds += getVolume(lb);
+			for( b in localBounds ) {
+				var tmp = new h3d.col.Bounds();
+				tmp.intersection(lb, b);
+				totalSeparateBounds -= getVolume(tmp);
+			}
+			localBounds.push(lb);
+
 			visibleMeshes.push(mesh);
 		}
 		if( visibleMeshes.length == 0 )
@@ -182,8 +198,12 @@ class Object3D extends Prefab {
 			var c : h3d.col.Collider = try m.getGlobalCollider() catch(e: Dynamic) null;
 			if(c != null) c;
 		}]);
-		var boundsCollider = new h3d.col.ObjectCollider(local3d, bounds);
-		var int = new h3d.scene.Interactive(boundsCollider, local3d);
+		var collider : h3d.col.Collider = new h3d.col.ObjectCollider(local3d, bounds);
+		if( totalSeparateBounds / getVolume(bounds) < 0.5 ) {
+			collider = new h3d.col.Collider.OptimizedCollider(collider, meshCollider);
+			meshCollider = null;
+		}
+		var int = new h3d.scene.Interactive(collider, local3d);
 		int.ignoreParentTransform = true;
 		int.preciseShape = meshCollider;
 		int.propagateEvents = true;