SceneObjectPart.cs 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824
  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.Collections.Generic;
  29. using System.Drawing;
  30. using System.Reflection;
  31. using System.Runtime.Serialization;
  32. using System.Security.Permissions;
  33. using System.Xml;
  34. using System.Xml.Serialization;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Packets;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes.Scripting;
  41. using OpenSim.Region.Physics.Manager;
  42. namespace OpenSim.Region.Framework.Scenes
  43. {
  44. #region Enumerations
  45. [Flags]
  46. public enum Changed : uint
  47. {
  48. INVENTORY = 1,
  49. COLOR = 2,
  50. SHAPE = 4,
  51. SCALE = 8,
  52. TEXTURE = 16,
  53. LINK = 32,
  54. ALLOWED_DROP = 64,
  55. OWNER = 128,
  56. REGION_RESTART = 256,
  57. REGION = 512,
  58. TELEPORT = 1024
  59. }
  60. // I don't really know where to put this except here.
  61. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  62. [Flags]
  63. public enum ExtraParamType
  64. {
  65. Something1 = 1,
  66. Something2 = 2,
  67. Something3 = 4,
  68. Something4 = 8,
  69. Flexible = 16,
  70. Light = 32,
  71. Sculpt = 48,
  72. Something5 = 64,
  73. Something6 = 128
  74. }
  75. [Flags]
  76. public enum TextureAnimFlags : byte
  77. {
  78. NONE = 0x00,
  79. ANIM_ON = 0x01,
  80. LOOP = 0x02,
  81. REVERSE = 0x04,
  82. PING_PONG = 0x08,
  83. SMOOTH = 0x10,
  84. ROTATE = 0x20,
  85. SCALE = 0x40
  86. }
  87. #endregion Enumerations
  88. public class SceneObjectPart : IScriptHost
  89. {
  90. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  91. // use only one serializer to give the runtime a chance to optimize it (it won't do that if you
  92. // use a new instance every time)
  93. private static XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  94. #region Fields
  95. public bool AllowedDrop = false;
  96. [XmlIgnore]
  97. public bool DIE_AT_EDGE = false;
  98. // TODO: This needs to be persisted in next XML version update!
  99. [XmlIgnore]
  100. public int[] PayPrice = {-2,-2,-2,-2,-2};
  101. [XmlIgnore]
  102. public PhysicsActor PhysActor = null;
  103. //Xantor 20080528 Sound stuff:
  104. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  105. // Not a big problem as long as the script that sets it remains in the prim on startup.
  106. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  107. [XmlIgnore]
  108. public UUID Sound;
  109. [XmlIgnore]
  110. public byte SoundFlags;
  111. [XmlIgnore]
  112. public double SoundGain;
  113. [XmlIgnore]
  114. public double SoundRadius;
  115. [XmlIgnore]
  116. public uint TimeStampFull = 0;
  117. [XmlIgnore]
  118. public uint TimeStampLastActivity = 0; // Will be used for AutoReturn
  119. [XmlIgnore]
  120. public uint TimeStampTerse = 0;
  121. [XmlIgnore]
  122. public UUID FromItemID = UUID.Zero;
  123. /// <value>
  124. /// The UUID of the user inventory item from which this object was rezzed if this is a root part.
  125. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item.
  126. /// </value>
  127. private UUID m_fromUserInventoryItemID = UUID.Zero;
  128. [XmlIgnore]
  129. public UUID FromUserInventoryItemID
  130. {
  131. get { return m_fromUserInventoryItemID; }
  132. }
  133. [XmlIgnore]
  134. public bool IsAttachment = false;
  135. [XmlIgnore]
  136. public scriptEvents AggregateScriptEvents = 0;
  137. [XmlIgnore]
  138. public UUID AttachedAvatar = UUID.Zero;
  139. [XmlIgnore]
  140. public Vector3 AttachedPos = Vector3.Zero;
  141. [XmlIgnore]
  142. public uint AttachmentPoint = (byte)0;
  143. [XmlIgnore]
  144. public PhysicsVector RotationAxis = new PhysicsVector(1f,1f,1f);
  145. [XmlIgnore]
  146. public bool VolumeDetectActive = false; // XmlIgnore set to avoid problems with persistance until I come to care for this
  147. // Certainly this must be a persistant setting finally
  148. [XmlIgnore]
  149. public bool IsWaitingForFirstSpinUpdatePacket = false;
  150. [XmlIgnore]
  151. public Quaternion SpinOldOrientation = new Quaternion();
  152. /// <summary>
  153. /// This part's inventory
  154. /// </summary>
  155. [XmlIgnore]
  156. public IEntityInventory Inventory
  157. {
  158. get { return m_inventory; }
  159. }
  160. protected SceneObjectPartInventory m_inventory;
  161. [XmlIgnore]
  162. public bool Undoing = false;
  163. [XmlIgnore]
  164. private PrimFlags LocalFlags = 0;
  165. [XmlIgnore]
  166. private float m_damage = -1.0f;
  167. private byte[] m_TextureAnimation;
  168. private byte m_clickAction = 0;
  169. private Color m_color = Color.Black;
  170. private string m_description = String.Empty;
  171. private readonly List<uint> m_lastColliders = new List<uint>();
  172. // private PhysicsVector m_lastRotationalVelocity = PhysicsVector.Zero;
  173. private int m_linkNum = 0;
  174. [XmlIgnore]
  175. private int m_scriptAccessPin = 0;
  176. [XmlIgnore]
  177. private readonly Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  178. private string m_sitName = String.Empty;
  179. private Quaternion m_sitTargetOrientation = Quaternion.Identity;
  180. private Vector3 m_sitTargetPosition = Vector3.Zero;
  181. private string m_sitAnimation = "SIT";
  182. private string m_text = String.Empty;
  183. private string m_touchName = String.Empty;
  184. private readonly UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5);
  185. private UUID _creatorID;
  186. private bool m_passTouches = false;
  187. /// <summary>
  188. /// Only used internally to schedule client updates.
  189. /// 0 - no update is scheduled
  190. /// 1 - terse update scheduled
  191. /// 2 - full update scheduled
  192. ///
  193. /// TODO - This should be an enumeration
  194. /// </summary>
  195. private byte m_updateFlag;
  196. protected Vector3 m_acceleration;
  197. protected Vector3 m_angularVelocity;
  198. //unkown if this will be kept, added as a way of removing the group position from the group class
  199. protected Vector3 m_groupPosition;
  200. protected uint m_localId;
  201. protected Material m_material = (Material)3; // Wood
  202. protected string m_name;
  203. protected Vector3 m_offsetPosition;
  204. // FIXME, TODO, ERROR: 'ParentGroup' can't be in here, move it out.
  205. protected SceneObjectGroup m_parentGroup;
  206. protected byte[] m_particleSystem = new byte[0];
  207. protected ulong m_regionHandle;
  208. protected Quaternion m_rotationOffset;
  209. protected PrimitiveBaseShape m_shape = null;
  210. protected UUID m_uuid;
  211. protected Vector3 m_velocity;
  212. // TODO: Those have to be changed into persistent properties at some later point,
  213. // or sit-camera on vehicles will break on sim-crossing.
  214. private Vector3 m_cameraEyeOffset = new Vector3(0.0f, 0.0f, 0.0f);
  215. private Vector3 m_cameraAtOffset = new Vector3(0.0f, 0.0f, 0.0f);
  216. private bool m_forceMouselook = false;
  217. // TODO: Collision sound should have default.
  218. private UUID m_collisionSound = UUID.Zero;
  219. private float m_collisionSoundVolume = 0.0f;
  220. #endregion Fields
  221. #region Constructors
  222. /// <summary>
  223. /// No arg constructor called by region restore db code
  224. /// </summary>
  225. public SceneObjectPart()
  226. {
  227. // It's not necessary to persist this
  228. m_TextureAnimation = new byte[0];
  229. m_particleSystem = new byte[0];
  230. Rezzed = DateTime.Now;
  231. m_inventory = new SceneObjectPartInventory(this);
  232. }
  233. /// <summary>
  234. /// Create a completely new SceneObjectPart (prim). This will need to be added separately to a SceneObjectGroup
  235. /// </summary>
  236. /// <param name="ownerID"></param>
  237. /// <param name="shape"></param>
  238. /// <param name="position"></param>
  239. /// <param name="rotationOffset"></param>
  240. /// <param name="offsetPosition"></param>
  241. public SceneObjectPart(
  242. UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
  243. Quaternion rotationOffset, Vector3 offsetPosition)
  244. {
  245. m_name = "Primitive";
  246. Rezzed = DateTime.Now;
  247. _creationDate = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  248. _ownerID = ownerID;
  249. _creatorID = _ownerID;
  250. _lastOwnerID = UUID.Zero;
  251. UUID = UUID.Random();
  252. Shape = shape;
  253. // Todo: Add More Object Parameter from above!
  254. _ownershipCost = 0;
  255. _objectSaleType = (byte) 0;
  256. _salePrice = 0;
  257. _category = (uint) 0;
  258. _lastOwnerID = _creatorID;
  259. // End Todo: ///
  260. GroupPosition = groupPosition;
  261. OffsetPosition = offsetPosition;
  262. RotationOffset = rotationOffset;
  263. Velocity = new Vector3(0, 0, 0);
  264. AngularVelocity = new Vector3(0, 0, 0);
  265. Acceleration = new Vector3(0, 0, 0);
  266. m_TextureAnimation = new byte[0];
  267. m_particleSystem = new byte[0];
  268. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  269. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  270. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  271. _flags = 0;
  272. _flags |= PrimFlags.CreateSelected;
  273. TrimPermissions();
  274. //m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo());
  275. m_inventory = new SceneObjectPartInventory(this);
  276. }
  277. #endregion Constructors
  278. #region XML Schema
  279. private UUID _lastOwnerID;
  280. private UUID _ownerID;
  281. private UUID _groupID;
  282. private int _ownershipCost;
  283. private byte _objectSaleType;
  284. private int _salePrice;
  285. private uint _category;
  286. private Int32 _creationDate;
  287. private uint _parentID = 0;
  288. private UUID m_sitTargetAvatar = UUID.Zero;
  289. private uint _baseMask = (uint)PermissionMask.All;
  290. private uint _ownerMask = (uint)PermissionMask.All;
  291. private uint _groupMask = (uint)PermissionMask.None;
  292. private uint _everyoneMask = (uint)PermissionMask.None;
  293. private uint _nextOwnerMask = (uint)PermissionMask.All;
  294. private PrimFlags _flags = 0;
  295. private DateTime m_expires;
  296. private DateTime m_rezzed;
  297. public UUID CreatorID
  298. {
  299. get
  300. {
  301. return _creatorID;
  302. }
  303. set
  304. {
  305. _creatorID = value;
  306. }
  307. }
  308. /// <summary>
  309. /// A relic from when we we thought that prims contained folder objects. In
  310. /// reality, prim == folder
  311. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  312. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  313. /// </summary>
  314. public UUID FolderID
  315. {
  316. get { return UUID; }
  317. set { } // Don't allow assignment, or legacy prims wil b0rk - but we need the setter for legacy serialization.
  318. }
  319. /// <value>
  320. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  321. /// </value>
  322. public uint InventorySerial
  323. {
  324. get { return m_inventory.Serial; }
  325. set { m_inventory.Serial = value; }
  326. }
  327. /// <value>
  328. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  329. /// </value>
  330. public TaskInventoryDictionary TaskInventory
  331. {
  332. get { return m_inventory.Items; }
  333. set { m_inventory.Items = value; }
  334. }
  335. public uint ObjectFlags
  336. {
  337. get { return (uint)_flags; }
  338. set { _flags = (PrimFlags)value; }
  339. }
  340. public UUID UUID
  341. {
  342. get { return m_uuid; }
  343. set { m_uuid = value; }
  344. }
  345. public uint LocalId
  346. {
  347. get { return m_localId; }
  348. set { m_localId = value; }
  349. }
  350. public virtual string Name
  351. {
  352. get { return m_name; }
  353. set
  354. {
  355. m_name = value;
  356. PhysicsActor pa = PhysActor;
  357. if (pa != null)
  358. {
  359. pa.SOPName = value;
  360. }
  361. }
  362. }
  363. public byte Material
  364. {
  365. get { return (byte) m_material; }
  366. set
  367. {
  368. PhysicsActor pa = PhysActor;
  369. m_material = (Material)value;
  370. if (pa != null)
  371. {
  372. pa.SetMaterial((int)value);
  373. }
  374. }
  375. }
  376. public bool PassTouches
  377. {
  378. get { return m_passTouches; }
  379. set
  380. {
  381. m_passTouches = value;
  382. if (ParentGroup != null)
  383. ParentGroup.HasGroupChanged = true;
  384. }
  385. }
  386. public ulong RegionHandle
  387. {
  388. get { return m_regionHandle; }
  389. set { m_regionHandle = value; }
  390. }
  391. public int ScriptAccessPin
  392. {
  393. get { return m_scriptAccessPin; }
  394. set { m_scriptAccessPin = (int)value; }
  395. }
  396. [XmlIgnore]
  397. public Byte[] TextureAnimation
  398. {
  399. get { return m_TextureAnimation; }
  400. set { m_TextureAnimation = value; }
  401. }
  402. [XmlIgnore]
  403. public Byte[] ParticleSystem
  404. {
  405. get { return m_particleSystem; }
  406. set { m_particleSystem = value; }
  407. }
  408. [XmlIgnore]
  409. public DateTime Expires
  410. {
  411. get { return m_expires; }
  412. set { m_expires = value; }
  413. }
  414. [XmlIgnore]
  415. public DateTime Rezzed
  416. {
  417. get { return m_rezzed; }
  418. set { m_rezzed = value; }
  419. }
  420. [XmlIgnore]
  421. public float Damage
  422. {
  423. get { return m_damage; }
  424. set { m_damage = value; }
  425. }
  426. /// <summary>
  427. /// The position of the entire group that this prim belongs to.
  428. /// </summary>
  429. public Vector3 GroupPosition
  430. {
  431. get
  432. {
  433. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  434. PhysicsActor pa = PhysActor;
  435. if (pa != null && _parentID == 0)
  436. {
  437. m_groupPosition.X = pa.Position.X;
  438. m_groupPosition.Y = pa.Position.Y;
  439. m_groupPosition.Z = pa.Position.Z;
  440. }
  441. if (IsAttachment)
  442. {
  443. ScenePresence sp = m_parentGroup.Scene.GetScenePresence(AttachedAvatar);
  444. if (sp != null)
  445. {
  446. return sp.AbsolutePosition;
  447. }
  448. }
  449. return m_groupPosition;
  450. }
  451. set
  452. {
  453. StoreUndoState();
  454. m_groupPosition = value;
  455. PhysicsActor pa = PhysActor;
  456. if (pa != null)
  457. {
  458. try
  459. {
  460. // Root prim actually goes at Position
  461. if (_parentID == 0)
  462. {
  463. pa.Position = new PhysicsVector(value.X, value.Y, value.Z);
  464. }
  465. else
  466. {
  467. // To move the child prim in respect to the group position and rotation we have to calculate
  468. Vector3 resultingposition = GetWorldPosition();
  469. pa.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z);
  470. Quaternion resultingrot = GetWorldRotation();
  471. pa.Orientation = resultingrot;
  472. }
  473. // Tell the physics engines that this prim changed.
  474. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  475. }
  476. catch (Exception e)
  477. {
  478. m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
  479. }
  480. }
  481. // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
  482. if (m_sitTargetAvatar != UUID.Zero)
  483. {
  484. if (m_parentGroup != null) // TODO can there be a SOP without a SOG?
  485. {
  486. ScenePresence avatar;
  487. if (m_parentGroup.Scene.TryGetAvatar(m_sitTargetAvatar, out avatar))
  488. {
  489. avatar.ParentPosition = GetWorldPosition();
  490. }
  491. }
  492. }
  493. }
  494. }
  495. public Vector3 OffsetPosition
  496. {
  497. get { return m_offsetPosition; }
  498. set
  499. {
  500. StoreUndoState();
  501. m_offsetPosition = value;
  502. if (ParentGroup != null && !ParentGroup.IsDeleted)
  503. {
  504. PhysicsActor pa = PhysActor;
  505. if (_parentID != 0 && pa != null)
  506. {
  507. Vector3 resultingposition = GetWorldPosition();
  508. pa.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z);
  509. Quaternion resultingrot = GetWorldRotation();
  510. pa.Orientation = resultingrot;
  511. // Tell the physics engines that this prim changed.
  512. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  513. }
  514. }
  515. }
  516. }
  517. public Quaternion RotationOffset
  518. {
  519. get
  520. {
  521. PhysicsActor pa = PhysActor;
  522. // We don't want the physics engine mucking up the rotations in a linkset
  523. if ((_parentID == 0) && (Shape.PCode != 9 || Shape.State == 0) && (pa != null))
  524. {
  525. if (pa.Orientation.X != 0 || pa.Orientation.Y != 0
  526. || pa.Orientation.Z != 0 || pa.Orientation.W != 0)
  527. {
  528. m_rotationOffset = pa.Orientation;
  529. }
  530. }
  531. return m_rotationOffset;
  532. }
  533. set
  534. {
  535. PhysicsActor pa = PhysActor;
  536. StoreUndoState();
  537. m_rotationOffset = value;
  538. if (pa != null)
  539. {
  540. try
  541. {
  542. // Root prim gets value directly
  543. if (_parentID == 0)
  544. {
  545. pa.Orientation = value;
  546. //m_log.Info("[PART]: RO1:" + PhysActor.Orientation.ToString());
  547. }
  548. else
  549. {
  550. // Child prim we have to calculate it's world rotationwel
  551. Quaternion resultingrotation = GetWorldRotation();
  552. pa.Orientation = resultingrotation;
  553. //m_log.Info("[PART]: RO2:" + PhysActor.Orientation.ToString());
  554. }
  555. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  556. //}
  557. }
  558. catch (Exception ex)
  559. {
  560. m_log.Error("[SCENEOBJECTPART]: ROTATIONOFFSET" + ex.Message);
  561. }
  562. }
  563. }
  564. }
  565. /// <summary></summary>
  566. public Vector3 Velocity
  567. {
  568. get
  569. {
  570. //if (PhysActor.Velocity.X != 0 || PhysActor.Velocity.Y != 0
  571. //|| PhysActor.Velocity.Z != 0)
  572. //{
  573. PhysicsActor pa = PhysActor;
  574. if (pa != null)
  575. {
  576. if (pa.IsPhysical)
  577. {
  578. m_velocity.X = pa.Velocity.X;
  579. m_velocity.Y = pa.Velocity.Y;
  580. m_velocity.Z = pa.Velocity.Z;
  581. }
  582. }
  583. return m_velocity;
  584. }
  585. set
  586. {
  587. m_velocity = value;
  588. PhysicsActor pa = PhysActor;
  589. if (pa != null)
  590. {
  591. if (pa.IsPhysical)
  592. {
  593. pa.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  594. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  595. }
  596. }
  597. }
  598. }
  599. public Vector3 RotationalVelocity
  600. {
  601. get { return AngularVelocity; }
  602. set { AngularVelocity = value; }
  603. }
  604. /// <summary></summary>
  605. public Vector3 AngularVelocity
  606. {
  607. get
  608. {
  609. PhysicsActor pa = PhysActor;
  610. if ((pa != null) && pa.IsPhysical)
  611. {
  612. m_angularVelocity.FromBytes(pa.RotationalVelocity.GetBytes(), 0);
  613. }
  614. return m_angularVelocity;
  615. }
  616. set { m_angularVelocity = value; }
  617. }
  618. /// <summary></summary>
  619. public Vector3 Acceleration
  620. {
  621. get { return m_acceleration; }
  622. set { m_acceleration = value; }
  623. }
  624. public string Description
  625. {
  626. get { return m_description; }
  627. set
  628. {
  629. PhysicsActor pa = PhysActor;
  630. m_description = value;
  631. if (pa != null)
  632. {
  633. pa.SOPDescription = value;
  634. }
  635. }
  636. }
  637. public Color Color
  638. {
  639. get { return m_color; }
  640. set
  641. {
  642. m_color = value;
  643. TriggerScriptChangedEvent(Changed.COLOR);
  644. /* ScheduleFullUpdate() need not be called b/c after
  645. * setting the color, the text will be set, so then
  646. * ScheduleFullUpdate() will be called. */
  647. //ScheduleFullUpdate();
  648. }
  649. }
  650. public string Text
  651. {
  652. get
  653. {
  654. string returnstr = m_text;
  655. if (returnstr.Length > 255)
  656. {
  657. returnstr = returnstr.Substring(0, 254);
  658. }
  659. return returnstr;
  660. }
  661. set
  662. {
  663. m_text = value;
  664. }
  665. }
  666. public string SitName
  667. {
  668. get { return m_sitName; }
  669. set { m_sitName = value; }
  670. }
  671. public string TouchName
  672. {
  673. get { return m_touchName; }
  674. set { m_touchName = value; }
  675. }
  676. public int LinkNum
  677. {
  678. get { return m_linkNum; }
  679. set { m_linkNum = value; }
  680. }
  681. public byte ClickAction
  682. {
  683. get { return m_clickAction; }
  684. set
  685. {
  686. m_clickAction = value;
  687. }
  688. }
  689. public PrimitiveBaseShape Shape
  690. {
  691. get { return m_shape; }
  692. set
  693. {
  694. bool shape_changed = false;
  695. // TODO: this should really be restricted to the right
  696. // set of attributes on shape change. For instance,
  697. // changing the lighting on a shape shouldn't cause
  698. // this.
  699. if (m_shape != null)
  700. shape_changed = true;
  701. m_shape = value;
  702. if (shape_changed)
  703. TriggerScriptChangedEvent(Changed.SHAPE);
  704. }
  705. }
  706. public Vector3 Scale
  707. {
  708. get { return m_shape.Scale; }
  709. set
  710. {
  711. StoreUndoState();
  712. if (m_shape != null) {
  713. m_shape.Scale = value;
  714. PhysicsActor pa = PhysActor;
  715. if (pa != null && m_parentGroup != null)
  716. {
  717. if (m_parentGroup.Scene != null)
  718. {
  719. if (m_parentGroup.Scene.PhysicsScene != null)
  720. {
  721. pa.Size = new PhysicsVector(m_shape.Scale.X, m_shape.Scale.Y, m_shape.Scale.Z);
  722. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  723. }
  724. }
  725. }
  726. }
  727. TriggerScriptChangedEvent(Changed.SCALE);
  728. }
  729. }
  730. public byte UpdateFlag
  731. {
  732. get { return m_updateFlag; }
  733. set { m_updateFlag = value; }
  734. }
  735. #endregion
  736. //---------------
  737. #region Public Properties with only Get
  738. public Vector3 AbsolutePosition
  739. {
  740. get {
  741. if (IsAttachment)
  742. return GroupPosition;
  743. return m_offsetPosition + m_groupPosition; }
  744. }
  745. public SceneObjectGroup ParentGroup
  746. {
  747. get { return m_parentGroup; }
  748. }
  749. public scriptEvents ScriptEvents
  750. {
  751. get { return AggregateScriptEvents; }
  752. }
  753. public Quaternion SitTargetOrientation
  754. {
  755. get { return m_sitTargetOrientation; }
  756. set { m_sitTargetOrientation = value; }
  757. }
  758. public Vector3 SitTargetPosition
  759. {
  760. get { return m_sitTargetPosition; }
  761. set { m_sitTargetPosition = value; }
  762. }
  763. // This sort of sucks, but I'm adding these in to make some of
  764. // the mappings more consistant.
  765. public Vector3 SitTargetPositionLL
  766. {
  767. get { return new Vector3(m_sitTargetPosition.X, m_sitTargetPosition.Y,m_sitTargetPosition.Z); }
  768. set { m_sitTargetPosition = value; }
  769. }
  770. public Quaternion SitTargetOrientationLL
  771. {
  772. get
  773. {
  774. return new Quaternion(
  775. m_sitTargetOrientation.X,
  776. m_sitTargetOrientation.Y,
  777. m_sitTargetOrientation.Z,
  778. m_sitTargetOrientation.W
  779. );
  780. }
  781. set { m_sitTargetOrientation = new Quaternion(value.X, value.Y, value.Z, value.W); }
  782. }
  783. public bool Stopped
  784. {
  785. get {
  786. double threshold = 0.02;
  787. return (Math.Abs(Velocity.X) < threshold &&
  788. Math.Abs(Velocity.Y) < threshold &&
  789. Math.Abs(Velocity.Z) < threshold &&
  790. Math.Abs(AngularVelocity.X) < threshold &&
  791. Math.Abs(AngularVelocity.Y) < threshold &&
  792. Math.Abs(AngularVelocity.Z) < threshold);
  793. }
  794. }
  795. public uint ParentID
  796. {
  797. get { return _parentID; }
  798. set { _parentID = value; }
  799. }
  800. public int CreationDate
  801. {
  802. get { return _creationDate; }
  803. set { _creationDate = value; }
  804. }
  805. public uint Category
  806. {
  807. get { return _category; }
  808. set { _category = value; }
  809. }
  810. public int SalePrice
  811. {
  812. get { return _salePrice; }
  813. set { _salePrice = value; }
  814. }
  815. public byte ObjectSaleType
  816. {
  817. get { return _objectSaleType; }
  818. set { _objectSaleType = value; }
  819. }
  820. public int OwnershipCost
  821. {
  822. get { return _ownershipCost; }
  823. set { _ownershipCost = value; }
  824. }
  825. public UUID GroupID
  826. {
  827. get { return _groupID; }
  828. set { _groupID = value; }
  829. }
  830. public UUID OwnerID
  831. {
  832. get { return _ownerID; }
  833. set { _ownerID = value; }
  834. }
  835. public UUID LastOwnerID
  836. {
  837. get { return _lastOwnerID; }
  838. set { _lastOwnerID = value; }
  839. }
  840. public uint BaseMask
  841. {
  842. get { return _baseMask; }
  843. set { _baseMask = value; }
  844. }
  845. public uint OwnerMask
  846. {
  847. get { return _ownerMask; }
  848. set { _ownerMask = value; }
  849. }
  850. public uint GroupMask
  851. {
  852. get { return _groupMask; }
  853. set { _groupMask = value; }
  854. }
  855. public uint EveryoneMask
  856. {
  857. get { return _everyoneMask; }
  858. set { _everyoneMask = value; }
  859. }
  860. public uint NextOwnerMask
  861. {
  862. get { return _nextOwnerMask; }
  863. set { _nextOwnerMask = value; }
  864. }
  865. public PrimFlags Flags
  866. {
  867. get { return _flags; }
  868. set { _flags = value; }
  869. }
  870. [XmlIgnore]
  871. public UUID SitTargetAvatar
  872. {
  873. get { return m_sitTargetAvatar; }
  874. set { m_sitTargetAvatar = value; }
  875. }
  876. [XmlIgnore]
  877. public virtual UUID RegionID
  878. {
  879. get
  880. {
  881. if (ParentGroup != null && ParentGroup.Scene != null)
  882. return ParentGroup.Scene.RegionInfo.RegionID;
  883. else
  884. return UUID.Zero;
  885. }
  886. set {} // read only
  887. }
  888. private UUID _parentUUID = UUID.Zero;
  889. [XmlIgnore]
  890. public UUID ParentUUID
  891. {
  892. get
  893. {
  894. if (ParentGroup != null)
  895. {
  896. _parentUUID = ParentGroup.UUID;
  897. }
  898. return _parentUUID;
  899. }
  900. set { _parentUUID = value; }
  901. }
  902. [XmlIgnore]
  903. public string SitAnimation
  904. {
  905. get { return m_sitAnimation; }
  906. set { m_sitAnimation = value; }
  907. }
  908. public UUID CollisionSound
  909. {
  910. get { return m_collisionSound; }
  911. set
  912. {
  913. m_collisionSound = value;
  914. aggregateScriptEvents();
  915. }
  916. }
  917. public float CollisionSoundVolume
  918. {
  919. get { return m_collisionSoundVolume; }
  920. set { m_collisionSoundVolume = value; }
  921. }
  922. #endregion Public Properties with only Get
  923. #region Private Methods
  924. private uint ApplyMask(uint val, bool set, uint mask)
  925. {
  926. if (set)
  927. {
  928. return val |= mask;
  929. }
  930. else
  931. {
  932. return val &= ~mask;
  933. }
  934. }
  935. /// <summary>
  936. /// Clear all pending updates of parts to clients
  937. /// </summary>
  938. private void ClearUpdateSchedule()
  939. {
  940. m_updateFlag = 0;
  941. }
  942. private void SendObjectPropertiesToClient(UUID AgentID)
  943. {
  944. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  945. for (int i = 0; i < avatars.Count; i++)
  946. {
  947. // Ugly reference :(
  948. if (avatars[i].UUID == AgentID)
  949. {
  950. m_parentGroup.GetProperties(avatars[i].ControllingClient);
  951. }
  952. }
  953. }
  954. // TODO: unused:
  955. // private void handleTimerAccounting(uint localID, double interval)
  956. // {
  957. // if (localID == LocalId)
  958. // {
  959. // float sec = (float)interval;
  960. // if (m_parentGroup != null)
  961. // {
  962. // if (sec == 0)
  963. // {
  964. // if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  965. // m_parentGroup.scriptScore = 0;
  966. //
  967. // m_parentGroup.scriptScore += 0.001f;
  968. // return;
  969. // }
  970. //
  971. // if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  972. // m_parentGroup.scriptScore = 0;
  973. // m_parentGroup.scriptScore += (0.001f / sec);
  974. // }
  975. // }
  976. // }
  977. #endregion Private Methods
  978. #region Public Methods
  979. public void ResetExpire()
  980. {
  981. Expires = DateTime.Now + new TimeSpan(600000000);
  982. }
  983. public void AddFlag(PrimFlags flag)
  984. {
  985. // PrimFlags prevflag = Flags;
  986. if ((ObjectFlags & (uint) flag) == 0)
  987. {
  988. //m_log.Debug("Adding flag: " + ((PrimFlags) flag).ToString());
  989. _flags |= flag;
  990. if (flag == PrimFlags.TemporaryOnRez)
  991. ResetExpire();
  992. }
  993. // m_log.Debug("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  994. }
  995. /// <summary>
  996. /// Tell all scene presences that they should send updates for this part to their clients
  997. /// </summary>
  998. public void AddFullUpdateToAllAvatars()
  999. {
  1000. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1001. for (int i = 0; i < avatars.Count; i++)
  1002. {
  1003. avatars[i].SceneViewer.QueuePartForUpdate(this);
  1004. }
  1005. }
  1006. public void AddFullUpdateToAvatar(ScenePresence presence)
  1007. {
  1008. presence.SceneViewer.QueuePartForUpdate(this);
  1009. }
  1010. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1011. {
  1012. m_particleSystem = pSystem.GetBytes();
  1013. }
  1014. public void RemoveParticleSystem()
  1015. {
  1016. m_particleSystem = new byte[0];
  1017. }
  1018. /// Terse updates
  1019. public void AddTerseUpdateToAllAvatars()
  1020. {
  1021. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1022. for (int i = 0; i < avatars.Count; i++)
  1023. {
  1024. avatars[i].SceneViewer.QueuePartForUpdate(this);
  1025. }
  1026. }
  1027. public void AddTerseUpdateToAvatar(ScenePresence presence)
  1028. {
  1029. presence.SceneViewer.QueuePartForUpdate(this);
  1030. }
  1031. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1032. {
  1033. byte[] data = new byte[16];
  1034. int pos = 0;
  1035. // The flags don't like conversion from uint to byte, so we have to do
  1036. // it the crappy way. See the above function :(
  1037. data[pos] = ConvertScriptUintToByte((uint)pTexAnim.Flags); pos++;
  1038. data[pos] = (byte)pTexAnim.Face; pos++;
  1039. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1040. data[pos] = (byte)pTexAnim.SizeY; pos++;
  1041. Utils.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1042. Utils.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4);
  1043. Utils.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1044. m_TextureAnimation = data;
  1045. }
  1046. public void AdjustSoundGain(double volume)
  1047. {
  1048. if (volume > 1)
  1049. volume = 1;
  1050. if (volume < 0)
  1051. volume = 0;
  1052. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1053. foreach (ScenePresence p in avatarts)
  1054. {
  1055. p.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
  1056. }
  1057. }
  1058. /// <summary>
  1059. /// hook to the physics scene to apply impulse
  1060. /// This is sent up to the group, which then finds the root prim
  1061. /// and applies the force on the root prim of the group
  1062. /// </summary>
  1063. /// <param name="impulsei">Vector force</param>
  1064. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1065. public void ApplyImpulse(Vector3 impulsei, bool localGlobalTF)
  1066. {
  1067. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  1068. if (localGlobalTF)
  1069. {
  1070. Quaternion grot = GetWorldRotation();
  1071. Quaternion AXgrot = grot;
  1072. Vector3 AXimpulsei = impulsei;
  1073. Vector3 newimpulse = AXimpulsei * AXgrot;
  1074. impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z);
  1075. }
  1076. if (m_parentGroup != null)
  1077. {
  1078. m_parentGroup.applyImpulse(impulse);
  1079. }
  1080. }
  1081. /// <summary>
  1082. /// hook to the physics scene to apply angular impulse
  1083. /// This is sent up to the group, which then finds the root prim
  1084. /// and applies the force on the root prim of the group
  1085. /// </summary>
  1086. /// <param name="impulsei">Vector force</param>
  1087. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1088. public void ApplyAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1089. {
  1090. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  1091. if (localGlobalTF)
  1092. {
  1093. Quaternion grot = GetWorldRotation();
  1094. Quaternion AXgrot = grot;
  1095. Vector3 AXimpulsei = impulsei;
  1096. Vector3 newimpulse = AXimpulsei * AXgrot;
  1097. impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z);
  1098. }
  1099. if (m_parentGroup != null)
  1100. {
  1101. m_parentGroup.applyAngularImpulse(impulse);
  1102. }
  1103. }
  1104. /// <summary>
  1105. /// hook to the physics scene to apply angular impulse
  1106. /// This is sent up to the group, which then finds the root prim
  1107. /// and applies the force on the root prim of the group
  1108. /// </summary>
  1109. /// <param name="impulsei">Vector force</param>
  1110. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1111. public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1112. {
  1113. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  1114. if (localGlobalTF)
  1115. {
  1116. Quaternion grot = GetWorldRotation();
  1117. Quaternion AXgrot = grot;
  1118. Vector3 AXimpulsei = impulsei;
  1119. Vector3 newimpulse = AXimpulsei * AXgrot;
  1120. impulse = new PhysicsVector(newimpulse.X, newimpulse.Y, newimpulse.Z);
  1121. }
  1122. if (m_parentGroup != null)
  1123. {
  1124. m_parentGroup.setAngularImpulse(impulse);
  1125. }
  1126. }
  1127. public Vector3 GetTorque()
  1128. {
  1129. if (m_parentGroup != null)
  1130. {
  1131. m_parentGroup.GetTorque();
  1132. }
  1133. return Vector3.Zero;
  1134. }
  1135. /// <summary>
  1136. /// Apply physics to this part.
  1137. /// </summary>
  1138. /// <param name="rootObjectFlags"></param>
  1139. /// <param name="m_physicalPrim"></param>
  1140. public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool m_physicalPrim)
  1141. {
  1142. bool isPhysical = (((rootObjectFlags & (uint) PrimFlags.Physics) != 0) && m_physicalPrim);
  1143. bool isPhantom = ((rootObjectFlags & (uint) PrimFlags.Phantom) != 0);
  1144. if (IsJoint())
  1145. {
  1146. DoPhysicsPropertyUpdate(isPhysical, true);
  1147. }
  1148. else
  1149. {
  1150. // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
  1151. if (VolumeDetectActive)
  1152. isPhantom = false;
  1153. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  1154. bool RigidBody = isPhysical && !isPhantom;
  1155. // The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
  1156. // or flexible
  1157. if (!isPhantom && !IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible))
  1158. {
  1159. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1160. Name,
  1161. Shape,
  1162. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z),
  1163. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1164. RotationOffset,
  1165. RigidBody);
  1166. // Basic Physics returns null.. joy joy joy.
  1167. PhysicsActor pa = PhysActor;
  1168. if (pa != null)
  1169. {
  1170. pa.SOPName = this.Name; // save object name and desc into the PhysActor so ODE internals know the joint/body info
  1171. pa.SOPDescription = this.Description;
  1172. pa.LocalID = LocalId;
  1173. DoPhysicsPropertyUpdate(RigidBody, true);
  1174. pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
  1175. }
  1176. }
  1177. }
  1178. }
  1179. public void ClearUndoState()
  1180. {
  1181. lock (m_undo)
  1182. {
  1183. m_undo.Clear();
  1184. }
  1185. StoreUndoState();
  1186. }
  1187. public byte ConvertScriptUintToByte(uint indata)
  1188. {
  1189. byte outdata = (byte)TextureAnimFlags.NONE;
  1190. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1191. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1192. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1193. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1194. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1195. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1196. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1197. return outdata;
  1198. }
  1199. /// <summary>
  1200. /// Duplicates this part.
  1201. /// </summary>
  1202. /// <returns></returns>
  1203. public SceneObjectPart Copy(uint localID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
  1204. {
  1205. SceneObjectPart dupe = (SceneObjectPart)MemberwiseClone();
  1206. dupe.m_shape = m_shape.Copy();
  1207. dupe.m_regionHandle = m_regionHandle;
  1208. if (userExposed)
  1209. dupe.UUID = UUID.Random();
  1210. //memberwiseclone means it also clones the physics actor reference
  1211. // This will make physical prim 'bounce' if not set to null.
  1212. if (!userExposed)
  1213. dupe.PhysActor = null;
  1214. dupe._ownerID = AgentID;
  1215. dupe._groupID = GroupID;
  1216. dupe.GroupPosition = GroupPosition;
  1217. dupe.OffsetPosition = OffsetPosition;
  1218. dupe.RotationOffset = RotationOffset;
  1219. dupe.Velocity = new Vector3(0, 0, 0);
  1220. dupe.Acceleration = new Vector3(0, 0, 0);
  1221. dupe.AngularVelocity = new Vector3(0, 0, 0);
  1222. dupe.ObjectFlags = ObjectFlags;
  1223. dupe._ownershipCost = _ownershipCost;
  1224. dupe._objectSaleType = _objectSaleType;
  1225. dupe._salePrice = _salePrice;
  1226. dupe._category = _category;
  1227. dupe.m_rezzed = m_rezzed;
  1228. dupe.m_inventory = new SceneObjectPartInventory(dupe);
  1229. dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
  1230. if (userExposed)
  1231. {
  1232. dupe.ResetIDs(linkNum);
  1233. dupe.m_inventory.HasInventoryChanged = true;
  1234. }
  1235. else
  1236. {
  1237. dupe.m_inventory.HasInventoryChanged = m_inventory.HasInventoryChanged;
  1238. }
  1239. // Move afterwards ResetIDs as it clears the localID
  1240. dupe.LocalId = localID;
  1241. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1242. dupe._lastOwnerID = OwnerID;
  1243. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1244. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1245. dupe.Shape.ExtraParams = extraP;
  1246. if (userExposed)
  1247. {
  1248. if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero)
  1249. {
  1250. m_parentGroup.Scene.AssetService.Get(dupe.m_shape.SculptTexture.ToString(), dupe, AssetReceived);
  1251. }
  1252. bool UsePhysics = ((dupe.ObjectFlags & (uint)PrimFlags.Physics) != 0);
  1253. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1254. }
  1255. return dupe;
  1256. }
  1257. protected void AssetReceived(string id, Object sender, AssetBase asset)
  1258. {
  1259. if (asset != null)
  1260. {
  1261. SceneObjectPart sop = (SceneObjectPart)sender;
  1262. if (sop != null)
  1263. sop.SculptTextureCallback(asset.FullID, asset);
  1264. }
  1265. }
  1266. public static SceneObjectPart Create()
  1267. {
  1268. SceneObjectPart part = new SceneObjectPart();
  1269. part.UUID = UUID.Random();
  1270. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  1271. part.Shape = shape;
  1272. part.Name = "Primitive";
  1273. part._ownerID = UUID.Random();
  1274. return part;
  1275. }
  1276. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1277. {
  1278. if (IsJoint())
  1279. {
  1280. if (UsePhysics)
  1281. {
  1282. // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
  1283. // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.
  1284. PhysicsJointType jointType;
  1285. if (IsHingeJoint())
  1286. {
  1287. jointType = PhysicsJointType.Hinge;
  1288. }
  1289. else if (IsBallJoint())
  1290. {
  1291. jointType = PhysicsJointType.Ball;
  1292. }
  1293. else
  1294. {
  1295. jointType = PhysicsJointType.Ball;
  1296. }
  1297. List<string> bodyNames = new List<string>();
  1298. string RawParams = Description;
  1299. string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
  1300. string trackedBodyName = null;
  1301. if (jointParams.Length >= 2)
  1302. {
  1303. for (int iBodyName = 0; iBodyName < 2; iBodyName++)
  1304. {
  1305. string bodyName = jointParams[iBodyName];
  1306. bodyNames.Add(bodyName);
  1307. if (bodyName != "NULL")
  1308. {
  1309. if (trackedBodyName == null)
  1310. {
  1311. trackedBodyName = bodyName;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
  1317. Quaternion localRotation = Quaternion.Identity;
  1318. if (trackedBody != null)
  1319. {
  1320. localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
  1321. }
  1322. else
  1323. {
  1324. // error, output it below
  1325. }
  1326. PhysicsJoint joint;
  1327. joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
  1328. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z),
  1329. this.RotationOffset,
  1330. Description,
  1331. bodyNames,
  1332. trackedBodyName,
  1333. localRotation);
  1334. if (trackedBody == null)
  1335. {
  1336. ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
  1337. }
  1338. }
  1339. else
  1340. {
  1341. if (isNew)
  1342. {
  1343. // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
  1344. // delete, and if we try to delete it, due to asynchronous processing, the deletion request
  1345. // will get processed later at an indeterminate time, which could cancel a later-arriving
  1346. // joint creation request.
  1347. }
  1348. else
  1349. {
  1350. // here we turn off the joint object, so remove the joint from the physics scene
  1351. m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?
  1352. // make sure client isn't interpolating the joint proxy object
  1353. Velocity = new Vector3(0, 0, 0);
  1354. RotationalVelocity = new Vector3(0, 0, 0);
  1355. Acceleration = new Vector3(0, 0, 0);
  1356. }
  1357. }
  1358. }
  1359. else
  1360. {
  1361. PhysicsActor pa = PhysActor;
  1362. if (pa != null)
  1363. {
  1364. if (UsePhysics != pa.IsPhysical || isNew)
  1365. {
  1366. if (pa.IsPhysical) // implies UsePhysics==false for this block
  1367. {
  1368. if (!isNew)
  1369. ParentGroup.Scene.RemovePhysicalPrim(1);
  1370. pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1371. pa.OnOutOfBounds -= PhysicsOutOfBounds;
  1372. pa.delink();
  1373. if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew))
  1374. {
  1375. // destroy all joints connected to this now deactivated body
  1376. m_parentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
  1377. }
  1378. // stop client-side interpolation of all joint proxy objects that have just been deleted
  1379. // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback,
  1380. // which stops client-side interpolation of deactivated joint proxy objects.
  1381. }
  1382. if (!UsePhysics && !isNew)
  1383. {
  1384. // reset velocity to 0 on physics switch-off. Without that, the client thinks the
  1385. // prim still has velocity and continues to interpolate its position along the old
  1386. // velocity-vector.
  1387. Velocity = new Vector3(0, 0, 0);
  1388. Acceleration = new Vector3(0, 0, 0);
  1389. AngularVelocity = new Vector3(0, 0, 0);
  1390. //RotationalVelocity = new Vector3(0, 0, 0);
  1391. }
  1392. pa.IsPhysical = UsePhysics;
  1393. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1394. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1395. /// that's not wholesome. Had to make Scene public
  1396. //PhysActor = null;
  1397. if ((ObjectFlags & (uint)PrimFlags.Phantom) == 0)
  1398. {
  1399. if (UsePhysics)
  1400. {
  1401. ParentGroup.Scene.AddPhysicalPrim(1);
  1402. pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1403. pa.OnOutOfBounds += PhysicsOutOfBounds;
  1404. if (_parentID != 0 && _parentID != LocalId)
  1405. {
  1406. if (ParentGroup.RootPart.PhysActor != null)
  1407. {
  1408. pa.link(ParentGroup.RootPart.PhysActor);
  1409. }
  1410. }
  1411. }
  1412. }
  1413. }
  1414. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  1415. }
  1416. }
  1417. }
  1418. /// <summary>
  1419. /// Restore this part from the serialized xml representation.
  1420. /// </summary>
  1421. /// <param name="xmlReader"></param>
  1422. /// <returns></returns>
  1423. public static SceneObjectPart FromXml(XmlReader xmlReader)
  1424. {
  1425. return FromXml(UUID.Zero, xmlReader);
  1426. }
  1427. /// <summary>
  1428. /// Restore this part from the serialized xml representation.
  1429. /// </summary>
  1430. /// <param name="fromUserInventoryItemId">The inventory id from which this part came, if applicable</param>
  1431. /// <param name="xmlReader"></param>
  1432. /// <returns></returns>
  1433. public static SceneObjectPart FromXml(UUID fromUserInventoryItemId, XmlReader xmlReader)
  1434. {
  1435. SceneObjectPart part = (SceneObjectPart)serializer.Deserialize(xmlReader);
  1436. part.m_fromUserInventoryItemID = fromUserInventoryItemId;
  1437. // for tempOnRez objects, we have to fix the Expire date.
  1438. if ((part.Flags & PrimFlags.TemporaryOnRez) != 0) part.ResetExpire();
  1439. return part;
  1440. }
  1441. public UUID GetAvatarOnSitTarget()
  1442. {
  1443. return m_sitTargetAvatar;
  1444. }
  1445. public bool GetDieAtEdge()
  1446. {
  1447. if (m_parentGroup == null)
  1448. return false;
  1449. if (m_parentGroup.IsDeleted)
  1450. return false;
  1451. return m_parentGroup.RootPart.DIE_AT_EDGE;
  1452. }
  1453. public double GetDistanceTo(Vector3 a, Vector3 b)
  1454. {
  1455. float dx = a.X - b.X;
  1456. float dy = a.Y - b.Y;
  1457. float dz = a.Z - b.Z;
  1458. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  1459. }
  1460. public uint GetEffectiveObjectFlags()
  1461. {
  1462. PrimFlags f = _flags;
  1463. if (m_parentGroup == null || m_parentGroup.RootPart == this)
  1464. f &= ~(PrimFlags.Touch | PrimFlags.Money);
  1465. return (uint)_flags | (uint)LocalFlags;
  1466. }
  1467. public Vector3 GetGeometricCenter()
  1468. {
  1469. PhysicsActor pa = PhysActor;
  1470. if (pa != null)
  1471. {
  1472. return new Vector3(pa.CenterOfMass.X, pa.CenterOfMass.Y, pa.CenterOfMass.Z);
  1473. }
  1474. else
  1475. {
  1476. return new Vector3(0, 0, 0);
  1477. }
  1478. }
  1479. public float GetMass()
  1480. {
  1481. PhysicsActor pa = PhysActor;
  1482. if (pa != null)
  1483. {
  1484. return pa.Mass;
  1485. }
  1486. else
  1487. {
  1488. return 0;
  1489. }
  1490. }
  1491. public PhysicsVector GetForce()
  1492. {
  1493. PhysicsActor pa = PhysActor;
  1494. if (pa != null)
  1495. return pa.Force;
  1496. else
  1497. return new PhysicsVector();
  1498. }
  1499. public void GetProperties(IClientAPI client)
  1500. {
  1501. client.SendObjectPropertiesReply(
  1502. m_fromUserInventoryItemID, (ulong)_creationDate, _creatorID, UUID.Zero, UUID.Zero,
  1503. _groupID, (short)InventorySerial, _lastOwnerID, UUID, _ownerID,
  1504. ParentGroup.RootPart.TouchName, new byte[0], ParentGroup.RootPart.SitName, Name, Description,
  1505. ParentGroup.RootPart._ownerMask, ParentGroup.RootPart._nextOwnerMask, ParentGroup.RootPart._groupMask, ParentGroup.RootPart._everyoneMask,
  1506. ParentGroup.RootPart._baseMask,
  1507. ParentGroup.RootPart.ObjectSaleType,
  1508. ParentGroup.RootPart.SalePrice);
  1509. }
  1510. public UUID GetRootPartUUID()
  1511. {
  1512. if (m_parentGroup != null)
  1513. {
  1514. return m_parentGroup.UUID;
  1515. }
  1516. return UUID.Zero;
  1517. }
  1518. /// <summary>
  1519. /// Method for a prim to get it's world position from the group.
  1520. /// Remember, the Group Position simply gives the position of the group itself
  1521. /// </summary>
  1522. /// <returns>A Linked Child Prim objects position in world</returns>
  1523. public Vector3 GetWorldPosition()
  1524. {
  1525. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1526. Vector3 axPos = OffsetPosition;
  1527. axPos *= parentRot;
  1528. Vector3 translationOffsetPosition = axPos;
  1529. return GroupPosition + translationOffsetPosition;
  1530. }
  1531. /// <summary>
  1532. /// Gets the rotation of this prim offset by the group rotation
  1533. /// </summary>
  1534. /// <returns></returns>
  1535. public Quaternion GetWorldRotation()
  1536. {
  1537. Quaternion newRot;
  1538. if (this.LinkNum == 0)
  1539. {
  1540. newRot = RotationOffset;
  1541. }
  1542. else
  1543. {
  1544. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1545. Quaternion oldRot = RotationOffset;
  1546. newRot = parentRot * oldRot;
  1547. }
  1548. return newRot;
  1549. }
  1550. public void MoveToTarget(Vector3 target, float tau)
  1551. {
  1552. if (tau > 0)
  1553. {
  1554. m_parentGroup.moveToTarget(target, tau);
  1555. }
  1556. else
  1557. {
  1558. StopMoveToTarget();
  1559. }
  1560. }
  1561. /// <summary>
  1562. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  1563. /// </summary>
  1564. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  1565. /// <param name="hoverType">Determines what the height is relative to </param>
  1566. /// <param name="tau">Number of seconds over which to reach target</param>
  1567. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  1568. {
  1569. m_parentGroup.SetHoverHeight(height, hoverType, tau);
  1570. }
  1571. public void StopHover()
  1572. {
  1573. m_parentGroup.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  1574. }
  1575. public virtual void OnGrab(Vector3 offsetPos, IClientAPI remoteClient)
  1576. {
  1577. }
  1578. public void PhysicsCollision(EventArgs e)
  1579. {
  1580. // single threaded here
  1581. if (e == null)
  1582. {
  1583. return;
  1584. }
  1585. CollisionEventUpdate a = (CollisionEventUpdate)e;
  1586. Dictionary<uint, float> collissionswith = a.m_objCollisionList;
  1587. List<uint> thisHitColliders = new List<uint>();
  1588. List<uint> endedColliders = new List<uint>();
  1589. List<uint> startedColliders = new List<uint>();
  1590. // calculate things that started colliding this time
  1591. // and build up list of colliders this time
  1592. foreach (uint localid in collissionswith.Keys)
  1593. {
  1594. if (localid != 0)
  1595. {
  1596. thisHitColliders.Add(localid);
  1597. if (!m_lastColliders.Contains(localid))
  1598. {
  1599. startedColliders.Add(localid);
  1600. }
  1601. //m_log.Debug("[OBJECT]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
  1602. }
  1603. }
  1604. // calculate things that ended colliding
  1605. foreach (uint localID in m_lastColliders)
  1606. {
  1607. if (!thisHitColliders.Contains(localID))
  1608. {
  1609. endedColliders.Add(localID);
  1610. }
  1611. }
  1612. //add the items that started colliding this time to the last colliders list.
  1613. foreach (uint localID in startedColliders)
  1614. {
  1615. m_lastColliders.Add(localID);
  1616. }
  1617. // remove things that ended colliding from the last colliders list
  1618. foreach (uint localID in endedColliders)
  1619. {
  1620. m_lastColliders.Remove(localID);
  1621. }
  1622. if (m_parentGroup == null)
  1623. return;
  1624. if (m_parentGroup.IsDeleted)
  1625. return;
  1626. // play the sound.
  1627. if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
  1628. {
  1629. SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0);
  1630. }
  1631. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
  1632. {
  1633. // do event notification
  1634. if (startedColliders.Count > 0)
  1635. {
  1636. ColliderArgs StartCollidingMessage = new ColliderArgs();
  1637. List<DetectedObject> colliding = new List<DetectedObject>();
  1638. foreach (uint localId in startedColliders)
  1639. {
  1640. // always running this check because if the user deletes the object it would return a null reference.
  1641. if (m_parentGroup == null)
  1642. return;
  1643. if (m_parentGroup.Scene == null)
  1644. return;
  1645. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1646. if (obj != null)
  1647. {
  1648. DetectedObject detobj = new DetectedObject();
  1649. detobj.keyUUID = obj.UUID;
  1650. detobj.nameStr = obj.Name;
  1651. detobj.ownerUUID = obj._ownerID;
  1652. detobj.posVector = obj.AbsolutePosition;
  1653. detobj.rotQuat = obj.GetWorldRotation();
  1654. detobj.velVector = obj.Velocity;
  1655. detobj.colliderType = 0;
  1656. detobj.groupUUID = obj._groupID;
  1657. colliding.Add(detobj);
  1658. }
  1659. else
  1660. {
  1661. List<ScenePresence> avlist = m_parentGroup.Scene.GetScenePresences();
  1662. if (avlist != null)
  1663. {
  1664. foreach (ScenePresence av in avlist)
  1665. {
  1666. if (av.LocalId == localId)
  1667. {
  1668. DetectedObject detobj = new DetectedObject();
  1669. detobj.keyUUID = av.UUID;
  1670. detobj.nameStr = av.ControllingClient.Name;
  1671. detobj.ownerUUID = av.UUID;
  1672. detobj.posVector = av.AbsolutePosition;
  1673. detobj.rotQuat = av.Rotation;
  1674. detobj.velVector = av.Velocity;
  1675. detobj.colliderType = 0;
  1676. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1677. colliding.Add(detobj);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. }
  1683. if (colliding.Count > 0)
  1684. {
  1685. StartCollidingMessage.Colliders = colliding;
  1686. // always running this check because if the user deletes the object it would return a null reference.
  1687. if (m_parentGroup == null)
  1688. return;
  1689. if (m_parentGroup.Scene == null)
  1690. return;
  1691. m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(LocalId, StartCollidingMessage);
  1692. }
  1693. }
  1694. }
  1695. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
  1696. {
  1697. if (m_lastColliders.Count > 0)
  1698. {
  1699. ColliderArgs CollidingMessage = new ColliderArgs();
  1700. List<DetectedObject> colliding = new List<DetectedObject>();
  1701. foreach (uint localId in m_lastColliders)
  1702. {
  1703. // always running this check because if the user deletes the object it would return a null reference.
  1704. if (localId == 0)
  1705. continue;
  1706. if (m_parentGroup == null)
  1707. return;
  1708. if (m_parentGroup.Scene == null)
  1709. return;
  1710. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1711. if (obj != null)
  1712. {
  1713. DetectedObject detobj = new DetectedObject();
  1714. detobj.keyUUID = obj.UUID;
  1715. detobj.nameStr = obj.Name;
  1716. detobj.ownerUUID = obj._ownerID;
  1717. detobj.posVector = obj.AbsolutePosition;
  1718. detobj.rotQuat = obj.GetWorldRotation();
  1719. detobj.velVector = obj.Velocity;
  1720. detobj.colliderType = 0;
  1721. detobj.groupUUID = obj._groupID;
  1722. colliding.Add(detobj);
  1723. }
  1724. else
  1725. {
  1726. List<ScenePresence> avlist = m_parentGroup.Scene.GetScenePresences();
  1727. if (avlist != null)
  1728. {
  1729. foreach (ScenePresence av in avlist)
  1730. {
  1731. if (av.LocalId == localId)
  1732. {
  1733. DetectedObject detobj = new DetectedObject();
  1734. detobj.keyUUID = av.UUID;
  1735. detobj.nameStr = av.Name;
  1736. detobj.ownerUUID = av.UUID;
  1737. detobj.posVector = av.AbsolutePosition;
  1738. detobj.rotQuat = av.Rotation;
  1739. detobj.velVector = av.Velocity;
  1740. detobj.colliderType = 0;
  1741. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1742. colliding.Add(detobj);
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if (colliding.Count > 0)
  1749. {
  1750. CollidingMessage.Colliders = colliding;
  1751. // always running this check because if the user deletes the object it would return a null reference.
  1752. if (m_parentGroup == null)
  1753. return;
  1754. if (m_parentGroup.Scene == null)
  1755. return;
  1756. m_parentGroup.Scene.EventManager.TriggerScriptColliding(LocalId, CollidingMessage);
  1757. }
  1758. }
  1759. }
  1760. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
  1761. {
  1762. if (endedColliders.Count > 0)
  1763. {
  1764. ColliderArgs EndCollidingMessage = new ColliderArgs();
  1765. List<DetectedObject> colliding = new List<DetectedObject>();
  1766. foreach (uint localId in endedColliders)
  1767. {
  1768. if (localId == 0)
  1769. continue;
  1770. // always running this check because if the user deletes the object it would return a null reference.
  1771. if (m_parentGroup == null)
  1772. return;
  1773. if (m_parentGroup.Scene == null)
  1774. return;
  1775. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1776. if (obj != null)
  1777. {
  1778. DetectedObject detobj = new DetectedObject();
  1779. detobj.keyUUID = obj.UUID;
  1780. detobj.nameStr = obj.Name;
  1781. detobj.ownerUUID = obj._ownerID;
  1782. detobj.posVector = obj.AbsolutePosition;
  1783. detobj.rotQuat = obj.GetWorldRotation();
  1784. detobj.velVector = obj.Velocity;
  1785. detobj.colliderType = 0;
  1786. detobj.groupUUID = obj._groupID;
  1787. colliding.Add(detobj);
  1788. }
  1789. else
  1790. {
  1791. List<ScenePresence> avlist = m_parentGroup.Scene.GetScenePresences();
  1792. if (avlist != null)
  1793. {
  1794. foreach (ScenePresence av in avlist)
  1795. {
  1796. if (av.LocalId == localId)
  1797. {
  1798. DetectedObject detobj = new DetectedObject();
  1799. detobj.keyUUID = av.UUID;
  1800. detobj.nameStr = av.Name;
  1801. detobj.ownerUUID = av.UUID;
  1802. detobj.posVector = av.AbsolutePosition;
  1803. detobj.rotQuat = av.Rotation;
  1804. detobj.velVector = av.Velocity;
  1805. detobj.colliderType = 0;
  1806. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1807. colliding.Add(detobj);
  1808. }
  1809. }
  1810. }
  1811. }
  1812. }
  1813. if (colliding.Count > 0)
  1814. {
  1815. EndCollidingMessage.Colliders = colliding;
  1816. // always running this check because if the user deletes the object it would return a null reference.
  1817. if (m_parentGroup == null)
  1818. return;
  1819. if (m_parentGroup.Scene == null)
  1820. return;
  1821. m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(LocalId, EndCollidingMessage);
  1822. }
  1823. }
  1824. }
  1825. }
  1826. public void PhysicsOutOfBounds(PhysicsVector pos)
  1827. {
  1828. m_log.Error("[PHYSICS]: Physical Object went out of bounds.");
  1829. RemFlag(PrimFlags.Physics);
  1830. DoPhysicsPropertyUpdate(false, true);
  1831. //m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1832. }
  1833. public void PhysicsRequestingTerseUpdate()
  1834. {
  1835. PhysicsActor pa = PhysActor;
  1836. if (pa != null)
  1837. {
  1838. Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0);
  1839. if (m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.N) |
  1840. m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.S) |
  1841. m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.E) |
  1842. m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
  1843. {
  1844. m_parentGroup.AbsolutePosition = newpos;
  1845. return;
  1846. }
  1847. }
  1848. ScheduleTerseUpdate();
  1849. //SendTerseUpdateToAllClients();
  1850. }
  1851. public void PreloadSound(string sound)
  1852. {
  1853. // UUID ownerID = OwnerID;
  1854. UUID objectID = UUID;
  1855. UUID soundID = UUID.Zero;
  1856. if (!UUID.TryParse(sound, out soundID))
  1857. {
  1858. //Trys to fetch sound id from prim's inventory.
  1859. //Prim's inventory doesn't support non script items yet
  1860. lock (TaskInventory)
  1861. {
  1862. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  1863. {
  1864. if (item.Value.Name == sound)
  1865. {
  1866. soundID = item.Value.ItemID;
  1867. break;
  1868. }
  1869. }
  1870. }
  1871. }
  1872. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1873. foreach (ScenePresence p in avatarts)
  1874. {
  1875. // TODO: some filtering by distance of avatar
  1876. p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  1877. }
  1878. }
  1879. public void RemFlag(PrimFlags flag)
  1880. {
  1881. // PrimFlags prevflag = Flags;
  1882. if ((ObjectFlags & (uint) flag) != 0)
  1883. {
  1884. //m_log.Debug("Removing flag: " + ((PrimFlags)flag).ToString());
  1885. _flags &= ~flag;
  1886. }
  1887. //m_log.Debug("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1888. //ScheduleFullUpdate();
  1889. }
  1890. public void RemoveScriptEvents(UUID scriptid)
  1891. {
  1892. lock (m_scriptEvents)
  1893. {
  1894. if (m_scriptEvents.ContainsKey(scriptid))
  1895. {
  1896. scriptEvents oldparts = scriptEvents.None;
  1897. oldparts = (scriptEvents) m_scriptEvents[scriptid];
  1898. // remove values from aggregated script events
  1899. AggregateScriptEvents &= ~oldparts;
  1900. m_scriptEvents.Remove(scriptid);
  1901. aggregateScriptEvents();
  1902. }
  1903. }
  1904. }
  1905. /// <summary>
  1906. /// Reset UUIDs for this part. This involves generate this part's own UUID and
  1907. /// generating new UUIDs for all the items in the inventory.
  1908. /// </summary>
  1909. /// <param name="linkNum">Link number for the part</param>
  1910. public void ResetIDs(int linkNum)
  1911. {
  1912. UUID = UUID.Random();
  1913. LinkNum = linkNum;
  1914. LocalId = 0;
  1915. Inventory.ResetInventoryIDs();
  1916. }
  1917. /// <summary>
  1918. /// Resize this part.
  1919. /// </summary>
  1920. /// <param name="scale"></param>
  1921. public void Resize(Vector3 scale)
  1922. {
  1923. StoreUndoState();
  1924. m_shape.Scale = scale;
  1925. ParentGroup.HasGroupChanged = true;
  1926. ScheduleFullUpdate();
  1927. }
  1928. /// <summary>
  1929. /// Schedules this prim for a full update
  1930. /// </summary>
  1931. public void ScheduleFullUpdate()
  1932. {
  1933. if (m_parentGroup != null)
  1934. {
  1935. m_parentGroup.QueueForUpdateCheck();
  1936. }
  1937. int timeNow = Util.UnixTimeSinceEpoch();
  1938. // If multiple updates are scheduled on the same second, we still need to perform all of them
  1939. // So we'll force the issue by bumping up the timestamp so that later processing sees these need
  1940. // to be performed.
  1941. if (timeNow <= TimeStampFull)
  1942. {
  1943. TimeStampFull += 1;
  1944. }
  1945. else
  1946. {
  1947. TimeStampFull = (uint)timeNow;
  1948. }
  1949. m_updateFlag = 2;
  1950. // m_log.DebugFormat(
  1951. // "[SCENE OBJECT PART]: Scheduling full update for {0}, {1} at {2}",
  1952. // UUID, Name, TimeStampFull);
  1953. }
  1954. /// <summary>
  1955. /// Schedule a terse update for this prim. Terse updates only send position,
  1956. /// rotation, velocity, rotational velocity and shape information.
  1957. /// </summary>
  1958. public void ScheduleTerseUpdate()
  1959. {
  1960. if (m_updateFlag < 1)
  1961. {
  1962. if (m_parentGroup != null)
  1963. {
  1964. m_parentGroup.HasGroupChanged = true;
  1965. m_parentGroup.QueueForUpdateCheck();
  1966. }
  1967. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  1968. m_updateFlag = 1;
  1969. // m_log.DebugFormat(
  1970. // "[SCENE OBJECT PART]: Scheduling terse update for {0}, {1} at {2}",
  1971. // UUID, Name, TimeStampTerse);
  1972. }
  1973. }
  1974. public void ScriptSetPhantomStatus(bool Phantom)
  1975. {
  1976. if (m_parentGroup != null)
  1977. {
  1978. m_parentGroup.ScriptSetPhantomStatus(Phantom);
  1979. }
  1980. }
  1981. public void ScriptSetTemporaryStatus(bool Temporary)
  1982. {
  1983. if (m_parentGroup != null)
  1984. {
  1985. m_parentGroup.ScriptSetTemporaryStatus(Temporary);
  1986. }
  1987. }
  1988. public void ScriptSetPhysicsStatus(bool UsePhysics)
  1989. {
  1990. if (m_parentGroup == null)
  1991. DoPhysicsPropertyUpdate(UsePhysics, false);
  1992. else
  1993. m_parentGroup.ScriptSetPhysicsStatus(UsePhysics);
  1994. }
  1995. public void ScriptSetVolumeDetect(bool SetVD)
  1996. {
  1997. if (m_parentGroup != null)
  1998. {
  1999. m_parentGroup.ScriptSetVolumeDetect(SetVD);
  2000. }
  2001. }
  2002. public void SculptTextureCallback(UUID textureID, AssetBase texture)
  2003. {
  2004. if (m_shape.SculptEntry)
  2005. {
  2006. // commented out for sculpt map caching test - null could mean a cached sculpt map has been found
  2007. //if (texture != null)
  2008. {
  2009. if (texture != null)
  2010. m_shape.SculptData = texture.Data;
  2011. PhysicsActor pa = PhysActor;
  2012. if (pa != null)
  2013. {
  2014. // Tricks physics engine into thinking we've changed the part shape.
  2015. PrimitiveBaseShape m_newshape = m_shape.Copy();
  2016. pa.Shape = m_newshape;
  2017. m_shape = m_newshape;
  2018. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2019. }
  2020. }
  2021. }
  2022. }
  2023. /// <summary>
  2024. ///
  2025. /// </summary>
  2026. /// <param name="remoteClient"></param>
  2027. public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  2028. {
  2029. m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
  2030. }
  2031. /// <summary>
  2032. ///
  2033. /// </summary>
  2034. public void SendFullUpdateToAllClients()
  2035. {
  2036. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  2037. for (int i = 0; i < avatars.Count; i++)
  2038. {
  2039. // Ugly reference :(
  2040. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  2041. avatars[i].GenerateClientFlags(UUID));
  2042. }
  2043. }
  2044. public void SendFullUpdateToAllClientsExcept(UUID agentID)
  2045. {
  2046. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  2047. for (int i = 0; i < avatars.Count; i++)
  2048. {
  2049. // Ugly reference :(
  2050. if (avatars[i].UUID != agentID)
  2051. {
  2052. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  2053. avatars[i].GenerateClientFlags(UUID));
  2054. }
  2055. }
  2056. }
  2057. /// <summary>
  2058. /// Sends a full update to the client
  2059. /// </summary>
  2060. /// <param name="remoteClient"></param>
  2061. /// <param name="clientFlags"></param>
  2062. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  2063. {
  2064. Vector3 lPos;
  2065. lPos = OffsetPosition;
  2066. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  2067. }
  2068. /// <summary>
  2069. /// Sends a full update to the client
  2070. /// </summary>
  2071. /// <param name="remoteClient"></param>
  2072. /// <param name="lPos"></param>
  2073. /// <param name="clientFlags"></param>
  2074. public void SendFullUpdateToClient(IClientAPI remoteClient, Vector3 lPos, uint clientFlags)
  2075. {
  2076. // Suppress full updates during attachment editing
  2077. //
  2078. if (ParentGroup.IsSelected && IsAttachment)
  2079. return;
  2080. if (ParentGroup.IsDeleted)
  2081. return;
  2082. clientFlags &= ~(uint) PrimFlags.CreateSelected;
  2083. if (remoteClient.AgentId == _ownerID)
  2084. {
  2085. if ((uint) (_flags & PrimFlags.CreateSelected) != 0)
  2086. {
  2087. clientFlags |= (uint) PrimFlags.CreateSelected;
  2088. _flags &= ~PrimFlags.CreateSelected;
  2089. }
  2090. }
  2091. //bool isattachment = IsAttachment;
  2092. //if (LocalId != ParentGroup.RootPart.LocalId)
  2093. //isattachment = ParentGroup.RootPart.IsAttachment;
  2094. byte[] color = new byte[] {m_color.R, m_color.G, m_color.B, m_color.A};
  2095. remoteClient.SendPrimitiveToClient(new SendPrimitiveData(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, m_shape,
  2096. lPos, Velocity, Acceleration, RotationOffset, RotationalVelocity, clientFlags, m_uuid, _ownerID,
  2097. m_text, color, _parentID, m_particleSystem, m_clickAction, (byte)m_material, m_TextureAnimation, IsAttachment,
  2098. AttachmentPoint,FromItemID, Sound, SoundGain, SoundFlags, SoundRadius, ParentGroup.GetUpdatePriority(remoteClient)));
  2099. }
  2100. /// <summary>
  2101. /// Tell all the prims which have had updates scheduled
  2102. /// </summary>
  2103. public void SendScheduledUpdates()
  2104. {
  2105. if (m_updateFlag == 1) //some change has been made so update the clients
  2106. {
  2107. AddTerseUpdateToAllAvatars();
  2108. ClearUpdateSchedule();
  2109. // This causes the Scene to 'poll' physical objects every couple of frames
  2110. // bad, so it's been replaced by an event driven method.
  2111. //if ((ObjectFlags & (uint)PrimFlags.Physics) != 0)
  2112. //{
  2113. // Only send the constant terse updates on physical objects!
  2114. //ScheduleTerseUpdate();
  2115. //}
  2116. }
  2117. else
  2118. {
  2119. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  2120. {
  2121. AddFullUpdateToAllAvatars();
  2122. ClearUpdateSchedule();
  2123. }
  2124. }
  2125. }
  2126. /// <summary>
  2127. /// Trigger or play an attached sound in this part's inventory.
  2128. /// </summary>
  2129. /// <param name="sound"></param>
  2130. /// <param name="volume"></param>
  2131. /// <param name="triggered"></param>
  2132. /// <param name="flags"></param>
  2133. public void SendSound(string sound, double volume, bool triggered, byte flags)
  2134. {
  2135. if (volume > 1)
  2136. volume = 1;
  2137. if (volume < 0)
  2138. volume = 0;
  2139. UUID ownerID = _ownerID;
  2140. UUID objectID = UUID;
  2141. UUID parentID = GetRootPartUUID();
  2142. UUID soundID = UUID.Zero;
  2143. Vector3 position = AbsolutePosition; // region local
  2144. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  2145. if (!UUID.TryParse(sound, out soundID))
  2146. {
  2147. // search sound file from inventory
  2148. lock (TaskInventory)
  2149. {
  2150. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  2151. {
  2152. if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
  2153. {
  2154. soundID = item.Value.ItemID;
  2155. break;
  2156. }
  2157. }
  2158. }
  2159. }
  2160. if (soundID == UUID.Zero)
  2161. return;
  2162. ISoundModule soundModule = m_parentGroup.Scene.RequestModuleInterface<ISoundModule>();
  2163. if (soundModule != null)
  2164. {
  2165. if (triggered)
  2166. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle);
  2167. else
  2168. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags);
  2169. }
  2170. }
  2171. /// <summary>
  2172. /// Send a terse update to all clients
  2173. /// </summary>
  2174. public void SendTerseUpdateToAllClients()
  2175. {
  2176. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  2177. for (int i = 0; i < avatars.Count; i++)
  2178. {
  2179. SendTerseUpdateToClient(avatars[i].ControllingClient);
  2180. }
  2181. }
  2182. public void SetAttachmentPoint(uint AttachmentPoint)
  2183. {
  2184. this.AttachmentPoint = AttachmentPoint;
  2185. if (AttachmentPoint != 0)
  2186. {
  2187. IsAttachment = true;
  2188. }
  2189. else
  2190. {
  2191. IsAttachment = false;
  2192. }
  2193. // save the attachment point.
  2194. //if (AttachmentPoint != 0)
  2195. //{
  2196. m_shape.State = (byte)AttachmentPoint;
  2197. //}
  2198. }
  2199. public void SetAvatarOnSitTarget(UUID avatarID)
  2200. {
  2201. m_sitTargetAvatar = avatarID;
  2202. if (ParentGroup != null)
  2203. ParentGroup.TriggerScriptChangedEvent(Changed.LINK);
  2204. }
  2205. public void SetAxisRotation(int axis, int rotate)
  2206. {
  2207. if (m_parentGroup != null)
  2208. {
  2209. m_parentGroup.SetAxisRotation(axis, rotate);
  2210. }
  2211. }
  2212. public void SetBuoyancy(float fvalue)
  2213. {
  2214. PhysicsActor pa = PhysActor;
  2215. if (pa != null)
  2216. {
  2217. pa.Buoyancy = fvalue;
  2218. }
  2219. }
  2220. public void SetDieAtEdge(bool p)
  2221. {
  2222. if (m_parentGroup == null)
  2223. return;
  2224. if (m_parentGroup.IsDeleted)
  2225. return;
  2226. m_parentGroup.RootPart.DIE_AT_EDGE = p;
  2227. }
  2228. public void SetFloatOnWater(int floatYN)
  2229. {
  2230. PhysicsActor pa = PhysActor;
  2231. if (pa != null)
  2232. {
  2233. if (floatYN == 1)
  2234. {
  2235. pa.FloatOnWater = true;
  2236. }
  2237. else
  2238. {
  2239. pa.FloatOnWater = false;
  2240. }
  2241. }
  2242. }
  2243. public void SetForce(PhysicsVector force)
  2244. {
  2245. PhysicsActor pa = PhysActor;
  2246. if (pa != null)
  2247. {
  2248. pa.Force = force;
  2249. }
  2250. }
  2251. public void SetVehicleType(int type)
  2252. {
  2253. PhysicsActor pa = PhysActor;
  2254. if (pa != null)
  2255. {
  2256. pa.VehicleType = type;
  2257. }
  2258. }
  2259. public void SetVehicleFloatParam(int param, float value)
  2260. {
  2261. PhysicsActor pa = PhysActor;
  2262. if (pa != null)
  2263. {
  2264. pa.VehicleFloatParam(param, value);
  2265. }
  2266. }
  2267. public void SetVehicleVectorParam(int param, PhysicsVector value)
  2268. {
  2269. PhysicsActor pa = PhysActor;
  2270. if (pa != null)
  2271. {
  2272. pa.VehicleVectorParam(param, value);
  2273. }
  2274. }
  2275. public void SetVehicleRotationParam(int param, Quaternion rotation)
  2276. {
  2277. PhysicsActor pa = PhysActor;
  2278. if (pa != null)
  2279. {
  2280. pa.VehicleRotationParam(param, rotation);
  2281. }
  2282. }
  2283. public void SetGroup(UUID groupID, IClientAPI client)
  2284. {
  2285. _groupID = groupID;
  2286. if (client != null)
  2287. GetProperties(client);
  2288. m_updateFlag = 2;
  2289. }
  2290. /// <summary>
  2291. ///
  2292. /// </summary>
  2293. public void SetParent(SceneObjectGroup parent)
  2294. {
  2295. m_parentGroup = parent;
  2296. }
  2297. // Use this for attachments! LocalID should be avatar's localid
  2298. public void SetParentLocalId(uint localID)
  2299. {
  2300. _parentID = localID;
  2301. }
  2302. public void SetPhysicsAxisRotation()
  2303. {
  2304. PhysicsActor pa = PhysActor;
  2305. if (pa != null)
  2306. {
  2307. pa.LockAngularMotion(RotationAxis);
  2308. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2309. }
  2310. }
  2311. public void SetScriptEvents(UUID scriptid, int events)
  2312. {
  2313. // scriptEvents oldparts;
  2314. lock (m_scriptEvents)
  2315. {
  2316. if (m_scriptEvents.ContainsKey(scriptid))
  2317. {
  2318. // oldparts = m_scriptEvents[scriptid];
  2319. // remove values from aggregated script events
  2320. if (m_scriptEvents[scriptid] == (scriptEvents) events)
  2321. return;
  2322. m_scriptEvents[scriptid] = (scriptEvents) events;
  2323. }
  2324. else
  2325. {
  2326. m_scriptEvents.Add(scriptid, (scriptEvents) events);
  2327. }
  2328. }
  2329. aggregateScriptEvents();
  2330. }
  2331. /// <summary>
  2332. /// Set the text displayed for this part.
  2333. /// </summary>
  2334. /// <param name="text"></param>
  2335. public void SetText(string text)
  2336. {
  2337. Text = text;
  2338. ParentGroup.HasGroupChanged = true;
  2339. ScheduleFullUpdate();
  2340. }
  2341. /// <summary>
  2342. /// Set the text displayed for this part.
  2343. /// </summary>
  2344. /// <param name="text"></param>
  2345. /// <param name="color"></param>
  2346. /// <param name="alpha"></param>
  2347. public void SetText(string text, Vector3 color, double alpha)
  2348. {
  2349. Color = Color.FromArgb(0xff - (int) (alpha*0xff),
  2350. (int) (color.X*0xff),
  2351. (int) (color.Y*0xff),
  2352. (int) (color.Z*0xff));
  2353. SetText(text);
  2354. }
  2355. public void StopMoveToTarget()
  2356. {
  2357. m_parentGroup.stopMoveToTarget();
  2358. m_parentGroup.ScheduleGroupForTerseUpdate();
  2359. //m_parentGroup.ScheduleGroupForFullUpdate();
  2360. }
  2361. public void StoreUndoState()
  2362. {
  2363. if (!Undoing)
  2364. {
  2365. if (m_parentGroup != null)
  2366. {
  2367. lock (m_undo)
  2368. {
  2369. if (m_undo.Count > 0)
  2370. {
  2371. UndoState last = m_undo.Peek();
  2372. if (last != null)
  2373. {
  2374. if (last.Compare(this))
  2375. return;
  2376. }
  2377. }
  2378. if (m_parentGroup.GetSceneMaxUndo() > 0)
  2379. {
  2380. UndoState nUndo = new UndoState(this);
  2381. m_undo.Push(nUndo);
  2382. }
  2383. }
  2384. }
  2385. }
  2386. }
  2387. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  2388. {
  2389. // In this case we're using a sphere with a radius of the largest dimension of the prim
  2390. // TODO: Change to take shape into account
  2391. EntityIntersection result = new EntityIntersection();
  2392. Vector3 vAbsolutePosition = AbsolutePosition;
  2393. Vector3 vScale = Scale;
  2394. Vector3 rOrigin = iray.Origin;
  2395. Vector3 rDirection = iray.Direction;
  2396. //rDirection = rDirection.Normalize();
  2397. // Buidling the first part of the Quadratic equation
  2398. Vector3 r2ndDirection = rDirection*rDirection;
  2399. float itestPart1 = r2ndDirection.X + r2ndDirection.Y + r2ndDirection.Z;
  2400. // Buidling the second part of the Quadratic equation
  2401. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  2402. Vector3 r2Direction = rDirection*2.0f;
  2403. Vector3 tmVal3 = r2Direction*tmVal2;
  2404. float itestPart2 = tmVal3.X + tmVal3.Y + tmVal3.Z;
  2405. // Buidling the third part of the Quadratic equation
  2406. Vector3 tmVal4 = rOrigin*rOrigin;
  2407. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  2408. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  2409. // Set Radius to the largest dimension of the prim
  2410. float radius = 0f;
  2411. if (vScale.X > radius)
  2412. radius = vScale.X;
  2413. if (vScale.Y > radius)
  2414. radius = vScale.Y;
  2415. if (vScale.Z > radius)
  2416. radius = vScale.Z;
  2417. // the second part of this is the default prim size
  2418. // once we factor in the aabb of the prim we're adding we can
  2419. // change this to;
  2420. // radius = (radius / 2) - 0.01f;
  2421. //
  2422. radius = (radius / 2) + (0.5f / 2) - 0.1f;
  2423. //radius = radius;
  2424. float itestPart3 = tmVal4.X + tmVal4.Y + tmVal4.Z + tmVal5.X + tmVal5.Y + tmVal5.Z -
  2425. (2.0f*(tmVal6.X + tmVal6.Y + tmVal6.Z + (radius*radius)));
  2426. // Yuk Quadradrics.. Solve first
  2427. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  2428. if (rootsqr < 0.0f)
  2429. {
  2430. // No intersection
  2431. return result;
  2432. }
  2433. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  2434. if (root < 0.0f)
  2435. {
  2436. // perform second quadratic root solution
  2437. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  2438. // is there any intersection?
  2439. if (root < 0.0f)
  2440. {
  2441. // nope, no intersection
  2442. return result;
  2443. }
  2444. }
  2445. // We got an intersection. putting together an EntityIntersection object with the
  2446. // intersection information
  2447. Vector3 ipoint =
  2448. new Vector3(iray.Origin.X + (iray.Direction.X*root), iray.Origin.Y + (iray.Direction.Y*root),
  2449. iray.Origin.Z + (iray.Direction.Z*root));
  2450. result.HitTF = true;
  2451. result.ipoint = ipoint;
  2452. // Normal is calculated by the difference and then normalizing the result
  2453. Vector3 normalpart = ipoint - vAbsolutePosition;
  2454. result.normal = normalpart / normalpart.Length();
  2455. // It's funny how the Vector3 object has a Distance function, but the Axiom.Math object doesn't.
  2456. // I can write a function to do it.. but I like the fact that this one is Static.
  2457. Vector3 distanceConvert1 = new Vector3(iray.Origin.X, iray.Origin.Y, iray.Origin.Z);
  2458. Vector3 distanceConvert2 = new Vector3(ipoint.X, ipoint.Y, ipoint.Z);
  2459. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  2460. result.distance = distance;
  2461. return result;
  2462. }
  2463. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  2464. {
  2465. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  2466. // This breaks down into the ray---> plane equation.
  2467. // TODO: Change to take shape into account
  2468. Vector3[] vertexes = new Vector3[8];
  2469. // float[] distance = new float[6];
  2470. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  2471. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  2472. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  2473. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  2474. Vector3[] normals = new Vector3[6]; // Normal for Facei
  2475. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  2476. AAfacenormals[0] = new Vector3(1, 0, 0);
  2477. AAfacenormals[1] = new Vector3(0, 1, 0);
  2478. AAfacenormals[2] = new Vector3(-1, 0, 0);
  2479. AAfacenormals[3] = new Vector3(0, -1, 0);
  2480. AAfacenormals[4] = new Vector3(0, 0, 1);
  2481. AAfacenormals[5] = new Vector3(0, 0, -1);
  2482. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  2483. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  2484. Vector3 cross = new Vector3();
  2485. Vector3 pos = GetWorldPosition();
  2486. Quaternion rot = GetWorldRotation();
  2487. // Variables prefixed with AX are Axiom.Math copies of the LL variety.
  2488. Quaternion AXrot = rot;
  2489. AXrot.Normalize();
  2490. Vector3 AXpos = pos;
  2491. // tScale is the offset to derive the vertex based on the scale.
  2492. // it's different for each vertex because we've got to rotate it
  2493. // to get the world position of the vertex to produce the Oriented Bounding Box
  2494. Vector3 tScale = Vector3.Zero;
  2495. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  2496. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  2497. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  2498. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  2499. Vector3 rScale = new Vector3();
  2500. // Get Vertexes for Faces Stick them into ABCD for each Face
  2501. // Form: Face<vertex>[face] that corresponds to the below diagram
  2502. #region ABCD Face Vertex Map Comment Diagram
  2503. // A _________ B
  2504. // | |
  2505. // | 4 top |
  2506. // |_________|
  2507. // C D
  2508. // A _________ B
  2509. // | Back |
  2510. // | 3 |
  2511. // |_________|
  2512. // C D
  2513. // A _________ B B _________ A
  2514. // | Left | | Right |
  2515. // | 0 | | 2 |
  2516. // |_________| |_________|
  2517. // C D D C
  2518. // A _________ B
  2519. // | Front |
  2520. // | 1 |
  2521. // |_________|
  2522. // C D
  2523. // C _________ D
  2524. // | |
  2525. // | 5 bot |
  2526. // |_________|
  2527. // A B
  2528. #endregion
  2529. #region Plane Decomposition of Oriented Bounding Box
  2530. tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
  2531. rScale = tScale * AXrot;
  2532. vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2533. // vertexes[0].X = pos.X + vertexes[0].X;
  2534. //vertexes[0].Y = pos.Y + vertexes[0].Y;
  2535. //vertexes[0].Z = pos.Z + vertexes[0].Z;
  2536. FaceA[0] = vertexes[0];
  2537. FaceB[3] = vertexes[0];
  2538. FaceA[4] = vertexes[0];
  2539. tScale = AXscale;
  2540. rScale = tScale * AXrot;
  2541. vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2542. // vertexes[1].X = pos.X + vertexes[1].X;
  2543. // vertexes[1].Y = pos.Y + vertexes[1].Y;
  2544. //vertexes[1].Z = pos.Z + vertexes[1].Z;
  2545. FaceB[0] = vertexes[1];
  2546. FaceA[1] = vertexes[1];
  2547. FaceC[4] = vertexes[1];
  2548. tScale = new Vector3(AXscale.X, -AXscale.Y, -AXscale.Z);
  2549. rScale = tScale * AXrot;
  2550. vertexes[2] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2551. //vertexes[2].X = pos.X + vertexes[2].X;
  2552. //vertexes[2].Y = pos.Y + vertexes[2].Y;
  2553. //vertexes[2].Z = pos.Z + vertexes[2].Z;
  2554. FaceC[0] = vertexes[2];
  2555. FaceD[3] = vertexes[2];
  2556. FaceC[5] = vertexes[2];
  2557. tScale = new Vector3(AXscale.X, AXscale.Y, -AXscale.Z);
  2558. rScale = tScale * AXrot;
  2559. vertexes[3] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2560. //vertexes[3].X = pos.X + vertexes[3].X;
  2561. // vertexes[3].Y = pos.Y + vertexes[3].Y;
  2562. // vertexes[3].Z = pos.Z + vertexes[3].Z;
  2563. FaceD[0] = vertexes[3];
  2564. FaceC[1] = vertexes[3];
  2565. FaceA[5] = vertexes[3];
  2566. tScale = new Vector3(-AXscale.X, AXscale.Y, AXscale.Z);
  2567. rScale = tScale * AXrot;
  2568. vertexes[4] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2569. // vertexes[4].X = pos.X + vertexes[4].X;
  2570. // vertexes[4].Y = pos.Y + vertexes[4].Y;
  2571. // vertexes[4].Z = pos.Z + vertexes[4].Z;
  2572. FaceB[1] = vertexes[4];
  2573. FaceA[2] = vertexes[4];
  2574. FaceD[4] = vertexes[4];
  2575. tScale = new Vector3(-AXscale.X, AXscale.Y, -AXscale.Z);
  2576. rScale = tScale * AXrot;
  2577. vertexes[5] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2578. // vertexes[5].X = pos.X + vertexes[5].X;
  2579. // vertexes[5].Y = pos.Y + vertexes[5].Y;
  2580. // vertexes[5].Z = pos.Z + vertexes[5].Z;
  2581. FaceD[1] = vertexes[5];
  2582. FaceC[2] = vertexes[5];
  2583. FaceB[5] = vertexes[5];
  2584. tScale = new Vector3(-AXscale.X, -AXscale.Y, AXscale.Z);
  2585. rScale = tScale * AXrot;
  2586. vertexes[6] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2587. // vertexes[6].X = pos.X + vertexes[6].X;
  2588. // vertexes[6].Y = pos.Y + vertexes[6].Y;
  2589. // vertexes[6].Z = pos.Z + vertexes[6].Z;
  2590. FaceB[2] = vertexes[6];
  2591. FaceA[3] = vertexes[6];
  2592. FaceB[4] = vertexes[6];
  2593. tScale = new Vector3(-AXscale.X, -AXscale.Y, -AXscale.Z);
  2594. rScale = tScale * AXrot;
  2595. vertexes[7] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  2596. // vertexes[7].X = pos.X + vertexes[7].X;
  2597. // vertexes[7].Y = pos.Y + vertexes[7].Y;
  2598. // vertexes[7].Z = pos.Z + vertexes[7].Z;
  2599. FaceD[2] = vertexes[7];
  2600. FaceC[3] = vertexes[7];
  2601. FaceD[5] = vertexes[7];
  2602. #endregion
  2603. // Get our plane normals
  2604. for (int i = 0; i < 6; i++)
  2605. {
  2606. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  2607. // Our Plane direction
  2608. AmBa = FaceA[i] - FaceB[i];
  2609. AmBb = FaceB[i] - FaceC[i];
  2610. cross = Vector3.Cross(AmBb, AmBa);
  2611. // normalize the cross product to get the normal.
  2612. normals[i] = cross / cross.Length();
  2613. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  2614. //distance[i] = (normals[i].X * AmBa.X + normals[i].Y * AmBa.Y + normals[i].Z * AmBa.Z) * -1;
  2615. }
  2616. EntityIntersection result = new EntityIntersection();
  2617. result.distance = 1024;
  2618. float c = 0;
  2619. float a = 0;
  2620. float d = 0;
  2621. Vector3 q = new Vector3();
  2622. #region OBB Version 2 Experiment
  2623. //float fmin = 999999;
  2624. //float fmax = -999999;
  2625. //float s = 0;
  2626. //for (int i=0;i<6;i++)
  2627. //{
  2628. //s = iray.Direction.Dot(normals[i]);
  2629. //d = normals[i].Dot(FaceB[i]);
  2630. //if (s == 0)
  2631. //{
  2632. //if (iray.Origin.Dot(normals[i]) > d)
  2633. //{
  2634. //return result;
  2635. //}
  2636. // else
  2637. //{
  2638. //continue;
  2639. //}
  2640. //}
  2641. //a = (d - iray.Origin.Dot(normals[i])) / s;
  2642. //if (iray.Direction.Dot(normals[i]) < 0)
  2643. //{
  2644. //if (a > fmax)
  2645. //{
  2646. //if (a > fmin)
  2647. //{
  2648. //return result;
  2649. //}
  2650. //fmax = a;
  2651. //}
  2652. //}
  2653. //else
  2654. //{
  2655. //if (a < fmin)
  2656. //{
  2657. //if (a < 0 || a < fmax)
  2658. //{
  2659. //return result;
  2660. //}
  2661. //fmin = a;
  2662. //}
  2663. //}
  2664. //}
  2665. //if (fmax > 0)
  2666. // a= fmax;
  2667. //else
  2668. // a=fmin;
  2669. //q = iray.Origin + a * iray.Direction;
  2670. #endregion
  2671. // Loop over faces (6 of them)
  2672. for (int i = 0; i < 6; i++)
  2673. {
  2674. AmBa = FaceA[i] - FaceB[i];
  2675. AmBb = FaceB[i] - FaceC[i];
  2676. d = Vector3.Dot(normals[i], FaceB[i]);
  2677. //if (faceCenters)
  2678. //{
  2679. // c = normals[i].Dot(normals[i]);
  2680. //}
  2681. //else
  2682. //{
  2683. c = Vector3.Dot(iray.Direction, normals[i]);
  2684. //}
  2685. if (c == 0)
  2686. continue;
  2687. a = (d - Vector3.Dot(iray.Origin, normals[i])) / c;
  2688. if (a < 0)
  2689. continue;
  2690. // If the normal is pointing outside the object
  2691. if (Vector3.Dot(iray.Direction, normals[i]) < 0 || !frontFacesOnly)
  2692. {
  2693. //if (faceCenters)
  2694. //{ //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  2695. // q = iray.Origin + a * normals[i];
  2696. //}
  2697. //else
  2698. //{
  2699. q = iray.Origin + iray.Direction * a;
  2700. //}
  2701. float distance2 = (float)GetDistanceTo(q, AXpos);
  2702. // Is this the closest hit to the object's origin?
  2703. //if (faceCenters)
  2704. //{
  2705. // distance2 = (float)GetDistanceTo(q, iray.Origin);
  2706. //}
  2707. if (distance2 < result.distance)
  2708. {
  2709. result.distance = distance2;
  2710. result.HitTF = true;
  2711. result.ipoint = q;
  2712. //m_log.Info("[FACE]:" + i.ToString());
  2713. //m_log.Info("[POINT]: " + q.ToString());
  2714. //m_log.Info("[DIST]: " + distance2.ToString());
  2715. if (faceCenters)
  2716. {
  2717. result.normal = AAfacenormals[i] * AXrot;
  2718. Vector3 scaleComponent = AAfacenormals[i];
  2719. float ScaleOffset = 0.5f;
  2720. if (scaleComponent.X != 0) ScaleOffset = AXscale.X;
  2721. if (scaleComponent.Y != 0) ScaleOffset = AXscale.Y;
  2722. if (scaleComponent.Z != 0) ScaleOffset = AXscale.Z;
  2723. ScaleOffset = Math.Abs(ScaleOffset);
  2724. Vector3 offset = result.normal * ScaleOffset;
  2725. result.ipoint = AXpos + offset;
  2726. ///pos = (intersectionpoint + offset);
  2727. }
  2728. else
  2729. {
  2730. result.normal = normals[i];
  2731. }
  2732. result.AAfaceNormal = AAfacenormals[i];
  2733. }
  2734. }
  2735. }
  2736. return result;
  2737. }
  2738. /// <summary>
  2739. /// Serialize this part to xml.
  2740. /// </summary>
  2741. /// <param name="xmlWriter"></param>
  2742. public void ToXml(XmlWriter xmlWriter)
  2743. {
  2744. serializer.Serialize(xmlWriter, this);
  2745. }
  2746. public void TriggerScriptChangedEvent(Changed val)
  2747. {
  2748. if (m_parentGroup != null && m_parentGroup.Scene != null)
  2749. m_parentGroup.Scene.EventManager.TriggerOnScriptChangedEvent(LocalId, (uint)val);
  2750. }
  2751. public void TrimPermissions()
  2752. {
  2753. _baseMask &= (uint)PermissionMask.All;
  2754. _ownerMask &= (uint)PermissionMask.All;
  2755. _groupMask &= (uint)PermissionMask.All;
  2756. _everyoneMask &= (uint)PermissionMask.All;
  2757. _nextOwnerMask &= (uint)PermissionMask.All;
  2758. }
  2759. public void Undo()
  2760. {
  2761. lock (m_undo)
  2762. {
  2763. if (m_undo.Count > 0)
  2764. {
  2765. UndoState goback = m_undo.Pop();
  2766. if (goback != null)
  2767. goback.PlaybackState(this);
  2768. }
  2769. }
  2770. }
  2771. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  2772. {
  2773. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  2774. if (type == 0x30)
  2775. {
  2776. if (m_shape.SculptEntry && m_shape.SculptTexture != UUID.Zero)
  2777. {
  2778. m_parentGroup.Scene.AssetService.Get(m_shape.SculptTexture.ToString(), this, AssetReceived);
  2779. }
  2780. }
  2781. ParentGroup.HasGroupChanged = true;
  2782. ScheduleFullUpdate();
  2783. }
  2784. public void UpdateGroupPosition(Vector3 pos)
  2785. {
  2786. if ((pos.X != GroupPosition.X) ||
  2787. (pos.Y != GroupPosition.Y) ||
  2788. (pos.Z != GroupPosition.Z))
  2789. {
  2790. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  2791. GroupPosition = newPos;
  2792. ScheduleTerseUpdate();
  2793. }
  2794. }
  2795. public virtual void UpdateMovement()
  2796. {
  2797. }
  2798. /// <summary>
  2799. ///
  2800. /// </summary>
  2801. /// <param name="pos"></param>
  2802. public void UpdateOffSet(Vector3 pos)
  2803. {
  2804. if ((pos.X != OffsetPosition.X) ||
  2805. (pos.Y != OffsetPosition.Y) ||
  2806. (pos.Z != OffsetPosition.Z))
  2807. {
  2808. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  2809. OffsetPosition = newPos;
  2810. ScheduleTerseUpdate();
  2811. }
  2812. }
  2813. public void UpdatePermissions(UUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  2814. {
  2815. bool set = addRemTF == 1;
  2816. bool god = m_parentGroup.Scene.Permissions.IsGod(AgentID);
  2817. uint baseMask = _baseMask;
  2818. if (god)
  2819. baseMask = 0x7ffffff0;
  2820. // Are we the owner?
  2821. if ((AgentID == _ownerID) || god)
  2822. {
  2823. switch (field)
  2824. {
  2825. case 1:
  2826. if (god)
  2827. {
  2828. _baseMask = ApplyMask(_baseMask, set, mask);
  2829. Inventory.ApplyGodPermissions(_baseMask);
  2830. }
  2831. break;
  2832. case 2:
  2833. _ownerMask = ApplyMask(_ownerMask, set, mask) &
  2834. baseMask;
  2835. break;
  2836. case 4:
  2837. _groupMask = ApplyMask(_groupMask, set, mask) &
  2838. baseMask;
  2839. break;
  2840. case 8:
  2841. _everyoneMask = ApplyMask(_everyoneMask, set, mask) &
  2842. baseMask;
  2843. break;
  2844. case 16:
  2845. _nextOwnerMask = ApplyMask(_nextOwnerMask, set, mask) &
  2846. baseMask;
  2847. break;
  2848. }
  2849. SendFullUpdateToAllClients();
  2850. SendObjectPropertiesToClient(AgentID);
  2851. }
  2852. }
  2853. public bool IsHingeJoint()
  2854. {
  2855. // For now, we use the NINJA naming scheme for identifying joints.
  2856. // In the future, we can support other joint specification schemes such as a
  2857. // custom checkbox in the viewer GUI.
  2858. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  2859. {
  2860. string hingeString = "hingejoint";
  2861. return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
  2862. }
  2863. else
  2864. {
  2865. return false;
  2866. }
  2867. }
  2868. public bool IsBallJoint()
  2869. {
  2870. // For now, we use the NINJA naming scheme for identifying joints.
  2871. // In the future, we can support other joint specification schemes such as a
  2872. // custom checkbox in the viewer GUI.
  2873. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  2874. {
  2875. string ballString = "balljoint";
  2876. return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
  2877. }
  2878. else
  2879. {
  2880. return false;
  2881. }
  2882. }
  2883. public bool IsJoint()
  2884. {
  2885. // For now, we use the NINJA naming scheme for identifying joints.
  2886. // In the future, we can support other joint specification schemes such as a
  2887. // custom checkbox in the viewer GUI.
  2888. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  2889. {
  2890. return IsHingeJoint() || IsBallJoint();
  2891. }
  2892. else
  2893. {
  2894. return false;
  2895. }
  2896. }
  2897. public void UpdatePrimFlags(bool UsePhysics, bool IsTemporary, bool IsPhantom, bool IsVD)
  2898. {
  2899. bool wasUsingPhysics = ((ObjectFlags & (uint) PrimFlags.Physics) != 0);
  2900. bool wasTemporary = ((ObjectFlags & (uint)PrimFlags.TemporaryOnRez) != 0);
  2901. bool wasPhantom = ((ObjectFlags & (uint)PrimFlags.Phantom) != 0);
  2902. bool wasVD = VolumeDetectActive;
  2903. if ((UsePhysics == wasUsingPhysics) && (wasTemporary == IsTemporary) && (wasPhantom == IsPhantom) && (IsVD==wasVD))
  2904. {
  2905. return;
  2906. }
  2907. // Special cases for VD. VD can only be called from a script
  2908. // and can't be combined with changes to other states. So we can rely
  2909. // that...
  2910. // ... if VD is changed, all others are not.
  2911. // ... if one of the others is changed, VD is not.
  2912. if (IsVD) // VD is active, special logic applies
  2913. {
  2914. // State machine logic for VolumeDetect
  2915. // More logic below
  2916. bool phanReset = (IsPhantom != wasPhantom) && !IsPhantom;
  2917. if (phanReset) // Phantom changes from on to off switch VD off too
  2918. {
  2919. IsVD = false; // Switch it of for the course of this routine
  2920. VolumeDetectActive = false; // and also permanently
  2921. PhysicsActor pa = PhysActor;
  2922. if (pa != null)
  2923. pa.SetVolumeDetect(0); // Let physics know about it too
  2924. }
  2925. else
  2926. {
  2927. IsPhantom = false;
  2928. // If volumedetect is active we don't want phantom to be applied.
  2929. // If this is a new call to VD out of the state "phantom"
  2930. // this will also cause the prim to be visible to physics
  2931. }
  2932. }
  2933. if (UsePhysics && IsJoint())
  2934. {
  2935. IsPhantom = true;
  2936. }
  2937. if (UsePhysics)
  2938. {
  2939. AddFlag(PrimFlags.Physics);
  2940. if (!wasUsingPhysics)
  2941. {
  2942. DoPhysicsPropertyUpdate(UsePhysics, false);
  2943. if (m_parentGroup != null)
  2944. {
  2945. if (!m_parentGroup.IsDeleted)
  2946. {
  2947. if (LocalId == m_parentGroup.RootPart.LocalId)
  2948. {
  2949. m_parentGroup.CheckSculptAndLoad();
  2950. }
  2951. }
  2952. }
  2953. }
  2954. }
  2955. else
  2956. {
  2957. RemFlag(PrimFlags.Physics);
  2958. if (wasUsingPhysics)
  2959. {
  2960. DoPhysicsPropertyUpdate(UsePhysics, false);
  2961. }
  2962. }
  2963. if (IsPhantom || IsAttachment || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
  2964. {
  2965. AddFlag(PrimFlags.Phantom);
  2966. PhysicsActor pa = PhysActor;
  2967. if (pa != null)
  2968. {
  2969. m_parentGroup.Scene.PhysicsScene.RemovePrim(pa);
  2970. /// that's not wholesome. Had to make Scene public
  2971. pa = null;
  2972. }
  2973. }
  2974. else // Not phantom
  2975. {
  2976. RemFlag(PrimFlags.Phantom);
  2977. // This is NOT safe!!
  2978. PhysicsActor pa = PhysActor;
  2979. if (pa == null)
  2980. {
  2981. // It's not phantom anymore. So make sure the physics engine get's knowledge of it
  2982. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  2983. Name,
  2984. Shape,
  2985. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z),
  2986. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  2987. RotationOffset,
  2988. UsePhysics);
  2989. pa = PhysActor;
  2990. if (pa != null)
  2991. {
  2992. pa.LocalID = LocalId;
  2993. DoPhysicsPropertyUpdate(UsePhysics, true);
  2994. if (m_parentGroup != null)
  2995. {
  2996. if (!m_parentGroup.IsDeleted)
  2997. {
  2998. if (LocalId == m_parentGroup.RootPart.LocalId)
  2999. {
  3000. m_parentGroup.CheckSculptAndLoad();
  3001. }
  3002. }
  3003. }
  3004. if (
  3005. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  3006. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  3007. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  3008. (CollisionSound != UUID.Zero)
  3009. )
  3010. {
  3011. pa.OnCollisionUpdate += PhysicsCollision;
  3012. pa.SubscribeEvents(1000);
  3013. }
  3014. }
  3015. }
  3016. else // it already has a physical representation
  3017. {
  3018. pa.IsPhysical = UsePhysics;
  3019. DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
  3020. if (m_parentGroup != null)
  3021. {
  3022. if (!m_parentGroup.IsDeleted)
  3023. {
  3024. if (LocalId == m_parentGroup.RootPart.LocalId)
  3025. {
  3026. m_parentGroup.CheckSculptAndLoad();
  3027. }
  3028. }
  3029. }
  3030. }
  3031. }
  3032. if (IsVD)
  3033. {
  3034. // If the above logic worked (this is urgent candidate to unit tests!)
  3035. // we now have a physicsactor.
  3036. // Defensive programming calls for a check here.
  3037. // Better would be throwing an exception that could be catched by a unit test as the internal
  3038. // logic should make sure, this Physactor is always here.
  3039. PhysicsActor pa = this.PhysActor;
  3040. if (pa != null)
  3041. {
  3042. pa.SetVolumeDetect(1);
  3043. AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
  3044. this.VolumeDetectActive = true;
  3045. }
  3046. }
  3047. else
  3048. { // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
  3049. // (mumbles, well, at least if you have infinte CPU powers :-))
  3050. PhysicsActor pa = this.PhysActor;
  3051. if (pa != null)
  3052. {
  3053. pa.SetVolumeDetect(0);
  3054. }
  3055. this.VolumeDetectActive = false;
  3056. }
  3057. if (IsTemporary)
  3058. {
  3059. AddFlag(PrimFlags.TemporaryOnRez);
  3060. }
  3061. else
  3062. {
  3063. RemFlag(PrimFlags.TemporaryOnRez);
  3064. }
  3065. // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  3066. ParentGroup.HasGroupChanged = true;
  3067. ScheduleFullUpdate();
  3068. }
  3069. public void UpdateRotation(Quaternion rot)
  3070. {
  3071. if ((rot.X != RotationOffset.X) ||
  3072. (rot.Y != RotationOffset.Y) ||
  3073. (rot.Z != RotationOffset.Z) ||
  3074. (rot.W != RotationOffset.W))
  3075. {
  3076. //StoreUndoState();
  3077. RotationOffset = rot;
  3078. ParentGroup.HasGroupChanged = true;
  3079. ScheduleTerseUpdate();
  3080. }
  3081. }
  3082. /// <summary>
  3083. /// Update the shape of this part.
  3084. /// </summary>
  3085. /// <param name="shapeBlock"></param>
  3086. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  3087. {
  3088. m_shape.PathBegin = shapeBlock.PathBegin;
  3089. m_shape.PathEnd = shapeBlock.PathEnd;
  3090. m_shape.PathScaleX = shapeBlock.PathScaleX;
  3091. m_shape.PathScaleY = shapeBlock.PathScaleY;
  3092. m_shape.PathShearX = shapeBlock.PathShearX;
  3093. m_shape.PathShearY = shapeBlock.PathShearY;
  3094. m_shape.PathSkew = shapeBlock.PathSkew;
  3095. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  3096. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  3097. m_shape.PathCurve = shapeBlock.PathCurve;
  3098. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  3099. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  3100. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  3101. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  3102. m_shape.PathTaperX = shapeBlock.PathTaperX;
  3103. m_shape.PathTaperY = shapeBlock.PathTaperY;
  3104. m_shape.PathTwist = shapeBlock.PathTwist;
  3105. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  3106. PhysicsActor pa = PhysActor;
  3107. if (pa != null)
  3108. {
  3109. pa.Shape = m_shape;
  3110. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3111. }
  3112. // This is what makes vehicle trailers work
  3113. // A script in a child prim re-issues
  3114. // llSetPrimitiveParams(PRIM_TYPE) every few seconds. That
  3115. // prevents autoreturn. This is not well known. It also works
  3116. // in SL.
  3117. //
  3118. if (ParentGroup.RootPart != this)
  3119. ParentGroup.RootPart.Rezzed = DateTime.Now;
  3120. ParentGroup.HasGroupChanged = true;
  3121. ScheduleFullUpdate();
  3122. }
  3123. // Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  3124. // not handling RGBA properly. Cycles through, and "fixes" the color
  3125. // info
  3126. public void UpdateTexture(Primitive.TextureEntry tex)
  3127. {
  3128. //Color4 tmpcolor;
  3129. //for (uint i = 0; i < 32; i++)
  3130. //{
  3131. // if (tex.FaceTextures[i] != null)
  3132. // {
  3133. // tmpcolor = tex.GetFace((uint) i).RGBA;
  3134. // tmpcolor.A = tmpcolor.A*255;
  3135. // tmpcolor.R = tmpcolor.R*255;
  3136. // tmpcolor.G = tmpcolor.G*255;
  3137. // tmpcolor.B = tmpcolor.B*255;
  3138. // tex.FaceTextures[i].RGBA = tmpcolor;
  3139. // }
  3140. //}
  3141. //tmpcolor = tex.DefaultTexture.RGBA;
  3142. //tmpcolor.A = tmpcolor.A*255;
  3143. //tmpcolor.R = tmpcolor.R*255;
  3144. //tmpcolor.G = tmpcolor.G*255;
  3145. //tmpcolor.B = tmpcolor.B*255;
  3146. //tex.DefaultTexture.RGBA = tmpcolor;
  3147. UpdateTextureEntry(tex.GetBytes());
  3148. }
  3149. /// <summary>
  3150. /// Update the texture entry for this part.
  3151. /// </summary>
  3152. /// <param name="textureEntry"></param>
  3153. public void UpdateTextureEntry(byte[] textureEntry)
  3154. {
  3155. m_shape.TextureEntry = textureEntry;
  3156. TriggerScriptChangedEvent(Changed.TEXTURE);
  3157. ParentGroup.HasGroupChanged = true;
  3158. //This is madness..
  3159. //ParentGroup.ScheduleGroupForFullUpdate();
  3160. //This is sparta
  3161. ScheduleFullUpdate();
  3162. }
  3163. public void aggregateScriptEvents()
  3164. {
  3165. AggregateScriptEvents = 0;
  3166. // Aggregate script events
  3167. lock (m_scriptEvents)
  3168. {
  3169. foreach (scriptEvents s in m_scriptEvents.Values)
  3170. {
  3171. AggregateScriptEvents |= s;
  3172. }
  3173. }
  3174. uint objectflagupdate = 0;
  3175. if (
  3176. ((AggregateScriptEvents & scriptEvents.touch) != 0) ||
  3177. ((AggregateScriptEvents & scriptEvents.touch_end) != 0) ||
  3178. ((AggregateScriptEvents & scriptEvents.touch_start) != 0)
  3179. )
  3180. {
  3181. objectflagupdate |= (uint) PrimFlags.Touch;
  3182. }
  3183. if ((AggregateScriptEvents & scriptEvents.money) != 0)
  3184. {
  3185. objectflagupdate |= (uint) PrimFlags.Money;
  3186. }
  3187. if (AllowedDrop)
  3188. {
  3189. objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
  3190. }
  3191. if (
  3192. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  3193. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  3194. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  3195. (CollisionSound != UUID.Zero)
  3196. )
  3197. {
  3198. // subscribe to physics updates.
  3199. PhysicsActor pa = PhysActor;
  3200. if (pa != null)
  3201. {
  3202. pa.OnCollisionUpdate += PhysicsCollision;
  3203. pa.SubscribeEvents(1000);
  3204. }
  3205. }
  3206. else
  3207. {
  3208. PhysicsActor pa = PhysActor;
  3209. if (pa != null)
  3210. {
  3211. pa.UnSubscribeEvents();
  3212. pa.OnCollisionUpdate -= PhysicsCollision;
  3213. }
  3214. }
  3215. if (m_parentGroup == null)
  3216. {
  3217. ScheduleFullUpdate();
  3218. return;
  3219. }
  3220. //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
  3221. //{
  3222. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting;
  3223. //}
  3224. //else
  3225. //{
  3226. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent -= handleTimerAccounting;
  3227. //}
  3228. LocalFlags=(PrimFlags)objectflagupdate;
  3229. if (m_parentGroup != null && m_parentGroup.RootPart == this)
  3230. m_parentGroup.aggregateScriptEvents();
  3231. else
  3232. ScheduleFullUpdate();
  3233. }
  3234. public int registerTargetWaypoint(Vector3 target, float tolerance)
  3235. {
  3236. if (m_parentGroup != null)
  3237. {
  3238. return m_parentGroup.registerTargetWaypoint(target, tolerance);
  3239. }
  3240. return 0;
  3241. }
  3242. public void unregisterTargetWaypoint(int handle)
  3243. {
  3244. if (m_parentGroup != null)
  3245. {
  3246. m_parentGroup.unregisterTargetWaypoint(handle);
  3247. }
  3248. }
  3249. public void SetCameraAtOffset(Vector3 v)
  3250. {
  3251. m_cameraAtOffset = v;
  3252. }
  3253. public void SetCameraEyeOffset(Vector3 v)
  3254. {
  3255. m_cameraEyeOffset = v;
  3256. }
  3257. public void SetForceMouselook(bool force)
  3258. {
  3259. m_forceMouselook = force;
  3260. }
  3261. public Vector3 GetCameraAtOffset()
  3262. {
  3263. return m_cameraAtOffset;
  3264. }
  3265. public Vector3 GetCameraEyeOffset()
  3266. {
  3267. return m_cameraEyeOffset;
  3268. }
  3269. public bool GetForceMouselook()
  3270. {
  3271. return m_forceMouselook;
  3272. }
  3273. public override string ToString()
  3274. {
  3275. return String.Format("{0} {1} (parent {2}))", Name, UUID, ParentGroup);
  3276. }
  3277. #endregion Public Methods
  3278. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  3279. {
  3280. if (ParentGroup == null || ParentGroup.IsDeleted)
  3281. return;
  3282. Vector3 lPos = OffsetPosition;
  3283. byte state = Shape.State;
  3284. if (IsAttachment)
  3285. {
  3286. if (ParentGroup.RootPart != this)
  3287. return;
  3288. lPos = ParentGroup.RootPart.AttachedPos;
  3289. state = (byte)AttachmentPoint;
  3290. }
  3291. else
  3292. {
  3293. if (ParentGroup.RootPart == this)
  3294. lPos = AbsolutePosition;
  3295. }
  3296. // Causes this thread to dig into the Client Thread Data.
  3297. // Remember your locking here!
  3298. remoteClient.SendPrimTerseUpdate(new SendPrimitiveTerseData(m_regionHandle,
  3299. (ushort)(m_parentGroup.GetTimeDilation() *
  3300. (float)ushort.MaxValue), LocalId, lPos,
  3301. RotationOffset, Velocity, Acceleration,
  3302. RotationalVelocity, state, FromItemID,
  3303. OwnerID, (int)AttachmentPoint, null, ParentGroup.GetUpdatePriority(remoteClient)));
  3304. }
  3305. public void AddScriptLPS(int count)
  3306. {
  3307. m_parentGroup.AddScriptLPS(count);
  3308. }
  3309. public void ApplyNextOwnerPermissions()
  3310. {
  3311. _baseMask &= _nextOwnerMask;
  3312. _ownerMask &= _nextOwnerMask;
  3313. _everyoneMask &= _nextOwnerMask;
  3314. Inventory.ApplyNextOwnerPermissions();
  3315. }
  3316. public bool CanBeDeleted()
  3317. {
  3318. return Inventory.CanBeDeleted();
  3319. }
  3320. }
  3321. }