PageRenderTime 86ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs

https://bitbucket.org/VirtualReality/aurora-sim
C# | 4424 lines | 3063 code | 447 blank | 914 comment | 695 complexity | 63c8a241f2f3c968dec023f390d39e6d MD5 | raw file
  1. /*
  2. * Copyright (c) Contributors, http://aurora-sim.org/, 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 Aurora-Sim 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.Collections.Generic;
  29. using System.Drawing;
  30. using System.Linq;
  31. using System.Xml.Serialization;
  32. using Aurora.Framework;
  33. using OpenMetaverse;
  34. using OpenMetaverse.Packets;
  35. using OpenMetaverse.StructuredData;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes.Serialization;
  38. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  39. namespace OpenSim.Region.Framework.Scenes
  40. {
  41. [Flags]
  42. public enum scriptEvents : long
  43. {
  44. None = 0,
  45. attach = 1,
  46. collision = 16,
  47. collision_end = 32,
  48. collision_start = 64,
  49. control = 128,
  50. dataserver = 256,
  51. email = 512,
  52. http_response = 1024,
  53. land_collision = 2048,
  54. land_collision_end = 4096,
  55. land_collision_start = 8192,
  56. at_target = 16384,
  57. at_rot_target = 16777216,
  58. listen = 32768,
  59. money = 65536,
  60. moving_end = 131072,
  61. moving_start = 262144,
  62. not_at_rot_target = 524288,
  63. not_at_target = 1048576,
  64. remote_data = 8388608,
  65. run_time_permissions = 268435456,
  66. state_entry = 1073741824,
  67. state_exit = 2,
  68. timer = 4,
  69. touch = 8,
  70. touch_end = 536870912,
  71. touch_start = 2097152,
  72. object_rez = 4194304,
  73. changed = 2147483648,
  74. link_message = 4294967296,
  75. no_sensor = 8589934592,
  76. on_rez = 17179869184,
  77. sensor = 34359738368,
  78. http_request = 68719476736
  79. }
  80. internal struct scriptPosTarget
  81. {
  82. public uint handle;
  83. public Vector3 targetPos;
  84. public float tolerance;
  85. }
  86. internal struct scriptRotTarget
  87. {
  88. public uint handle;
  89. public Quaternion targetRot;
  90. public float tolerance;
  91. }
  92. /// <summary>
  93. /// A scene object group is conceptually an object in the scene. The object is constituted of SceneObjectParts
  94. /// (often known as prims), one of which is considered the root part.
  95. /// </summary>
  96. public partial class SceneObjectGroup : ISceneObject
  97. //(ISceneObject implements ISceneEntity and IEntity)
  98. {
  99. private readonly List<uint> m_lastColliders = new List<uint>();
  100. private readonly Dictionary<uint, scriptRotTarget> m_rotTargets = new Dictionary<uint, scriptRotTarget>();
  101. private readonly Dictionary<uint, scriptPosTarget> m_targets = new Dictionary<uint, scriptPosTarget>();
  102. [XmlIgnore] private bool m_ValidgrpOOB; // control recalcutation
  103. [XmlIgnore] private float m_grpBSphereRadiusSQ; // the square of the radius of a sphere containing the oob
  104. [XmlIgnore] private Vector3 m_grpOOBoffset; // the position center of the bounding box relative to it's Position
  105. [XmlIgnore] private Vector3 m_grpOOBsize;
  106. // the size of a bounding box oriented as prim, is future will consider cutted prims, meshs etc
  107. public bool IsInTransit { get; set; }
  108. public bool m_isLoaded;
  109. private UUID m_lastParcelUUID = UUID.Zero;
  110. private Vector3 m_lastSignificantPosition = Vector3.Zero;
  111. protected Dictionary<UUID, SceneObjectPart> m_parts = new Dictionary<UUID, SceneObjectPart>();
  112. //Same as m_parts, but this is used for fast linear operations
  113. protected List<SceneObjectPart> m_partsList = new List<SceneObjectPart>();
  114. //This is the lock for m_parts and m_partsList
  115. protected object m_partsLock = new object();
  116. protected ulong m_regionHandle;
  117. protected SceneObjectPart m_rootPart;
  118. private bool m_scriptListens_atRotTarget;
  119. private bool m_scriptListens_atTarget;
  120. private bool m_scriptListens_notAtRotTarget;
  121. private bool m_scriptListens_notAtTarget;
  122. #region Properties
  123. private List<ISceneChildEntity> m_LoopSoundSlavePrims = new List<ISceneChildEntity>();
  124. private List<ISceneChildEntity> m_PlaySoundSlavePrims = new List<ISceneChildEntity>();
  125. /// <summary>
  126. /// Added because the Parcel code seems to use it
  127. /// but not sure a object should have this
  128. /// as what does it tell us? that some avatar has selected it (but not what Avatar/user)
  129. /// think really there should be a list (or whatever) in each scenepresence
  130. /// saying what prim(s) that user has selected.
  131. /// </summary>
  132. protected bool m_isSelected;
  133. protected Quaternion m_rotation = Quaternion.Identity;
  134. public SceneObjectPart[] Parts
  135. {
  136. get { return m_partsList.ToArray(); }
  137. }
  138. /// <value>
  139. /// The parts of this scene object group. You must lock this property before using it.
  140. /// </value>
  141. public List<SceneObjectPart> ChildrenList
  142. {
  143. get { return m_partsList; }
  144. }
  145. /// <value>
  146. /// The root part of this scene object
  147. /// </value>
  148. public SceneObjectPart RootPart
  149. {
  150. get { return m_rootPart; }
  151. }
  152. public Color Color
  153. {
  154. get { return m_rootPart.Color; }
  155. set
  156. {
  157. if (m_rootPart != null && m_rootPart.Color != value)
  158. m_rootPart.Color = value;
  159. }
  160. }
  161. public KeyframeAnimation m_KeyframeAnimation = null;
  162. public KeyframeAnimation KeyframeAnimation
  163. {
  164. get
  165. {
  166. OSDMap map = (OSDMap)m_rootPart.GetComponentState("KeyframeAnimation");
  167. m_KeyframeAnimation = new KeyframeAnimation();
  168. m_KeyframeAnimation.FromOSD(map);
  169. return m_KeyframeAnimation;
  170. }
  171. set
  172. {
  173. m_KeyframeAnimation = value;
  174. if (m_KeyframeAnimation == null)
  175. m_rootPart.RemoveComponentState("KeyframeAnimation");
  176. else
  177. m_rootPart.SetComponentState("KeyframeAnimation", m_KeyframeAnimation.ToOSD());
  178. }
  179. }
  180. public string Text
  181. {
  182. get
  183. {
  184. string returnstr = m_rootPart.Text;
  185. if (returnstr.Length > 255)
  186. {
  187. returnstr = returnstr.Substring(0, 255);
  188. }
  189. return returnstr;
  190. }
  191. set
  192. {
  193. if (m_rootPart != null && m_rootPart.Text != value)
  194. m_rootPart.Text = value;
  195. }
  196. }
  197. public ISceneChildEntity PlaySoundMasterPrim { get; set; }
  198. public List<ISceneChildEntity> PlaySoundSlavePrims
  199. {
  200. get { return m_PlaySoundSlavePrims; }
  201. set { m_PlaySoundSlavePrims = value; }
  202. }
  203. public UUID RegionUUID
  204. {
  205. get
  206. {
  207. if (m_scene != null)
  208. {
  209. return m_scene.RegionInfo.RegionID;
  210. }
  211. return UUID.Zero;
  212. }
  213. }
  214. /// <summary>
  215. /// The name of an object grouping is always the same as its root part
  216. /// </summary>
  217. public override string Name
  218. {
  219. get
  220. {
  221. if (RootPart == null)
  222. return String.Empty;
  223. return RootPart.Name;
  224. }
  225. set { RootPart.Name = value; }
  226. }
  227. /// <summary>
  228. /// Number of prims in this group
  229. /// </summary>
  230. public int PrimCount
  231. {
  232. get { return m_parts.Count; }
  233. }
  234. public override Quaternion Rotation
  235. {
  236. get { return m_rotation; }
  237. set
  238. {
  239. HasGroupChanged = true;
  240. m_rotation = value;
  241. }
  242. }
  243. public Quaternion GroupRotation
  244. {
  245. get { return m_rootPart.RotationOffset; }
  246. }
  247. public UUID GroupID
  248. {
  249. get { return m_rootPart.GroupID; }
  250. set
  251. {
  252. HasGroupChanged = true;
  253. m_rootPart.GroupID = value;
  254. }
  255. }
  256. public List<ISceneChildEntity> ChildrenEntities()
  257. {
  258. return new List<SceneObjectPart>(m_partsList).Cast<ISceneChildEntity>().ToList();
  259. }
  260. public List<UUID> SitTargetAvatar
  261. {
  262. get
  263. {
  264. List<UUID> sittingAvatars = new List<UUID>();
  265. foreach (var prim in ChildrenEntities())
  266. sittingAvatars.AddRange(new List<UUID>(prim.SitTargetAvatar));
  267. return sittingAvatars;
  268. }
  269. }
  270. /// <summary>
  271. /// The absolute position of this scene object in the scene
  272. /// </summary>
  273. public override Vector3 AbsolutePosition
  274. {
  275. get { return m_rootPart.GroupPosition; }
  276. set { SetAbsolutePosition(true, value); }
  277. }
  278. public override uint LocalId
  279. {
  280. get { return m_rootPart.LocalId; }
  281. set { m_rootPart.LocalId = value; }
  282. }
  283. public override UUID UUID
  284. {
  285. get { return m_rootPart.UUID; }
  286. set { Scene.SceneGraph.UpdateEntity(this, value); }
  287. }
  288. public UUID OwnerID
  289. {
  290. get { return m_rootPart.OwnerID; }
  291. set
  292. {
  293. HasGroupChanged = true;
  294. m_rootPart.OwnerID = value;
  295. }
  296. }
  297. public float Damage
  298. {
  299. get { return m_rootPart.Damage; }
  300. set
  301. {
  302. HasGroupChanged = true;
  303. m_rootPart.Damage = value;
  304. }
  305. }
  306. public bool IsSelected
  307. {
  308. get { return m_isSelected; }
  309. set
  310. {
  311. m_isSelected = value;
  312. // Tell physics engine that group is selected
  313. if (m_rootPart.PhysActor != null)
  314. {
  315. m_rootPart.PhysActor.Selected = value;
  316. // Pass it on to the children.
  317. #if (!ISWIN)
  318. foreach (SceneObjectPart child in ChildrenList)
  319. {
  320. if (child.PhysActor != null)
  321. {
  322. child.PhysActor.Selected = value;
  323. }
  324. }
  325. #else
  326. foreach (SceneObjectPart child in ChildrenList.Where(child => child.PhysActor != null))
  327. {
  328. child.PhysActor.Selected = value;
  329. }
  330. #endif
  331. }
  332. }
  333. }
  334. public ISceneChildEntity LoopSoundMasterPrim { get; set; }
  335. public List<ISceneChildEntity> LoopSoundSlavePrims
  336. {
  337. get { return m_LoopSoundSlavePrims; }
  338. set { m_LoopSoundSlavePrims = value; }
  339. }
  340. public bool ContainsPart(UUID partID)
  341. {
  342. return m_parts.ContainsKey(partID);
  343. }
  344. /// <summary>
  345. /// Check both the attachment property and the relevant properties of the underlying root part.
  346. /// </summary>
  347. /// This is necessary in some cases, particularly when a scene object has just crossed into a region and doesn't
  348. /// have the IsAttachment property yet checked.
  349. ///
  350. /// FIXME: However, this should be fixed so that this property
  351. /// propertly reflects the underlying status.
  352. /// <returns></returns>
  353. public bool IsAttachmentCheckFull()
  354. {
  355. return (IsAttachment || (m_rootPart.Shape.PCode == 9 && m_rootPart.Shape.State != 0));
  356. }
  357. // The UUID for the Region this Object is in.
  358. #endregion
  359. #region Constructors
  360. /// <summary>
  361. /// THIS IS ONLY FOR SERIALIZATION AND AS A BASE CONSTRUCTOR
  362. /// </summary>
  363. public SceneObjectGroup(IScene scene)
  364. {
  365. m_scene = scene;
  366. m_isLoaded = true;
  367. }
  368. /// <summary>
  369. /// This constructor creates a SceneObjectGroup using a pre-existing SceneObjectPart.
  370. /// The original SceneObjectPart will be used rather than a copy, preserving
  371. /// its existing localID and UUID.
  372. /// </summary>
  373. public SceneObjectGroup(SceneObjectPart part, IScene scene) : this(scene)
  374. {
  375. SetRootPart(part);
  376. part.Scale = part.Shape.Scale; // temporary hack to update oobb
  377. m_ValidgrpOOB = false;
  378. }
  379. public SceneObjectGroup(SceneObjectPart part, IScene scene, bool AddToScene)
  380. : this(scene)
  381. {
  382. if (!AddToScene)
  383. {
  384. m_isLoaded = false;
  385. m_isDeleted = true;
  386. }
  387. SetRootPart(part);
  388. part.Scale = part.Shape.Scale; // temporary hack to update oobb
  389. m_ValidgrpOOB = false;
  390. }
  391. /// <summary>
  392. /// Constructor. This object is added to the scene later via AttachToScene()
  393. /// </summary>
  394. public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape, string name,
  395. IScene scene) : this(scene)
  396. {
  397. SceneObjectPart part = new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero, name, scene);
  398. SetRootPart(part);
  399. //This has to be set, otherwise it will break things like rezzing objects in an area where crossing is disabled, but rez isn't
  400. m_lastSignificantPosition = pos;
  401. m_ValidgrpOOB = false;
  402. }
  403. public void SetFromItemID(UUID itemID, UUID assetID)
  404. {
  405. foreach (SceneObjectPart part in m_partsList)
  406. {
  407. part.FromUserInventoryItemID = itemID;
  408. part.FromUserInventoryAssetID = assetID;
  409. }
  410. }
  411. /// <summary>
  412. /// Attach this object to a scene. It will also now apply to agents.
  413. /// </summary>
  414. /// <param name = "scene"></param>
  415. public void AttachToScene(IScene scene)
  416. {
  417. m_scene = scene;
  418. if (m_rootPart.Shape == null)
  419. {
  420. MainConsole.Instance.Warn("[SceneObjectGroup]: Found null shape for prim " + UUID + ", creating default box shape");
  421. m_rootPart.Shape = new PrimitiveBaseShape();
  422. }
  423. IOpenRegionSettingsModule WSModule = Scene.RequestModuleInterface<IOpenRegionSettingsModule>();
  424. if (WSModule != null)
  425. {
  426. foreach (SceneObjectPart part in ChildrenList)
  427. {
  428. //It's being rezzed, add it to the scene if it doesn't already have a rez date
  429. if (part.Rezzed != Util.ToDateTime(Util.EnvironmentTickCount()))
  430. part.Rezzed = DateTime.UtcNow;
  431. if (part.Shape == null)
  432. continue;
  433. Vector3 scale = part.Shape.Scale;
  434. if (WSModule.MinimumPrimScale != -1)
  435. {
  436. if (scale.X < WSModule.MinimumPrimScale)
  437. scale.X = WSModule.MinimumPrimScale;
  438. if (scale.Y < WSModule.MinimumPrimScale)
  439. scale.Y = WSModule.MinimumPrimScale;
  440. if (scale.Z < WSModule.MinimumPrimScale)
  441. scale.Z = WSModule.MinimumPrimScale;
  442. }
  443. if (part.ParentGroup.RootPart.PhysActor != null && part.ParentGroup.RootPart.PhysActor.IsPhysical &&
  444. WSModule.MaximumPhysPrimScale != -1)
  445. {
  446. if (scale.X > WSModule.MaximumPhysPrimScale)
  447. scale.X = WSModule.MaximumPhysPrimScale;
  448. if (scale.Y > WSModule.MaximumPhysPrimScale)
  449. scale.Y = WSModule.MaximumPhysPrimScale;
  450. if (scale.Z > WSModule.MaximumPhysPrimScale)
  451. scale.Z = WSModule.MaximumPhysPrimScale;
  452. }
  453. if (WSModule.MaximumPrimScale != -1)
  454. {
  455. if (scale.X > WSModule.MaximumPrimScale)
  456. scale.X = WSModule.MaximumPrimScale;
  457. if (scale.Y > WSModule.MaximumPrimScale)
  458. scale.Y = WSModule.MaximumPrimScale;
  459. if (scale.Z > WSModule.MaximumPrimScale)
  460. scale.Z = WSModule.MaximumPrimScale;
  461. }
  462. part.Scale = scale;
  463. }
  464. }
  465. //Trigger our event
  466. Scene.EventManager.TriggerObjectBeingAddedToScene(this);
  467. RebuildPhysicalRepresentation(false);
  468. m_ValidgrpOOB = false;
  469. }
  470. public Vector3 GroupScale()
  471. {
  472. if (m_partsList.Count == 1)
  473. return RootPart.Scale;
  474. Vector3 minScale = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  475. Vector3 maxScale = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  476. Vector3 finalScale;
  477. foreach (SceneObjectPart part in m_partsList)
  478. {
  479. Vector3 partscale = part.Scale*0.5f;
  480. // not assuming root is at index 0
  481. if (part.ParentID == 0) // root is in local frame of reference, partscale.? are positive, no rotations
  482. {
  483. // if root is always at index 0 this can be just assigns
  484. if (partscale.X > maxScale.X)
  485. maxScale.X = partscale.X;
  486. if (partscale.Y > maxScale.Y)
  487. maxScale.Y = partscale.Y;
  488. if (partscale.Z > maxScale.Z)
  489. maxScale.Z = partscale.Z;
  490. partscale = -partscale;
  491. if (partscale.X < minScale.X)
  492. minScale.X = partscale.X;
  493. if (partscale.Y < minScale.Y)
  494. minScale.Y = partscale.Y;
  495. if (partscale.Z < minScale.Z)
  496. minScale.Z = partscale.Z;
  497. }
  498. else // prims are in their local frame of reference
  499. {
  500. Vector3 partoffset = part.OffsetPosition;
  501. Quaternion partrot = part.RotationOffset;
  502. // bring into this frame
  503. partscale *= partrot;
  504. partoffset *= partrot;
  505. partoffset += part.OffsetPosition;
  506. // now just 2 vertices in a diagonal
  507. Vector3 deltam = partoffset - partscale;
  508. Vector3 deltaM = partoffset + partscale;
  509. if (deltaM.X > deltam.X) // right vertices order for extrem X
  510. {
  511. if (deltam.X < minScale.X)
  512. minScale.X = deltam.X;
  513. if (deltaM.X > maxScale.X)
  514. maxScale.X = deltaM.X;
  515. }
  516. else // nopes inverse one
  517. {
  518. if (deltaM.X < minScale.X)
  519. minScale.X = deltaM.X;
  520. if (deltam.X > maxScale.X)
  521. maxScale.X = deltam.X;
  522. }
  523. if (deltaM.Y > deltam.Y)
  524. {
  525. if (deltam.Y < minScale.Y)
  526. minScale.Y = deltam.Y;
  527. if (deltaM.Y > maxScale.Y)
  528. maxScale.Y = deltaM.Y;
  529. }
  530. else
  531. {
  532. if (deltaM.Y < minScale.Y)
  533. minScale.Y = deltaM.Y;
  534. if (deltam.Y > maxScale.Y)
  535. maxScale.Y = deltam.Y;
  536. }
  537. if (deltaM.Z > deltam.Z)
  538. {
  539. if (deltam.Z < minScale.Z)
  540. minScale.Z = deltam.Z;
  541. if (deltaM.Z > maxScale.Z)
  542. maxScale.Z = deltaM.Z;
  543. }
  544. else
  545. {
  546. if (deltaM.Z < minScale.Z)
  547. minScale.Z = deltaM.Z;
  548. if (deltam.Z > maxScale.Z)
  549. maxScale.Z = deltam.Z;
  550. }
  551. }
  552. }
  553. finalScale.X = Math.Abs(maxScale.X - minScale.X);
  554. finalScale.Y = Math.Abs(maxScale.Y - minScale.Y);
  555. finalScale.Z = Math.Abs(maxScale.Z - minScale.Z);
  556. return finalScale;
  557. }
  558. public override int GetHashCode()
  559. {
  560. return UUID.GetHashCode();
  561. }
  562. public bool IsPhysical()
  563. {
  564. return ((RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics);
  565. }
  566. public void UpdateOOBfromOOBs()
  567. {
  568. if (m_partsList.Count == 1)
  569. {
  570. SceneObjectPart part = m_partsList.First();
  571. m_grpOOBsize = part.OOBsize;
  572. m_grpOOBoffset = part.OOBoffset;
  573. m_grpBSphereRadiusSQ = part.BSphereRadiusSQ;
  574. m_ValidgrpOOB = true;
  575. return;
  576. }
  577. Vector3 minScale = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  578. Vector3 maxScale = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  579. foreach (SceneObjectPart part in m_partsList)
  580. {
  581. Vector3 partscale = part.OOBsize; // (oobsize == vector with box vertice with all coords positive)
  582. Vector3 partoffset = part.OOBoffset;
  583. // not assuming root is at index 0
  584. Vector3 deltam;
  585. Vector3 deltaM;
  586. if (part.ParentID == 0) // root is in local frame of reference, partscale.? are positive, no rotations
  587. {
  588. //2 vertices in the right extrem sides:
  589. deltam = partoffset - partscale;
  590. deltaM = partoffset + partscale;
  591. // if root is always at index 0 this can be just assigns
  592. if (deltam.X < minScale.X)
  593. minScale.X = deltam.X;
  594. if (deltam.Y < minScale.Y)
  595. minScale.Y = deltam.Y;
  596. if (deltam.Z < minScale.Z)
  597. minScale.Z = deltam.Z;
  598. if (deltaM.X > maxScale.X)
  599. maxScale.X = deltaM.X;
  600. if (deltaM.Y > maxScale.Y)
  601. maxScale.Y = deltaM.Y;
  602. if (deltaM.Z > maxScale.Z)
  603. maxScale.Z = deltaM.Z;
  604. }
  605. else // prims are in their local frame of reference
  606. {
  607. // bring into this frame
  608. Quaternion partrot = part.RotationOffset;
  609. partscale *= partrot;
  610. partoffset *= partrot;
  611. partoffset += part.OffsetPosition;
  612. // now just 2 vertices in a diagonal
  613. deltam = partoffset - partscale;
  614. deltaM = partoffset + partscale;
  615. if (deltaM.X > deltam.X) // right vertices order for extrem X
  616. {
  617. if (deltam.X < minScale.X)
  618. minScale.X = deltam.X;
  619. if (deltaM.X > maxScale.X)
  620. maxScale.X = deltaM.X;
  621. }
  622. else // nopes inverse one
  623. {
  624. if (deltaM.X < minScale.X)
  625. minScale.X = deltaM.X;
  626. if (deltam.X > maxScale.X)
  627. maxScale.X = deltam.X;
  628. }
  629. if (deltaM.Y > deltam.Y)
  630. {
  631. if (deltam.Y < minScale.Y)
  632. minScale.Y = deltam.Y;
  633. if (deltaM.Y > maxScale.Y)
  634. maxScale.Y = deltaM.Y;
  635. }
  636. else
  637. {
  638. if (deltaM.Y < minScale.Y)
  639. minScale.Y = deltaM.Y;
  640. if (deltam.Y > maxScale.Y)
  641. maxScale.Y = deltam.Y;
  642. }
  643. if (deltaM.Z > deltam.Z)
  644. {
  645. if (deltam.Z < minScale.Z)
  646. minScale.Z = deltam.Z;
  647. if (deltaM.Z > maxScale.Z)
  648. maxScale.Z = deltaM.Z;
  649. }
  650. else
  651. {
  652. if (deltaM.Z < minScale.Z)
  653. minScale.Z = deltaM.Z;
  654. if (deltam.Z > maxScale.Z)
  655. maxScale.Z = deltam.Z;
  656. }
  657. }
  658. }
  659. // size == the vertice of box with all coords positive
  660. m_grpOOBsize.X = 0.5f*Math.Abs(maxScale.X - minScale.X);
  661. m_grpOOBsize.Y = 0.5f*Math.Abs(maxScale.Y - minScale.Y);
  662. m_grpOOBsize.Z = 0.5f*Math.Abs(maxScale.Z - minScale.Z);
  663. // centroid:
  664. m_grpOOBoffset.X = 0.5f*(maxScale.X + minScale.X);
  665. m_grpOOBoffset.Y = 0.5f*(maxScale.Y + minScale.Y);
  666. m_grpOOBoffset.Z = 0.5f*(maxScale.Z + minScale.Z);
  667. // containing sphere:
  668. m_grpBSphereRadiusSQ = m_grpOOBsize.LengthSquared();
  669. m_ValidgrpOOB = true;
  670. }
  671. public EntityIntersection TestIntersection(Ray hRay, bool frontFacesOnly, bool faceCenters)
  672. {
  673. // We got a request from the inner_scene to raytrace along the Ray hRay
  674. // We're going to check all of the prim in this group for intersection with the ray
  675. // If we get a result, we're going to find the closest result to the origin of the ray
  676. // and send back the intersection information back to the innerscene.
  677. EntityIntersection result = new EntityIntersection();
  678. foreach (SceneObjectPart part in m_partsList)
  679. {
  680. // Temporary commented to stop compiler warning
  681. //Vector3 partPosition =
  682. // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
  683. Quaternion parentrotation = GroupRotation;
  684. // Telling the prim to raytrace.
  685. //EntityIntersection inter = part.TestIntersection(hRay, parentrotation);
  686. EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
  687. // This may need to be updated to the maximum draw distance possible..
  688. // We might (and probably will) be checking for prim creation from other sims
  689. // when the camera crosses the border.
  690. if (m_scene != null)
  691. {
  692. float idist = (m_scene.RegionInfo.RegionSizeX + m_scene.RegionInfo.RegionSizeY)/2;
  693. if (inter.HitTF)
  694. {
  695. // We need to find the closest prim to return to the testcaller along the ray
  696. if (inter.distance < idist)
  697. {
  698. result.HitTF = true;
  699. result.ipoint = inter.ipoint;
  700. result.obj = part;
  701. result.normal = inter.normal;
  702. result.distance = inter.distance;
  703. }
  704. }
  705. }
  706. }
  707. return result;
  708. }
  709. /// <summary>
  710. /// Gets a vector representing the size of the bounding box containing all the prims in the group
  711. /// Treats all prims as rectangular, so no shape (cut etc) is taken into account
  712. /// offsetHeight is the offset in the Z axis from the centre of the bounding box to the centre of the root prim
  713. /// </summary>
  714. /// <returns></returns>
  715. public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY,
  716. out float minZ, out float maxZ)
  717. {
  718. Vector3 pos = m_rootPart.AbsolutePosition;
  719. Quaternion rot = m_rootPart.RotationOffset;
  720. // Vector3 size = GroupScale();
  721. Vector3 minScale = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
  722. Vector3 maxScale = new Vector3(float.MinValue, float.MinValue, float.MinValue);
  723. //limits in group frame
  724. foreach (SceneObjectPart part in m_partsList)
  725. {
  726. Vector3 partscale = part.Scale*0.5f;
  727. Vector3 partoffset = part.OffsetPosition;
  728. if (part.ParentID != 0) // prims are rotated in group
  729. {
  730. partscale *= part.RotationOffset;
  731. partscale.X = Math.Abs(partscale.X);
  732. partscale.Y = Math.Abs(partscale.Y);
  733. partscale.Z = Math.Abs(partscale.Z);
  734. }
  735. Vector3 deltam = partoffset - partscale;
  736. Vector3 deltaM = partoffset + partscale;
  737. if (deltam.X < minScale.X)
  738. minScale.X = deltam.X;
  739. if (deltam.Y < minScale.Y)
  740. minScale.Y = deltam.Y;
  741. if (deltam.Z < minScale.Z)
  742. minScale.Z = deltam.Z;
  743. if (deltaM.X > maxScale.X)
  744. maxScale.X = deltaM.X;
  745. if (deltaM.Y > maxScale.Y)
  746. maxScale.Y = deltaM.Y;
  747. if (deltaM.Z > maxScale.Z)
  748. maxScale.Z = deltaM.Z;
  749. }
  750. Vector3 tmp;
  751. tmp.X = 0.5f*Math.Abs(maxScale.X - minScale.X);
  752. tmp.Y = 0.5f*Math.Abs(maxScale.Y - minScale.Y);
  753. tmp.Z = 0.5f*Math.Abs(maxScale.Z - minScale.Z);
  754. // tmp has half scale
  755. // group rotation
  756. tmp = tmp*rot;
  757. // scale is positive
  758. tmp.X = Math.Abs(tmp.X);
  759. tmp.Y = Math.Abs(tmp.Y);
  760. tmp.Z = Math.Abs(tmp.Z);
  761. // group position
  762. minX = pos.X - tmp.X;
  763. minY = pos.Y - tmp.Y;
  764. minZ = pos.Z - tmp.Z;
  765. maxX = pos.X + tmp.X;
  766. maxY = pos.Y + tmp.Y;
  767. maxZ = pos.Z + tmp.Z;
  768. /*
  769. maxX = -256f;
  770. maxY = -256f;
  771. maxZ = -256f;
  772. minX = 256f;
  773. minY = 256f;
  774. minZ = 8192f;
  775. foreach (SceneObjectPart part in m_partsList)
  776. {
  777. Vector3 worldPos = part.GetWorldPosition();
  778. Vector3 offset = worldPos - AbsolutePosition;
  779. Quaternion worldRot;
  780. if (part.ParentID == 0)
  781. worldRot = part.RotationOffset;
  782. else
  783. worldRot = part.GetWorldRotation();
  784. Vector3 frontTopLeft;
  785. Vector3 frontTopRight;
  786. Vector3 frontBottomLeft;
  787. Vector3 frontBottomRight;
  788. Vector3 backTopLeft;
  789. Vector3 backTopRight;
  790. Vector3 backBottomLeft;
  791. Vector3 backBottomRight;
  792. Vector3 orig = Vector3.Zero;
  793. frontTopLeft.X = orig.X - (part.Scale.X / 2);
  794. frontTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  795. frontTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  796. frontTopRight.X = orig.X - (part.Scale.X / 2);
  797. frontTopRight.Y = orig.Y + (part.Scale.Y / 2);
  798. frontTopRight.Z = orig.Z + (part.Scale.Z / 2);
  799. frontBottomLeft.X = orig.X - (part.Scale.X / 2);
  800. frontBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  801. frontBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  802. frontBottomRight.X = orig.X - (part.Scale.X / 2);
  803. frontBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  804. frontBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  805. backTopLeft.X = orig.X + (part.Scale.X / 2);
  806. backTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  807. backTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  808. backTopRight.X = orig.X + (part.Scale.X / 2);
  809. backTopRight.Y = orig.Y + (part.Scale.Y / 2);
  810. backTopRight.Z = orig.Z + (part.Scale.Z / 2);
  811. backBottomLeft.X = orig.X + (part.Scale.X / 2);
  812. backBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  813. backBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  814. backBottomRight.X = orig.X + (part.Scale.X / 2);
  815. backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  816. backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  817. frontTopLeft = frontTopLeft * worldRot;
  818. frontTopRight = frontTopRight * worldRot;
  819. frontBottomLeft = frontBottomLeft * worldRot;
  820. frontBottomRight = frontBottomRight * worldRot;
  821. backBottomLeft = backBottomLeft * worldRot;
  822. backBottomRight = backBottomRight * worldRot;
  823. backTopLeft = backTopLeft * worldRot;
  824. backTopRight = backTopRight * worldRot;
  825. frontTopLeft += offset;
  826. frontTopRight += offset;
  827. frontBottomLeft += offset;
  828. frontBottomRight += offset;
  829. backBottomLeft += offset;
  830. backBottomRight += offset;
  831. backTopLeft += offset;
  832. backTopRight += offset;
  833. if (frontTopRight.X > maxX)
  834. maxX = frontTopRight.X;
  835. if (frontTopLeft.X > maxX)
  836. maxX = frontTopLeft.X;
  837. if (frontBottomRight.X > maxX)
  838. maxX = frontBottomRight.X;
  839. if (frontBottomLeft.X > maxX)
  840. maxX = frontBottomLeft.X;
  841. if (backTopRight.X > maxX)
  842. maxX = backTopRight.X;
  843. if (backTopLeft.X > maxX)
  844. maxX = backTopLeft.X;
  845. if (backBottomRight.X > maxX)
  846. maxX = backBottomRight.X;
  847. if (backBottomLeft.X > maxX)
  848. maxX = backBottomLeft.X;
  849. if (frontTopRight.X < minX)
  850. minX = frontTopRight.X;
  851. if (frontTopLeft.X < minX)
  852. minX = frontTopLeft.X;
  853. if (frontBottomRight.X < minX)
  854. minX = frontBottomRight.X;
  855. if (frontBottomLeft.X < minX)
  856. minX = frontBottomLeft.X;
  857. if (backTopRight.X < minX)
  858. minX = backTopRight.X;
  859. if (backTopLeft.X < minX)
  860. minX = backTopLeft.X;
  861. if (backBottomRight.X < minX)
  862. minX = backBottomRight.X;
  863. if (backBottomLeft.X < minX)
  864. minX = backBottomLeft.X;
  865. if (frontTopRight.Y > maxY)
  866. maxY = frontTopRight.Y;
  867. if (frontTopLeft.Y > maxY)
  868. maxY = frontTopLeft.Y;
  869. if (frontBottomRight.Y > maxY)
  870. maxY = frontBottomRight.Y;
  871. if (frontBottomLeft.Y > maxY)
  872. maxY = frontBottomLeft.Y;
  873. if (backTopRight.Y > maxY)
  874. maxY = backTopRight.Y;
  875. if (backTopLeft.Y > maxY)
  876. maxY = backTopLeft.Y;
  877. if (backBottomRight.Y > maxY)
  878. maxY = backBottomRight.Y;
  879. if (backBottomLeft.Y > maxY)
  880. maxY = backBottomLeft.Y;
  881. if (backTopRight.Y < minY)
  882. minY = backTopRight.Y;
  883. if (backTopLeft.Y < minY)
  884. minY = backTopLeft.Y;
  885. if (backBottomRight.Y < minY)
  886. minY = backBottomRight.Y;
  887. if (backBottomLeft.Y < minY)
  888. minY = backBottomLeft.Y;
  889. if (backTopRight.Y < minY)
  890. minY = backTopRight.Y;
  891. if (backTopLeft.Y < minY)
  892. minY = backTopLeft.Y;
  893. if (backBottomRight.Y < minY)
  894. minY = backBottomRight.Y;
  895. if (backBottomLeft.Y < minY)
  896. minY = backBottomLeft.Y;
  897. if (frontTopRight.Z > maxZ)
  898. maxZ = frontTopRight.Z;
  899. if (frontTopLeft.Z > maxZ)
  900. maxZ = frontTopLeft.Z;
  901. if (frontBottomRight.Z > maxZ)
  902. maxZ = frontBottomRight.Z;
  903. if (frontBottomLeft.Z > maxZ)
  904. maxZ = frontBottomLeft.Z;
  905. if (backTopRight.Z > maxZ)
  906. maxZ = backTopRight.Z;
  907. if (backTopLeft.Z > maxZ)
  908. maxZ = backTopLeft.Z;
  909. if (backBottomRight.Z > maxZ)
  910. maxZ = backBottomRight.Z;
  911. if (backBottomLeft.Z > maxZ)
  912. maxZ = backBottomLeft.Z;
  913. if (frontTopRight.Z < minZ)
  914. minZ = frontTopRight.Z;
  915. if (frontTopLeft.Z < minZ)
  916. minZ = frontTopLeft.Z;
  917. if (frontBottomRight.Z < minZ)
  918. minZ = frontBottomRight.Z;
  919. if (frontBottomLeft.Z < minZ)
  920. minZ = frontBottomLeft.Z;
  921. if (backTopRight.Z < minZ)
  922. minZ = backTopRight.Z;
  923. if (backTopLeft.Z < minZ)
  924. minZ = backTopLeft.Z;
  925. if (backBottomRight.Z < minZ)
  926. minZ = backBottomRight.Z;
  927. if (backBottomLeft.Z < minZ)
  928. minZ = backBottomLeft.Z;
  929. }
  930. */
  931. }
  932. public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
  933. {
  934. float minX;
  935. float maxX;
  936. float minY;
  937. float maxY;
  938. float minZ;
  939. float maxZ;
  940. GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  941. Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
  942. offsetHeight = 0.5f*(maxZ + minZ);
  943. offsetHeight -= m_rootPart.AbsolutePosition.Z;
  944. /*
  945. offsetHeight = 0;
  946. float lower = (minZ * -1);
  947. if (lower > maxZ)
  948. {
  949. offsetHeight = lower - (boundingBox.Z / 2);
  950. }
  951. else if (maxZ > lower)
  952. {
  953. offsetHeight = maxZ - (boundingBox.Z / 2);
  954. offsetHeight *= -1;
  955. }
  956. */
  957. // MainConsole.Instance.InfoFormat("BoundingBox is {0} , {1} , {2} ", boundingBox.X, boundingBox.Y, boundingBox.Z);
  958. return boundingBox;
  959. }
  960. #region Adding/Removing children from this group
  961. /// <summary>
  962. /// Clear all children from this group
  963. /// </summary>
  964. public void ClearChildren()
  965. {
  966. lock (m_partsLock)
  967. {
  968. m_parts.Clear();
  969. m_partsList.Clear();
  970. m_ValidgrpOOB = false;
  971. }
  972. }
  973. /// <summary>
  974. /// Add a child to the group, set the parent id's and then set the link number
  975. /// </summary>
  976. /// <param name = "child"></param>
  977. /// <param name="linkNum"></param>
  978. /// <returns></returns>
  979. public bool AddChild(ISceneChildEntity child, int linkNum)
  980. {
  981. lock (m_partsLock)
  982. {
  983. if (child is SceneObjectPart)
  984. {
  985. SceneObjectPart part = (SceneObjectPart) child;
  986. //Root part is first
  987. if (m_partsList.Count == 0)
  988. {
  989. m_rootPart = part;
  990. }
  991. //Set the parent prim
  992. part.SetParent(this);
  993. if (m_rootPart.LocalId != 0 && !part.IsRoot)
  994. part.SetParentLocalId(m_rootPart.LocalId);
  995. else
  996. part.SetParentLocalId(0);
  997. //Fix the link num
  998. part.LinkNum = linkNum;
  999. if (!m_parts.ContainsKey(child.UUID))
  1000. {
  1001. m_parts.Add(child.UUID, part);
  1002. m_partsList.Add(part);
  1003. m_ValidgrpOOB = false;
  1004. }
  1005. return true;
  1006. }
  1007. }
  1008. return false;
  1009. }
  1010. /// <summary>
  1011. /// Add this child to the group and set the parent ID's,
  1012. /// but do NOT set the link number,
  1013. /// the caller wants to deal with it if they call this
  1014. /// </summary>
  1015. /// <param name = "child"></param>
  1016. /// <returns></returns>
  1017. public bool LinkChild(ISceneChildEntity child)
  1018. {
  1019. lock (m_partsLock)
  1020. {
  1021. if (child is SceneObjectPart)
  1022. {
  1023. SceneObjectPart part = (SceneObjectPart) child;
  1024. //Root part is first
  1025. if (m_partsList.Count == 0)
  1026. {
  1027. m_rootPart = part;
  1028. }
  1029. //Set the parent prim
  1030. part.SetParent(this);
  1031. part.SetParentLocalId(m_rootPart.LocalId);
  1032. if (!m_parts.ContainsKey(child.UUID))
  1033. {
  1034. m_parts.Add(child.UUID, part);
  1035. m_partsList.Add(part);
  1036. m_ValidgrpOOB = false;
  1037. }
  1038. m_partsList.Sort(m_scene.SceneGraph.LinkSetSorter);
  1039. return true;
  1040. }
  1041. }
  1042. return false;
  1043. }
  1044. /// <summary>
  1045. /// Remove this child from the group and then update the link numbers so that there is not a hole
  1046. /// </summary>
  1047. /// <param name = "child"></param>
  1048. /// <returns></returns>
  1049. public bool RemoveChild(ISceneChildEntity child)
  1050. {
  1051. lock (m_partsLock)
  1052. {
  1053. if (child is SceneObjectPart)
  1054. {
  1055. SceneObjectPart part = (SceneObjectPart) child;
  1056. m_parts.Remove(part.UUID);
  1057. m_partsList.Remove(part);
  1058. m_ValidgrpOOB = false;
  1059. //Fix the link numbers now
  1060. FixLinkNumbers();
  1061. return true;
  1062. }
  1063. }
  1064. return false;
  1065. }
  1066. /// <summary>
  1067. /// After a prim is removed, fix the link numbers so that they are correct
  1068. /// </summary>
  1069. private void FixLinkNumbers()
  1070. {
  1071. if (m_partsList.Count == 1)
  1072. {
  1073. m_partsList[0].LinkNum = 0;
  1074. return;
  1075. }
  1076. lock (m_partsLock)
  1077. {
  1078. // has prims so starts at 1
  1079. int lastSeenLinkNum = 1;
  1080. m_partsList.Sort(Scene.SceneGraph.LinkSetSorter);
  1081. foreach (SceneObjectPart t in m_partsList)
  1082. {
  1083. //If it isn't the same as the last seen +1, fix it
  1084. if (t != null && t.LinkNum != lastSeenLinkNum)
  1085. t.LinkNum = lastSeenLinkNum;
  1086. //Go onto the next prim
  1087. lastSeenLinkNum++;
  1088. }
  1089. }
  1090. }
  1091. #endregion
  1092. #endregion
  1093. [XmlIgnore]
  1094. public bool ValidgrpOOB
  1095. {
  1096. set { m_ValidgrpOOB = value; }
  1097. }
  1098. /// <summary>
  1099. /// The position center of the bounding box relative to it's Position
  1100. /// </summary>
  1101. [XmlIgnore]
  1102. public Vector3 OOBoffset
  1103. {
  1104. get
  1105. {
  1106. if (!m_ValidgrpOOB)
  1107. UpdateOOBfromOOBs();
  1108. return m_grpOOBoffset;
  1109. }
  1110. }
  1111. public object ChildrenListLock
  1112. {
  1113. get { return m_partsLock; }
  1114. }
  1115. #region ISceneObject Members
  1116. public event BlankHandler OnFinishedPhysicalRepresentationBuilding;
  1117. public Vector3 LastSignificantPosition
  1118. {
  1119. get { return m_lastSignificantPosition; }
  1120. }
  1121. public UUID LastParcelUUID
  1122. {
  1123. get { return m_lastParcelUUID; }
  1124. set { m_lastParcelUUID = value; }
  1125. }
  1126. /// <summary>
  1127. /// The size of a bounding box oriented as prim, is future will consider cutted prims, meshs etc
  1128. /// </summary>
  1129. [XmlIgnore]
  1130. public Vector3 OOBsize
  1131. {
  1132. get
  1133. {
  1134. if (!m_ValidgrpOOB)
  1135. UpdateOOBfromOOBs();
  1136. return m_grpOOBsize;
  1137. }
  1138. }
  1139. /// <summary>
  1140. /// The square of the radius of a sphere containing the oob
  1141. /// </summary>
  1142. [XmlIgnore]
  1143. public float BSphereRadiusSQ
  1144. {
  1145. get
  1146. {
  1147. if (!m_ValidgrpOOB)
  1148. UpdateOOBfromOOBs();
  1149. return m_grpBSphereRadiusSQ;
  1150. }
  1151. }
  1152. public override bool HasGroupChanged
  1153. {
  1154. get { return m_hasGroupChanged; }
  1155. set
  1156. {
  1157. if (value)
  1158. {
  1159. if (m_scene != null)
  1160. {
  1161. IBackupModule backup = m_scene.RequestModuleInterface<IBackupModule>();
  1162. if (backup != null)
  1163. {
  1164. if (m_isLoaded && !backup.LoadingPrims) //Do NOT add to backup while still loading prims
  1165. backup.AddPrimBackupTaint(this);
  1166. }
  1167. }
  1168. }
  1169. m_hasGroupChanged = value;
  1170. }
  1171. }
  1172. /// <summary>
  1173. /// Force all prims in the scene object to persist
  1174. /// </summary>
  1175. public void ForcePersistence()
  1176. {
  1177. //Force normal backup
  1178. HasGroupChanged = true;
  1179. ForceInventoryPersistence();
  1180. }
  1181. /// <summary>
  1182. /// Clears all undo states from this group
  1183. /// </summary>
  1184. public void ClearUndoState()
  1185. {
  1186. foreach (SceneObjectPart child in ChildrenList)
  1187. {
  1188. child.ClearUndoState();
  1189. }
  1190. }
  1191. ///<value>
  1192. /// Is this scene object acting as an attachment?
  1193. ///
  1194. /// We return false if the group has already been deleted.
  1195. ///
  1196. /// TODO: At the moment set must be done on the part itself. There may be a case for doing it here since I
  1197. /// presume either all or no parts in a linkset can be part of an attachment (in which
  1198. /// case the value would get proprogated down into all the descendent parts).
  1199. ///</value>
  1200. public bool IsAttachment
  1201. {
  1202. get { return m_rootPart.IsAttachment; }
  1203. }
  1204. //private bool m_isBackedUp = false;
  1205. public byte GetAttachmentPoint()
  1206. {
  1207. return m_rootPart.Shape.State;
  1208. }
  1209. public Vector3 GetAttachmentPos()
  1210. {
  1211. return m_rootPart.SavedAttachedPos;
  1212. }
  1213. public byte GetSavedAttachmentPoint()
  1214. {
  1215. return (byte) m_rootPart.SavedAttachmentPoint;
  1216. }
  1217. public void DetachToGround()
  1218. {
  1219. IScenePresence avatar = m_scene.GetScenePresence(m_rootPart.AttachedAvatar);
  1220. if (avatar == null)
  1221. return;
  1222. RootPart.FromUserInventoryItemID = UUID.Zero;
  1223. AbsolutePosition = avatar.AbsolutePosition;
  1224. m_rootPart.AttachedAvatar = UUID.Zero;
  1225. //Anakin Lohner bug #3839
  1226. foreach (SceneObjectPart p in m_partsList)
  1227. {
  1228. p.AttachedAvatar = UUID.Zero;
  1229. }
  1230. m_rootPart.SetParentLocalId(0);
  1231. SetAttachmentPoint(0);
  1232. RebuildPhysicalRepresentation(false);
  1233. HasGroupChanged = true;
  1234. m_ValidgrpOOB = false;
  1235. RootPart.Rezzed = DateTime.UtcNow;
  1236. RootPart.RemFlag(PrimFlags.TemporaryOnRez);
  1237. m_rootPart.ScheduleUpdate(PrimUpdateFlags.ForcedFullUpdate);
  1238. }
  1239. public void DetachToInventoryPrep()
  1240. {
  1241. m_rootPart.AttachedAvatar = UUID.Zero;
  1242. //Anakin Lohner bug #3839
  1243. foreach (SceneObjectPart p in m_partsList)
  1244. {
  1245. p.AttachedAvatar = UUID.Zero;
  1246. }
  1247. m_rootPart.SetParentLocalId(0);
  1248. //m_rootPart.SetAttachmentPoint((byte)0);
  1249. m_rootPart.IsAttachment = false;
  1250. AbsolutePosition = m_rootPart.AttachedPos;
  1251. m_ValidgrpOOB = false;
  1252. //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
  1253. //AttachToBackup();
  1254. //m_rootPart.ScheduleFullUpdate();
  1255. }
  1256. // justincc: I don't believe this hack is needed any longer, especially since the physics
  1257. // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
  1258. // this method was preventing proper reload of scene objects.
  1259. // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects
  1260. // at region startup
  1261. // teravus: After this was removed from the linking algorithm, Linked prims no longer collided
  1262. // properly when non-physical if they havn't been moved. This breaks ALL builds.
  1263. // see: http://opensimulator.org/mantis/view.php?id=3108
  1264. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1265. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1266. // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute
  1267. // Position has been set!
  1268. public void ResetChildPrimPhysicsPositions()
  1269. {
  1270. AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
  1271. // teravus: AbsolutePosition is NOT a normal property!
  1272. // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
  1273. // jhurliman: Then why is it a property instead of two methods?
  1274. }
  1275. public void SetOwnerId(UUID userId)
  1276. {
  1277. ForEachPart(delegate(SceneObjectPart part)
  1278. {
  1279. part.LastOwnerID = part.OwnerID;
  1280. part.OwnerID = userId;
  1281. });
  1282. }
  1283. public float GetMass()
  1284. {
  1285. return RootChild.GetMass();
  1286. }
  1287. /// <summary>
  1288. /// Set the user group to which this scene object belongs.
  1289. /// </summary>
  1290. /// <param name = "GroupID2"></param>
  1291. /// <param name = "client"></param>
  1292. public void SetGroup(UUID GroupID2, UUID attemptingUserID, bool needsUpdate)
  1293. {
  1294. IGroupsModule module = Scene.RequestModuleInterface<IGroupsModule>();
  1295. if (module != null)
  1296. if (!module.GroupPermissionCheck(attemptingUserID, GroupID2, GroupPowers.None))
  1297. return; // No settings to groups you arn't in
  1298. foreach (SceneObjectPart part in m_partsList)
  1299. {
  1300. part.SetGroup(GroupID2);
  1301. part.Inventory.ChangeInventoryGroup(GroupID2);
  1302. }
  1303. HasGroupChanged = true;
  1304. IScenePresence sp = Scene.GetScenePresence(attemptingUserID);
  1305. if (sp != null && needsUpdate)
  1306. GetProperties(sp.ControllingClient);
  1307. }
  1308. public void TriggerScriptChangedEvent(Changed val)
  1309. {
  1310. foreach (SceneObjectPart part in ChildrenList)
  1311. {
  1312. part.TriggerScriptChangedEvent(val);
  1313. }
  1314. }
  1315. public void SetAttachmentPoint(byte point)
  1316. {
  1317. foreach (SceneObjectPart part in m_partsList)
  1318. part.SetAttachmentPoint(point);
  1319. }
  1320. public void FireAttachmentCollisionEvents(EventArgs e)
  1321. {
  1322. CollisionEventUpdate a = (CollisionEventUpdate) e;
  1323. Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
  1324. List<uint> thisHitColliders = new List<uint>();
  1325. List<uint> startedColliders = new List<uint>();
  1326. // calculate things that started colliding this time
  1327. // and build up list of colliders this time
  1328. foreach (uint localid in collissionswith.Keys)
  1329. {
  1330. thisHitColliders.Add(localid);
  1331. if (!m_lastColliders.Contains(localid))
  1332. {
  1333. startedColliders.Add(localid);
  1334. }
  1335. //MainConsole.Instance.Debug("[OBJECT]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
  1336. }
  1337. // calculate things that ended colliding
  1338. #if (!ISWIN)
  1339. List<uint> endedColliders = new List<uint>();
  1340. foreach (uint localId in m_lastColliders)
  1341. {
  1342. if (!thisHitColliders.Contains(localId)) endedColliders.Add(localId);
  1343. }
  1344. #else
  1345. List<uint> endedColliders = m_lastColliders.Where(localID => !thisHitColliders.Contains(localID)).ToList();
  1346. #endif
  1347. //add the items that started colliding this time to the last colliders list.
  1348. foreach (uint localID in startedColliders)
  1349. {
  1350. m_lastColliders.Add(localID);
  1351. }
  1352. // remove things that ended colliding from the last colliders list
  1353. foreach (uint localID in endedColliders)
  1354. {
  1355. m_lastColliders.Remove(localID);
  1356. }
  1357. if (IsDeleted)
  1358. return;
  1359. // play the sound.
  1360. if (startedColliders.Count > 0 && RootPart.CollisionSound != UUID.Zero &&
  1361. RootPart.CollisionSoundVolume > 0.0f)
  1362. {
  1363. RootPart.SendSound(RootPart.CollisionSound.ToString(), RootPart.CollisionSoundVolume, true, 0, 0, false,
  1364. false);
  1365. }
  1366. if (RootPart.CollisionSprite != UUID.Zero && RootPart.CollisionSoundVolume > 0.0f)
  1367. // The collision volume isn't a mistake, its an SL feature/bug
  1368. {
  1369. // TODO: make a sprite!
  1370. }
  1371. if ((RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
  1372. {
  1373. // do event notification
  1374. if (startedColliders.Count > 0)
  1375. {
  1376. ColliderArgs StartCollidingMessage = new ColliderArgs();
  1377. List<DetectedObject> colliding = new List<DetectedObject>();
  1378. foreach (uint localId in startedColliders)
  1379. {
  1380. if (localId != 0)
  1381. {
  1382. if (Scene == null)
  1383. return;
  1384. ISceneChildEntity obj = Scene.GetSceneObjectPart(localId);
  1385. string data = "";
  1386. if (obj != null)
  1387. {
  1388. if (RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(obj.Name))
  1389. {
  1390. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1391. //If it is 1, it is to accept ONLY collisions from this object
  1392. if (found)
  1393. {
  1394. DetectedObject detobj = new DetectedObject
  1395. {
  1396. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1397. };
  1398. colliding.Add(detobj);
  1399. }
  1400. //If it is 0, it is to not accept collisions from this object
  1401. }
  1402. else
  1403. {
  1404. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1405. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1406. if (!found)
  1407. {
  1408. DetectedObject detobj = new DetectedObject
  1409. {
  1410. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1411. };
  1412. colliding.Add(detobj);
  1413. }
  1414. }
  1415. }
  1416. else
  1417. {
  1418. IScenePresence av = Scene.GetScenePresence(localId);
  1419. if (av.LocalId == localId)
  1420. {
  1421. if (RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(av.Name))
  1422. {
  1423. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1424. //If it is 1, it is to accept ONLY collisions from this avatar
  1425. if (found)
  1426. {
  1427. DetectedObject detobj = new DetectedObject
  1428. {
  1429. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1430. };
  1431. colliding.Add(detobj);
  1432. }
  1433. //If it is 0, it is to not accept collisions from this avatar
  1434. }
  1435. else
  1436. {
  1437. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1438. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  1439. if (!found)
  1440. {
  1441. DetectedObject detobj = new DetectedObject
  1442. {
  1443. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1444. };
  1445. colliding.Add(detobj);
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. if (colliding.Count > 0)
  1453. {
  1454. StartCollidingMessage.Colliders = colliding;
  1455. // always running this check because if the user deletes the object it would return a null reference.
  1456. if (Scene == null)
  1457. return;
  1458. Scene.EventManager.TriggerScriptCollidingStart(RootPart, StartCollidingMessage);
  1459. }
  1460. }
  1461. }
  1462. if ((RootPart.ScriptEvents & scriptEvents.collision) != 0)
  1463. {
  1464. if (m_lastColliders.Count > 0)
  1465. {
  1466. ColliderArgs CollidingMessage = new ColliderArgs();
  1467. List<DetectedObject> colliding = new List<DetectedObject>();
  1468. foreach (uint localId in m_lastColliders)
  1469. {
  1470. if (localId != 0)
  1471. {
  1472. if (Scene == null)
  1473. return;
  1474. ISceneChildEntity obj = Scene.GetSceneObjectPart(localId);
  1475. string data = "";
  1476. if (obj != null)
  1477. {
  1478. if (RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(obj.Name))
  1479. {
  1480. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1481. //If it is 1, it is to accept ONLY collisions from this object
  1482. if (found)
  1483. {
  1484. DetectedObject detobj = new DetectedObject
  1485. {
  1486. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1487. };
  1488. colliding.Add(detobj);
  1489. }
  1490. //If it is 0, it is to not accept collisions from this object
  1491. }
  1492. else
  1493. {
  1494. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1495. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1496. if (!found)
  1497. {
  1498. DetectedObject detobj = new DetectedObject
  1499. {
  1500. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1501. };
  1502. colliding.Add(detobj);
  1503. }
  1504. }
  1505. }
  1506. else
  1507. {
  1508. IScenePresence av = Scene.GetScenePresence(localId);
  1509. if (av != null && av.LocalId == localId)
  1510. {
  1511. if (RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(av.Name))
  1512. {
  1513. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1514. //If it is 1, it is to accept ONLY collisions from this avatar
  1515. if (found)
  1516. {
  1517. DetectedObject detobj = new DetectedObject
  1518. {
  1519. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1520. };
  1521. colliding.Add(detobj);
  1522. }
  1523. //If it is 0, it is to not accept collisions from this avatar
  1524. }
  1525. else
  1526. {
  1527. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1528. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  1529. if (!found)
  1530. {
  1531. DetectedObject detobj = new DetectedObject
  1532. {
  1533. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1534. };
  1535. colliding.Add(detobj);
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. if (colliding.Count > 0)
  1543. {
  1544. CollidingMessage.Colliders = colliding;
  1545. if (Scene == null)
  1546. return;
  1547. Scene.EventManager.TriggerScriptColliding(RootPart, CollidingMessage);
  1548. }
  1549. }
  1550. }
  1551. if ((RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
  1552. {
  1553. if (endedColliders.Count > 0)
  1554. {
  1555. ColliderArgs EndCollidingMessage = new ColliderArgs();
  1556. List<DetectedObject> colliding = new List<DetectedObject>();
  1557. foreach (uint localId in endedColliders)
  1558. {
  1559. if (localId != 0)
  1560. {
  1561. // always running this check because if the user deletes the object it would return a null reference.
  1562. if (Scene == null)
  1563. return;
  1564. ISceneChildEntity obj = Scene.GetSceneObjectPart(localId);
  1565. string data = "";
  1566. if (obj != null)
  1567. {
  1568. if (RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(obj.Name))
  1569. {
  1570. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1571. //If it is 1, it is to accept ONLY collisions from this object
  1572. if (found)
  1573. {
  1574. DetectedObject detobj = new DetectedObject
  1575. {
  1576. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1577. };
  1578. colliding.Add(detobj);
  1579. }
  1580. //If it is 0, it is to not accept collisions from this object
  1581. }
  1582. else
  1583. {
  1584. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1585. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1586. if (!found)
  1587. {
  1588. DetectedObject detobj = new DetectedObject
  1589. {
  1590. keyUUID = obj.UUID, nameStr = obj.Name, ownerUUID = obj.OwnerID, posVector = obj.AbsolutePosition, rotQuat = obj.GetWorldRotation(), velVector = obj.Velocity, colliderType = 0, groupUUID = obj.GroupID
  1591. };
  1592. colliding.Add(detobj);
  1593. }
  1594. }
  1595. }
  1596. else
  1597. {
  1598. IScenePresence av = Scene.GetScenePresence(localId);
  1599. if (av != null && av.LocalId == localId)
  1600. {
  1601. if (RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || RootPart.CollisionFilter.ContainsValue(av.Name))
  1602. {
  1603. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1604. //If it is 1, it is to accept ONLY collisions from this avatar
  1605. if (found)
  1606. {
  1607. DetectedObject detobj = new DetectedObject
  1608. {
  1609. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1610. };
  1611. colliding.Add(detobj);
  1612. }
  1613. //If it is 0, it is to not accept collisions from this avatar
  1614. }
  1615. else
  1616. {
  1617. bool found = RootPart.CollisionFilter.TryGetValue(1, out data);
  1618. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  1619. if (!found)
  1620. {
  1621. DetectedObject detobj = new DetectedObject
  1622. {
  1623. keyUUID = av.UUID, nameStr = av.ControllingClient.Name, ownerUUID = av.UUID, posVector = av.AbsolutePosition, rotQuat = av.Rotation, velVector = av.Velocity, colliderType = 0, groupUUID = av.ControllingClient.ActiveGroupId
  1624. };
  1625. colliding.Add(detobj);
  1626. }
  1627. }
  1628. }
  1629. }
  1630. }
  1631. }
  1632. if (colliding.Count > 0)
  1633. {
  1634. EndCollidingMessage.Colliders = colliding;
  1635. if (Scene == null)
  1636. return;
  1637. Scene.EventManager.TriggerScriptCollidingEnd(RootPart, EndCollidingMessage);
  1638. }
  1639. }
  1640. }
  1641. if ((RootPart.ScriptEvents & scriptEvents.land_collision_start) != 0)
  1642. {
  1643. if (startedColliders.Count > 0)
  1644. {
  1645. ColliderArgs LandStartCollidingMessage = new ColliderArgs();
  1646. List<DetectedObject> colliding = (from localId in startedColliders
  1647. where localId == 0
  1648. select new DetectedObject
  1649. {
  1650. keyUUID = UUID.Zero, nameStr = "", ownerUUID = UUID.Zero, posVector = RootPart.AbsolutePosition, rotQuat = Quaternion.Identity, velVector = Vector3.Zero, colliderType = 0, groupUUID = UUID.Zero
  1651. }).ToList();
  1652. if (colliding.Count > 0)
  1653. {
  1654. LandStartCollidingMessage.Colliders = colliding;
  1655. if (Scene == null)
  1656. return;
  1657. Scene.EventManager.TriggerScriptLandCollidingStart(RootPart, LandStartCollidingMessage);
  1658. }
  1659. }
  1660. }
  1661. if ((RootPart.ScriptEvents & scriptEvents.land_collision) != 0)
  1662. {
  1663. if (m_lastColliders.Count > 0)
  1664. {
  1665. ColliderArgs LandCollidingMessage = new ColliderArgs();
  1666. List<DetectedObject> colliding = (from localId in startedColliders
  1667. where localId == 0
  1668. select new DetectedObject
  1669. {
  1670. keyUUID = UUID.Zero, nameStr = "", ownerUUID = UUID.Zero, posVector = RootPart.AbsolutePosition, rotQuat = Quaternion.Identity, velVector = Vector3.Zero, colliderType = 0, groupUUID = UUID.Zero
  1671. }).ToList();
  1672. if (colliding.Count > 0)
  1673. {
  1674. LandCollidingMessage.Colliders = colliding;
  1675. if (Scene == null)
  1676. return;
  1677. Scene.EventManager.TriggerScriptLandColliding(RootPart, LandCollidingMessage);
  1678. }
  1679. }
  1680. }
  1681. if ((RootPart.ScriptEvents & scriptEvents.land_collision_end) != 0)
  1682. {
  1683. if (endedColliders.Count > 0)
  1684. {
  1685. ColliderArgs LandEndCollidingMessage = new ColliderArgs();
  1686. List<DetectedObject> colliding = (from localId in startedColliders
  1687. where localId == 0
  1688. select new DetectedObject
  1689. {
  1690. keyUUID = UUID.Zero, nameStr = "", ownerUUID = UUID.Zero, posVector = RootPart.AbsolutePosition, rotQuat = Quaternion.Identity, velVector = Vector3.Zero, colliderType = 0, groupUUID = UUID.Zero
  1691. }).ToList();
  1692. if (colliding.Count > 0)
  1693. {
  1694. LandEndCollidingMessage.Colliders = colliding;
  1695. // always running this check because if the user deletes the object it would return a null reference.
  1696. if (Scene == null)
  1697. return;
  1698. Scene.EventManager.TriggerScriptLandCollidingEnd(RootPart, LandEndCollidingMessage);
  1699. }
  1700. }
  1701. }
  1702. }
  1703. public ISceneChildEntity RootChild
  1704. {
  1705. get { return m_rootPart; }
  1706. set { m_rootPart = (SceneObjectPart) value; }
  1707. }
  1708. #endregion
  1709. #region ISceneObject
  1710. public virtual string ToXml2()
  1711. {
  1712. return SceneObjectSerializer.ToXml2Format(this);
  1713. }
  1714. public virtual byte[] ToBinaryXml2()
  1715. {
  1716. return SceneObjectSerializer.ToBinaryXml2Format(this);
  1717. }
  1718. public virtual string ExtraToXmlString()
  1719. {
  1720. return "<ExtraFromItemID>" + RootChild.FromUserInventoryItemID + "</ExtraFromItemID>" +
  1721. "<ExtraFromAssetID>" + RootChild.FromUserInventoryAssetID + "</ExtraFromAssetID>";
  1722. }
  1723. public virtual void ExtraFromXmlString(string xmlstr)
  1724. {
  1725. if (xmlstr == "")
  1726. return;
  1727. string id = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromItemID>"));
  1728. id = xmlstr.Replace("<ExtraFromItemID>", "");
  1729. id = id.Replace("</ExtraFromItemID>", "");
  1730. string assetid = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromAssetID>"));
  1731. assetid = xmlstr.Replace("<ExtraFromAssetID>", "");
  1732. assetid = id.Replace("</ExtraFromAssetID>", "");
  1733. UUID uuid = UUID.Zero;
  1734. UUID.TryParse(id, out uuid);
  1735. UUID assetuuid = UUID.Zero;
  1736. UUID.TryParse(assetid, out assetuuid);
  1737. SetFromItemID(uuid, assetuuid);
  1738. }
  1739. #endregion
  1740. public void ClearPartAttachmentData()
  1741. {
  1742. SetAttachmentPoint(0);
  1743. }
  1744. /// <summary>
  1745. /// Set a part to act as the root part for this scene object
  1746. /// </summary>
  1747. /// <param name = "part"></param>
  1748. public void SetRootPart(SceneObjectPart part)
  1749. {
  1750. if (part == null)
  1751. throw new ArgumentNullException("part");
  1752. m_rootPart = part;
  1753. if (!IsAttachment)
  1754. part.SetParentLocalId(0);
  1755. AddChild(part, part.LinkNum);
  1756. }
  1757. public void ObjectGrabHandler(uint localId, Vector3 offsetPos, IClientAPI remoteClient)
  1758. {
  1759. if (m_rootPart.LocalId == localId)
  1760. {
  1761. OnGrabGroup(offsetPos, remoteClient);
  1762. }
  1763. else
  1764. {
  1765. SceneObjectPart part = (SceneObjectPart) GetChildPart(localId);
  1766. OnGrabPart(part, offsetPos, remoteClient);
  1767. }
  1768. }
  1769. public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient)
  1770. {
  1771. part.StoreUndoState();
  1772. part.OnGrab(offsetPos, remoteClient);
  1773. }
  1774. public virtual void OnGrabGroup(Vector3 offsetPos, IClientAPI remoteClient)
  1775. {
  1776. m_scene.EventManager.TriggerGroupGrab(UUID, offsetPos, remoteClient.AgentId);
  1777. }
  1778. public void aggregateScriptEvents()
  1779. {
  1780. PrimFlags objectflagupdate = (PrimFlags) RootPart.GetEffectiveObjectFlags();
  1781. scriptEvents aggregateScriptEvents = 0;
  1782. #if (!ISWIN)
  1783. foreach (SceneObjectPart part in m_partsList)
  1784. {
  1785. if (part != null)
  1786. {
  1787. if (part != RootPart)
  1788. part.Flags = objectflagupdate;
  1789. aggregateScriptEvents |= part.AggregateScriptEvents;
  1790. }
  1791. }
  1792. #else
  1793. foreach (SceneObjectPart part in m_partsList.Where(part => part != null))
  1794. {
  1795. if (part != RootPart)
  1796. part.Flags = objectflagupdate;
  1797. aggregateScriptEvents |= part.AggregateScriptEvents;
  1798. }
  1799. #endif
  1800. m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
  1801. m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
  1802. if (!m_scriptListens_atTarget && !m_scriptListens_notAtTarget)
  1803. {
  1804. lock (m_targets)
  1805. m_targets.Clear();
  1806. RemoveGroupTarget(this);
  1807. }
  1808. m_scriptListens_atRotTarget = ((aggregateScriptEvents & scriptEvents.at_rot_target) != 0);
  1809. m_scriptListens_notAtRotTarget = ((aggregateScriptEvents & scriptEvents.not_at_rot_target) != 0);
  1810. if (!m_scriptListens_atRotTarget && !m_scriptListens_notAtRotTarget)
  1811. {
  1812. lock (m_rotTargets)
  1813. m_rotTargets.Clear();
  1814. RemoveGroupTarget(this);
  1815. }
  1816. ScheduleGroupUpdate(PrimUpdateFlags.PrimFlags);
  1817. }
  1818. public void SetText(string text, Vector3 color, double alpha)
  1819. {
  1820. Color = Color.FromArgb(0xff - (int) (alpha*0xff),
  1821. (int) (color.X*0xff),
  1822. (int) (color.Y*0xff),
  1823. (int) (color.Z*0xff));
  1824. Text = text;
  1825. m_rootPart.ScheduleUpdate(PrimUpdateFlags.Text);
  1826. }
  1827. public void ForEachPart(Action<SceneObjectPart> whatToDo)
  1828. {
  1829. lock (m_partsLock)
  1830. {
  1831. foreach (SceneObjectPart part in m_partsList)
  1832. {
  1833. whatToDo(part);
  1834. }
  1835. }
  1836. }
  1837. internal void SetAxisRotation(int axis, int rotate10)
  1838. {
  1839. const int xaxis = 2;
  1840. const int yaxis = 4;
  1841. const int zaxis = 8;
  1842. if (m_rootPart != null)
  1843. {
  1844. bool setX = ((axis & xaxis) != 0);
  1845. bool setY = ((axis & yaxis) != 0);
  1846. bool setZ = ((axis & zaxis) != 0);
  1847. float setval = (rotate10 > 0) ? 1f : 0f;
  1848. if (setX)
  1849. m_rootPart.RotationAxis.X = setval;
  1850. if (setY)
  1851. m_rootPart.RotationAxis.Y = setval;
  1852. if (setZ)
  1853. m_rootPart.RotationAxis.Z = setval;
  1854. if (setX || setY || setZ)
  1855. {
  1856. m_rootPart.SetPhysicsAxisRotation();
  1857. }
  1858. }
  1859. }
  1860. public int registerRotTargetWaypoint(Quaternion target, float tolerance)
  1861. {
  1862. scriptRotTarget waypoint = new scriptRotTarget {targetRot = target, tolerance = tolerance};
  1863. uint handle = m_scene.SceneGraph.AllocateLocalId();
  1864. waypoint.handle = handle;
  1865. lock (m_rotTargets)
  1866. {
  1867. m_rotTargets.Add(handle, waypoint);
  1868. }
  1869. AddGroupTarget(this);
  1870. return (int) handle;
  1871. }
  1872. public void unregisterRotTargetWaypoint(int handle)
  1873. {
  1874. lock (m_targets)
  1875. {
  1876. m_rotTargets.Remove((uint) handle);
  1877. if (m_targets.Count == 0)
  1878. RemoveGroupTarget(this);
  1879. }
  1880. }
  1881. public int registerTargetWaypoint(Vector3 target, float tolerance)
  1882. {
  1883. scriptPosTarget waypoint = new scriptPosTarget {targetPos = target, tolerance = tolerance};
  1884. uint handle = m_scene.SceneGraph.AllocateLocalId();
  1885. waypoint.handle = handle;
  1886. lock (m_targets)
  1887. {
  1888. m_targets.Add(handle, waypoint);
  1889. }
  1890. AddGroupTarget(this);
  1891. return (int) handle;
  1892. }
  1893. public void unregisterTargetWaypoint(int handle)
  1894. {
  1895. lock (m_targets)
  1896. {
  1897. m_targets.Remove((uint) handle);
  1898. if (m_targets.Count == 0)
  1899. RemoveGroupTarget(this);
  1900. }
  1901. }
  1902. public void AddGroupTarget(SceneObjectGroup grp)
  1903. {
  1904. m_scene.EventManager.OnFrame += checkAtTargets;
  1905. }
  1906. public void RemoveGroupTarget(SceneObjectGroup grp)
  1907. {
  1908. m_scene.EventManager.OnFrame -= checkAtTargets;
  1909. }
  1910. public void AddKeyframedMotion(KeyframeAnimation animation, KeyframeAnimation.Commands command)
  1911. {
  1912. if (command == KeyframeAnimation.Commands.Play)
  1913. {
  1914. KeyframeAnimation = animation;
  1915. m_scene.EventManager.OnFrame += moveKeyframeMotion;
  1916. }
  1917. else
  1918. {
  1919. m_scene.EventManager.OnFrame -= moveKeyframeMotion;
  1920. if (command == KeyframeAnimation.Commands.Stop)
  1921. KeyframeAnimation = null;
  1922. }
  1923. }
  1924. public void moveKeyframeMotion()
  1925. {
  1926. if (m_KeyframeAnimation == null || m_KeyframeAnimation.TimeList.Length == 0)
  1927. {
  1928. m_scene.EventManager.OnFrame -= moveKeyframeMotion;
  1929. return;
  1930. }
  1931. try
  1932. {
  1933. int currentTime = m_KeyframeAnimation.TimeList[m_KeyframeAnimation.CurrentAnimationPosition];
  1934. float timeAmt = (1f / (float)currentTime);
  1935. Vector3 currentTarget = m_KeyframeAnimation.PositionList.Length == 0 ? Vector3.Zero :
  1936. m_KeyframeAnimation.PositionList[m_KeyframeAnimation.CurrentAnimationPosition];
  1937. Quaternion target = m_KeyframeAnimation.RotationList.Length == 0 ? Quaternion.Identity :
  1938. m_KeyframeAnimation.RotationList[m_KeyframeAnimation.CurrentAnimationPosition];
  1939. m_KeyframeAnimation.CurrentFrame++; //Add one to the current frame so that we know when to stops
  1940. bool AllDoneMoving = false;
  1941. bool MadeItToCheckpoint = false;
  1942. if (m_KeyframeAnimation.CurrentFrame == currentTime)
  1943. {
  1944. if (m_KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Forward)
  1945. {
  1946. m_KeyframeAnimation.CurrentAnimationPosition += 1;
  1947. if (m_KeyframeAnimation.CurrentAnimationPosition == m_KeyframeAnimation.TimeList.Length)
  1948. {
  1949. //All done moving...
  1950. AllDoneMoving = true;
  1951. m_scene.EventManager.OnFrame -= moveKeyframeMotion;
  1952. }
  1953. }
  1954. else if (m_KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Reverse)
  1955. {
  1956. m_KeyframeAnimation.CurrentAnimationPosition -= 1;
  1957. if (m_KeyframeAnimation.CurrentAnimationPosition < 0)
  1958. {
  1959. //All done moving...
  1960. AllDoneMoving = true;
  1961. m_scene.EventManager.OnFrame -= moveKeyframeMotion;
  1962. }
  1963. }
  1964. else if (m_KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.Loop)
  1965. {
  1966. m_KeyframeAnimation.CurrentAnimationPosition += 1;
  1967. if (m_KeyframeAnimation.CurrentAnimationPosition == m_KeyframeAnimation.TimeList.Length)
  1968. m_KeyframeAnimation.CurrentAnimationPosition = 0;
  1969. }
  1970. else if (m_KeyframeAnimation.CurrentMode == KeyframeAnimation.Modes.PingPong)
  1971. {
  1972. if (m_KeyframeAnimation.PingPongForwardMotion)
  1973. {
  1974. m_KeyframeAnimation.CurrentAnimationPosition += 1;
  1975. if (m_KeyframeAnimation.CurrentAnimationPosition == m_KeyframeAnimation.TimeList.Length)
  1976. {
  1977. m_KeyframeAnimation.PingPongForwardMotion = !m_KeyframeAnimation.PingPongForwardMotion;
  1978. m_KeyframeAnimation.CurrentAnimationPosition -= 2;
  1979. }
  1980. }
  1981. else
  1982. {
  1983. m_KeyframeAnimation.CurrentAnimationPosition -= 1;
  1984. if (m_KeyframeAnimation.CurrentAnimationPosition < 0)
  1985. {
  1986. m_KeyframeAnimation.PingPongForwardMotion = !m_KeyframeAnimation.PingPongForwardMotion;
  1987. m_KeyframeAnimation.CurrentAnimationPosition += 2;
  1988. }
  1989. }
  1990. }
  1991. m_KeyframeAnimation.CurrentFrame = 0;
  1992. MadeItToCheckpoint = true;
  1993. }
  1994. if (m_KeyframeAnimation.PositionList.Length != 0)
  1995. {
  1996. Vector3 _target_velocity =
  1997. new Vector3(
  1998. (currentTarget.X - m_KeyframeAnimation.InitialPosition.X) * timeAmt,
  1999. (currentTarget.Y - m_KeyframeAnimation.InitialPosition.Y) * timeAmt,
  2000. (currentTarget.Z - m_KeyframeAnimation.InitialPosition.Z) * timeAmt
  2001. );
  2002. if (MadeItToCheckpoint)
  2003. {
  2004. if(AllDoneMoving)
  2005. Velocity = Vector3.Zero;
  2006. SetAbsolutePosition(true, currentTarget);
  2007. m_KeyframeAnimation.InitialPosition = currentTarget;
  2008. }
  2009. else
  2010. {
  2011. SetAbsolutePosition(true, m_rootPart.AbsolutePosition + _target_velocity);
  2012. m_rootPart.Velocity = _target_velocity / 45f;
  2013. }
  2014. }
  2015. if (m_KeyframeAnimation.RotationList.Length != 0)
  2016. {
  2017. Quaternion source = m_rootPart.RotationOffset;
  2018. Quaternion newInterpolation = Quaternion.Slerp(source, target, 1f / ((float)currentTime - (float)m_KeyframeAnimation.CurrentFrame));
  2019. m_rootPart.UpdateRotation(newInterpolation);
  2020. if (MadeItToCheckpoint)
  2021. {
  2022. //Force set it to the right position, just to be sure
  2023. m_rootPart.UpdateRotation(target);
  2024. m_KeyframeAnimation.InitialRotation = target;
  2025. }
  2026. }
  2027. }
  2028. catch
  2029. {
  2030. m_scene.EventManager.OnFrame -= moveKeyframeMotion;
  2031. }
  2032. ScheduleGroupTerseUpdate();
  2033. }
  2034. public void checkAtTargets()
  2035. {
  2036. if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
  2037. {
  2038. if (m_targets.Count > 0)
  2039. {
  2040. bool at_target = false;
  2041. //Vector3 targetPos;
  2042. //uint targetHandle;
  2043. Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
  2044. lock (m_targets)
  2045. {
  2046. foreach (uint idx in m_targets.Keys)
  2047. {
  2048. scriptPosTarget target = m_targets[idx];
  2049. if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
  2050. {
  2051. // trigger at_target
  2052. if (m_scriptListens_atTarget)
  2053. {
  2054. at_target = true;
  2055. scriptPosTarget att = new scriptPosTarget
  2056. {
  2057. targetPos = target.targetPos,
  2058. tolerance = target.tolerance,
  2059. handle = target.handle
  2060. };
  2061. atTargets.Add(idx, att);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. if (atTargets.Count > 0)
  2067. {
  2068. uint[] localids = new uint[0];
  2069. localids = new uint[m_parts.Count];
  2070. int cntr = 0;
  2071. foreach (SceneObjectPart part in m_partsList)
  2072. {
  2073. localids[cntr] = part.LocalId;
  2074. cntr++;
  2075. }
  2076. foreach (uint t in localids)
  2077. {
  2078. foreach(scriptPosTarget att in atTargets.Values)
  2079. {
  2080. m_scene.EventManager.TriggerAtTargetEvent(
  2081. t, att.handle, att.targetPos, m_rootPart.GroupPosition);
  2082. }
  2083. }
  2084. return;
  2085. }
  2086. if (m_scriptListens_notAtTarget && !at_target)
  2087. {
  2088. //trigger not_at_target
  2089. uint[] localids = new uint[0];
  2090. localids = new uint[m_parts.Count];
  2091. int cntr = 0;
  2092. foreach (SceneObjectPart part in m_partsList)
  2093. {
  2094. localids[cntr] = part.LocalId;
  2095. cntr++;
  2096. }
  2097. foreach (uint t in localids)
  2098. {
  2099. m_scene.EventManager.TriggerNotAtTargetEvent(t);
  2100. }
  2101. }
  2102. }
  2103. }
  2104. if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
  2105. {
  2106. if (m_rotTargets.Count > 0)
  2107. {
  2108. bool at_Rottarget = false;
  2109. Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
  2110. lock (m_rotTargets)
  2111. {
  2112. foreach (uint idx in m_rotTargets.Keys)
  2113. {
  2114. scriptRotTarget target = m_rotTargets[idx];
  2115. double angle =
  2116. Math.Acos(target.targetRot.X*m_rootPart.RotationOffset.X +
  2117. target.targetRot.Y*m_rootPart.RotationOffset.Y +
  2118. target.targetRot.Z*m_rootPart.RotationOffset.Z +
  2119. target.targetRot.W*m_rootPart.RotationOffset.W)*2;
  2120. if (angle < 0) angle = -angle;
  2121. if (angle > Math.PI) angle = (Math.PI*2 - angle);
  2122. if (angle <= target.tolerance)
  2123. {
  2124. // trigger at_rot_target
  2125. if (m_scriptListens_atRotTarget)
  2126. {
  2127. at_Rottarget = true;
  2128. scriptRotTarget att = new scriptRotTarget
  2129. {
  2130. targetRot = target.targetRot,
  2131. tolerance = target.tolerance,
  2132. handle = target.handle
  2133. };
  2134. atRotTargets.Add(idx, att);
  2135. }
  2136. }
  2137. }
  2138. }
  2139. if (atRotTargets.Count > 0)
  2140. {
  2141. uint[] localids = new uint[0];
  2142. localids = new uint[m_parts.Count];
  2143. int cntr = 0;
  2144. foreach (SceneObjectPart part in m_partsList)
  2145. {
  2146. localids[cntr] = part.LocalId;
  2147. cntr++;
  2148. }
  2149. foreach (uint t in localids)
  2150. {
  2151. foreach (scriptRotTarget att in atRotTargets.Values)
  2152. {
  2153. m_scene.EventManager.TriggerAtRotTargetEvent(
  2154. t, att.handle, att.targetRot, m_rootPart.RotationOffset);
  2155. }
  2156. }
  2157. return;
  2158. }
  2159. if (m_scriptListens_notAtRotTarget && !at_Rottarget)
  2160. {
  2161. //trigger not_at_target
  2162. uint[] localids = new uint[0];
  2163. localids = new uint[m_parts.Count];
  2164. int cntr = 0;
  2165. foreach (SceneObjectPart part in m_partsList)
  2166. {
  2167. localids[cntr] = part.LocalId;
  2168. cntr++;
  2169. }
  2170. foreach (uint t in localids)
  2171. {
  2172. m_scene.EventManager.TriggerNotAtRotTargetEvent(t);
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. public void CheckSculptAndLoad()
  2179. {
  2180. foreach (SceneObjectPart part in m_partsList)
  2181. {
  2182. if (part.Shape == null)
  2183. continue;
  2184. if (!(RootPart.PhysicsType == (byte) PhysicsShapeType.None ||
  2185. part.PhysicsType == (byte) PhysicsShapeType.None ||
  2186. ((part.Flags & PrimFlags.Phantom) == PrimFlags.Phantom &&
  2187. !part.VolumeDetectActive) ||
  2188. ((RootPart.Flags & PrimFlags.Phantom) == PrimFlags.Phantom &&
  2189. !RootPart.VolumeDetectActive)))
  2190. {
  2191. if (part.Shape.SculptEntry && part.Shape.SculptTexture != UUID.Zero)
  2192. {
  2193. // If no sculpt data exists, we need to get the data
  2194. m_scene.AssetService.Get(part.Shape.SculptTexture.ToString(), true, part.AssetReceived);
  2195. //In the mean time...
  2196. //part.Shape.SculptEntry = false;
  2197. part.Shape.SculptData = new byte[0];
  2198. }
  2199. }
  2200. }
  2201. }
  2202. public void GeneratedMesh(ISceneChildEntity part, IMesh mesh)
  2203. {
  2204. //This destroys the mesh if it is added... this needs added in a way that won't corrupt the mesh
  2205. /*if (part.Shape.SculptType == (byte)SculptType.Mesh && !mesh.WasCached)//If it was cached, we don't want to resave it
  2206. {
  2207. //We can cache meshes into the mesh itself, saving time generating it next time around
  2208. OSDMap meshOsd = (OSDMap)OSDParser.DeserializeLLSDBinary(part.Shape.SculptData);
  2209. meshOsd["physics_cached"] = new OSDMap();
  2210. mesh.Serialize();
  2211. mesh.WasCached = true;
  2212. UUID newSculptTexture;
  2213. if (m_scene.AssetService.UpdateContent(part.Shape.SculptTexture,
  2214. OSDParser.SerializeLLSDBinary(meshOsd), out newSculptTexture))
  2215. {
  2216. part.Shape.SculptTexture = newSculptTexture;
  2217. HasGroupChanged = true;
  2218. }
  2219. }*/
  2220. }
  2221. public void TriggerScriptMovingStartEvent()
  2222. {
  2223. foreach (SceneObjectPart part in ChildrenList)
  2224. {
  2225. part.TriggerScriptMovingStartEvent();
  2226. }
  2227. }
  2228. public void TriggerScriptMovingEndEvent()
  2229. {
  2230. foreach (SceneObjectPart part in ChildrenList)
  2231. {
  2232. part.TriggerScriptMovingEndEvent();
  2233. }
  2234. }
  2235. public override string ToString()
  2236. {
  2237. return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
  2238. }
  2239. #region Copying
  2240. /// <summary>
  2241. /// Make an exact copy of this group.
  2242. /// This does NOT reset any UUIDs, localIDs, or anything, as this is an EXACT copy.
  2243. /// </summary>
  2244. /// <returns></returns>
  2245. public ISceneEntity Copy(bool clonePhys)
  2246. {
  2247. SceneObjectGroup dupe = (SceneObjectGroup) MemberwiseClone();
  2248. //Block attempts to persist to the DB
  2249. dupe.m_isLoaded = false;
  2250. dupe.m_parts = new Dictionary<UUID, SceneObjectPart>();
  2251. dupe.m_partsList = new List<SceneObjectPart>();
  2252. dupe.m_scene = Scene;
  2253. // Warning, The following code related to previousAttachmentStatus is needed so that clones of
  2254. // attachments do not bordercross while they're being duplicated. This is hacktastic!
  2255. // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region!
  2256. // unless IsAttachment is true!, so to prevent border crossing, we save it's attachment state
  2257. // (which should be false anyway) set it as an Attachment and then set it's Absolute Position,
  2258. // then restore it's attachment state
  2259. // This is only necessary when userExposed is false!
  2260. dupe.ClearChildren();
  2261. dupe.AddChild(m_rootPart.Copy(dupe, clonePhys), m_rootPart.LinkNum);
  2262. bool previousAttachmentStatus = dupe.RootPart.IsAttachment;
  2263. dupe.RootPart.IsAttachment = true;
  2264. dupe.AbsolutePosition = AbsolutePosition;
  2265. dupe.RootPart.IsAttachment = previousAttachmentStatus;
  2266. dupe.m_rootPart.TrimPermissions();
  2267. List<SceneObjectPart> partList = new List<SceneObjectPart>();
  2268. lock (m_partsLock)
  2269. {
  2270. partList.AddRange(m_partsList);
  2271. }
  2272. //Sort the list by link number so that we get them in the right order
  2273. partList.Sort(Scene.SceneGraph.LinkSetSorter);
  2274. foreach (SceneObjectPart part in partList)
  2275. {
  2276. if (part.UUID != m_rootPart.UUID)
  2277. {
  2278. SceneObjectPart copy = part.Copy(dupe, clonePhys);
  2279. copy.LinkNum = part.LinkNum;
  2280. dupe.LinkChild(copy);
  2281. }
  2282. }
  2283. dupe.m_ValidgrpOOB = false;
  2284. //Reset the loaded setting
  2285. dupe.m_isLoaded = true;
  2286. return dupe;
  2287. }
  2288. /// <summary>
  2289. /// Rebuild the physical representation of all the prims.
  2290. /// This is used after copying the prim so that all of the object is readded to the physics scene.
  2291. /// </summary>
  2292. public void RebuildPhysicalRepresentation(bool keepSelectedStatuses)
  2293. {
  2294. // long lock or array copy? in this case lets try array
  2295. SceneObjectPart[] parts;
  2296. SceneObjectPart part;
  2297. int i;
  2298. lock (m_partsLock)
  2299. parts = m_partsList.ToArray();
  2300. if (RootPart.PhysActor != null)
  2301. RootPart.PhysActor.BlockPhysicalReconstruction = true;
  2302. for (i = 0; i < parts.Length; i++)
  2303. {
  2304. part = parts[i];
  2305. // PhysicsObject oldActor = part.PhysActor;
  2306. // PrimitiveBaseShape pbs = part.Shape;
  2307. if (part.PhysActor != null)
  2308. {
  2309. part.PhysActor.RotationalVelocity = Vector3.Zero;
  2310. part.m_hasSubscribedToCollisionEvent = false;
  2311. part.PhysActor.OnCollisionUpdate -= part.PhysicsCollision;
  2312. part.PhysActor.OnRequestTerseUpdate -= part.PhysicsRequestingTerseUpdate;
  2313. part.PhysActor.OnSignificantMovement -= part.ParentGroup.CheckForSignificantMovement;
  2314. part.PhysActor.OnOutOfBounds -= part.PhysicsOutOfBounds;
  2315. //part.PhysActor.delink ();
  2316. //Remove the old one so that we don't have more than we should,
  2317. // as when we copy, it readds it to the PhysicsScene somehow
  2318. //if (part.IsRoot)//The root removes all children
  2319. m_scene.PhysicsScene.RemovePrim(part.PhysActor);
  2320. part.FireOnRemovedPhysics();
  2321. part.PhysActor = null;
  2322. }
  2323. //Reset any old data that we have
  2324. part.Velocity = Vector3.Zero;
  2325. part.AngularVelocity = Vector3.Zero;
  2326. part.Acceleration = Vector3.Zero;
  2327. part.GenerateRotationalVelocityFromOmega();
  2328. }
  2329. //Check for meshes and stuff
  2330. CheckSculptAndLoad();
  2331. // check root part setting that make the entire object not having physics rep
  2332. if (RootPart.PhysicsType == (byte) PhysicsShapeType.None ||
  2333. ((RootPart.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !RootPart.VolumeDetectActive))
  2334. {
  2335. Scene.AuroraEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this);
  2336. if (OnFinishedPhysicalRepresentationBuilding != null)
  2337. OnFinishedPhysicalRepresentationBuilding();
  2338. OnFinishedPhysicalRepresentationBuilding = null;
  2339. return;
  2340. }
  2341. // create the root part
  2342. RootPart.PhysActor = m_scene.PhysicsScene.AddPrimShape(RootPart);
  2343. if (RootPart.PhysActor == null)
  2344. return;
  2345. // RootPart.PhysActor.BuildingRepresentation = true;
  2346. RootPart.PhysActor.BlockPhysicalReconstruction = true;
  2347. //Don't let it rebuild it until we have all the links done
  2348. //Fix the localID!
  2349. RootPart.PhysActor.LocalID = RootPart.LocalId;
  2350. RootPart.PhysActor.UUID = RootPart.UUID;
  2351. RootPart.PhysActor.VolumeDetect = RootPart.VolumeDetectActive;
  2352. //Force deselection here so that it isn't stuck forever
  2353. RootPart.PhysActor.Selected = keepSelectedStatuses && RootPart.IsSelected;
  2354. RootPart.PhysActor.SetMaterial(RootPart.Material, false);
  2355. // bool rootIsPhysical;
  2356. if ((RootPart.Flags & PrimFlags.Physics) == PrimFlags.Physics)
  2357. {
  2358. // rootIsPhysical = true;
  2359. RootPart.PhysActor.IsPhysical = true;
  2360. }
  2361. // else
  2362. // rootIsPhysical = false;
  2363. //Add collision updates
  2364. //part.PhysActor.OnCollisionUpdate += RootPart.PhysicsCollision;
  2365. RootPart.PhysActor.OnRequestTerseUpdate += RootPart.PhysicsRequestingTerseUpdate;
  2366. RootPart.PhysActor.OnSignificantMovement += RootPart.ParentGroup.CheckForSignificantMovement;
  2367. RootPart.PhysActor.OnOutOfBounds += RootPart.PhysicsOutOfBounds;
  2368. RootPart.FireOnAddedPhysics();
  2369. RootPart.aggregateScriptEvents();
  2370. for (i = 0; i < parts.Length; i++)
  2371. {
  2372. part = parts[i];
  2373. if (part == RootPart ||
  2374. part.PhysicsType == (byte) PhysicsShapeType.None ||
  2375. ((part.Flags & PrimFlags.Phantom) == PrimFlags.Phantom && !part.VolumeDetectActive))
  2376. {
  2377. continue; // ignore phantom prims
  2378. }
  2379. //Now read the physics actor to the physics scene
  2380. part.PhysActor = m_scene.PhysicsScene.AddPrimShape(part);
  2381. if (part.PhysActor == null)
  2382. continue;
  2383. // part.PhysActor.BuildingRepresentation = true;
  2384. // if(part.IsRoot)
  2385. part.PhysActor.BlockPhysicalReconstruction = true;
  2386. //Don't let it rebuild it until we have all the links done
  2387. //Fix the localID!
  2388. part.PhysActor.LocalID = part.LocalId;
  2389. part.PhysActor.UUID = part.UUID;
  2390. part.PhysActor.VolumeDetect = part.VolumeDetectActive;
  2391. //Force deselection here so that it isn't stuck forever
  2392. part.PhysActor.Selected = keepSelectedStatuses && part.IsSelected;
  2393. part.PhysActor.SetMaterial(part.Material, false);
  2394. if ((part.Flags & PrimFlags.Physics) == PrimFlags.Physics)
  2395. part.PhysActor.IsPhysical = true;
  2396. //Add collision updates
  2397. //part.PhysActor.OnCollisionUpdate += part.PhysicsCollision;
  2398. part.PhysActor.OnRequestTerseUpdate += part.PhysicsRequestingTerseUpdate;
  2399. part.PhysActor.OnSignificantMovement += part.ParentGroup.CheckForSignificantMovement;
  2400. part.PhysActor.OnOutOfBounds += part.PhysicsOutOfBounds;
  2401. part.FireOnAddedPhysics();
  2402. part.aggregateScriptEvents();
  2403. //Link the prim then
  2404. // if(rootIsPhysical)
  2405. part.PhysActor.link(RootPart.PhysActor);
  2406. }
  2407. Scene.AuroraEventManager.FireGenericEventHandler("ObjectChangedPhysicalStatus", this);
  2408. RootPart.PhysActor.BlockPhysicalReconstruction = false; // this sets children also (in AODE at least)
  2409. // RootPart.PhysActor.BuildingRepresentation = false;
  2410. FixVehicleParams(RootPart);
  2411. if (OnFinishedPhysicalRepresentationBuilding != null)
  2412. OnFinishedPhysicalRepresentationBuilding();
  2413. OnFinishedPhysicalRepresentationBuilding = null;
  2414. }
  2415. /*
  2416. lock (m_partsLock)
  2417. {
  2418. foreach (SceneObjectPart part in m_partsList)
  2419. {
  2420. PhysicsObject oldActor = part.PhysActor;
  2421. PrimitiveBaseShape pbs = part.Shape;
  2422. //Reset any old data that we have
  2423. part.Velocity = Vector3.Zero;
  2424. part.Acceleration = Vector3.Zero;
  2425. if (part.PhysActor != null)
  2426. {
  2427. part.PhysActor.RotationalVelocity = Vector3.Zero;
  2428. part.PhysActor.UnSubscribeEvents ();
  2429. part.m_hasSubscribedToCollisionEvent = false;
  2430. part.PhysActor.OnCollisionUpdate -= part.PhysicsCollision;
  2431. part.PhysActor.OnRequestTerseUpdate -= part.PhysicsRequestingTerseUpdate;
  2432. part.PhysActor.OnSignificantMovement -= part.ParentGroup.CheckForSignificantMovement;
  2433. part.PhysActor.OnOutOfBounds -= part.PhysicsOutOfBounds;
  2434. //part.PhysActor.delink ();
  2435. //Remove the old one so that we don't have more than we should,
  2436. // as when we copy, it readds it to the PhysicsScene somehow
  2437. //if (part.IsRoot)//The root removes all children
  2438. m_scene.PhysicsScene.RemovePrim (part.PhysActor);
  2439. part.FireOnRemovedPhysics ();
  2440. }
  2441. part.AngularVelocity = Vector3.Zero;
  2442. part.GenerateRotationalVelocityFromOmega ();
  2443. }
  2444. }
  2445. //Check for meshes and stuff
  2446. CheckSculptAndLoad ();
  2447. //This is a heavy operation... it is really bad to lock this, but if we don't, we could have multiple threads in here... which would be baaad
  2448. lock (m_partsLock)
  2449. {
  2450. foreach (SceneObjectPart part in m_partsList)
  2451. {
  2452. if (RootPart.PhysicsType == (byte)PhysicsShapeType.None ||
  2453. part.PhysicsType == (byte)PhysicsShapeType.None ||
  2454. ((part.Flags & PrimFlags.Phantom) == PrimFlags.Phantom &&
  2455. !part.VolumeDetectActive) ||
  2456. ((RootPart.Flags & PrimFlags.Phantom) == PrimFlags.Phantom &&
  2457. !RootPart.VolumeDetectActive))
  2458. {
  2459. part.PhysActor = null;
  2460. continue; //Don't rebuild! All phantom if the root is phantom
  2461. }
  2462. //Now readd the physics actor to the physics scene
  2463. part.PhysActor = m_scene.PhysicsScene.AddPrimShape (part);
  2464. // part.PhysActor.BuildingRepresentation = true;
  2465. // if(part.IsRoot)
  2466. // part.PhysActor.BlockPhysicalReconstruction = true;//Don't let it rebuild it until we have all the links done
  2467. //Fix the localID!
  2468. part.PhysActor.LocalID = part.LocalId;
  2469. part.PhysActor.UUID = part.UUID;
  2470. part.PhysActor.VolumeDetect = part.VolumeDetectActive;
  2471. //Force deselection here so that it isn't stuck forever
  2472. if (!keepSelectedStatuses)
  2473. part.PhysActor.Selected = false;
  2474. else
  2475. part.PhysActor.Selected = part.IsSelected;
  2476. part.PhysActor.SetMaterial (part.Material, false);
  2477. //Add collision updates
  2478. //part.PhysActor.OnCollisionUpdate += part.PhysicsCollision;
  2479. part.PhysActor.OnRequestTerseUpdate += part.PhysicsRequestingTerseUpdate;
  2480. part.PhysActor.OnSignificantMovement += part.ParentGroup.CheckForSignificantMovement;
  2481. part.PhysActor.OnOutOfBounds += part.PhysicsOutOfBounds;
  2482. part.FireOnAddedPhysics ();
  2483. part.aggregateScriptEvents ();
  2484. }
  2485. Scene.AuroraEventManager.FireGenericEventHandler ("ObjectChangedPhysicalStatus", this);
  2486. }
  2487. lock (m_partsLock)
  2488. {
  2489. foreach (SceneObjectPart part in m_partsList)
  2490. {
  2491. if (!part.IsRoot && RootPart.PhysActor != null && part.PhysActor != null)//Link the prim then
  2492. part.PhysActor.link (RootPart.PhysActor);
  2493. }
  2494. foreach (SceneObjectPart part in m_partsList)
  2495. {
  2496. if (part.PhysActor != null)
  2497. {
  2498. FixVehicleParams(part);
  2499. // *
  2500. if(part.IsRoot)
  2501. {
  2502. //All done linking, build the body
  2503. part.PhysActor.BlockPhysicalReconstruction = false;
  2504. }
  2505. part.PhysActor.BuildingRepresentation = false;
  2506. // *
  2507. }
  2508. }
  2509. if(OnFinishedPhysicalRepresentationBuilding != null)
  2510. OnFinishedPhysicalRepresentationBuilding();
  2511. }
  2512. }
  2513. */
  2514. /// <summary>
  2515. /// Fix all the vehicle params after rebuilding the representation
  2516. /// </summary>
  2517. /// <param name = "part"></param>
  2518. private void FixVehicleParams(SceneObjectPart part)
  2519. {
  2520. part.PhysActor.VehicleType = part.VehicleType;
  2521. // OSD o = part.GetComponentState("VehicleParameters");
  2522. foreach (OSD param in part.VehicleFlags)
  2523. {
  2524. part.PhysActor.VehicleFlags(param.AsInteger(), false);
  2525. }
  2526. foreach (KeyValuePair<string, OSD> param in part.VehicleParameters)
  2527. {
  2528. if (param.Value.Type == OSDType.Real)
  2529. part.PhysActor.VehicleFloatParam(int.Parse(param.Key), (float) param.Value.AsReal());
  2530. else if (param.Value.Type == OSDType.Array)
  2531. {
  2532. OSDArray a = (OSDArray) param.Value;
  2533. if (a.Count == 3)
  2534. part.PhysActor.VehicleVectorParam(int.Parse(param.Key), param.Value.AsVector3());
  2535. else
  2536. part.PhysActor.VehicleRotationParam(int.Parse(param.Key), param.Value.AsQuaternion());
  2537. }
  2538. }
  2539. }
  2540. #endregion
  2541. #region Script methods
  2542. public Vector3 GetTorque()
  2543. {
  2544. // We check if rootpart is null here because scripts don't delete if you delete the host.
  2545. // This means that unfortunately, we can pass a null physics actor to Simulate!
  2546. // Make sure we don't do that!
  2547. SceneObjectPart rootpart = m_rootPart;
  2548. if (rootpart != null)
  2549. {
  2550. if (rootpart.PhysActor != null)
  2551. {
  2552. if (!IsAttachment)
  2553. {
  2554. Vector3 torque = rootpart.PhysActor.Torque;
  2555. return torque;
  2556. }
  2557. }
  2558. }
  2559. return Vector3.Zero;
  2560. }
  2561. /// <summary>
  2562. /// Set the owner of the root part.
  2563. /// </summary>
  2564. /// <param name = "part"></param>
  2565. /// <param name = "cAgentID"></param>
  2566. /// <param name = "cGroupID"></param>
  2567. public void SetRootPartOwner(ISceneChildEntity part, UUID cAgentID, UUID cGroupID)
  2568. {
  2569. part.LastOwnerID = part.OwnerID;
  2570. part.OwnerID = cAgentID;
  2571. part.GroupID = cGroupID;
  2572. if (part.OwnerID != cAgentID)
  2573. {
  2574. // Apply Next Owner Permissions if we're not bypassing permissions
  2575. if (!m_scene.Permissions.BypassPermissions())
  2576. ApplyNextOwnerPermissions();
  2577. }
  2578. part.ScheduleUpdate(PrimUpdateFlags.ForcedFullUpdate);
  2579. }
  2580. public void ScriptSetPhysicsStatus(bool UsePhysics)
  2581. {
  2582. bool IsTemporary = ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0);
  2583. bool IsPhantom = ((RootPart.Flags & PrimFlags.Phantom) != 0);
  2584. bool IsVolumeDetect = RootPart.VolumeDetectActive;
  2585. UpdatePrimFlags(RootPart.LocalId, UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect, null);
  2586. }
  2587. public void ScriptSetTemporaryStatus(bool TemporaryStatus)
  2588. {
  2589. bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
  2590. bool IsPhantom = ((RootPart.Flags & PrimFlags.Phantom) != 0);
  2591. bool IsVolumeDetect = RootPart.VolumeDetectActive;
  2592. UpdatePrimFlags(RootPart.LocalId, UsePhysics, TemporaryStatus, IsPhantom, IsVolumeDetect, null);
  2593. }
  2594. public void ScriptSetPhantomStatus(bool PhantomStatus)
  2595. {
  2596. bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
  2597. bool IsTemporary = ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0);
  2598. bool IsVolumeDetect = RootPart.VolumeDetectActive;
  2599. UpdatePrimFlags(RootPart.LocalId, UsePhysics, IsTemporary, PhantomStatus, IsVolumeDetect, null);
  2600. }
  2601. public void ScriptSetVolumeDetect(bool VDStatus)
  2602. {
  2603. bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
  2604. bool IsTemporary = ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0);
  2605. bool IsPhantom = ((RootPart.Flags & PrimFlags.Phantom) != 0);
  2606. UpdatePrimFlags(RootPart.LocalId, UsePhysics, IsTemporary, IsPhantom, VDStatus, null);
  2607. }
  2608. public void applyImpulse(Vector3 impulse)
  2609. {
  2610. // We check if rootpart is null here because scripts don't delete if you delete the host.
  2611. // This means that unfortunately, we can pass a null physics actor to Simulate!
  2612. // Make sure we don't do that!
  2613. SceneObjectPart rootpart = m_rootPart;
  2614. if (rootpart != null)
  2615. {
  2616. if (IsAttachment)
  2617. {
  2618. IScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
  2619. if (avatar != null)
  2620. {
  2621. avatar.PushForce(impulse);
  2622. }
  2623. }
  2624. else
  2625. {
  2626. if (rootpart.PhysActor != null)
  2627. rootpart.PhysActor.AddForce(impulse, true);
  2628. }
  2629. }
  2630. }
  2631. public void applyAngularImpulse(Vector3 impulse)
  2632. {
  2633. // We check if rootpart is null here because scripts don't delete if you delete the host.
  2634. // This means that unfortunately, we can pass a null physics actor to Simulate!
  2635. // Make sure we don't do that!
  2636. SceneObjectPart rootpart = m_rootPart;
  2637. if (rootpart != null)
  2638. {
  2639. if (rootpart.PhysActor != null)
  2640. {
  2641. if (!IsAttachment)
  2642. rootpart.PhysActor.AddAngularForce(impulse, true);
  2643. }
  2644. }
  2645. }
  2646. public void setAngularImpulse(Vector3 impulse)
  2647. {
  2648. // We check if rootpart is null here because scripts don't delete if you delete the host.
  2649. // This means that unfortunately, we can pass a null physics actor to Simulate!
  2650. // Make sure we don't do that!
  2651. SceneObjectPart rootpart = m_rootPart;
  2652. if (rootpart != null)
  2653. {
  2654. if (rootpart.PhysActor != null)
  2655. {
  2656. if (!IsAttachment)
  2657. rootpart.PhysActor.Torque = impulse;
  2658. }
  2659. }
  2660. }
  2661. public void moveToTarget(Vector3 target, float tau)
  2662. {
  2663. SceneObjectPart rootpart = m_rootPart;
  2664. if (rootpart != null)
  2665. {
  2666. if (IsAttachment)
  2667. {
  2668. IScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
  2669. if (avatar != null)
  2670. {
  2671. List<string> coords = new List<string>();
  2672. uint regionX = 0;
  2673. uint regionY = 0;
  2674. Utils.LongToUInts(Scene.RegionInfo.RegionHandle, out regionX, out regionY);
  2675. target.X += regionX;
  2676. target.Y += regionY;
  2677. coords.Add(target.X.ToString());
  2678. coords.Add(target.Y.ToString());
  2679. coords.Add(target.Z.ToString());
  2680. avatar.DoMoveToPosition(avatar, "", coords);
  2681. }
  2682. }
  2683. else
  2684. {
  2685. rootpart.SetMoveToTarget(true, target, tau);
  2686. }
  2687. }
  2688. }
  2689. public void stopMoveToTarget()
  2690. {
  2691. SceneObjectPart rootpart = m_rootPart;
  2692. if (rootpart != null)
  2693. {
  2694. if (rootpart.PhysActor != null)
  2695. {
  2696. rootpart.SetMoveToTarget(false, Vector3.Zero, 0);
  2697. }
  2698. }
  2699. }
  2700. /// <summary>
  2701. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2702. /// </summary>
  2703. /// <param name = "height">Height to hover. Height of zero disables hover.</param>
  2704. /// <param name = "hoverType">Determines what the height is relative to </param>
  2705. /// <param name = "tau">Number of seconds over which to reach target</param>
  2706. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2707. {
  2708. SceneObjectPart rootpart = m_rootPart;
  2709. if (rootpart != null)
  2710. {
  2711. if (rootpart.PhysActor != null)
  2712. {
  2713. if (height != 0f)
  2714. {
  2715. rootpart.PIDHoverHeight = height;
  2716. rootpart.PIDHoverType = hoverType;
  2717. rootpart.PIDTau = tau;
  2718. rootpart.PIDHoverActive = true;
  2719. }
  2720. else
  2721. {
  2722. rootpart.PIDHoverActive = false;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  2728. {
  2729. part.OwnerID = cAgentID;
  2730. part.GroupID = cGroupID;
  2731. }
  2732. #endregion
  2733. #region Scheduling
  2734. /// <summary>
  2735. /// Send an update to all prims in the group to a specific avatar
  2736. /// </summary>
  2737. /// <param name = "presence"></param>
  2738. /// <param name = "UpdateFlags"></param>
  2739. public void ScheduleGroupUpdateToAvatar(IScenePresence presence, PrimUpdateFlags UpdateFlags)
  2740. {
  2741. //We have to send the root part first as the client wants it that way
  2742. presence.AddUpdateToAvatar(RootPart, UpdateFlags);
  2743. #if (!ISWIN)
  2744. foreach (SceneObjectPart part in m_partsList)
  2745. {
  2746. if (part != RootPart)
  2747. {
  2748. presence.AddUpdateToAvatar(part, UpdateFlags);
  2749. }
  2750. }
  2751. #else
  2752. foreach (SceneObjectPart part in m_partsList.Where(part => part != RootPart))
  2753. {
  2754. presence.AddUpdateToAvatar(part, UpdateFlags);
  2755. }
  2756. #endif
  2757. }
  2758. /// <summary>
  2759. /// Send an update to all prims in the group
  2760. /// </summary>
  2761. /// <param name = "UpdateFlags"></param>
  2762. public void ScheduleGroupUpdate(PrimUpdateFlags UpdateFlags)
  2763. {
  2764. //We have to send the root part first as the client wants it that way
  2765. RootPart.ScheduleUpdate(UpdateFlags);
  2766. #if (!ISWIN)
  2767. foreach (SceneObjectPart part in m_partsList)
  2768. {
  2769. if (part != RootPart)
  2770. {
  2771. part.ScheduleUpdate(UpdateFlags);
  2772. }
  2773. }
  2774. #else
  2775. foreach (SceneObjectPart part in m_partsList.Where(part => part != RootPart))
  2776. {
  2777. part.ScheduleUpdate(UpdateFlags);
  2778. }
  2779. #endif
  2780. }
  2781. /// <summary>
  2782. /// Schedule a terse update (position, rotation, velocity, and rotational velocity update) for this object to all clients
  2783. /// </summary>
  2784. public void ScheduleGroupTerseUpdate()
  2785. {
  2786. //We have to send the root part first as the client wants it that way
  2787. RootPart.ScheduleTerseUpdate();
  2788. #if (!ISWIN)
  2789. foreach (SceneObjectPart part in m_partsList)
  2790. {
  2791. if (part != RootPart)
  2792. {
  2793. part.ScheduleTerseUpdate();
  2794. }
  2795. }
  2796. #else
  2797. foreach (SceneObjectPart part in m_partsList.Where(part => part != RootPart))
  2798. {
  2799. part.ScheduleTerseUpdate();
  2800. }
  2801. #endif
  2802. }
  2803. public void Update()
  2804. {
  2805. }
  2806. ///<summary>
  2807. ///</summary>
  2808. ///<param name="remoteClient"></param>
  2809. ///<param name="AgentID"></param>
  2810. ///<param name="RequestFlags"></param>
  2811. public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags)
  2812. {
  2813. remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID,
  2814. RootPart.BaseMask,
  2815. RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask,
  2816. RootPart.NextOwnerMask,
  2817. RootPart.OwnershipCost, RootPart.ObjectSaleType,
  2818. RootPart.SalePrice, RootPart.Category,
  2819. RootPart.CreatorID, RootPart.Name, RootPart.Description);
  2820. }
  2821. /// <summary>
  2822. /// See if the object has moved enough to trigger the Significant Movement event
  2823. /// </summary>
  2824. protected internal void CheckForSignificantMovement()
  2825. {
  2826. m_scene.EventManager.TriggerSignificantObjectMovement(this);
  2827. //Do this second! This is important, otherwise
  2828. // if the object isn't allowed, we will not be able
  2829. // to reset its position to the last known good pos
  2830. m_lastSignificantPosition = AbsolutePosition;
  2831. }
  2832. #endregion
  2833. #region Get Children Methods
  2834. /// <summary>
  2835. /// Get the child part by LinkNum
  2836. /// </summary>
  2837. /// <param name = "linknum"></param>
  2838. /// <returns>null if no child part with that linknum or child part</returns>
  2839. public IEntity GetLinkNumPart(int linknum)
  2840. {
  2841. if (linknum <= m_parts.Count)
  2842. {
  2843. if (m_parts.Count == 1)
  2844. return RootPart;
  2845. #if (!ISWIN)
  2846. foreach (SceneObjectPart part in m_partsList)
  2847. {
  2848. if (part.LinkNum == linknum)
  2849. {
  2850. return part;
  2851. }
  2852. }
  2853. #else
  2854. foreach (SceneObjectPart part in m_partsList.Where(part => part.LinkNum == linknum))
  2855. {
  2856. return part;
  2857. }
  2858. #endif
  2859. }
  2860. //Check sitting avatars
  2861. int count = m_parts.Count + 1;
  2862. foreach (UUID agentID in SitTargetAvatar)
  2863. {
  2864. if (count == linknum)
  2865. {
  2866. return m_scene.GetScenePresence(agentID);
  2867. }
  2868. count++;
  2869. }
  2870. return null;
  2871. }
  2872. /// <summary>
  2873. /// Get a child prim of this group by LocalID
  2874. /// </summary>
  2875. /// <param name = "LocalID"></param>
  2876. /// <param name = "entity"></param>
  2877. /// <returns></returns>
  2878. public bool GetChildPrim(uint LocalID, out ISceneChildEntity entity)
  2879. {
  2880. entity = GetChildPart(LocalID);
  2881. return entity != null;
  2882. }
  2883. /// <summary>
  2884. /// Get a child prim of this group by UUID
  2885. /// </summary>
  2886. /// <param name = "UUID2"></param>
  2887. /// <param name = "entity"></param>
  2888. /// <returns></returns>
  2889. public bool GetChildPrim(UUID UUID2, out ISceneChildEntity entity)
  2890. {
  2891. entity = GetChildPart(UUID2);
  2892. return entity != null;
  2893. }
  2894. /// <summary>
  2895. /// Get a part with a given UUID
  2896. /// </summary>
  2897. /// <param name = "primID"></param>
  2898. /// <returns>null if a child part with the primID was not found</returns>
  2899. public ISceneChildEntity GetChildPart(UUID primID)
  2900. {
  2901. SceneObjectPart childPart = null;
  2902. m_parts.TryGetValue(primID, out childPart);
  2903. return childPart;
  2904. }
  2905. /// <summary>
  2906. /// Get a part with a given UUID
  2907. /// </summary>
  2908. /// <param name = "primID"></param>
  2909. /// <returns>null if a child part with the primID was not found</returns>
  2910. public ISceneChildEntity GetChildPart(uint primID)
  2911. {
  2912. #if (!ISWIN)
  2913. foreach (ISceneChildEntity part in m_partsList)
  2914. {
  2915. if (part.LocalId == primID) return part;
  2916. }
  2917. return null;
  2918. #else
  2919. return m_partsList.Cast<ISceneChildEntity>().FirstOrDefault(part => part.LocalId == primID);
  2920. #endif
  2921. }
  2922. #endregion
  2923. #region Packet Handlers
  2924. #region Linking and Delinking
  2925. /// <summary>
  2926. /// Link the prims in a given group to this group
  2927. /// </summary>
  2928. /// <param name = "grp">The group of prims which should be linked to this group</param>
  2929. public void LinkToGroup(ISceneEntity grp)
  2930. {
  2931. //MainConsole.Instance.DebugFormat(
  2932. // "[SCENE OBJECT GROUP]: Linking group with root part {0}, {1} to group with root part {2}, {3}",
  2933. // objectGroup.RootPart.Name, objectGroup.RootPart.UUID, RootPart.Name, RootPart.UUID);
  2934. if (!(grp is SceneObjectGroup))
  2935. return;
  2936. SceneObjectGroup objectGroup = (SceneObjectGroup) grp;
  2937. if (m_rootPart.PhysActor != null)
  2938. m_rootPart.PhysActor.BlockPhysicalReconstruction = true;
  2939. SceneObjectPart linkPart = objectGroup.m_rootPart;
  2940. Vector3 oldGroupPosition = linkPart.GroupPosition;
  2941. Quaternion oldRootRotation = linkPart.RotationOffset;
  2942. Quaternion parentRot = m_rootPart.RotationOffset;
  2943. linkPart.SetGroupPosition(AbsolutePosition); // just change it without doing anything else
  2944. Vector3 axPos = oldGroupPosition - AbsolutePosition;
  2945. axPos *= Quaternion.Inverse(parentRot);
  2946. linkPart.SetOffsetPosition(axPos);
  2947. Quaternion newRot = Quaternion.Inverse(parentRot)*oldRootRotation;
  2948. linkPart.SetRotationOffset(false, newRot, false);
  2949. //Fix the link number for the root
  2950. if (m_rootPart.LinkNum == 0)
  2951. m_rootPart.LinkNum = 1;
  2952. SceneObjectPart[] objectGroupChildren = new SceneObjectPart[objectGroup.ChildrenList.Count];
  2953. objectGroup.ChildrenList.CopyTo(objectGroupChildren, 0);
  2954. //Destroy the old group
  2955. m_scene.SceneGraph.DeleteEntity(objectGroup);
  2956. objectGroup.IsDeleted = true;
  2957. objectGroup.ClearChildren();
  2958. lock (m_partsLock)
  2959. {
  2960. int linkNum = 2;
  2961. //Add the root part to our group!
  2962. m_scene.SceneGraph.LinkPartToSOG(this, linkPart, linkNum++);
  2963. linkPart.CreateSelected = true;
  2964. linkPart.FixOffsetPosition(linkPart.OffsetPosition, true); // nasty let all know about where this is
  2965. // let physics link it
  2966. if (linkPart.PhysActor != null && m_rootPart.PhysActor != null)
  2967. {
  2968. if (linkPart.PhysicsType != (byte) PhysicsShapeType.None)
  2969. linkPart.PhysActor.link(m_rootPart.PhysActor);
  2970. }
  2971. //rest of parts
  2972. #if (!ISWIN)
  2973. foreach (SceneObjectPart part in objectGroupChildren)
  2974. {
  2975. if (part.UUID != objectGroup.m_rootPart.UUID)
  2976. {
  2977. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  2978. part.FixOffsetPosition(part.OffsetPosition, true);
  2979. if (part.PhysActor != null && m_rootPart.PhysActor != null)
  2980. part.PhysActor.link(m_rootPart.PhysActor);
  2981. }
  2982. }
  2983. #else
  2984. foreach (SceneObjectPart part in objectGroupChildren.Where(part => part.UUID != objectGroup.m_rootPart.UUID))
  2985. {
  2986. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  2987. part.FixOffsetPosition(part.OffsetPosition, true);
  2988. if (part.PhysActor != null && m_rootPart.PhysActor != null)
  2989. part.PhysActor.link(m_rootPart.PhysActor);
  2990. }
  2991. #endif
  2992. }
  2993. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  2994. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  2995. // unmoved prims!
  2996. m_ValidgrpOOB = false;
  2997. ResetChildPrimPhysicsPositions();
  2998. if (m_rootPart.PhysActor != null)
  2999. m_rootPart.PhysActor.BlockPhysicalReconstruction = false;
  3000. }
  3001. /// <summary>
  3002. /// Delink the given prim from this group. The delinked prim is established as
  3003. /// an independent SceneObjectGroup.
  3004. /// </summary>
  3005. /// <param name = "part"></param>
  3006. /// <param name = "sendEvents"></param>
  3007. /// <returns>The object group of the newly delinked prim.</returns>
  3008. public ISceneEntity DelinkFromGroup(ISceneChildEntity part, bool sendEvents)
  3009. {
  3010. if (!(part is SceneObjectPart))
  3011. return null;
  3012. SceneObjectPart linkPart = part as SceneObjectPart;
  3013. // MainConsole.Instance.DebugFormat(
  3014. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3015. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3016. Quaternion worldRot = linkPart.GetWorldRotation();
  3017. // Remove the part from this object
  3018. m_scene.SceneGraph.DeLinkPartFromEntity(this, linkPart);
  3019. linkPart.SetParentLocalId(0);
  3020. linkPart.LinkNum = 0;
  3021. if (linkPart.PhysActor != null)
  3022. {
  3023. m_scene.PhysicsScene.RemovePrim(linkPart.PhysActor);
  3024. }
  3025. // We need to reset the child part's position
  3026. // ready for life as a separate object after being a part of another object
  3027. Quaternion parentRot = m_rootPart.RotationOffset;
  3028. Vector3 axPos = linkPart.OffsetPosition;
  3029. axPos *= parentRot;
  3030. linkPart.SetOffsetPosition(axPos);
  3031. linkPart.FixGroupPosition(AbsolutePosition + linkPart.OffsetPosition, false);
  3032. linkPart.FixOffsetPosition(Vector3.Zero, false);
  3033. linkPart.RotationOffset = worldRot;
  3034. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart, Scene);
  3035. m_scene.SceneGraph.DelinkPartToScene(objectGroup);
  3036. if (sendEvents)
  3037. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3038. linkPart.Rezzed = RootPart.Rezzed;
  3039. //This is already set multiple places, no need to do it again
  3040. //HasGroupChanged = true;
  3041. //We need to send this so that we don't have issues with the client not realizing that the prims were unlinked
  3042. ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);
  3043. m_ValidgrpOOB = false;
  3044. return objectGroup;
  3045. }
  3046. private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation,
  3047. int linkNum)
  3048. {
  3049. Quaternion WorldRot = oldGroupRotation*part.RotationOffset;
  3050. // first fix from old local to world
  3051. // position
  3052. Vector3 axPos = part.OffsetPosition;
  3053. axPos *= oldGroupRotation;
  3054. part.SetGroupPosition(oldGroupPosition + axPos);
  3055. //offset
  3056. part.SetRotationOffset(false, WorldRot, false);
  3057. // have it in world coords lets fix other things
  3058. m_scene.SceneGraph.LinkPartToSOG(this, part, linkNum);
  3059. part.CreateSelected = true;
  3060. // now lets move to the new parent frame
  3061. Quaternion rootRotation = m_rootPart.RotationOffset;
  3062. Vector3 pos = part.GroupPosition - AbsolutePosition;
  3063. pos *= Quaternion.Inverse(rootRotation);
  3064. part.SetOffsetPosition(pos);
  3065. Quaternion newRot = Quaternion.Inverse(rootRotation)*WorldRot;
  3066. part.SetRotationOffset(false, newRot, false);
  3067. // caller will tell the rest about this position changes..
  3068. }
  3069. #endregion
  3070. /// <summary>
  3071. /// Return metadata about a prim (name, description, sale price, etc.)
  3072. /// </summary>
  3073. /// <param name = "client"></param>
  3074. public void GetProperties(IClientAPI client)
  3075. {
  3076. m_rootPart.GetProperties(client);
  3077. }
  3078. public void UpdatePermissions(UUID AgentID, byte field, uint localID,
  3079. uint mask, byte addRemTF)
  3080. {
  3081. foreach (SceneObjectPart part in m_partsList)
  3082. part.UpdatePermissions(AgentID, field, localID, mask,
  3083. addRemTF);
  3084. HasGroupChanged = true;
  3085. }
  3086. /// <summary>
  3087. /// If object is physical, apply force to move it around
  3088. /// If object is not physical, just put it at the resulting location
  3089. /// </summary>
  3090. /// <param name = "offset">Always seems to be 0,0,0, so ignoring</param>
  3091. /// <param name = "pos">New position. We do the math here to turn it into a force</param>
  3092. /// <param name = "remoteClient"></param>
  3093. public void GrabMovement(Vector3 offset, Vector3 pos, IClientAPI remoteClient)
  3094. {
  3095. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3096. {
  3097. if (m_rootPart.PhysActor != null)
  3098. {
  3099. if (m_rootPart.PhysActor.IsPhysical)
  3100. {
  3101. if (!m_rootPart.BlockGrab && !m_rootPart.BlockGrabObject)
  3102. {
  3103. Vector3 grabforce = pos - AbsolutePosition;
  3104. grabforce = grabforce * m_rootPart.PhysActor.Mass;
  3105. m_rootPart.PhysActor.AddForce(grabforce, true);
  3106. // This is outside the above permissions condition
  3107. // so that if the object is locked the client moving the object
  3108. // get's it's position on the simulator even if it was the same as before
  3109. // This keeps the moving user's client in sync with the rest of the world.
  3110. ScheduleGroupTerseUpdate();
  3111. }
  3112. }
  3113. }
  3114. }
  3115. }
  3116. public void NonPhysicalGrabMovement(Vector3 pos)
  3117. {
  3118. AbsolutePosition = pos;
  3119. m_rootPart.ScheduleTerseUpdate();
  3120. }
  3121. /// <summary>
  3122. /// If object is physical, prepare for spinning torques (set flag to save old orientation)
  3123. /// </summary>
  3124. /// <param name = "remoteClient"></param>
  3125. public void SpinStart(IClientAPI remoteClient)
  3126. {
  3127. if (m_scene.EventManager.TriggerGroupSpinStart(UUID))
  3128. {
  3129. if (m_rootPart.PhysActor != null)
  3130. {
  3131. if (m_rootPart.PhysActor.IsPhysical)
  3132. {
  3133. m_rootPart.IsWaitingForFirstSpinUpdatePacket = true;
  3134. }
  3135. }
  3136. }
  3137. }
  3138. /// <summary>
  3139. /// If object is physical, apply torque to spin it around
  3140. /// </summary>
  3141. /// <param name="newOrientation">Rotation. We do the math here to turn it into a torque</param>
  3142. /// <param name = "remoteClient"></param>
  3143. public void SpinMovement(Quaternion newOrientation, IClientAPI remoteClient)
  3144. {
  3145. // The incoming newOrientation, sent by the client, "seems" to be the
  3146. // desired target orientation. This needs further verification; in particular,
  3147. // one would expect that the initial incoming newOrientation should be
  3148. // fairly close to the original prim's physical orientation,
  3149. // m_rootPart.PhysActor.Orientation. This however does not seem to be the
  3150. // case (might just be an issue with different quaternions representing the
  3151. // same rotation, or it might be a coordinate system issue).
  3152. //
  3153. // Since it's not clear what the relationship is between the PhysActor.Orientation
  3154. // and the incoming orientations sent by the client, we take an alternative approach
  3155. // of calculating the delta rotation between the orientations being sent by the
  3156. // client. (Since a spin is invoked by ctrl+shift+drag in the client, we expect
  3157. // a steady stream of several new orientations coming in from the client.)
  3158. // This ensures that the delta rotations are being calculated from self-consistent
  3159. // pairs of old/new rotations. Given the delta rotation, we apply a torque around
  3160. // the delta rotation axis, scaled by the object mass times an arbitrary scaling
  3161. // factor (to ensure the resulting torque is not "too strong" or "too weak").
  3162. //
  3163. // Ideally we need to calculate (probably iteratively) the exact torque or series
  3164. // of torques needed to arrive exactly at the destination orientation. However, since
  3165. // it is not yet clear how to map the destination orientation (provided by the viewer)
  3166. // into PhysActor orientations (needed by the physics engine), we omit this step.
  3167. // This means that the resulting torque will at least be in the correct direction,
  3168. // but it will result in over-shoot or under-shoot of the target orientation.
  3169. // For the end user, this means that ctrl+shift+drag can be used for relative,
  3170. // but not absolute, adjustments of orientation for physical prims.
  3171. if (m_scene.EventManager.TriggerGroupSpin(UUID, newOrientation))
  3172. {
  3173. if (m_rootPart.PhysActor != null)
  3174. {
  3175. if (m_rootPart.PhysActor.IsPhysical)
  3176. {
  3177. if (m_rootPart.IsWaitingForFirstSpinUpdatePacket)
  3178. {
  3179. // first time initialization of "old" orientation for calculation of delta rotations
  3180. m_rootPart.SpinOldOrientation = newOrientation;
  3181. m_rootPart.IsWaitingForFirstSpinUpdatePacket = false;
  3182. }
  3183. else
  3184. {
  3185. // save and update old orientation
  3186. Quaternion old = m_rootPart.SpinOldOrientation;
  3187. m_rootPart.SpinOldOrientation = newOrientation;
  3188. //MainConsole.Instance.Error("[SCENE OBJECT GROUP]: Old orientation is " + old);
  3189. //MainConsole.Instance.Error("[SCENE OBJECT GROUP]: Incoming new orientation is " + newOrientation);
  3190. // compute difference between previous old rotation and new incoming rotation
  3191. Quaternion minimalRotationFromQ1ToQ2 = Quaternion.Inverse(old)*newOrientation;
  3192. float rotationAngle;
  3193. Vector3 rotationAxis;
  3194. minimalRotationFromQ1ToQ2.GetAxisAngle(out rotationAxis, out rotationAngle);
  3195. rotationAxis.Normalize();
  3196. //MainConsole.Instance.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis);
  3197. Vector3 spinforce = new Vector3(rotationAxis.X, rotationAxis.Y, rotationAxis.Z);
  3198. spinforce = (spinforce/8)*m_rootPart.PhysActor.Mass;
  3199. // 8 is an arbitrary torque scaling factor
  3200. m_rootPart.PhysActor.AddAngularForce(spinforce, true);
  3201. }
  3202. }
  3203. }
  3204. }
  3205. }
  3206. /// <summary>
  3207. /// Set the name of a prim
  3208. /// </summary>
  3209. /// <param name = "name"></param>
  3210. /// <param name = "localID"></param>
  3211. public void SetPartName(string name, uint localID)
  3212. {
  3213. ISceneChildEntity part = GetChildPart(localID);
  3214. if (part != null)
  3215. {
  3216. part.Name = name;
  3217. }
  3218. }
  3219. public void SetPartDescription(string des, uint localID)
  3220. {
  3221. ISceneChildEntity part = GetChildPart(localID);
  3222. if (part != null)
  3223. {
  3224. part.Description = des;
  3225. }
  3226. }
  3227. public void SetPartText(string text, uint localID)
  3228. {
  3229. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3230. if (part != null)
  3231. {
  3232. part.SetText(text);
  3233. }
  3234. }
  3235. public void SetPartText(string text, UUID partID)
  3236. {
  3237. SceneObjectPart part = (SceneObjectPart) GetChildPart(partID);
  3238. if (part != null)
  3239. {
  3240. part.SetText(text);
  3241. }
  3242. }
  3243. public string GetPartName(uint localID)
  3244. {
  3245. ISceneChildEntity part = GetChildPart(localID);
  3246. if (part != null)
  3247. {
  3248. return part.Name;
  3249. }
  3250. return String.Empty;
  3251. }
  3252. public string GetPartDescription(uint localID)
  3253. {
  3254. ISceneChildEntity part = GetChildPart(localID);
  3255. if (part != null)
  3256. {
  3257. return part.Description;
  3258. }
  3259. return String.Empty;
  3260. }
  3261. /// <summary>
  3262. /// Update prim flags for this group.
  3263. /// </summary>
  3264. /// <param name = "localID"></param>
  3265. /// <param name="UsePhysics"></param>
  3266. /// <param name="IsTemporary"></param>
  3267. /// <param name="IsPhantom"></param>
  3268. /// <param name="IsVolumeDetect"></param>
  3269. /// <param name="blocks"></param>
  3270. public void UpdatePrimFlags(uint localID, bool UsePhysics, bool IsTemporary, bool IsPhantom, bool IsVolumeDetect,
  3271. ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks)
  3272. {
  3273. ISceneChildEntity selectionPart = GetChildPart(localID);
  3274. if (IsTemporary)
  3275. {
  3276. // Remove from database and parcel prim count
  3277. // Temporary objects arn't saved to the database ever, so we don't need to do anything
  3278. }
  3279. if (selectionPart != null)
  3280. {
  3281. foreach (SceneObjectPart part in m_partsList)
  3282. {
  3283. IOpenRegionSettingsModule WSModule = Scene.RequestModuleInterface<IOpenRegionSettingsModule>();
  3284. if (WSModule != null)
  3285. {
  3286. if (WSModule.MaximumPhysPrimScale == -1)
  3287. break;
  3288. if (part.Scale.X > WSModule.MaximumPhysPrimScale ||
  3289. part.Scale.Y > WSModule.MaximumPhysPrimScale ||
  3290. part.Scale.Z > WSModule.MaximumPhysPrimScale)
  3291. {
  3292. UsePhysics = false; // Reset physics
  3293. break;
  3294. }
  3295. }
  3296. }
  3297. bool needsPhysicalRebuild = ((SceneObjectPart) selectionPart).UpdatePrimFlags(UsePhysics, IsTemporary,
  3298. IsPhantom, IsVolumeDetect,
  3299. blocks);
  3300. #if (!ISWIN)
  3301. foreach (SceneObjectPart part in m_partsList)
  3302. {
  3303. if (selectionPart != part)
  3304. {
  3305. if (needsPhysicalRebuild)
  3306. part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect, null);
  3307. else
  3308. needsPhysicalRebuild = part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect, null);
  3309. }
  3310. }
  3311. #else
  3312. foreach (SceneObjectPart part in m_partsList.Where(part => selectionPart != part))
  3313. {
  3314. if (needsPhysicalRebuild)
  3315. part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom, IsVolumeDetect, null);
  3316. else
  3317. needsPhysicalRebuild = part.UpdatePrimFlags(UsePhysics, IsTemporary, IsPhantom,
  3318. IsVolumeDetect, null);
  3319. }
  3320. #endif
  3321. if (needsPhysicalRebuild)
  3322. RebuildPhysicalRepresentation(true);
  3323. }
  3324. }
  3325. public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data)
  3326. {
  3327. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3328. if (part != null)
  3329. {
  3330. part.UpdateExtraParam(type, inUse, data);
  3331. }
  3332. }
  3333. /// <summary>
  3334. /// Update the texture entry for this part
  3335. /// </summary>
  3336. /// <param name = "localID"></param>
  3337. /// <param name = "textureEntry"></param>
  3338. public void UpdateTextureEntry(uint localID, byte[] textureEntry, bool sendChangedEvent)
  3339. {
  3340. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3341. if (part != null)
  3342. {
  3343. part.UpdateTextureEntry(textureEntry, sendChangedEvent);
  3344. }
  3345. }
  3346. #endregion
  3347. #region Shape
  3348. ///<summary>
  3349. ///</summary>
  3350. ///<param name = "shapeBlock"></param>
  3351. ///<param name="localID"></param>
  3352. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock, uint localID)
  3353. {
  3354. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3355. if (part != null)
  3356. {
  3357. part.UpdateShape(shapeBlock);
  3358. m_ValidgrpOOB = false;
  3359. }
  3360. }
  3361. #endregion
  3362. #region Resize
  3363. /// <summary>
  3364. /// Resize the given part
  3365. /// </summary>
  3366. /// <param name = "scale"></param>
  3367. /// <param name = "localID"></param>
  3368. public void Resize(Vector3 scale, uint localID)
  3369. {
  3370. CheckSculptAndLoad();
  3371. //Grab the mesh again if it is a sculpty/mesh as we remove it after the first mesh is built
  3372. IOpenRegionSettingsModule WSModule = Scene.RequestModuleInterface<IOpenRegionSettingsModule>();
  3373. if (WSModule != null)
  3374. {
  3375. if (WSModule.MinimumPrimScale != -1)
  3376. {
  3377. if (scale.X < WSModule.MinimumPrimScale)
  3378. scale.X = WSModule.MinimumPrimScale;
  3379. if (scale.Y < WSModule.MinimumPrimScale)
  3380. scale.Y = WSModule.MinimumPrimScale;
  3381. if (scale.Z < WSModule.MinimumPrimScale)
  3382. scale.Z = WSModule.MinimumPrimScale;
  3383. }
  3384. if (RootPart.PhysActor != null && RootPart.PhysActor.IsPhysical &&
  3385. WSModule.MaximumPhysPrimScale != -1)
  3386. {
  3387. if (scale.X > WSModule.MaximumPhysPrimScale)
  3388. scale.X = WSModule.MaximumPhysPrimScale;
  3389. if (scale.Y > WSModule.MaximumPhysPrimScale)
  3390. scale.Y = WSModule.MaximumPhysPrimScale;
  3391. if (scale.Z > WSModule.MaximumPhysPrimScale)
  3392. scale.Z = WSModule.MaximumPhysPrimScale;
  3393. }
  3394. if (WSModule.MaximumPrimScale != -1)
  3395. {
  3396. if (scale.X > WSModule.MaximumPrimScale)
  3397. scale.X = WSModule.MaximumPrimScale;
  3398. if (scale.Y > WSModule.MaximumPrimScale)
  3399. scale.Y = WSModule.MaximumPrimScale;
  3400. if (scale.Z > WSModule.MaximumPrimScale)
  3401. scale.Z = WSModule.MaximumPrimScale;
  3402. }
  3403. }
  3404. m_ValidgrpOOB = false;
  3405. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3406. if (part != null)
  3407. {
  3408. part.Resize(scale);
  3409. if (part.PhysActor != null)
  3410. part.PhysActor.Size = scale;
  3411. //if (part.UUID != m_rootPart.UUID)
  3412. HasGroupChanged = true;
  3413. ScheduleGroupUpdate(PrimUpdateFlags.Shape);
  3414. //if (part.UUID == m_rootPart.UUID)
  3415. //{
  3416. //if (m_rootPart.PhysActor != null)
  3417. //{
  3418. //m_rootPart.PhysActor.Size =
  3419. //new PhysicsVector(m_rootPart.Scale.X, m_rootPart.Scale.Y, m_rootPart.Scale.Z);
  3420. //m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
  3421. //}
  3422. //}
  3423. }
  3424. }
  3425. public void GroupResize(Vector3 scale, uint localID)
  3426. {
  3427. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3428. if (part != null)
  3429. {
  3430. CheckSculptAndLoad();
  3431. //Grab the mesh again if it is a sculpty/mesh as we remove it after the first mesh is built
  3432. part.IgnoreUndoUpdate = true;
  3433. IOpenRegionSettingsModule WSModule = Scene.RequestModuleInterface<IOpenRegionSettingsModule>();
  3434. if (WSModule != null)
  3435. {
  3436. if (WSModule.MinimumPrimScale != -1)
  3437. {
  3438. if (scale.X < WSModule.MinimumPrimScale)
  3439. scale.X = WSModule.MinimumPrimScale;
  3440. if (scale.Y < WSModule.MinimumPrimScale)
  3441. scale.Y = WSModule.MinimumPrimScale;
  3442. if (scale.Z < WSModule.MinimumPrimScale)
  3443. scale.Z = WSModule.MinimumPrimScale;
  3444. }
  3445. if (RootPart.PhysActor != null && RootPart.PhysActor.IsPhysical &&
  3446. WSModule.MaximumPhysPrimScale != -1)
  3447. {
  3448. if (scale.X > WSModule.MaximumPhysPrimScale)
  3449. scale.X = WSModule.MaximumPhysPrimScale;
  3450. if (scale.Y > WSModule.MaximumPhysPrimScale)
  3451. scale.Y = WSModule.MaximumPhysPrimScale;
  3452. if (scale.Z > WSModule.MaximumPhysPrimScale)
  3453. scale.Z = WSModule.MaximumPhysPrimScale;
  3454. }
  3455. if (WSModule.MaximumPrimScale != -1)
  3456. {
  3457. if (scale.X > WSModule.MaximumPrimScale)
  3458. scale.X = WSModule.MaximumPrimScale;
  3459. if (scale.Y > WSModule.MaximumPrimScale)
  3460. scale.Y = WSModule.MaximumPrimScale;
  3461. if (scale.Z > WSModule.MaximumPrimScale)
  3462. scale.Z = WSModule.MaximumPrimScale;
  3463. }
  3464. }
  3465. float x = (scale.X/part.Scale.X);
  3466. float y = (scale.Y/part.Scale.Y);
  3467. float z = (scale.Z/part.Scale.Z);
  3468. foreach (SceneObjectPart obPart in m_partsList)
  3469. {
  3470. obPart.StoreUndoState();
  3471. }
  3472. Vector3 prevScale = part.Scale;
  3473. prevScale.X *= x;
  3474. prevScale.Y *= y;
  3475. prevScale.Z *= z;
  3476. part.Resize(prevScale);
  3477. #if (!ISWIN)
  3478. foreach (SceneObjectPart obPart in m_partsList)
  3479. {
  3480. if (obPart.UUID != m_rootPart.UUID)
  3481. {
  3482. obPart.IgnoreUndoUpdate = true;
  3483. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  3484. currentpos.X *= x;
  3485. currentpos.Y *= y;
  3486. currentpos.Z *= z;
  3487. Vector3 newSize = new Vector3(obPart.Scale);
  3488. newSize.X *= x;
  3489. newSize.Y *= y;
  3490. newSize.Z *= z;
  3491. obPart.Resize(newSize);
  3492. obPart.UpdateOffSet(currentpos);
  3493. obPart.IgnoreUndoUpdate = false;
  3494. }
  3495. }
  3496. #else
  3497. foreach (SceneObjectPart obPart in m_partsList.Where(obPart => obPart.UUID != m_rootPart.UUID))
  3498. {
  3499. obPart.IgnoreUndoUpdate = true;
  3500. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  3501. currentpos.X *= x;
  3502. currentpos.Y *= y;
  3503. currentpos.Z *= z;
  3504. Vector3 newSize = new Vector3(obPart.Scale);
  3505. newSize.X *= x;
  3506. newSize.Y *= y;
  3507. newSize.Z *= z;
  3508. obPart.Resize(newSize);
  3509. obPart.UpdateOffSet(currentpos);
  3510. obPart.IgnoreUndoUpdate = false;
  3511. }
  3512. #endif
  3513. if (part.PhysActor != null)
  3514. part.PhysActor.Size = prevScale;
  3515. part.IgnoreUndoUpdate = false;
  3516. m_rootPart.IgnoreUndoUpdate = false;
  3517. HasGroupChanged = true;
  3518. ScheduleGroupTerseUpdate();
  3519. m_ValidgrpOOB = false;
  3520. }
  3521. }
  3522. #endregion
  3523. #region Position
  3524. private Vector3 m_lastSigInfiniteRegionPos = Vector3.Zero;
  3525. private List<GridRegion> m_nearbyInfiniteRegions = new List<GridRegion>();
  3526. /// <summary>
  3527. /// Move this scene object
  3528. /// </summary>
  3529. /// <param name = "pos"></param>
  3530. /// <param name="SaveUpdate"></param>
  3531. public void UpdateGroupPosition(Vector3 pos, bool SaveUpdate)
  3532. {
  3533. if (SaveUpdate)
  3534. {
  3535. foreach (SceneObjectPart part in ChildrenList)
  3536. {
  3537. part.StoreUndoState();
  3538. }
  3539. }
  3540. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3541. {
  3542. if (IsAttachment)
  3543. {
  3544. m_rootPart.AttachedPos = pos;
  3545. }
  3546. if (RootPart.GetStatusSandbox())
  3547. {
  3548. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, pos) > 10)
  3549. {
  3550. ScriptSetPhysicsStatus(false);
  3551. pos = AbsolutePosition;
  3552. IChatModule chatModule = Scene.RequestModuleInterface<IChatModule>();
  3553. if (chatModule != null)
  3554. chatModule.SimChat("Hit Sandbox Limit", ChatTypeEnum.DebugChannel, 0x7FFFFFFF,
  3555. RootPart.AbsolutePosition, Name, UUID, false, Scene);
  3556. }
  3557. }
  3558. AbsolutePosition = pos;
  3559. HasGroupChanged = true;
  3560. }
  3561. //we need to do a terse update even if the move wasn't allowed
  3562. // so that the position is reset in the client (the object snaps back)
  3563. ScheduleGroupTerseUpdate();
  3564. if (SitTargetAvatar.Count != 0)
  3565. {
  3566. foreach (UUID clientID in SitTargetAvatar)
  3567. {
  3568. //Send full updates to the avatar as well so that they move as well
  3569. IScenePresence SP;
  3570. if (m_scene.TryGetScenePresence(clientID, out SP))
  3571. {
  3572. SP.ParentPosition = AbsolutePosition;
  3573. SP.SendTerseUpdateToAllClients();
  3574. }
  3575. }
  3576. }
  3577. }
  3578. public void SetAbsolutePosition(bool UpdatePrimActor, Vector3 val)
  3579. {
  3580. if (!IsAttachment && RootPart != null && RootPart.Shape != null && Scene != null && Scene.RegionInfo != null &&
  3581. RootPart.Shape.State == 0 && !IsDeleted)
  3582. {
  3583. IBackupModule backup = Scene.RequestModuleInterface<IBackupModule>();
  3584. if ((val.X < 0f || val.Y < 0f || val.Z < 0f ||
  3585. val.X > Scene.RegionInfo.RegionSizeX || val.Y > Scene.RegionInfo.RegionSizeY)
  3586. && !IsAttachmentCheckFull() && (backup != null && !backup.LoadingPrims))
  3587. //Don't do it when backup is loading prims, otherwise it lags the region out
  3588. {
  3589. if (Scene.RegionInfo.InfiniteRegion && !IsInTransit)
  3590. {
  3591. IsInTransit = true;
  3592. double TargetX = Scene.RegionInfo.RegionLocX + (double) val.X;
  3593. double TargetY = Scene.RegionInfo.RegionLocY + (double) val.Y;
  3594. if (m_lastSigInfiniteRegionPos.X - AbsolutePosition.X > 256 ||
  3595. m_lastSigInfiniteRegionPos.X - AbsolutePosition.X < -256 ||
  3596. m_lastSigInfiniteRegionPos.Y - AbsolutePosition.Y > 256 ||
  3597. m_lastSigInfiniteRegionPos.Y - AbsolutePosition.Y < -256)
  3598. {
  3599. m_lastSigInfiniteRegionPos = AbsolutePosition;
  3600. m_nearbyInfiniteRegions = Scene.GridService.GetRegionRange(null,
  3601. (int)(TargetX - Scene.GridService.GetMaxRegionSize()),
  3602. (int)(TargetX + 256),
  3603. (int)(TargetY - Scene.GridService.GetMaxRegionSize()),
  3604. (int)(TargetY + 256));
  3605. }
  3606. #if (!ISWIN)
  3607. GridRegion neighborRegion = null;
  3608. foreach (GridRegion region in m_nearbyInfiniteRegions)
  3609. {
  3610. if (TargetX >= region.RegionLocX && TargetY >= region.RegionLocY && TargetX < (region.RegionLocX + region.RegionSizeX) && TargetY < (region.RegionLocY + region.RegionSizeY))
  3611. {
  3612. neighborRegion = region;
  3613. break;
  3614. }
  3615. }
  3616. #else
  3617. GridRegion neighborRegion = m_nearbyInfiniteRegions.FirstOrDefault(region => TargetX >= region.RegionLocX && TargetY >= region.RegionLocY && TargetX < (region.RegionLocX + region.RegionSizeX) && TargetY < (region.RegionLocY + region.RegionSizeY));
  3618. #endif
  3619. if (neighborRegion != null)
  3620. {
  3621. //Fix the location that the prim will land
  3622. if (val.X < 0)
  3623. val.X += neighborRegion.RegionSizeX;
  3624. if (val.X > Scene.RegionInfo.RegionSizeX)
  3625. val.X -= Scene.RegionInfo.RegionSizeX;
  3626. if (val.Y < 0)
  3627. val.Y += neighborRegion.RegionSizeY;
  3628. if (val.Y > Scene.RegionInfo.RegionSizeY)
  3629. val.Y -= Scene.RegionInfo.RegionSizeY;
  3630. IEntityTransferModule transferModule = Scene.RequestModuleInterface<IEntityTransferModule>();
  3631. if (transferModule != null)
  3632. {
  3633. if (transferModule.CrossGroupToNewRegion(this, val, neighborRegion))
  3634. {
  3635. IsInTransit = false;
  3636. return;
  3637. }
  3638. }
  3639. }
  3640. IsInTransit = false;
  3641. return;
  3642. }
  3643. //If we are headed out of the region, make sure we have a region there
  3644. IGridRegisterModule neighborService = Scene.RequestModuleInterface<IGridRegisterModule>();
  3645. if (neighborService != null && !IsInTransit)
  3646. {
  3647. IsInTransit = true;
  3648. List<GridRegion> neighbors = neighborService.GetNeighbors(Scene);
  3649. int RegionCrossX = Scene.RegionInfo.RegionLocX;
  3650. int RegionCrossY = Scene.RegionInfo.RegionLocY;
  3651. if (val.X < 0f)
  3652. RegionCrossX -= Constants.RegionSize;
  3653. if (val.Y < 0f)
  3654. RegionCrossY -= Constants.RegionSize;
  3655. if (val.X > Scene.RegionInfo.RegionSizeX)
  3656. RegionCrossX += Scene.RegionInfo.RegionSizeX;
  3657. if (val.Y > Scene.RegionInfo.RegionSizeY)
  3658. RegionCrossY += Scene.RegionInfo.RegionSizeY;
  3659. GridRegion neighborRegion = neighbors.FirstOrDefault(region => region.RegionLocX == RegionCrossX && region.RegionLocY == RegionCrossY);
  3660. if (neighborRegion != null)
  3661. {
  3662. //Fix the location that the prim will land
  3663. if (val.X < 0)
  3664. val.X += neighborRegion.RegionSizeX;
  3665. if (val.X > Scene.RegionInfo.RegionSizeX)
  3666. val.X -= Scene.RegionInfo.RegionSizeX;
  3667. if (val.Y < 0)
  3668. val.Y += neighborRegion.RegionSizeY;
  3669. if (val.Y > Scene.RegionInfo.RegionSizeY)
  3670. val.Y -= Scene.RegionInfo.RegionSizeY;
  3671. IEntityTransferModule transferModule =
  3672. Scene.RequestModuleInterface<IEntityTransferModule>();
  3673. if (transferModule != null)
  3674. {
  3675. if (transferModule.CrossGroupToNewRegion(this, val, neighborRegion))
  3676. {
  3677. IsInTransit = false;
  3678. return;
  3679. }
  3680. }
  3681. }
  3682. IsInTransit = false;
  3683. //The group should have crossed a region, but no region was found so return it instead
  3684. MainConsole.Instance.Info("[SceneObjectGroup]: Returning prim " + Name + " @ " + AbsolutePosition +
  3685. " because it has gone out of bounds.");
  3686. ILLClientInventory inventoryModule = Scene.RequestModuleInterface<ILLClientInventory>();
  3687. if (inventoryModule != null)
  3688. inventoryModule.ReturnObjects(new ISceneEntity[] {this}, UUID.Zero);
  3689. return;
  3690. }
  3691. }
  3692. }
  3693. if (RootPart != null && RootPart.GetStatusSandbox())
  3694. {
  3695. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, val) > 10)
  3696. {
  3697. ScriptSetPhysicsStatus(false);
  3698. if (Scene != null)
  3699. {
  3700. IChatModule chatModule = Scene.RequestModuleInterface<IChatModule>();
  3701. if (chatModule != null)
  3702. chatModule.SimChat("Hit Sandbox Limit",
  3703. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID,
  3704. false, Scene);
  3705. }
  3706. return;
  3707. }
  3708. }
  3709. foreach (SceneObjectPart part in m_partsList)
  3710. {
  3711. part.FixGroupPositionComum(UpdatePrimActor, val, false);
  3712. }
  3713. //if (m_rootPart.PhysActor != null)
  3714. //{
  3715. //m_rootPart.PhysActor.Position =
  3716. //new PhysicsVector(m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y,
  3717. //m_rootPart.GroupPosition.Z);
  3718. //m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
  3719. //}
  3720. }
  3721. /// <summary>
  3722. /// Update the position of a single part of this scene object
  3723. /// </summary>
  3724. /// <param name = "pos"></param>
  3725. /// <param name = "localID"></param>
  3726. /// <param name="SaveUpdate"></param>
  3727. public void UpdateSinglePosition(Vector3 pos, uint localID, bool SaveUpdate)
  3728. {
  3729. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3730. if (part != null)
  3731. {
  3732. if (!SaveUpdate)
  3733. part.IgnoreUndoUpdate = true;
  3734. if (part.UUID == m_rootPart.UUID)
  3735. {
  3736. UpdateRootPosition(pos);
  3737. }
  3738. else
  3739. {
  3740. part.UpdateOffSet(pos);
  3741. }
  3742. if (!SaveUpdate)
  3743. part.IgnoreUndoUpdate = false;
  3744. HasGroupChanged = true;
  3745. }
  3746. }
  3747. ///<summary>
  3748. ///</summary>
  3749. ///<param name = "pos"></param>
  3750. public void UpdateRootPosition(Vector3 pos)
  3751. {
  3752. foreach (SceneObjectPart part in ChildrenList)
  3753. {
  3754. part.StoreUndoState();
  3755. }
  3756. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  3757. Vector3 oldPos =
  3758. IsAttachment
  3759. ? new Vector3(m_rootPart.OffsetPosition.X, m_rootPart.OffsetPosition.Y,
  3760. m_rootPart.OffsetPosition.Z)
  3761. : new Vector3(AbsolutePosition.X + m_rootPart.OffsetPosition.X,
  3762. AbsolutePosition.Y + m_rootPart.OffsetPosition.Y,
  3763. AbsolutePosition.Z + m_rootPart.OffsetPosition.Z);
  3764. Vector3 diff = oldPos - newPos;
  3765. Vector3 axDiff = new Vector3(diff.X, diff.Y, diff.Z);
  3766. Quaternion partRotation = m_rootPart.RotationOffset;
  3767. axDiff *= Quaternion.Inverse(partRotation);
  3768. diff = axDiff;
  3769. if (IsAttachment)
  3770. {
  3771. m_rootPart.FixOffsetPosition((newPos), false);
  3772. foreach (SceneObjectPart obPart in m_partsList)
  3773. {
  3774. if (obPart.UUID != m_rootPart.UUID)
  3775. {
  3776. obPart.OffsetPosition += diff;
  3777. obPart.SetGroupPosition(AbsolutePosition);
  3778. }
  3779. }
  3780. }
  3781. else
  3782. {
  3783. foreach (SceneObjectPart obPart in m_partsList)
  3784. {
  3785. if (obPart.UUID != m_rootPart.UUID)
  3786. obPart.FixOffsetPosition((obPart.OffsetPosition + diff), false);
  3787. }
  3788. AbsolutePosition = newPos;
  3789. }
  3790. HasGroupChanged = true;
  3791. ScheduleGroupTerseUpdate();
  3792. }
  3793. public void OffsetForNewRegion(Vector3 offset)
  3794. {
  3795. m_rootPart.FixGroupPosition(offset, false);
  3796. }
  3797. #endregion
  3798. #region Rotation
  3799. ///<summary>
  3800. ///</summary>
  3801. ///<param name = "rot"></param>
  3802. public void UpdateGroupRotationR(Quaternion rot)
  3803. {
  3804. foreach (SceneObjectPart parts in ChildrenList)
  3805. {
  3806. parts.StoreUndoState();
  3807. }
  3808. m_rootPart.UpdateRotation(rot);
  3809. PhysicsObject actor = m_rootPart.PhysActor;
  3810. if (actor != null)
  3811. actor.Orientation = m_rootPart.RotationOffset;
  3812. HasGroupChanged = true;
  3813. ScheduleGroupTerseUpdate();
  3814. }
  3815. ///<summary>
  3816. ///</summary>
  3817. ///<param name = "pos"></param>
  3818. ///<param name = "rot"></param>
  3819. public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
  3820. {
  3821. foreach (SceneObjectPart part in ChildrenList)
  3822. {
  3823. part.StoreUndoState();
  3824. }
  3825. m_rootPart.UpdateRotation(rot);
  3826. PhysicsObject actor = m_rootPart.PhysActor;
  3827. if (actor != null)
  3828. actor.Orientation = m_rootPart.RotationOffset;
  3829. AbsolutePosition = pos;
  3830. HasGroupChanged = true;
  3831. ScheduleGroupTerseUpdate();
  3832. }
  3833. ///<summary>
  3834. ///</summary>
  3835. ///<param name = "rot"></param>
  3836. ///<param name = "localID"></param>
  3837. public void UpdateSingleRotation(Quaternion rot, uint localID)
  3838. {
  3839. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3840. foreach (SceneObjectPart parts in ChildrenList)
  3841. {
  3842. parts.StoreUndoState();
  3843. }
  3844. if (part != null)
  3845. {
  3846. if (part.UUID == m_rootPart.UUID)
  3847. {
  3848. UpdateRootRotation(rot);
  3849. }
  3850. else
  3851. {
  3852. part.UpdateRotation(rot);
  3853. }
  3854. }
  3855. }
  3856. ///<summary>
  3857. ///</summary>
  3858. ///<param name = "rot"></param>
  3859. ///<param name="pos"></param>
  3860. ///<param name = "localID"></param>
  3861. public void UpdateSingleRotation(Quaternion rot, Vector3 pos, uint localID)
  3862. {
  3863. SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
  3864. if (part != null)
  3865. {
  3866. if (part.UUID == m_rootPart.UUID)
  3867. {
  3868. UpdateRootRotation(rot);
  3869. AbsolutePosition = pos;
  3870. }
  3871. else
  3872. {
  3873. part.StoreUndoState();
  3874. part.IgnoreUndoUpdate = true;
  3875. part.UpdateRotation(rot);
  3876. part.FixOffsetPosition(pos, true);
  3877. part.IgnoreUndoUpdate = false;
  3878. }
  3879. }
  3880. }
  3881. ///<summary>
  3882. ///</summary>
  3883. ///<param name = "rot"></param>
  3884. private void UpdateRootRotation(Quaternion rot)
  3885. {
  3886. Quaternion new_global_group_rot = rot;
  3887. Quaternion old_global_group_rot = m_rootPart.RotationOffset;
  3888. m_rootPart.UpdateRotation(rot);
  3889. if (m_rootPart.PhysActor != null)
  3890. m_rootPart.PhysActor.Orientation = m_rootPart.RotationOffset;
  3891. #if (!ISWIN)
  3892. foreach (SceneObjectPart childPrim in m_partsList)
  3893. {
  3894. if (childPrim.UUID != m_rootPart.UUID)
  3895. {
  3896. childPrim.StoreUndoState();
  3897. childPrim.IgnoreUndoUpdate = true;
  3898. // fix rotation
  3899. // get in world coords
  3900. Quaternion primsRot = old_global_group_rot*childPrim.RotationOffset;
  3901. // set new offset as inverse of the one on root
  3902. // so world is right
  3903. primsRot = Quaternion.Inverse(new_global_group_rot)*primsRot;
  3904. // just store it
  3905. childPrim.SetRotationOffset(false, primsRot, false);
  3906. // fix position offset
  3907. Vector3 axPos = childPrim.OffsetPosition;
  3908. axPos *= old_global_group_rot;
  3909. axPos *= Quaternion.Inverse(new_global_group_rot);
  3910. // store it and let physics know about both changes
  3911. childPrim.FixOffsetPosition(axPos, true);
  3912. childPrim.ScheduleTerseUpdate();
  3913. childPrim.IgnoreUndoUpdate = false;
  3914. }
  3915. }
  3916. #else
  3917. foreach (SceneObjectPart childPrim in m_partsList.Where(childPrim => childPrim.UUID != m_rootPart.UUID))
  3918. {
  3919. childPrim.StoreUndoState();
  3920. childPrim.IgnoreUndoUpdate = true;
  3921. // fix rotation
  3922. // get in world coords
  3923. Quaternion primsRot = old_global_group_rot * childPrim.RotationOffset;
  3924. // set new offset as inverse of the one on root
  3925. // so world is right
  3926. primsRot = Quaternion.Inverse(new_global_group_rot) * primsRot;
  3927. // just store it
  3928. childPrim.SetRotationOffset(false, primsRot, false);
  3929. // fix position offset
  3930. Vector3 axPos = childPrim.OffsetPosition;
  3931. axPos *= old_global_group_rot;
  3932. axPos *= Quaternion.Inverse(new_global_group_rot);
  3933. // store it and let physics know about both changes
  3934. childPrim.FixOffsetPosition(axPos, true);
  3935. childPrim.ScheduleTerseUpdate();
  3936. childPrim.IgnoreUndoUpdate = false;
  3937. }
  3938. #endif
  3939. m_rootPart.ScheduleTerseUpdate();
  3940. }
  3941. #endregion
  3942. }
  3943. }