28 using System.Collections.Generic;
31 using OMV = OpenMetaverse;
33 namespace OpenSim.Region.PhysicsModule.BulletS
53 case LinksetImplementation.Constraint:
56 case LinksetImplementation.Compound:
59 case LinksetImplementation.Manual:
68 physScene.Logger.ErrorFormat(
"[BULLETSIM LINKSET] Factory could not create linkset. Parent name={1}, ID={2}", parent.Name, parent.LocalID);
90 protected BSScene m_physicsScene {
get;
private set; }
92 static int m_nextLinksetID = 1;
93 public int LinksetID {
get;
private set; }
97 protected Dictionary<BSPrimLinkable, BSLinkInfo>
m_children;
102 protected object m_linksetActivityLock =
new Object();
105 public float LinksetMass {
get;
protected set; }
107 public virtual bool LinksetIsColliding {
get {
return false; } }
109 public OMV.Vector3 CenterOfMass
111 get {
return ComputeLinksetCenterOfMass(); }
114 public OMV.Vector3 GeometricCenter
116 get {
return ComputeLinksetGeometricCenter(); }
122 LinksetID = m_nextLinksetID++;
124 if (m_nextLinksetID <= 0)
126 m_physicsScene = scene;
127 LinksetRoot = parent;
128 m_children =
new Dictionary<BSPrimLinkable, BSLinkInfo>();
129 LinksetMass = parent.RawMass;
131 RebuildScheduled =
false;
133 parent.ClearDisplacement();
142 lock (m_linksetActivityLock)
146 AddChildToLinkset(child);
147 LinksetMass = ComputeLinksetMass();
158 lock (m_linksetActivityLock)
165 RemoveChildFromLinkset(child, inTaintTime);
166 LinksetMass = ComputeLinksetMass();
170 return BSLinkset.Factory(m_physicsScene, child);
176 return (requestor.
LocalID == LinksetRoot.LocalID);
179 public int NumberOfChildren {
get {
return m_children.Count; } }
182 public bool HasAnyChildren {
get {
return (m_children.Count > 0); } }
188 lock (m_linksetActivityLock)
190 ret = m_children.ContainsKey(child);
201 lock (m_linksetActivityLock)
217 lock (m_linksetActivityLock)
219 ret = m_children.TryGetValue(child, out found);
226 public delegate
bool ForEachLinkInfoAction(BSLinkInfo obj);
230 lock (m_linksetActivityLock)
248 if (m_children.TryGetValue(child, out linkInfo))
250 ret = linkInfo.ShouldUpdateChildProperties();
261 OMV.Vector3 contactPoint,
OMV.Vector3 contactNormal,
float pentrationDepth)
277 LinksetRoot.SomeCollisionSimulationStep = m_physicsScene.SimulationStep;
289 protected abstract void RemoveChildFromLinkset(
BSPrimLinkable child,
bool inTaintTime);
296 LinksetMass = ComputeLinksetMass();
302 protected bool Rebuilding {
get; set; }
309 public bool RebuildScheduled {
get;
protected set; }
319 public virtual bool AllPartsComplete
323 this.ForEachMember((member) =>
325 if ((!member.IsInitialized) || member.IsIncomplete || member.PrimAssetState == BSPhysObject.PrimAssetCondition.Waiting)
359 ForEachMember((member) =>
361 if (member.PhysBody.HasPhysicalBody)
362 m_physicsScene.PE.SetFriction(member.PhysBody, friction);
369 ForEachMember((member) =>
371 if (member.PhysBody.HasPhysicalBody)
372 m_physicsScene.PE.SetRestitution(member.PhysBody, restitution);
379 ForEachMember((member) =>
381 if (member.PhysBody.HasPhysicalBody)
382 m_physicsScene.PE.SetGravity(member.PhysBody, gravity);
389 ForEachMember((member) =>
391 if (member.PhysBody.HasPhysicalBody)
393 OMV.Vector3 inertia = m_physicsScene.PE.CalculateLocalInertia(member.PhysShape.physShapeInfo, linksetMass);
394 member.Inertia = inertia * inertiaFactor;
395 m_physicsScene.PE.SetMassProps(member.PhysBody, linksetMass, member.Inertia);
396 m_physicsScene.PE.UpdateInertiaTensor(member.PhysBody);
397 DetailLog(
"{0},BSLinkset.ComputeAndSetLocalInertia,m.mass={1}, inertia={2}", member.LocalID, linksetMass, member.Inertia);
406 ForEachMember((member) =>
408 if (member.PhysBody.HasPhysicalBody)
409 m_physicsScene.PE.SetCollisionFlags(member.PhysBody, collFlags);
416 ForEachMember((member) =>
418 if (member.PhysBody.HasPhysicalBody)
419 m_physicsScene.PE.AddToCollisionFlags(member.PhysBody, collFlags);
426 ForEachMember((member) =>
428 if (member.PhysBody.HasPhysicalBody)
429 m_physicsScene.PE.RemoveFromCollisionFlags(member.PhysBody, collFlags);
437 float mass = LinksetRoot.RawMass;
440 lock (m_linksetActivityLock)
455 lock (m_linksetActivityLock)
457 com = LinksetRoot.Position * LinksetRoot.RawMass;
458 float totalMass = LinksetRoot.RawMass;
462 com += bp.Position * bp.RawMass;
463 totalMass += bp.RawMass;
475 lock (m_linksetActivityLock)
477 com = LinksetRoot.Position;
483 com /= (m_children.Count + 1);
490 public virtual object Extension(
string pFunct, params
object[] pParams)
494 #endregion // Extension
497 protected void DetailLog(
string msg, params Object[] args)
499 if (m_physicsScene.PhysicsLogging.Enabled)
500 m_physicsScene.DetailLog(msg, args);
bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
virtual bool HandleCollide(BSPhysObject collider, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
virtual void SetPhysicalCollisionFlags(CollisionFlags collFlags)
virtual OMV.Vector3 ComputeLinksetGeometricCenter()
bool IsRoot(BSPrimLinkable requestor)
BSLinkInfo(BSPrimLinkable pMember)
virtual void RemoveFromPhysicalCollisionFlags(CollisionFlags collFlags)
virtual float ComputeLinksetMass()
BSLinkset.LinksetImplementation LinksetType
virtual void SetPhysicalGravity(OMV.Vector3 gravity)
Dictionary< BSPrimLinkable, BSLinkInfo > m_children
BSLinkset RemoveMeFromLinkset(BSPrimLinkable child, bool inTaintTime)
virtual void SetPhysicalFriction(float friction)
BSLinkset AddMeToLinkset(BSPrimLinkable child)
virtual void SetLinkParameters(BSConstraint constrain)
virtual bool ShouldUpdateChildProperties()
virtual void AddToPhysicalCollisionFlags(CollisionFlags collFlags)
virtual OMV.Vector3 ComputeLinksetCenterOfMass()
virtual void ComputeAndSetLocalInertia(OMV.Vector3 inertiaFactor, float linksetMass)
virtual void SetPhysicalRestitution(float restitution)
void DetailLog(string msg, params Object[] args)
virtual object Extension(string pFunct, params object[] pParams)
static BSLinkset Factory(BSScene physScene, BSPrimLinkable parent)
virtual bool ForEachMember(ForEachMemberAction action)
virtual bool ShouldReportPropertyUpdates(BSPrimLinkable child)
virtual void Refresh(BSPrimLinkable requestor)
bool HasChild(BSPrimLinkable child)
virtual bool ForEachLinkInfo(ForEachLinkInfoAction action)
BSLinkset(BSScene scene, BSPrimLinkable parent)