Пример #1
0
    // Create the correct type of linkset for this child
    public static BSLinkset Factory(BSScene physScene, BSPrimLinkable parent)
    {
        BSLinkset ret = null;

        switch (parent.LinksetType)
        {
            case LinksetImplementation.Constraint:
                ret = new BSLinksetConstraints(physScene, parent);
                break;
            case LinksetImplementation.Compound:
                ret = new BSLinksetCompound(physScene, parent);
                break;
            case LinksetImplementation.Manual:
                // ret = new BSLinksetManual(physScene, parent);
                break;
            default:
                ret = new BSLinksetCompound(physScene, parent);
                break;
        }
        if (ret == null)
        {
            physScene.Logger.ErrorFormat("[BULLETSIM LINKSET] Factory could not create linkset. Parent name={1}, ID={2}", parent.Name, parent.LocalID);
        }
        return ret;
    }
 public BSLinkInfoConstraint(BSPrimLinkable pMember)
     : base(pMember)
 {
     constraint = null;
     ResetLink();
     member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.creation", member.LocalID);
 }
Пример #3
0
        // Routine called when rebuilding the body of some member of the linkset.
        // If one of the bodies is being changed, the linkset needs rebuilding.
        // For instance, a linkset is built and then a mesh asset is read in and the mesh is recreated.
        // Returns 'true' of something was actually removed and would need restoring
        // Called at taint-time!!
        public override bool RemoveDependencies(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.RemoveDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}",
                      child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody, IsRoot(child));

            Refresh(child);

            return(ret);
        }
        // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset.
        // Only the state of the passed object can be modified. The rest of the linkset
        //     has not yet been fully constructed.
        // Return 'true' if any properties updated on the passed object.
        // Called at taint-time!
        public override bool MakeDynamic(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            if (IsRoot(child))
            {
                // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly.
                ScheduleRebuild(LinksetRoot);
            }
            return(ret);
        }
Пример #5
0
        public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
        {
            bool       ret   = false;
            BSLinkInfo found = null;

            lock (m_linksetActivityLock)
            {
                ret = m_children.TryGetValue(child, out found);
            }
            foundInfo = found;
            return(ret);
        }
Пример #6
0
        // For compound implimented linksets, if there are children, use compound shape for the root.
        public override BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
        {
            // Returning 'unknown' means we don't have a preference.
            BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN;

            if (IsRoot(requestor) && HasAnyChildren)
            {
                ret = BSPhysicsShapeType.SHAPE_COMPOUND;
            }
            // DetailLog("{0},BSLinksetCompound.PreferredPhysicalShape,call,shape={1}", LinksetRoot.LocalID, ret);
            return(ret);
        }
Пример #7
0
 public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
 {
     m_linksetActivityLock.AcquireReaderLock(-1);
     try
     {
         return(m_children.TryGetValue(child, out foundInfo));
     }
     finally
     {
         m_linksetActivityLock.ReleaseReaderLock();
     }
 }
Пример #8
0
 // Return 'true' if this child is in this linkset
 public bool HasChild(BSPrimLinkable child)
 {
     m_linksetActivityLock.AcquireReaderLock(-1);
     try
     {
         return(m_children.ContainsKey(child));
     }
     finally
     {
         m_linksetActivityLock.ReleaseReaderLock();
     }
 }
Пример #9
0
        public override bool Collide(uint collidingWith, BSPhysObject collidee,
                                     OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
        {
            // prims in the same linkset cannot collide with each other
            BSPrimLinkable convCollidee = collidee as BSPrimLinkable;

            if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID))
            {
                return(false);
            }
            return(base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth));
        }
Пример #10
0
        // The object is going static (non-physical). We do not do anything for static linksets.
        // Return 'true' if any properties updated on the passed object.
        // Called at taint-time!
        public override bool MakeStatic(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            if (IsRoot(child))
            {
                // Schedule a rebuild to verify that the root shape is set to the real shape.
                ScheduleRebuild(LinksetRoot);
            }
            return(ret);
        }
        // The object is going static (non-physical). Do any setup necessary for a static linkset.
        // Return 'true' if any properties updated on the passed object.
        // This doesn't normally happen -- OpenSim removes the objects from the physical
        //     world if it is a static linkset.
        // Called at taint-time!
        public override bool MakeStatic(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetConstraint.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            child.ClearDisplacement();
            if (IsRoot(child))
            {
                // Schedule a rebuild to verify that the root shape is set to the real shape.
                Refresh(LinksetRoot);
            }
            return(ret);
        }
Пример #12
0
        // Check the type of the link and return 'true' if the link is flexible and the
        //    updates from the child should be sent to the simulator so things change.
        public virtual bool ShouldReportPropertyUpdates(BSPrimLinkable child)
        {
            bool ret = false;

            BSLinkInfo linkInfo;

            if (m_children.TryGetValue(child, out linkInfo))
            {
                ret = linkInfo.ShouldUpdateChildProperties();
            }

            return(ret);
        }
Пример #13
0
 // Link to a linkset where the child knows the parent.
 // Parent changing should not happen so do some sanity checking.
 // We return the parent's linkset so the child can track its membership.
 // Called at runtime.
 public BSLinkset AddMeToLinkset(BSPrimLinkable child)
 {
     lock (m_linksetActivityLock)
     {
         // Don't add the root to its own linkset
         if (!IsRoot(child))
         {
             AddChildToLinkset(child);
         }
         LinksetMass = ComputeLinksetMass();
     }
     return(this);
 }
Пример #14
0
 // Schedule a refresh to happen after all the other taint processing.
 private void ScheduleRebuild(BSPrimLinkable requestor)
 {
     // When rebuilding, it is possible to set properties that would normally require a rebuild.
     //    If already rebuilding, don't request another rebuild.
     //    If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding.
     lock (m_linksetActivityLock)
     {
         if (!RebuildScheduled && !Rebuilding && HasAnyChildren)
         {
             InternalScheduleRebuild(requestor);
         }
     }
 }
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child)
        {
            if (!HasChild(child))
            {
                m_children.Add(child, new BSLinkInfo(child));

                DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Rebuild the compound shape with the new child shape included
                ScheduleRebuild(child);
            }
            return;
        }
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child)
        {
            if (!HasChild(child))
            {
                m_children.Add(child, new BSLinkInfoConstraint(child));

                DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Cause constraints and assorted properties to be recomputed before the next simulation step.
                ScheduleRebuild(LinksetRoot);
            }
            return;
        }
Пример #17
0
        // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape)
        public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement)
        {
            // Each child position and rotation is given relative to the center-of-mass.
            OMV.Quaternion invRootOrientation   = OMV.Quaternion.Inverse(root.RawOrientation);
            OMV.Vector3    displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation;
            OMV.Vector3    displacementFromCOM  = displacementFromRoot - centerDisplacement;
            OMV.Quaternion displacementRot      = child.RawOrientation * invRootOrientation;

            // Save relative position for recomputing child's world position after moving linkset.
            Index                  = indx;
            OffsetFromRoot         = displacementFromRoot;
            OffsetFromCenterOfMass = displacementFromCOM;
            OffsetRot              = displacementRot;
        }
Пример #18
0
    // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape)
    public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement)
    {
        // Each child position and rotation is given relative to the center-of-mass.
        OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(root.RawOrientation);
        OMV.Vector3 displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation;
        OMV.Vector3 displacementFromCOM = displacementFromRoot - centerDisplacement;
        OMV.Quaternion displacementRot = child.RawOrientation * invRootOrientation;

        // Save relative position for recomputing child's world position after moving linkset.
        Index = indx;
        OffsetFromRoot = displacementFromRoot;
        OffsetFromCenterOfMass = displacementFromCOM;
        OffsetRot = displacementRot;
    }
Пример #19
0
    // When physical properties are changed the linkset needs to recalculate
    //   its internal properties.
    // This is queued in the 'post taint' queue so the
    //   refresh will happen once after all the other taints are applied.
    public override void Refresh(BSPrimLinkable requestor)
    {
        base.Refresh(requestor);

        if (HasAnyChildren && IsRoot(requestor))
        {
            // Queue to happen after all the other taint processing
            PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
                {
                    if (HasAnyChildren && IsRoot(requestor))
                        RecomputeLinksetConstraints();
                });
        }
    }
Пример #20
0
        protected BSLinkset(BSScene scene, BSPrimLinkable parent)
        {
            // A simple linkset of one (no children)
            LinksetID = m_nextLinksetID++;
            // We create LOTS of linksets.
            if (m_nextLinksetID <= 0)
            m_nextLinksetID = 1;
            PhysicsScene = scene;
            LinksetRoot = parent;
            m_children = new HashSet<BSPrimLinkable>();
            LinksetMass = parent.RawMass;
            Rebuilding = false;

            parent.ClearDisplacement();
        }
        // When physical properties are changed the linkset needs to recalculate
        //   its internal properties.
        // This is queued in the 'post taint' queue so the
        //   refresh will happen once after all the other taints are applied.
        public override void Refresh(BSPrimLinkable requestor)
        {
            base.Refresh(requestor);

            if (HasAnyChildren && IsRoot(requestor))
            {
                // Queue to happen after all the other taint processing
                PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
                {
                    if (HasAnyChildren && IsRoot(requestor))
                    {
                        RecomputeLinksetConstraints();
                    }
                });
            }
        }
Пример #22
0
        public override void link(Manager.PhysicsActor obj)
        {
            BSPrimLinkable parent = obj as BSPrimLinkable;

            if (parent != null)
            {
                BSPhysObject parentBefore   = Linkset.LinksetRoot;      // DEBUG
                int          childrenBefore = Linkset.NumberOfChildren; // DEBUG

                Linkset = parent.Linkset.AddMeToLinkset(this);

                DetailLog("{0},BSPrimLinkable.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
                          LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
            }
            return;
        }
        // Routine called when rebuilding the body of some member of the linkset.
        // Destroy all the constraints have have been made to root and set
        //     up to rebuild the constraints before the next simulation step.
        // Returns 'true' of something was actually removed and would need restoring
        // Called at taint-time!!
        public override bool RemoveBodyDependencies(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
                      child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);

            lock (m_linksetActivityLock)
            {
                // Just undo all the constraints for this linkset. Rebuild at the end of the step.
                ret = PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot);
                // Cause the constraints, et al to be rebuilt before the next simulation step.
                Refresh(LinksetRoot);
            }
            return(ret);
        }
Пример #24
0
        public override bool Collide(uint collidingWith, BSPhysObject collidee,
                                     OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
        {
            // prims in the same linkset cannot collide with each other
            BSPrimLinkable convCollidee = collidee as BSPrimLinkable;

            if (convCollidee != null && (this.Linkset.LinksetID == convCollidee.Linkset.LinksetID))
            {
                return(false);
            }

            // TODO: handle collisions of other objects with with children of linkset.
            //    This is a problem for LinksetCompound since the children are packed into the root.

            return(base.Collide(collidingWith, collidee, contactPoint, contactNormal, pentrationDepth));
        }
Пример #25
0
        // Remove a child from a linkset.
        // Returns a new linkset for the child which is a linkset of one (just the
        //    orphened child).
        // Called at runtime.
        public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child)
        {
            lock (m_linksetActivityLock)
            {
                if (IsRoot(child))
                {
                    // Cannot remove the root from a linkset.
                    return(this);
                }
                RemoveChildFromLinkset(child);
                LinksetMass = ComputeLinksetMass();
            }

            // The child is down to a linkset of just itself
            return(BSLinkset.Factory(m_physicsScene, child));
        }
Пример #26
0
        protected BSLinkset(BSScene scene, BSPrimLinkable parent)
        {
            // A simple linkset of one (no children)
            LinksetID = m_nextLinksetID++;
            // We create LOTS of linksets.
            if (m_nextLinksetID <= 0)
            {
                m_nextLinksetID = 1;
            }
            m_physicsScene = scene;
            LinksetRoot    = parent;
            m_children     = new Dictionary <BSPrimLinkable, BSLinkInfo>();
            LinksetMass    = parent.RawMass;
            Rebuilding     = false;

            parent.ClearDisplacement();
        }
Пример #27
0
        public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
        {
            bool       ret   = false;
            BSLinkInfo found = null;

            m_linksetActivityLock.AcquireReaderLock(-1);
            try
            {
                ret = m_children.TryGetValue(child, out found);
            }
            finally
            {
                m_linksetActivityLock.ReleaseReaderLock();
            }
            foundInfo = found;
            return(ret);
        }
Пример #28
0
        public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
                                                  Vector3 size, Quaternion rotation, bool isPhysical, uint localID)
        {
            // m_log.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

            if (!m_initialized)
            {
                return(null);
            }

            // DetailLog("{0},BSScene.AddPrimShape,call", localID);

            BSPhysObject prim = new BSPrimLinkable(localID, primName, this, position, size, rotation, pbs, isPhysical);

            lock (PhysObjects) PhysObjects.Add(localID, prim);
            return(prim);
        }
Пример #29
0
 // Schedule a refresh to happen after all the other taint processing.
 protected override void ScheduleRebuild(BSPrimLinkable requestor)
 {
     DetailLog("{0},BSLinksetCompound.ScheduleRebuild,,rebuilding={1},hasChildren={2},actuallyScheduling={3}",
               requestor.LocalID, Rebuilding, HasAnyChildren, (!Rebuilding && HasAnyChildren));
     // When rebuilding, it is possible to set properties that would normally require a rebuild.
     //    If already rebuilding, don't request another rebuild.
     //    If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding.
     if (!Rebuilding && HasAnyChildren)
     {
         PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate()
         {
             if (HasAnyChildren)
             {
                 RecomputeLinksetCompound();
             }
         });
     }
 }
Пример #30
0
        public override void DeletePrim(PhysicsActor prim)
        {
            BSPrimLinkable linkablePrim = prim as BSPrimLinkable;

            if (linkablePrim != null && linkablePrim.Linkset.HasAnyChildren)
            {
                linkablePrim.BlockPhysicalReconstruction = true;
                //Remove all the children prims first, then kill the root
                foreach (BSPrimLinkable childPrim in linkablePrim.Linkset.Children)
                {
                    childPrim.BlockPhysicalReconstruction = true;
                    RemovePrim(childPrim);
                }
                //TODO: DISABLE LINKSET REBUILDING DURING THIS PROCESS
            }

            RemovePrim(prim);
        }
Пример #31
0
 // Link to a linkset where the child knows the parent.
 // Parent changing should not happen so do some sanity checking.
 // We return the parent's linkset so the child can track its membership.
 // Called at runtime.
 public BSLinkset AddMeToLinkset(BSPrimLinkable child)
 {
     m_linksetActivityLock.AcquireWriterLock(-1);
     try
     {
         // Don't add the root to its own linkset
         if (!IsRoot(child))
         {
             AddChildToLinkset(child);
         }
         LinksetMass = ComputeLinksetMass();
     }
     finally
     {
         m_linksetActivityLock.ReleaseWriterLock();
     }
     return(this);
 }
Пример #32
0
        public override PhysicsActor AddPrimShape(UUID primID, uint localID, string name, byte physicsType, PrimitiveBaseShape shape,
                                                  Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, int material,
                                                  float friction, float restitution, float gravityMultiplier, float density)
        {
            // MainConsole.Instance.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

            if (!m_initialized)
            {
                return(null);
            }

            // DetailLog("{0},BSScene.AddPrimShape,call", localID);

            BSPhysObject prim = new BSPrimLinkable(localID, name, this, position, size, rotation, shape, false, material, friction, restitution, gravityMultiplier, density);

            prim.UUID = primID;
            lock (PhysObjects) PhysObjects.Add(localID, prim);
            return(prim);
        }
        // Remove linkage between the linkset root and a particular child
        // The root and child bodies are passed in because we need to remove the constraint between
        //      the bodies that were present at unlink time.
        // Called at taint time!
        private bool PhysicallyUnlinkAChildFromRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
                      rootPrim.LocalID,
                      rootPrim.LocalID, rootPrim.PhysBody.AddrString,
                      childPrim.LocalID, childPrim.PhysBody.AddrString);

            // Find the constraint for this link and get rid of it from the overall collection and from my list
            if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
            {
                // Make the child refresh its location
                PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
                ret = true;
            }

            return(ret);
        }
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child, bool scheduleRebuild)
        {
            if (!this.LinksetRoot.IsPhysical)
            {
                return;
            }
            if (!HasChild(child))
            {
                m_children.Add(child);

                DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Cause constraints and assorted properties to be recomputed before the next simulation step.
                if (scheduleRebuild)
                {
                    Refresh(LinksetRoot);
                }
            }
            return;
        }
Пример #35
0
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child, bool scheduleRebuild)
        {
            if (!this.LinksetRoot.IsPhysical)
            {
                return;
            }
            if (!HasChild(child))
            {
                m_children.Add(child);

                DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Rebuild the compound shape with the new child shape included
                if (scheduleRebuild)
                {
                    ScheduleRebuild(child);
                }
            }
            return;
        }
Пример #36
0
        // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset.
        // Only the state of the passed object can be modified. The rest of the linkset
        //     has not yet been fully constructed.
        // Return 'true' if any properties updated on the passed object.
        // Called at taint-time!
        public override bool MakeDynamic(BSPrimLinkable child)
        {
            bool ret = false;
            DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            if (IsRoot(child))
            {
            // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly.
            ScheduleRebuild(LinksetRoot);
            }
            else
            {
            // The origional prims are removed from the world as the shape of the root compound
            //     shape takes over.
            PhysicsScene.PE.AddToCollisionFlags(child.PhysBody, CollisionFlags.CF_NO_CONTACT_RESPONSE);
            PhysicsScene.PE.ForceActivationState(child.PhysBody, ActivationState.DISABLE_SIMULATION);
            // We don't want collisions from the old linkset children.
            PhysicsScene.PE.RemoveFromCollisionFlags(child.PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);

            child.PhysBody.collisionType = CollisionType.LinksetChild;

            ret = true;
            }
            return ret;
        }
Пример #37
0
 // I am the root of a linkset and a new child is being added
 // Called while LinkActivity is locked.
 protected abstract void AddChildToLinkset(BSPrimLinkable child);
Пример #38
0
 // Return 'true' if the passed object is the root object of this linkset
 public bool IsRoot(BSPrimLinkable requestor)
 {
     return (requestor.LocalID == LinksetRoot.LocalID);
 }
Пример #39
0
 public BSLinkInfo(BSPrimLinkable pMember)
 {
     member = pMember;
 }
Пример #40
0
 // Return 'true' if this child is in this linkset
 public bool HasChild(BSPrimLinkable child)
 {
     m_linksetActivityLock.AcquireReaderLock(-1);
     try
     {
         return m_children.ContainsKey(child);
     }
     finally
     {
         m_linksetActivityLock.ReleaseReaderLock();
     }
 }
Пример #41
0
 public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
 {
     m_linksetActivityLock.AcquireReaderLock(-1);
     try
     {
         return m_children.TryGetValue(child, out foundInfo);
     }
     finally
     {
         m_linksetActivityLock.ReleaseReaderLock();
     }
 }
Пример #42
0
    // Remove the specified child from the linkset.
    // Safe to call even if the child is not really in my linkset.
    protected override void RemoveChildFromLinkset(BSPrimLinkable child)
    {
        if (m_children.Remove(child))
        {
            BSPrimLinkable rootx = LinksetRoot; // capture the root and body as of now
            BSPrimLinkable childx = child;

            DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
                            childx.LocalID,
                            rootx.LocalID, rootx.PhysBody.AddrString,
                            childx.LocalID, childx.PhysBody.AddrString);

            PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate()
            {
                PhysicallyUnlinkAChildFromRoot(rootx, childx);
            });
            // See that the linkset parameters are recomputed at the end of the taint time.
            Refresh(LinksetRoot);
        }
        else
        {
            // Non-fatal occurance.
            // PhysicsScene.Logger.ErrorFormat("{0}: Asked to remove child from linkset that was not in linkset", LogHeader);
        }
        return;
    }
Пример #43
0
 // When physical properties are changed the linkset needs to recalculate
 //   its internal properties.
 // May be called at runtime or taint-time.
 public virtual void Refresh(BSPrimLinkable requestor)
 {
     LinksetMass = ComputeLinksetMass();
 }
Пример #44
0
 // The object is going static (non-physical). Do any setup necessary
 //     for a static linkset.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeStatic(BSPrimLinkable child);
Пример #45
0
        public override PhysicsActor AddPrimShape(UUID primID, uint localID, string name, byte physicsType, PrimitiveBaseShape shape,
            Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, int material,
            float friction, float restitution, float gravityMultiplier, float density)
        {
            // MainConsole.Instance.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

            if (!m_initialized) return null;

            // DetailLog("{0},BSScene.AddPrimShape,call", localID);

            BSPhysObject prim = new BSPrimLinkable(localID, name, this, position, size, rotation, shape, false, material, friction, restitution, gravityMultiplier, density);
            prim.UUID = primID;
            lock (PhysObjects) PhysObjects.Add(localID, prim);
            return prim;
        }
Пример #46
0
    // Remove linkage between myself and any possible children I might have.
    // Returns 'true' of any constraints were destroyed.
    // Called at taint time!
    private bool PhysicallyUnlinkAllChildrenFromRoot(BSPrimLinkable rootPrim)
    {
        DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID);

        return PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody);
    }
Пример #47
0
    // Remove linkage between the linkset root and a particular child
    // The root and child bodies are passed in because we need to remove the constraint between
    //      the bodies that were present at unlink time.
    // Called at taint time!
    private bool PhysicallyUnlinkAChildFromRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
    {
        bool ret = false;
        DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
                            rootPrim.LocalID,
                            rootPrim.LocalID, rootPrim.PhysBody.AddrString,
                            childPrim.LocalID, childPrim.PhysBody.AddrString);

        // Find the constraint for this link and get rid of it from the overall collection and from my list
        if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
        {
            // Make the child refresh its location
            PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
            ret = true;
        }

        return ret;
    }
Пример #48
0
    private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
    {
        // Zero motion for children so they don't interpolate
        childPrim.ZeroMotion(true);

        // Relative position normalized to the root prim
        // Essentually a vector pointing from center of rootPrim to center of childPrim
        OMV.Vector3 childRelativePosition = childPrim.Position - rootPrim.Position;

        // real world coordinate of midpoint between the two objects
        OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);

        DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
                                        rootPrim.LocalID,
                                        rootPrim.LocalID, rootPrim.PhysBody.AddrString,
                                        childPrim.LocalID, childPrim.PhysBody.AddrString,
                                        rootPrim.Position, childPrim.Position, midPoint);

        // create a constraint that allows no freedom of movement between the two objects
        // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818

        BSConstraint6Dof constrain = new BSConstraint6Dof(
                            PhysicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true );
                            // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true );

        /* NOTE: below is an attempt to build constraint with full frame computation, etc.
         *     Using the midpoint is easier since it lets the Bullet code manipulate the transforms
         *     of the objects.
         * Code left for future programmers.
        // ==================================================================================
        // relative position normalized to the root prim
        OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
        OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation;

        // relative rotation of the child to the parent
        OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation;
        OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);

        DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
        BS6DofConstraint constrain = new BS6DofConstraint(
                        PhysicsScene.World, rootPrim.Body, childPrim.Body,
                        OMV.Vector3.Zero,
                        OMV.Quaternion.Inverse(rootPrim.Orientation),
                        OMV.Vector3.Zero,
                        OMV.Quaternion.Inverse(childPrim.Orientation),
                        true,
                        true
                        );
        // ==================================================================================
        */

        PhysicsScene.Constraints.AddConstraint(constrain);

        // zero linear and angular limits makes the objects unable to move in relation to each other
        constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
        constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);

        // tweek the constraint to increase stability
        constrain.UseFrameOffset(BSParam.LinkConstraintUseFrameOffset);
        constrain.TranslationalLimitMotor(BSParam.LinkConstraintEnableTransMotor,
                        BSParam.LinkConstraintTransMotorMaxVel,
                        BSParam.LinkConstraintTransMotorMaxForce);
        constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP);
        if (BSParam.LinkConstraintSolverIterations != 0f)
        {
            constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations);
        }
        return constrain;
    }
Пример #49
0
 // Create a constraint between me (root of linkset) and the passed prim (the child).
 // Called at taint time!
 private void PhysicallyLinkAChildToRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
 {
     // Don't build the constraint when asked. Put it off until just before the simulation step.
     Refresh(rootPrim);
 }
Пример #50
0
 // I am the root of a linkset and one of my children is being removed.
 // Safe to call even if the child is not really in my linkset.
 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime);
Пример #51
0
 // Called at taint-time!!
 public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable pObj)
 {
     // Nothing to do for constraints on property updates
 }
Пример #52
0
    // Routine called when rebuilding the body of some member of the linkset.
    // Destroy all the constraints have have been made to root and set
    //     up to rebuild the constraints before the next simulation step.
    // Returns 'true' of something was actually removed and would need restoring
    // Called at taint-time!!
    public override bool RemoveBodyDependencies(BSPrimLinkable child)
    {
        bool ret = false;

        DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
                                    child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);

        lock (m_linksetActivityLock)
        {
            // Just undo all the constraints for this linkset. Rebuild at the end of the step.
            ret = PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot);
            // Cause the constraints, et al to be rebuilt before the next simulation step.
            Refresh(LinksetRoot);
        }
        return ret;
    }
Пример #53
0
    // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";

    public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent)
    {
    }
Пример #54
0
    // ================================================================

    // Add a new child to the linkset.
    // Called while LinkActivity is locked.
    protected override void AddChildToLinkset(BSPrimLinkable child)
    {
        if (!HasChild(child))
        {
            m_children.Add(child);

            DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

            // Cause constraints and assorted properties to be recomputed before the next simulation step.
            Refresh(LinksetRoot);
        }
        return;
    }
Пример #55
0
    // Check the type of the link and return 'true' if the link is flexible and the
    //    updates from the child should be sent to the simulator so things change.
    public virtual bool ShouldReportPropertyUpdates(BSPrimLinkable child)
    {
        bool ret = false;

        BSLinkInfo linkInfo;
        if (m_children.TryGetValue(child, out linkInfo))
        {
            ret = linkInfo.ShouldUpdateChildProperties();
        }

        return ret;
    }
Пример #56
0
 // The object is going static (non-physical). Do any setup necessary for a static linkset.
 // Return 'true' if any properties updated on the passed object.
 // This doesn't normally happen -- OpenSim removes the objects from the physical
 //     world if it is a static linkset.
 // Called at taint-time!
 public override bool MakeStatic(BSPrimLinkable child)
 {
     // What is done for each object in BSPrim is what we want.
     return false;
 }
Пример #57
0
 // Called when a parameter update comes from the physics engine for any object
 //      of the linkset is received.
 // Passed flag is update came from physics engine (true) or the user (false).
 // Called at taint-time!!
 public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable physObject);
Пример #58
0
 // The object is going dynamic (physical). Do any setup necessary
 //     for a dynamic linkset.
 // Only the state of the passed object can be modified. The rest of the linkset
 //     has not yet been fully constructed.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeDynamic(BSPrimLinkable child);
Пример #59
0
    public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
                                              Vector3 size, Quaternion rotation, bool isPhysical, uint localID)
    {
        // m_log.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

        if (!m_initialized) return null;

        // DetailLog("{0},BSScene.AddPrimShape,call", localID);

        BSPhysObject prim = new BSPrimLinkable(localID, primName, this, position, size, rotation, pbs, isPhysical);
        lock (PhysObjects) PhysObjects.Add(localID, prim);
        return prim;
    }
Пример #60
0
 // Routine used when rebuilding the body of the root of the linkset
 // Destroy all the constraints have have been made to root.
 // This is called when the root body is changing.
 // Returns 'true' of something was actually removed and would need restoring
 // Called at taint-time!!
 public abstract bool RemoveDependencies(BSPrimLinkable child);