aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneGraph.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/Framework/Scenes/SceneGraph.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneGraph.cs')
-rwxr-xr-xOpenSim/Region/Framework/Scenes/SceneGraph.cs2067
1 files changed, 2067 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
new file mode 100755
index 0000000..c2e9b61
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -0,0 +1,2067 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Threading;
30using System.Collections.Generic;
31using System.Reflection;
32using OpenMetaverse;
33using OpenMetaverse.Packets;
34using log4net;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Scenes.Types;
37using OpenSim.Region.Physics.Manager;
38using OpenSim.Region.Framework.Interfaces;
39
40namespace OpenSim.Region.Framework.Scenes
41{
42 public delegate void PhysicsCrash();
43
44 /// <summary>
45 /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components
46 /// should be migrated out over time.
47 /// </summary>
48 public class SceneGraph
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51
52 #region Events
53
54 protected internal event PhysicsCrash UnRecoverableError;
55 private PhysicsCrash handlerPhysicsCrash = null;
56
57 #endregion
58
59 #region Fields
60
61 protected object m_presenceLock = new object();
62 protected Dictionary<UUID, ScenePresence> m_scenePresenceMap = new Dictionary<UUID, ScenePresence>();
63 protected List<ScenePresence> m_scenePresenceArray = new List<ScenePresence>();
64
65 protected internal EntityManager Entities = new EntityManager();
66
67 protected Scene m_parentScene;
68 protected Dictionary<UUID, SceneObjectGroup> m_updateList = new Dictionary<UUID, SceneObjectGroup>();
69 protected int m_numRootAgents = 0;
70 protected int m_numTotalPrim = 0;
71 protected int m_numPrim = 0;
72 protected int m_numMesh = 0;
73 protected int m_numChildAgents = 0;
74 protected int m_physicalPrim = 0;
75
76 protected int m_activeScripts = 0;
77 protected int m_scriptLPS = 0;
78
79 protected internal PhysicsScene _PhyScene;
80
81 /// <summary>
82 /// Index the SceneObjectGroup for each part by the root part's UUID.
83 /// </summary>
84 protected internal Dictionary<UUID, SceneObjectGroup> SceneObjectGroupsByFullID = new Dictionary<UUID, SceneObjectGroup>();
85
86 /// <summary>
87 /// Index the SceneObjectGroup for each part by that part's UUID.
88 /// </summary>
89 protected internal Dictionary<UUID, SceneObjectGroup> SceneObjectGroupsByFullPartID = new Dictionary<UUID, SceneObjectGroup>();
90
91 /// <summary>
92 /// Index the SceneObjectGroup for each part by that part's local ID.
93 /// </summary>
94 protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalPartID = new Dictionary<uint, SceneObjectGroup>();
95
96 /// <summary>
97 /// Lock to prevent object group update, linking, delinking and duplication operations from running concurrently.
98 /// </summary>
99 /// <remarks>
100 /// These operations rely on the parts composition of the object. If allowed to run concurrently then race
101 /// conditions can occur.
102 /// </remarks>
103 private Object m_updateLock = new Object();
104
105 #endregion
106
107 protected internal SceneGraph(Scene parent)
108 {
109 m_parentScene = parent;
110 }
111
112 public PhysicsScene PhysicsScene
113 {
114 get { return _PhyScene; }
115 set
116 {
117 // If we're not doing the initial set
118 // Then we've got to remove the previous
119 // event handler
120 if (_PhyScene != null)
121 _PhyScene.OnPhysicsCrash -= physicsBasedCrash;
122
123 _PhyScene = value;
124
125 if (_PhyScene != null)
126 _PhyScene.OnPhysicsCrash += physicsBasedCrash;
127 }
128 }
129
130 protected internal void Close()
131 {
132 lock (m_presenceLock)
133 {
134 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>();
135 List<ScenePresence> newlist = new List<ScenePresence>();
136 m_scenePresenceMap = newmap;
137 m_scenePresenceArray = newlist;
138 }
139
140 lock (SceneObjectGroupsByFullID)
141 SceneObjectGroupsByFullID.Clear();
142 lock (SceneObjectGroupsByFullPartID)
143 SceneObjectGroupsByFullPartID.Clear();
144 lock (SceneObjectGroupsByLocalPartID)
145 SceneObjectGroupsByLocalPartID.Clear();
146
147 Entities.Clear();
148 }
149
150 #region Update Methods
151
152 protected internal void UpdatePreparePhysics()
153 {
154 // If we are using a threaded physics engine
155 // grab the latest scene from the engine before
156 // trying to process it.
157
158 // PhysX does this (runs in the background).
159
160 if (_PhyScene.IsThreaded)
161 {
162 _PhyScene.GetResults();
163 }
164 }
165
166 /// <summary>
167 /// Update the position of all the scene presences.
168 /// </summary>
169 /// <remarks>
170 /// Called only from the main scene loop.
171 /// </remarks>
172 protected internal void UpdatePresences()
173 {
174 ForEachScenePresence(delegate(ScenePresence presence)
175 {
176 presence.Update();
177 });
178 }
179
180 /// <summary>
181 /// Perform a physics frame update.
182 /// </summary>
183 /// <param name="elapsed"></param>
184 /// <returns></returns>
185 protected internal float UpdatePhysics(double elapsed)
186 {
187 // Here is where the Scene calls the PhysicsScene. This is a one-way
188 // interaction; the PhysicsScene cannot access the calling Scene directly.
189 // But with joints, we want a PhysicsActor to be able to influence a
190 // non-physics SceneObjectPart. In particular, a PhysicsActor that is connected
191 // with a joint should be able to move the SceneObjectPart which is the visual
192 // representation of that joint (for editing and serialization purposes).
193 // However the PhysicsActor normally cannot directly influence anything outside
194 // of the PhysicsScene, and the non-physical SceneObjectPart which represents
195 // the joint in the Scene does not exist in the PhysicsScene.
196 //
197 // To solve this, we have an event in the PhysicsScene that is fired when a joint
198 // has changed position (because one of its associated PhysicsActors has changed
199 // position).
200 //
201 // Therefore, JointMoved and JointDeactivated events will be fired as a result of the following Simulate().
202 return _PhyScene.Simulate((float)elapsed);
203 }
204
205 protected internal void UpdateScenePresenceMovement()
206 {
207 ForEachScenePresence(delegate(ScenePresence presence)
208 {
209 presence.UpdateMovement();
210 });
211 }
212
213 public void GetCoarseLocations(out List<Vector3> coarseLocations, out List<UUID> avatarUUIDs, uint maxLocations)
214 {
215 coarseLocations = new List<Vector3>();
216 avatarUUIDs = new List<UUID>();
217
218 List<ScenePresence> presences = GetScenePresences();
219 for (int i = 0; i < Math.Min(presences.Count, maxLocations); ++i)
220 {
221 ScenePresence sp = presences[i];
222
223 // If this presence is a child agent, we don't want its coarse locations
224 if (sp.IsChildAgent)
225 continue;
226
227 coarseLocations.Add(sp.AbsolutePosition);
228
229 avatarUUIDs.Add(sp.UUID);
230 }
231 }
232
233 #endregion
234
235 #region Entity Methods
236
237 /// <summary>
238 /// Add an object into the scene that has come from storage
239 /// </summary>
240 /// <param name="sceneObject"></param>
241 /// <param name="attachToBackup">
242 /// If true, changes to the object will be reflected in its persisted data
243 /// If false, the persisted data will not be changed even if the object in the scene is changed
244 /// </param>
245 /// <param name="alreadyPersisted">
246 /// If true, we won't persist this object until it changes
247 /// If false, we'll persist this object immediately
248 /// </param>
249 /// <param name="sendClientUpdates">
250 /// If true, we send updates to the client to tell it about this object
251 /// If false, we leave it up to the caller to do this
252 /// </param>
253 /// <returns>
254 /// true if the object was added, false if an object with the same uuid was already in the scene
255 /// </returns>
256 protected internal bool AddRestoredSceneObject(
257 SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted, bool sendClientUpdates)
258 {
259 if (attachToBackup && (!alreadyPersisted))
260 {
261 sceneObject.ForceInventoryPersistence();
262 sceneObject.HasGroupChanged = true;
263 }
264
265 return AddSceneObject(sceneObject, attachToBackup, sendClientUpdates);
266 }
267
268 /// <summary>
269 /// Add a newly created object to the scene. This will both update the scene, and send information about the
270 /// new object to all clients interested in the scene.
271 /// </summary>
272 /// <param name="sceneObject"></param>
273 /// <param name="attachToBackup">
274 /// If true, the object is made persistent into the scene.
275 /// If false, the object will not persist over server restarts
276 /// </param>
277 /// <returns>
278 /// true if the object was added, false if an object with the same uuid was already in the scene
279 /// </returns>
280 protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
281 {
282 // Ensure that we persist this new scene object if it's not an
283 // attachment
284 if (attachToBackup)
285 sceneObject.HasGroupChanged = true;
286
287 return AddSceneObject(sceneObject, attachToBackup, sendClientUpdates);
288 }
289
290 /// <summary>
291 /// Add a newly created object to the scene.
292 /// </summary>
293 ///
294 /// This method does not send updates to the client - callers need to handle this themselves.
295 /// Caller should also trigger EventManager.TriggerObjectAddedToScene
296 /// <param name="sceneObject"></param>
297 /// <param name="attachToBackup"></param>
298 /// <param name="pos">Position of the object. If null then the position stored in the object is used.</param>
299 /// <param name="rot">Rotation of the object. If null then the rotation stored in the object is used.</param>
300 /// <param name="vel">Velocity of the object. This parameter only has an effect if the object is physical</param>
301 /// <returns></returns>
302 public bool AddNewSceneObject(
303 SceneObjectGroup sceneObject, bool attachToBackup, Vector3? pos, Quaternion? rot, Vector3 vel)
304 {
305 AddNewSceneObject(sceneObject, attachToBackup, false);
306
307 if (pos != null)
308 sceneObject.AbsolutePosition = (Vector3)pos;
309
310 if (sceneObject.RootPart.Shape.PCode == (byte)PCode.Prim)
311 {
312 sceneObject.ClearPartAttachmentData();
313 }
314
315 if (rot != null)
316 sceneObject.UpdateGroupRotationR((Quaternion)rot);
317
318 PhysicsActor pa = sceneObject.RootPart.PhysActor;
319 if (pa != null && pa.IsPhysical && vel != Vector3.Zero)
320 {
321 sceneObject.RootPart.ApplyImpulse((vel * sceneObject.GetMass()), false);
322 sceneObject.Velocity = vel;
323 }
324
325 return true;
326 }
327
328 /// <summary>
329 /// Add an object to the scene. This will both update the scene, and send information about the
330 /// new object to all clients interested in the scene.
331 /// </summary>
332 /// <remarks>
333 /// The object's stored position, rotation and velocity are used.
334 /// </remarks>
335 /// <param name="sceneObject"></param>
336 /// <param name="attachToBackup">
337 /// If true, the object is made persistent into the scene.
338 /// If false, the object will not persist over server restarts
339 /// </param>
340 /// <param name="sendClientUpdates">
341 /// If true, updates for the new scene object are sent to all viewers in range.
342 /// If false, it is left to the caller to schedule the update
343 /// </param>
344 /// <returns>
345 /// true if the object was added, false if an object with the same uuid was already in the scene
346 /// </returns>
347 protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup, bool sendClientUpdates)
348 {
349 if (sceneObject.UUID == UUID.Zero)
350 {
351 m_log.ErrorFormat(
352 "[SCENEGRAPH]: Tried to add scene object {0} to {1} with illegal UUID of {2}",
353 sceneObject.Name, m_parentScene.RegionInfo.RegionName, UUID.Zero);
354
355 return false;
356 }
357
358 if (Entities.ContainsKey(sceneObject.UUID))
359 {
360 m_log.DebugFormat(
361 "[SCENEGRAPH]: Scene graph for {0} already contains object {1} in AddSceneObject()",
362 m_parentScene.RegionInfo.RegionName, sceneObject.UUID);
363
364 return false;
365 }
366
367// m_log.DebugFormat(
368// "[SCENEGRAPH]: Adding scene object {0} {1}, with {2} parts on {3}",
369// sceneObject.Name, sceneObject.UUID, sceneObject.Parts.Length, m_parentScene.RegionInfo.RegionName);
370
371 SceneObjectPart[] parts = sceneObject.Parts;
372
373 // Clamp the sizes (scales) of the child prims and add the child prims to the count of all primitives
374 // (meshes and geometric primitives) in the scene; add child prims to m_numTotalPrim count
375 if (m_parentScene.m_clampPrimSize)
376 {
377 foreach (SceneObjectPart part in parts)
378 {
379 Vector3 scale = part.Shape.Scale;
380
381 scale.X = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.X));
382 scale.Y = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.Y));
383 scale.Z = Math.Max(m_parentScene.m_minNonphys, Math.Min(m_parentScene.m_maxNonphys, scale.Z));
384
385 part.Shape.Scale = scale;
386 }
387 }
388 m_numTotalPrim += parts.Length;
389
390 // Go through all parts (geometric primitives and meshes) of this Scene Object
391 foreach (SceneObjectPart part in parts)
392 {
393 // Keep track of the total number of meshes or geometric primitives now in the scene;
394 // determine which object this is based on its primitive type: sculpted (sculpt) prim refers to
395 // a mesh and all other prims (i.e. box, sphere, etc) are geometric primitives
396 if (part.GetPrimType() == PrimType.SCULPT)
397 m_numMesh++;
398 else
399 m_numPrim++;
400 }
401
402 sceneObject.AttachToScene(m_parentScene);
403
404 if (sendClientUpdates)
405 sceneObject.ScheduleGroupForFullUpdate();
406
407 Entities.Add(sceneObject);
408
409 if (attachToBackup)
410 sceneObject.AttachToBackup();
411
412 lock (SceneObjectGroupsByFullID)
413 SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject;
414
415 lock (SceneObjectGroupsByFullPartID)
416 {
417 foreach (SceneObjectPart part in parts)
418 SceneObjectGroupsByFullPartID[part.UUID] = sceneObject;
419 }
420
421 lock (SceneObjectGroupsByLocalPartID)
422 {
423// m_log.DebugFormat(
424// "[SCENE GRAPH]: Adding scene object {0} {1} {2} to SceneObjectGroupsByLocalPartID in {3}",
425// sceneObject.Name, sceneObject.UUID, sceneObject.LocalId, m_parentScene.RegionInfo.RegionName);
426
427 foreach (SceneObjectPart part in parts)
428 SceneObjectGroupsByLocalPartID[part.LocalId] = sceneObject;
429 }
430
431 return true;
432 }
433
434 /// <summary>
435 /// Delete an object from the scene
436 /// </summary>
437 /// <returns>true if the object was deleted, false if there was no object to delete</returns>
438 public bool DeleteSceneObject(UUID uuid, bool resultOfObjectLinked)
439 {
440// m_log.DebugFormat(
441// "[SCENE GRAPH]: Deleting scene object with uuid {0}, resultOfObjectLinked = {1}",
442// uuid, resultOfObjectLinked);
443
444 EntityBase entity;
445 if (!Entities.TryGetValue(uuid, out entity) || (!(entity is SceneObjectGroup)))
446 return false;
447
448 SceneObjectGroup grp = (SceneObjectGroup)entity;
449
450 if (entity == null)
451 return false;
452
453 if (!resultOfObjectLinked)
454 {
455 // Decrement the total number of primitives (meshes and geometric primitives)
456 // that are part of the Scene Object being removed
457 m_numTotalPrim -= grp.PrimCount;
458
459 // Go through all parts (primitives and meshes) of this Scene Object
460 foreach (SceneObjectPart part in grp.Parts)
461 {
462 // Keep track of the total number of meshes or geometric primitives left in the scene;
463 // determine which object this is based on its primitive type: sculpted (sculpt) prim refers to
464 // a mesh and all other prims (i.e. box, sphere, etc) are geometric primitives
465 if (part.GetPrimType() == PrimType.SCULPT)
466 m_numMesh--;
467 else
468 m_numPrim--;
469 }
470
471 if ((grp.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics)
472 RemovePhysicalPrim(grp.PrimCount);
473 }
474
475 lock (SceneObjectGroupsByFullID)
476 SceneObjectGroupsByFullID.Remove(grp.UUID);
477
478 lock (SceneObjectGroupsByFullPartID)
479 {
480 SceneObjectPart[] parts = grp.Parts;
481 for (int i = 0; i < parts.Length; i++)
482 SceneObjectGroupsByFullPartID.Remove(parts[i].UUID);
483 }
484
485 lock (SceneObjectGroupsByLocalPartID)
486 {
487 SceneObjectPart[] parts = grp.Parts;
488 for (int i = 0; i < parts.Length; i++)
489 SceneObjectGroupsByLocalPartID.Remove(parts[i].LocalId);
490 }
491
492 return Entities.Remove(uuid);
493 }
494
495 /// <summary>
496 /// Add an object to the list of prims to process on the next update
497 /// </summary>
498 /// <param name="obj">
499 /// A <see cref="SceneObjectGroup"/>
500 /// </param>
501 protected internal void AddToUpdateList(SceneObjectGroup obj)
502 {
503 lock (m_updateList)
504 m_updateList[obj.UUID] = obj;
505 }
506
507 /// <summary>
508 /// Process all pending updates
509 /// </summary>
510 protected internal void UpdateObjectGroups()
511 {
512 if (!Monitor.TryEnter(m_updateLock))
513 return;
514 try
515 {
516 List<SceneObjectGroup> updates;
517
518 // Some updates add more updates to the updateList.
519 // Get the current list of updates and clear the list before iterating
520 lock (m_updateList)
521 {
522 updates = new List<SceneObjectGroup>(m_updateList.Values);
523 m_updateList.Clear();
524 }
525
526 // Go through all updates
527 for (int i = 0; i < updates.Count; i++)
528 {
529 SceneObjectGroup sog = updates[i];
530
531 // Don't abort the whole update if one entity happens to give us an exception.
532 try
533 {
534 sog.Update();
535 }
536 catch (Exception e)
537 {
538 m_log.ErrorFormat(
539 "[INNER SCENE]: Failed to update {0}, {1} - {2}", sog.Name, sog.UUID, e);
540 }
541 }
542 }
543 finally
544 {
545 Monitor.Exit(m_updateLock);
546 }
547 }
548
549 protected internal void AddPhysicalPrim(int number)
550 {
551 m_physicalPrim += number;
552 }
553
554 protected internal void RemovePhysicalPrim(int number)
555 {
556 m_physicalPrim -= number;
557 }
558
559 protected internal void AddToScriptLPS(int number)
560 {
561 m_scriptLPS += number;
562 }
563
564 protected internal void AddActiveScripts(int number)
565 {
566 m_activeScripts += number;
567 }
568
569 protected internal void HandleUndo(IClientAPI remoteClient, UUID primId)
570 {
571 if (primId != UUID.Zero)
572 {
573 SceneObjectPart part = m_parentScene.GetSceneObjectPart(primId);
574 if (part != null)
575 part.Undo();
576 }
577 }
578
579 protected internal void HandleRedo(IClientAPI remoteClient, UUID primId)
580 {
581 if (primId != UUID.Zero)
582 {
583 SceneObjectPart part = m_parentScene.GetSceneObjectPart(primId);
584
585 if (part != null)
586 part.Redo();
587 }
588 }
589
590 protected internal ScenePresence CreateAndAddChildScenePresence(
591 IClientAPI client, AvatarAppearance appearance, PresenceType type)
592 {
593 // ScenePresence always defaults to child agent
594 ScenePresence presence = new ScenePresence(client, m_parentScene, appearance, type);
595
596 Entities[presence.UUID] = presence;
597
598 lock (m_presenceLock)
599 {
600 m_numChildAgents++;
601
602 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
603 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
604
605 if (!newmap.ContainsKey(presence.UUID))
606 {
607 newmap.Add(presence.UUID, presence);
608 newlist.Add(presence);
609 }
610 else
611 {
612 // Remember the old presence reference from the dictionary
613 ScenePresence oldref = newmap[presence.UUID];
614 // Replace the presence reference in the dictionary with the new value
615 newmap[presence.UUID] = presence;
616 // Find the index in the list where the old ref was stored and update the reference
617 newlist[newlist.IndexOf(oldref)] = presence;
618 }
619
620 // Swap out the dictionary and list with new references
621 m_scenePresenceMap = newmap;
622 m_scenePresenceArray = newlist;
623 }
624
625 return presence;
626 }
627
628 /// <summary>
629 /// Remove a presence from the scene
630 /// </summary>
631 protected internal void RemoveScenePresence(UUID agentID)
632 {
633 if (!Entities.Remove(agentID))
634 {
635 m_log.WarnFormat(
636 "[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene Entities list",
637 agentID);
638 }
639
640 lock (m_presenceLock)
641 {
642 Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
643 List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
644
645 // Remove the presence reference from the dictionary
646 if (newmap.ContainsKey(agentID))
647 {
648 ScenePresence oldref = newmap[agentID];
649 newmap.Remove(agentID);
650
651 // Find the index in the list where the old ref was stored and remove the reference
652 newlist.RemoveAt(newlist.IndexOf(oldref));
653 // Swap out the dictionary and list with new references
654 m_scenePresenceMap = newmap;
655 m_scenePresenceArray = newlist;
656 }
657 else
658 {
659 m_log.WarnFormat("[SCENE GRAPH]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
660 }
661 }
662 }
663
664 protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
665 {
666 if (direction_RC_CR_T_F)
667 {
668 m_numRootAgents--;
669 m_numChildAgents++;
670 }
671 else
672 {
673 m_numChildAgents--;
674 m_numRootAgents++;
675 }
676 }
677
678 public void removeUserCount(bool TypeRCTF)
679 {
680 if (TypeRCTF)
681 {
682 m_numRootAgents--;
683 }
684 else
685 {
686 m_numChildAgents--;
687 }
688 }
689
690 public void RecalculateStats()
691 {
692 int rootcount = 0;
693 int childcount = 0;
694
695 ForEachScenePresence(delegate(ScenePresence presence)
696 {
697 if (presence.IsChildAgent)
698 ++childcount;
699 else
700 ++rootcount;
701 });
702
703 m_numRootAgents = rootcount;
704 m_numChildAgents = childcount;
705 }
706
707 public int GetChildAgentCount()
708 {
709 return m_numChildAgents;
710 }
711
712 public int GetRootAgentCount()
713 {
714 return m_numRootAgents;
715 }
716
717 public int GetTotalObjectsCount()
718 {
719 return m_numTotalPrim;
720 }
721
722 public int GetTotalPrimObjectsCount()
723 {
724 return m_numPrim;
725 }
726
727 public int GetTotalMeshObjectsCount()
728 {
729 return m_numMesh;
730 }
731
732 public int GetActiveObjectsCount()
733 {
734 return m_physicalPrim;
735 }
736
737 public int GetActiveScriptsCount()
738 {
739 return m_activeScripts;
740 }
741
742 public int GetScriptLPS()
743 {
744 int returnval = m_scriptLPS;
745 m_scriptLPS = 0;
746 return returnval;
747 }
748
749 #endregion
750
751 #region Get Methods
752
753 /// <summary>
754 /// Get the controlling client for the given avatar, if there is one.
755 ///
756 /// FIXME: The only user of the method right now is Caps.cs, in order to resolve a client API since it can't
757 /// use the ScenePresence. This could be better solved in a number of ways - we could establish an
758 /// OpenSim.Framework.IScenePresence, or move the caps code into a region package (which might be the more
759 /// suitable solution).
760 /// </summary>
761 /// <param name="agentId"></param>
762 /// <returns>null if either the avatar wasn't in the scene, or
763 /// they do not have a controlling client</returns>
764 /// <remarks>this used to be protected internal, but that
765 /// prevents CapabilitiesModule from accessing it</remarks>
766 public IClientAPI GetControllingClient(UUID agentId)
767 {
768 ScenePresence presence = GetScenePresence(agentId);
769
770 if (presence != null)
771 {
772 return presence.ControllingClient;
773 }
774
775 return null;
776 }
777
778 /// <summary>
779 /// Get a reference to the scene presence list. Changes to the list will be done in a copy
780 /// There is no guarantee that presences will remain in the scene after the list is returned.
781 /// This list should remain private to SceneGraph. Callers wishing to iterate should instead
782 /// pass a delegate to ForEachScenePresence.
783 /// </summary>
784 /// <returns></returns>
785 protected internal List<ScenePresence> GetScenePresences()
786 {
787 return m_scenePresenceArray;
788 }
789
790 /// <summary>
791 /// Request a scene presence by UUID. Fast, indexed lookup.
792 /// </summary>
793 /// <param name="agentID"></param>
794 /// <returns>null if the presence was not found</returns>
795 protected internal ScenePresence GetScenePresence(UUID agentID)
796 {
797 Dictionary<UUID, ScenePresence> presences = m_scenePresenceMap;
798 ScenePresence presence;
799 presences.TryGetValue(agentID, out presence);
800 return presence;
801 }
802
803 /// <summary>
804 /// Request the scene presence by name.
805 /// </summary>
806 /// <param name="firstName"></param>
807 /// <param name="lastName"></param>
808 /// <returns>null if the presence was not found</returns>
809 protected internal ScenePresence GetScenePresence(string firstName, string lastName)
810 {
811 List<ScenePresence> presences = GetScenePresences();
812 foreach (ScenePresence presence in presences)
813 {
814 if (string.Equals(presence.Firstname, firstName, StringComparison.CurrentCultureIgnoreCase)
815 && string.Equals(presence.Lastname, lastName, StringComparison.CurrentCultureIgnoreCase))
816 return presence;
817 }
818 return null;
819 }
820
821 /// <summary>
822 /// Request the scene presence by localID.
823 /// </summary>
824 /// <param name="localID"></param>
825 /// <returns>null if the presence was not found</returns>
826 protected internal ScenePresence GetScenePresence(uint localID)
827 {
828 List<ScenePresence> presences = GetScenePresences();
829 foreach (ScenePresence presence in presences)
830 if (presence.LocalId == localID)
831 return presence;
832 return null;
833 }
834
835 protected internal bool TryGetScenePresence(UUID agentID, out ScenePresence avatar)
836 {
837 Dictionary<UUID, ScenePresence> presences = m_scenePresenceMap;
838 presences.TryGetValue(agentID, out avatar);
839 return (avatar != null);
840 }
841
842 protected internal bool TryGetAvatarByName(string name, out ScenePresence avatar)
843 {
844 avatar = null;
845 foreach (ScenePresence presence in GetScenePresences())
846 {
847 if (String.Compare(name, presence.ControllingClient.Name, true) == 0)
848 {
849 avatar = presence;
850 break;
851 }
852 }
853 return (avatar != null);
854 }
855
856 /// <summary>
857 /// Get a scene object group that contains the prim with the given local id
858 /// </summary>
859 /// <param name="localID"></param>
860 /// <returns>null if no scene object group containing that prim is found</returns>
861 public SceneObjectGroup GetGroupByPrim(uint localID)
862 {
863 EntityBase entity;
864 if (Entities.TryGetValue(localID, out entity))
865 return entity as SceneObjectGroup;
866
867// m_log.DebugFormat("[SCENE GRAPH]: Entered GetGroupByPrim with localID {0}", localID);
868
869 SceneObjectGroup sog;
870 lock (SceneObjectGroupsByLocalPartID)
871 SceneObjectGroupsByLocalPartID.TryGetValue(localID, out sog);
872
873 if (sog != null)
874 {
875 if (sog.ContainsPart(localID))
876 {
877// m_log.DebugFormat(
878// "[SCENE GRAPH]: Found scene object {0} {1} {2} containing part with local id {3} in {4}. Returning.",
879// sog.Name, sog.UUID, sog.LocalId, localID, m_parentScene.RegionInfo.RegionName);
880
881 return sog;
882 }
883 else
884 {
885 lock (SceneObjectGroupsByLocalPartID)
886 {
887 m_log.WarnFormat(
888 "[SCENE GRAPH]: Found scene object {0} {1} {2} via SceneObjectGroupsByLocalPartID index but it doesn't contain part with local id {3}. Removing from entry from index in {4}.",
889 sog.Name, sog.UUID, sog.LocalId, localID, m_parentScene.RegionInfo.RegionName);
890
891 SceneObjectGroupsByLocalPartID.Remove(localID);
892 }
893 }
894 }
895
896 EntityBase[] entityList = GetEntities();
897 foreach (EntityBase ent in entityList)
898 {
899 //m_log.DebugFormat("Looking at entity {0}", ent.UUID);
900 if (ent is SceneObjectGroup)
901 {
902 sog = (SceneObjectGroup)ent;
903 if (sog.ContainsPart(localID))
904 {
905 lock (SceneObjectGroupsByLocalPartID)
906 SceneObjectGroupsByLocalPartID[localID] = sog;
907 return sog;
908 }
909 }
910 }
911
912 return null;
913 }
914
915 /// <summary>
916 /// Get a scene object group that contains the prim with the given uuid
917 /// </summary>
918 /// <param name="fullID"></param>
919 /// <returns>null if no scene object group containing that prim is found</returns>
920 public SceneObjectGroup GetGroupByPrim(UUID fullID)
921 {
922 SceneObjectGroup sog;
923 lock (SceneObjectGroupsByFullPartID)
924 SceneObjectGroupsByFullPartID.TryGetValue(fullID, out sog);
925
926 if (sog != null)
927 {
928 if (sog.ContainsPart(fullID))
929 return sog;
930
931 lock (SceneObjectGroupsByFullPartID)
932 SceneObjectGroupsByFullPartID.Remove(fullID);
933 }
934
935 EntityBase[] entityList = GetEntities();
936 foreach (EntityBase ent in entityList)
937 {
938 if (ent is SceneObjectGroup)
939 {
940 sog = (SceneObjectGroup)ent;
941 if (sog.ContainsPart(fullID))
942 {
943 lock (SceneObjectGroupsByFullPartID)
944 SceneObjectGroupsByFullPartID[fullID] = sog;
945 return sog;
946 }
947 }
948 }
949
950 return null;
951 }
952
953 protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
954 {
955 // Primitive Ray Tracing
956 float closestDistance = 280f;
957 EntityIntersection result = new EntityIntersection();
958 EntityBase[] EntityList = GetEntities();
959 foreach (EntityBase ent in EntityList)
960 {
961 if (ent is SceneObjectGroup)
962 {
963 SceneObjectGroup reportingG = (SceneObjectGroup)ent;
964 EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
965 if (inter.HitTF && inter.distance < closestDistance)
966 {
967 closestDistance = inter.distance;
968 result = inter;
969 }
970 }
971 }
972 return result;
973 }
974
975 /// <summary>
976 /// Get all the scene object groups.
977 /// </summary>
978 /// <returns>
979 /// The scene object groups. If the scene is empty then an empty list is returned.
980 /// </returns>
981 protected internal List<SceneObjectGroup> GetSceneObjectGroups()
982 {
983 lock (SceneObjectGroupsByFullID)
984 return new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values);
985 }
986
987 /// <summary>
988 /// Get a group in the scene
989 /// </summary>
990 /// <param name="fullID">UUID of the group</param>
991 /// <returns>null if no such group was found</returns>
992 protected internal SceneObjectGroup GetSceneObjectGroup(UUID fullID)
993 {
994 lock (SceneObjectGroupsByFullID)
995 {
996 if (SceneObjectGroupsByFullID.ContainsKey(fullID))
997 return SceneObjectGroupsByFullID[fullID];
998 }
999
1000 return null;
1001 }
1002
1003 /// <summary>
1004 /// Get a group in the scene
1005 /// </summary>
1006 /// <remarks>
1007 /// This will only return a group if the local ID matches the root part, not other parts.
1008 /// </remarks>
1009 /// <param name="localID">Local id of the root part of the group</param>
1010 /// <returns>null if no such group was found</returns>
1011 protected internal SceneObjectGroup GetSceneObjectGroup(uint localID)
1012 {
1013 lock (SceneObjectGroupsByLocalPartID)
1014 {
1015 if (SceneObjectGroupsByLocalPartID.ContainsKey(localID))
1016 {
1017 SceneObjectGroup so = SceneObjectGroupsByLocalPartID[localID];
1018
1019 if (so.LocalId == localID)
1020 return so;
1021 }
1022 }
1023
1024 return null;
1025 }
1026
1027 /// <summary>
1028 /// Get a group by name from the scene (will return the first
1029 /// found, if there are more than one prim with the same name)
1030 /// </summary>
1031 /// <param name="name"></param>
1032 /// <returns>null if the part was not found</returns>
1033 protected internal SceneObjectGroup GetSceneObjectGroup(string name)
1034 {
1035 SceneObjectGroup so = null;
1036
1037 Entities.Find(
1038 delegate(EntityBase entity)
1039 {
1040 if (entity is SceneObjectGroup)
1041 {
1042 if (entity.Name == name)
1043 {
1044 so = (SceneObjectGroup)entity;
1045 return true;
1046 }
1047 }
1048
1049 return false;
1050 }
1051 );
1052
1053 return so;
1054 }
1055
1056 /// <summary>
1057 /// Get a part contained in this scene.
1058 /// </summary>
1059 /// <param name="localID"></param>
1060 /// <returns>null if the part was not found</returns>
1061 protected internal SceneObjectPart GetSceneObjectPart(uint localID)
1062 {
1063 SceneObjectGroup group = GetGroupByPrim(localID);
1064 if (group == null)
1065 return null;
1066 return group.GetPart(localID);
1067 }
1068
1069 /// <summary>
1070 /// Get a prim by name from the scene (will return the first
1071 /// found, if there are more than one prim with the same name)
1072 /// </summary>
1073 /// <param name="name"></param>
1074 /// <returns>null if the part was not found</returns>
1075 protected internal SceneObjectPart GetSceneObjectPart(string name)
1076 {
1077 SceneObjectPart sop = null;
1078
1079 Entities.Find(
1080 delegate(EntityBase entity)
1081 {
1082 if (entity is SceneObjectGroup)
1083 {
1084 foreach (SceneObjectPart p in ((SceneObjectGroup)entity).Parts)
1085 {
1086// m_log.DebugFormat("[SCENE GRAPH]: Part {0} has name {1}", p.UUID, p.Name);
1087
1088 if (p.Name == name)
1089 {
1090 sop = p;
1091 return true;
1092 }
1093 }
1094 }
1095
1096 return false;
1097 }
1098 );
1099
1100 return sop;
1101 }
1102
1103 /// <summary>
1104 /// Get a part contained in this scene.
1105 /// </summary>
1106 /// <param name="fullID"></param>
1107 /// <returns>null if the part was not found</returns>
1108 protected internal SceneObjectPart GetSceneObjectPart(UUID fullID)
1109 {
1110 SceneObjectGroup group = GetGroupByPrim(fullID);
1111 if (group == null)
1112 return null;
1113 return group.GetPart(fullID);
1114 }
1115
1116 /// <summary>
1117 /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
1118 /// it
1119 /// </summary>
1120 /// <returns></returns>
1121 protected internal EntityBase[] GetEntities()
1122 {
1123 return Entities.GetEntities();
1124 }
1125
1126 #endregion
1127
1128 #region Other Methods
1129
1130 protected internal void physicsBasedCrash()
1131 {
1132 handlerPhysicsCrash = UnRecoverableError;
1133 if (handlerPhysicsCrash != null)
1134 {
1135 handlerPhysicsCrash();
1136 }
1137 }
1138
1139 protected internal UUID ConvertLocalIDToFullID(uint localID)
1140 {
1141 SceneObjectGroup group = GetGroupByPrim(localID);
1142 if (group != null)
1143 return group.GetPartsFullID(localID);
1144 else
1145 return UUID.Zero;
1146 }
1147
1148 /// <summary>
1149 /// Performs action once on all scene object groups.
1150 /// </summary>
1151 /// <param name="action"></param>
1152 protected internal void ForEachSOG(Action<SceneObjectGroup> action)
1153 {
1154 foreach (SceneObjectGroup obj in GetSceneObjectGroups())
1155 {
1156 try
1157 {
1158 action(obj);
1159 }
1160 catch (Exception e)
1161 {
1162 // Catch it and move on. This includes situations where objlist has inconsistent info
1163 m_log.WarnFormat(
1164 "[SCENEGRAPH]: Problem processing action in ForEachSOG: {0} {1}", e.Message, e.StackTrace);
1165 }
1166 }
1167 }
1168
1169 /// <summary>
1170 /// Performs action on all ROOT (not child) scene presences.
1171 /// This is just a shortcut function since frequently actions only appy to root SPs
1172 /// </summary>
1173 /// <param name="action"></param>
1174 public void ForEachAvatar(Action<ScenePresence> action)
1175 {
1176 ForEachScenePresence(delegate(ScenePresence sp)
1177 {
1178 if (!sp.IsChildAgent)
1179 action(sp);
1180 });
1181 }
1182
1183 /// <summary>
1184 /// Performs action on all scene presences. This can ultimately run the actions in parallel but
1185 /// any delegates passed in will need to implement their own locking on data they reference and
1186 /// modify outside of the scope of the delegate.
1187 /// </summary>
1188 /// <param name="action"></param>
1189 public void ForEachScenePresence(Action<ScenePresence> action)
1190 {
1191 // Once all callers have their delegates configured for parallelism, we can unleash this
1192 /*
1193 Action<ScenePresence> protectedAction = new Action<ScenePresence>(delegate(ScenePresence sp)
1194 {
1195 try
1196 {
1197 action(sp);
1198 }
1199 catch (Exception e)
1200 {
1201 m_log.Info("[SCENEGRAPH]: Error in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1202 m_log.Info("[SCENEGRAPH]: Stack Trace: " + e.StackTrace);
1203 }
1204 });
1205 Parallel.ForEach<ScenePresence>(GetScenePresences(), protectedAction);
1206 */
1207 // For now, perform actions serially
1208 List<ScenePresence> presences = GetScenePresences();
1209 foreach (ScenePresence sp in presences)
1210 {
1211 try
1212 {
1213 action(sp);
1214 }
1215 catch (Exception e)
1216 {
1217 m_log.Error("[SCENEGRAPH]: Error in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString());
1218 }
1219 }
1220 }
1221
1222 #endregion
1223
1224 #region Client Event handlers
1225
1226 /// <summary>
1227 /// Update the scale of an individual prim.
1228 /// </summary>
1229 /// <param name="localID"></param>
1230 /// <param name="scale"></param>
1231 /// <param name="remoteClient"></param>
1232 protected internal void UpdatePrimScale(uint localID, Vector3 scale, IClientAPI remoteClient)
1233 {
1234 SceneObjectPart part = GetSceneObjectPart(localID);
1235
1236 if (part != null)
1237 {
1238 if (m_parentScene.Permissions.CanEditObject(part.ParentGroup.UUID, remoteClient.AgentId))
1239 {
1240 part.Resize(scale);
1241 }
1242 }
1243 }
1244
1245 protected internal void UpdatePrimGroupScale(uint localID, Vector3 scale, IClientAPI remoteClient)
1246 {
1247 SceneObjectGroup group = GetGroupByPrim(localID);
1248 if (group != null)
1249 {
1250 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1251 {
1252 group.GroupResize(scale);
1253 }
1254 }
1255 }
1256
1257 /// <summary>
1258 /// This handles the nifty little tool tip that you get when you drag your mouse over an object
1259 /// Send to the Object Group to process. We don't know enough to service the request
1260 /// </summary>
1261 /// <param name="remoteClient"></param>
1262 /// <param name="AgentID"></param>
1263 /// <param name="RequestFlags"></param>
1264 /// <param name="ObjectID"></param>
1265 protected internal void RequestObjectPropertiesFamily(
1266 IClientAPI remoteClient, UUID AgentID, uint RequestFlags, UUID ObjectID)
1267 {
1268 SceneObjectGroup group = GetGroupByPrim(ObjectID);
1269 if (group != null)
1270 {
1271 group.ServiceObjectPropertiesFamilyRequest(remoteClient, AgentID, RequestFlags);
1272 }
1273 }
1274
1275 /// <summary>
1276 ///
1277 /// </summary>
1278 /// <param name="localID"></param>
1279 /// <param name="rot"></param>
1280 /// <param name="remoteClient"></param>
1281 protected internal void UpdatePrimSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
1282 {
1283 SceneObjectGroup group = GetGroupByPrim(localID);
1284 if (group != null)
1285 {
1286 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
1287 {
1288 group.UpdateSingleRotation(rot, localID);
1289 }
1290 }
1291 }
1292
1293 /// <summary>
1294 ///
1295 /// </summary>
1296 /// <param name="localID"></param>
1297 /// <param name="rot"></param>
1298 /// <param name="remoteClient"></param>
1299 protected internal void UpdatePrimSingleRotationPosition(uint localID, Quaternion rot, Vector3 pos, IClientAPI remoteClient)
1300 {
1301 SceneObjectGroup group = GetGroupByPrim(localID);
1302 if (group != null)
1303 {
1304 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
1305 {
1306 group.UpdateSingleRotation(rot, pos, localID);
1307 }
1308 }
1309 }
1310
1311 /// <summary>
1312 /// Update the rotation of a whole group.
1313 /// </summary>
1314 /// <param name="localID"></param>
1315 /// <param name="rot"></param>
1316 /// <param name="remoteClient"></param>
1317 protected internal void UpdatePrimGroupRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
1318 {
1319 SceneObjectGroup group = GetGroupByPrim(localID);
1320 if (group != null)
1321 {
1322 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
1323 {
1324 group.UpdateGroupRotationR(rot);
1325 }
1326 }
1327 }
1328
1329 /// <summary>
1330 ///
1331 /// </summary>
1332 /// <param name="localID"></param>
1333 /// <param name="pos"></param>
1334 /// <param name="rot"></param>
1335 /// <param name="remoteClient"></param>
1336 protected internal void UpdatePrimGroupRotation(uint localID, Vector3 pos, Quaternion rot, IClientAPI remoteClient)
1337 {
1338 SceneObjectGroup group = GetGroupByPrim(localID);
1339 if (group != null)
1340 {
1341 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
1342 {
1343 group.UpdateGroupRotationPR(pos, rot);
1344 }
1345 }
1346 }
1347
1348 /// <summary>
1349 /// Update the position of the given part
1350 /// </summary>
1351 /// <param name="localID"></param>
1352 /// <param name="pos"></param>
1353 /// <param name="remoteClient"></param>
1354 protected internal void UpdatePrimSinglePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
1355 {
1356 SceneObjectGroup group = GetGroupByPrim(localID);
1357 if (group != null)
1358 {
1359 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId) || group.IsAttachment)
1360 {
1361 group.UpdateSinglePosition(pos, localID);
1362 }
1363 }
1364 }
1365
1366 /// <summary>
1367 /// Update the position of the given group.
1368 /// </summary>
1369 /// <param name="localId"></param>
1370 /// <param name="pos"></param>
1371 /// <param name="remoteClient"></param>
1372 public void UpdatePrimGroupPosition(uint localId, Vector3 pos, IClientAPI remoteClient)
1373 {
1374 UpdatePrimGroupPosition(localId, pos, remoteClient.AgentId);
1375 }
1376
1377 /// <summary>
1378 /// Update the position of the given group.
1379 /// </summary>
1380 /// <param name="localId"></param>
1381 /// <param name="pos"></param>
1382 /// <param name="updatingAgentId"></param>
1383 public void UpdatePrimGroupPosition(uint localId, Vector3 pos, UUID updatingAgentId)
1384 {
1385 SceneObjectGroup group = GetGroupByPrim(localId);
1386
1387 if (group != null)
1388 {
1389 if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
1390 {
1391 if (m_parentScene.AttachmentsModule != null)
1392 m_parentScene.AttachmentsModule.UpdateAttachmentPosition(group, pos);
1393 }
1394 else
1395 {
1396 if (m_parentScene.Permissions.CanMoveObject(group.UUID, updatingAgentId)
1397 && m_parentScene.Permissions.CanObjectEntry(group.UUID, false, pos))
1398 {
1399 group.UpdateGroupPosition(pos);
1400 }
1401 }
1402 }
1403 }
1404
1405 /// <summary>
1406 /// Update the texture entry of the given prim.
1407 /// </summary>
1408 /// <remarks>
1409 /// A texture entry is an object that contains details of all the textures of the prim's face. In this case,
1410 /// the texture is given in its byte serialized form.
1411 /// </remarks>
1412 /// <param name="localID"></param>
1413 /// <param name="texture"></param>
1414 /// <param name="remoteClient"></param>
1415 protected internal void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
1416 {
1417 SceneObjectGroup group = GetGroupByPrim(localID);
1418
1419 if (group != null)
1420 {
1421 if (m_parentScene.Permissions.CanEditObject(group.UUID,remoteClient.AgentId))
1422 {
1423 group.UpdateTextureEntry(localID, texture);
1424 }
1425 }
1426 }
1427
1428 /// <summary>
1429 /// Update the flags on a scene object. This covers properties such as phantom, physics and temporary.
1430 /// </summary>
1431 /// <remarks>
1432 /// This is currently handling the incoming call from the client stack (e.g. LLClientView).
1433 /// </remarks>
1434 /// <param name="localID"></param>
1435 /// <param name="UsePhysics"></param>
1436 /// <param name="SetTemporary"></param>
1437 /// <param name="SetPhantom"></param>
1438 /// <param name="remoteClient"></param>
1439 protected internal void UpdatePrimFlags(
1440 uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, ExtraPhysicsData PhysData, IClientAPI remoteClient)
1441 {
1442 SceneObjectGroup group = GetGroupByPrim(localID);
1443 if (group != null)
1444 {
1445 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1446 {
1447 // VolumeDetect can't be set via UI and will always be off when a change is made there
1448 // now only change volume dtc if phantom off
1449
1450 if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data
1451 {
1452 bool vdtc;
1453 if (SetPhantom) // if phantom keep volumedtc
1454 vdtc = group.RootPart.VolumeDetectActive;
1455 else // else turn it off
1456 vdtc = false;
1457
1458 group.UpdatePrimFlags(localID, UsePhysics, SetTemporary, SetPhantom, vdtc);
1459 }
1460 else
1461 {
1462 SceneObjectPart part = GetSceneObjectPart(localID);
1463 if (part != null)
1464 {
1465 part.UpdateExtraPhysics(PhysData);
1466 if (part.UpdatePhysRequired)
1467 remoteClient.SendPartPhysicsProprieties(part);
1468 }
1469 }
1470 }
1471 }
1472 }
1473
1474 /// <summary>
1475 /// Move the given object
1476 /// </summary>
1477 /// <param name="objectID"></param>
1478 /// <param name="offset"></param>
1479 /// <param name="pos"></param>
1480 /// <param name="remoteClient"></param>
1481 protected internal void MoveObject(UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
1482 {
1483 SceneObjectGroup group = GetGroupByPrim(objectID);
1484 if (group != null)
1485 {
1486 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
1487 {
1488 group.GrabMovement(objectID, offset, pos, remoteClient);
1489 }
1490
1491 // This is outside the above permissions condition
1492 // so that if the object is locked the client moving the object
1493 // get's it's position on the simulator even if it was the same as before
1494 // This keeps the moving user's client in sync with the rest of the world.
1495 group.SendGroupTerseUpdate();
1496 }
1497 }
1498
1499 /// <summary>
1500 /// Start spinning the given object
1501 /// </summary>
1502 /// <param name="objectID"></param>
1503 /// <param name="rotation"></param>
1504 /// <param name="remoteClient"></param>
1505 protected internal void SpinStart(UUID objectID, IClientAPI remoteClient)
1506 {
1507 SceneObjectGroup group = GetGroupByPrim(objectID);
1508 if (group != null)
1509 {
1510 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
1511 {
1512 group.SpinStart(remoteClient);
1513 }
1514 }
1515 }
1516
1517 /// <summary>
1518 /// Spin the given object
1519 /// </summary>
1520 /// <param name="objectID"></param>
1521 /// <param name="rotation"></param>
1522 /// <param name="remoteClient"></param>
1523 protected internal void SpinObject(UUID objectID, Quaternion rotation, IClientAPI remoteClient)
1524 {
1525 SceneObjectGroup group = GetGroupByPrim(objectID);
1526 if (group != null)
1527 {
1528 if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
1529 {
1530 group.SpinMovement(rotation, remoteClient);
1531 }
1532 // This is outside the above permissions condition
1533 // so that if the object is locked the client moving the object
1534 // get's it's position on the simulator even if it was the same as before
1535 // This keeps the moving user's client in sync with the rest of the world.
1536 group.SendGroupTerseUpdate();
1537 }
1538 }
1539
1540 /// <summary>
1541 ///
1542 /// </summary>
1543 /// <param name="primLocalID"></param>
1544 /// <param name="description"></param>
1545 protected internal void PrimName(IClientAPI remoteClient, uint primLocalID, string name)
1546 {
1547 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1548 if (group != null)
1549 {
1550 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1551 {
1552 group.SetPartName(Util.CleanString(name), primLocalID);
1553 group.HasGroupChanged = true;
1554 }
1555 }
1556 }
1557
1558 /// <summary>
1559 /// Handle a prim description set request from a viewer.
1560 /// </summary>
1561 /// <param name="primLocalID"></param>
1562 /// <param name="description"></param>
1563 protected internal void PrimDescription(IClientAPI remoteClient, uint primLocalID, string description)
1564 {
1565 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1566 if (group != null)
1567 {
1568 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1569 {
1570 group.SetPartDescription(Util.CleanString(description), primLocalID);
1571 group.HasGroupChanged = true;
1572 }
1573 }
1574 }
1575
1576 /// <summary>
1577 /// Set a click action for the prim.
1578 /// </summary>
1579 /// <param name="remoteClient"></param>
1580 /// <param name="primLocalID"></param>
1581 /// <param name="clickAction"></param>
1582 protected internal void PrimClickAction(IClientAPI remoteClient, uint primLocalID, string clickAction)
1583 {
1584// m_log.DebugFormat(
1585// "[SCENEGRAPH]: User {0} set click action for {1} to {2}", remoteClient.Name, primLocalID, clickAction);
1586
1587 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1588 if (group != null)
1589 {
1590 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1591 {
1592 SceneObjectPart part = m_parentScene.GetSceneObjectPart(primLocalID);
1593 if (part != null)
1594 {
1595 part.ClickAction = Convert.ToByte(clickAction);
1596 group.HasGroupChanged = true;
1597 }
1598 }
1599 }
1600 }
1601
1602 protected internal void PrimMaterial(IClientAPI remoteClient, uint primLocalID, string material)
1603 {
1604 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1605 if (group != null)
1606 {
1607 if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
1608 {
1609 SceneObjectPart part = m_parentScene.GetSceneObjectPart(primLocalID);
1610 if (part != null)
1611 {
1612 part.Material = Convert.ToByte(material);
1613 group.HasGroupChanged = true;
1614 }
1615 }
1616 }
1617 }
1618
1619 protected internal void UpdateExtraParam(UUID agentID, uint primLocalID, ushort type, bool inUse, byte[] data)
1620 {
1621 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1622
1623 if (group != null)
1624 {
1625 if (m_parentScene.Permissions.CanEditObject(group.UUID, agentID))
1626 {
1627 group.UpdateExtraParam(primLocalID, type, inUse, data);
1628 }
1629 }
1630 }
1631
1632 /// <summary>
1633 ///
1634 /// </summary>
1635 /// <param name="primLocalID"></param>
1636 /// <param name="shapeBlock"></param>
1637 protected internal void UpdatePrimShape(UUID agentID, uint primLocalID, UpdateShapeArgs shapeBlock)
1638 {
1639 SceneObjectGroup group = GetGroupByPrim(primLocalID);
1640 if (group != null)
1641 {
1642 if (m_parentScene.Permissions.CanEditObject(group.UUID, agentID))
1643 {
1644 ObjectShapePacket.ObjectDataBlock shapeData = new ObjectShapePacket.ObjectDataBlock();
1645 shapeData.ObjectLocalID = shapeBlock.ObjectLocalID;
1646 shapeData.PathBegin = shapeBlock.PathBegin;
1647 shapeData.PathCurve = shapeBlock.PathCurve;
1648 shapeData.PathEnd = shapeBlock.PathEnd;
1649 shapeData.PathRadiusOffset = shapeBlock.PathRadiusOffset;
1650 shapeData.PathRevolutions = shapeBlock.PathRevolutions;
1651 shapeData.PathScaleX = shapeBlock.PathScaleX;
1652 shapeData.PathScaleY = shapeBlock.PathScaleY;
1653 shapeData.PathShearX = shapeBlock.PathShearX;
1654 shapeData.PathShearY = shapeBlock.PathShearY;
1655 shapeData.PathSkew = shapeBlock.PathSkew;
1656 shapeData.PathTaperX = shapeBlock.PathTaperX;
1657 shapeData.PathTaperY = shapeBlock.PathTaperY;
1658 shapeData.PathTwist = shapeBlock.PathTwist;
1659 shapeData.PathTwistBegin = shapeBlock.PathTwistBegin;
1660 shapeData.ProfileBegin = shapeBlock.ProfileBegin;
1661 shapeData.ProfileCurve = shapeBlock.ProfileCurve;
1662 shapeData.ProfileEnd = shapeBlock.ProfileEnd;
1663 shapeData.ProfileHollow = shapeBlock.ProfileHollow;
1664
1665 group.UpdateShape(shapeData, primLocalID);
1666 }
1667 }
1668 }
1669
1670 /// <summary>
1671 /// Initial method invoked when we receive a link objects request from the client.
1672 /// </summary>
1673 /// <param name="client"></param>
1674 /// <param name="parentPrim"></param>
1675 /// <param name="childPrims"></param>
1676 protected internal void LinkObjects(SceneObjectPart root, List<SceneObjectPart> children)
1677 {
1678 if (root.KeyframeMotion != null)
1679 {
1680 root.KeyframeMotion.Stop();
1681 root.KeyframeMotion = null;
1682 }
1683
1684 SceneObjectGroup parentGroup = root.ParentGroup;
1685 if (parentGroup == null) return;
1686
1687 // Cowardly refuse to link to a group owned root
1688 if (parentGroup.OwnerID == parentGroup.GroupID)
1689 return;
1690
1691 Monitor.Enter(m_updateLock);
1692 try
1693 {
1694 List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
1695
1696 // We do this in reverse to get the link order of the prims correct
1697 for (int i = 0 ; i < children.Count ; i++)
1698 {
1699 SceneObjectGroup child = children[i].ParentGroup;
1700
1701 // Don't try and add a group to itself - this will only cause severe problems later on.
1702 if (child == parentGroup)
1703 continue;
1704
1705 // Make sure no child prim is set for sale
1706 // So that, on delink, no prims are unwittingly
1707 // left for sale and sold off
1708 child.RootPart.ObjectSaleType = 0;
1709 child.RootPart.SalePrice = 10;
1710 childGroups.Add(child);
1711 }
1712
1713 foreach (SceneObjectGroup child in childGroups)
1714 {
1715 if (parentGroup.OwnerID == child.OwnerID)
1716 {
1717 parentGroup.LinkToGroup(child);
1718
1719 child.DetachFromBackup();
1720
1721 // this is here so physics gets updated!
1722 // Don't remove! Bad juju! Stay away! or fix physics!
1723 child.AbsolutePosition = child.AbsolutePosition;
1724 }
1725 }
1726
1727 // We need to explicitly resend the newly link prim's object properties since no other actions
1728 // occur on link to invoke this elsewhere (such as object selection)
1729 if (childGroups.Count > 0)
1730 {
1731 parentGroup.RootPart.CreateSelected = true;
1732 parentGroup.TriggerScriptChangedEvent(Changed.LINK);
1733 parentGroup.HasGroupChanged = true;
1734 parentGroup.ScheduleGroupForFullUpdate();
1735 }
1736 }
1737 finally
1738 {
1739 Monitor.Exit(m_updateLock);
1740 }
1741 }
1742
1743 /// <summary>
1744 /// Delink a linkset
1745 /// </summary>
1746 /// <param name="prims"></param>
1747 protected internal void DelinkObjects(List<SceneObjectPart> prims)
1748 {
1749 Monitor.Enter(m_updateLock);
1750 try
1751 {
1752 List<SceneObjectPart> childParts = new List<SceneObjectPart>();
1753 List<SceneObjectPart> rootParts = new List<SceneObjectPart>();
1754 List<SceneObjectGroup> affectedGroups = new List<SceneObjectGroup>();
1755 // Look them all up in one go, since that is comparatively expensive
1756 //
1757 foreach (SceneObjectPart part in prims)
1758 {
1759 if (part != null)
1760 {
1761 if (part.KeyframeMotion != null)
1762 {
1763 part.KeyframeMotion.Stop();
1764 part.KeyframeMotion = null;
1765 }
1766 if (part.ParentGroup.PrimCount != 1) // Skip single
1767 {
1768 if (part.LinkNum < 2) // Root
1769 {
1770 rootParts.Add(part);
1771 }
1772 else
1773 {
1774 part.LastOwnerID = part.ParentGroup.RootPart.LastOwnerID;
1775 childParts.Add(part);
1776 }
1777
1778 SceneObjectGroup group = part.ParentGroup;
1779 if (!affectedGroups.Contains(group))
1780 affectedGroups.Add(group);
1781 }
1782 }
1783 }
1784
1785 foreach (SceneObjectPart child in childParts)
1786 {
1787 // Unlink all child parts from their groups
1788 //
1789 child.ParentGroup.DelinkFromGroup(child, true);
1790
1791 // These are not in affected groups and will not be
1792 // handled further. Do the honors here.
1793 child.ParentGroup.HasGroupChanged = true;
1794 child.ParentGroup.ScheduleGroupForFullUpdate();
1795 }
1796
1797 foreach (SceneObjectPart root in rootParts)
1798 {
1799 // In most cases, this will run only one time, and the prim
1800 // will be a solo prim
1801 // However, editing linked parts and unlinking may be different
1802 //
1803 SceneObjectGroup group = root.ParentGroup;
1804
1805 List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Parts);
1806 int numChildren = newSet.Count;
1807
1808 // If there are prims left in a link set, but the root is
1809 // slated for unlink, we need to do this
1810 //
1811 if (numChildren != 1)
1812 {
1813 // Unlink the remaining set
1814 //
1815 bool sendEventsToRemainder = true;
1816 if (numChildren > 1)
1817 sendEventsToRemainder = false;
1818
1819 foreach (SceneObjectPart p in newSet)
1820 {
1821 if (p != group.RootPart)
1822 group.DelinkFromGroup(p, sendEventsToRemainder);
1823 }
1824
1825 // If there is more than one prim remaining, we
1826 // need to re-link
1827 //
1828 if (numChildren > 2)
1829 {
1830 // Remove old root
1831 //
1832 if (newSet.Contains(root))
1833 newSet.Remove(root);
1834
1835 // Preserve link ordering
1836 //
1837 newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
1838 {
1839 return a.LinkNum.CompareTo(b.LinkNum);
1840 });
1841
1842 // Determine new root
1843 //
1844 SceneObjectPart newRoot = newSet[0];
1845 newSet.RemoveAt(0);
1846
1847 foreach (SceneObjectPart newChild in newSet)
1848 newChild.ClearUpdateSchedule();
1849
1850 LinkObjects(newRoot, newSet);
1851 if (!affectedGroups.Contains(newRoot.ParentGroup))
1852 affectedGroups.Add(newRoot.ParentGroup);
1853 }
1854 }
1855 }
1856
1857 // Finally, trigger events in the roots
1858 //
1859 foreach (SceneObjectGroup g in affectedGroups)
1860 {
1861 g.TriggerScriptChangedEvent(Changed.LINK);
1862 g.HasGroupChanged = true; // Persist
1863 g.ScheduleGroupForFullUpdate();
1864 }
1865 }
1866 finally
1867 {
1868 Monitor.Exit(m_updateLock);
1869 }
1870 }
1871
1872 protected internal void MakeObjectSearchable(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
1873 {
1874 UUID user = remoteClient.AgentId;
1875 UUID objid = UUID.Zero;
1876 SceneObjectPart obj = null;
1877
1878 EntityBase[] entityList = GetEntities();
1879 foreach (EntityBase ent in entityList)
1880 {
1881 if (ent is SceneObjectGroup)
1882 {
1883 SceneObjectGroup sog = ent as SceneObjectGroup;
1884
1885 foreach (SceneObjectPart part in sog.Parts)
1886 {
1887 if (part.LocalId == localID)
1888 {
1889 objid = part.UUID;
1890 obj = part;
1891 }
1892 }
1893 }
1894 }
1895
1896 //Protip: In my day, we didn't call them searchable objects, we called them limited point-to-point joints
1897 //aka ObjectFlags.JointWheel = IncludeInSearch
1898
1899 //Permissions model: Object can be REMOVED from search IFF:
1900 // * User owns object
1901 //use CanEditObject
1902
1903 //Object can be ADDED to search IFF:
1904 // * User owns object
1905 // * Asset/DRM permission bit "modify" is enabled
1906 //use CanEditObjectPosition
1907
1908 // libomv will complain about PrimFlags.JointWheel being
1909 // deprecated, so we
1910 #pragma warning disable 0612
1911 if (IncludeInSearch && m_parentScene.Permissions.CanEditObject(objid, user))
1912 {
1913 obj.ParentGroup.RootPart.AddFlag(PrimFlags.JointWheel);
1914 obj.ParentGroup.HasGroupChanged = true;
1915 }
1916 else if (!IncludeInSearch && m_parentScene.Permissions.CanMoveObject(objid,user))
1917 {
1918 obj.ParentGroup.RootPart.RemFlag(PrimFlags.JointWheel);
1919 obj.ParentGroup.HasGroupChanged = true;
1920 }
1921 #pragma warning restore 0612
1922 }
1923
1924 /// <summary>
1925 /// Duplicate the given object.
1926 /// </summary>
1927 /// <param name="originalPrim"></param>
1928 /// <param name="offset"></param>
1929 /// <param name="flags"></param>
1930 /// <param name="AgentID"></param>
1931 /// <param name="GroupID"></param>
1932 /// <param name="rot"></param>
1933 /// <returns>null if duplication fails, otherwise the duplicated object</returns>
1934 public SceneObjectGroup DuplicateObject(
1935 uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
1936 {
1937 Monitor.Enter(m_updateLock);
1938
1939 try
1940 {
1941 // m_log.DebugFormat(
1942 // "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
1943 // originalPrimID, offset, AgentID);
1944
1945 SceneObjectGroup original = GetGroupByPrim(originalPrimID);
1946 if (original == null)
1947 {
1948 m_log.WarnFormat(
1949 "[SCENEGRAPH]: Attempt to duplicate nonexistent prim id {0} by {1}", originalPrimID, AgentID);
1950
1951 return null;
1952 }
1953
1954 if (!m_parentScene.Permissions.CanDuplicateObject(
1955 original.PrimCount, original.UUID, AgentID, original.AbsolutePosition))
1956 return null;
1957
1958 SceneObjectGroup copy = original.Copy(true);
1959 copy.AbsolutePosition = copy.AbsolutePosition + offset;
1960
1961 if (original.OwnerID != AgentID)
1962 {
1963 copy.SetOwnerId(AgentID);
1964 copy.SetRootPartOwner(copy.RootPart, AgentID, GroupID);
1965
1966 SceneObjectPart[] partList = copy.Parts;
1967
1968 if (m_parentScene.Permissions.PropagatePermissions())
1969 {
1970 foreach (SceneObjectPart child in partList)
1971 {
1972 child.Inventory.ChangeInventoryOwner(AgentID);
1973 child.TriggerScriptChangedEvent(Changed.OWNER);
1974 child.ApplyNextOwnerPermissions();
1975 }
1976 }
1977
1978 copy.RootPart.ObjectSaleType = 0;
1979 copy.RootPart.SalePrice = 10;
1980 }
1981
1982 // FIXME: This section needs to be refactored so that it just calls AddSceneObject()
1983 Entities.Add(copy);
1984
1985 lock (SceneObjectGroupsByFullID)
1986 SceneObjectGroupsByFullID[copy.UUID] = copy;
1987
1988 SceneObjectPart[] children = copy.Parts;
1989
1990 lock (SceneObjectGroupsByFullPartID)
1991 {
1992 SceneObjectGroupsByFullPartID[copy.UUID] = copy;
1993 foreach (SceneObjectPart part in children)
1994 SceneObjectGroupsByFullPartID[part.UUID] = copy;
1995 }
1996
1997 lock (SceneObjectGroupsByLocalPartID)
1998 {
1999 SceneObjectGroupsByLocalPartID[copy.LocalId] = copy;
2000 foreach (SceneObjectPart part in children)
2001 SceneObjectGroupsByLocalPartID[part.LocalId] = copy;
2002 }
2003 // PROBABLE END OF FIXME
2004
2005 // Since we copy from a source group that is in selected
2006 // state, but the copy is shown deselected in the viewer,
2007 // We need to clear the selection flag here, else that
2008 // prim never gets persisted at all. The client doesn't
2009 // think it's selected, so it will never send a deselect...
2010 copy.IsSelected = false;
2011
2012 m_numTotalPrim += copy.Parts.Length;
2013
2014 // Go through all parts (primitives and meshes) of this Scene Object
2015 foreach (SceneObjectPart part in copy.Parts)
2016 {
2017 // Keep track of the total number of meshes or geometric primitives now in the scene;
2018 // determine which object this is based on its primitive type: sculpted (sculpt) prim refers to
2019 // a mesh and all other prims (i.e. box, sphere, etc) are geometric primitives
2020 if (part.GetPrimType() == PrimType.SCULPT)
2021 m_numMesh++;
2022 else
2023 m_numPrim++;
2024 }
2025
2026 if (rot != Quaternion.Identity)
2027 {
2028 copy.UpdateGroupRotationR(rot);
2029 }
2030
2031 copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 1);
2032 copy.HasGroupChanged = true;
2033 copy.ScheduleGroupForFullUpdate();
2034 copy.ResumeScripts();
2035
2036 // required for physics to update it's position
2037 copy.AbsolutePosition = copy.AbsolutePosition;
2038
2039 return copy;
2040 }
2041 finally
2042 {
2043 Monitor.Exit(m_updateLock);
2044 }
2045 }
2046
2047 /// <summary>
2048 /// Calculates the distance between two Vector3s
2049 /// </summary>
2050 /// <param name="v1"></param>
2051 /// <param name="v2"></param>
2052 /// <returns></returns>
2053 protected internal float Vector3Distance(Vector3 v1, Vector3 v2)
2054 {
2055 // We don't really need the double floating point precision...
2056 // so casting it to a single
2057
2058 return
2059 (float)
2060 Math.Sqrt((v1.X - v2.X) * (v1.X - v2.X) + (v1.Y - v2.Y) * (v1.Y - v2.Y) + (v1.Z - v2.Z) * (v1.Z - v2.Z));
2061 }
2062
2063 #endregion
2064
2065
2066 }
2067}