/Aurora/Region/SceneGraph.cs
C# | 2314 lines | 1537 code | 221 blank | 556 comment | 276 complexity | 9b54046049b2fed1c55899ebd36e7387 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- /*
- * Copyright (c) Contributors, http://aurora-sim.org/, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Aurora-Sim Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- using Aurora.Framework;
- using Aurora.Framework.ClientInterfaces;
- using Aurora.Framework.ConsoleFramework;
- using Aurora.Framework.Modules;
- using Aurora.Framework.Physics;
- using Aurora.Framework.PresenceInfo;
- using Aurora.Framework.SceneInfo;
- using Aurora.Framework.SceneInfo.Entities;
- using Aurora.Framework.Services;
- using Aurora.Framework.Utilities;
- using Nini.Config;
- using OpenMetaverse;
- using OpenMetaverse.Packets;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
-
- namespace Aurora.Region
- {
- /// <summary>
- /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components
- /// should be migrated out over time.
- /// </summary>
- public class SceneGraph : ISceneGraph
- {
- #region Declares
-
- protected internal EntityManager Entities = new EntityManager();
-
- protected RegionInfo m_regInfo;
- protected IScene m_parentScene;
- protected bool EnableFakeRaycasting = false;
- protected string m_DefaultObjectName = "Primitive";
-
- /// <summary>
- /// The last allocated local prim id. When a new local id is requested, the next number in the sequence is
- /// dispensed.
- /// </summary>
- protected uint m_lastAllocatedLocalId = 720000;
-
- private readonly object _primAllocateLock = new object();
-
- protected internal object m_syncRoot = new object();
-
- protected internal PhysicsScene _PhyScene;
-
- private readonly Object m_updateLock = new Object();
-
- public PhysicsScene PhysicsScene
- {
- get { return _PhyScene; }
- set { _PhyScene = value; }
- }
-
- #endregion
-
- #region Constructor and close
-
- protected internal SceneGraph(IScene parent, RegionInfo regInfo)
- {
- Random random = new Random();
- m_lastAllocatedLocalId = (uint) (random.NextDouble()*(uint.MaxValue/2)) + uint.MaxValue/4;
- m_parentScene = parent;
- m_regInfo = regInfo;
-
- //Subscript to the scene events
- m_parentScene.EventManager.OnNewClient += SubscribeToClientEvents;
- m_parentScene.EventManager.OnClosingClient += UnSubscribeToClientEvents;
-
- IConfig aurorastartupConfig = parent.Config.Configs["AuroraStartup"];
- if (aurorastartupConfig != null)
- {
- m_DefaultObjectName = aurorastartupConfig.GetString("DefaultObjectName", m_DefaultObjectName);
- EnableFakeRaycasting = aurorastartupConfig.GetBoolean("EnableFakeRaycasting", false);
- }
- }
-
- protected internal void Close()
- {
- Entities.Clear();
- //Remove the events
- m_parentScene.EventManager.OnNewClient -= SubscribeToClientEvents;
- m_parentScene.EventManager.OnClosingClient -= UnSubscribeToClientEvents;
- }
-
- #endregion
-
- #region Update Methods
-
- protected internal void UpdatePreparePhysics()
- {
- // If we are using a threaded physics engine
- // grab the latest scene from the engine before
- // trying to process it.
-
- // PhysX does this (runs in the background).
-
- if (_PhyScene != null && _PhyScene.IsThreaded)
- {
- _PhyScene.GetResults();
- }
- }
-
- private readonly object m_taintedPresencesLock = new object();
- private readonly List<IScenePresence> m_taintedPresences = new List<IScenePresence>();
-
- public void TaintPresenceForUpdate(IScenePresence presence, PresenceTaint taint)
- {
- lock (m_taintedPresencesLock)
- {
- if (!presence.IsTainted) //We ONLY set the IsTainted under this lock, so we can trust it
- m_taintedPresences.Add(presence);
- presence.Taints |= taint;
- }
- }
-
- protected internal void UpdateEntities()
- {
- IScenePresence[] presences;
- lock (m_taintedPresencesLock)
- {
- presences = new IScenePresence[m_taintedPresences.Count];
- m_taintedPresences.CopyTo(presences);
- m_taintedPresences.Clear();
- }
- foreach (IScenePresence presence in presences)
- {
- presence.IsTainted = false;
- //We set this first so that it is cleared out, but also so that the method can re-taint us
- presence.Update();
- }
- }
-
- protected internal void UpdatePhysics(double elapsed)
- {
- if (_PhyScene == null)
- return;
- lock (m_syncRoot)
- {
- // Update DisableCollisions
- _PhyScene.DisableCollisions = m_regInfo.RegionSettings.DisableCollisions;
-
- // Here is where the Scene calls the PhysicsScene. This is a one-way
- // interaction; the PhysicsScene cannot access the calling Scene directly.
- // But with joints, we want a PhysicsActor to be able to influence a
- // non-physics SceneObjectPart. In particular, a PhysicsActor that is connected
- // with a joint should be able to move the SceneObjectPart which is the visual
- // representation of that joint (for editing and serialization purposes).
- // However the PhysicsActor normally cannot directly influence anything outside
- // of the PhysicsScene, and the non-physical SceneObjectPart which represents
- // the joint in the Scene does not exist in the PhysicsScene.
- //
- // To solve this, we have an event in the PhysicsScene that is fired when a joint
- // has changed position (because one of its associated PhysicsActors has changed
- // position).
- //
- // Therefore, JointMoved and JointDeactivated events will be fired as a result of the following Simulate().
-
- _PhyScene.Simulate((float) elapsed);
- }
- }
-
- private List<Vector3> m_oldCoarseLocations = new List<Vector3>();
- private List<UUID> m_oldAvatarUUIDs = new List<UUID>();
-
- public bool GetCoarseLocations(out List<Vector3> coarseLocations, out List<UUID> avatarUUIDs, uint maxLocations)
- {
- coarseLocations = new List<Vector3>();
- avatarUUIDs = new List<UUID>();
-
- List<IScenePresence> presences = GetScenePresences();
- for (int i = 0; i < Math.Min(presences.Count, maxLocations); i++)
- {
- IScenePresence sp = presences[i];
- // If this presence is a child agent, we don't want its coarse locations
- if (sp.IsChildAgent)
- continue;
-
- if (sp.ParentID != UUID.Zero)
- {
- // sitting avatar
- ISceneChildEntity sop = m_parentScene.GetSceneObjectPart(sp.ParentID);
- if (sop != null)
- {
- coarseLocations.Add(sop.AbsolutePosition + sp.OffsetPosition);
- avatarUUIDs.Add(sp.UUID);
- }
- else
- {
- // we can't find the parent.. ! arg!
- MainConsole.Instance.Warn("Could not find parent prim for avatar " + sp.Name);
- coarseLocations.Add(sp.AbsolutePosition);
- avatarUUIDs.Add(sp.UUID);
- }
- }
- else
- {
- coarseLocations.Add(sp.AbsolutePosition);
- avatarUUIDs.Add(sp.UUID);
- }
- }
-
- if (m_oldCoarseLocations.Count == coarseLocations.Count)
- {
- List<UUID> foundAvies = new List<UUID>(m_oldAvatarUUIDs);
- foreach (UUID t in avatarUUIDs)
- {
- foundAvies.Remove(t);
- }
- if (foundAvies.Count == 0)
- {
- //All avies are still the same, check their locations now
- for (int i = 0; i < avatarUUIDs.Count; i++)
- {
- if (m_oldCoarseLocations[i].ApproxEquals(coarseLocations[i], 5))
- continue;
- m_oldCoarseLocations = coarseLocations;
- m_oldAvatarUUIDs = avatarUUIDs;
- return true;
- }
- //Things are still close enough to the same
- return false;
- }
- }
- m_oldCoarseLocations = coarseLocations;
- m_oldAvatarUUIDs = avatarUUIDs;
- //Its changed, tell it to send new
- return true;
- }
-
- #endregion
-
- #region Entity Methods
-
- protected internal void HandleUndo(IClientAPI remoteClient, UUID primId)
- {
- if (primId != UUID.Zero)
- {
- ISceneChildEntity part = m_parentScene.GetSceneObjectPart(primId);
- if (part != null)
- if (m_parentScene.Permissions.CanEditObject(part.UUID, remoteClient.AgentId))
- part.Undo();
- }
- }
-
- protected internal void HandleRedo(IClientAPI remoteClient, UUID primId)
- {
- if (primId != UUID.Zero)
- {
- ISceneChildEntity part = m_parentScene.GetSceneObjectPart(primId);
- if (part != null)
- if (m_parentScene.Permissions.CanEditObject(part.UUID, remoteClient.AgentId))
- part.Redo();
- }
- }
-
- protected internal void HandleObjectGroupUpdate(
- IClientAPI remoteClient, UUID GroupID, uint LocalID, UUID Garbage)
- {
- IEntity entity;
- if (TryGetEntity(LocalID, out entity))
- {
- if (m_parentScene.Permissions.CanEditObject(entity.UUID, remoteClient.AgentId))
- if (((ISceneEntity) entity).OwnerID == remoteClient.AgentId)
- ((ISceneEntity) entity).SetGroup(GroupID, remoteClient.AgentId, true);
- }
- }
-
- /// <summary>
- /// Add a presence to the scene
- /// </summary>
- /// <param name="presence"></param>
- protected internal void AddScenePresence(IScenePresence presence)
- {
- AddEntity(presence, true);
- }
-
- /// <summary>
- /// Remove a presence from the scene
- /// </summary>
- protected internal void RemoveScenePresence(IEntity agent)
- {
- if (!Entities.Remove(agent))
- {
- MainConsole.Instance.WarnFormat(
- "[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene Entities list",
- agent.UUID);
- return;
- }
- }
-
- #endregion
-
- #region Get Methods
-
- /// <summary>
- /// Get a reference to the scene presence list. Changes to the list will be done in a copy
- /// There is no guarantee that presences will remain in the scene after the list is returned.
- /// This list should remain private to SceneGraph. Callers wishing to iterate should instead
- /// pass a delegate to ForEachScenePresence.
- /// </summary>
- /// <returns></returns>
- public List<IScenePresence> GetScenePresences()
- {
- return Entities.GetPresences();
- }
-
- /// <summary>
- /// Request a scene presence by UUID. Fast, indexed lookup.
- /// </summary>
- /// <param name="agentID"></param>
- /// <returns>null if the presence was not found</returns>
- protected internal IScenePresence GetScenePresence(UUID agentID)
- {
- IScenePresence sp;
- Entities.TryGetPresenceValue(agentID, out sp);
- return sp;
- }
-
- /// <summary>
- /// Request the scene presence by name.
- /// NOTE: Depricated, use the ScenePresence GetScenePresence (string Name) instead!
- /// </summary>
- /// <param name="firstName"></param>
- /// <param name="lastName"></param>
- /// <returns>null if the presence was not found</returns>
- public IScenePresence GetScenePresence(string firstName, string lastName)
- {
- List<IScenePresence> presences = GetScenePresences();
- #if (!ISWIN)
- foreach (IScenePresence presence in presences)
- {
- if (presence.Firstname == firstName && presence.Lastname == lastName) return presence;
- }
- return null;
- #else
- return presences.FirstOrDefault(presence => presence.Firstname == firstName && presence.Lastname == lastName);
- #endif
- }
-
- /// <summary>
- /// Request the scene presence by localID.
- /// </summary>
- /// <param name="localID"></param>
- /// <returns>null if the presence was not found</returns>
- public IScenePresence GetScenePresence(uint localID)
- {
- List<IScenePresence> presences = GetScenePresences();
- #if (!ISWIN)
- foreach (IScenePresence presence in presences)
- {
- if (presence.LocalId == localID) return presence;
- }
- return null;
- #else
- return presences.FirstOrDefault(presence => presence.LocalId == localID);
- #endif
- }
-
- protected internal bool TryGetScenePresence(UUID agentID, out IScenePresence avatar)
- {
- return Entities.TryGetPresenceValue(agentID, out avatar);
- }
-
- protected internal bool TryGetAvatarByName(string name, out IScenePresence avatar)
- {
- #if (!ISWIN)
- avatar = null;
- foreach (IScenePresence presence in GetScenePresences())
- {
- if (String.Compare(name, presence.ControllingClient.Name, true) == 0)
- {
- avatar = presence;
- break;
- }
- }
- #else
- avatar =
- GetScenePresences()
- .FirstOrDefault(presence => String.Compare(name, presence.ControllingClient.Name, true) == 0);
- #endif
- return (avatar != null);
- }
-
- /// <summary>
- /// Get a scene object group that contains the prim with the given uuid
- /// </summary>
- /// <param name="hray"></param>
- /// <param name="frontFacesOnly"></param>
- /// <param name="faceCenters"></param>
- /// <returns>null if no scene object group containing that prim is found</returns>
- protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
- {
- // Primitive Ray Tracing
- float closestDistance = 280f;
- EntityIntersection result = new EntityIntersection();
- ISceneEntity[] EntityList = Entities.GetEntities(hray.Origin, closestDistance);
- foreach (ISceneEntity ent in EntityList)
- {
- if (ent is SceneObjectGroup)
- {
- SceneObjectGroup reportingG = (SceneObjectGroup) ent;
- EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
- if (inter.HitTF && inter.distance < closestDistance)
- {
- closestDistance = inter.distance;
- result = inter;
- }
- }
- }
- return result;
- }
-
- /// <summary>
- /// Gets a list of scene object group that intersect with the given ray
- /// </summary>
- public List<EntityIntersection> GetIntersectingPrims(Ray hray, float length, int count,
- bool frontFacesOnly, bool faceCenters, bool getAvatars,
- bool getLand, bool getPrims)
- {
- // Primitive Ray Tracing
- List<EntityIntersection> result = new List<EntityIntersection>(count);
- if (getPrims)
- {
- ISceneEntity[] EntityList = Entities.GetEntities(hray.Origin, length);
- #if (!ISWIN)
- foreach (ISceneEntity ent in EntityList)
- {
- if (ent is SceneObjectGroup)
- {
- SceneObjectGroup reportingG = (SceneObjectGroup)ent;
- EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
- if (inter.HitTF)
- result.Add(inter);
- }
- }
- #else
- result.AddRange(
- EntityList.OfType<SceneObjectGroup>()
- .Select(reportingG => reportingG.TestIntersection(hray, frontFacesOnly, faceCenters))
- .Where(inter => inter.HitTF));
- #endif
- }
- if (getAvatars)
- {
- List<IScenePresence> presenceList = Entities.GetPresences();
- foreach (IScenePresence ent in presenceList)
- {
- //Do rough approximation and keep the # of loops down
- Vector3 newPos = hray.Origin;
- for (int i = 0; i < 100; i++)
- {
- newPos += ((Vector3.One*(length*(i/100)))*hray.Direction);
- if (ent.AbsolutePosition.ApproxEquals(newPos, ent.PhysicsActor.Size.X*2))
- {
- EntityIntersection intersection = new EntityIntersection();
- intersection.distance = length*(i/100);
- intersection.face = 0;
- intersection.HitTF = true;
- intersection.obj = ent;
- intersection.ipoint = newPos;
- intersection.normal = newPos;
- result.Add(intersection);
- break;
- }
- }
- }
- }
- if (getLand)
- {
- //TODO
- }
- #if (!ISWIN)
- result.Sort(delegate(EntityIntersection a, EntityIntersection b)
- {
- return a.distance.CompareTo(b.distance);
- });
- #else
- result.Sort((a, b) => a.distance.CompareTo(b.distance));
- #endif
- if (result.Count > count)
- result.RemoveRange(count, result.Count - count);
- return result;
- }
-
- #endregion
-
- #region ForEach* Methods
-
- /// <summary>
- /// Performs action on all scene object groups.
- /// </summary>
- /// <param name="action"></param>
- protected internal void ForEachSceneEntity(Action<ISceneEntity> action)
- {
- ISceneEntity[] objlist = Entities.GetEntities();
- foreach (ISceneEntity obj in objlist)
- {
- try
- {
- action(obj);
- }
- catch (Exception e)
- {
- // Catch it and move on. This includes situations where splist has inconsistent info
- MainConsole.Instance.WarnFormat("[SCENE]: Problem processing action in ForEachSOG: {0}",
- e.ToString());
- }
- }
- }
-
- /// <summary>
- /// Performs action on all scene presences. This can ultimately run the actions in parallel but
- /// any delegates passed in will need to implement their own locking on data they reference and
- /// modify outside of the scope of the delegate.
- /// </summary>
- /// <param name="action"></param>
- public void ForEachScenePresence(Action<IScenePresence> action)
- {
- // Once all callers have their delegates configured for parallelism, we can unleash this
- /*
- Action<ScenePresence> protectedAction = new Action<ScenePresence>(delegate(ScenePresence sp)
- {
- try
- {
- action(sp);
- }
- catch (Exception e)
- {
- MainConsole.Instance.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
- MainConsole.Instance.Info("[BUG] Stack Trace: " + e.StackTrace);
- }
- });
- Parallel.ForEach<ScenePresence>(GetScenePresences(), protectedAction);
- */
- // For now, perform actions serially
- List<IScenePresence> presences = new List<IScenePresence>(GetScenePresences());
- foreach (IScenePresence sp in presences)
- {
- try
- {
- action(sp);
- }
- catch (Exception e)
- {
- MainConsole.Instance.Info("[BUG] in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
- MainConsole.Instance.Info("[BUG] Stack Trace: " + e.StackTrace);
- }
- }
- }
-
- #endregion ForEach* Methods
-
- #region Client Event handlers
-
- public void SubscribeToClientEvents(IClientAPI client)
- {
- client.OnUpdatePrimGroupPosition += UpdatePrimPosition;
- client.OnUpdatePrimSinglePosition += UpdatePrimSinglePosition;
- client.OnUpdatePrimGroupRotation += UpdatePrimRotation;
- client.OnUpdatePrimGroupMouseRotation += UpdatePrimRotation;
- client.OnUpdatePrimSingleRotation += UpdatePrimSingleRotation;
- client.OnUpdatePrimSingleRotationPosition += UpdatePrimSingleRotationPosition;
- client.OnUpdatePrimScale += UpdatePrimScale;
- client.OnUpdatePrimGroupScale += UpdatePrimGroupScale;
- client.OnUpdateExtraParams += UpdateExtraParam;
- client.OnUpdatePrimShape += UpdatePrimShape;
- client.OnUpdatePrimTexture += UpdatePrimTexture;
- client.OnGrabUpdate += MoveObject;
- client.OnSpinStart += SpinStart;
- client.OnSpinUpdate += SpinObject;
-
- client.OnObjectName += PrimName;
- client.OnObjectClickAction += PrimClickAction;
- client.OnObjectMaterial += PrimMaterial;
- client.OnLinkObjects += LinkObjects;
- client.OnDelinkObjects += DelinkObjects;
- client.OnObjectDuplicate += DuplicateObject;
- client.OnUpdatePrimFlags += UpdatePrimFlags;
- client.OnRequestObjectPropertiesFamily += RequestObjectPropertiesFamily;
- client.OnObjectPermissions += HandleObjectPermissionsUpdate;
- client.OnGrabObject += ProcessObjectGrab;
- client.OnGrabUpdate += ProcessObjectGrabUpdate;
- client.OnDeGrabObject += ProcessObjectDeGrab;
- client.OnUndo += HandleUndo;
- client.OnRedo += HandleRedo;
- client.OnObjectDescription += PrimDescription;
- client.OnObjectIncludeInSearch += MakeObjectSearchable;
- client.OnObjectOwner += ObjectOwner;
- client.OnObjectGroupRequest += HandleObjectGroupUpdate;
-
- client.OnAddPrim += AddNewPrim;
- client.OnObjectDuplicateOnRay += doObjectDuplicateOnRay;
- }
-
- public void UnSubscribeToClientEvents(IClientAPI client)
- {
- client.OnUpdatePrimGroupPosition -= UpdatePrimPosition;
- client.OnUpdatePrimSinglePosition -= UpdatePrimSinglePosition;
- client.OnUpdatePrimGroupRotation -= UpdatePrimRotation;
- client.OnUpdatePrimGroupMouseRotation -= UpdatePrimRotation;
- client.OnUpdatePrimSingleRotation -= UpdatePrimSingleRotation;
- client.OnUpdatePrimSingleRotationPosition -= UpdatePrimSingleRotationPosition;
- client.OnUpdatePrimScale -= UpdatePrimScale;
- client.OnUpdatePrimGroupScale -= UpdatePrimGroupScale;
- client.OnUpdateExtraParams -= UpdateExtraParam;
- client.OnUpdatePrimShape -= UpdatePrimShape;
- client.OnUpdatePrimTexture -= UpdatePrimTexture;
- client.OnGrabUpdate -= MoveObject;
- client.OnSpinStart -= SpinStart;
- client.OnSpinUpdate -= SpinObject;
- client.OnObjectName -= PrimName;
- client.OnObjectClickAction -= PrimClickAction;
- client.OnObjectMaterial -= PrimMaterial;
- client.OnLinkObjects -= LinkObjects;
- client.OnDelinkObjects -= DelinkObjects;
- client.OnObjectDuplicate -= DuplicateObject;
- client.OnUpdatePrimFlags -= UpdatePrimFlags;
- client.OnRequestObjectPropertiesFamily -= RequestObjectPropertiesFamily;
- client.OnObjectPermissions -= HandleObjectPermissionsUpdate;
- client.OnGrabObject -= ProcessObjectGrab;
- client.OnGrabUpdate -= ProcessObjectGrabUpdate;
- client.OnDeGrabObject -= ProcessObjectDeGrab;
- client.OnUndo -= HandleUndo;
- client.OnRedo -= HandleRedo;
- client.OnObjectDescription -= PrimDescription;
- client.OnObjectIncludeInSearch -= MakeObjectSearchable;
- client.OnObjectOwner -= ObjectOwner;
- client.OnObjectGroupRequest -= HandleObjectGroupUpdate;
- client.OnAddPrim -= AddNewPrim;
- client.OnObjectDuplicateOnRay -= doObjectDuplicateOnRay;
- }
-
- public virtual void ProcessObjectGrab(uint localID, Vector3 offsetPos, IClientAPI remoteClient,
- List<SurfaceTouchEventArgs> surfaceArgs)
- {
- SurfaceTouchEventArgs surfaceArg = null;
- if (surfaceArgs != null && surfaceArgs.Count > 0)
- surfaceArg = surfaceArgs[0];
- ISceneChildEntity childPrim;
- if (TryGetPart(localID, out childPrim))
- {
- SceneObjectPart part = childPrim as SceneObjectPart;
- if (part != null)
- {
- SceneObjectGroup obj = part.ParentGroup;
- if (obj.RootPart.BlockGrab || obj.RootPart.BlockGrabObject)
- return;
- // Currently only grab/touch for the single prim
- // the client handles rez correctly
- obj.ObjectGrabHandler(localID, offsetPos, remoteClient);
-
- // If the touched prim handles touches, deliver it
- // If not, deliver to root prim
- m_parentScene.EventManager.TriggerObjectGrab(part, part, part.OffsetPosition, remoteClient,
- surfaceArg);
- // Deliver to the root prim if the touched prim doesn't handle touches
- // or if we're meant to pass on touches anyway. Don't send to root prim
- // if prim touched is the root prim as we just did it
- if ((part.LocalId != obj.RootPart.LocalId))
- {
- const int PASS_IF_NOT_HANDLED = 0;
- const int PASS_ALWAYS = 1;
- const int PASS_NEVER = 2;
- if (part.PassTouch == PASS_NEVER)
- {
- }
- if (part.PassTouch == PASS_ALWAYS)
- {
- m_parentScene.EventManager.TriggerObjectGrab(obj.RootPart, part, part.OffsetPosition,
- remoteClient, surfaceArg);
- }
- else if (((part.ScriptEvents & scriptEvents.touch_start) == 0) &&
- part.PassTouch == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
- {
- m_parentScene.EventManager.TriggerObjectGrab(obj.RootPart, part, part.OffsetPosition,
- remoteClient, surfaceArg);
- }
- }
- }
- }
- }
-
- public virtual void ProcessObjectGrabUpdate(UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient,
- List<SurfaceTouchEventArgs> surfaceArgs)
- {
- SurfaceTouchEventArgs surfaceArg = null;
- if (surfaceArgs != null && surfaceArgs.Count > 0)
- surfaceArg = surfaceArgs[0];
-
- ISceneChildEntity childPrim;
-
- if (TryGetPart(objectID, out childPrim))
- {
- SceneObjectPart part = childPrim as SceneObjectPart;
- if (part != null)
- {
- SceneObjectGroup obj = part.ParentGroup;
- if (obj.RootPart.BlockGrab || obj.RootPart.BlockGrabObject)
- return;
-
- // If the touched prim handles touches, deliver it
- // If not, deliver to root prim
- m_parentScene.EventManager.TriggerObjectGrabbing(part, part, part.OffsetPosition, remoteClient,
- surfaceArg);
- // Deliver to the root prim if the touched prim doesn't handle touches
- // or if we're meant to pass on touches anyway. Don't send to root prim
- // if prim touched is the root prim as we just did it
-
- if ((part.LocalId != obj.RootPart.LocalId))
- {
- const int PASS_IF_NOT_HANDLED = 0;
- const int PASS_ALWAYS = 1;
- const int PASS_NEVER = 2;
- if (part.PassTouch == PASS_NEVER)
- {
- }
- if (part.PassTouch == PASS_ALWAYS)
- {
- m_parentScene.EventManager.TriggerObjectGrabbing(obj.RootPart, part, part.OffsetPosition,
- remoteClient, surfaceArg);
- }
- else if ((((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
- ((part.ScriptEvents & scriptEvents.touch) == 0)) &&
- part.PassTouch == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
- {
- m_parentScene.EventManager.TriggerObjectGrabbing(obj.RootPart, part, part.OffsetPosition,
- remoteClient, surfaceArg);
- }
- }
- }
- }
- }
-
- public virtual void ProcessObjectDeGrab(uint localID, IClientAPI remoteClient,
- List<SurfaceTouchEventArgs> surfaceArgs)
- {
- SurfaceTouchEventArgs surfaceArg = null;
- if (surfaceArgs != null && surfaceArgs.Count > 0)
- surfaceArg = surfaceArgs[0];
-
- ISceneChildEntity childPrim;
- if (TryGetPart(localID, out childPrim))
- {
- SceneObjectPart part = childPrim as SceneObjectPart;
- if (part != null)
- {
- SceneObjectGroup obj = part.ParentGroup;
- // If the touched prim handles touches, deliver it
- // If not, deliver to root prim
- m_parentScene.EventManager.TriggerObjectDeGrab(part, part, remoteClient, surfaceArg);
-
- if ((part.LocalId != obj.RootPart.LocalId))
- {
- const int PASS_IF_NOT_HANDLED = 0;
- const int PASS_ALWAYS = 1;
- const int PASS_NEVER = 2;
- if (part.PassTouch == PASS_NEVER)
- {
- }
- if (part.PassTouch == PASS_ALWAYS)
- {
- m_parentScene.EventManager.TriggerObjectDeGrab(obj.RootPart, part, remoteClient, surfaceArg);
- }
- else if ((((part.ScriptEvents & scriptEvents.touch_start) == 0) ||
- ((part.ScriptEvents & scriptEvents.touch_end) == 0)) &&
- part.PassTouch == PASS_IF_NOT_HANDLED) //If no event in this prim, pass to parent
- {
- m_parentScene.EventManager.TriggerObjectDeGrab(obj.RootPart, part, remoteClient,
- surfaceArg);
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Gets a new rez location based on the raycast and the size of the object that is being rezzed.
- /// </summary>
- /// <param name="RayStart"></param>
- /// <param name="RayEnd"></param>
- /// <param name="RayTargetID"></param>
- /// <param name="rot"></param>
- /// <param name="bypassRayCast"></param>
- /// <param name="RayEndIsIntersection"></param>
- /// <param name="frontFacesOnly"></param>
- /// <param name="scale"></param>
- /// <param name="FaceCenter"></param>
- /// <returns></returns>
- public Vector3 GetNewRezLocation(Vector3 RayStart, Vector3 RayEnd, UUID RayTargetID, Quaternion rot,
- byte bypassRayCast, byte RayEndIsIntersection, bool frontFacesOnly,
- Vector3 scale, bool FaceCenter)
- {
- Vector3 pos = Vector3.Zero;
- if (RayEndIsIntersection == 1)
- {
- pos = RayEnd;
- return pos;
- }
-
- if (RayTargetID != UUID.Zero)
- {
- ISceneChildEntity target = m_parentScene.GetSceneObjectPart(RayTargetID);
-
- Vector3 direction = Vector3.Normalize(RayEnd - RayStart);
- Vector3 AXOrigin = new Vector3(RayStart.X, RayStart.Y, RayStart.Z);
- Vector3 AXdirection = new Vector3(direction.X, direction.Y, direction.Z);
-
- if (target != null)
- {
- pos = target.AbsolutePosition;
- //MainConsole.Instance.Info("[OBJECT_REZ]: TargetPos: " + pos.ToString() + ", RayStart: " + RayStart.ToString() + ", RayEnd: " + RayEnd.ToString() + ", Volume: " + Util.GetDistanceTo(RayStart,RayEnd).ToString() + ", mag1: " + Util.GetMagnitude(RayStart).ToString() + ", mag2: " + Util.GetMagnitude(RayEnd).ToString());
-
- // TODO: Raytrace better here
-
- //EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection));
- Ray NewRay = new Ray(AXOrigin, AXdirection);
-
- // Ray Trace against target here
- EntityIntersection ei = target.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly,
- FaceCenter);
-
- // Un-comment out the following line to Get Raytrace results printed to the console.
- //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
- float ScaleOffset = 0.5f;
-
- // If we hit something
- if (ei.HitTF)
- {
- Vector3 scaleComponent = new Vector3(ei.AAfaceNormal.X, ei.AAfaceNormal.Y, ei.AAfaceNormal.Z);
- if (scaleComponent.X != 0) ScaleOffset = scale.X;
- if (scaleComponent.Y != 0) ScaleOffset = scale.Y;
- if (scaleComponent.Z != 0) ScaleOffset = scale.Z;
- ScaleOffset = Math.Abs(ScaleOffset);
- Vector3 intersectionpoint = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
- Vector3 normal = new Vector3(ei.normal.X, ei.normal.Y, ei.normal.Z);
- // Set the position to the intersection point
- Vector3 offset = (normal*(ScaleOffset/2f));
- pos = (intersectionpoint + offset);
-
- //Seems to make no sense to do this as this call is used for rezzing from inventory as well, and with inventory items their size is not always 0.5f
- //And in cases when we weren't rezzing from inventory we were re-adding the 0.25 straight after calling this method
- // Un-offset the prim (it gets offset later by the consumer method)
- //pos.Z -= 0.25F;
- }
-
- return pos;
- }
- else
- {
- // We don't have a target here, so we're going to raytrace all the objects in the scene.
-
- EntityIntersection ei = GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), true, false);
-
- // Un-comment the following line to print the raytrace results to the console.
- //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
-
- pos = ei.HitTF ? new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z) : RayEnd;
-
- return pos;
- }
- }
- // fall back to our stupid functionality
- pos = RayEnd;
-
- //increase height so its above the ground.
- //should be getting the normal of the ground at the rez point and using that?
- pos.Z += scale.Z/2f;
- return pos;
- }
-
- public virtual void AddNewPrim(UUID ownerID, UUID groupID, Vector3 RayEnd, Quaternion rot,
- PrimitiveBaseShape shape,
- byte bypassRaycast, Vector3 RayStart, UUID RayTargetID,
- byte RayEndIsIntersection)
- {
- Vector3 pos = GetNewRezLocation(RayStart, RayEnd, RayTargetID, rot, bypassRaycast, RayEndIsIntersection,
- true, new Vector3(0.5f, 0.5f, 0.5f), false);
-
- string reason;
- if (m_parentScene.Permissions.CanRezObject(1, ownerID, pos, out reason))
- {
- AddNewPrim(ownerID, groupID, pos, rot, shape);
- }
- else
- {
- GetScenePresence(ownerID)
- .ControllingClient.SendAlertMessage("You do not have permission to rez objects here: " + reason);
- }
- }
-
- /// <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>
- /// Duplicates object specified by localID at position raycasted against RayTargetObject using
- /// RayEnd and RayStart to determine what the angle of the ray is
- /// </summary>
- /// <param name="localID">ID of object to duplicate</param>
- /// <param name="dupeFlags"></param>
- /// <param name="AgentID">Agent doing the duplication</param>
- /// <param name="GroupID">Group of new object</param>
- /// <param name="RayTargetObj">The target of the Ray</param>
- /// <param name="RayEnd">The ending of the ray (farthest away point)</param>
- /// <param name="RayStart">The Beginning of the ray (closest point)</param>
- /// <param name="BypassRaycast">Bool to bypass raycasting</param>
- /// <param name="RayEndIsIntersection">The End specified is the place to add the object</param>
- /// <param name="CopyCenters">Position the object at the center of the face that it's colliding with</param>
- /// <param name="CopyRotates">Rotate the object the same as the localID object</param>
- public void doObjectDuplicateOnRay(uint localID, uint dupeFlags, UUID AgentID, UUID GroupID,
- UUID RayTargetObj, Vector3 RayEnd, Vector3 RayStart,
- bool BypassRaycast, bool RayEndIsIntersection, bool CopyCenters,
- bool CopyRotates)
- {
- const bool frontFacesOnly = true;
- //MainConsole.Instance.Info("HITTARGET: " + RayTargetObj.ToString() + ", COPYTARGET: " + localID.ToString());
- ISceneChildEntity target = m_parentScene.GetSceneObjectPart(localID);
- ISceneChildEntity target2 = m_parentScene.GetSceneObjectPart(RayTargetObj);
- IScenePresence Sp = GetScenePresence(AgentID);
- if (target != null && target2 != null)
- {
- Vector3 pos;
- if (EnableFakeRaycasting)
- {
- RayStart = Sp.CameraPosition;
- RayEnd = pos = target2.AbsolutePosition;
- }
- Vector3 direction = Vector3.Normalize(RayEnd - RayStart);
- Vector3 AXOrigin = new Vector3(RayStart.X, RayStart.Y, RayStart.Z);
- Vector3 AXdirection = new Vector3(direction.X, direction.Y, direction.Z);
-
- if (target2.ParentEntity != null)
- {
- pos = target2.AbsolutePosition;
- // TODO: Raytrace better here
-
- //EntityIntersection ei = m_sceneGraph.GetClosestIntersectingPrim(new Ray(AXOrigin, AXdirection), false, false);
- Ray NewRay = new Ray(AXOrigin, AXdirection);
-
- // Ray Trace against target here
- EntityIntersection ei = target2.TestIntersectionOBB(NewRay, Quaternion.Identity, frontFacesOnly,
- CopyCenters);
-
- // Un-comment out the following line to Get Raytrace results printed to the console.
- //MainConsole.Instance.Info("[RAYTRACERESULTS]: Hit:" + ei.HitTF.ToString() + " Point: " + ei.ipoint.ToString() + " Normal: " + ei.normal.ToString());
- float ScaleOffset = 0.5f;
-
- // If we hit something
- if (ei.HitTF)
- {
- Vector3 scale = target.Scale;
- Vector3 scaleComponent = new Vector3(ei.AAfaceNormal.X, ei.AAfaceNormal.Y, ei.AAfaceNormal.Z);
- if (scaleComponent.X != 0) ScaleOffset = scale.X;
- if (scaleComponent.Y != 0) ScaleOffset = scale.Y;
- if (scaleComponent.Z != 0) ScaleOffset = scale.Z;
- ScaleOffset = Math.Abs(ScaleOffset);
- Vector3 intersectionpoint = new Vector3(ei.ipoint.X, ei.ipoint.Y, ei.ipoint.Z);
- Vector3 normal = new Vector3(ei.normal.X, ei.normal.Y, ei.normal.Z);
- Vector3 offset = normal*(ScaleOffset/2f);
- pos = intersectionpoint + offset;
-
- // stick in offset format from the original prim
- pos = pos - target.ParentEntity.AbsolutePosition;
- if (CopyRotates)
- {
- Quaternion worldRot = target2.GetWorldRotation();
-
- // SceneObjectGroup obj = m_sceneGraph.DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
- DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID, worldRot);
- //obj.Rotation = worldRot;
- //obj.UpdateGroupRotationR(worldRot);
- }
- else
- {
- DuplicateObject(localID, pos, target.GetEffectiveObjectFlags(), AgentID, GroupID,
- Quaternion.Identity);
- }
- }
-
- return;
- }
-
- return;
- }
- }
-
- /// <value>
- /// Registered classes that are capable of creating entities.
- /// </value>
- protected Dictionary<PCode, IEntityCreator> m_entityCreators = new Dictionary<PCode, IEntityCreator>();
-
- public void RegisterEntityCreatorModule(IEntityCreator entityCreator)
- {
- lock (m_entityCreators)
- {
- foreach (PCode pcode in entityCreator.CreationCapabilities)
- {
- m_entityCreators[pcode] = entityCreator;
- }
- }
- }
-
- /// <summary>
- /// Unregister a module commander and all its commands
- /// </summary>
- /// <param name="entityCreator"></param>
- public void UnregisterEntityCreatorCommander(IEntityCreator entityCreator)
- {
- lock (m_entityCreators)
- {
- foreach (PCode pcode in entityCreator.CreationC…
Large files files are truncated, but you can click here to view the full file