1
0

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