Inheritance: ISceneEntity
        public RegionData LoadBackup(string file)
        {
            if (!File.Exists(file))
                return null;
            try
            {
                FileStream stream = File.OpenRead(file);
                RegionData regiondata = ProtoBuf.Serializer.Deserialize<RegionData>(stream);
                stream.Close();

                List<SceneObjectGroup> grps = new List<SceneObjectGroup>();

                if (regiondata.Groups != null)
                {
                    foreach (SceneObjectGroup grp in regiondata.Groups)
                    {
                        SceneObjectGroup sceneObject = new SceneObjectGroup(grp.ChildrenList[0], null);
                        foreach (SceneObjectPart part in grp.ChildrenList)
                        {
                            if (part.UUID == sceneObject.UUID)
                                continue;
                            sceneObject.AddChild(part, part.LinkNum);

                            part.StoreUndoState();
                        }
                        grps.Add(sceneObject);
                    }
                    regiondata.Groups = grps;
                }
                else
                    regiondata.Groups = new List<SceneObjectGroup>();
                return regiondata;
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Warn("[ProtobufRegionLoader]: Failed to load backup: " + ex.ToString());
                return null;
            }
        }
 void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
 {
 }
        /// <summary>
        ///     Create a New SceneObjectGroup/Part by raycasting
        /// </summary>
        /// <param name="ownerID"></param>
        /// <param name="groupID"></param>
        /// <param name="pos"></param>
        /// <param name="rot"></param>
        /// <param name="shape"></param>
        public virtual ISceneEntity AddNewPrim (
            UUID ownerID, UUID groupID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
        {
            SceneObjectGroup sceneObject = new SceneObjectGroup (ownerID, pos, rot, shape, m_DefaultObjectName,
                                                                m_parentScene);

            // If an entity creator has been registered for this prim type then use that
            if (m_entityCreators.ContainsKey ((PCode)shape.PCode)) {
                sceneObject =
                    (SceneObjectGroup)
                    m_entityCreators [(PCode)shape.PCode].CreateEntity (sceneObject, ownerID, groupID, pos, rot, shape);
            } else {
                // Otherwise, use this default creation code;
                sceneObject.SetGroup (groupID, ownerID, false);
                AddPrimToScene (sceneObject);
                sceneObject.ScheduleGroupUpdate (PrimUpdateFlags.ForcedFullUpdate);
            }


            return sceneObject;
        }
        /// <summary>
        ///     Delink the given prim from this group.  The delinked prim is established as
        ///     an independent SceneObjectGroup.
        /// </summary>
        /// <param name="part"></param>
        /// <param name="sendEvents"></param>
        /// <returns>The object group of the newly delinked prim.</returns>
        public ISceneEntity DelinkFromGroup(ISceneChildEntity part, bool sendEvents)
        {
            if (!(part is SceneObjectPart))
                return null;
            SceneObjectPart linkPart = part as SceneObjectPart;
                //MainConsole.Instance.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
            m_scene.SceneGraph.DeLinkPartFromEntity(this, linkPart);
            linkPart.SetParentLocalId(0);
            linkPart.LinkNum = 0;

            if (linkPart.PhysActor != null)
            {
                m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
                linkPart.PhysActor = null;
            }

            // 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.GetRotationOffset();

            Vector3 axPos = linkPart.OffsetPosition;

            axPos *= parentRot;
            linkPart.SetOffsetPosition(axPos);
            linkPart.FixGroupPosition(AbsolutePosition + linkPart.OffsetPosition, false);
            linkPart.FixOffsetPosition(Vector3.Zero, false);

            linkPart.SetRotationOffset(true, worldRot, true);

            SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart, Scene);
            m_scene.SceneGraph.DelinkPartToScene(objectGroup);

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

            linkPart.Rezzed = RootPart.Rezzed;

            //We need to send this so that we don't have issues with the client not realizing that the prims were unlinked
            ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);

            m_ValidgrpOOB = false;
            return objectGroup;
        }
        /// <summary>
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="assetDescription"></param>
        /// <param name="assetID"></param>
        /// <param name="inventoryItem"></param>
        /// <param name="parentFolder"></param>
        /// <param name="data"></param>
        /// <param name="inventoryType"></param>
        /// <param name="assetType"></param>
        /// <param name="everyoneMask"></param>
        /// <param name="groupMask"></param>
        /// <param name="nextOwnerMask"></param>
        public UUID UploadCompleteHandler (string assetName, string assetDescription, UUID assetID,
                                           UUID inventoryItem, UUID parentFolder, byte [] data, string inventoryType,
                                           string assetType, uint everyoneMask, uint groupMask, uint nextOwnerMask)
        {
            sbyte assType = 0;
            sbyte inType = 0;

            switch (inventoryType) {
            case "sound":
                inType = 1;
                assType = 1;
                break;
            case "animation":
                inType = 19;
                assType = 20;
                break;
            case "snapshot":
                inType = 15;
                assType = 0;
                break;
            case "wearable":
                inType = 18;
                switch (assetType) {
                case "bodypart":
                    assType = 13;
                    break;
                case "clothing":
                    assType = 5;
                    break;
                }
                break;
            case "object": {
                    inType = (sbyte)InventoryType.Object;
                    assType = (sbyte)AssetType.Object;

                    List<Vector3> positions = new List<Vector3> ();
                    List<Quaternion> rotations = new List<Quaternion> ();
                    OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml (data);
                    OSDArray instance_list = (OSDArray)request ["instance_list"];
                    OSDArray mesh_list = (OSDArray)request ["mesh_list"];
                    OSDArray texture_list = (OSDArray)request ["texture_list"];
                    SceneObjectGroup grp = null;

                    List<UUID> textures = new List<UUID> ();
                    foreach (
                            AssetBase textureAsset in
                                texture_list.Select (t => new AssetBase (UUID.Random (), assetName, AssetType.Texture,
                                                                        m_agentID) { Data = t.AsBinary () })) {
                        textureAsset.ID = m_assetService.Store (textureAsset);
                        textures.Add (textureAsset.ID);
                    }

                    InventoryFolderBase meshFolder = m_inventoryService.GetFolderForType (m_agentID, InventoryType.Mesh, FolderType.Mesh);
                    for (int i = 0; i < mesh_list.Count; i++) {
                        PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox ();

                        Primitive.TextureEntry textureEntry =
                            new Primitive.TextureEntry (Primitive.TextureEntry.WHITE_TEXTURE);
                        OSDMap inner_instance_list = (OSDMap)instance_list [i];

                        OSDArray face_list = (OSDArray)inner_instance_list ["face_list"];
                        for (uint face = 0; face < face_list.Count; face++) {
                            OSDMap faceMap = (OSDMap)face_list [(int)face];
                            Primitive.TextureEntryFace f = pbs.Textures.CreateFace (face);
                            if (faceMap.ContainsKey ("fullbright"))
                                f.Fullbright = faceMap ["fullbright"].AsBoolean ();
                            if (faceMap.ContainsKey ("diffuse_color"))
                                f.RGBA = faceMap ["diffuse_color"].AsColor4 ();

                            int textureNum = faceMap ["image"].AsInteger ();
                            float imagerot = faceMap ["imagerot"].AsInteger ();
                            float offsets = (float)faceMap ["offsets"].AsReal ();
                            float offsett = (float)faceMap ["offsett"].AsReal ();
                            float scales = (float)faceMap ["scales"].AsReal ();
                            float scalet = (float)faceMap ["scalet"].AsReal ();

                            if (imagerot != 0)
                                f.Rotation = imagerot;
                            if (offsets != 0)
                                f.OffsetU = offsets;
                            if (offsett != 0)
                                f.OffsetV = offsett;
                            if (scales != 0)
                                f.RepeatU = scales;
                            if (scalet != 0)
                                f.RepeatV = scalet;
                            f.TextureID = textures.Count > textureNum
                                                  ? textures [textureNum]
                                                  : Primitive.TextureEntry.WHITE_TEXTURE;
                            textureEntry.FaceTextures [face] = f;
                        }
                        pbs.TextureEntry = textureEntry.GetBytes ();

                        AssetBase meshAsset = new AssetBase (UUID.Random (), assetName, AssetType.Mesh, m_agentID) { Data = mesh_list [i].AsBinary () };
                        meshAsset.ID = m_assetService.Store (meshAsset);

                        if (meshFolder == null) {
                            m_inventoryService.CreateUserInventory (m_agentID, false);
                            meshFolder = m_inventoryService.GetFolderForType (m_agentID, InventoryType.Mesh, FolderType.Mesh);
                        }

                        InventoryItemBase itemBase = new InventoryItemBase (UUID.Random (), m_agentID) {
                            AssetType = (sbyte)AssetType.Mesh,
                            AssetID = meshAsset.ID,
                            CreatorId = m_agentID.ToString (),
                            Folder = meshFolder.ID,
                            InvType = (int)InventoryType.Texture,
                            Name = "(Mesh) - " + assetName,
                            CurrentPermissions = (uint)PermissionMask.All,
                            BasePermissions = (uint)PermissionMask.All,
                            EveryOnePermissions = everyoneMask,
                            GroupPermissions = groupMask,
                            NextPermissions = nextOwnerMask
                        };
                        //Bad... but whatever
                        m_inventoryService.AddItem (itemBase);

                        pbs.SculptEntry = true;
                        pbs.SculptTexture = meshAsset.ID;
                        pbs.SculptType = (byte)SculptType.Mesh;
                        pbs.SculptData = meshAsset.Data;

                        Vector3 position = inner_instance_list ["position"].AsVector3 ();
                        Vector3 scale = inner_instance_list ["scale"].AsVector3 ();
                        Quaternion rotation = inner_instance_list ["rotation"].AsQuaternion ();

                        int physicsShapeType = inner_instance_list ["physics_shape_type"].AsInteger ();
                        // not currently used                        int material = inner_instance_list["material"].AsInteger();
                        // not currently used                        int mesh = inner_instance_list["mesh"].AsInteger();

                        SceneObjectPart prim = new SceneObjectPart (m_agentID, pbs, position, Quaternion.Identity,
                                                   Vector3.Zero, assetName) { Scale = scale, AbsolutePosition = position };

                        rotations.Add (rotation);
                        positions.Add (position);
                        prim.UUID = UUID.Random ();
                        prim.CreatorID = m_agentID;
                        prim.OwnerID = m_agentID;
                        prim.GroupID = UUID.Zero;
                        prim.LastOwnerID = m_agentID;
                        prim.CreationDate = Util.UnixTimeSinceEpoch ();
                        prim.Name = assetName;
                        prim.Description = "";
                        prim.PhysicsType = (byte)physicsShapeType;

                        prim.BaseMask = (uint)PermissionMask.All;
                        prim.EveryoneMask = everyoneMask;
                        prim.NextOwnerMask = nextOwnerMask;
                        prim.GroupMask = groupMask;
                        prim.OwnerMask = (uint)PermissionMask.All;

                        if (grp == null)
                            grp = new SceneObjectGroup (prim, null);
                        else
                            grp.AddChild (prim, i + 1);
                        grp.RootPart.IsAttachment = false;
                    }
                    if (grp != null) {              // unlikely not to have anything but itis possible
                        if (grp.ChildrenList.Count > 1) //Fix first link #
                            grp.RootPart.LinkNum++;

                        Vector3 rootPos = positions [0];
                        grp.SetAbsolutePosition (false, rootPos);
                        for (int i = 0; i < positions.Count; i++) {
                            Vector3 offset = positions [i] - rootPos;
                            grp.ChildrenList [i].SetOffsetPosition (offset);
                        }
                        //grp.Rotation = rotations[0];
                        for (int i = 0; i < rotations.Count; i++) {
                            if (i != 0)
                                grp.ChildrenList [i].SetRotationOffset (false, rotations [i], false);
                        }
                        grp.UpdateGroupRotationR (rotations [0]);
                        data = Encoding.ASCII.GetBytes (grp.ToXml2 ());
                    }
                }
                break;
            }
            AssetBase asset = new AssetBase (assetID, assetName, (AssetType)assType, m_agentID) { Data = data };
            asset.ID = m_assetService.Store (asset);
            assetID = asset.ID;

            InventoryItemBase item = new InventoryItemBase {
                Owner = m_agentID,
                CreatorId = m_agentID.ToString (),
                ID = inventoryItem,
                AssetID = asset.ID,
                Description = assetDescription,
                Name = assetName,
                AssetType = assType,
                InvType = inType,
                Folder = parentFolder,
                CurrentPermissions = (uint)PermissionMask.All,
                BasePermissions = (uint)PermissionMask.All,
                EveryOnePermissions = everyoneMask,
                NextPermissions = nextOwnerMask,
                GroupPermissions = groupMask,
                CreationDate = Util.UnixTimeSinceEpoch ()
            };

            m_inventoryService.AddItem (item);

            return assetID;
        }
 public void RemoveGroupTarget(SceneObjectGroup grp)
 {
     m_scene.EventManager.OnFrame -= checkAtTargets;
 }
 public void AddGroupTarget(SceneObjectGroup grp)
 {
     m_scene.EventManager.OnFrame += checkAtTargets;
 }
        /// <summary>
        ///     Parses ad request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="AgentId"></param>
        /// <returns></returns>
        public byte[] ProcessAdd(Stream request, OSHttpResponse response, UUID AgentId)
        {
            IScenePresence avatar;

            if (!m_scene.TryGetScenePresence(AgentId, out avatar))
                return MainServer.BlankResponse;

            OSDMap r = (OSDMap) OSDParser.Deserialize(HttpServerHandlerHelpers.ReadFully(request));
            UploadObjectAssetMessage message = new UploadObjectAssetMessage();
            try
            {
                message.Deserialize(r);
            }
            catch (Exception ex)
            {
                MainConsole.Instance.Error("[UploadObjectAssetModule]: Error de-serializing message " + ex);
                message = null;
            }

            if (message == null)
            {
                response.StatusCode = 400; //501; //410; //404;
                return
                    Encoding.UTF8.GetBytes(
                        "<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>");
            }

            Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX*avatar.Rotation);
            Quaternion rot = Quaternion.Identity;
            Vector3 rootpos = Vector3.Zero;

            SceneObjectGroup rootGroup = null;
            SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length];
            for (int i = 0; i < message.Objects.Length; i++)
            {
                UploadObjectAssetMessage.Object obj = message.Objects[i];
                PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();

                if (i == 0)
                {
                    rootpos = obj.Position;
                }


                // Combine the extraparams data into it's ugly blob again....
                //int bytelength = 0;
                //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
                //{
                //    bytelength += obj.ExtraParams[extparams].ExtraParamData.Length;
                //}
                //byte[] extraparams = new byte[bytelength];
                //int position = 0;


                //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++)
                //{
                //    Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position,
                //                     obj.ExtraParams[extparams].ExtraParamData.Length);
                //
                //    position += obj.ExtraParams[extparams].ExtraParamData.Length;
                // }

                //pbs.ExtraParams = extraparams;
                foreach (UploadObjectAssetMessage.Object.ExtraParam extraParam in obj.ExtraParams)
                {
                    switch ((ushort) extraParam.Type)
                    {
                        case (ushort) ExtraParamType.Sculpt:
                            Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0);

                            pbs.SculptEntry = true;

                            pbs.SculptTexture = obj.SculptID;
                            pbs.SculptType = (byte) sculpt.Type;

                            break;
                        case (ushort) ExtraParamType.Flexible:
                            Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0);
                            pbs.FlexiEntry = true;
                            pbs.FlexiDrag = flex.Drag;
                            pbs.FlexiForceX = flex.Force.X;
                            pbs.FlexiForceY = flex.Force.Y;
                            pbs.FlexiForceZ = flex.Force.Z;
                            pbs.FlexiGravity = flex.Gravity;
                            pbs.FlexiSoftness = flex.Softness;
                            pbs.FlexiTension = flex.Tension;
                            pbs.FlexiWind = flex.Wind;
                            break;
                        case (ushort) ExtraParamType.Light:
                            Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0);
                            pbs.LightColorA = light.Color.A;
                            pbs.LightColorB = light.Color.B;
                            pbs.LightColorG = light.Color.G;
                            pbs.LightColorR = light.Color.R;
                            pbs.LightCutoff = light.Cutoff;
                            pbs.LightEntry = true;
                            pbs.LightFalloff = light.Falloff;
                            pbs.LightIntensity = light.Intensity;
                            pbs.LightRadius = light.Radius;
                            break;
                        case 0x40:
                            pbs.ReadProjectionData(extraParam.ExtraParamData, 0);
                            break;
                    }
                }
                pbs.PathBegin = (ushort) obj.PathBegin;
                pbs.PathCurve = (byte) obj.PathCurve;
                pbs.PathEnd = (ushort) obj.PathEnd;
                pbs.PathRadiusOffset = (sbyte) obj.RadiusOffset;
                pbs.PathRevolutions = (byte) obj.Revolutions;
                pbs.PathScaleX = (byte) obj.ScaleX;
                pbs.PathScaleY = (byte) obj.ScaleY;
                pbs.PathShearX = (byte) obj.ShearX;
                pbs.PathShearY = (byte) obj.ShearY;
                pbs.PathSkew = (sbyte) obj.Skew;
                pbs.PathTaperX = (sbyte) obj.TaperX;
                pbs.PathTaperY = (sbyte) obj.TaperY;
                pbs.PathTwist = (sbyte) obj.Twist;
                pbs.PathTwistBegin = (sbyte) obj.TwistBegin;
                pbs.HollowShape = (HollowShape) obj.ProfileHollow;
                pbs.PCode = (byte) PCode.Prim;
                pbs.ProfileBegin = (ushort) obj.ProfileBegin;
                pbs.ProfileCurve = (byte) obj.ProfileCurve;
                pbs.ProfileEnd = (ushort) obj.ProfileEnd;
                pbs.Scale = obj.Scale;
                pbs.State = 0;
                SceneObjectPart prim = new SceneObjectPart(AgentId, pbs, obj.Position, obj.Rotation,
                                                           Vector3.Zero, obj.Name)
                                           {
                                               UUID = UUID.Random(),
                                               CreatorID = AgentId,
                                               OwnerID = AgentId,
                                               GroupID = obj.GroupID
                                           };
                prim.LastOwnerID = prim.OwnerID;
                prim.CreationDate = Util.UnixTimeSinceEpoch();
                prim.Name = obj.Name;
                prim.Description = "";

                prim.PayPrice[0] = -2;
                prim.PayPrice[1] = -2;
                prim.PayPrice[2] = -2;
                prim.PayPrice[3] = -2;
                prim.PayPrice[4] = -2;
                Primitive.TextureEntry tmp =
                    new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f"));

                for (int j = 0; j < obj.Faces.Length; j++)
                {
                    UploadObjectAssetMessage.Object.Face face = obj.Faces[j];

                    Primitive.TextureEntryFace primFace = tmp.CreateFace((uint) j);

                    primFace.Bump = face.Bump;
                    primFace.RGBA = face.Color;
                    primFace.Fullbright = face.Fullbright;
                    primFace.Glow = face.Glow;
                    primFace.TextureID = face.ImageID;
                    primFace.Rotation = face.ImageRot;
                    primFace.MediaFlags = ((face.MediaFlags & 1) != 0);

                    primFace.OffsetU = face.OffsetS;
                    primFace.OffsetV = face.OffsetT;
                    primFace.RepeatU = face.ScaleS;
                    primFace.RepeatV = face.ScaleT;
                    primFace.TexMapType = (MappingType) (face.MediaFlags & 6);
                }
                pbs.TextureEntry = tmp.GetBytes();
                prim.Shape = pbs;
                prim.Scale = obj.Scale;

                SceneObjectGroup grp = new SceneObjectGroup(prim, m_scene);

                prim.ParentID = 0;
                if (i == 0)
                    rootGroup = grp;

                grp.AbsolutePosition = obj.Position;
                prim.SetRotationOffset(true, obj.Rotation, true);

                grp.RootPart.IsAttachment = false;

                string reason;
                if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos, out reason))
                {
                    m_scene.SceneGraph.AddPrimToScene(grp);
                    grp.AbsolutePosition = obj.Position;
                }
                else
                {
                    //Stop now then
                    avatar.ControllingClient.SendAlertMessage("You do not have permission to rez objects here: " +
                                                              reason);
                    return MainServer.BlankResponse;
                }
                allparts[i] = grp;
            }

            if (rootGroup != null) {
                for (int j = 1; j < allparts.Length; j++) {
                    rootGroup.LinkToGroup (allparts [j]);
                }

                rootGroup.ScheduleGroupUpdate (PrimUpdateFlags.ForcedFullUpdate);
                pos = m_scene.SceneGraph.GetNewRezLocation (Vector3.Zero, rootpos, UUID.Zero, rot, 1, 1, true, allparts [0].GroupScale (), false);
            } else
                MainConsole.Instance.Error ("[UploadObjectAssetModule]: Unable to locate root group!");
            
            OSDMap map = new OSDMap();
            map["local_id"] = allparts[0].LocalId;
            return OSDParser.SerializeLLSDXmlBytes(map);
        }
        public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client)
        {
            m_autopilotMoving = true;
            m_autoPilotTarget = Pos;
            m_sitAtAutoTarget = false;
            PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;
            //proxy.PCode = (byte)PCode.ParticleSystem;

            proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy, "", m_scene);
            proxyObjectGroup.AttachToScene(m_scene);

            // Commented out this code since it could never have executed, but might still be informative.
            //            if (proxyObjectGroup != null)
            //            {
            proxyObjectGroup.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
            remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero,
                                          Vector3.Zero, false);
            IBackupModule backup = m_scene.RequestModuleInterface<IBackupModule>();
            if (backup != null)
                backup.DeleteSceneObjects(new[] {proxyObjectGroup}, true, true);
            //            }
            //            else
            //            {
            //                m_autopilotMoving = false;
            //                m_autoPilotTarget = Vector3.Zero;
            //                ControllingClient.SendAlertMessage("Autopilot cancelled");
            //            }
        }
        public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client)
        {
            m_autopilotMoving = true;
            m_autoPilotTarget = Pos;
            m_sitAtAutoTarget = false;
            PrimitiveBaseShape proxy = PrimitiveBaseShape.Default;

            proxyObjectGroup = new SceneObjectGroup(UUID, Pos, Rotation, proxy, "", m_scene);
            proxyObjectGroup.AttachToScene(m_scene);

            proxyObjectGroup.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
            remote_client.SendSitResponse(proxyObjectGroup.UUID, Vector3.Zero, Quaternion.Identity, true, Vector3.Zero,
                                          Vector3.Zero, false);
            IBackupModule backup = m_scene.RequestModuleInterface<IBackupModule>();
            if (backup != null)
                backup.DeleteSceneObjects(new[] {proxyObjectGroup}, true, true);
        }
        /// <summary>
        ///     Duplicates this part.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="clonePhys"></param>
        /// <returns></returns>
        public SceneObjectPart Copy(SceneObjectGroup parent, bool clonePhys)
        {
            SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone();
            dupe.m_parentGroup = parent;
            dupe.m_shape = m_shape.Copy();
            dupe.m_partOOBsize = m_partOOBsize;
            dupe.m_partOOBoffset = m_partOOBoffset;
            dupe.m_partBSphereRadiusSQ = m_partBSphereRadiusSQ;
            dupe.m_regionHandle = m_regionHandle;

            //memberwiseclone means it also clones the physics actor reference
            // This will make physical prim 'bounce' if not set to null.

            if (!clonePhys)
                dupe.PhysActor = null;

            dupe._groupID = GroupID;
            dupe.m_groupPosition = m_groupPosition;
            dupe.m_offsetPosition = m_offsetPosition;
            dupe.RotationOffset = RotationOffset;
            dupe.Velocity = new Vector3(0, 0, 0);
            dupe.Acceleration = new Vector3(0, 0, 0);
            dupe.AngularVelocity = new Vector3(0, 0, 0);
            dupe.Flags = Flags;
            dupe.LinkNum = LinkNum;
            dupe.SitTargetAvatar = new List<UUID>();

            dupe.m_ValidpartOOB = false;

            dupe._ownershipCost = _ownershipCost;
            dupe._objectSaleType = _objectSaleType;
            dupe._salePrice = _salePrice;
            dupe._category = _category;
            dupe.Rezzed = Rezzed;

            dupe.m_inventory = new SceneObjectPartInventory(dupe)
                                   {
                                       Items = (TaskInventoryDictionary) m_inventory.Items.Clone(),
                                       HasInventoryChanged = m_inventory.HasInventoryChanged
                                   };

            byte[] extraP = new byte[Shape.ExtraParams.Length];
            Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
            dupe.Shape.ExtraParams = extraP;

            dupe.m_scriptEvents = new Dictionary<UUID, scriptEvents>();
            dupe.Shape.SculptData = Shape.SculptData;
            dupe.GenerateRotationalVelocityFromOmega();

            return dupe;
        }
 /// <summary>
 /// </summary>
 public void SetParent(ISceneEntity parent)
 {
     m_parentGroup = (SceneObjectGroup) parent;
 }