SceneObjectPart.cs 133 KB

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