Browse Source

Compute trail bounds and collider when trails is changing

borisrp 4 tháng trước cách đây
mục cha
commit
4248a4a672
1 tập tin đã thay đổi với 3 bổ sung1 xóa
  1. 3 1
      hrt/prefab/l3d/Trails.hx

+ 3 - 1
hrt/prefab/l3d/Trails.hx

@@ -351,7 +351,6 @@ class TrailObj extends h3d.scene.Mesh {
 	public function new(parentPrefab: Trails, ?parent : h3d.scene.Object, ?numTrails : Int) {
 		bounds = new h3d.col.Bounds();
 		prefab = parentPrefab;
-		bounds.addPos(0,0,0);
 
 		var nTrails = numTrails != null ? numTrails : 1;
 		if ( nTrails == 1 && parentPrefab.children.length > 1 )
@@ -602,6 +601,7 @@ class TrailObj extends h3d.scene.Mesh {
 		}
 
 		inline function addEdge( p : TrailPoint, u : Float ) {
+			bounds.addPos(p.x, p.y, p.z);
 
 			buffer[count++] = p.x + (tmpBinormal.x * p.w * baseScale.x);
 			buffer[count++] = p.y + (tmpBinormal.y * p.w * baseScale.y);
@@ -658,6 +658,7 @@ class TrailObj extends h3d.scene.Mesh {
 		var customAxis = ( orientRight ) ? tmpBinormal : tmpNormal;
 		var computedAxis = ( orientRight ) ? tmpNormal : tmpBinormal;
 
+		bounds.empty();
 		for (i in 0...numTrails) {
 			var trail = trails[i];
 			if ( trail.firstPoint == null )
@@ -724,6 +725,7 @@ class TrailObj extends h3d.scene.Mesh {
 				segmentIndex++;
 				cur = cur.next;
 			}
+			this.cullingCollider = bounds.toSphere();
 		}
 
 		var numVerts = Std.int(count/format.stride);