SceneObjectGroup.cs 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.ComponentModel;
  29. using System.Collections.Generic;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Linq;
  33. using System.Threading;
  34. using System.Xml;
  35. using System.Xml.Serialization;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Packets;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Physics.Manager;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using PermissionMask = OpenSim.Framework.PermissionMask;
  43. namespace OpenSim.Region.Framework.Scenes
  44. {
  45. [Flags]
  46. public enum scriptEvents
  47. {
  48. None = 0,
  49. attach = 1,
  50. collision = 16,
  51. collision_end = 32,
  52. collision_start = 64,
  53. control = 128,
  54. dataserver = 256,
  55. email = 512,
  56. http_response = 1024,
  57. land_collision = 2048,
  58. land_collision_end = 4096,
  59. land_collision_start = 8192,
  60. at_target = 16384,
  61. at_rot_target = 16777216,
  62. listen = 32768,
  63. money = 65536,
  64. moving_end = 131072,
  65. moving_start = 262144,
  66. not_at_rot_target = 524288,
  67. not_at_target = 1048576,
  68. remote_data = 8388608,
  69. run_time_permissions = 268435456,
  70. state_entry = 1073741824,
  71. state_exit = 2,
  72. timer = 4,
  73. touch = 8,
  74. touch_end = 536870912,
  75. touch_start = 2097152,
  76. object_rez = 4194304
  77. }
  78. struct scriptPosTarget
  79. {
  80. public Vector3 targetPos;
  81. public float tolerance;
  82. public uint handle;
  83. }
  84. struct scriptRotTarget
  85. {
  86. public Quaternion targetRot;
  87. public float tolerance;
  88. public uint handle;
  89. }
  90. public delegate void PrimCountTaintedDelegate();
  91. /// <summary>
  92. /// A scene object group is conceptually an object in the scene. The object is constituted of SceneObjectParts
  93. /// (often known as prims), one of which is considered the root part.
  94. /// </summary>
  95. public partial class SceneObjectGroup : EntityBase, ISceneObject
  96. {
  97. // Axis selection bitmask used by SetAxisRotation()
  98. // Just happen to be the same bits used by llSetStatus() and defined in ScriptBaseClass.
  99. public enum axisSelect : int
  100. {
  101. STATUS_ROTATE_X = 0x002,
  102. STATUS_ROTATE_Y = 0x004,
  103. STATUS_ROTATE_Z = 0x008,
  104. }
  105. // This flag has the same purpose as InventoryItemFlags.ObjectSlamPerm
  106. public static readonly uint SLAM = 16;
  107. // private PrimCountTaintedDelegate handlerPrimCountTainted = null;
  108. /// <summary>
  109. /// Signal whether the non-inventory attributes of any prims in the group have changed
  110. /// since the group's last persistent backup
  111. /// </summary>
  112. private bool m_hasGroupChanged = false;
  113. private long timeFirstChanged;
  114. private long timeLastChanged;
  115. /// <summary>
  116. /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage
  117. /// (the database).
  118. /// </summary>
  119. /// <remarks>
  120. /// Ultimately, this should be managed such that region modules can change it at the end of a set of operations
  121. /// so that either all changes are preserved or none at all. However, currently, a large amount of internal
  122. /// code will set this anyway when some object properties are changed.
  123. /// </remarks>
  124. public bool HasGroupChanged
  125. {
  126. set
  127. {
  128. if (value)
  129. {
  130. timeLastChanged = DateTime.Now.Ticks;
  131. if (!m_hasGroupChanged)
  132. timeFirstChanged = DateTime.Now.Ticks;
  133. }
  134. m_hasGroupChanged = value;
  135. // m_log.DebugFormat(
  136. // "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId);
  137. }
  138. get { return m_hasGroupChanged; }
  139. }
  140. /// <summary>
  141. /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since
  142. /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation.
  143. /// </summary>
  144. public bool HasGroupChangedDueToDelink { get; private set; }
  145. private bool isTimeToPersist()
  146. {
  147. if (IsSelected || IsDeleted || IsAttachment)
  148. return false;
  149. if (!m_hasGroupChanged)
  150. return false;
  151. if (m_scene.ShuttingDown)
  152. return true;
  153. long currentTime = DateTime.Now.Ticks;
  154. if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter)
  155. return true;
  156. return false;
  157. }
  158. /// <summary>
  159. /// Is this scene object acting as an attachment?
  160. /// </summary>
  161. public bool IsAttachment { get; set; }
  162. /// <summary>
  163. /// The avatar to which this scene object is attached.
  164. /// </summary>
  165. /// <remarks>
  166. /// If we're not attached to an avatar then this is UUID.Zero
  167. /// </remarks>
  168. public UUID AttachedAvatar { get; set; }
  169. /// <summary>
  170. /// Attachment point of this scene object to an avatar.
  171. /// </summary>
  172. /// <remarks>
  173. /// 0 if we're not attached to anything
  174. /// </remarks>
  175. public uint AttachmentPoint
  176. {
  177. get
  178. {
  179. return m_rootPart.Shape.State;
  180. }
  181. set
  182. {
  183. IsAttachment = value != 0;
  184. m_rootPart.Shape.State = (byte)value;
  185. }
  186. }
  187. /// <summary>
  188. /// If this scene object has an attachment point then indicate whether there is a point where
  189. /// attachments are perceivable by avatars other than the avatar to which this object is attached.
  190. /// </summary>
  191. /// <remarks>
  192. /// HUDs are not perceivable by other avatars.
  193. /// </remarks>
  194. public bool HasPrivateAttachmentPoint
  195. {
  196. get
  197. {
  198. return AttachmentPoint >= (uint)OpenMetaverse.AttachmentPoint.HUDCenter2
  199. && AttachmentPoint <= (uint)OpenMetaverse.AttachmentPoint.HUDBottomRight;
  200. }
  201. }
  202. public void ClearPartAttachmentData()
  203. {
  204. AttachmentPoint = 0;
  205. // Even though we don't use child part state parameters for attachments any more, we still need to set
  206. // these to zero since having them non-zero in rezzed scene objects will crash some clients. Even if
  207. // we store them correctly, scene objects that we receive from elsewhere might not.
  208. foreach (SceneObjectPart part in Parts)
  209. part.Shape.State = 0;
  210. }
  211. /// <summary>
  212. /// Is this scene object phantom?
  213. /// </summary>
  214. /// <remarks>
  215. /// Updating must currently take place through UpdatePrimFlags()
  216. /// </remarks>
  217. public bool IsPhantom
  218. {
  219. get { return (RootPart.Flags & PrimFlags.Phantom) != 0; }
  220. }
  221. /// <summary>
  222. /// Does this scene object use physics?
  223. /// </summary>
  224. /// <remarks>
  225. /// Updating must currently take place through UpdatePrimFlags()
  226. /// </remarks>
  227. public bool UsesPhysics
  228. {
  229. get { return (RootPart.Flags & PrimFlags.Physics) != 0; }
  230. }
  231. /// <summary>
  232. /// Is this scene object temporary?
  233. /// </summary>
  234. /// <remarks>
  235. /// Updating must currently take place through UpdatePrimFlags()
  236. /// </remarks>
  237. public bool IsTemporary
  238. {
  239. get { return (RootPart.Flags & PrimFlags.TemporaryOnRez) != 0; }
  240. }
  241. public bool IsVolumeDetect
  242. {
  243. get { return RootPart.VolumeDetectActive; }
  244. }
  245. private Vector3 lastPhysGroupPos;
  246. private Quaternion lastPhysGroupRot;
  247. private bool m_isBackedUp;
  248. protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>();
  249. protected ulong m_regionHandle;
  250. protected SceneObjectPart m_rootPart;
  251. // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  252. private Dictionary<uint, scriptPosTarget> m_targets = new Dictionary<uint, scriptPosTarget>();
  253. private Dictionary<uint, scriptRotTarget> m_rotTargets = new Dictionary<uint, scriptRotTarget>();
  254. private bool m_scriptListens_atTarget;
  255. private bool m_scriptListens_notAtTarget;
  256. private bool m_scriptListens_atRotTarget;
  257. private bool m_scriptListens_notAtRotTarget;
  258. internal Dictionary<UUID, string> m_savedScriptState;
  259. #region Properties
  260. /// <summary>
  261. /// The name of an object grouping is always the same as its root part
  262. /// </summary>
  263. public override string Name
  264. {
  265. get { return RootPart.Name; }
  266. set { RootPart.Name = value; }
  267. }
  268. public string Description
  269. {
  270. get { return RootPart.Description; }
  271. set { RootPart.Description = value; }
  272. }
  273. /// <summary>
  274. /// Added because the Parcel code seems to use it
  275. /// but not sure a object should have this
  276. /// as what does it tell us? that some avatar has selected it (but not what Avatar/user)
  277. /// think really there should be a list (or whatever) in each scenepresence
  278. /// saying what prim(s) that user has selected.
  279. /// </summary>
  280. protected bool m_isSelected = false;
  281. /// <summary>
  282. /// Number of prims in this group
  283. /// </summary>
  284. public int PrimCount
  285. {
  286. get { return m_parts.Count; }
  287. }
  288. public Quaternion GroupRotation
  289. {
  290. get { return m_rootPart.RotationOffset; }
  291. }
  292. public Vector3 GroupScale
  293. {
  294. get
  295. {
  296. Vector3 minScale = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionSize);
  297. Vector3 maxScale = Vector3.Zero;
  298. Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
  299. SceneObjectPart[] parts = m_parts.GetArray();
  300. for (int i = 0; i < parts.Length; i++)
  301. {
  302. SceneObjectPart part = parts[i];
  303. Vector3 partscale = part.Scale;
  304. Vector3 partoffset = part.OffsetPosition;
  305. minScale.X = (partscale.X + partoffset.X < minScale.X) ? partscale.X + partoffset.X : minScale.X;
  306. minScale.Y = (partscale.Y + partoffset.Y < minScale.Y) ? partscale.Y + partoffset.Y : minScale.Y;
  307. minScale.Z = (partscale.Z + partoffset.Z < minScale.Z) ? partscale.Z + partoffset.Z : minScale.Z;
  308. maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X;
  309. maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y;
  310. maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
  311. }
  312. finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
  313. finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
  314. finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
  315. return finalScale;
  316. }
  317. }
  318. public UUID GroupID
  319. {
  320. get { return m_rootPart.GroupID; }
  321. set { m_rootPart.GroupID = value; }
  322. }
  323. public SceneObjectPart[] Parts
  324. {
  325. get { return m_parts.GetArray(); }
  326. }
  327. public bool ContainsPart(UUID partID)
  328. {
  329. return m_parts.ContainsKey(partID);
  330. }
  331. /// <summary>
  332. /// Does this group contain the given part?
  333. /// should be able to remove these methods once we have a entity index in scene
  334. /// </summary>
  335. /// <param name="localID"></param>
  336. /// <returns></returns>
  337. public bool ContainsPart(uint localID)
  338. {
  339. SceneObjectPart[] parts = m_parts.GetArray();
  340. for (int i = 0; i < parts.Length; i++)
  341. {
  342. if (parts[i].LocalId == localID)
  343. return true;
  344. }
  345. return false;
  346. }
  347. /// <value>
  348. /// The root part of this scene object
  349. /// </value>
  350. public SceneObjectPart RootPart
  351. {
  352. get { return m_rootPart; }
  353. }
  354. public ulong RegionHandle
  355. {
  356. get { return m_regionHandle; }
  357. set
  358. {
  359. m_regionHandle = value;
  360. SceneObjectPart[] parts = m_parts.GetArray();
  361. for (int i = 0; i < parts.Length; i++)
  362. parts[i].RegionHandle = value;
  363. }
  364. }
  365. /// <summary>
  366. /// Check both the attachment property and the relevant properties of the underlying root part.
  367. /// </summary>
  368. /// <remarks>
  369. /// This is necessary in some cases, particularly when a scene object has just crossed into a region and doesn't
  370. /// have the IsAttachment property yet checked.
  371. ///
  372. /// FIXME: However, this should be fixed so that this property
  373. /// propertly reflects the underlying status.
  374. /// </remarks>
  375. /// <returns></returns>
  376. public bool IsAttachmentCheckFull()
  377. {
  378. return (IsAttachment || (m_rootPart.Shape.PCode == 9 && m_rootPart.Shape.State != 0));
  379. }
  380. /// <summary>
  381. /// The absolute position of this scene object in the scene
  382. /// </summary>
  383. public override Vector3 AbsolutePosition
  384. {
  385. get { return m_rootPart.GroupPosition; }
  386. set
  387. {
  388. Vector3 val = value;
  389. if (Scene != null)
  390. {
  391. if (
  392. // (Scene.TestBorderCross(val - Vector3.UnitX, Cardinals.E)
  393. // || Scene.TestBorderCross(val + Vector3.UnitX, Cardinals.W)
  394. // || Scene.TestBorderCross(val - Vector3.UnitY, Cardinals.N)
  395. // || Scene.TestBorderCross(val + Vector3.UnitY, Cardinals.S))
  396. // Experimental change for better border crossings.
  397. // The commented out original lines above would, it seems, trigger
  398. // a border crossing a little early or late depending on which
  399. // direction the object was moving.
  400. (Scene.TestBorderCross(val, Cardinals.E)
  401. || Scene.TestBorderCross(val, Cardinals.W)
  402. || Scene.TestBorderCross(val, Cardinals.N)
  403. || Scene.TestBorderCross(val, Cardinals.S))
  404. && !IsAttachmentCheckFull() && (!Scene.LoadingPrims))
  405. {
  406. if (m_rootPart.KeyframeMotion != null)
  407. m_rootPart.KeyframeMotion.StartCrossingCheck();
  408. m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
  409. }
  410. }
  411. if (RootPart.GetStatusSandbox())
  412. {
  413. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
  414. {
  415. RootPart.ScriptSetPhysicsStatus(false);
  416. if (Scene != null)
  417. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  418. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  419. return;
  420. }
  421. }
  422. // Restuff the new GroupPosition into each SOP of the linkset.
  423. // This has the affect of resetting and tainting the physics actors.
  424. SceneObjectPart[] parts = m_parts.GetArray();
  425. for (int i = 0; i < parts.Length; i++)
  426. parts[i].GroupPosition = val;
  427. //if (m_rootPart.PhysActor != null)
  428. //{
  429. //m_rootPart.PhysActor.Position =
  430. //new PhysicsVector(m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y,
  431. //m_rootPart.GroupPosition.Z);
  432. //m_scene.PhysicsScene.AddPhysicsActorTaint(m_rootPart.PhysActor);
  433. //}
  434. if (Scene != null)
  435. Scene.EventManager.TriggerParcelPrimCountTainted();
  436. }
  437. }
  438. public override uint LocalId
  439. {
  440. get { return m_rootPart.LocalId; }
  441. set { m_rootPart.LocalId = value; }
  442. }
  443. public override UUID UUID
  444. {
  445. get { return m_rootPart.UUID; }
  446. set
  447. {
  448. lock (m_parts.SyncRoot)
  449. {
  450. m_parts.Remove(m_rootPart.UUID);
  451. m_rootPart.UUID = value;
  452. m_parts.Add(value, m_rootPart);
  453. }
  454. }
  455. }
  456. public UUID LastOwnerID
  457. {
  458. get { return m_rootPart.LastOwnerID; }
  459. set { m_rootPart.LastOwnerID = value; }
  460. }
  461. public UUID OwnerID
  462. {
  463. get { return m_rootPart.OwnerID; }
  464. set { m_rootPart.OwnerID = value; }
  465. }
  466. public float Damage
  467. {
  468. get { return m_rootPart.Damage; }
  469. set { m_rootPart.Damage = value; }
  470. }
  471. public Color Color
  472. {
  473. get { return m_rootPart.Color; }
  474. set { m_rootPart.Color = value; }
  475. }
  476. public string Text
  477. {
  478. get {
  479. string returnstr = m_rootPart.Text;
  480. if (returnstr.Length > 255)
  481. {
  482. returnstr = returnstr.Substring(0, 255);
  483. }
  484. return returnstr;
  485. }
  486. set { m_rootPart.Text = value; }
  487. }
  488. protected virtual bool InSceneBackup
  489. {
  490. get { return true; }
  491. }
  492. public bool IsSelected
  493. {
  494. get { return m_isSelected; }
  495. set
  496. {
  497. m_isSelected = value;
  498. // Tell physics engine that group is selected
  499. PhysicsActor pa = m_rootPart.PhysActor;
  500. if (pa != null)
  501. {
  502. pa.Selected = value;
  503. // Pass it on to the children.
  504. SceneObjectPart[] parts = m_parts.GetArray();
  505. for (int i = 0; i < parts.Length; i++)
  506. {
  507. SceneObjectPart child = parts[i];
  508. PhysicsActor childPa = child.PhysActor;
  509. if (childPa != null)
  510. childPa.Selected = value;
  511. }
  512. }
  513. if (RootPart.KeyframeMotion != null)
  514. RootPart.KeyframeMotion.Selected = value;
  515. }
  516. }
  517. private SceneObjectPart m_PlaySoundMasterPrim = null;
  518. public SceneObjectPart PlaySoundMasterPrim
  519. {
  520. get { return m_PlaySoundMasterPrim; }
  521. set { m_PlaySoundMasterPrim = value; }
  522. }
  523. private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
  524. public List<SceneObjectPart> PlaySoundSlavePrims
  525. {
  526. get { return m_PlaySoundSlavePrims; }
  527. set { m_PlaySoundSlavePrims = value; }
  528. }
  529. private SceneObjectPart m_LoopSoundMasterPrim = null;
  530. public SceneObjectPart LoopSoundMasterPrim
  531. {
  532. get { return m_LoopSoundMasterPrim; }
  533. set { m_LoopSoundMasterPrim = value; }
  534. }
  535. private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
  536. public List<SceneObjectPart> LoopSoundSlavePrims
  537. {
  538. get { return m_LoopSoundSlavePrims; }
  539. set { m_LoopSoundSlavePrims = value; }
  540. }
  541. /// <summary>
  542. /// The UUID for the region this object is in.
  543. /// </summary>
  544. public UUID RegionUUID
  545. {
  546. get
  547. {
  548. if (m_scene != null)
  549. {
  550. return m_scene.RegionInfo.RegionID;
  551. }
  552. return UUID.Zero;
  553. }
  554. }
  555. /// <summary>
  556. /// The item ID that this object was rezzed from, if applicable.
  557. /// </summary>
  558. /// <remarks>
  559. /// If not applicable will be UUID.Zero
  560. /// </remarks>
  561. public UUID FromItemID { get; set; }
  562. /// <summary>
  563. /// Refers to the SceneObjectPart.UUID property of the object that this object was rezzed from, if applicable.
  564. /// </summary>
  565. /// <remarks>
  566. /// If not applicable will be UUID.Zero
  567. /// </remarks>
  568. public UUID FromPartID { get; set; }
  569. /// <summary>
  570. /// The folder ID that this object was rezzed from, if applicable.
  571. /// </summary>
  572. /// <remarks>
  573. /// If not applicable will be UUID.Zero
  574. /// </remarks>
  575. public UUID FromFolderID { get; set; }
  576. /// <summary>
  577. /// IDs of all avatars sat on this scene object.
  578. /// </summary>
  579. /// <remarks>
  580. /// We need this so that we can maintain a linkset wide ordering of avatars sat on different parts.
  581. /// This must be locked before it is read or written.
  582. /// SceneObjectPart sitting avatar add/remove code also locks on this object to avoid race conditions.
  583. /// No avatar should appear more than once in this list.
  584. /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart.
  585. /// </remarks>
  586. protected internal List<UUID> m_sittingAvatars = new List<UUID>();
  587. #endregion
  588. // ~SceneObjectGroup()
  589. // {
  590. // //m_log.DebugFormat("[SCENE OBJECT GROUP]: Destructor called for {0}, local id {1}", Name, LocalId);
  591. // Console.WriteLine("Destructor called for {0}, local id {1}", Name, LocalId);
  592. // }
  593. #region Constructors
  594. /// <summary>
  595. /// Constructor
  596. /// </summary>
  597. public SceneObjectGroup()
  598. {
  599. }
  600. /// <summary>
  601. /// This constructor creates a SceneObjectGroup using a pre-existing SceneObjectPart.
  602. /// The original SceneObjectPart will be used rather than a copy, preserving
  603. /// its existing localID and UUID.
  604. /// </summary>
  605. /// <param name='part'>Root part for this scene object.</param>
  606. public SceneObjectGroup(SceneObjectPart part) : this()
  607. {
  608. SetRootPart(part);
  609. }
  610. /// <summary>
  611. /// Constructor. This object is added to the scene later via AttachToScene()
  612. /// </summary>
  613. public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
  614. :this(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero))
  615. {
  616. }
  617. /// <summary>
  618. /// Constructor.
  619. /// </summary>
  620. public SceneObjectGroup(UUID ownerID, Vector3 pos, PrimitiveBaseShape shape)
  621. : this(ownerID, pos, Quaternion.Identity, shape)
  622. {
  623. }
  624. public void LoadScriptState(XmlDocument doc)
  625. {
  626. XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState");
  627. if (nodes.Count > 0)
  628. {
  629. if (m_savedScriptState == null)
  630. m_savedScriptState = new Dictionary<UUID, string>();
  631. foreach (XmlNode node in nodes)
  632. {
  633. if (node.Attributes["UUID"] != null)
  634. {
  635. UUID itemid = new UUID(node.Attributes["UUID"].Value);
  636. if (itemid != UUID.Zero)
  637. m_savedScriptState[itemid] = node.InnerXml;
  638. }
  639. }
  640. }
  641. }
  642. /// <summary>
  643. /// Hooks this object up to the backup event so that it is persisted to the database when the update thread executes.
  644. /// </summary>
  645. public virtual void AttachToBackup()
  646. {
  647. if (InSceneBackup)
  648. {
  649. //m_log.DebugFormat(
  650. // "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID);
  651. if (!m_isBackedUp)
  652. m_scene.EventManager.OnBackup += ProcessBackup;
  653. m_isBackedUp = true;
  654. }
  655. }
  656. /// <summary>
  657. /// Attach this object to a scene. It will also now appear to agents.
  658. /// </summary>
  659. /// <param name="scene"></param>
  660. public void AttachToScene(Scene scene)
  661. {
  662. m_scene = scene;
  663. RegionHandle = m_scene.RegionInfo.RegionHandle;
  664. if (m_rootPart.Shape.PCode != 9 || m_rootPart.Shape.State == 0)
  665. m_rootPart.ParentID = 0;
  666. if (m_rootPart.LocalId == 0)
  667. m_rootPart.LocalId = m_scene.AllocateLocalId();
  668. SceneObjectPart[] parts = m_parts.GetArray();
  669. for (int i = 0; i < parts.Length; i++)
  670. {
  671. SceneObjectPart part = parts[i];
  672. if (part.KeyframeMotion != null)
  673. {
  674. part.KeyframeMotion.UpdateSceneObject(this);
  675. }
  676. if (Object.ReferenceEquals(part, m_rootPart))
  677. continue;
  678. if (part.LocalId == 0)
  679. part.LocalId = m_scene.AllocateLocalId();
  680. part.ParentID = m_rootPart.LocalId;
  681. //m_log.DebugFormat("[SCENE]: Given local id {0} to part {1}, linknum {2}, parent {3} {4}", part.LocalId, part.UUID, part.LinkNum, part.ParentID, part.ParentUUID);
  682. }
  683. ApplyPhysics();
  684. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  685. // for the same object with very different properties. The caller must schedule the update.
  686. //ScheduleGroupForFullUpdate();
  687. }
  688. public EntityIntersection TestIntersection(Ray hRay, bool frontFacesOnly, bool faceCenters)
  689. {
  690. // We got a request from the inner_scene to raytrace along the Ray hRay
  691. // We're going to check all of the prim in this group for intersection with the ray
  692. // If we get a result, we're going to find the closest result to the origin of the ray
  693. // and send back the intersection information back to the innerscene.
  694. EntityIntersection result = new EntityIntersection();
  695. SceneObjectPart[] parts = m_parts.GetArray();
  696. for (int i = 0; i < parts.Length; i++)
  697. {
  698. SceneObjectPart part = parts[i];
  699. // Temporary commented to stop compiler warning
  700. //Vector3 partPosition =
  701. // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
  702. Quaternion parentrotation = GroupRotation;
  703. // Telling the prim to raytrace.
  704. //EntityIntersection inter = part.TestIntersection(hRay, parentrotation);
  705. EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
  706. // This may need to be updated to the maximum draw distance possible..
  707. // We might (and probably will) be checking for prim creation from other sims
  708. // when the camera crosses the border.
  709. float idist = Constants.RegionSize;
  710. if (inter.HitTF)
  711. {
  712. // We need to find the closest prim to return to the testcaller along the ray
  713. if (inter.distance < idist)
  714. {
  715. result.HitTF = true;
  716. result.ipoint = inter.ipoint;
  717. result.obj = part;
  718. result.normal = inter.normal;
  719. result.distance = inter.distance;
  720. }
  721. }
  722. }
  723. return result;
  724. }
  725. /// <summary>
  726. /// Gets a vector representing the size of the bounding box containing all the prims in the group
  727. /// Treats all prims as rectangular, so no shape (cut etc) is taken into account
  728. /// offsetHeight is the offset in the Z axis from the centre of the bounding box to the centre of the root prim
  729. /// </summary>
  730. /// <returns></returns>
  731. public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ)
  732. {
  733. maxX = -256f;
  734. maxY = -256f;
  735. maxZ = -256f;
  736. minX = 256f;
  737. minY = 256f;
  738. minZ = 8192f;
  739. SceneObjectPart[] parts = m_parts.GetArray();
  740. for (int i = 0; i < parts.Length; i++)
  741. {
  742. SceneObjectPart part = parts[i];
  743. Vector3 worldPos = part.GetWorldPosition();
  744. Vector3 offset = worldPos - AbsolutePosition;
  745. Quaternion worldRot;
  746. if (part.ParentID == 0)
  747. worldRot = part.RotationOffset;
  748. else
  749. worldRot = part.GetWorldRotation();
  750. Vector3 frontTopLeft;
  751. Vector3 frontTopRight;
  752. Vector3 frontBottomLeft;
  753. Vector3 frontBottomRight;
  754. Vector3 backTopLeft;
  755. Vector3 backTopRight;
  756. Vector3 backBottomLeft;
  757. Vector3 backBottomRight;
  758. Vector3 orig = Vector3.Zero;
  759. frontTopLeft.X = orig.X - (part.Scale.X / 2);
  760. frontTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  761. frontTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  762. frontTopRight.X = orig.X - (part.Scale.X / 2);
  763. frontTopRight.Y = orig.Y + (part.Scale.Y / 2);
  764. frontTopRight.Z = orig.Z + (part.Scale.Z / 2);
  765. frontBottomLeft.X = orig.X - (part.Scale.X / 2);
  766. frontBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  767. frontBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  768. frontBottomRight.X = orig.X - (part.Scale.X / 2);
  769. frontBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  770. frontBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  771. backTopLeft.X = orig.X + (part.Scale.X / 2);
  772. backTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  773. backTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  774. backTopRight.X = orig.X + (part.Scale.X / 2);
  775. backTopRight.Y = orig.Y + (part.Scale.Y / 2);
  776. backTopRight.Z = orig.Z + (part.Scale.Z / 2);
  777. backBottomLeft.X = orig.X + (part.Scale.X / 2);
  778. backBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  779. backBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  780. backBottomRight.X = orig.X + (part.Scale.X / 2);
  781. backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  782. backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  783. frontTopLeft = frontTopLeft * worldRot;
  784. frontTopRight = frontTopRight * worldRot;
  785. frontBottomLeft = frontBottomLeft * worldRot;
  786. frontBottomRight = frontBottomRight * worldRot;
  787. backBottomLeft = backBottomLeft * worldRot;
  788. backBottomRight = backBottomRight * worldRot;
  789. backTopLeft = backTopLeft * worldRot;
  790. backTopRight = backTopRight * worldRot;
  791. frontTopLeft += offset;
  792. frontTopRight += offset;
  793. frontBottomLeft += offset;
  794. frontBottomRight += offset;
  795. backBottomLeft += offset;
  796. backBottomRight += offset;
  797. backTopLeft += offset;
  798. backTopRight += offset;
  799. if (frontTopRight.X > maxX)
  800. maxX = frontTopRight.X;
  801. if (frontTopLeft.X > maxX)
  802. maxX = frontTopLeft.X;
  803. if (frontBottomRight.X > maxX)
  804. maxX = frontBottomRight.X;
  805. if (frontBottomLeft.X > maxX)
  806. maxX = frontBottomLeft.X;
  807. if (backTopRight.X > maxX)
  808. maxX = backTopRight.X;
  809. if (backTopLeft.X > maxX)
  810. maxX = backTopLeft.X;
  811. if (backBottomRight.X > maxX)
  812. maxX = backBottomRight.X;
  813. if (backBottomLeft.X > maxX)
  814. maxX = backBottomLeft.X;
  815. if (frontTopRight.X < minX)
  816. minX = frontTopRight.X;
  817. if (frontTopLeft.X < minX)
  818. minX = frontTopLeft.X;
  819. if (frontBottomRight.X < minX)
  820. minX = frontBottomRight.X;
  821. if (frontBottomLeft.X < minX)
  822. minX = frontBottomLeft.X;
  823. if (backTopRight.X < minX)
  824. minX = backTopRight.X;
  825. if (backTopLeft.X < minX)
  826. minX = backTopLeft.X;
  827. if (backBottomRight.X < minX)
  828. minX = backBottomRight.X;
  829. if (backBottomLeft.X < minX)
  830. minX = backBottomLeft.X;
  831. //
  832. if (frontTopRight.Y > maxY)
  833. maxY = frontTopRight.Y;
  834. if (frontTopLeft.Y > maxY)
  835. maxY = frontTopLeft.Y;
  836. if (frontBottomRight.Y > maxY)
  837. maxY = frontBottomRight.Y;
  838. if (frontBottomLeft.Y > maxY)
  839. maxY = frontBottomLeft.Y;
  840. if (backTopRight.Y > maxY)
  841. maxY = backTopRight.Y;
  842. if (backTopLeft.Y > maxY)
  843. maxY = backTopLeft.Y;
  844. if (backBottomRight.Y > maxY)
  845. maxY = backBottomRight.Y;
  846. if (backBottomLeft.Y > maxY)
  847. maxY = backBottomLeft.Y;
  848. if (frontTopRight.Y < minY)
  849. minY = frontTopRight.Y;
  850. if (frontTopLeft.Y < minY)
  851. minY = frontTopLeft.Y;
  852. if (frontBottomRight.Y < minY)
  853. minY = frontBottomRight.Y;
  854. if (frontBottomLeft.Y < minY)
  855. minY = frontBottomLeft.Y;
  856. if (backTopRight.Y < minY)
  857. minY = backTopRight.Y;
  858. if (backTopLeft.Y < minY)
  859. minY = backTopLeft.Y;
  860. if (backBottomRight.Y < minY)
  861. minY = backBottomRight.Y;
  862. if (backBottomLeft.Y < minY)
  863. minY = backBottomLeft.Y;
  864. //
  865. if (frontTopRight.Z > maxZ)
  866. maxZ = frontTopRight.Z;
  867. if (frontTopLeft.Z > maxZ)
  868. maxZ = frontTopLeft.Z;
  869. if (frontBottomRight.Z > maxZ)
  870. maxZ = frontBottomRight.Z;
  871. if (frontBottomLeft.Z > maxZ)
  872. maxZ = frontBottomLeft.Z;
  873. if (backTopRight.Z > maxZ)
  874. maxZ = backTopRight.Z;
  875. if (backTopLeft.Z > maxZ)
  876. maxZ = backTopLeft.Z;
  877. if (backBottomRight.Z > maxZ)
  878. maxZ = backBottomRight.Z;
  879. if (backBottomLeft.Z > maxZ)
  880. maxZ = backBottomLeft.Z;
  881. if (frontTopRight.Z < minZ)
  882. minZ = frontTopRight.Z;
  883. if (frontTopLeft.Z < minZ)
  884. minZ = frontTopLeft.Z;
  885. if (frontBottomRight.Z < minZ)
  886. minZ = frontBottomRight.Z;
  887. if (frontBottomLeft.Z < minZ)
  888. minZ = frontBottomLeft.Z;
  889. if (backTopRight.Z < minZ)
  890. minZ = backTopRight.Z;
  891. if (backTopLeft.Z < minZ)
  892. minZ = backTopLeft.Z;
  893. if (backBottomRight.Z < minZ)
  894. minZ = backBottomRight.Z;
  895. if (backBottomLeft.Z < minZ)
  896. minZ = backBottomLeft.Z;
  897. }
  898. }
  899. public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
  900. {
  901. float minX;
  902. float maxX;
  903. float minY;
  904. float maxY;
  905. float minZ;
  906. float maxZ;
  907. GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  908. Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
  909. offsetHeight = 0;
  910. float lower = (minZ * -1);
  911. if (lower > maxZ)
  912. {
  913. offsetHeight = lower - (boundingBox.Z / 2);
  914. }
  915. else if (maxZ > lower)
  916. {
  917. offsetHeight = maxZ - (boundingBox.Z / 2);
  918. offsetHeight *= -1;
  919. }
  920. // m_log.InfoFormat("BoundingBox is {0} , {1} , {2} ", boundingBox.X, boundingBox.Y, boundingBox.Z);
  921. return boundingBox;
  922. }
  923. #endregion
  924. public void SaveScriptedState(XmlTextWriter writer)
  925. {
  926. XmlDocument doc = new XmlDocument();
  927. Dictionary<UUID,string> states = new Dictionary<UUID,string>();
  928. SceneObjectPart[] parts = m_parts.GetArray();
  929. for (int i = 0; i < parts.Length; i++)
  930. {
  931. Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates();
  932. foreach (KeyValuePair<UUID, string> kvp in pstates)
  933. states.Add(kvp.Key, kvp.Value);
  934. }
  935. if (states.Count > 0)
  936. {
  937. // Now generate the necessary XML wrappings
  938. writer.WriteStartElement(String.Empty, "GroupScriptStates", String.Empty);
  939. foreach (UUID itemid in states.Keys)
  940. {
  941. doc.LoadXml(states[itemid]);
  942. writer.WriteStartElement(String.Empty, "SavedScriptState", String.Empty);
  943. writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
  944. writer.WriteRaw(doc.DocumentElement.OuterXml); // Writes ScriptState element
  945. writer.WriteEndElement(); // End of SavedScriptState
  946. }
  947. writer.WriteEndElement(); // End of GroupScriptStates
  948. }
  949. }
  950. /// <summary>
  951. ///
  952. /// </summary>
  953. /// <param name="part"></param>
  954. private void SetPartAsNonRoot(SceneObjectPart part)
  955. {
  956. part.ParentID = m_rootPart.LocalId;
  957. part.ClearUndoState();
  958. }
  959. public ushort GetTimeDilation()
  960. {
  961. return Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  962. }
  963. /// <summary>
  964. /// Set a part to act as the root part for this scene object
  965. /// </summary>
  966. /// <param name="part"></param>
  967. public void SetRootPart(SceneObjectPart part)
  968. {
  969. if (part == null)
  970. throw new ArgumentNullException("Cannot give SceneObjectGroup a null root SceneObjectPart");
  971. part.SetParent(this);
  972. m_rootPart = part;
  973. if (!IsAttachment)
  974. part.ParentID = 0;
  975. part.LinkNum = 0;
  976. m_parts.Add(m_rootPart.UUID, m_rootPart);
  977. }
  978. /// <summary>
  979. /// Add a new part to this scene object. The part must already be correctly configured.
  980. /// </summary>
  981. /// <param name="part"></param>
  982. public void AddPart(SceneObjectPart part)
  983. {
  984. part.SetParent(this);
  985. part.LinkNum = m_parts.Add(part.UUID, part);
  986. if (part.LinkNum == 2)
  987. RootPart.LinkNum = 1;
  988. }
  989. /// <summary>
  990. /// Make sure that every non root part has the proper parent root part local id
  991. /// </summary>
  992. private void UpdateParentIDs()
  993. {
  994. SceneObjectPart[] parts = m_parts.GetArray();
  995. for (int i = 0; i < parts.Length; i++)
  996. {
  997. SceneObjectPart part = parts[i];
  998. if (part.UUID != m_rootPart.UUID)
  999. part.ParentID = m_rootPart.LocalId;
  1000. }
  1001. }
  1002. public void RegenerateFullIDs()
  1003. {
  1004. SceneObjectPart[] parts = m_parts.GetArray();
  1005. for (int i = 0; i < parts.Length; i++)
  1006. parts[i].UUID = UUID.Random();
  1007. }
  1008. // justincc: I don't believe this hack is needed any longer, especially since the physics
  1009. // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
  1010. // this method was preventing proper reload of scene objects.
  1011. // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects
  1012. // at region startup
  1013. // teravus: After this was removed from the linking algorithm, Linked prims no longer collided
  1014. // properly when non-physical if they havn't been moved. This breaks ALL builds.
  1015. // see: http://opensimulator.org/mantis/view.php?id=3108
  1016. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1017. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1018. // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute
  1019. // Position has been set!
  1020. public void ResetChildPrimPhysicsPositions()
  1021. {
  1022. // Setting this SOG's absolute position also loops through and sets the positions
  1023. // of the SOP's in this SOG's linkset. This has the side affect of making sure
  1024. // the physics world matches the simulated world.
  1025. AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
  1026. // teravus: AbsolutePosition is NOT a normal property!
  1027. // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
  1028. // jhurliman: Then why is it a property instead of two methods?
  1029. }
  1030. public UUID GetPartsFullID(uint localID)
  1031. {
  1032. SceneObjectPart part = GetPart(localID);
  1033. if (part != null)
  1034. {
  1035. return part.UUID;
  1036. }
  1037. return UUID.Zero;
  1038. }
  1039. public void ObjectGrabHandler(uint localId, Vector3 offsetPos, IClientAPI remoteClient)
  1040. {
  1041. if (m_rootPart.LocalId == localId)
  1042. {
  1043. OnGrabGroup(offsetPos, remoteClient);
  1044. }
  1045. else
  1046. {
  1047. SceneObjectPart part = GetPart(localId);
  1048. OnGrabPart(part, offsetPos, remoteClient);
  1049. }
  1050. }
  1051. public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient)
  1052. {
  1053. // m_log.DebugFormat(
  1054. // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}",
  1055. // remoteClient.Name, part.Name, part.LocalId, offsetPos);
  1056. part.StoreUndoState();
  1057. part.OnGrab(offsetPos, remoteClient);
  1058. }
  1059. public virtual void OnGrabGroup(Vector3 offsetPos, IClientAPI remoteClient)
  1060. {
  1061. m_scene.EventManager.TriggerGroupGrab(UUID, offsetPos, remoteClient.AgentId);
  1062. }
  1063. /// <summary>
  1064. /// Delete this group from its scene.
  1065. /// </summary>
  1066. /// <remarks>
  1067. /// This only handles the in-world consequences of deletion (e.g. any avatars sitting on it are forcibly stood
  1068. /// up and all avatars receive notification of its removal. Removal of the scene object from database backup
  1069. /// must be handled by the caller.
  1070. /// </remarks>
  1071. /// <param name="silent">If true then deletion is not broadcast to clients</param>
  1072. public void DeleteGroupFromScene(bool silent)
  1073. {
  1074. SceneObjectPart[] parts = m_parts.GetArray();
  1075. for (int i = 0; i < parts.Length; i++)
  1076. {
  1077. SceneObjectPart part = parts[i];
  1078. Scene.ForEachScenePresence(sp =>
  1079. {
  1080. if (!sp.IsChildAgent && sp.ParentID == LocalId)
  1081. sp.StandUp();
  1082. if (!silent)
  1083. {
  1084. part.ClearUpdateSchedule();
  1085. if (part == m_rootPart)
  1086. {
  1087. if (!IsAttachment
  1088. || AttachedAvatar == sp.UUID
  1089. || !HasPrivateAttachmentPoint)
  1090. sp.ControllingClient.SendKillObject(new List<uint> { part.LocalId });
  1091. }
  1092. }
  1093. });
  1094. }
  1095. }
  1096. public void AddScriptLPS(int count)
  1097. {
  1098. m_scene.SceneGraph.AddToScriptLPS(count);
  1099. }
  1100. public void AddActiveScriptCount(int count)
  1101. {
  1102. SceneGraph d = m_scene.SceneGraph;
  1103. d.AddActiveScripts(count);
  1104. }
  1105. public void aggregateScriptEvents()
  1106. {
  1107. PrimFlags objectflagupdate = (PrimFlags)RootPart.GetEffectiveObjectFlags();
  1108. scriptEvents aggregateScriptEvents = 0;
  1109. SceneObjectPart[] parts = m_parts.GetArray();
  1110. for (int i = 0; i < parts.Length; i++)
  1111. {
  1112. SceneObjectPart part = parts[i];
  1113. if (part == null)
  1114. continue;
  1115. if (part != RootPart)
  1116. part.Flags = objectflagupdate;
  1117. aggregateScriptEvents |= part.AggregateScriptEvents;
  1118. }
  1119. m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
  1120. m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
  1121. if (!m_scriptListens_atTarget && !m_scriptListens_notAtTarget)
  1122. {
  1123. lock (m_targets)
  1124. m_targets.Clear();
  1125. m_scene.RemoveGroupTarget(this);
  1126. }
  1127. m_scriptListens_atRotTarget = ((aggregateScriptEvents & scriptEvents.at_rot_target) != 0);
  1128. m_scriptListens_notAtRotTarget = ((aggregateScriptEvents & scriptEvents.not_at_rot_target) != 0);
  1129. if (!m_scriptListens_atRotTarget && !m_scriptListens_notAtRotTarget)
  1130. {
  1131. lock (m_rotTargets)
  1132. m_rotTargets.Clear();
  1133. m_scene.RemoveGroupTarget(this);
  1134. }
  1135. ScheduleGroupForFullUpdate();
  1136. }
  1137. public void SetText(string text, Vector3 color, double alpha)
  1138. {
  1139. Color = Color.FromArgb(0xff - (int) (alpha * 0xff),
  1140. (int) (color.X * 0xff),
  1141. (int) (color.Y * 0xff),
  1142. (int) (color.Z * 0xff));
  1143. Text = text;
  1144. HasGroupChanged = true;
  1145. m_rootPart.ScheduleFullUpdate();
  1146. }
  1147. /// <summary>
  1148. /// Apply physics to this group
  1149. /// </summary>
  1150. public void ApplyPhysics()
  1151. {
  1152. // Apply physics to the root prim
  1153. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive);
  1154. // Apply physics to child prims
  1155. SceneObjectPart[] parts = m_parts.GetArray();
  1156. if (parts.Length > 1)
  1157. {
  1158. for (int i = 0; i < parts.Length; i++)
  1159. {
  1160. SceneObjectPart part = parts[i];
  1161. if (part.LocalId != m_rootPart.LocalId)
  1162. part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive);
  1163. }
  1164. // Hack to get the physics scene geometries in the right spot
  1165. ResetChildPrimPhysicsPositions();
  1166. }
  1167. }
  1168. public void SetOwnerId(UUID userId)
  1169. {
  1170. ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; });
  1171. }
  1172. public void ForEachPart(Action<SceneObjectPart> whatToDo)
  1173. {
  1174. SceneObjectPart[] parts = m_parts.GetArray();
  1175. for (int i = 0; i < parts.Length; i++)
  1176. whatToDo(parts[i]);
  1177. }
  1178. #region Events
  1179. /// <summary>
  1180. /// Processes backup.
  1181. /// </summary>
  1182. /// <param name="datastore"></param>
  1183. public virtual void ProcessBackup(ISimulationDataService datastore, bool forcedBackup)
  1184. {
  1185. if (!m_isBackedUp)
  1186. {
  1187. // m_log.DebugFormat(
  1188. // "[WATER WARS]: Ignoring backup of {0} {1} since object is not marked to be backed up", Name, UUID);
  1189. return;
  1190. }
  1191. if (IsDeleted || UUID == UUID.Zero)
  1192. {
  1193. // m_log.DebugFormat(
  1194. // "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID);
  1195. return;
  1196. }
  1197. // Since this is the top of the section of call stack for backing up a particular scene object, don't let
  1198. // any exception propogate upwards.
  1199. try
  1200. {
  1201. if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart
  1202. {
  1203. ILandObject parcel = m_scene.LandChannel.GetLandObject(
  1204. m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
  1205. if (parcel != null && parcel.LandData != null &&
  1206. parcel.LandData.OtherCleanTime != 0)
  1207. {
  1208. if (parcel.LandData.OwnerID != OwnerID &&
  1209. (parcel.LandData.GroupID != GroupID ||
  1210. parcel.LandData.GroupID == UUID.Zero))
  1211. {
  1212. if ((DateTime.UtcNow - RootPart.Rezzed).TotalMinutes >
  1213. parcel.LandData.OtherCleanTime)
  1214. {
  1215. DetachFromBackup();
  1216. m_log.DebugFormat(
  1217. "[SCENE OBJECT GROUP]: Returning object {0} due to parcel autoreturn",
  1218. RootPart.UUID);
  1219. m_scene.AddReturn(OwnerID == GroupID ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn");
  1220. m_scene.DeRezObjects(null, new List<uint>() { RootPart.LocalId }, UUID.Zero,
  1221. DeRezAction.Return, UUID.Zero);
  1222. return;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. if (m_scene.UseBackup && HasGroupChanged)
  1228. {
  1229. // don't backup while it's selected or you're asking for changes mid stream.
  1230. if (isTimeToPersist() || forcedBackup)
  1231. {
  1232. // m_log.DebugFormat(
  1233. // "[SCENE]: Storing {0}, {1} in {2}",
  1234. // Name, UUID, m_scene.RegionInfo.RegionName);
  1235. SceneObjectGroup backup_group = Copy(false);
  1236. backup_group.RootPart.Velocity = RootPart.Velocity;
  1237. backup_group.RootPart.Acceleration = RootPart.Acceleration;
  1238. backup_group.RootPart.AngularVelocity = RootPart.AngularVelocity;
  1239. backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
  1240. HasGroupChanged = false;
  1241. HasGroupChangedDueToDelink = false;
  1242. m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
  1243. datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
  1244. backup_group.ForEachPart(delegate(SceneObjectPart part)
  1245. {
  1246. part.Inventory.ProcessInventoryBackup(datastore);
  1247. });
  1248. backup_group = null;
  1249. }
  1250. // else
  1251. // {
  1252. // m_log.DebugFormat(
  1253. // "[SCENE]: Did not update persistence of object {0} {1}, selected = {2}",
  1254. // Name, UUID, IsSelected);
  1255. // }
  1256. }
  1257. }
  1258. catch (Exception e)
  1259. {
  1260. m_log.ErrorFormat(
  1261. "[SCENE]: Storing of {0}, {1} in {2} failed with exception {3}{4}",
  1262. Name, UUID, m_scene.RegionInfo.RegionName, e.Message, e.StackTrace);
  1263. }
  1264. }
  1265. #endregion
  1266. /// <summary>
  1267. /// Send the parts of this SOG to a single client
  1268. /// </summary>
  1269. /// <remarks>
  1270. /// Used when the client initially connects and when client sends RequestPrim packet
  1271. /// </remarks>
  1272. /// <param name="remoteClient"></param>
  1273. public void SendFullUpdateToClient(IClientAPI remoteClient)
  1274. {
  1275. RootPart.SendFullUpdate(remoteClient);
  1276. SceneObjectPart[] parts = m_parts.GetArray();
  1277. for (int i = 0; i < parts.Length; i++)
  1278. {
  1279. SceneObjectPart part = parts[i];
  1280. if (part != RootPart)
  1281. part.SendFullUpdate(remoteClient);
  1282. }
  1283. }
  1284. #region Copying
  1285. /// <summary>
  1286. /// Duplicates this object, including operations such as physics set up and attaching to the backup event.
  1287. /// </summary>
  1288. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  1289. /// <returns></returns>
  1290. public SceneObjectGroup Copy(bool userExposed)
  1291. {
  1292. SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone();
  1293. dupe.m_isBackedUp = false;
  1294. dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
  1295. // Warning, The following code related to previousAttachmentStatus is needed so that clones of
  1296. // attachments do not bordercross while they're being duplicated. This is hacktastic!
  1297. // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region!
  1298. // unless IsAttachment is true!, so to prevent border crossing, we save it's attachment state
  1299. // (which should be false anyway) set it as an Attachment and then set it's Absolute Position,
  1300. // then restore it's attachment state
  1301. // This is only necessary when userExposed is false!
  1302. bool previousAttachmentStatus = dupe.IsAttachment;
  1303. if (!userExposed)
  1304. dupe.IsAttachment = true;
  1305. dupe.m_sittingAvatars = new List<UUID>();
  1306. if (!userExposed)
  1307. {
  1308. dupe.IsAttachment = previousAttachmentStatus;
  1309. }
  1310. dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
  1311. dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
  1312. if (userExposed)
  1313. dupe.m_rootPart.TrimPermissions();
  1314. List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
  1315. partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
  1316. {
  1317. return p1.LinkNum.CompareTo(p2.LinkNum);
  1318. }
  1319. );
  1320. foreach (SceneObjectPart part in partList)
  1321. {
  1322. SceneObjectPart newPart;
  1323. if (part.UUID != m_rootPart.UUID)
  1324. {
  1325. newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed);
  1326. newPart.LinkNum = part.LinkNum;
  1327. }
  1328. else
  1329. {
  1330. newPart = dupe.m_rootPart;
  1331. }
  1332. // Need to duplicate the physics actor as well
  1333. PhysicsActor originalPartPa = part.PhysActor;
  1334. if (originalPartPa != null && userExposed)
  1335. {
  1336. PrimitiveBaseShape pbs = newPart.Shape;
  1337. newPart.PhysActor
  1338. = m_scene.PhysicsScene.AddPrimShape(
  1339. string.Format("{0}/{1}", newPart.Name, newPart.UUID),
  1340. pbs,
  1341. newPart.AbsolutePosition,
  1342. newPart.Scale,
  1343. newPart.RotationOffset,
  1344. originalPartPa.IsPhysical,
  1345. newPart.LocalId);
  1346. newPart.DoPhysicsPropertyUpdate(originalPartPa.IsPhysical, true);
  1347. }
  1348. if (part.KeyframeMotion != null)
  1349. newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe);
  1350. }
  1351. if (userExposed)
  1352. {
  1353. dupe.UpdateParentIDs();
  1354. dupe.HasGroupChanged = true;
  1355. dupe.AttachToBackup();
  1356. ScheduleGroupForFullUpdate();
  1357. }
  1358. return dupe;
  1359. }
  1360. /// <summary>
  1361. /// Copy the given part as the root part of this scene object.
  1362. /// </summary>
  1363. /// <param name="part"></param>
  1364. /// <param name="cAgentID"></param>
  1365. /// <param name="cGroupID"></param>
  1366. public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  1367. {
  1368. SetRootPart(part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed));
  1369. }
  1370. public void ScriptSetPhysicsStatus(bool usePhysics)
  1371. {
  1372. if (usePhysics)
  1373. {
  1374. if (RootPart.KeyframeMotion != null)
  1375. RootPart.KeyframeMotion.Stop();
  1376. RootPart.KeyframeMotion = null;
  1377. }
  1378. UpdatePrimFlags(RootPart.LocalId, usePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
  1379. }
  1380. public void ScriptSetTemporaryStatus(bool makeTemporary)
  1381. {
  1382. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, makeTemporary, IsPhantom, IsVolumeDetect);
  1383. }
  1384. public void ScriptSetPhantomStatus(bool makePhantom)
  1385. {
  1386. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, IsTemporary, makePhantom, IsVolumeDetect);
  1387. }
  1388. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  1389. {
  1390. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, IsTemporary, IsPhantom, makeVolumeDetect);
  1391. /*
  1392. ScriptSetPhantomStatus(false); // What ever it was before, now it's not phantom anymore
  1393. if (PhysActor != null) // Should always be the case now
  1394. {
  1395. PhysActor.SetVolumeDetect(param);
  1396. }
  1397. if (param != 0)
  1398. AddFlag(PrimFlags.Phantom);
  1399. ScheduleFullUpdate();
  1400. */
  1401. }
  1402. public void applyImpulse(Vector3 impulse)
  1403. {
  1404. if (IsAttachment)
  1405. {
  1406. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1407. if (avatar != null)
  1408. {
  1409. avatar.PushForce(impulse);
  1410. }
  1411. }
  1412. else
  1413. {
  1414. PhysicsActor pa = RootPart.PhysActor;
  1415. if (pa != null)
  1416. {
  1417. pa.AddForce(impulse, true);
  1418. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  1419. }
  1420. }
  1421. }
  1422. public void applyAngularImpulse(Vector3 impulse)
  1423. {
  1424. PhysicsActor pa = RootPart.PhysActor;
  1425. if (pa != null)
  1426. {
  1427. if (!IsAttachment)
  1428. {
  1429. pa.AddAngularForce(impulse, true);
  1430. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  1431. }
  1432. }
  1433. }
  1434. public void setAngularImpulse(Vector3 impulse)
  1435. {
  1436. PhysicsActor pa = RootPart.PhysActor;
  1437. if (pa != null)
  1438. {
  1439. if (!IsAttachment)
  1440. {
  1441. pa.Torque = impulse;
  1442. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  1443. }
  1444. }
  1445. }
  1446. public Vector3 GetTorque()
  1447. {
  1448. PhysicsActor pa = RootPart.PhysActor;
  1449. if (pa != null)
  1450. {
  1451. if (!IsAttachment)
  1452. {
  1453. Vector3 torque = pa.Torque;
  1454. return torque;
  1455. }
  1456. }
  1457. return Vector3.Zero;
  1458. }
  1459. public void moveToTarget(Vector3 target, float tau)
  1460. {
  1461. if (IsAttachment)
  1462. {
  1463. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1464. if (avatar != null)
  1465. {
  1466. avatar.MoveToTarget(target, false, false);
  1467. }
  1468. }
  1469. else
  1470. {
  1471. PhysicsActor pa = RootPart.PhysActor;
  1472. if (pa != null)
  1473. {
  1474. pa.PIDTarget = target;
  1475. pa.PIDTau = tau;
  1476. pa.PIDActive = true;
  1477. }
  1478. }
  1479. }
  1480. public void stopMoveToTarget()
  1481. {
  1482. PhysicsActor pa = RootPart.PhysActor;
  1483. if (pa != null)
  1484. pa.PIDActive = false;
  1485. }
  1486. /// <summary>
  1487. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  1488. /// </summary>
  1489. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  1490. /// <param name="hoverType">Determines what the height is relative to </param>
  1491. /// <param name="tau">Number of seconds over which to reach target</param>
  1492. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  1493. {
  1494. PhysicsActor pa = RootPart.PhysActor;
  1495. if (pa != null)
  1496. {
  1497. if (height != 0f)
  1498. {
  1499. pa.PIDHoverHeight = height;
  1500. pa.PIDHoverType = hoverType;
  1501. pa.PIDTau = tau;
  1502. pa.PIDHoverActive = true;
  1503. }
  1504. else
  1505. {
  1506. pa.PIDHoverActive = false;
  1507. }
  1508. }
  1509. }
  1510. /// <summary>
  1511. /// Set the owner of the root part.
  1512. /// </summary>
  1513. /// <param name="part"></param>
  1514. /// <param name="cAgentID"></param>
  1515. /// <param name="cGroupID"></param>
  1516. public void SetRootPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  1517. {
  1518. part.LastOwnerID = part.OwnerID;
  1519. part.OwnerID = cAgentID;
  1520. part.GroupID = cGroupID;
  1521. if (part.OwnerID != cAgentID)
  1522. {
  1523. // Apply Next Owner Permissions if we're not bypassing permissions
  1524. if (!m_scene.Permissions.BypassPermissions())
  1525. ApplyNextOwnerPermissions();
  1526. }
  1527. part.ScheduleFullUpdate();
  1528. }
  1529. /// <summary>
  1530. /// Make a copy of the given part.
  1531. /// </summary>
  1532. /// <param name="part"></param>
  1533. /// <param name="cAgentID"></param>
  1534. /// <param name="cGroupID"></param>
  1535. public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  1536. {
  1537. SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
  1538. AddPart(newPart);
  1539. SetPartAsNonRoot(newPart);
  1540. return newPart;
  1541. }
  1542. /// <summary>
  1543. /// Reset the UUIDs for all the prims that make up this group.
  1544. /// </summary>
  1545. /// <remarks>
  1546. /// This is called by methods which want to add a new group to an existing scene, in order
  1547. /// to ensure that there are no clashes with groups already present.
  1548. /// </remarks>
  1549. public void ResetIDs()
  1550. {
  1551. lock (m_parts.SyncRoot)
  1552. {
  1553. List<SceneObjectPart> partsList = new List<SceneObjectPart>(m_parts.GetArray());
  1554. m_parts.Clear();
  1555. foreach (SceneObjectPart part in partsList)
  1556. {
  1557. part.ResetIDs(part.LinkNum); // Don't change link nums
  1558. m_parts.Add(part.UUID, part);
  1559. }
  1560. }
  1561. }
  1562. /// <summary>
  1563. ///
  1564. /// </summary>
  1565. /// <param name="part"></param>
  1566. public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags)
  1567. {
  1568. remoteClient.SendObjectPropertiesFamilyData(RootPart, RequestFlags);
  1569. // remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask,
  1570. // RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask,
  1571. // RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category,
  1572. // RootPart.CreatorID, RootPart.Name, RootPart.Description);
  1573. }
  1574. public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  1575. {
  1576. part.OwnerID = cAgentID;
  1577. part.GroupID = cGroupID;
  1578. }
  1579. #endregion
  1580. public override void Update()
  1581. {
  1582. // Check that the group was not deleted before the scheduled update
  1583. // FIXME: This is merely a temporary measure to reduce the incidence of failure when
  1584. // an object has been deleted from a scene before update was processed.
  1585. // A more fundamental overhaul of the update mechanism is required to eliminate all
  1586. // the race conditions.
  1587. if (IsDeleted)
  1588. return;
  1589. // Even temporary objects take part in physics (e.g. temp-on-rez bullets)
  1590. //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  1591. // return;
  1592. // If we somehow got here to updating the SOG and its root part is not scheduled for update,
  1593. // check to see if the physical position or rotation warrant an update.
  1594. if (m_rootPart.UpdateFlag == UpdateRequired.NONE)
  1595. {
  1596. bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
  1597. if (UsePhysics && !AbsolutePosition.ApproxEquals(lastPhysGroupPos, 0.02f))
  1598. {
  1599. m_rootPart.UpdateFlag = UpdateRequired.TERSE;
  1600. lastPhysGroupPos = AbsolutePosition;
  1601. }
  1602. if (UsePhysics && !GroupRotation.ApproxEquals(lastPhysGroupRot, 0.1f))
  1603. {
  1604. m_rootPart.UpdateFlag = UpdateRequired.TERSE;
  1605. lastPhysGroupRot = GroupRotation;
  1606. }
  1607. }
  1608. SceneObjectPart[] parts = m_parts.GetArray();
  1609. for (int i = 0; i < parts.Length; i++)
  1610. {
  1611. SceneObjectPart part = parts[i];
  1612. if (!IsSelected)
  1613. part.UpdateLookAt();
  1614. part.SendScheduledUpdates();
  1615. }
  1616. }
  1617. /// <summary>
  1618. /// Schedule a full update for this scene object to all interested viewers.
  1619. /// </summary>
  1620. /// <remarks>
  1621. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  1622. /// so that either all changes are sent at once. However, currently, a large amount of internal
  1623. /// code will set this anyway when some object properties are changed.
  1624. /// </remarks>
  1625. public void ScheduleGroupForFullUpdate()
  1626. {
  1627. // if (IsAttachment)
  1628. // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
  1629. checkAtTargets();
  1630. RootPart.ScheduleFullUpdate();
  1631. SceneObjectPart[] parts = m_parts.GetArray();
  1632. for (int i = 0; i < parts.Length; i++)
  1633. {
  1634. SceneObjectPart part = parts[i];
  1635. if (part != RootPart)
  1636. part.ScheduleFullUpdate();
  1637. }
  1638. }
  1639. /// <summary>
  1640. /// Schedule a terse update for this scene object to all interested viewers.
  1641. /// </summary>
  1642. /// <remarks>
  1643. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  1644. /// so that either all changes are sent at once. However, currently, a large amount of internal
  1645. /// code will set this anyway when some object properties are changed.
  1646. /// </remarks>
  1647. public void ScheduleGroupForTerseUpdate()
  1648. {
  1649. // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID);
  1650. SceneObjectPart[] parts = m_parts.GetArray();
  1651. for (int i = 0; i < parts.Length; i++)
  1652. parts[i].ScheduleTerseUpdate();
  1653. }
  1654. /// <summary>
  1655. /// Immediately send a full update for this scene object.
  1656. /// </summary>
  1657. public void SendGroupFullUpdate()
  1658. {
  1659. if (IsDeleted)
  1660. return;
  1661. // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
  1662. RootPart.SendFullUpdateToAllClients();
  1663. SceneObjectPart[] parts = m_parts.GetArray();
  1664. for (int i = 0; i < parts.Length; i++)
  1665. {
  1666. SceneObjectPart part = parts[i];
  1667. if (part != RootPart)
  1668. part.SendFullUpdateToAllClients();
  1669. }
  1670. }
  1671. /// <summary>
  1672. /// Immediately send an update for this scene object's root prim only.
  1673. /// This is for updates regarding the object as a whole, and none of its parts in particular.
  1674. /// Note: this may not be used by opensim (it probably should) but it's used by
  1675. /// external modules.
  1676. /// </summary>
  1677. public void SendGroupRootTerseUpdate()
  1678. {
  1679. if (IsDeleted)
  1680. return;
  1681. RootPart.SendTerseUpdateToAllClients();
  1682. }
  1683. public void QueueForUpdateCheck()
  1684. {
  1685. if (m_scene == null) // Need to check here as it's null during object creation
  1686. return;
  1687. m_scene.SceneGraph.AddToUpdateList(this);
  1688. }
  1689. /// <summary>
  1690. /// Immediately send a terse update for this scene object.
  1691. /// </summary>
  1692. public void SendGroupTerseUpdate()
  1693. {
  1694. if (IsDeleted)
  1695. return;
  1696. SceneObjectPart[] parts = m_parts.GetArray();
  1697. for (int i = 0; i < parts.Length; i++)
  1698. parts[i].SendTerseUpdateToAllClients();
  1699. }
  1700. /// <summary>
  1701. /// Send metadata about the root prim (name, description, sale price, permissions, etc.) to a client.
  1702. /// </summary>
  1703. /// <param name="client"></param>
  1704. public void SendPropertiesToClient(IClientAPI client)
  1705. {
  1706. m_rootPart.SendPropertiesToClient(client);
  1707. }
  1708. #region SceneGroupPart Methods
  1709. /// <summary>
  1710. /// Get the child part by LinkNum
  1711. /// </summary>
  1712. /// <param name="linknum"></param>
  1713. /// <returns>null if no child part with that linknum or child part</returns>
  1714. public SceneObjectPart GetLinkNumPart(int linknum)
  1715. {
  1716. SceneObjectPart[] parts = m_parts.GetArray();
  1717. for (int i = 0; i < parts.Length; i++)
  1718. {
  1719. if (parts[i].LinkNum == linknum)
  1720. return parts[i];
  1721. }
  1722. return null;
  1723. }
  1724. /// <summary>
  1725. /// Get a part with a given UUID
  1726. /// </summary>
  1727. /// <param name="primID"></param>
  1728. /// <returns>null if a part with the primID was not found</returns>
  1729. public SceneObjectPart GetPart(UUID primID)
  1730. {
  1731. SceneObjectPart childPart;
  1732. m_parts.TryGetValue(primID, out childPart);
  1733. return childPart;
  1734. }
  1735. /// <summary>
  1736. /// Get a part with a given local ID
  1737. /// </summary>
  1738. /// <param name="localID"></param>
  1739. /// <returns>null if a part with the local ID was not found</returns>
  1740. public SceneObjectPart GetPart(uint localID)
  1741. {
  1742. SceneObjectPart[] parts = m_parts.GetArray();
  1743. for (int i = 0; i < parts.Length; i++)
  1744. {
  1745. if (parts[i].LocalId == localID)
  1746. return parts[i];
  1747. }
  1748. return null;
  1749. }
  1750. #endregion
  1751. #region Packet Handlers
  1752. /// <summary>
  1753. /// Link the prims in a given group to this group
  1754. /// </summary>
  1755. /// <remarks>
  1756. /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads.
  1757. /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition.
  1758. /// </remarks>
  1759. /// <param name="objectGroup">The group of prims which should be linked to this group</param>
  1760. public void LinkToGroup(SceneObjectGroup objectGroup)
  1761. {
  1762. LinkToGroup(objectGroup, false);
  1763. }
  1764. // Link an existing group to this group.
  1765. // The group being linked need not be a linkset -- it can have just one prim.
  1766. public void LinkToGroup(SceneObjectGroup objectGroup, bool insert)
  1767. {
  1768. // m_log.DebugFormat(
  1769. // "[SCENE OBJECT GROUP]: Linking group with root part {0}, {1} to group with root part {2}, {3}",
  1770. // objectGroup.RootPart.Name, objectGroup.RootPart.UUID, RootPart.Name, RootPart.UUID);
  1771. // Linking to ourselves is not a valid operation.
  1772. if (objectGroup == this)
  1773. return;
  1774. // If the configured linkset capacity is greater than zero,
  1775. // and the new linkset would have a prim count higher than this
  1776. // value, do not link it.
  1777. if (m_scene.m_linksetCapacity > 0 &&
  1778. (PrimCount + objectGroup.PrimCount) >
  1779. m_scene.m_linksetCapacity)
  1780. {
  1781. m_log.DebugFormat(
  1782. "[SCENE OBJECT GROUP]: Cannot link group with root" +
  1783. " part {0}, {1} ({2} prims) to group with root part" +
  1784. " {3}, {4} ({5} prims) because the new linkset" +
  1785. " would exceed the configured maximum of {6}",
  1786. objectGroup.RootPart.Name, objectGroup.RootPart.UUID,
  1787. objectGroup.PrimCount, RootPart.Name, RootPart.UUID,
  1788. PrimCount, m_scene.m_linksetCapacity);
  1789. return;
  1790. }
  1791. // 'linkPart' == the root of the group being linked into this group
  1792. SceneObjectPart linkPart = objectGroup.m_rootPart;
  1793. // physics flags from group to be applied to linked parts
  1794. bool grpusephys = UsesPhysics;
  1795. bool grptemporary = IsTemporary;
  1796. // Remember where the group being linked thought it was
  1797. Vector3 oldGroupPosition = linkPart.GroupPosition;
  1798. Quaternion oldRootRotation = linkPart.RotationOffset;
  1799. // A linked SOP remembers its location and rotation relative to the root of a group.
  1800. // Convert the root of the group being linked to be relative to the
  1801. // root of the group being linked to.
  1802. // Note: Some of the assignments have complex side effects.
  1803. // First move the new group's root SOP's position to be relative to ours
  1804. // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not,
  1805. // this code can be reordered to have a more logical flow.)
  1806. linkPart.OffsetPosition = linkPart.GroupPosition - AbsolutePosition;
  1807. // Assign the new parent to the root of the old group
  1808. linkPart.ParentID = m_rootPart.LocalId;
  1809. // Now that it's a child, it's group position is our root position
  1810. linkPart.GroupPosition = AbsolutePosition;
  1811. Vector3 axPos = linkPart.OffsetPosition;
  1812. // Rotate the linking root SOP's position to be relative to the new root prim
  1813. Quaternion parentRot = m_rootPart.RotationOffset;
  1814. axPos *= Quaternion.Inverse(parentRot);
  1815. linkPart.OffsetPosition = axPos;
  1816. // Make the linking root SOP's rotation relative to the new root prim
  1817. Quaternion oldRot = linkPart.RotationOffset;
  1818. Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot;
  1819. linkPart.RotationOffset = newRot;
  1820. // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset.
  1821. // Now that we know this SOG has at least two SOPs in it, the new root
  1822. // SOP becomes the first in the linkset.
  1823. if (m_rootPart.LinkNum == 0)
  1824. m_rootPart.LinkNum = 1;
  1825. lock (m_parts.SyncRoot)
  1826. {
  1827. // Calculate the new link number for the old root SOP
  1828. int linkNum;
  1829. if (insert)
  1830. {
  1831. linkNum = 2;
  1832. foreach (SceneObjectPart part in Parts)
  1833. {
  1834. if (part.LinkNum > 1)
  1835. part.LinkNum++;
  1836. }
  1837. }
  1838. else
  1839. {
  1840. linkNum = PrimCount + 1;
  1841. }
  1842. // Add the old root SOP as a part in our group's list
  1843. m_parts.Add(linkPart.UUID, linkPart);
  1844. linkPart.SetParent(this);
  1845. linkPart.CreateSelected = true;
  1846. // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
  1847. linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive);
  1848. // If the added SOP is physical, also tell the physics engine about the link relationship.
  1849. if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  1850. {
  1851. linkPart.PhysActor.link(m_rootPart.PhysActor);
  1852. this.Scene.PhysicsScene.AddPhysicsActorTaint(linkPart.PhysActor);
  1853. }
  1854. linkPart.LinkNum = linkNum++;
  1855. // Get a list of the SOP's in the old group in order of their linknum's.
  1856. SceneObjectPart[] ogParts = objectGroup.Parts;
  1857. Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b)
  1858. {
  1859. return a.LinkNum - b.LinkNum;
  1860. });
  1861. // Add each of the SOP's from the old linkset to our linkset
  1862. for (int i = 0; i < ogParts.Length; i++)
  1863. {
  1864. SceneObjectPart part = ogParts[i];
  1865. if (part.UUID != objectGroup.m_rootPart.UUID)
  1866. {
  1867. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  1868. // Update the physics flags for the newly added SOP
  1869. // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??)
  1870. part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive);
  1871. // If the added SOP is physical, also tell the physics engine about the link relationship.
  1872. if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  1873. {
  1874. part.PhysActor.link(m_rootPart.PhysActor);
  1875. this.Scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
  1876. }
  1877. }
  1878. part.ClearUndoState();
  1879. }
  1880. }
  1881. // Now that we've aquired all of the old SOG's parts, remove the old SOG from the scene.
  1882. m_scene.UnlinkSceneObject(objectGroup, true);
  1883. objectGroup.IsDeleted = true;
  1884. objectGroup.m_parts.Clear();
  1885. // Can't do this yet since backup still makes use of the root part without any synchronization
  1886. // objectGroup.m_rootPart = null;
  1887. // If linking prims with different permissions, fix them
  1888. AdjustChildPrimPermissions();
  1889. AttachToBackup();
  1890. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1891. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1892. // unmoved prims!
  1893. ResetChildPrimPhysicsPositions();
  1894. //HasGroupChanged = true;
  1895. //ScheduleGroupForFullUpdate();
  1896. }
  1897. /// <summary>
  1898. /// Delink the given prim from this group. The delinked prim is established as
  1899. /// an independent SceneObjectGroup.
  1900. /// </summary>
  1901. /// <remarks>
  1902. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  1903. /// condition. But currently there is no
  1904. /// alternative method that does take a lonk to delink a single prim.
  1905. /// </remarks>
  1906. /// <param name="partID"></param>
  1907. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  1908. public SceneObjectGroup DelinkFromGroup(uint partID)
  1909. {
  1910. return DelinkFromGroup(partID, true);
  1911. }
  1912. /// <summary>
  1913. /// Delink the given prim from this group. The delinked prim is established as
  1914. /// an independent SceneObjectGroup.
  1915. /// </summary>
  1916. /// <remarks>
  1917. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  1918. /// condition. But currently there is no
  1919. /// alternative method that does take a lonk to delink a single prim.
  1920. /// </remarks>
  1921. /// <param name="partID"></param>
  1922. /// <param name="sendEvents"></param>
  1923. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  1924. public SceneObjectGroup DelinkFromGroup(uint partID, bool sendEvents)
  1925. {
  1926. SceneObjectPart linkPart = GetPart(partID);
  1927. if (linkPart != null)
  1928. {
  1929. return DelinkFromGroup(linkPart, sendEvents);
  1930. }
  1931. else
  1932. {
  1933. m_log.WarnFormat("[SCENE OBJECT GROUP]: " +
  1934. "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}",
  1935. partID, LocalId, UUID);
  1936. return null;
  1937. }
  1938. }
  1939. /// <summary>
  1940. /// Delink the given prim from this group. The delinked prim is established as
  1941. /// an independent SceneObjectGroup.
  1942. /// </summary>
  1943. /// <remarks>
  1944. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  1945. /// condition. But currently there is no
  1946. /// alternative method that does take a lock to delink a single prim.
  1947. /// </remarks>
  1948. /// <param name="partID"></param>
  1949. /// <param name="sendEvents"></param>
  1950. /// <returns>The object group of the newly delinked prim.</returns>
  1951. public SceneObjectGroup DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents)
  1952. {
  1953. // m_log.DebugFormat(
  1954. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  1955. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  1956. linkPart.ClearUndoState();
  1957. Vector3 worldPos = linkPart.GetWorldPosition();
  1958. Quaternion worldRot = linkPart.GetWorldRotation();
  1959. // Remove the part from this object
  1960. lock (m_parts.SyncRoot)
  1961. {
  1962. m_parts.Remove(linkPart.UUID);
  1963. SceneObjectPart[] parts = m_parts.GetArray();
  1964. // Rejigger the linknum's of the remaining SOP's to fill any gap
  1965. if (parts.Length == 1 && RootPart != null)
  1966. {
  1967. // Single prim left
  1968. RootPart.LinkNum = 0;
  1969. }
  1970. else
  1971. {
  1972. for (int i = 0; i < parts.Length; i++)
  1973. {
  1974. SceneObjectPart part = parts[i];
  1975. if (part.LinkNum > linkPart.LinkNum)
  1976. part.LinkNum--;
  1977. }
  1978. }
  1979. }
  1980. linkPart.ParentID = 0;
  1981. linkPart.LinkNum = 0;
  1982. PhysicsActor linkPartPa = linkPart.PhysActor;
  1983. // Remove the SOP from the physical scene.
  1984. // If the new SOG is physical, it is re-created later.
  1985. // (There is a problem here in that we have not yet told the physics
  1986. // engine about the delink. Someday, linksets should be made first
  1987. // class objects in the physics engine interface).
  1988. if (linkPartPa != null)
  1989. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  1990. // We need to reset the child part's position
  1991. // ready for life as a separate object after being a part of another object
  1992. /* This commented out code seems to recompute what GetWorldPosition already does.
  1993. * Replace with a call to GetWorldPosition (before unlinking)
  1994. Quaternion parentRot = m_rootPart.RotationOffset;
  1995. Vector3 axPos = linkPart.OffsetPosition;
  1996. axPos *= parentRot;
  1997. linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z);
  1998. linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition;
  1999. linkPart.OffsetPosition = new Vector3(0, 0, 0);
  2000. */
  2001. linkPart.GroupPosition = worldPos;
  2002. linkPart.OffsetPosition = Vector3.Zero;
  2003. linkPart.RotationOffset = worldRot;
  2004. // Create a new SOG to go around this unlinked and unattached SOP
  2005. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  2006. m_scene.AddNewSceneObject(objectGroup, true);
  2007. if (sendEvents)
  2008. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  2009. linkPart.Rezzed = RootPart.Rezzed;
  2010. // When we delete a group, we currently have to force persist to the database if the object id has changed
  2011. // (since delete works by deleting all rows which have a given object id)
  2012. objectGroup.HasGroupChangedDueToDelink = true;
  2013. return objectGroup;
  2014. }
  2015. /// <summary>
  2016. /// Stop this object from being persisted over server restarts.
  2017. /// </summary>
  2018. /// <param name="objectGroup"></param>
  2019. public virtual void DetachFromBackup()
  2020. {
  2021. if (m_isBackedUp && Scene != null)
  2022. m_scene.EventManager.OnBackup -= ProcessBackup;
  2023. m_isBackedUp = false;
  2024. }
  2025. // This links an SOP from a previous linkset into my linkset.
  2026. // The trick is that the SOP's position and rotation are relative to the old root SOP's
  2027. // so we are passed in the position and rotation of the old linkset so this can
  2028. // unjigger this SOP's position and rotation from the previous linkset and
  2029. // then make them relative to my linkset root.
  2030. private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation, int linkNum)
  2031. {
  2032. Quaternion parentRot = oldGroupRotation;
  2033. Quaternion oldRot = part.RotationOffset;
  2034. // Move our position to not be relative to the old parent
  2035. Vector3 axPos = part.OffsetPosition;
  2036. axPos *= parentRot;
  2037. part.OffsetPosition = axPos;
  2038. part.GroupPosition = oldGroupPosition + part.OffsetPosition;
  2039. part.OffsetPosition = Vector3.Zero;
  2040. // Compution our rotation to be not relative to the old parent
  2041. Quaternion worldRot = parentRot * oldRot;
  2042. part.RotationOffset = worldRot;
  2043. // Add this SOP to our linkset
  2044. part.SetParent(this);
  2045. part.ParentID = m_rootPart.LocalId;
  2046. m_parts.Add(part.UUID, part);
  2047. part.LinkNum = linkNum;
  2048. // Compute the new position of this SOP relative to the group position
  2049. part.OffsetPosition = part.GroupPosition - AbsolutePosition;
  2050. // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times.
  2051. // It would have the affect of setting the physics engine position multiple
  2052. // times. In theory, that is not necessary but I don't have a good linkset
  2053. // test to know that cleaning up this code wouldn't break things.)
  2054. // Rotate the relative position by the rotation of the group
  2055. Quaternion rootRotation = m_rootPart.RotationOffset;
  2056. Vector3 pos = part.OffsetPosition;
  2057. pos *= Quaternion.Inverse(rootRotation);
  2058. part.OffsetPosition = pos;
  2059. // Compute the SOP's rotation relative to the rotation of the group.
  2060. parentRot = m_rootPart.RotationOffset;
  2061. oldRot = part.RotationOffset;
  2062. Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot;
  2063. part.RotationOffset = newRot;
  2064. // Since this SOP's state has changed, push those changes into the physics engine
  2065. // and the simulator.
  2066. part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect);
  2067. }
  2068. /// <summary>
  2069. /// If object is physical, apply force to move it around
  2070. /// If object is not physical, just put it at the resulting location
  2071. /// </summary>
  2072. /// <param name="offset">Always seems to be 0,0,0, so ignoring</param>
  2073. /// <param name="pos">New position. We do the math here to turn it into a force</param>
  2074. /// <param name="remoteClient"></param>
  2075. public void GrabMovement(Vector3 offset, Vector3 pos, IClientAPI remoteClient)
  2076. {
  2077. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  2078. {
  2079. PhysicsActor pa = m_rootPart.PhysActor;
  2080. if (pa != null)
  2081. {
  2082. if (pa.IsPhysical)
  2083. {
  2084. if (!m_rootPart.BlockGrab)
  2085. {
  2086. Vector3 llmoveforce = pos - AbsolutePosition;
  2087. Vector3 grabforce = llmoveforce;
  2088. grabforce = (grabforce / 10) * pa.Mass;
  2089. pa.AddForce(grabforce, true);
  2090. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2091. }
  2092. }
  2093. else
  2094. {
  2095. //NonPhysicalGrabMovement(pos);
  2096. }
  2097. }
  2098. else
  2099. {
  2100. //NonPhysicalGrabMovement(pos);
  2101. }
  2102. }
  2103. }
  2104. public void NonPhysicalGrabMovement(Vector3 pos)
  2105. {
  2106. AbsolutePosition = pos;
  2107. m_rootPart.SendTerseUpdateToAllClients();
  2108. }
  2109. /// <summary>
  2110. /// If object is physical, prepare for spinning torques (set flag to save old orientation)
  2111. /// </summary>
  2112. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  2113. /// <param name="remoteClient"></param>
  2114. public void SpinStart(IClientAPI remoteClient)
  2115. {
  2116. if (m_scene.EventManager.TriggerGroupSpinStart(UUID))
  2117. {
  2118. PhysicsActor pa = m_rootPart.PhysActor;
  2119. if (pa != null)
  2120. {
  2121. if (pa.IsPhysical)
  2122. {
  2123. m_rootPart.IsWaitingForFirstSpinUpdatePacket = true;
  2124. }
  2125. }
  2126. }
  2127. }
  2128. /// <summary>
  2129. /// If object is physical, apply torque to spin it around
  2130. /// </summary>
  2131. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  2132. /// <param name="remoteClient"></param>
  2133. public void SpinMovement(Quaternion newOrientation, IClientAPI remoteClient)
  2134. {
  2135. // The incoming newOrientation, sent by the client, "seems" to be the
  2136. // desired target orientation. This needs further verification; in particular,
  2137. // one would expect that the initial incoming newOrientation should be
  2138. // fairly close to the original prim's physical orientation,
  2139. // m_rootPart.PhysActor.Orientation. This however does not seem to be the
  2140. // case (might just be an issue with different quaternions representing the
  2141. // same rotation, or it might be a coordinate system issue).
  2142. //
  2143. // Since it's not clear what the relationship is between the PhysActor.Orientation
  2144. // and the incoming orientations sent by the client, we take an alternative approach
  2145. // of calculating the delta rotation between the orientations being sent by the
  2146. // client. (Since a spin is invoked by ctrl+shift+drag in the client, we expect
  2147. // a steady stream of several new orientations coming in from the client.)
  2148. // This ensures that the delta rotations are being calculated from self-consistent
  2149. // pairs of old/new rotations. Given the delta rotation, we apply a torque around
  2150. // the delta rotation axis, scaled by the object mass times an arbitrary scaling
  2151. // factor (to ensure the resulting torque is not "too strong" or "too weak").
  2152. //
  2153. // Ideally we need to calculate (probably iteratively) the exact torque or series
  2154. // of torques needed to arrive exactly at the destination orientation. However, since
  2155. // it is not yet clear how to map the destination orientation (provided by the viewer)
  2156. // into PhysActor orientations (needed by the physics engine), we omit this step.
  2157. // This means that the resulting torque will at least be in the correct direction,
  2158. // but it will result in over-shoot or under-shoot of the target orientation.
  2159. // For the end user, this means that ctrl+shift+drag can be used for relative,
  2160. // but not absolute, adjustments of orientation for physical prims.
  2161. if (m_scene.EventManager.TriggerGroupSpin(UUID, newOrientation))
  2162. {
  2163. PhysicsActor pa = m_rootPart.PhysActor;
  2164. if (pa != null)
  2165. {
  2166. if (pa.IsPhysical)
  2167. {
  2168. if (m_rootPart.IsWaitingForFirstSpinUpdatePacket)
  2169. {
  2170. // first time initialization of "old" orientation for calculation of delta rotations
  2171. m_rootPart.SpinOldOrientation = newOrientation;
  2172. m_rootPart.IsWaitingForFirstSpinUpdatePacket = false;
  2173. }
  2174. else
  2175. {
  2176. // save and update old orientation
  2177. Quaternion old = m_rootPart.SpinOldOrientation;
  2178. m_rootPart.SpinOldOrientation = newOrientation;
  2179. //m_log.Error("[SCENE OBJECT GROUP]: Old orientation is " + old);
  2180. //m_log.Error("[SCENE OBJECT GROUP]: Incoming new orientation is " + newOrientation);
  2181. // compute difference between previous old rotation and new incoming rotation
  2182. Quaternion minimalRotationFromQ1ToQ2 = Quaternion.Inverse(old) * newOrientation;
  2183. float rotationAngle;
  2184. Vector3 rotationAxis;
  2185. minimalRotationFromQ1ToQ2.GetAxisAngle(out rotationAxis, out rotationAngle);
  2186. rotationAxis.Normalize();
  2187. //m_log.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis);
  2188. Vector3 spinforce = new Vector3(rotationAxis.X, rotationAxis.Y, rotationAxis.Z);
  2189. spinforce = (spinforce/8) * pa.Mass; // 8 is an arbitrary torque scaling factor
  2190. pa.AddAngularForce(spinforce,true);
  2191. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2192. }
  2193. }
  2194. else
  2195. {
  2196. //NonPhysicalSpinMovement(pos);
  2197. }
  2198. }
  2199. else
  2200. {
  2201. //NonPhysicalSpinMovement(pos);
  2202. }
  2203. }
  2204. }
  2205. /// <summary>
  2206. /// Set the name of a prim
  2207. /// </summary>
  2208. /// <param name="name"></param>
  2209. /// <param name="localID"></param>
  2210. public void SetPartName(string name, uint localID)
  2211. {
  2212. SceneObjectPart part = GetPart(localID);
  2213. if (part != null)
  2214. {
  2215. part.Name = name;
  2216. }
  2217. }
  2218. public void SetPartDescription(string des, uint localID)
  2219. {
  2220. SceneObjectPart part = GetPart(localID);
  2221. if (part != null)
  2222. {
  2223. part.Description = des;
  2224. }
  2225. }
  2226. public void SetPartText(string text, uint localID)
  2227. {
  2228. SceneObjectPart part = GetPart(localID);
  2229. if (part != null)
  2230. {
  2231. part.SetText(text);
  2232. }
  2233. }
  2234. public void SetPartText(string text, UUID partID)
  2235. {
  2236. SceneObjectPart part = GetPart(partID);
  2237. if (part != null)
  2238. {
  2239. part.SetText(text);
  2240. }
  2241. }
  2242. public string GetPartName(uint localID)
  2243. {
  2244. SceneObjectPart part = GetPart(localID);
  2245. if (part != null)
  2246. {
  2247. return part.Name;
  2248. }
  2249. return String.Empty;
  2250. }
  2251. public string GetPartDescription(uint localID)
  2252. {
  2253. SceneObjectPart part = GetPart(localID);
  2254. if (part != null)
  2255. {
  2256. return part.Description;
  2257. }
  2258. return String.Empty;
  2259. }
  2260. /// <summary>
  2261. /// Update prim flags for this group.
  2262. /// </summary>
  2263. /// <param name="localID"></param>
  2264. /// <param name="UsePhysics"></param>
  2265. /// <param name="SetTemporary"></param>
  2266. /// <param name="SetPhantom"></param>
  2267. /// <param name="SetVolumeDetect"></param>
  2268. public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect)
  2269. {
  2270. SceneObjectPart selectionPart = GetPart(localID);
  2271. if (SetTemporary && Scene != null)
  2272. {
  2273. DetachFromBackup();
  2274. // Remove from database and parcel prim count
  2275. //
  2276. m_scene.DeleteFromStorage(UUID);
  2277. m_scene.EventManager.TriggerParcelPrimCountTainted();
  2278. }
  2279. if (selectionPart != null)
  2280. {
  2281. SceneObjectPart[] parts = m_parts.GetArray();
  2282. if (Scene != null)
  2283. {
  2284. for (int i = 0; i < parts.Length; i++)
  2285. {
  2286. SceneObjectPart part = parts[i];
  2287. if (part.Scale.X > m_scene.m_maxPhys ||
  2288. part.Scale.Y > m_scene.m_maxPhys ||
  2289. part.Scale.Z > m_scene.m_maxPhys )
  2290. {
  2291. UsePhysics = false; // Reset physics
  2292. break;
  2293. }
  2294. }
  2295. }
  2296. for (int i = 0; i < parts.Length; i++)
  2297. parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect);
  2298. }
  2299. }
  2300. public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data)
  2301. {
  2302. SceneObjectPart part = GetPart(localID);
  2303. if (part != null)
  2304. {
  2305. part.UpdateExtraParam(type, inUse, data);
  2306. }
  2307. }
  2308. /// <summary>
  2309. /// Update the texture entry for this part
  2310. /// </summary>
  2311. /// <param name="localID"></param>
  2312. /// <param name="textureEntry"></param>
  2313. public void UpdateTextureEntry(uint localID, byte[] textureEntry)
  2314. {
  2315. SceneObjectPart part = GetPart(localID);
  2316. if (part != null)
  2317. {
  2318. part.UpdateTextureEntry(textureEntry);
  2319. }
  2320. }
  2321. public void AdjustChildPrimPermissions()
  2322. {
  2323. uint newOwnerMask = (uint)(PermissionMask.All | PermissionMask.Export) & 0xfffffff8; // Mask folded bits
  2324. uint foldedPerms = RootPart.OwnerMask & 3;
  2325. ForEachPart(part =>
  2326. {
  2327. newOwnerMask &= part.BaseMask;
  2328. if (part != RootPart)
  2329. part.ClonePermissions(RootPart);
  2330. });
  2331. uint lockMask = ~(uint)(PermissionMask.Move | PermissionMask.Modify);
  2332. uint lockBit = RootPart.OwnerMask & (uint)(PermissionMask.Move | PermissionMask.Modify);
  2333. RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask);
  2334. RootPart.ScheduleFullUpdate();
  2335. }
  2336. public void UpdatePermissions(UUID AgentID, byte field, uint localID,
  2337. uint mask, byte addRemTF)
  2338. {
  2339. RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF);
  2340. AdjustChildPrimPermissions();
  2341. HasGroupChanged = true;
  2342. // Send the group's properties to all clients once all parts are updated
  2343. IClientAPI client;
  2344. if (Scene.TryGetClient(AgentID, out client))
  2345. SendPropertiesToClient(client);
  2346. }
  2347. #endregion
  2348. #region Shape
  2349. /// <summary>
  2350. ///
  2351. /// </summary>
  2352. /// <param name="shapeBlock"></param>
  2353. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock, uint localID)
  2354. {
  2355. SceneObjectPart part = GetPart(localID);
  2356. if (part != null)
  2357. {
  2358. part.UpdateShape(shapeBlock);
  2359. PhysicsActor pa = m_rootPart.PhysActor;
  2360. if (pa != null)
  2361. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2362. }
  2363. }
  2364. #endregion
  2365. #region Resize
  2366. /// <summary>
  2367. /// Resize the entire group of prims.
  2368. /// </summary>
  2369. /// <param name="scale"></param>
  2370. public void GroupResize(Vector3 scale)
  2371. {
  2372. // m_log.DebugFormat(
  2373. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
  2374. PhysicsActor pa = m_rootPart.PhysActor;
  2375. RootPart.StoreUndoState(true);
  2376. if (Scene != null)
  2377. {
  2378. scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X));
  2379. scale.Y = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.Y));
  2380. scale.Z = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.Z));
  2381. if (pa != null && pa.IsPhysical)
  2382. {
  2383. scale.X = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.X));
  2384. scale.Y = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.Y));
  2385. scale.Z = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.Z));
  2386. }
  2387. }
  2388. float x = (scale.X / RootPart.Scale.X);
  2389. float y = (scale.Y / RootPart.Scale.Y);
  2390. float z = (scale.Z / RootPart.Scale.Z);
  2391. SceneObjectPart[] parts = m_parts.GetArray();
  2392. if (Scene != null & (x > 1.0f || y > 1.0f || z > 1.0f))
  2393. {
  2394. for (int i = 0; i < parts.Length; i++)
  2395. {
  2396. SceneObjectPart obPart = parts[i];
  2397. if (obPart.UUID != m_rootPart.UUID)
  2398. {
  2399. // obPart.IgnoreUndoUpdate = true;
  2400. Vector3 oldSize = new Vector3(obPart.Scale);
  2401. float f = 1.0f;
  2402. float a = 1.0f;
  2403. if (pa != null && pa.IsPhysical)
  2404. {
  2405. if (oldSize.X * x > Scene.m_maxPhys)
  2406. {
  2407. f = m_scene.m_maxPhys / oldSize.X;
  2408. a = f / x;
  2409. x *= a;
  2410. y *= a;
  2411. z *= a;
  2412. }
  2413. else if (oldSize.X * x < Scene.m_minPhys)
  2414. {
  2415. f = m_scene.m_minPhys / oldSize.X;
  2416. a = f / x;
  2417. x *= a;
  2418. y *= a;
  2419. z *= a;
  2420. }
  2421. if (oldSize.Y * y > Scene.m_maxPhys)
  2422. {
  2423. f = m_scene.m_maxPhys / oldSize.Y;
  2424. a = f / y;
  2425. x *= a;
  2426. y *= a;
  2427. z *= a;
  2428. }
  2429. else if (oldSize.Y * y < Scene.m_minPhys)
  2430. {
  2431. f = m_scene.m_minPhys / oldSize.Y;
  2432. a = f / y;
  2433. x *= a;
  2434. y *= a;
  2435. z *= a;
  2436. }
  2437. if (oldSize.Z * z > Scene.m_maxPhys)
  2438. {
  2439. f = m_scene.m_maxPhys / oldSize.Z;
  2440. a = f / z;
  2441. x *= a;
  2442. y *= a;
  2443. z *= a;
  2444. }
  2445. else if (oldSize.Z * z < Scene.m_minPhys)
  2446. {
  2447. f = m_scene.m_minPhys / oldSize.Z;
  2448. a = f / z;
  2449. x *= a;
  2450. y *= a;
  2451. z *= a;
  2452. }
  2453. }
  2454. else
  2455. {
  2456. if (oldSize.X * x > Scene.m_maxNonphys)
  2457. {
  2458. f = m_scene.m_maxNonphys / oldSize.X;
  2459. a = f / x;
  2460. x *= a;
  2461. y *= a;
  2462. z *= a;
  2463. }
  2464. else if (oldSize.X * x < Scene.m_minNonphys)
  2465. {
  2466. f = m_scene.m_minNonphys / oldSize.X;
  2467. a = f / x;
  2468. x *= a;
  2469. y *= a;
  2470. z *= a;
  2471. }
  2472. if (oldSize.Y * y > Scene.m_maxNonphys)
  2473. {
  2474. f = m_scene.m_maxNonphys / oldSize.Y;
  2475. a = f / y;
  2476. x *= a;
  2477. y *= a;
  2478. z *= a;
  2479. }
  2480. else if (oldSize.Y * y < Scene.m_minNonphys)
  2481. {
  2482. f = m_scene.m_minNonphys / oldSize.Y;
  2483. a = f / y;
  2484. x *= a;
  2485. y *= a;
  2486. z *= a;
  2487. }
  2488. if (oldSize.Z * z > Scene.m_maxNonphys)
  2489. {
  2490. f = m_scene.m_maxNonphys / oldSize.Z;
  2491. a = f / z;
  2492. x *= a;
  2493. y *= a;
  2494. z *= a;
  2495. }
  2496. else if (oldSize.Z * z < Scene.m_minNonphys)
  2497. {
  2498. f = m_scene.m_minNonphys / oldSize.Z;
  2499. a = f / z;
  2500. x *= a;
  2501. y *= a;
  2502. z *= a;
  2503. }
  2504. }
  2505. // obPart.IgnoreUndoUpdate = false;
  2506. }
  2507. }
  2508. }
  2509. Vector3 prevScale = RootPart.Scale;
  2510. prevScale.X *= x;
  2511. prevScale.Y *= y;
  2512. prevScale.Z *= z;
  2513. // RootPart.IgnoreUndoUpdate = true;
  2514. RootPart.Resize(prevScale);
  2515. // RootPart.IgnoreUndoUpdate = false;
  2516. for (int i = 0; i < parts.Length; i++)
  2517. {
  2518. SceneObjectPart obPart = parts[i];
  2519. if (obPart.UUID != m_rootPart.UUID)
  2520. {
  2521. obPart.IgnoreUndoUpdate = true;
  2522. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  2523. currentpos.X *= x;
  2524. currentpos.Y *= y;
  2525. currentpos.Z *= z;
  2526. Vector3 newSize = new Vector3(obPart.Scale);
  2527. newSize.X *= x;
  2528. newSize.Y *= y;
  2529. newSize.Z *= z;
  2530. obPart.Resize(newSize);
  2531. obPart.UpdateOffSet(currentpos);
  2532. obPart.IgnoreUndoUpdate = false;
  2533. }
  2534. // obPart.IgnoreUndoUpdate = false;
  2535. // obPart.StoreUndoState();
  2536. }
  2537. // m_log.DebugFormat(
  2538. // "[SCENE OBJECT GROUP]: Finished group resizing {0} {1} to {2}", Name, LocalId, RootPart.Scale);
  2539. }
  2540. #endregion
  2541. #region Position
  2542. /// <summary>
  2543. /// Move this scene object
  2544. /// </summary>
  2545. /// <param name="pos"></param>
  2546. public void UpdateGroupPosition(Vector3 pos)
  2547. {
  2548. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Updating group position on {0} {1} to {2}", Name, LocalId, pos);
  2549. RootPart.StoreUndoState(true);
  2550. // SceneObjectPart[] parts = m_parts.GetArray();
  2551. // for (int i = 0; i < parts.Length; i++)
  2552. // parts[i].StoreUndoState();
  2553. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  2554. {
  2555. if (IsAttachment)
  2556. {
  2557. m_rootPart.AttachedPos = pos;
  2558. }
  2559. if (RootPart.GetStatusSandbox())
  2560. {
  2561. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, pos) > 10)
  2562. {
  2563. RootPart.ScriptSetPhysicsStatus(false);
  2564. pos = AbsolutePosition;
  2565. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  2566. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  2567. }
  2568. }
  2569. AbsolutePosition = pos;
  2570. HasGroupChanged = true;
  2571. }
  2572. //we need to do a terse update even if the move wasn't allowed
  2573. // so that the position is reset in the client (the object snaps back)
  2574. RootPart.ScheduleTerseUpdate();
  2575. }
  2576. /// <summary>
  2577. /// Update the position of a single part of this scene object
  2578. /// </summary>
  2579. /// <param name="pos"></param>
  2580. /// <param name="localID"></param>
  2581. public void UpdateSinglePosition(Vector3 pos, uint localID)
  2582. {
  2583. SceneObjectPart part = GetPart(localID);
  2584. // SceneObjectPart[] parts = m_parts.GetArray();
  2585. // for (int i = 0; i < parts.Length; i++)
  2586. // parts[i].StoreUndoState();
  2587. if (part != null)
  2588. {
  2589. // m_log.DebugFormat(
  2590. // "[SCENE OBJECT GROUP]: Updating single position of {0} {1} to {2}", part.Name, part.LocalId, pos);
  2591. part.StoreUndoState(false);
  2592. part.IgnoreUndoUpdate = true;
  2593. if (part.UUID == m_rootPart.UUID)
  2594. {
  2595. UpdateRootPosition(pos);
  2596. }
  2597. else
  2598. {
  2599. part.UpdateOffSet(pos);
  2600. }
  2601. HasGroupChanged = true;
  2602. part.IgnoreUndoUpdate = false;
  2603. }
  2604. }
  2605. /// <summary>
  2606. /// Update just the root prim position in a linkset
  2607. /// </summary>
  2608. /// <param name="newPos"></param>
  2609. public void UpdateRootPosition(Vector3 newPos)
  2610. {
  2611. // m_log.DebugFormat(
  2612. // "[SCENE OBJECT GROUP]: Updating root position of {0} {1} to {2}", Name, LocalId, pos);
  2613. // SceneObjectPart[] parts = m_parts.GetArray();
  2614. // for (int i = 0; i < parts.Length; i++)
  2615. // parts[i].StoreUndoState();
  2616. Vector3 oldPos;
  2617. if (IsAttachment)
  2618. oldPos = m_rootPart.AttachedPos + m_rootPart.OffsetPosition; // OffsetPosition should always be 0 in an attachments's root prim
  2619. else
  2620. oldPos = AbsolutePosition + m_rootPart.OffsetPosition;
  2621. Vector3 diff = oldPos - newPos;
  2622. Quaternion partRotation = m_rootPart.RotationOffset;
  2623. diff *= Quaternion.Inverse(partRotation);
  2624. SceneObjectPart[] parts = m_parts.GetArray();
  2625. for (int i = 0; i < parts.Length; i++)
  2626. {
  2627. SceneObjectPart obPart = parts[i];
  2628. if (obPart.UUID != m_rootPart.UUID)
  2629. obPart.OffsetPosition = obPart.OffsetPosition + diff;
  2630. }
  2631. AbsolutePosition = newPos;
  2632. if (IsAttachment)
  2633. m_rootPart.AttachedPos = newPos;
  2634. HasGroupChanged = true;
  2635. ScheduleGroupForTerseUpdate();
  2636. }
  2637. #endregion
  2638. #region Rotation
  2639. /// <summary>
  2640. /// Update the rotation of the group.
  2641. /// </summary>
  2642. /// <param name="rot"></param>
  2643. public void UpdateGroupRotationR(Quaternion rot)
  2644. {
  2645. // m_log.DebugFormat(
  2646. // "[SCENE OBJECT GROUP]: Updating group rotation R of {0} {1} to {2}", Name, LocalId, rot);
  2647. // SceneObjectPart[] parts = m_parts.GetArray();
  2648. // for (int i = 0; i < parts.Length; i++)
  2649. // parts[i].StoreUndoState();
  2650. m_rootPart.StoreUndoState(true);
  2651. m_rootPart.UpdateRotation(rot);
  2652. PhysicsActor actor = m_rootPart.PhysActor;
  2653. if (actor != null)
  2654. {
  2655. actor.Orientation = m_rootPart.RotationOffset;
  2656. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  2657. }
  2658. HasGroupChanged = true;
  2659. ScheduleGroupForTerseUpdate();
  2660. }
  2661. /// <summary>
  2662. /// Update the position and rotation of a group simultaneously.
  2663. /// </summary>
  2664. /// <param name="pos"></param>
  2665. /// <param name="rot"></param>
  2666. public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
  2667. {
  2668. // m_log.DebugFormat(
  2669. // "[SCENE OBJECT GROUP]: Updating group rotation PR of {0} {1} to {2}", Name, LocalId, rot);
  2670. // SceneObjectPart[] parts = m_parts.GetArray();
  2671. // for (int i = 0; i < parts.Length; i++)
  2672. // parts[i].StoreUndoState();
  2673. RootPart.StoreUndoState(true);
  2674. RootPart.IgnoreUndoUpdate = true;
  2675. m_rootPart.UpdateRotation(rot);
  2676. PhysicsActor actor = m_rootPart.PhysActor;
  2677. if (actor != null)
  2678. {
  2679. actor.Orientation = m_rootPart.RotationOffset;
  2680. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  2681. }
  2682. if (IsAttachment)
  2683. {
  2684. m_rootPart.AttachedPos = pos;
  2685. }
  2686. AbsolutePosition = pos;
  2687. HasGroupChanged = true;
  2688. ScheduleGroupForTerseUpdate();
  2689. RootPart.IgnoreUndoUpdate = false;
  2690. }
  2691. /// <summary>
  2692. /// Update the rotation of a single prim within the group.
  2693. /// </summary>
  2694. /// <param name="rot"></param>
  2695. /// <param name="localID"></param>
  2696. public void UpdateSingleRotation(Quaternion rot, uint localID)
  2697. {
  2698. SceneObjectPart part = GetPart(localID);
  2699. SceneObjectPart[] parts = m_parts.GetArray();
  2700. for (int i = 0; i < parts.Length; i++)
  2701. parts[i].StoreUndoState();
  2702. if (part != null)
  2703. {
  2704. // m_log.DebugFormat(
  2705. // "[SCENE OBJECT GROUP]: Updating single rotation of {0} {1} to {2}", part.Name, part.LocalId, rot);
  2706. if (part.UUID == m_rootPart.UUID)
  2707. {
  2708. UpdateRootRotation(rot);
  2709. }
  2710. else
  2711. {
  2712. part.UpdateRotation(rot);
  2713. }
  2714. }
  2715. }
  2716. /// <summary>
  2717. /// Update the position and rotation simultaneously of a single prim within the group.
  2718. /// </summary>
  2719. /// <param name="rot"></param>
  2720. /// <param name="localID"></param>
  2721. public void UpdateSingleRotation(Quaternion rot, Vector3 pos, uint localID)
  2722. {
  2723. SceneObjectPart part = GetPart(localID);
  2724. if (part != null)
  2725. {
  2726. // m_log.DebugFormat(
  2727. // "[SCENE OBJECT GROUP]: Updating single position and rotation of {0} {1} to {2}",
  2728. // part.Name, part.LocalId, rot);
  2729. part.StoreUndoState();
  2730. part.IgnoreUndoUpdate = true;
  2731. if (part.UUID == m_rootPart.UUID)
  2732. {
  2733. UpdateRootRotation(rot);
  2734. AbsolutePosition = pos;
  2735. }
  2736. else
  2737. {
  2738. part.UpdateRotation(rot);
  2739. part.OffsetPosition = pos;
  2740. }
  2741. part.IgnoreUndoUpdate = false;
  2742. }
  2743. }
  2744. /// <summary>
  2745. /// Update the rotation of just the root prim of a linkset.
  2746. /// </summary>
  2747. /// <param name="rot"></param>
  2748. public void UpdateRootRotation(Quaternion rot)
  2749. {
  2750. // m_log.DebugFormat(
  2751. // "[SCENE OBJECT GROUP]: Updating root rotation of {0} {1} to {2}",
  2752. // Name, LocalId, rot);
  2753. Quaternion axRot = rot;
  2754. Quaternion oldParentRot = m_rootPart.RotationOffset;
  2755. m_rootPart.StoreUndoState();
  2756. m_rootPart.UpdateRotation(rot);
  2757. PhysicsActor pa = m_rootPart.PhysActor;
  2758. if (pa != null)
  2759. {
  2760. pa.Orientation = m_rootPart.RotationOffset;
  2761. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2762. }
  2763. SceneObjectPart[] parts = m_parts.GetArray();
  2764. for (int i = 0; i < parts.Length; i++)
  2765. {
  2766. SceneObjectPart prim = parts[i];
  2767. if (prim.UUID != m_rootPart.UUID)
  2768. {
  2769. prim.IgnoreUndoUpdate = true;
  2770. Vector3 axPos = prim.OffsetPosition;
  2771. axPos *= oldParentRot;
  2772. axPos *= Quaternion.Inverse(axRot);
  2773. prim.OffsetPosition = axPos;
  2774. Quaternion primsRot = prim.RotationOffset;
  2775. Quaternion newRot = oldParentRot * primsRot;
  2776. newRot = Quaternion.Inverse(axRot) * newRot;
  2777. prim.RotationOffset = newRot;
  2778. prim.ScheduleTerseUpdate();
  2779. prim.IgnoreUndoUpdate = false;
  2780. }
  2781. }
  2782. // for (int i = 0; i < parts.Length; i++)
  2783. // {
  2784. // SceneObjectPart childpart = parts[i];
  2785. // if (childpart != m_rootPart)
  2786. // {
  2787. //// childpart.IgnoreUndoUpdate = false;
  2788. //// childpart.StoreUndoState();
  2789. // }
  2790. // }
  2791. m_rootPart.ScheduleTerseUpdate();
  2792. // m_log.DebugFormat(
  2793. // "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}",
  2794. // Name, LocalId, rot);
  2795. }
  2796. #endregion
  2797. internal void SetAxisRotation(int axis, int rotate10)
  2798. {
  2799. bool setX = false;
  2800. bool setY = false;
  2801. bool setZ = false;
  2802. int xaxis = 2;
  2803. int yaxis = 4;
  2804. int zaxis = 8;
  2805. setX = ((axis & xaxis) != 0) ? true : false;
  2806. setY = ((axis & yaxis) != 0) ? true : false;
  2807. setZ = ((axis & zaxis) != 0) ? true : false;
  2808. float setval = (rotate10 > 0) ? 1f : 0f;
  2809. if (setX)
  2810. RootPart.RotationAxis.X = setval;
  2811. if (setY)
  2812. RootPart.RotationAxis.Y = setval;
  2813. if (setZ)
  2814. RootPart.RotationAxis.Z = setval;
  2815. if (setX || setY || setZ)
  2816. RootPart.SetPhysicsAxisRotation();
  2817. }
  2818. public int registerRotTargetWaypoint(Quaternion target, float tolerance)
  2819. {
  2820. scriptRotTarget waypoint = new scriptRotTarget();
  2821. waypoint.targetRot = target;
  2822. waypoint.tolerance = tolerance;
  2823. uint handle = m_scene.AllocateLocalId();
  2824. waypoint.handle = handle;
  2825. lock (m_rotTargets)
  2826. {
  2827. m_rotTargets.Add(handle, waypoint);
  2828. }
  2829. m_scene.AddGroupTarget(this);
  2830. return (int)handle;
  2831. }
  2832. public void unregisterRotTargetWaypoint(int handle)
  2833. {
  2834. lock (m_targets)
  2835. {
  2836. m_rotTargets.Remove((uint)handle);
  2837. if (m_targets.Count == 0)
  2838. m_scene.RemoveGroupTarget(this);
  2839. }
  2840. }
  2841. public int registerTargetWaypoint(Vector3 target, float tolerance)
  2842. {
  2843. scriptPosTarget waypoint = new scriptPosTarget();
  2844. waypoint.targetPos = target;
  2845. waypoint.tolerance = tolerance;
  2846. uint handle = m_scene.AllocateLocalId();
  2847. waypoint.handle = handle;
  2848. lock (m_targets)
  2849. {
  2850. m_targets.Add(handle, waypoint);
  2851. }
  2852. m_scene.AddGroupTarget(this);
  2853. return (int)handle;
  2854. }
  2855. public void unregisterTargetWaypoint(int handle)
  2856. {
  2857. lock (m_targets)
  2858. {
  2859. m_targets.Remove((uint)handle);
  2860. if (m_targets.Count == 0)
  2861. m_scene.RemoveGroupTarget(this);
  2862. }
  2863. }
  2864. public void checkAtTargets()
  2865. {
  2866. if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
  2867. {
  2868. if (m_targets.Count > 0)
  2869. {
  2870. bool at_target = false;
  2871. //Vector3 targetPos;
  2872. //uint targetHandle;
  2873. Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
  2874. lock (m_targets)
  2875. {
  2876. foreach (uint idx in m_targets.Keys)
  2877. {
  2878. scriptPosTarget target = m_targets[idx];
  2879. if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
  2880. {
  2881. // trigger at_target
  2882. if (m_scriptListens_atTarget)
  2883. {
  2884. at_target = true;
  2885. scriptPosTarget att = new scriptPosTarget();
  2886. att.targetPos = target.targetPos;
  2887. att.tolerance = target.tolerance;
  2888. att.handle = target.handle;
  2889. atTargets.Add(idx, att);
  2890. }
  2891. }
  2892. }
  2893. }
  2894. if (atTargets.Count > 0)
  2895. {
  2896. SceneObjectPart[] parts = m_parts.GetArray();
  2897. uint[] localids = new uint[parts.Length];
  2898. for (int i = 0; i < parts.Length; i++)
  2899. localids[i] = parts[i].LocalId;
  2900. for (int ctr = 0; ctr < localids.Length; ctr++)
  2901. {
  2902. foreach (uint target in atTargets.Keys)
  2903. {
  2904. scriptPosTarget att = atTargets[target];
  2905. m_scene.EventManager.TriggerAtTargetEvent(
  2906. localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
  2907. }
  2908. }
  2909. return;
  2910. }
  2911. if (m_scriptListens_notAtTarget && !at_target)
  2912. {
  2913. //trigger not_at_target
  2914. SceneObjectPart[] parts = m_parts.GetArray();
  2915. uint[] localids = new uint[parts.Length];
  2916. for (int i = 0; i < parts.Length; i++)
  2917. localids[i] = parts[i].LocalId;
  2918. for (int ctr = 0; ctr < localids.Length; ctr++)
  2919. {
  2920. m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
  2921. }
  2922. }
  2923. }
  2924. }
  2925. if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
  2926. {
  2927. if (m_rotTargets.Count > 0)
  2928. {
  2929. bool at_Rottarget = false;
  2930. Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
  2931. lock (m_rotTargets)
  2932. {
  2933. foreach (uint idx in m_rotTargets.Keys)
  2934. {
  2935. scriptRotTarget target = m_rotTargets[idx];
  2936. double angle
  2937. = Math.Acos(
  2938. target.targetRot.X * m_rootPart.RotationOffset.X
  2939. + target.targetRot.Y * m_rootPart.RotationOffset.Y
  2940. + target.targetRot.Z * m_rootPart.RotationOffset.Z
  2941. + target.targetRot.W * m_rootPart.RotationOffset.W)
  2942. * 2;
  2943. if (angle < 0) angle = -angle;
  2944. if (angle > Math.PI) angle = (Math.PI * 2 - angle);
  2945. if (angle <= target.tolerance)
  2946. {
  2947. // trigger at_rot_target
  2948. if (m_scriptListens_atRotTarget)
  2949. {
  2950. at_Rottarget = true;
  2951. scriptRotTarget att = new scriptRotTarget();
  2952. att.targetRot = target.targetRot;
  2953. att.tolerance = target.tolerance;
  2954. att.handle = target.handle;
  2955. atRotTargets.Add(idx, att);
  2956. }
  2957. }
  2958. }
  2959. }
  2960. if (atRotTargets.Count > 0)
  2961. {
  2962. SceneObjectPart[] parts = m_parts.GetArray();
  2963. uint[] localids = new uint[parts.Length];
  2964. for (int i = 0; i < parts.Length; i++)
  2965. localids[i] = parts[i].LocalId;
  2966. for (int ctr = 0; ctr < localids.Length; ctr++)
  2967. {
  2968. foreach (uint target in atRotTargets.Keys)
  2969. {
  2970. scriptRotTarget att = atRotTargets[target];
  2971. m_scene.EventManager.TriggerAtRotTargetEvent(
  2972. localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
  2973. }
  2974. }
  2975. return;
  2976. }
  2977. if (m_scriptListens_notAtRotTarget && !at_Rottarget)
  2978. {
  2979. //trigger not_at_target
  2980. SceneObjectPart[] parts = m_parts.GetArray();
  2981. uint[] localids = new uint[parts.Length];
  2982. for (int i = 0; i < parts.Length; i++)
  2983. localids[i] = parts[i].LocalId;
  2984. for (int ctr = 0; ctr < localids.Length; ctr++)
  2985. {
  2986. m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
  2987. }
  2988. }
  2989. }
  2990. }
  2991. }
  2992. public float GetMass()
  2993. {
  2994. float retmass = 0f;
  2995. SceneObjectPart[] parts = m_parts.GetArray();
  2996. for (int i = 0; i < parts.Length; i++)
  2997. retmass += parts[i].GetMass();
  2998. return retmass;
  2999. }
  3000. /// <summary>
  3001. /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that
  3002. /// the physics engine can use it.
  3003. /// </summary>
  3004. /// <remarks>
  3005. /// When the physics engine has finished with it, the sculpt data is discarded to save memory.
  3006. /// </remarks>
  3007. /*
  3008. public void CheckSculptAndLoad()
  3009. {
  3010. if (IsDeleted)
  3011. return;
  3012. if ((RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  3013. return;
  3014. // m_log.Debug("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
  3015. SceneObjectPart[] parts = m_parts.GetArray();
  3016. for (int i = 0; i < parts.Length; i++)
  3017. parts[i].CheckSculptAndLoad();
  3018. }
  3019. */
  3020. /// <summary>
  3021. /// Set the user group to which this scene object belongs.
  3022. /// </summary>
  3023. /// <param name="GroupID"></param>
  3024. /// <param name="client"></param>
  3025. public void SetGroup(UUID GroupID, IClientAPI client)
  3026. {
  3027. SceneObjectPart[] parts = m_parts.GetArray();
  3028. for (int i = 0; i < parts.Length; i++)
  3029. {
  3030. SceneObjectPart part = parts[i];
  3031. part.SetGroup(GroupID, client);
  3032. part.Inventory.ChangeInventoryGroup(GroupID);
  3033. }
  3034. HasGroupChanged = true;
  3035. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  3036. // for the same object with very different properties. The caller must schedule the update.
  3037. //ScheduleGroupForFullUpdate();
  3038. }
  3039. public void TriggerScriptChangedEvent(Changed val)
  3040. {
  3041. SceneObjectPart[] parts = m_parts.GetArray();
  3042. for (int i = 0; i < parts.Length; i++)
  3043. parts[i].TriggerScriptChangedEvent(val);
  3044. }
  3045. /// <summary>
  3046. /// Returns a count of the number of scripts in this groups parts.
  3047. /// </summary>
  3048. public int ScriptCount()
  3049. {
  3050. int count = 0;
  3051. SceneObjectPart[] parts = m_parts.GetArray();
  3052. for (int i = 0; i < parts.Length; i++)
  3053. count += parts[i].Inventory.ScriptCount();
  3054. return count;
  3055. }
  3056. /// <summary>
  3057. /// A float the value is a representative execution time in milliseconds of all scripts in the link set.
  3058. /// </summary>
  3059. public float ScriptExecutionTime()
  3060. {
  3061. IScriptModule[] engines = Scene.RequestModuleInterfaces<IScriptModule>();
  3062. if (engines.Length == 0) // No engine at all
  3063. return 0.0f;
  3064. float time = 0.0f;
  3065. // get all the scripts in all parts
  3066. SceneObjectPart[] parts = m_parts.GetArray();
  3067. List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
  3068. for (int i = 0; i < parts.Length; i++)
  3069. {
  3070. scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
  3071. }
  3072. // extract the UUIDs
  3073. List<UUID> ids = new List<UUID>(scripts.Count);
  3074. foreach (TaskInventoryItem script in scripts)
  3075. {
  3076. if (!ids.Contains(script.ItemID))
  3077. {
  3078. ids.Add(script.ItemID);
  3079. }
  3080. }
  3081. // Offer the list of script UUIDs to each engine found and accumulate the time
  3082. foreach (IScriptModule e in engines)
  3083. {
  3084. if (e != null)
  3085. {
  3086. time += e.GetScriptExecutionTime(ids);
  3087. }
  3088. }
  3089. return time;
  3090. }
  3091. /// <summary>
  3092. /// Returns a count of the number of running scripts in this groups parts.
  3093. /// </summary>
  3094. public int RunningScriptCount()
  3095. {
  3096. int count = 0;
  3097. SceneObjectPart[] parts = m_parts.GetArray();
  3098. for (int i = 0; i < parts.Length; i++)
  3099. count += parts[i].Inventory.RunningScriptCount();
  3100. return count;
  3101. }
  3102. /// <summary>
  3103. /// Get a copy of the list of sitting avatars on all prims of this object.
  3104. /// </summary>
  3105. /// <remarks>
  3106. /// This is sorted by the order in which avatars sat down. If an avatar stands up then all avatars that sat
  3107. /// down after it move one place down the list.
  3108. /// </remarks>
  3109. /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns>
  3110. public List<UUID> GetSittingAvatars()
  3111. {
  3112. lock (m_sittingAvatars)
  3113. return new List<UUID>(m_sittingAvatars);
  3114. }
  3115. /// <summary>
  3116. /// Gets the number of sitting avatars.
  3117. /// </summary>
  3118. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  3119. /// <returns></returns>
  3120. public int GetSittingAvatarsCount()
  3121. {
  3122. lock (m_sittingAvatars)
  3123. return m_sittingAvatars.Count;
  3124. }
  3125. public override string ToString()
  3126. {
  3127. return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
  3128. }
  3129. #region ISceneObject
  3130. public virtual ISceneObject CloneForNewScene()
  3131. {
  3132. SceneObjectGroup sog = Copy(false);
  3133. sog.IsDeleted = false;
  3134. return sog;
  3135. }
  3136. public virtual string ToXml2()
  3137. {
  3138. return SceneObjectSerializer.ToXml2Format(this);
  3139. }
  3140. public virtual string ExtraToXmlString()
  3141. {
  3142. return "<ExtraFromItemID>" + FromItemID.ToString() + "</ExtraFromItemID>";
  3143. }
  3144. public virtual void ExtraFromXmlString(string xmlstr)
  3145. {
  3146. string id = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromItemID>"));
  3147. id = xmlstr.Replace("<ExtraFromItemID>", "");
  3148. id = id.Replace("</ExtraFromItemID>", "");
  3149. UUID uuid = UUID.Zero;
  3150. UUID.TryParse(id, out uuid);
  3151. FromItemID = uuid;
  3152. }
  3153. #endregion
  3154. }
  3155. }