BulletSim: set material properties for static objects. Move Linkset.MakeStatic() after call to ForceActivationState2() since linkset might change activation state. Make BSPrim.CreateGeomAndObject public as linkset rebuilding might need access to it. Only rebuild prim if selection state is actually changes -- OpenSimulator calls PhysObject.Selected() multiple times whenever a prim is selected or deselected.

0.7.5-pf-bulletsim
Robert Adams 2012-12-08 09:12:45 -08:00
parent 216c121935
commit 04e64d73df
2 changed files with 24 additions and 11 deletions

View File

@ -257,6 +257,11 @@ public sealed class BSLinksetCompound : BSLinkset
BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot); BulletSimAPI.AddChildShapeToCompoundShape2(LinksetRoot.PhysShape.ptr, cPrim.PhysShape.ptr, displacementPos, displacementRot);
} }
} }
// TODO: need to phantomize the child prims left behind.
// Maybe just destroy the children bodies and shapes and have them rebuild on unlink.
// Selection/deselection might cause way too many build/destructions esp. for LARGE linksets.
return false; // 'false' says to move onto the next child in the list return false; // 'false' says to move onto the next child in the list
}); });

View File

@ -190,6 +190,8 @@ public sealed class BSPrim : BSPhysObject
} }
public override bool Selected { public override bool Selected {
set { set {
if (value != _isSelected)
{
_isSelected = value; _isSelected = value;
PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() PhysicsScene.TaintedObject("BSPrim.setSelected", delegate()
{ {
@ -198,6 +200,7 @@ public sealed class BSPrim : BSPhysObject
}); });
} }
} }
}
public override void CrossingFailure() { return; } public override void CrossingFailure() { return; }
// link me to the specified parent // link me to the specified parent
@ -678,8 +681,11 @@ public sealed class BSPrim : BSPhysObject
CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT); CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_STATIC_OBJECT);
// Stop all movement // Stop all movement
ZeroMotion(true); ZeroMotion(true);
// Center of mass is at the center of the object
// DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); // Set various physical properties so other object interact properly
BulletSimAPI.SetFriction2(PhysBody.ptr, PhysicsScene.Params.defaultFriction);
BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.defaultRestitution);
// Mass is zero which disables a bunch of physics stuff in Bullet // Mass is zero which disables a bunch of physics stuff in Bullet
UpdatePhysicalMassProperties(0f); UpdatePhysicalMassProperties(0f);
// Set collision detection parameters // Set collision detection parameters
@ -688,13 +694,15 @@ public sealed class BSPrim : BSPhysObject
BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold); BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold);
BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius);
} }
// There can be special things needed for implementing linksets
Linkset.MakeStatic(this);
// The activation state is 'disabled' so Bullet will not try to act on it. // The activation state is 'disabled' so Bullet will not try to act on it.
// BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION); // BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_SIMULATION);
// Start it out sleeping and physical actions could wake it up. // Start it out sleeping and physical actions could wake it up.
BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING); BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.ISLAND_SLEEPING);
// There can be special things needed for implementing linksets
Linkset.MakeStatic(this);
PhysBody.collisionGroup = CollisionFilterGroups.StaticObjectGroup; PhysBody.collisionGroup = CollisionFilterGroups.StaticObjectGroup;
PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask; PhysBody.collisionMask = CollisionFilterGroups.StaticObjectMask;
} }
@ -1326,7 +1334,7 @@ public sealed class BSPrim : BSPhysObject
// Rebuild the geometry and object. // Rebuild the geometry and object.
// This is called when the shape changes so we need to recreate the mesh/hull. // This is called when the shape changes so we need to recreate the mesh/hull.
// Called at taint-time!!! // Called at taint-time!!!
private void CreateGeomAndObject(bool forceRebuild) public void CreateGeomAndObject(bool forceRebuild)
{ {
// If this prim is part of a linkset, we must remove and restore the physical // If this prim is part of a linkset, we must remove and restore the physical
// links if the body is rebuilt. // links if the body is rebuilt.
@ -1341,7 +1349,7 @@ public sealed class BSPrim : BSPhysObject
{ {
// Called if the current prim body is about to be destroyed. // Called if the current prim body is about to be destroyed.
// Remove all the physical dependencies on the old body. // Remove all the physical dependencies on the old body.
// (Maybe someday make the changing of BSShape an event handled by BSLinkset.) // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...)
needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); needToRestoreLinkset = Linkset.RemoveBodyDependencies(this);
needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this); needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this);
}); });