diff options
author | Robert Adams | 2013-04-28 21:44:06 -0700 |
---|---|---|
committer | Robert Adams | 2013-04-29 07:38:51 -0700 |
commit | 21ec4346884d6cc02f67bbbdafa49f3b5db5426e (patch) | |
tree | 4bda0b70e412c36e23e9910506f53be5ee6954ac /OpenSim/Region | |
parent | BulletSim: fix crash when creating new hull. (diff) | |
download | opensim-SC_OLD-21ec4346884d6cc02f67bbbdafa49f3b5db5426e.zip opensim-SC_OLD-21ec4346884d6cc02f67bbbdafa49f3b5db5426e.tar.gz opensim-SC_OLD-21ec4346884d6cc02f67bbbdafa49f3b5db5426e.tar.bz2 opensim-SC_OLD-21ec4346884d6cc02f67bbbdafa49f3b5db5426e.tar.xz |
BulletSim: first cut at new linksetCompound shape building.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | 90 |
1 files changed, 27 insertions, 63 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index a20bbc3..be01808 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs | |||
@@ -93,9 +93,12 @@ public sealed class BSLinksetCompound : BSLinkset | |||
93 | { | 93 | { |
94 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; | 94 | private static string LogHeader = "[BULLETSIM LINKSET COMPOUND]"; |
95 | 95 | ||
96 | private BSShape LinksetShape; | ||
97 | |||
96 | public BSLinksetCompound(BSScene scene, BSPrimLinkable parent) | 98 | public BSLinksetCompound(BSScene scene, BSPrimLinkable parent) |
97 | : base(scene, parent) | 99 | : base(scene, parent) |
98 | { | 100 | { |
101 | LinksetShape = new BSShapeNull(); | ||
99 | } | 102 | } |
100 | 103 | ||
101 | // When physical properties are changed the linkset needs to recalculate | 104 | // When physical properties are changed the linkset needs to recalculate |
@@ -391,22 +394,21 @@ public sealed class BSLinksetCompound : BSLinkset | |||
391 | { | 394 | { |
392 | try | 395 | try |
393 | { | 396 | { |
394 | /* | 397 | // This replaces the physical shape of the root prim with a compound shape made up of the root |
395 | // Suppress rebuilding while rebuilding. (We know rebuilding is on only one thread.) | 398 | // shape and all the children. |
396 | Rebuilding = true; | 399 | |
400 | // RootPrim.PhysShape is the shape of the root prim. | ||
401 | // Here we build the compound shape made up of all the children. | ||
402 | |||
403 | // Free up any shape we'd previously built. | ||
404 | LinksetShape.Dereference(PhysicsScene); | ||
397 | 405 | ||
398 | // Cause the root shape to be rebuilt as a compound object with just the root in it | 406 | LinksetShape = BSShapeCompound.GetReference(PhysicsScene, LinksetRoot); |
399 | LinksetRoot.ForceBodyShapeRebuild(true /* inTaintTime ); | ||
400 | 407 | ||
401 | // The center of mass for the linkset is the geometric center of the group. | 408 | // The center of mass for the linkset is the geometric center of the group. |
402 | // Compute a displacement for each component so it is relative to the center-of-mass. | 409 | // Compute a displacement for each component so it is relative to the center-of-mass. |
403 | // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass | 410 | // Bullet presumes an object's origin (relative <0,0,0>) is its center-of-mass |
404 | OMV.Vector3 centerOfMassW = LinksetRoot.RawPosition; | 411 | OMV.Vector3 centerOfMassW = ComputeLinksetCenterOfMass(); |
405 | if (!disableCOM) // DEBUG DEBUG | ||
406 | { | ||
407 | // Compute a center-of-mass in world coordinates. | ||
408 | centerOfMassW = ComputeLinksetCenterOfMass(); | ||
409 | } | ||
410 | 412 | ||
411 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); | 413 | OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(LinksetRoot.RawOrientation); |
412 | 414 | ||
@@ -414,20 +416,7 @@ public sealed class BSLinksetCompound : BSLinkset | |||
414 | OMV.Vector3 centerDisplacement = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; | 416 | OMV.Vector3 centerDisplacement = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation; |
415 | LinksetRoot.SetEffectiveCenterOfMassW(centerDisplacement); | 417 | LinksetRoot.SetEffectiveCenterOfMassW(centerDisplacement); |
416 | 418 | ||
417 | // This causes the physical position of the root prim to be offset to accomodate for the displacements | 419 | // TODO: add phantom root shape to be the center-of-mass |
418 | LinksetRoot.ForcePosition = LinksetRoot.RawPosition; | ||
419 | |||
420 | // Update the local transform for the root child shape so it is offset from the <0,0,0> which is COM | ||
421 | PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape.physShapeInfo, 0 /* childIndex , | ||
422 | -centerDisplacement, | ||
423 | OMV.Quaternion.Identity, // LinksetRoot.RawOrientation, | ||
424 | false /* shouldRecalculateLocalAabb (is done later after linkset built) ); | ||
425 | |||
426 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,com={1},rootPos={2},centerDisp={3}", | ||
427 | LinksetRoot.LocalID, centerOfMassW, LinksetRoot.RawPosition, centerDisplacement); | ||
428 | |||
429 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,start,rBody={1},rShape={2},numChildren={3}", | ||
430 | LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetRoot.PhysShape, NumberOfChildren); | ||
431 | 420 | ||
432 | // Add a shape for each of the other children in the linkset | 421 | // Add a shape for each of the other children in the linkset |
433 | int memberIndex = 1; | 422 | int memberIndex = 1; |
@@ -440,56 +429,31 @@ public sealed class BSLinksetCompound : BSLinkset | |||
440 | else | 429 | else |
441 | { | 430 | { |
442 | cPrim.LinksetChildIndex = memberIndex; | 431 | cPrim.LinksetChildIndex = memberIndex; |
432 | } | ||
443 | 433 | ||
444 | if (cPrim.PhysShape.isNativeShape) | 434 | BSShape childShape = cPrim.PhysShape; |
445 | { | 435 | childShape.IncrementReference(); |
446 | // A native shape is turned into a hull collision shape because native | 436 | OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; |
447 | // shapes are not shared so we have to hullify it so it will be tracked | 437 | OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; |
448 | // and freed at the correct time. This also solves the scaling problem | 438 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot); |
449 | // (native shapes scale but hull/meshes are assumed to not be). | 439 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", |
450 | // TODO: decide of the native shape can just be used in the compound shape. | ||
451 | // Use call to CreateGeomNonSpecial(). | ||
452 | BulletShape saveShape = cPrim.PhysShape; | ||
453 | cPrim.PhysShape.Clear(); // Don't let the create free the child's shape | ||
454 | PhysicsScene.Shapes.CreateGeomMeshOrHull(cPrim, null); | ||
455 | BulletShape newShape = cPrim.PhysShape; | ||
456 | cPrim.PhysShape = saveShape; | ||
457 | |||
458 | OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; | ||
459 | OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; | ||
460 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, newShape, offsetPos, offsetRot); | ||
461 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", | ||
462 | LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, newShape, offsetPos, offsetRot); | ||
463 | } | ||
464 | else | ||
465 | { | ||
466 | // For the shared shapes (meshes and hulls), just use the shape in the child. | ||
467 | // The reference count added here will be decremented when the compound shape | ||
468 | // is destroyed in BSShapeCollection (the child shapes are looped over and dereferenced). | ||
469 | if (PhysicsScene.Shapes.ReferenceShape(cPrim.PhysShape)) | ||
470 | { | ||
471 | PhysicsScene.Logger.ErrorFormat("{0} Rebuilt sharable shape when building linkset! Region={1}, primID={2}, shape={3}", | ||
472 | LogHeader, PhysicsScene.RegionName, cPrim.LocalID, cPrim.PhysShape); | ||
473 | } | ||
474 | OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; | ||
475 | OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; | ||
476 | PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); | ||
477 | DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNonNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", | ||
478 | LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); | 440 | LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); |
479 | 441 | ||
480 | } | 442 | memberIndex++; |
481 | memberIndex++; | 443 | |
482 | } | ||
483 | return false; // 'false' says to move onto the next child in the list | 444 | return false; // 'false' says to move onto the next child in the list |
484 | }); | 445 | }); |
485 | 446 | ||
447 | // Sneak the built compound shape in as the shape of the root prim. | ||
448 | // Note this doesn't touch the root prim's PhysShape so be sure the manage the difference. | ||
449 | PhysicsScene.PE.SetCollisionShape(PhysicsScene.World, LinksetRoot.PhysBody, LinksetShape.physShapeInfo); | ||
450 | |||
486 | // With all of the linkset packed into the root prim, it has the mass of everyone. | 451 | // With all of the linkset packed into the root prim, it has the mass of everyone. |
487 | LinksetMass = ComputeLinksetMass(); | 452 | LinksetMass = ComputeLinksetMass(); |
488 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); | 453 | LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true); |
489 | 454 | ||
490 | // Enable the physical position updator to return the position and rotation of the root shape | 455 | // Enable the physical position updator to return the position and rotation of the root shape |
491 | PhysicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); | 456 | PhysicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE); |
492 | */ | ||
493 | } | 457 | } |
494 | finally | 458 | finally |
495 | { | 459 | { |