Example #1
0
        private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation, int linkNum)
        {
            Quaternion parentRot = oldGroupRotation;
            Quaternion oldRot = part.RotationOffset;
            Quaternion worldRot = parentRot * oldRot;

            Vector3 partOffsetPosition = part.OffsetPosition;
            Vector3 partGroupPosition = part.GroupPosition;
            Quaternion partRotationOffset = part.RotationOffset;

            parentRot = oldGroupRotation;

            Vector3 axPos = partOffsetPosition;
            axPos *= parentRot;
            partOffsetPosition = axPos;

            partGroupPosition = oldGroupPosition + partOffsetPosition;
            partOffsetPosition = Vector3.Zero;
            partRotationOffset = worldRot;

            // Caller locks m_parts for us
            m_parts.Add(part.UUID, part);
            this.TrackLocalId(part, part.LocalId);

            part.LinkNum = linkNum;

            partOffsetPosition = partGroupPosition - AbsolutePosition;

            Quaternion rootRotation = m_rootPart.RotationOffset;

            Vector3 pos = partOffsetPosition;
            pos *= Quaternion.Inverse(rootRotation);
            partOffsetPosition = pos;

            parentRot = m_rootPart.RotationOffset;
            oldRot = partRotationOffset;
            Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot;
            partRotationOffset = newRot;

            part.SetOffsetPositionDirect(partOffsetPosition);
            part.SetGroupPositionDirect(partGroupPosition);
            part.SetRotationOffsetDirect(partRotationOffset);

            part.ParentID = m_rootPart.LocalId;
            part.SetParentAndUpdatePhysics(this);
        }
Example #2
0
        public void DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents, bool sendGroupUpdate)
        {
            linkPart.ClearUndoState();
            //                m_log.DebugFormat(
            //                    "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
            //                    linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);

            Quaternion worldRot = linkPart.GetWorldRotation();

            // Remove the part from this object
            lock (m_parts)
            {
                m_parts.Remove(linkPart.UUID);
                _partsByLocalId.Remove(linkPart.LocalId);

                if (m_parts.Count == 1 && RootPart != null) //Single prim is left
                {
                    RootPart.LinkNum = 0;
                }
                else
                {
                    foreach (SceneObjectPart p in m_parts.Values)
                    {
                        if (p.LinkNum > linkPart.LinkNum)
                            p.LinkNum--;
                    }
                }
            }

            linkPart.ParentID = 0;
            linkPart.LinkNum = 0;

            // We need to reset the child part's position
            // ready for life as a separate object after being a part of another object
            Quaternion parentRot = m_rootPart.RotationOffset;

            Vector3 axPos = linkPart.OffsetPosition;
            axPos *= parentRot;

            Vector3 groupPosition = AbsolutePosition + axPos;

            linkPart.SetGroupPositionDirect(groupPosition);
            linkPart.SetOffsetPositionDirect(Vector3.Zero);
            linkPart.SetRotationOffsetDirect(worldRot);

            SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);

            PhysicsActor partActor = linkPart.PhysActor;
            if (partActor != null)
            {
                partActor.DelinkFromParent(groupPosition, worldRot);
            }

            m_scene.AddNewSceneObject(objectGroup, true);

            if (sendEvents)
                linkPart.TriggerScriptChangedEvent(Changed.LINK);

            linkPart.Rezzed = RootPart.Rezzed;

            //Rebuild the bounding box
            ClearBoundingBoxCache();

            // Update the ServerWeight/LandImpact and StreamingCost
            RecalcPrimWeights();

            if (sendGroupUpdate)
            {
                HasGroupChanged = true;
                ScheduleGroupForFullUpdate();
                objectGroup.ScheduleGroupForFullUpdate();
            }
        }