@@ -69,6 +69,7 @@ public class GeometryPartModule : PartModule, IRescalable<GeometryPartModule>
6969 public Rigidbody partRigidBody ;
7070
7171 public Bounds overallMeshBounds ;
72+ public Bounds localMeshBounds ;
7273
7374 public List < GeometryMesh > meshDataList ;
7475 private List < IGeometryUpdater > geometryUpdaters ;
@@ -279,14 +280,14 @@ private void FixedUpdate()
279280 {
280281 if ( ! _ready && _meshesToUpdate == 0 )
281282 {
282- overallMeshBounds = SetBoundsFromMeshes ( ) ;
283+ ( localMeshBounds , overallMeshBounds ) = SetBoundsFromMeshes ( ) ;
283284
284285 // @DRVeyl: Force all cubes to have the same bounds. Do this any time you recalculate a mesh
285286 // (ie when handling animations since this breaks the cubes for anything other than the *current* cube.)
286287 foreach ( DragCube cube in part . DragCubes . Cubes )
287288 {
288- cube . Size = overallMeshBounds . size ;
289- cube . Center = overallMeshBounds . center ;
289+ cube . Size = localMeshBounds . size ;
290+ cube . Center = localMeshBounds . center ;
290291 }
291292
292293 part . DragCubes . ForceUpdate ( true , true ) ;
@@ -367,7 +368,7 @@ private bool IgnoredPredicate(Transform t)
367368 return true ;
368369 }
369370
370- private Bounds SetBoundsFromMeshes ( )
371+ private ( Bounds , Bounds ) SetBoundsFromMeshes ( )
371372 {
372373 if ( meshDataList . Count == 0 )
373374 {
@@ -377,16 +378,22 @@ private Bounds SetBoundsFromMeshes()
377378 }
378379
379380 Vector3 upper = Vector3 . one * float . NegativeInfinity , lower = Vector3 . one * float . PositiveInfinity ;
381+ Vector3 upperLocal = Vector3 . one * float . NegativeInfinity , lowerLocal = Vector3 . one * float . PositiveInfinity ;
380382 foreach ( GeometryMesh geoMesh in meshDataList )
381383 {
382384 if ( ! geoMesh . valid )
383385 continue ;
384386
385387 upper = Vector3 . Max ( upper , geoMesh . bounds . max ) ;
386388 lower = Vector3 . Min ( lower , geoMesh . bounds . min ) ;
389+
390+ Bounds meshBounds = GeometryMesh . TransformBounds ( geoMesh . meshLocalBounds , geoMesh . meshLocalToPart ) ;
391+ upperLocal = Vector3 . Max ( upperLocal , meshBounds . max ) ;
392+ lowerLocal = Vector3 . Max ( lowerLocal , meshBounds . min ) ;
387393 }
388394
389395 var overallBounds = new Bounds ( ( upper + lower ) * 0.5f , upper - lower ) ;
396+ var localBounds = new Bounds ( ( upperLocal + lowerLocal ) * 0.5f , upperLocal - lowerLocal ) ;
390397
391398 float tmpTestBounds = overallBounds . center . x +
392399 overallBounds . center . y +
@@ -404,7 +411,7 @@ private Bounds SetBoundsFromMeshes()
404411 Valid = true ;
405412 }
406413
407- return overallBounds ;
414+ return ( localBounds , overallBounds ) ;
408415 }
409416
410417 private void GetAnimations ( )
0 commit comments