1
0

SceneObjectGroup.cs 138 KB

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