SceneGraph.cs 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  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. using System;
  28. using System.Threading;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using OpenMetaverse.Packets;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Scenes.Types;
  36. using OpenSim.Region.Physics.Manager;
  37. namespace OpenSim.Region.Framework.Scenes
  38. {
  39. public delegate void PhysicsCrash();
  40. public delegate void ObjectDuplicateDelegate(EntityBase original, EntityBase clone);
  41. public delegate void ObjectCreateDelegate(EntityBase obj);
  42. public delegate void ObjectDeleteDelegate(EntityBase obj);
  43. /// <summary>
  44. /// This class used to be called InnerScene and may not yet truly be a SceneGraph. The non scene graph components
  45. /// should be migrated out over time.
  46. /// </summary>
  47. public class SceneGraph
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. #region Events
  51. protected internal event PhysicsCrash UnRecoverableError;
  52. private PhysicsCrash handlerPhysicsCrash = null;
  53. public event ObjectDuplicateDelegate OnObjectDuplicate;
  54. public event ObjectCreateDelegate OnObjectCreate;
  55. public event ObjectDeleteDelegate OnObjectRemove;
  56. #endregion
  57. #region Fields
  58. protected Dictionary<UUID, ScenePresence> m_scenePresences = new Dictionary<UUID, ScenePresence>();
  59. protected ScenePresence[] m_scenePresenceArray = new ScenePresence[0];
  60. // SceneObjects is not currently populated or used.
  61. //public Dictionary<UUID, SceneObjectGroup> SceneObjects;
  62. protected internal EntityManager Entities = new EntityManager();
  63. // protected internal Dictionary<UUID, EntityBase> Entities = new Dictionary<UUID, EntityBase>();
  64. protected internal Dictionary<UUID, ScenePresence> RestorePresences = new Dictionary<UUID, ScenePresence>();
  65. protected internal BasicQuadTreeNode QuadTree;
  66. protected RegionInfo m_regInfo;
  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_numPrim = 0;
  71. protected int m_numChildAgents = 0;
  72. protected int m_physicalPrim = 0;
  73. protected int m_activeScripts = 0;
  74. protected int m_scriptLPS = 0;
  75. protected internal object m_syncRoot = new object();
  76. protected internal PhysicsScene _PhyScene;
  77. protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalID = new Dictionary<uint, SceneObjectGroup>();
  78. protected internal Dictionary<UUID, SceneObjectGroup> SceneObjectGroupsByFullID = new Dictionary<UUID, SceneObjectGroup>();
  79. private readonly Object m_dictionary_lock = new Object();
  80. private Object m_updateLock = new Object();
  81. #endregion
  82. protected internal SceneGraph(Scene parent, RegionInfo regInfo)
  83. {
  84. m_parentScene = parent;
  85. m_regInfo = regInfo;
  86. QuadTree = new BasicQuadTreeNode(null, "/0/", 0, 0, (short)Constants.RegionSize, (short)Constants.RegionSize);
  87. QuadTree.Subdivide();
  88. QuadTree.Subdivide();
  89. }
  90. public PhysicsScene PhysicsScene
  91. {
  92. get { return _PhyScene; }
  93. set
  94. {
  95. // If we're not doing the initial set
  96. // Then we've got to remove the previous
  97. // event handler
  98. if (_PhyScene != null)
  99. _PhyScene.OnPhysicsCrash -= physicsBasedCrash;
  100. _PhyScene = value;
  101. if (_PhyScene != null)
  102. _PhyScene.OnPhysicsCrash += physicsBasedCrash;
  103. }
  104. }
  105. protected internal void Close()
  106. {
  107. lock (m_scenePresences)
  108. {
  109. m_scenePresences.Clear();
  110. m_scenePresenceArray = new ScenePresence[0];
  111. }
  112. lock (m_dictionary_lock)
  113. {
  114. SceneObjectGroupsByFullID.Clear();
  115. SceneObjectGroupsByLocalID.Clear();
  116. }
  117. Entities.Clear();
  118. }
  119. #region Update Methods
  120. protected internal void UpdatePreparePhysics()
  121. {
  122. // If we are using a threaded physics engine
  123. // grab the latest scene from the engine before
  124. // trying to process it.
  125. // PhysX does this (runs in the background).
  126. if (_PhyScene.IsThreaded)
  127. {
  128. _PhyScene.GetResults();
  129. }
  130. }
  131. protected internal void UpdatePresences()
  132. {
  133. ScenePresence[] updateScenePresences = GetScenePresences();
  134. for (int i = 0; i < updateScenePresences.Length; i++)
  135. updateScenePresences[i].Update();
  136. }
  137. protected internal float UpdatePhysics(double elapsed)
  138. {
  139. lock (m_syncRoot)
  140. {
  141. // Here is where the Scene calls the PhysicsScene. This is a one-way
  142. // interaction; the PhysicsScene cannot access the calling Scene directly.
  143. // But with joints, we want a PhysicsActor to be able to influence a
  144. // non-physics SceneObjectPart. In particular, a PhysicsActor that is connected
  145. // with a joint should be able to move the SceneObjectPart which is the visual
  146. // representation of that joint (for editing and serialization purposes).
  147. // However the PhysicsActor normally cannot directly influence anything outside
  148. // of the PhysicsScene, and the non-physical SceneObjectPart which represents
  149. // the joint in the Scene does not exist in the PhysicsScene.
  150. //
  151. // To solve this, we have an event in the PhysicsScene that is fired when a joint
  152. // has changed position (because one of its associated PhysicsActors has changed
  153. // position).
  154. //
  155. // Therefore, JointMoved and JointDeactivated events will be fired as a result of the following Simulate().
  156. return _PhyScene.Simulate((float)elapsed);
  157. }
  158. }
  159. protected internal void UpdateScenePresenceMovement()
  160. {
  161. ScenePresence[] moveEntities = GetScenePresences();
  162. for (int i = 0; i < moveEntities.Length; i++)
  163. moveEntities[i].UpdateMovement();
  164. }
  165. #endregion
  166. #region Entity Methods
  167. /// <summary>
  168. /// Add an object into the scene that has come from storage
  169. /// </summary>
  170. /// <param name="sceneObject"></param>
  171. /// <param name="attachToBackup">
  172. /// If true, changes to the object will be reflected in its persisted data
  173. /// If false, the persisted data will not be changed even if the object in the scene is changed
  174. /// </param>
  175. /// <param name="alreadyPersisted">
  176. /// If true, we won't persist this object until it changes
  177. /// If false, we'll persist this object immediately
  178. /// </param>
  179. /// <returns>
  180. /// true if the object was added, false if an object with the same uuid was already in the scene
  181. /// </returns>
  182. protected internal bool AddRestoredSceneObject(
  183. SceneObjectGroup sceneObject, bool attachToBackup, bool alreadyPersisted)
  184. {
  185. if (!alreadyPersisted)
  186. {
  187. sceneObject.ForceInventoryPersistence();
  188. sceneObject.HasGroupChanged = true;
  189. }
  190. return AddSceneObject(sceneObject, attachToBackup);
  191. }
  192. /// <summary>
  193. /// Add a newly created object to the scene. This will both update the scene, and send information about the
  194. /// new object to all clients interested in the scene.
  195. /// </summary>
  196. /// <param name="sceneObject"></param>
  197. /// <param name="attachToBackup">
  198. /// If true, the object is made persistent into the scene.
  199. /// If false, the object will not persist over server restarts
  200. /// </param>
  201. /// <returns>
  202. /// true if the object was added, false if an object with the same uuid was already in the scene
  203. /// </returns>
  204. protected internal bool AddNewSceneObject(SceneObjectGroup sceneObject, bool attachToBackup)
  205. {
  206. // Ensure that we persist this new scene object
  207. sceneObject.HasGroupChanged = true;
  208. return AddSceneObject(sceneObject, attachToBackup);
  209. }
  210. /// <summary>
  211. /// Add an object to the scene. This will both update the scene, and send information about the
  212. /// new object to all clients interested in the scene.
  213. /// </summary>
  214. /// <param name="sceneObject"></param>
  215. /// <param name="attachToBackup">
  216. /// If true, the object is made persistent into the scene.
  217. /// If false, the object will not persist over server restarts
  218. /// </param>
  219. /// <returns>true if the object was added, false if an object with the same uuid was already in the scene
  220. /// </returns>
  221. protected bool AddSceneObject(SceneObjectGroup sceneObject, bool attachToBackup)
  222. {
  223. if (sceneObject == null || sceneObject.RootPart == null || sceneObject.RootPart.UUID == UUID.Zero)
  224. return false;
  225. if (m_parentScene.m_clampPrimSize)
  226. {
  227. foreach (SceneObjectPart part in sceneObject.Children.Values)
  228. {
  229. Vector3 scale = part.Shape.Scale;
  230. if (scale.X > m_parentScene.m_maxNonphys)
  231. scale.X = m_parentScene.m_maxNonphys;
  232. if (scale.Y > m_parentScene.m_maxNonphys)
  233. scale.Y = m_parentScene.m_maxNonphys;
  234. if (scale.Z > m_parentScene.m_maxNonphys)
  235. scale.Z = m_parentScene.m_maxNonphys;
  236. part.Shape.Scale = scale;
  237. }
  238. }
  239. sceneObject.AttachToScene(m_parentScene);
  240. lock (sceneObject)
  241. {
  242. if (!Entities.ContainsKey(sceneObject.UUID))
  243. {
  244. Entities.Add(sceneObject);
  245. m_numPrim += sceneObject.Children.Count;
  246. if (attachToBackup)
  247. sceneObject.AttachToBackup();
  248. if (OnObjectCreate != null)
  249. OnObjectCreate(sceneObject);
  250. lock (m_dictionary_lock)
  251. {
  252. SceneObjectGroupsByFullID[sceneObject.UUID] = sceneObject;
  253. SceneObjectGroupsByLocalID[sceneObject.LocalId] = sceneObject;
  254. foreach (SceneObjectPart part in sceneObject.Children.Values)
  255. {
  256. SceneObjectGroupsByFullID[part.UUID] = sceneObject;
  257. SceneObjectGroupsByLocalID[part.LocalId] = sceneObject;
  258. }
  259. }
  260. return true;
  261. }
  262. }
  263. return false;
  264. }
  265. /// <summary>
  266. /// Delete an object from the scene
  267. /// </summary>
  268. /// <returns>true if the object was deleted, false if there was no object to delete</returns>
  269. public bool DeleteSceneObject(UUID uuid, bool resultOfObjectLinked)
  270. {
  271. if (Entities.ContainsKey(uuid))
  272. {
  273. if (!resultOfObjectLinked)
  274. {
  275. m_numPrim -= ((SceneObjectGroup) Entities[uuid]).Children.Count;
  276. if ((((SceneObjectGroup)Entities[uuid]).RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics)
  277. {
  278. RemovePhysicalPrim(((SceneObjectGroup)Entities[uuid]).Children.Count);
  279. }
  280. }
  281. if (OnObjectRemove != null)
  282. OnObjectRemove(Entities[uuid]);
  283. lock (m_dictionary_lock)
  284. {
  285. SceneObjectGroupsByFullID.Remove(uuid);
  286. SceneObjectGroupsByLocalID.Remove(((SceneObjectGroup)Entities[uuid]).LocalId);
  287. }
  288. Entities.Remove(uuid);
  289. //SceneObjectGroup part;
  290. //((part.RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics)
  291. return true;
  292. }
  293. return false;
  294. }
  295. /// <summary>
  296. /// Add an object to the list of prims to process on the next update
  297. /// </summary>
  298. /// <param name="obj">
  299. /// A <see cref="SceneObjectGroup"/>
  300. /// </param>
  301. protected internal void AddToUpdateList(SceneObjectGroup obj)
  302. {
  303. lock (m_updateList)
  304. {
  305. m_updateList[obj.UUID] = obj;
  306. }
  307. }
  308. /// <summary>
  309. /// Process all pending updates
  310. /// </summary>
  311. protected internal void UpdateObjectGroups()
  312. {
  313. if (!Monitor.TryEnter(m_updateLock))
  314. return;
  315. List<SceneObjectGroup> updates;
  316. // Some updates add more updates to the updateList.
  317. // Get the current list of updates and clear the list before iterating
  318. lock (m_updateList)
  319. {
  320. updates = new List<SceneObjectGroup>(m_updateList.Values);
  321. m_updateList.Clear();
  322. }
  323. // Go through all updates
  324. for (int i = 0; i < updates.Count; i++)
  325. {
  326. SceneObjectGroup sog = updates[i];
  327. // Don't abort the whole update if one entity happens to give us an exception.
  328. try
  329. {
  330. sog.Update();
  331. }
  332. catch (Exception e)
  333. {
  334. m_log.ErrorFormat(
  335. "[INNER SCENE]: Failed to update {0}, {1} - {2}", sog.Name, sog.UUID, e);
  336. }
  337. }
  338. Monitor.Exit(m_updateLock);
  339. }
  340. protected internal void AddPhysicalPrim(int number)
  341. {
  342. m_physicalPrim++;
  343. }
  344. protected internal void RemovePhysicalPrim(int number)
  345. {
  346. m_physicalPrim--;
  347. }
  348. protected internal void AddToScriptLPS(int number)
  349. {
  350. m_scriptLPS += number;
  351. }
  352. protected internal void AddActiveScripts(int number)
  353. {
  354. m_activeScripts += number;
  355. }
  356. public void DropObject(uint objectLocalID, IClientAPI remoteClient)
  357. {
  358. SceneObjectGroup group = GetGroupByPrim(objectLocalID);
  359. if (group != null)
  360. {
  361. m_parentScene.DetachSingleAttachmentToGround(group.UUID, remoteClient);
  362. }
  363. }
  364. protected internal void DetachObject(uint objectLocalID, IClientAPI remoteClient)
  365. {
  366. SceneObjectGroup group = GetGroupByPrim(objectLocalID);
  367. if (group != null)
  368. {
  369. //group.DetachToGround();
  370. m_parentScene.DetachSingleAttachmentToInv(group.GetFromItemID(), remoteClient);
  371. }
  372. }
  373. protected internal void HandleUndo(IClientAPI remoteClient, UUID primId)
  374. {
  375. if (primId != UUID.Zero)
  376. {
  377. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primId);
  378. if (part != null)
  379. part.Undo();
  380. }
  381. }
  382. protected internal void HandleObjectGroupUpdate(
  383. IClientAPI remoteClient, UUID GroupID, uint objectLocalID, UUID Garbage)
  384. {
  385. SceneObjectGroup group = GetGroupByPrim(objectLocalID);
  386. if (group != null)
  387. {
  388. if (group.OwnerID == remoteClient.AgentId)
  389. group.SetGroup(GroupID, remoteClient);
  390. }
  391. }
  392. /// <summary>
  393. /// Event Handling routine for Attach Object
  394. /// </summary>
  395. /// <param name="remoteClient"></param>
  396. /// <param name="objectLocalID"></param>
  397. /// <param name="AttachmentPt"></param>
  398. /// <param name="rot"></param>
  399. protected internal void AttachObject(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, bool silent)
  400. {
  401. // If we can't take it, we can't attach it!
  402. SceneObjectPart part = m_parentScene.GetSceneObjectPart(objectLocalID);
  403. if (part == null)
  404. return;
  405. if (!m_parentScene.Permissions.CanTakeObject(
  406. part.UUID, remoteClient.AgentId))
  407. return;
  408. // Calls attach with a Zero position
  409. AttachObject(remoteClient, objectLocalID, AttachmentPt, rot, Vector3.Zero, false);
  410. m_parentScene.SendAttachEvent(objectLocalID, part.ParentGroup.GetFromItemID(), remoteClient.AgentId);
  411. // Save avatar attachment information
  412. ScenePresence presence;
  413. if (m_parentScene.AvatarFactory != null && m_parentScene.TryGetAvatar(remoteClient.AgentId, out presence))
  414. {
  415. m_log.Info("[SCENE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", AttachmentPoint: " + AttachmentPt);
  416. m_parentScene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
  417. }
  418. }
  419. public SceneObjectGroup RezSingleAttachment(
  420. IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
  421. {
  422. SceneObjectGroup objatt = m_parentScene.RezObject(remoteClient,
  423. itemID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
  424. false, false, remoteClient.AgentId, true);
  425. if (objatt != null)
  426. {
  427. bool tainted = false;
  428. if (AttachmentPt != 0 && AttachmentPt != objatt.GetAttachmentPoint())
  429. tainted = true;
  430. AttachObject(remoteClient, objatt.LocalId, AttachmentPt, Quaternion.Identity, objatt.AbsolutePosition, false);
  431. objatt.ScheduleGroupForFullUpdate();
  432. if (tainted)
  433. objatt.HasGroupChanged = true;
  434. // Fire after attach, so we don't get messy perms dialogs
  435. // 3 == AttachedRez
  436. objatt.CreateScriptInstances(0, true, m_parentScene.DefaultScriptEngine, 3);
  437. }
  438. return objatt;
  439. }
  440. // What makes this method odd and unique is it tries to detach using an UUID.... Yay for standards.
  441. // To LocalId or UUID, *THAT* is the question. How now Brown UUID??
  442. public void DetachSingleAttachmentToInv(UUID itemID, IClientAPI remoteClient)
  443. {
  444. if (itemID == UUID.Zero) // If this happened, someone made a mistake....
  445. return;
  446. // We can NOT use the dictionries here, as we are looking
  447. // for an entity by the fromAssetID, which is NOT the prim UUID
  448. //
  449. List<EntityBase> detachEntities = GetEntities();
  450. SceneObjectGroup group;
  451. foreach (EntityBase entity in detachEntities)
  452. {
  453. if (entity is SceneObjectGroup)
  454. {
  455. group = (SceneObjectGroup)entity;
  456. if (group.GetFromItemID() == itemID)
  457. {
  458. m_parentScene.SendAttachEvent(group.LocalId, itemID, UUID.Zero);
  459. group.DetachToInventoryPrep();
  460. m_log.Debug("[DETACH]: Saving attachpoint: " +
  461. ((uint)group.GetAttachmentPoint()).ToString());
  462. m_parentScene.UpdateKnownItem(remoteClient, group,
  463. group.GetFromItemID(), group.OwnerID);
  464. m_parentScene.DeleteSceneObject(group, false);
  465. return;
  466. }
  467. }
  468. }
  469. }
  470. protected internal void AttachObject(
  471. IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent)
  472. {
  473. SceneObjectGroup group = GetGroupByPrim(objectLocalID);
  474. if (group != null)
  475. {
  476. if (m_parentScene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId))
  477. {
  478. // If the attachment point isn't the same as the one previously used
  479. // set it's offset position = 0 so that it appears on the attachment point
  480. // and not in a weird location somewhere unknown.
  481. if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
  482. {
  483. attachPos = Vector3.Zero;
  484. }
  485. // AttachmentPt 0 means the client chose to 'wear' the attachment.
  486. if (AttachmentPt == 0)
  487. {
  488. // Check object for stored attachment point
  489. AttachmentPt = (uint)group.GetAttachmentPoint();
  490. }
  491. // if we still didn't find a suitable attachment point.......
  492. if (AttachmentPt == 0)
  493. {
  494. // Stick it on left hand with Zero Offset from the attachment point.
  495. AttachmentPt = (uint)AttachmentPoint.LeftHand;
  496. attachPos = Vector3.Zero;
  497. }
  498. group.SetAttachmentPoint((byte)AttachmentPt);
  499. group.AbsolutePosition = attachPos;
  500. // Saves and gets itemID
  501. UUID itemId;
  502. if (group.GetFromItemID() == UUID.Zero)
  503. {
  504. m_parentScene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId);
  505. }
  506. else
  507. {
  508. itemId = group.GetFromItemID();
  509. }
  510. m_parentScene.AttachObject(remoteClient, AttachmentPt, itemId, group);
  511. group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos, silent);
  512. // In case it is later dropped again, don't let
  513. // it get cleaned up
  514. //
  515. group.RootPart.RemFlag(PrimFlags.TemporaryOnRez);
  516. group.HasGroupChanged = false;
  517. }
  518. else
  519. {
  520. remoteClient.SendAgentAlertMessage("You don't have sufficient permissions to attach this object", false);
  521. }
  522. }
  523. else
  524. m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID);
  525. }
  526. protected internal ScenePresence CreateAndAddChildScenePresence(IClientAPI client, AvatarAppearance appearance)
  527. {
  528. ScenePresence newAvatar = null;
  529. newAvatar = new ScenePresence(client, m_parentScene, m_regInfo, appearance);
  530. newAvatar.IsChildAgent = true;
  531. AddScenePresence(newAvatar);
  532. return newAvatar;
  533. }
  534. /// <summary>
  535. /// Add a presence to the scene
  536. /// </summary>
  537. /// <param name="presence"></param>
  538. protected internal void AddScenePresence(ScenePresence presence)
  539. {
  540. bool child = presence.IsChildAgent;
  541. if (child)
  542. {
  543. m_numChildAgents++;
  544. }
  545. else
  546. {
  547. m_numRootAgents++;
  548. presence.AddToPhysicalScene(false);
  549. }
  550. Entities[presence.UUID] = presence;
  551. lock (m_scenePresences)
  552. {
  553. if (!m_scenePresences.ContainsKey(presence.UUID))
  554. {
  555. m_scenePresences.Add(presence.UUID, presence);
  556. // Create a new array of ScenePresence references
  557. int oldLength = m_scenePresenceArray.Length;
  558. ScenePresence[] newArray = new ScenePresence[oldLength + 1];
  559. Array.Copy(m_scenePresenceArray, newArray, oldLength);
  560. newArray[oldLength] = presence;
  561. m_scenePresenceArray = newArray;
  562. }
  563. else
  564. {
  565. m_scenePresences[presence.UUID] = presence;
  566. // Do a linear search through the array of ScenePresence references
  567. // and update the modified entry
  568. for (int i = 0; i < m_scenePresenceArray.Length; i++)
  569. {
  570. if (m_scenePresenceArray[i].UUID == presence.UUID)
  571. {
  572. m_scenePresenceArray[i] = presence;
  573. break;
  574. }
  575. }
  576. }
  577. }
  578. }
  579. /// <summary>
  580. /// Remove a presence from the scene
  581. /// </summary>
  582. protected internal void RemoveScenePresence(UUID agentID)
  583. {
  584. if (!Entities.Remove(agentID))
  585. {
  586. m_log.WarnFormat(
  587. "[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene Entities list",
  588. agentID);
  589. }
  590. lock (m_scenePresences)
  591. {
  592. if (m_scenePresences.Remove(agentID))
  593. {
  594. // Copy all of the elements from the previous array
  595. // into the new array except the removed element
  596. int oldLength = m_scenePresenceArray.Length;
  597. ScenePresence[] newArray = new ScenePresence[oldLength - 1];
  598. int j = 0;
  599. for (int i = 0; i < m_scenePresenceArray.Length; i++)
  600. {
  601. ScenePresence presence = m_scenePresenceArray[i];
  602. if (presence.UUID != agentID)
  603. {
  604. newArray[j] = presence;
  605. ++j;
  606. }
  607. }
  608. m_scenePresenceArray = newArray;
  609. }
  610. else
  611. {
  612. m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
  613. }
  614. }
  615. }
  616. protected internal void SwapRootChildAgent(bool direction_RC_CR_T_F)
  617. {
  618. if (direction_RC_CR_T_F)
  619. {
  620. m_numRootAgents--;
  621. m_numChildAgents++;
  622. }
  623. else
  624. {
  625. m_numChildAgents--;
  626. m_numRootAgents++;
  627. }
  628. }
  629. public void removeUserCount(bool TypeRCTF)
  630. {
  631. if (TypeRCTF)
  632. {
  633. m_numRootAgents--;
  634. }
  635. else
  636. {
  637. m_numChildAgents--;
  638. }
  639. }
  640. public void RecalculateStats()
  641. {
  642. ScenePresence[] presences = GetScenePresences();
  643. int rootcount = 0;
  644. int childcount = 0;
  645. for (int i = 0; i < presences.Length; i++)
  646. {
  647. ScenePresence user = presences[i];
  648. if (user.IsChildAgent)
  649. ++childcount;
  650. else
  651. ++rootcount;
  652. }
  653. m_numRootAgents = rootcount;
  654. m_numChildAgents = childcount;
  655. }
  656. public int GetChildAgentCount()
  657. {
  658. // some network situations come in where child agents get closed twice.
  659. if (m_numChildAgents < 0)
  660. {
  661. m_numChildAgents = 0;
  662. }
  663. return m_numChildAgents;
  664. }
  665. public int GetRootAgentCount()
  666. {
  667. return m_numRootAgents;
  668. }
  669. public int GetTotalObjectsCount()
  670. {
  671. return m_numPrim;
  672. }
  673. public int GetActiveObjectsCount()
  674. {
  675. return m_physicalPrim;
  676. }
  677. public int GetActiveScriptsCount()
  678. {
  679. return m_activeScripts;
  680. }
  681. public int GetScriptLPS()
  682. {
  683. int returnval = m_scriptLPS;
  684. m_scriptLPS = 0;
  685. return returnval;
  686. }
  687. #endregion
  688. #region Get Methods
  689. /// <summary>
  690. /// Request a List of all scene presences in this scene. This is a new list, so no
  691. /// locking is required to iterate over it.
  692. /// </summary>
  693. /// <returns></returns>
  694. protected internal ScenePresence[] GetScenePresences()
  695. {
  696. return m_scenePresenceArray;
  697. }
  698. protected internal List<ScenePresence> GetAvatars()
  699. {
  700. List<ScenePresence> result =
  701. GetScenePresences(delegate(ScenePresence scenePresence) { return !scenePresence.IsChildAgent; });
  702. return result;
  703. }
  704. /// <summary>
  705. /// Get the controlling client for the given avatar, if there is one.
  706. ///
  707. /// FIXME: The only user of the method right now is Caps.cs, in order to resolve a client API since it can't
  708. /// use the ScenePresence. This could be better solved in a number of ways - we could establish an
  709. /// OpenSim.Framework.IScenePresence, or move the caps code into a region package (which might be the more
  710. /// suitable solution).
  711. /// </summary>
  712. /// <param name="agentId"></param>
  713. /// <returns>null if either the avatar wasn't in the scene, or
  714. /// they do not have a controlling client</returns>
  715. /// <remarks>this used to be protected internal, but that
  716. /// prevents CapabilitiesModule from accessing it</remarks>
  717. public IClientAPI GetControllingClient(UUID agentId)
  718. {
  719. ScenePresence presence = GetScenePresence(agentId);
  720. if (presence != null)
  721. {
  722. return presence.ControllingClient;
  723. }
  724. return null;
  725. }
  726. /// <summary>
  727. /// Request a filtered list of m_scenePresences in this World
  728. /// </summary>
  729. /// <returns></returns>
  730. protected internal List<ScenePresence> GetScenePresences(FilterAvatarList filter)
  731. {
  732. // No locking of scene presences here since we're passing back a list...
  733. List<ScenePresence> result = new List<ScenePresence>();
  734. ScenePresence[] scenePresences = GetScenePresences();
  735. for (int i = 0; i < scenePresences.Length; i++)
  736. {
  737. ScenePresence avatar = scenePresences[i];
  738. if (filter(avatar))
  739. result.Add(avatar);
  740. }
  741. return result;
  742. }
  743. /// <summary>
  744. /// Request a scene presence by UUID
  745. /// </summary>
  746. /// <param name="avatarID"></param>
  747. /// <returns>null if the agent was not found</returns>
  748. protected internal ScenePresence GetScenePresence(UUID agentID)
  749. {
  750. ScenePresence sp;
  751. lock (m_scenePresences)
  752. {
  753. m_scenePresences.TryGetValue(agentID, out sp);
  754. }
  755. return sp;
  756. }
  757. /// <summary>
  758. /// Get a scene object group that contains the prim with the given local id
  759. /// </summary>
  760. /// <param name="localID"></param>
  761. /// <returns>null if no scene object group containing that prim is found</returns>
  762. public SceneObjectGroup GetGroupByPrim(uint localID)
  763. {
  764. if (Entities.ContainsKey(localID))
  765. return Entities[localID] as SceneObjectGroup;
  766. //m_log.DebugFormat("Entered GetGroupByPrim with localID {0}", localID);
  767. SceneObjectGroup sog;
  768. lock (SceneObjectGroupsByLocalID)
  769. {
  770. if (SceneObjectGroupsByLocalID.TryGetValue(localID, out sog))
  771. {
  772. return sog;
  773. }
  774. }
  775. List<EntityBase> EntityList = GetEntities();
  776. foreach (EntityBase ent in EntityList)
  777. {
  778. //m_log.DebugFormat("Looking at entity {0}", ent.UUID);
  779. if (ent is SceneObjectGroup)
  780. {
  781. if (((SceneObjectGroup)ent).HasChildPrim(localID))
  782. {
  783. sog = (SceneObjectGroup)ent;
  784. lock (SceneObjectGroupsByLocalID)
  785. {
  786. SceneObjectGroupsByLocalID[localID] = sog;
  787. }
  788. return sog;
  789. }
  790. }
  791. }
  792. return null;
  793. }
  794. /// <summary>
  795. /// Get a scene object group that contains the prim with the given uuid
  796. /// </summary>
  797. /// <param name="fullID"></param>
  798. /// <returns>null if no scene object group containing that prim is found</returns>
  799. private SceneObjectGroup GetGroupByPrim(UUID fullID)
  800. {
  801. SceneObjectGroup sog;
  802. lock (SceneObjectGroupsByFullID)
  803. {
  804. if (SceneObjectGroupsByFullID.TryGetValue(fullID, out sog))
  805. {
  806. return sog;
  807. }
  808. }
  809. List<EntityBase> EntityList = GetEntities();
  810. foreach (EntityBase ent in EntityList)
  811. {
  812. if (ent is SceneObjectGroup)
  813. {
  814. if (((SceneObjectGroup)ent).HasChildPrim(fullID))
  815. {
  816. sog = (SceneObjectGroup)ent;
  817. lock (SceneObjectGroupsByFullID)
  818. {
  819. SceneObjectGroupsByFullID[fullID] = sog;
  820. }
  821. return sog;
  822. }
  823. }
  824. }
  825. return null;
  826. }
  827. protected internal EntityIntersection GetClosestIntersectingPrim(Ray hray, bool frontFacesOnly, bool faceCenters)
  828. {
  829. // Primitive Ray Tracing
  830. float closestDistance = 280f;
  831. EntityIntersection result = new EntityIntersection();
  832. List<EntityBase> EntityList = GetEntities();
  833. foreach (EntityBase ent in EntityList)
  834. {
  835. if (ent is SceneObjectGroup)
  836. {
  837. SceneObjectGroup reportingG = (SceneObjectGroup)ent;
  838. EntityIntersection inter = reportingG.TestIntersection(hray, frontFacesOnly, faceCenters);
  839. if (inter.HitTF && inter.distance < closestDistance)
  840. {
  841. closestDistance = inter.distance;
  842. result = inter;
  843. }
  844. }
  845. }
  846. return result;
  847. }
  848. /// <summary>
  849. /// Get a part contained in this scene.
  850. /// </summary>
  851. /// <param name="localID"></param>
  852. /// <returns>null if the part was not found</returns>
  853. protected internal SceneObjectPart GetSceneObjectPart(uint localID)
  854. {
  855. SceneObjectGroup group = GetGroupByPrim(localID);
  856. if (group == null)
  857. return null;
  858. return group.GetChildPart(localID);
  859. }
  860. /// <summary>
  861. /// Get a named prim contained in this scene (will return the first
  862. /// found, if there are more than one prim with the same name)
  863. /// </summary>
  864. /// <param name="name"></param>
  865. /// <returns>null if the part was not found</returns>
  866. protected internal SceneObjectPart GetSceneObjectPart(string name)
  867. {
  868. List<EntityBase> EntityList = GetEntities();
  869. // FIXME: use a dictionary here
  870. foreach (EntityBase ent in EntityList)
  871. {
  872. if (ent is SceneObjectGroup)
  873. {
  874. foreach (SceneObjectPart p in ((SceneObjectGroup) ent).GetParts())
  875. {
  876. if (p.Name == name)
  877. {
  878. return p;
  879. }
  880. }
  881. }
  882. }
  883. return null;
  884. }
  885. /// <summary>
  886. /// Get a part contained in this scene.
  887. /// </summary>
  888. /// <param name="fullID"></param>
  889. /// <returns>null if the part was not found</returns>
  890. protected internal SceneObjectPart GetSceneObjectPart(UUID fullID)
  891. {
  892. SceneObjectGroup group = GetGroupByPrim(fullID);
  893. if (group == null)
  894. return null;
  895. return group.GetChildPart(fullID);
  896. }
  897. protected internal bool TryGetAvatar(UUID avatarId, out ScenePresence avatar)
  898. {
  899. lock (m_scenePresences)
  900. return m_scenePresences.TryGetValue(avatarId, out avatar);
  901. }
  902. protected internal bool TryGetAvatarByName(string avatarName, out ScenePresence avatar)
  903. {
  904. ScenePresence[] presences = GetScenePresences();
  905. for (int i = 0; i < presences.Length; i++)
  906. {
  907. ScenePresence presence = presences[i];
  908. if (!presence.IsChildAgent)
  909. {
  910. if (String.Compare(avatarName, presence.ControllingClient.Name, true) == 0)
  911. {
  912. avatar = presence;
  913. return true;
  914. }
  915. }
  916. }
  917. avatar = null;
  918. return false;
  919. }
  920. /// <summary>
  921. /// Returns a list of the entities in the scene. This is a new list so no locking is required to iterate over
  922. /// it
  923. /// </summary>
  924. /// <returns></returns>
  925. protected internal List<EntityBase> GetEntities()
  926. {
  927. return Entities.GetEntities();
  928. }
  929. public Dictionary<uint, float> GetTopScripts()
  930. {
  931. Dictionary<uint, float> topScripts = new Dictionary<uint, float>();
  932. List<EntityBase> EntityList = GetEntities();
  933. int limit = 0;
  934. foreach (EntityBase ent in EntityList)
  935. {
  936. if (ent is SceneObjectGroup)
  937. {
  938. SceneObjectGroup grp = (SceneObjectGroup)ent;
  939. if ((grp.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
  940. {
  941. if (grp.scriptScore >= 0.01)
  942. {
  943. topScripts.Add(grp.LocalId, grp.scriptScore);
  944. limit++;
  945. if (limit >= 100)
  946. {
  947. break;
  948. }
  949. }
  950. grp.scriptScore = 0;
  951. }
  952. }
  953. }
  954. return topScripts;
  955. }
  956. #endregion
  957. #region Other Methods
  958. protected internal void physicsBasedCrash()
  959. {
  960. handlerPhysicsCrash = UnRecoverableError;
  961. if (handlerPhysicsCrash != null)
  962. {
  963. handlerPhysicsCrash();
  964. }
  965. }
  966. protected internal UUID ConvertLocalIDToFullID(uint localID)
  967. {
  968. SceneObjectGroup group = GetGroupByPrim(localID);
  969. if (group != null)
  970. return group.GetPartsFullID(localID);
  971. else
  972. return UUID.Zero;
  973. }
  974. protected internal void ForEachSOG(Action<SceneObjectGroup> action)
  975. {
  976. List<SceneObjectGroup> objlist = new List<SceneObjectGroup>(SceneObjectGroupsByFullID.Values);
  977. foreach (SceneObjectGroup obj in objlist)
  978. {
  979. try
  980. {
  981. action(obj);
  982. }
  983. catch (Exception e)
  984. {
  985. // Catch it and move on. This includes situations where splist has inconsistent info
  986. m_log.WarnFormat("[SCENE]: Problem processing action in ForEachSOG: ", e.Message);
  987. }
  988. }
  989. }
  990. #endregion
  991. #region Client Event handlers
  992. /// <summary>
  993. ///
  994. /// </summary>
  995. /// <param name="localID"></param>
  996. /// <param name="scale"></param>
  997. /// <param name="remoteClient"></param>
  998. protected internal void UpdatePrimScale(uint localID, Vector3 scale, IClientAPI remoteClient)
  999. {
  1000. SceneObjectGroup group = GetGroupByPrim(localID);
  1001. if (group != null)
  1002. {
  1003. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1004. {
  1005. group.Resize(scale, localID);
  1006. }
  1007. }
  1008. }
  1009. protected internal void UpdatePrimGroupScale(uint localID, Vector3 scale, IClientAPI remoteClient)
  1010. {
  1011. SceneObjectGroup group = GetGroupByPrim(localID);
  1012. if (group != null)
  1013. {
  1014. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1015. {
  1016. group.GroupResize(scale, localID);
  1017. }
  1018. }
  1019. }
  1020. /// <summary>
  1021. /// This handles the nifty little tool tip that you get when you drag your mouse over an object
  1022. /// Send to the Object Group to process. We don't know enough to service the request
  1023. /// </summary>
  1024. /// <param name="remoteClient"></param>
  1025. /// <param name="AgentID"></param>
  1026. /// <param name="RequestFlags"></param>
  1027. /// <param name="ObjectID"></param>
  1028. protected internal void RequestObjectPropertiesFamily(
  1029. IClientAPI remoteClient, UUID AgentID, uint RequestFlags, UUID ObjectID)
  1030. {
  1031. SceneObjectGroup group = GetGroupByPrim(ObjectID);
  1032. if (group != null)
  1033. {
  1034. group.ServiceObjectPropertiesFamilyRequest(remoteClient, AgentID, RequestFlags);
  1035. }
  1036. }
  1037. /// <summary>
  1038. ///
  1039. /// </summary>
  1040. /// <param name="localID"></param>
  1041. /// <param name="rot"></param>
  1042. /// <param name="remoteClient"></param>
  1043. protected internal void UpdatePrimSingleRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
  1044. {
  1045. SceneObjectGroup group = GetGroupByPrim(localID);
  1046. if (group != null)
  1047. {
  1048. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
  1049. {
  1050. group.UpdateSingleRotation(rot, localID);
  1051. }
  1052. }
  1053. }
  1054. /// <summary>
  1055. ///
  1056. /// </summary>
  1057. /// <param name="localID"></param>
  1058. /// <param name="rot"></param>
  1059. /// <param name="remoteClient"></param>
  1060. protected internal void UpdatePrimSingleRotationPosition(uint localID, Quaternion rot, Vector3 pos, IClientAPI remoteClient)
  1061. {
  1062. SceneObjectGroup group = GetGroupByPrim(localID);
  1063. if (group != null)
  1064. {
  1065. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
  1066. {
  1067. group.UpdateSingleRotation(rot,pos, localID);
  1068. }
  1069. }
  1070. }
  1071. /// <summary>
  1072. ///
  1073. /// </summary>
  1074. /// <param name="localID"></param>
  1075. /// <param name="rot"></param>
  1076. /// <param name="remoteClient"></param>
  1077. protected internal void UpdatePrimRotation(uint localID, Quaternion rot, IClientAPI remoteClient)
  1078. {
  1079. SceneObjectGroup group = GetGroupByPrim(localID);
  1080. if (group != null)
  1081. {
  1082. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
  1083. {
  1084. group.UpdateGroupRotationR(rot);
  1085. }
  1086. }
  1087. }
  1088. /// <summary>
  1089. ///
  1090. /// </summary>
  1091. /// <param name="localID"></param>
  1092. /// <param name="pos"></param>
  1093. /// <param name="rot"></param>
  1094. /// <param name="remoteClient"></param>
  1095. protected internal void UpdatePrimRotation(uint localID, Vector3 pos, Quaternion rot, IClientAPI remoteClient)
  1096. {
  1097. SceneObjectGroup group = GetGroupByPrim(localID);
  1098. if (group != null)
  1099. {
  1100. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))
  1101. {
  1102. group.UpdateGroupRotationPR(pos, rot);
  1103. }
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// Update the position of the given part
  1108. /// </summary>
  1109. /// <param name="localID"></param>
  1110. /// <param name="pos"></param>
  1111. /// <param name="remoteClient"></param>
  1112. protected internal void UpdatePrimSinglePosition(uint localID, Vector3 pos, IClientAPI remoteClient)
  1113. {
  1114. SceneObjectGroup group = GetGroupByPrim(localID);
  1115. if (group != null)
  1116. {
  1117. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId) || group.IsAttachment)
  1118. {
  1119. group.UpdateSinglePosition(pos, localID);
  1120. }
  1121. }
  1122. }
  1123. /// <summary>
  1124. /// Update the position of the given part
  1125. /// </summary>
  1126. /// <param name="localID"></param>
  1127. /// <param name="pos"></param>
  1128. /// <param name="remoteClient"></param>
  1129. protected internal void UpdatePrimPosition(uint localID, Vector3 pos, IClientAPI remoteClient)
  1130. {
  1131. SceneObjectGroup group = GetGroupByPrim(localID);
  1132. if (group != null)
  1133. {
  1134. // Vector3 oldPos = group.AbsolutePosition;
  1135. if (group.IsAttachment || (group.RootPart.Shape.PCode == 9 && group.RootPart.Shape.State != 0))
  1136. {
  1137. // If this is an attachment, then we need to save the modified
  1138. // object back into the avatar's inventory. First we save the
  1139. // attachment point information, then we update the relative
  1140. // positioning (which caused this method to get driven in the
  1141. // first place. Then we have to mark the object as NOT an
  1142. // attachment. This is necessary in order to correctly save
  1143. // and retrieve GroupPosition information for the attachment.
  1144. // Then we save the asset back into the appropriate inventory
  1145. // entry. Finally, we restore the object's attachment status.
  1146. byte attachmentPoint = group.GetAttachmentPoint();
  1147. group.UpdateGroupPosition(pos);
  1148. group.RootPart.IsAttachment = false;
  1149. group.AbsolutePosition = group.RootPart.AttachedPos;
  1150. m_parentScene.UpdateKnownItem(remoteClient, group, group.GetFromItemID(), group.OwnerID);
  1151. group.SetAttachmentPoint(attachmentPoint);
  1152. }
  1153. else
  1154. {
  1155. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId) && m_parentScene.Permissions.CanObjectEntry(group.UUID, false, pos))
  1156. {
  1157. group.UpdateGroupPosition(pos);
  1158. }
  1159. }
  1160. }
  1161. }
  1162. /// <summary>
  1163. ///
  1164. /// </summary>
  1165. /// <param name="localID"></param>
  1166. /// <param name="texture"></param>
  1167. /// <param name="remoteClient"></param>
  1168. protected internal void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
  1169. {
  1170. SceneObjectGroup group = GetGroupByPrim(localID);
  1171. if (group != null)
  1172. {
  1173. if (m_parentScene.Permissions.CanEditObject(group.UUID,remoteClient.AgentId))
  1174. {
  1175. group.UpdateTextureEntry(localID, texture);
  1176. }
  1177. }
  1178. }
  1179. /// <summary>
  1180. ///
  1181. /// </summary>
  1182. /// <param name="localID"></param>
  1183. /// <param name="packet"></param>
  1184. /// <param name="remoteClient"></param>
  1185. /// This routine seems to get called when a user changes object settings in the viewer.
  1186. /// If some one can confirm that, please change the comment according.
  1187. protected internal void UpdatePrimFlags(uint localID, bool UsePhysics, bool IsTemporary, bool IsPhantom, IClientAPI remoteClient)
  1188. {
  1189. SceneObjectGroup group = GetGroupByPrim(localID);
  1190. if (group != null)
  1191. {
  1192. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1193. {
  1194. group.UpdatePrimFlags(localID, UsePhysics, IsTemporary, IsPhantom, false); // VolumeDetect can't be set via UI and will always be off when a change is made there
  1195. }
  1196. }
  1197. }
  1198. /// <summary>
  1199. /// Move the given object
  1200. /// </summary>
  1201. /// <param name="objectID"></param>
  1202. /// <param name="offset"></param>
  1203. /// <param name="pos"></param>
  1204. /// <param name="remoteClient"></param>
  1205. protected internal void MoveObject(UUID objectID, Vector3 offset, Vector3 pos, IClientAPI remoteClient, List<SurfaceTouchEventArgs> surfaceArgs)
  1206. {
  1207. SceneObjectGroup group = GetGroupByPrim(objectID);
  1208. if (group != null)
  1209. {
  1210. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
  1211. {
  1212. group.GrabMovement(offset, pos, remoteClient);
  1213. }
  1214. // This is outside the above permissions condition
  1215. // so that if the object is locked the client moving the object
  1216. // get's it's position on the simulator even if it was the same as before
  1217. // This keeps the moving user's client in sync with the rest of the world.
  1218. group.SendGroupTerseUpdate();
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// Start spinning the given object
  1223. /// </summary>
  1224. /// <param name="objectID"></param>
  1225. /// <param name="rotation"></param>
  1226. /// <param name="remoteClient"></param>
  1227. protected internal void SpinStart(UUID objectID, IClientAPI remoteClient)
  1228. {
  1229. SceneObjectGroup group = GetGroupByPrim(objectID);
  1230. if (group != null)
  1231. {
  1232. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
  1233. {
  1234. group.SpinStart(remoteClient);
  1235. }
  1236. }
  1237. }
  1238. /// <summary>
  1239. /// Spin the given object
  1240. /// </summary>
  1241. /// <param name="objectID"></param>
  1242. /// <param name="rotation"></param>
  1243. /// <param name="remoteClient"></param>
  1244. protected internal void SpinObject(UUID objectID, Quaternion rotation, IClientAPI remoteClient)
  1245. {
  1246. SceneObjectGroup group = GetGroupByPrim(objectID);
  1247. if (group != null)
  1248. {
  1249. if (m_parentScene.Permissions.CanMoveObject(group.UUID, remoteClient.AgentId))// && PermissionsMngr.)
  1250. {
  1251. group.SpinMovement(rotation, remoteClient);
  1252. }
  1253. // This is outside the above permissions condition
  1254. // so that if the object is locked the client moving the object
  1255. // get's it's position on the simulator even if it was the same as before
  1256. // This keeps the moving user's client in sync with the rest of the world.
  1257. group.SendGroupTerseUpdate();
  1258. }
  1259. }
  1260. /// <summary>
  1261. ///
  1262. /// </summary>
  1263. /// <param name="primLocalID"></param>
  1264. /// <param name="description"></param>
  1265. protected internal void PrimName(IClientAPI remoteClient, uint primLocalID, string name)
  1266. {
  1267. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1268. if (group != null)
  1269. {
  1270. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1271. {
  1272. group.SetPartName(Util.CleanString(name), primLocalID);
  1273. group.HasGroupChanged = true;
  1274. }
  1275. }
  1276. }
  1277. /// <summary>
  1278. ///
  1279. /// </summary>
  1280. /// <param name="primLocalID"></param>
  1281. /// <param name="description"></param>
  1282. protected internal void PrimDescription(IClientAPI remoteClient, uint primLocalID, string description)
  1283. {
  1284. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1285. if (group != null)
  1286. {
  1287. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1288. {
  1289. group.SetPartDescription(Util.CleanString(description), primLocalID);
  1290. group.HasGroupChanged = true;
  1291. }
  1292. }
  1293. }
  1294. protected internal void PrimClickAction(IClientAPI remoteClient, uint primLocalID, string clickAction)
  1295. {
  1296. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1297. if (group != null)
  1298. {
  1299. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1300. {
  1301. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primLocalID);
  1302. part.ClickAction = Convert.ToByte(clickAction);
  1303. group.HasGroupChanged = true;
  1304. }
  1305. }
  1306. }
  1307. protected internal void PrimMaterial(IClientAPI remoteClient, uint primLocalID, string material)
  1308. {
  1309. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1310. if (group != null)
  1311. {
  1312. if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
  1313. {
  1314. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primLocalID);
  1315. part.Material = Convert.ToByte(material);
  1316. group.HasGroupChanged = true;
  1317. }
  1318. }
  1319. }
  1320. protected internal void UpdateExtraParam(UUID agentID, uint primLocalID, ushort type, bool inUse, byte[] data)
  1321. {
  1322. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1323. if (group != null)
  1324. {
  1325. if (m_parentScene.Permissions.CanEditObject(group.UUID,agentID))
  1326. {
  1327. group.UpdateExtraParam(primLocalID, type, inUse, data);
  1328. }
  1329. }
  1330. }
  1331. /// <summary>
  1332. ///
  1333. /// </summary>
  1334. /// <param name="primLocalID"></param>
  1335. /// <param name="shapeBlock"></param>
  1336. protected internal void UpdatePrimShape(UUID agentID, uint primLocalID, UpdateShapeArgs shapeBlock)
  1337. {
  1338. SceneObjectGroup group = GetGroupByPrim(primLocalID);
  1339. if (group != null)
  1340. {
  1341. if (m_parentScene.Permissions.CanEditObject(group.GetPartsFullID(primLocalID), agentID))
  1342. {
  1343. ObjectShapePacket.ObjectDataBlock shapeData = new ObjectShapePacket.ObjectDataBlock();
  1344. shapeData.ObjectLocalID = shapeBlock.ObjectLocalID;
  1345. shapeData.PathBegin = shapeBlock.PathBegin;
  1346. shapeData.PathCurve = shapeBlock.PathCurve;
  1347. shapeData.PathEnd = shapeBlock.PathEnd;
  1348. shapeData.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  1349. shapeData.PathRevolutions = shapeBlock.PathRevolutions;
  1350. shapeData.PathScaleX = shapeBlock.PathScaleX;
  1351. shapeData.PathScaleY = shapeBlock.PathScaleY;
  1352. shapeData.PathShearX = shapeBlock.PathShearX;
  1353. shapeData.PathShearY = shapeBlock.PathShearY;
  1354. shapeData.PathSkew = shapeBlock.PathSkew;
  1355. shapeData.PathTaperX = shapeBlock.PathTaperX;
  1356. shapeData.PathTaperY = shapeBlock.PathTaperY;
  1357. shapeData.PathTwist = shapeBlock.PathTwist;
  1358. shapeData.PathTwistBegin = shapeBlock.PathTwistBegin;
  1359. shapeData.ProfileBegin = shapeBlock.ProfileBegin;
  1360. shapeData.ProfileCurve = shapeBlock.ProfileCurve;
  1361. shapeData.ProfileEnd = shapeBlock.ProfileEnd;
  1362. shapeData.ProfileHollow = shapeBlock.ProfileHollow;
  1363. group.UpdateShape(shapeData, primLocalID);
  1364. }
  1365. }
  1366. }
  1367. /// <summary>
  1368. /// Initial method invoked when we receive a link objects request from the client.
  1369. /// </summary>
  1370. /// <param name="client"></param>
  1371. /// <param name="parentPrim"></param>
  1372. /// <param name="childPrims"></param>
  1373. protected internal void LinkObjects(IClientAPI client, uint parentPrimId, List<uint> childPrimIds)
  1374. {
  1375. Monitor.Enter(m_updateLock);
  1376. try
  1377. {
  1378. SceneObjectGroup parentGroup = GetGroupByPrim(parentPrimId);
  1379. List<SceneObjectGroup> childGroups = new List<SceneObjectGroup>();
  1380. if (parentGroup != null)
  1381. {
  1382. // We do this in reverse to get the link order of the prims correct
  1383. for (int i = childPrimIds.Count - 1; i >= 0; i--)
  1384. {
  1385. SceneObjectGroup child = GetGroupByPrim(childPrimIds[i]);
  1386. if (child != null)
  1387. {
  1388. // Make sure no child prim is set for sale
  1389. // So that, on delink, no prims are unwittingly
  1390. // left for sale and sold off
  1391. child.RootPart.ObjectSaleType = 0;
  1392. child.RootPart.SalePrice = 10;
  1393. childGroups.Add(child);
  1394. }
  1395. }
  1396. }
  1397. else
  1398. {
  1399. return; // parent is null so not in this region
  1400. }
  1401. foreach (SceneObjectGroup child in childGroups)
  1402. {
  1403. parentGroup.LinkToGroup(child);
  1404. // this is here so physics gets updated!
  1405. // Don't remove! Bad juju! Stay away! or fix physics!
  1406. child.AbsolutePosition = child.AbsolutePosition;
  1407. }
  1408. // We need to explicitly resend the newly link prim's object properties since no other actions
  1409. // occur on link to invoke this elsewhere (such as object selection)
  1410. parentGroup.RootPart.AddFlag(PrimFlags.CreateSelected);
  1411. parentGroup.TriggerScriptChangedEvent(Changed.LINK);
  1412. parentGroup.HasGroupChanged = true;
  1413. parentGroup.ScheduleGroupForFullUpdate();
  1414. // if (client != null)
  1415. // {
  1416. // parentGroup.GetProperties(client);
  1417. // }
  1418. // else
  1419. // {
  1420. // foreach (ScenePresence p in GetScenePresences())
  1421. // {
  1422. // parentGroup.GetProperties(p.ControllingClient);
  1423. // }
  1424. // }
  1425. }
  1426. finally
  1427. {
  1428. Monitor.Exit(m_updateLock);
  1429. }
  1430. }
  1431. /// <summary>
  1432. /// Delink a linkset
  1433. /// </summary>
  1434. /// <param name="prims"></param>
  1435. protected internal void DelinkObjects(List<uint> primIds)
  1436. {
  1437. DelinkObjects(primIds, true);
  1438. }
  1439. protected internal void DelinkObjects(List<uint> primIds, bool sendEvents)
  1440. {
  1441. Monitor.Enter(m_updateLock);
  1442. try
  1443. {
  1444. List<SceneObjectPart> childParts = new List<SceneObjectPart>();
  1445. List<SceneObjectPart> rootParts = new List<SceneObjectPart>();
  1446. List<SceneObjectGroup> affectedGroups = new List<SceneObjectGroup>();
  1447. // Look them all up in one go, since that is comparatively expensive
  1448. //
  1449. foreach (uint primID in primIds)
  1450. {
  1451. SceneObjectPart part = m_parentScene.GetSceneObjectPart(primID);
  1452. if (part != null)
  1453. {
  1454. if (part.ParentGroup.Children.Count != 1) // Skip single
  1455. {
  1456. if (part.LinkNum < 2) // Root
  1457. rootParts.Add(part);
  1458. else
  1459. childParts.Add(part);
  1460. SceneObjectGroup group = part.ParentGroup;
  1461. if (!affectedGroups.Contains(group))
  1462. affectedGroups.Add(group);
  1463. }
  1464. }
  1465. else
  1466. {
  1467. m_log.ErrorFormat("Viewer requested unlink of nonexistent part {0}", primID);
  1468. }
  1469. }
  1470. foreach (SceneObjectPart child in childParts)
  1471. {
  1472. // Unlink all child parts from their groups
  1473. //
  1474. child.ParentGroup.DelinkFromGroup(child, sendEvents);
  1475. }
  1476. foreach (SceneObjectPart root in rootParts)
  1477. {
  1478. // In most cases, this will run only one time, and the prim
  1479. // will be a solo prim
  1480. // However, editing linked parts and unlinking may be different
  1481. //
  1482. SceneObjectGroup group = root.ParentGroup;
  1483. List<SceneObjectPart> newSet = new List<SceneObjectPart>(group.Children.Values);
  1484. int numChildren = group.Children.Count;
  1485. // If there are prims left in a link set, but the root is
  1486. // slated for unlink, we need to do this
  1487. //
  1488. if (numChildren != 1)
  1489. {
  1490. // Unlink the remaining set
  1491. //
  1492. bool sendEventsToRemainder = true;
  1493. if (numChildren > 1)
  1494. sendEventsToRemainder = false;
  1495. foreach (SceneObjectPart p in newSet)
  1496. {
  1497. if (p != group.RootPart)
  1498. group.DelinkFromGroup(p, sendEventsToRemainder);
  1499. }
  1500. // If there is more than one prim remaining, we
  1501. // need to re-link
  1502. //
  1503. if (numChildren > 2)
  1504. {
  1505. // Remove old root
  1506. //
  1507. if (newSet.Contains(root))
  1508. newSet.Remove(root);
  1509. // Preserve link ordering
  1510. //
  1511. newSet.Sort(delegate (SceneObjectPart a, SceneObjectPart b)
  1512. {
  1513. return a.LinkNum.CompareTo(b.LinkNum);
  1514. });
  1515. // Determine new root
  1516. //
  1517. SceneObjectPart newRoot = newSet[0];
  1518. newSet.RemoveAt(0);
  1519. List<uint> linkIDs = new List<uint>();
  1520. foreach (SceneObjectPart newChild in newSet)
  1521. {
  1522. newChild.UpdateFlag = 0;
  1523. linkIDs.Add(newChild.LocalId);
  1524. }
  1525. LinkObjects(null, newRoot.LocalId, linkIDs);
  1526. if (!affectedGroups.Contains(newRoot.ParentGroup))
  1527. affectedGroups.Add(newRoot.ParentGroup);
  1528. }
  1529. }
  1530. }
  1531. // Finally, trigger events in the roots
  1532. //
  1533. foreach (SceneObjectGroup g in affectedGroups)
  1534. {
  1535. g.TriggerScriptChangedEvent(Changed.LINK);
  1536. g.HasGroupChanged = true; // Persist
  1537. g.ScheduleGroupForFullUpdate();
  1538. }
  1539. }
  1540. finally
  1541. {
  1542. Monitor.Exit(m_updateLock);
  1543. }
  1544. }
  1545. protected internal void MakeObjectSearchable(IClientAPI remoteClient, bool IncludeInSearch, uint localID)
  1546. {
  1547. UUID user = remoteClient.AgentId;
  1548. UUID objid = UUID.Zero;
  1549. SceneObjectPart obj = null;
  1550. List<EntityBase> EntityList = GetEntities();
  1551. foreach (EntityBase ent in EntityList)
  1552. {
  1553. if (ent is SceneObjectGroup)
  1554. {
  1555. foreach (KeyValuePair<UUID, SceneObjectPart> subent in ((SceneObjectGroup)ent).Children)
  1556. {
  1557. if (subent.Value.LocalId == localID)
  1558. {
  1559. objid = subent.Key;
  1560. obj = subent.Value;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. //Protip: In my day, we didn't call them searchable objects, we called them limited point-to-point joints
  1566. //aka ObjectFlags.JointWheel = IncludeInSearch
  1567. //Permissions model: Object can be REMOVED from search IFF:
  1568. // * User owns object
  1569. //use CanEditObject
  1570. //Object can be ADDED to search IFF:
  1571. // * User owns object
  1572. // * Asset/DRM permission bit "modify" is enabled
  1573. //use CanEditObjectPosition
  1574. // libomv will complain about PrimFlags.JointWheel being
  1575. // deprecated, so we
  1576. #pragma warning disable 0612
  1577. if (IncludeInSearch && m_parentScene.Permissions.CanEditObject(objid, user))
  1578. {
  1579. obj.ParentGroup.RootPart.AddFlag(PrimFlags.JointWheel);
  1580. obj.ParentGroup.HasGroupChanged = true;
  1581. }
  1582. else if (!IncludeInSearch && m_parentScene.Permissions.CanMoveObject(objid,user))
  1583. {
  1584. obj.ParentGroup.RootPart.RemFlag(PrimFlags.JointWheel);
  1585. obj.ParentGroup.HasGroupChanged = true;
  1586. }
  1587. #pragma warning restore 0612
  1588. }
  1589. /// <summary>
  1590. /// Duplicate the given object, Fire and Forget, No rotation, no return wrapper
  1591. /// </summary>
  1592. /// <param name="originalPrim"></param>
  1593. /// <param name="offset"></param>
  1594. /// <param name="flags"></param>
  1595. protected internal void DuplicateObject(uint originalPrim, Vector3 offset, uint flags, UUID AgentID, UUID GroupID)
  1596. {
  1597. //m_log.DebugFormat("[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", originalPrim, offset, AgentID);
  1598. // SceneObjectGroup dupe = DuplicateObject(originalPrim, offset, flags, AgentID, GroupID, Quaternion.Zero);
  1599. DuplicateObject(originalPrim, offset, flags, AgentID, GroupID, Quaternion.Identity);
  1600. }
  1601. /// <summary>
  1602. /// Duplicate the given object.
  1603. /// </summary>
  1604. /// <param name="originalPrim"></param>
  1605. /// <param name="offset"></param>
  1606. /// <param name="flags"></param>
  1607. protected internal SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
  1608. {
  1609. //m_log.DebugFormat("[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", originalPrim, offset, AgentID);
  1610. SceneObjectGroup original = GetGroupByPrim(originalPrimID);
  1611. if (original != null)
  1612. {
  1613. if (m_parentScene.Permissions.CanDuplicateObject(original.Children.Count, original.UUID, AgentID, original.AbsolutePosition))
  1614. {
  1615. SceneObjectGroup copy = original.Copy(AgentID, GroupID, true);
  1616. copy.AbsolutePosition = copy.AbsolutePosition + offset;
  1617. Entities.Add(copy);
  1618. // Since we copy from a source group that is in selected
  1619. // state, but the copy is shown deselected in the viewer,
  1620. // We need to clear the selection flag here, else that
  1621. // prim never gets persisted at all. The client doesn't
  1622. // think it's selected, so it will never send a deselect...
  1623. copy.IsSelected = false;
  1624. m_numPrim += copy.Children.Count;
  1625. if (rot != Quaternion.Identity)
  1626. {
  1627. copy.UpdateGroupRotationR(rot);
  1628. }
  1629. copy.CreateScriptInstances(0, false, m_parentScene.DefaultScriptEngine, 0);
  1630. copy.HasGroupChanged = true;
  1631. copy.ScheduleGroupForFullUpdate();
  1632. // required for physics to update it's position
  1633. copy.AbsolutePosition = copy.AbsolutePosition;
  1634. if (OnObjectDuplicate != null)
  1635. OnObjectDuplicate(original, copy);
  1636. return copy;
  1637. }
  1638. }
  1639. else
  1640. {
  1641. m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
  1642. }
  1643. return null;
  1644. }
  1645. /// <summary>
  1646. /// Calculates the distance between two Vector3s
  1647. /// </summary>
  1648. /// <param name="v1"></param>
  1649. /// <param name="v2"></param>
  1650. /// <returns></returns>
  1651. protected internal float Vector3Distance(Vector3 v1, Vector3 v2)
  1652. {
  1653. // We don't really need the double floating point precision...
  1654. // so casting it to a single
  1655. return
  1656. (float)
  1657. 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));
  1658. }
  1659. #endregion
  1660. }
  1661. }