SceneObjectPart.cs 176 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859
  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.IO;
  31. using System.Reflection;
  32. using System.Runtime.Serialization;
  33. using System.Security.Permissions;
  34. using System.Xml;
  35. using System.Xml.Serialization;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes.Scripting;
  42. using OpenSim.Region.Framework.Scenes.Serialization;
  43. using OpenSim.Region.Physics.Manager;
  44. namespace OpenSim.Region.Framework.Scenes
  45. {
  46. #region Enumerations
  47. [Flags]
  48. public enum Changed : uint
  49. {
  50. INVENTORY = 1,
  51. COLOR = 2,
  52. SHAPE = 4,
  53. SCALE = 8,
  54. TEXTURE = 16,
  55. LINK = 32,
  56. ALLOWED_DROP = 64,
  57. OWNER = 128,
  58. REGION = 256,
  59. TELEPORT = 512,
  60. REGION_RESTART = 1024,
  61. MEDIA = 2048,
  62. ANIMATION = 16384
  63. }
  64. // I don't really know where to put this except here.
  65. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  66. [Flags]
  67. public enum ExtraParamType
  68. {
  69. Something1 = 1,
  70. Something2 = 2,
  71. Something3 = 4,
  72. Something4 = 8,
  73. Flexible = 16,
  74. Light = 32,
  75. Sculpt = 48,
  76. Something5 = 64,
  77. Something6 = 128
  78. }
  79. [Flags]
  80. public enum TextureAnimFlags : byte
  81. {
  82. NONE = 0x00,
  83. ANIM_ON = 0x01,
  84. LOOP = 0x02,
  85. REVERSE = 0x04,
  86. PING_PONG = 0x08,
  87. SMOOTH = 0x10,
  88. ROTATE = 0x20,
  89. SCALE = 0x40
  90. }
  91. public enum PrimType : int
  92. {
  93. BOX = 0,
  94. CYLINDER = 1,
  95. PRISM = 2,
  96. SPHERE = 3,
  97. TORUS = 4,
  98. TUBE = 5,
  99. RING = 6,
  100. SCULPT = 7
  101. }
  102. #endregion Enumerations
  103. public class SceneObjectPart : IScriptHost, ISceneEntity
  104. {
  105. /// <value>
  106. /// Denote all sides of the prim
  107. /// </value>
  108. public const int ALL_SIDES = -1;
  109. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  110. /// <value>
  111. /// Is this sop a root part?
  112. /// </value>
  113. public bool IsRoot
  114. {
  115. get { return ParentGroup.RootPart == this; }
  116. }
  117. #region Fields
  118. public bool AllowedDrop;
  119. public bool DIE_AT_EDGE;
  120. public bool RETURN_AT_EDGE;
  121. public bool BlockGrab;
  122. public bool StatusSandbox;
  123. public Vector3 StatusSandboxPos;
  124. [XmlIgnore]
  125. public int[] PayPrice = {-2,-2,-2,-2,-2};
  126. [XmlIgnore]
  127. public PhysicsActor PhysActor
  128. {
  129. get { return m_physActor; }
  130. set
  131. {
  132. // m_log.DebugFormat("[SOP]: PhysActor set to {0} for {1} {2}", value, Name, UUID);
  133. m_physActor = value;
  134. }
  135. }
  136. //Xantor 20080528 Sound stuff:
  137. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  138. // Not a big problem as long as the script that sets it remains in the prim on startup.
  139. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  140. public UUID Sound;
  141. public byte SoundFlags;
  142. public double SoundGain;
  143. public double SoundRadius;
  144. public uint TimeStampFull;
  145. public uint TimeStampLastActivity; // Will be used for AutoReturn
  146. public uint TimeStampTerse;
  147. public UUID FromItemID;
  148. public UUID FromFolderID;
  149. public int STATUS_ROTATE_X;
  150. public int STATUS_ROTATE_Y;
  151. public int STATUS_ROTATE_Z;
  152. private Dictionary<int, string> m_CollisionFilter = new Dictionary<int, string>();
  153. /// <value>
  154. /// The UUID of the user inventory item from which this object was rezzed if this is a root part.
  155. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item.
  156. /// </value>
  157. private UUID m_fromUserInventoryItemID;
  158. public UUID FromUserInventoryItemID
  159. {
  160. get { return m_fromUserInventoryItemID; }
  161. set { m_fromUserInventoryItemID = value; }
  162. }
  163. public scriptEvents AggregateScriptEvents;
  164. public Vector3 AttachedPos;
  165. public Vector3 RotationAxis = Vector3.One;
  166. public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this
  167. // Certainly this must be a persistant setting finally
  168. public bool IsWaitingForFirstSpinUpdatePacket;
  169. public Quaternion SpinOldOrientation = Quaternion.Identity;
  170. public Quaternion m_APIDTarget = Quaternion.Identity;
  171. public float m_APIDDamp = 0;
  172. public float m_APIDStrength = 0;
  173. /// <summary>
  174. /// This part's inventory
  175. /// </summary>
  176. public IEntityInventory Inventory
  177. {
  178. get { return m_inventory; }
  179. }
  180. protected SceneObjectPartInventory m_inventory;
  181. public bool Undoing;
  182. public bool IgnoreUndoUpdate = false;
  183. private PrimFlags LocalFlags;
  184. private float m_damage = -1.0f;
  185. private byte[] m_TextureAnimation;
  186. private byte m_clickAction;
  187. private Color m_color = Color.Black;
  188. private string m_description = String.Empty;
  189. private readonly List<uint> m_lastColliders = new List<uint>();
  190. private int m_linkNum;
  191. private int m_scriptAccessPin;
  192. private readonly Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  193. private string m_sitName = String.Empty;
  194. private Quaternion m_sitTargetOrientation = Quaternion.Identity;
  195. private Vector3 m_sitTargetPosition;
  196. private string m_sitAnimation = "SIT";
  197. private string m_text = String.Empty;
  198. private string m_touchName = String.Empty;
  199. private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5);
  200. private readonly Stack<UndoState> m_redo = new Stack<UndoState>(5);
  201. private UUID _creatorID;
  202. private bool m_passTouches;
  203. /// <summary>
  204. /// Only used internally to schedule client updates.
  205. /// 0 - no update is scheduled
  206. /// 1 - terse update scheduled
  207. /// 2 - full update scheduled
  208. ///
  209. /// TODO - This should be an enumeration
  210. /// </summary>
  211. private byte m_updateFlag;
  212. private PhysicsActor m_physActor;
  213. protected Vector3 m_acceleration;
  214. protected Vector3 m_angularVelocity;
  215. //unkown if this will be kept, added as a way of removing the group position from the group class
  216. protected Vector3 m_groupPosition;
  217. protected uint m_localId;
  218. protected Material m_material = OpenMetaverse.Material.Wood;
  219. protected string m_name;
  220. protected Vector3 m_offsetPosition;
  221. protected SceneObjectGroup m_parentGroup;
  222. protected byte[] m_particleSystem = Utils.EmptyBytes;
  223. protected ulong m_regionHandle;
  224. protected Quaternion m_rotationOffset = Quaternion.Identity;
  225. protected PrimitiveBaseShape m_shape;
  226. protected UUID m_uuid;
  227. protected Vector3 m_velocity;
  228. protected Vector3 m_lastPosition;
  229. protected Quaternion m_lastRotation;
  230. protected Vector3 m_lastVelocity;
  231. protected Vector3 m_lastAcceleration;
  232. protected Vector3 m_lastAngularVelocity;
  233. protected int m_lastTerseSent;
  234. /// <summary>
  235. /// Stores media texture data
  236. /// </summary>
  237. protected string m_mediaUrl;
  238. // TODO: Those have to be changed into persistent properties at some later point,
  239. // or sit-camera on vehicles will break on sim-crossing.
  240. private Vector3 m_cameraEyeOffset;
  241. private Vector3 m_cameraAtOffset;
  242. private bool m_forceMouselook;
  243. // TODO: Collision sound should have default.
  244. private UUID m_collisionSound;
  245. private float m_collisionSoundVolume;
  246. #endregion Fields
  247. // ~SceneObjectPart()
  248. // {
  249. // m_log.DebugFormat(
  250. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  251. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  252. // }
  253. #region Constructors
  254. /// <summary>
  255. /// No arg constructor called by region restore db code
  256. /// </summary>
  257. public SceneObjectPart()
  258. {
  259. // It's not necessary to persist this
  260. m_TextureAnimation = Utils.EmptyBytes;
  261. m_particleSystem = Utils.EmptyBytes;
  262. Rezzed = DateTime.UtcNow;
  263. m_inventory = new SceneObjectPartInventory(this);
  264. }
  265. /// <summary>
  266. /// Create a completely new SceneObjectPart (prim). This will need to be added separately to a SceneObjectGroup
  267. /// </summary>
  268. /// <param name="ownerID"></param>
  269. /// <param name="shape"></param>
  270. /// <param name="position"></param>
  271. /// <param name="rotationOffset"></param>
  272. /// <param name="offsetPosition"></param>
  273. public SceneObjectPart(
  274. UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
  275. Quaternion rotationOffset, Vector3 offsetPosition)
  276. {
  277. m_name = "Primitive";
  278. Rezzed = DateTime.UtcNow;
  279. _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
  280. _ownerID = ownerID;
  281. _creatorID = _ownerID;
  282. _lastOwnerID = UUID.Zero;
  283. UUID = UUID.Random();
  284. Shape = shape;
  285. // Todo: Add More Object Parameter from above!
  286. _ownershipCost = 0;
  287. _objectSaleType = 0;
  288. _salePrice = 0;
  289. _category = 0;
  290. _lastOwnerID = _creatorID;
  291. // End Todo: ///
  292. GroupPosition = groupPosition;
  293. OffsetPosition = offsetPosition;
  294. RotationOffset = rotationOffset;
  295. Velocity = Vector3.Zero;
  296. AngularVelocity = Vector3.Zero;
  297. Acceleration = Vector3.Zero;
  298. m_TextureAnimation = Utils.EmptyBytes;
  299. m_particleSystem = Utils.EmptyBytes;
  300. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  301. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  302. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  303. Flags = 0;
  304. CreateSelected = true;
  305. TrimPermissions();
  306. m_inventory = new SceneObjectPartInventory(this);
  307. }
  308. #endregion Constructors
  309. #region XML Schema
  310. private UUID _lastOwnerID;
  311. private UUID _ownerID;
  312. private UUID _groupID;
  313. private int _ownershipCost;
  314. private byte _objectSaleType;
  315. private int _salePrice;
  316. private uint _category;
  317. private Int32 _creationDate;
  318. private uint _parentID = 0;
  319. private UUID m_sitTargetAvatar = UUID.Zero;
  320. private uint _baseMask = (uint)PermissionMask.All;
  321. private uint _ownerMask = (uint)PermissionMask.All;
  322. private uint _groupMask = (uint)PermissionMask.None;
  323. private uint _everyoneMask = (uint)PermissionMask.None;
  324. private uint _nextOwnerMask = (uint)PermissionMask.All;
  325. private PrimFlags _flags = PrimFlags.None;
  326. private DateTime m_expires;
  327. private DateTime m_rezzed;
  328. private bool m_createSelected = false;
  329. private string m_creatorData = string.Empty;
  330. public UUID CreatorID
  331. {
  332. get
  333. {
  334. return _creatorID;
  335. }
  336. set
  337. {
  338. _creatorID = value;
  339. }
  340. }
  341. /// <summary>
  342. /// Data about the creator in the form profile_url;name
  343. /// </summary>
  344. public string CreatorData
  345. {
  346. get { return m_creatorData; }
  347. set { m_creatorData = value; }
  348. }
  349. /// <summary>
  350. /// Used by the DB layer to retrieve / store the entire user identification.
  351. /// The identification can either be a simple UUID or a string of the form
  352. /// uuid[;profile_url[;name]]
  353. /// </summary>
  354. public string CreatorIdentification
  355. {
  356. get
  357. {
  358. if (m_creatorData != null && m_creatorData != string.Empty)
  359. return _creatorID.ToString() + ';' + m_creatorData;
  360. else
  361. return _creatorID.ToString();
  362. }
  363. set
  364. {
  365. if ((value == null) || (value != null && value == string.Empty))
  366. {
  367. m_creatorData = string.Empty;
  368. return;
  369. }
  370. if (!value.Contains(";")) // plain UUID
  371. {
  372. UUID uuid = UUID.Zero;
  373. UUID.TryParse(value, out uuid);
  374. _creatorID = uuid;
  375. }
  376. else // <uuid>[;<endpoint>[;name]]
  377. {
  378. string name = "Unknown User";
  379. string[] parts = value.Split(';');
  380. if (parts.Length >= 1)
  381. {
  382. UUID uuid = UUID.Zero;
  383. UUID.TryParse(parts[0], out uuid);
  384. _creatorID = uuid;
  385. }
  386. if (parts.Length >= 2)
  387. m_creatorData = parts[1];
  388. if (parts.Length >= 3)
  389. name = parts[2];
  390. m_creatorData += ';' + name;
  391. }
  392. }
  393. }
  394. /// <summary>
  395. /// A relic from when we we thought that prims contained folder objects. In
  396. /// reality, prim == folder
  397. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  398. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  399. /// </summary>
  400. public UUID FolderID
  401. {
  402. get { return UUID; }
  403. set { } // Don't allow assignment, or legacy prims wil b0rk - but we need the setter for legacy serialization.
  404. }
  405. /// <value>
  406. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  407. /// </value>
  408. public uint InventorySerial
  409. {
  410. get { return m_inventory.Serial; }
  411. set { m_inventory.Serial = value; }
  412. }
  413. /// <value>
  414. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  415. /// </value>
  416. public TaskInventoryDictionary TaskInventory
  417. {
  418. get { return m_inventory.Items; }
  419. set { m_inventory.Items = value; }
  420. }
  421. /// <summary>
  422. /// This is idential to the Flags property, except that the returned value is uint rather than PrimFlags
  423. /// </summary>
  424. [Obsolete("Use Flags property instead")]
  425. public uint ObjectFlags
  426. {
  427. get { return (uint)Flags; }
  428. set { Flags = (PrimFlags)value; }
  429. }
  430. public UUID UUID
  431. {
  432. get { return m_uuid; }
  433. set
  434. {
  435. m_uuid = value;
  436. // This is necessary so that TaskInventoryItem parent ids correctly reference the new uuid of this part
  437. if (Inventory != null)
  438. Inventory.ResetObjectID();
  439. }
  440. }
  441. public uint LocalId
  442. {
  443. get { return m_localId; }
  444. set { m_localId = value; }
  445. }
  446. public virtual string Name
  447. {
  448. get { return m_name; }
  449. set
  450. {
  451. m_name = value;
  452. if (PhysActor != null)
  453. {
  454. PhysActor.SOPName = value;
  455. }
  456. }
  457. }
  458. public byte Material
  459. {
  460. get { return (byte) m_material; }
  461. set
  462. {
  463. m_material = (Material)value;
  464. if (PhysActor != null)
  465. {
  466. PhysActor.SetMaterial((int)value);
  467. }
  468. }
  469. }
  470. public bool PassTouches
  471. {
  472. get { return m_passTouches; }
  473. set
  474. {
  475. m_passTouches = value;
  476. if (ParentGroup != null)
  477. ParentGroup.HasGroupChanged = true;
  478. }
  479. }
  480. public Dictionary<int, string> CollisionFilter
  481. {
  482. get { return m_CollisionFilter; }
  483. set
  484. {
  485. m_CollisionFilter = value;
  486. }
  487. }
  488. public Quaternion APIDTarget
  489. {
  490. get { return m_APIDTarget; }
  491. set { m_APIDTarget = value; }
  492. }
  493. public float APIDDamp
  494. {
  495. get { return m_APIDDamp; }
  496. set { m_APIDDamp = value; }
  497. }
  498. public float APIDStrength
  499. {
  500. get { return m_APIDStrength; }
  501. set { m_APIDStrength = value; }
  502. }
  503. public ulong RegionHandle
  504. {
  505. get { return m_regionHandle; }
  506. set { m_regionHandle = value; }
  507. }
  508. public int ScriptAccessPin
  509. {
  510. get { return m_scriptAccessPin; }
  511. set { m_scriptAccessPin = (int)value; }
  512. }
  513. private SceneObjectPart m_PlaySoundMasterPrim = null;
  514. public SceneObjectPart PlaySoundMasterPrim
  515. {
  516. get { return m_PlaySoundMasterPrim; }
  517. set { m_PlaySoundMasterPrim = value; }
  518. }
  519. private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
  520. public List<SceneObjectPart> PlaySoundSlavePrims
  521. {
  522. get { return m_PlaySoundSlavePrims; }
  523. set { m_PlaySoundSlavePrims = value; }
  524. }
  525. private SceneObjectPart m_LoopSoundMasterPrim = null;
  526. public SceneObjectPart LoopSoundMasterPrim
  527. {
  528. get { return m_LoopSoundMasterPrim; }
  529. set { m_LoopSoundMasterPrim = value; }
  530. }
  531. private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
  532. public List<SceneObjectPart> LoopSoundSlavePrims
  533. {
  534. get { return m_LoopSoundSlavePrims; }
  535. set { m_LoopSoundSlavePrims = value; }
  536. }
  537. public Byte[] TextureAnimation
  538. {
  539. get { return m_TextureAnimation; }
  540. set { m_TextureAnimation = value; }
  541. }
  542. public Byte[] ParticleSystem
  543. {
  544. get { return m_particleSystem; }
  545. set { m_particleSystem = value; }
  546. }
  547. public DateTime Expires
  548. {
  549. get { return m_expires; }
  550. set { m_expires = value; }
  551. }
  552. public DateTime Rezzed
  553. {
  554. get { return m_rezzed; }
  555. set { m_rezzed = value; }
  556. }
  557. public float Damage
  558. {
  559. get { return m_damage; }
  560. set { m_damage = value; }
  561. }
  562. /// <summary>
  563. /// The position of the entire group that this prim belongs to.
  564. /// </summary>
  565. public Vector3 GroupPosition
  566. {
  567. get
  568. {
  569. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  570. PhysicsActor actor = PhysActor;
  571. if (actor != null && _parentID == 0)
  572. {
  573. m_groupPosition = actor.Position;
  574. }
  575. if (m_parentGroup.IsAttachment)
  576. {
  577. ScenePresence sp = m_parentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  578. if (sp != null)
  579. return sp.AbsolutePosition;
  580. }
  581. return m_groupPosition;
  582. }
  583. set
  584. {
  585. m_groupPosition = value;
  586. PhysicsActor actor = PhysActor;
  587. if (actor != null)
  588. {
  589. try
  590. {
  591. // Root prim actually goes at Position
  592. if (_parentID == 0)
  593. {
  594. actor.Position = value;
  595. }
  596. else
  597. {
  598. // To move the child prim in respect to the group position and rotation we have to calculate
  599. actor.Position = GetWorldPosition();
  600. actor.Orientation = GetWorldRotation();
  601. }
  602. // Tell the physics engines that this prim changed.
  603. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  604. }
  605. catch (Exception e)
  606. {
  607. m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
  608. }
  609. }
  610. // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
  611. if (m_sitTargetAvatar != UUID.Zero)
  612. {
  613. ScenePresence avatar;
  614. if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar))
  615. {
  616. avatar.ParentPosition = GetWorldPosition();
  617. }
  618. }
  619. }
  620. }
  621. public Vector3 OffsetPosition
  622. {
  623. get { return m_offsetPosition; }
  624. set
  625. {
  626. // StoreUndoState();
  627. m_offsetPosition = value;
  628. if (ParentGroup != null && !ParentGroup.IsDeleted)
  629. {
  630. PhysicsActor actor = PhysActor;
  631. if (_parentID != 0 && actor != null)
  632. {
  633. actor.Position = GetWorldPosition();
  634. actor.Orientation = GetWorldRotation();
  635. // Tell the physics engines that this prim changed.
  636. if (m_parentGroup.Scene != null)
  637. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  638. }
  639. }
  640. }
  641. }
  642. public Vector3 RelativePosition
  643. {
  644. get
  645. {
  646. if (IsRoot)
  647. {
  648. if (m_parentGroup.IsAttachment)
  649. return AttachedPos;
  650. else
  651. return AbsolutePosition;
  652. }
  653. else
  654. {
  655. return OffsetPosition;
  656. }
  657. }
  658. }
  659. public Quaternion RotationOffset
  660. {
  661. get
  662. {
  663. // We don't want the physics engine mucking up the rotations in a linkset
  664. PhysicsActor actor = PhysActor;
  665. if (_parentID == 0 && (Shape.PCode != 9 || Shape.State == 0) && actor != null)
  666. {
  667. if (actor.Orientation.X != 0f || actor.Orientation.Y != 0f
  668. || actor.Orientation.Z != 0f || actor.Orientation.W != 0f)
  669. {
  670. m_rotationOffset = actor.Orientation;
  671. }
  672. }
  673. return m_rotationOffset;
  674. }
  675. set
  676. {
  677. StoreUndoState();
  678. m_rotationOffset = value;
  679. PhysicsActor actor = PhysActor;
  680. if (actor != null)
  681. {
  682. try
  683. {
  684. // Root prim gets value directly
  685. if (_parentID == 0)
  686. {
  687. actor.Orientation = value;
  688. //m_log.Info("[PART]: RO1:" + actor.Orientation.ToString());
  689. }
  690. else
  691. {
  692. // Child prim we have to calculate it's world rotationwel
  693. Quaternion resultingrotation = GetWorldRotation();
  694. actor.Orientation = resultingrotation;
  695. //m_log.Info("[PART]: RO2:" + actor.Orientation.ToString());
  696. }
  697. if (m_parentGroup != null)
  698. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  699. //}
  700. }
  701. catch (Exception ex)
  702. {
  703. m_log.Error("[SCENEOBJECTPART]: ROTATIONOFFSET" + ex.Message);
  704. }
  705. }
  706. }
  707. }
  708. /// <summary></summary>
  709. public Vector3 Velocity
  710. {
  711. get
  712. {
  713. PhysicsActor actor = PhysActor;
  714. if (actor != null)
  715. {
  716. if (actor.IsPhysical)
  717. {
  718. m_velocity = actor.Velocity;
  719. }
  720. }
  721. return m_velocity;
  722. }
  723. set
  724. {
  725. m_velocity = value;
  726. PhysicsActor actor = PhysActor;
  727. if (actor != null)
  728. {
  729. if (actor.IsPhysical)
  730. {
  731. actor.Velocity = value;
  732. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  733. }
  734. }
  735. }
  736. }
  737. /// <summary></summary>
  738. public Vector3 AngularVelocity
  739. {
  740. get
  741. {
  742. PhysicsActor actor = PhysActor;
  743. if ((actor != null) && actor.IsPhysical)
  744. {
  745. m_angularVelocity = actor.RotationalVelocity;
  746. }
  747. return m_angularVelocity;
  748. }
  749. set { m_angularVelocity = value; }
  750. }
  751. /// <summary></summary>
  752. public Vector3 Acceleration
  753. {
  754. get { return m_acceleration; }
  755. set { m_acceleration = value; }
  756. }
  757. public string Description
  758. {
  759. get { return m_description; }
  760. set
  761. {
  762. m_description = value;
  763. PhysicsActor actor = PhysActor;
  764. if (actor != null)
  765. {
  766. actor.SOPDescription = value;
  767. }
  768. }
  769. }
  770. /// <value>
  771. /// Text color.
  772. /// </value>
  773. public Color Color
  774. {
  775. get { return m_color; }
  776. set
  777. {
  778. m_color = value;
  779. /* ScheduleFullUpdate() need not be called b/c after
  780. * setting the color, the text will be set, so then
  781. * ScheduleFullUpdate() will be called. */
  782. //ScheduleFullUpdate();
  783. }
  784. }
  785. public string Text
  786. {
  787. get
  788. {
  789. string returnstr = m_text;
  790. if (returnstr.Length > 255)
  791. {
  792. returnstr = returnstr.Substring(0, 254);
  793. }
  794. return returnstr;
  795. }
  796. set
  797. {
  798. m_text = value;
  799. }
  800. }
  801. public string SitName
  802. {
  803. get { return m_sitName; }
  804. set { m_sitName = value; }
  805. }
  806. public string TouchName
  807. {
  808. get { return m_touchName; }
  809. set { m_touchName = value; }
  810. }
  811. public int LinkNum
  812. {
  813. get { return m_linkNum; }
  814. set { m_linkNum = value; }
  815. }
  816. public byte ClickAction
  817. {
  818. get { return m_clickAction; }
  819. set
  820. {
  821. m_clickAction = value;
  822. }
  823. }
  824. public PrimitiveBaseShape Shape
  825. {
  826. get { return m_shape; }
  827. set { m_shape = value; }
  828. }
  829. /// <summary>
  830. /// Change the scale of this part.
  831. /// </summary>
  832. public Vector3 Scale
  833. {
  834. get { return m_shape.Scale; }
  835. set
  836. {
  837. if (m_shape != null)
  838. {
  839. StoreUndoState();
  840. m_shape.Scale = value;
  841. PhysicsActor actor = PhysActor;
  842. if (actor != null)
  843. {
  844. if (m_parentGroup.Scene != null)
  845. {
  846. if (m_parentGroup.Scene.PhysicsScene != null)
  847. {
  848. actor.Size = m_shape.Scale;
  849. if (Shape.SculptEntry)
  850. CheckSculptAndLoad();
  851. else
  852. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  853. }
  854. }
  855. }
  856. }
  857. TriggerScriptChangedEvent(Changed.SCALE);
  858. }
  859. }
  860. public byte UpdateFlag
  861. {
  862. get { return m_updateFlag; }
  863. set { m_updateFlag = value; }
  864. }
  865. /// <summary>
  866. /// Used for media on a prim.
  867. /// </summary>
  868. /// Do not change this value directly - always do it through an IMoapModule.
  869. public string MediaUrl
  870. {
  871. get
  872. {
  873. return m_mediaUrl;
  874. }
  875. set
  876. {
  877. m_mediaUrl = value;
  878. if (ParentGroup != null)
  879. ParentGroup.HasGroupChanged = true;
  880. }
  881. }
  882. public bool CreateSelected
  883. {
  884. get { return m_createSelected; }
  885. set
  886. {
  887. // m_log.DebugFormat("[SOP]: Setting CreateSelected to {0} for {1} {2}", value, Name, UUID);
  888. m_createSelected = value;
  889. }
  890. }
  891. #endregion
  892. //---------------
  893. #region Public Properties with only Get
  894. public Vector3 AbsolutePosition
  895. {
  896. get
  897. {
  898. if (m_parentGroup.IsAttachment)
  899. return GroupPosition;
  900. return m_offsetPosition + m_groupPosition;
  901. }
  902. }
  903. public SceneObjectGroup ParentGroup
  904. {
  905. get { return m_parentGroup; }
  906. }
  907. public scriptEvents ScriptEvents
  908. {
  909. get { return AggregateScriptEvents; }
  910. }
  911. public Quaternion SitTargetOrientation
  912. {
  913. get { return m_sitTargetOrientation; }
  914. set { m_sitTargetOrientation = value; }
  915. }
  916. public Vector3 SitTargetPosition
  917. {
  918. get { return m_sitTargetPosition; }
  919. set { m_sitTargetPosition = value; }
  920. }
  921. // This sort of sucks, but I'm adding these in to make some of
  922. // the mappings more consistant.
  923. public Vector3 SitTargetPositionLL
  924. {
  925. get { return new Vector3(m_sitTargetPosition.X, m_sitTargetPosition.Y,m_sitTargetPosition.Z); }
  926. set { m_sitTargetPosition = value; }
  927. }
  928. public Quaternion SitTargetOrientationLL
  929. {
  930. get
  931. {
  932. return new Quaternion(
  933. m_sitTargetOrientation.X,
  934. m_sitTargetOrientation.Y,
  935. m_sitTargetOrientation.Z,
  936. m_sitTargetOrientation.W
  937. );
  938. }
  939. set { m_sitTargetOrientation = new Quaternion(value.X, value.Y, value.Z, value.W); }
  940. }
  941. public bool Stopped
  942. {
  943. get {
  944. double threshold = 0.02;
  945. return (Math.Abs(Velocity.X) < threshold &&
  946. Math.Abs(Velocity.Y) < threshold &&
  947. Math.Abs(Velocity.Z) < threshold &&
  948. Math.Abs(AngularVelocity.X) < threshold &&
  949. Math.Abs(AngularVelocity.Y) < threshold &&
  950. Math.Abs(AngularVelocity.Z) < threshold);
  951. }
  952. }
  953. public uint ParentID
  954. {
  955. get { return _parentID; }
  956. set { _parentID = value; }
  957. }
  958. public int CreationDate
  959. {
  960. get { return _creationDate; }
  961. set { _creationDate = value; }
  962. }
  963. public uint Category
  964. {
  965. get { return _category; }
  966. set { _category = value; }
  967. }
  968. public int SalePrice
  969. {
  970. get { return _salePrice; }
  971. set { _salePrice = value; }
  972. }
  973. public byte ObjectSaleType
  974. {
  975. get { return _objectSaleType; }
  976. set { _objectSaleType = value; }
  977. }
  978. public int OwnershipCost
  979. {
  980. get { return _ownershipCost; }
  981. set { _ownershipCost = value; }
  982. }
  983. public UUID GroupID
  984. {
  985. get { return _groupID; }
  986. set { _groupID = value; }
  987. }
  988. public UUID OwnerID
  989. {
  990. get { return _ownerID; }
  991. set { _ownerID = value; }
  992. }
  993. public UUID LastOwnerID
  994. {
  995. get { return _lastOwnerID; }
  996. set { _lastOwnerID = value; }
  997. }
  998. public uint BaseMask
  999. {
  1000. get { return _baseMask; }
  1001. set { _baseMask = value; }
  1002. }
  1003. public uint OwnerMask
  1004. {
  1005. get { return _ownerMask; }
  1006. set { _ownerMask = value; }
  1007. }
  1008. public uint GroupMask
  1009. {
  1010. get { return _groupMask; }
  1011. set { _groupMask = value; }
  1012. }
  1013. public uint EveryoneMask
  1014. {
  1015. get { return _everyoneMask; }
  1016. set { _everyoneMask = value; }
  1017. }
  1018. public uint NextOwnerMask
  1019. {
  1020. get { return _nextOwnerMask; }
  1021. set { _nextOwnerMask = value; }
  1022. }
  1023. /// <summary>
  1024. /// Property flags. See OpenMetaverse.PrimFlags
  1025. /// </summary>
  1026. /// <remarks>
  1027. /// Example properties are PrimFlags.Phantom and PrimFlags.DieAtEdge
  1028. /// </remarks>
  1029. public PrimFlags Flags
  1030. {
  1031. get { return _flags; }
  1032. set
  1033. {
  1034. // m_log.DebugFormat("[SOP]: Setting flags for {0} {1} to {2}", UUID, Name, value);
  1035. _flags = value;
  1036. }
  1037. }
  1038. public UUID SitTargetAvatar
  1039. {
  1040. get { return m_sitTargetAvatar; }
  1041. set { m_sitTargetAvatar = value; }
  1042. }
  1043. public virtual UUID RegionID
  1044. {
  1045. get
  1046. {
  1047. if (ParentGroup.Scene != null)
  1048. return ParentGroup.Scene.RegionInfo.RegionID;
  1049. else
  1050. return UUID.Zero;
  1051. }
  1052. set {} // read only
  1053. }
  1054. private UUID _parentUUID = UUID.Zero;
  1055. public UUID ParentUUID
  1056. {
  1057. get
  1058. {
  1059. if (ParentGroup != null)
  1060. _parentUUID = ParentGroup.UUID;
  1061. return _parentUUID;
  1062. }
  1063. set { _parentUUID = value; }
  1064. }
  1065. public string SitAnimation
  1066. {
  1067. get { return m_sitAnimation; }
  1068. set { m_sitAnimation = value; }
  1069. }
  1070. public UUID CollisionSound
  1071. {
  1072. get { return m_collisionSound; }
  1073. set
  1074. {
  1075. m_collisionSound = value;
  1076. aggregateScriptEvents();
  1077. }
  1078. }
  1079. public float CollisionSoundVolume
  1080. {
  1081. get { return m_collisionSoundVolume; }
  1082. set { m_collisionSoundVolume = value; }
  1083. }
  1084. #endregion Public Properties with only Get
  1085. #region Private Methods
  1086. private uint ApplyMask(uint val, bool set, uint mask)
  1087. {
  1088. if (set)
  1089. {
  1090. return val |= mask;
  1091. }
  1092. else
  1093. {
  1094. return val &= ~mask;
  1095. }
  1096. }
  1097. /// <summary>
  1098. /// Clear all pending updates of parts to clients
  1099. /// </summary>
  1100. private void ClearUpdateSchedule()
  1101. {
  1102. m_updateFlag = 0;
  1103. }
  1104. private void SendObjectPropertiesToClient(UUID AgentID)
  1105. {
  1106. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1107. {
  1108. // Ugly reference :(
  1109. if (avatar.UUID == AgentID)
  1110. {
  1111. m_parentGroup.GetProperties(avatar.ControllingClient);
  1112. }
  1113. });
  1114. }
  1115. // TODO: unused:
  1116. // private void handleTimerAccounting(uint localID, double interval)
  1117. // {
  1118. // if (localID == LocalId)
  1119. // {
  1120. // float sec = (float)interval;
  1121. // if (m_parentGroup != null)
  1122. // {
  1123. // if (sec == 0)
  1124. // {
  1125. // if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  1126. // m_parentGroup.scriptScore = 0;
  1127. //
  1128. // m_parentGroup.scriptScore += 0.001f;
  1129. // return;
  1130. // }
  1131. //
  1132. // if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  1133. // m_parentGroup.scriptScore = 0;
  1134. // m_parentGroup.scriptScore += (0.001f / sec);
  1135. // }
  1136. // }
  1137. // }
  1138. #endregion Private Methods
  1139. #region Public Methods
  1140. public void ResetExpire()
  1141. {
  1142. Expires = DateTime.Now + new TimeSpan(600000000);
  1143. }
  1144. public void AddFlag(PrimFlags flag)
  1145. {
  1146. // PrimFlags prevflag = Flags;
  1147. if ((Flags & flag) == 0)
  1148. {
  1149. //m_log.Debug("Adding flag: " + ((PrimFlags) flag).ToString());
  1150. Flags |= flag;
  1151. if (flag == PrimFlags.TemporaryOnRez)
  1152. ResetExpire();
  1153. }
  1154. // m_log.Debug("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1155. }
  1156. /// <summary>
  1157. /// Tell all scene presences that they should send updates for this part to their clients
  1158. /// </summary>
  1159. public void AddFullUpdateToAllAvatars()
  1160. {
  1161. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1162. {
  1163. AddFullUpdateToAvatar(avatar);
  1164. });
  1165. }
  1166. /// <summary>
  1167. /// Tell the scene presence that it should send updates for this part to its client
  1168. /// </summary>
  1169. public void AddFullUpdateToAvatar(ScenePresence presence)
  1170. {
  1171. presence.SceneViewer.QueuePartForUpdate(this);
  1172. }
  1173. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1174. {
  1175. m_particleSystem = pSystem.GetBytes();
  1176. }
  1177. public void RemoveParticleSystem()
  1178. {
  1179. m_particleSystem = new byte[0];
  1180. }
  1181. /// Terse updates
  1182. public void AddTerseUpdateToAllAvatars()
  1183. {
  1184. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1185. {
  1186. AddTerseUpdateToAvatar(avatar);
  1187. });
  1188. }
  1189. public void AddTerseUpdateToAvatar(ScenePresence presence)
  1190. {
  1191. presence.SceneViewer.QueuePartForUpdate(this);
  1192. }
  1193. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1194. {
  1195. byte[] data = new byte[16];
  1196. int pos = 0;
  1197. // The flags don't like conversion from uint to byte, so we have to do
  1198. // it the crappy way. See the above function :(
  1199. data[pos] = ConvertScriptUintToByte((uint)pTexAnim.Flags); pos++;
  1200. data[pos] = (byte)pTexAnim.Face; pos++;
  1201. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1202. data[pos] = (byte)pTexAnim.SizeY; pos++;
  1203. Utils.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1204. Utils.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4);
  1205. Utils.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1206. m_TextureAnimation = data;
  1207. }
  1208. public void AdjustSoundGain(double volume)
  1209. {
  1210. if (volume > 1)
  1211. volume = 1;
  1212. if (volume < 0)
  1213. volume = 0;
  1214. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
  1215. {
  1216. if (!sp.IsChildAgent)
  1217. sp.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
  1218. });
  1219. }
  1220. /// <summary>
  1221. /// hook to the physics scene to apply impulse
  1222. /// This is sent up to the group, which then finds the root prim
  1223. /// and applies the force on the root prim of the group
  1224. /// </summary>
  1225. /// <param name="impulsei">Vector force</param>
  1226. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1227. public void ApplyImpulse(Vector3 impulsei, bool localGlobalTF)
  1228. {
  1229. Vector3 impulse = impulsei;
  1230. if (localGlobalTF)
  1231. {
  1232. Quaternion grot = GetWorldRotation();
  1233. Quaternion AXgrot = grot;
  1234. Vector3 AXimpulsei = impulsei;
  1235. Vector3 newimpulse = AXimpulsei * AXgrot;
  1236. impulse = newimpulse;
  1237. }
  1238. if (m_parentGroup != null)
  1239. {
  1240. m_parentGroup.applyImpulse(impulse);
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// hook to the physics scene to apply angular impulse
  1245. /// This is sent up to the group, which then finds the root prim
  1246. /// and applies the force on the root prim of the group
  1247. /// </summary>
  1248. /// <param name="impulsei">Vector force</param>
  1249. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1250. public void ApplyAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1251. {
  1252. Vector3 impulse = impulsei;
  1253. if (localGlobalTF)
  1254. {
  1255. Quaternion grot = GetWorldRotation();
  1256. Quaternion AXgrot = grot;
  1257. Vector3 AXimpulsei = impulsei;
  1258. Vector3 newimpulse = AXimpulsei * AXgrot;
  1259. impulse = newimpulse;
  1260. }
  1261. m_parentGroup.applyAngularImpulse(impulse);
  1262. }
  1263. /// <summary>
  1264. /// hook to the physics scene to apply angular impulse
  1265. /// This is sent up to the group, which then finds the root prim
  1266. /// and applies the force on the root prim of the group
  1267. /// </summary>
  1268. /// <param name="impulsei">Vector force</param>
  1269. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1270. public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1271. {
  1272. Vector3 impulse = impulsei;
  1273. if (localGlobalTF)
  1274. {
  1275. Quaternion grot = GetWorldRotation();
  1276. Quaternion AXgrot = grot;
  1277. Vector3 AXimpulsei = impulsei;
  1278. Vector3 newimpulse = AXimpulsei * AXgrot;
  1279. impulse = newimpulse;
  1280. }
  1281. m_parentGroup.setAngularImpulse(impulse);
  1282. }
  1283. /// <summary>
  1284. /// Apply physics to this part.
  1285. /// </summary>
  1286. /// <param name="rootObjectFlags"></param>
  1287. /// <param name="m_physicalPrim"></param>
  1288. public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool m_physicalPrim)
  1289. {
  1290. // m_log.DebugFormat("[SCENE OBJECT PART]: Applying physics to {0} {1} {2}", Name, LocalId, UUID);
  1291. bool isPhysical = (((rootObjectFlags & (uint) PrimFlags.Physics) != 0) && m_physicalPrim);
  1292. bool isPhantom = ((rootObjectFlags & (uint) PrimFlags.Phantom) != 0);
  1293. if (IsJoint())
  1294. {
  1295. DoPhysicsPropertyUpdate(isPhysical, true);
  1296. }
  1297. else
  1298. {
  1299. // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
  1300. if (VolumeDetectActive)
  1301. isPhantom = false;
  1302. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  1303. bool RigidBody = isPhysical && !isPhantom;
  1304. // 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
  1305. // or flexible
  1306. if (!isPhantom && !m_parentGroup.IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible))
  1307. {
  1308. try
  1309. {
  1310. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1311. string.Format("{0}/{1}", Name, UUID),
  1312. Shape,
  1313. AbsolutePosition,
  1314. Scale,
  1315. RotationOffset,
  1316. RigidBody,
  1317. m_localId);
  1318. }
  1319. catch
  1320. {
  1321. m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid);
  1322. PhysActor = null;
  1323. }
  1324. // Basic Physics returns null.. joy joy joy.
  1325. if (PhysActor != null)
  1326. {
  1327. PhysActor.SOPName = this.Name; // save object name and desc into the PhysActor so ODE internals know the joint/body info
  1328. PhysActor.SOPDescription = this.Description;
  1329. PhysActor.SetMaterial(Material);
  1330. DoPhysicsPropertyUpdate(RigidBody, true);
  1331. PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
  1332. }
  1333. else
  1334. {
  1335. m_log.DebugFormat("[SOP]: physics actor is null for {0} with parent {1}", UUID, this.ParentGroup.UUID);
  1336. }
  1337. }
  1338. }
  1339. }
  1340. public byte ConvertScriptUintToByte(uint indata)
  1341. {
  1342. byte outdata = (byte)TextureAnimFlags.NONE;
  1343. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1344. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1345. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1346. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1347. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1348. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1349. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1350. return outdata;
  1351. }
  1352. /// <summary>
  1353. /// Duplicates this part.
  1354. /// </summary>
  1355. /// <param name="localID"></param>
  1356. /// <param name="AgentID"></param>
  1357. /// <param name="GroupID"></param>
  1358. /// <param name="linkNum"></param>
  1359. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  1360. /// <returns></returns>
  1361. public SceneObjectPart Copy(uint localID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
  1362. {
  1363. SceneObjectPart dupe = (SceneObjectPart)MemberwiseClone();
  1364. dupe.m_shape = m_shape.Copy();
  1365. dupe.m_regionHandle = m_regionHandle;
  1366. if (userExposed)
  1367. dupe.UUID = UUID.Random();
  1368. //memberwiseclone means it also clones the physics actor reference
  1369. // This will make physical prim 'bounce' if not set to null.
  1370. if (!userExposed)
  1371. dupe.PhysActor = null;
  1372. dupe._ownerID = AgentID;
  1373. dupe._groupID = GroupID;
  1374. dupe.GroupPosition = GroupPosition;
  1375. dupe.OffsetPosition = OffsetPosition;
  1376. dupe.RotationOffset = RotationOffset;
  1377. dupe.Velocity = new Vector3(0, 0, 0);
  1378. dupe.Acceleration = new Vector3(0, 0, 0);
  1379. dupe.AngularVelocity = new Vector3(0, 0, 0);
  1380. dupe.Flags = Flags;
  1381. dupe._ownershipCost = _ownershipCost;
  1382. dupe._objectSaleType = _objectSaleType;
  1383. dupe._salePrice = _salePrice;
  1384. dupe._category = _category;
  1385. dupe.m_rezzed = m_rezzed;
  1386. dupe.m_inventory = new SceneObjectPartInventory(dupe);
  1387. dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
  1388. if (userExposed)
  1389. {
  1390. dupe.ResetIDs(linkNum);
  1391. dupe.m_inventory.HasInventoryChanged = true;
  1392. }
  1393. else
  1394. {
  1395. dupe.m_inventory.HasInventoryChanged = m_inventory.HasInventoryChanged;
  1396. }
  1397. // Move afterwards ResetIDs as it clears the localID
  1398. dupe.LocalId = localID;
  1399. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1400. dupe._lastOwnerID = OwnerID;
  1401. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1402. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1403. dupe.Shape.ExtraParams = extraP;
  1404. if (userExposed)
  1405. {
  1406. if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero)
  1407. {
  1408. ParentGroup.Scene.AssetService.Get(
  1409. dupe.m_shape.SculptTexture.ToString(), dupe, dupe.AssetReceived);
  1410. }
  1411. bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
  1412. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1413. }
  1414. ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
  1415. // m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
  1416. return dupe;
  1417. }
  1418. /// <summary>
  1419. /// Called back by asynchronous asset fetch.
  1420. /// </summary>
  1421. /// <param name="id">ID of asset received</param>
  1422. /// <param name="sender">Register</param>
  1423. /// <param name="asset"></param>
  1424. protected void AssetReceived(string id, Object sender, AssetBase asset)
  1425. {
  1426. if (asset != null)
  1427. SculptTextureCallback(asset);
  1428. else
  1429. m_log.WarnFormat(
  1430. "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
  1431. Name, LocalId, id);
  1432. }
  1433. public static SceneObjectPart Create()
  1434. {
  1435. SceneObjectPart part = new SceneObjectPart();
  1436. part.UUID = UUID.Random();
  1437. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  1438. part.Shape = shape;
  1439. part.Name = "Primitive";
  1440. part._ownerID = UUID.Random();
  1441. return part;
  1442. }
  1443. /// <summary>
  1444. /// Do a physics property update for a NINJA joint.
  1445. /// </summary>
  1446. /// <param name="UsePhysics"></param>
  1447. /// <param name="isNew"></param>
  1448. protected void DoPhysicsPropertyUpdateForNinjaJoint(bool UsePhysics, bool isNew)
  1449. {
  1450. if (UsePhysics)
  1451. {
  1452. // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
  1453. // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.
  1454. PhysicsJointType jointType;
  1455. if (IsHingeJoint())
  1456. {
  1457. jointType = PhysicsJointType.Hinge;
  1458. }
  1459. else if (IsBallJoint())
  1460. {
  1461. jointType = PhysicsJointType.Ball;
  1462. }
  1463. else
  1464. {
  1465. jointType = PhysicsJointType.Ball;
  1466. }
  1467. List<string> bodyNames = new List<string>();
  1468. string RawParams = Description;
  1469. string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
  1470. string trackedBodyName = null;
  1471. if (jointParams.Length >= 2)
  1472. {
  1473. for (int iBodyName = 0; iBodyName < 2; iBodyName++)
  1474. {
  1475. string bodyName = jointParams[iBodyName];
  1476. bodyNames.Add(bodyName);
  1477. if (bodyName != "NULL")
  1478. {
  1479. if (trackedBodyName == null)
  1480. {
  1481. trackedBodyName = bodyName;
  1482. }
  1483. }
  1484. }
  1485. }
  1486. SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
  1487. Quaternion localRotation = Quaternion.Identity;
  1488. if (trackedBody != null)
  1489. {
  1490. localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
  1491. }
  1492. else
  1493. {
  1494. // error, output it below
  1495. }
  1496. PhysicsJoint joint;
  1497. joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
  1498. AbsolutePosition,
  1499. this.RotationOffset,
  1500. Description,
  1501. bodyNames,
  1502. trackedBodyName,
  1503. localRotation);
  1504. if (trackedBody == null)
  1505. {
  1506. ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
  1507. }
  1508. }
  1509. else
  1510. {
  1511. if (isNew)
  1512. {
  1513. // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
  1514. // delete, and if we try to delete it, due to asynchronous processing, the deletion request
  1515. // will get processed later at an indeterminate time, which could cancel a later-arriving
  1516. // joint creation request.
  1517. }
  1518. else
  1519. {
  1520. // here we turn off the joint object, so remove the joint from the physics scene
  1521. m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?
  1522. // make sure client isn't interpolating the joint proxy object
  1523. Velocity = Vector3.Zero;
  1524. AngularVelocity = Vector3.Zero;
  1525. Acceleration = Vector3.Zero;
  1526. }
  1527. }
  1528. }
  1529. /// <summary>
  1530. /// Do a physics propery update for this part.
  1531. /// </summary>
  1532. /// <param name="UsePhysics"></param>
  1533. /// <param name="isNew"></param>
  1534. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1535. {
  1536. if (IsJoint())
  1537. {
  1538. DoPhysicsPropertyUpdateForNinjaJoint(UsePhysics, isNew);
  1539. }
  1540. else
  1541. {
  1542. if (PhysActor != null)
  1543. {
  1544. if (UsePhysics != PhysActor.IsPhysical || isNew)
  1545. {
  1546. if (PhysActor.IsPhysical) // implies UsePhysics==false for this block
  1547. {
  1548. if (!isNew)
  1549. ParentGroup.Scene.RemovePhysicalPrim(1);
  1550. PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1551. PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
  1552. PhysActor.delink();
  1553. if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew))
  1554. {
  1555. // destroy all joints connected to this now deactivated body
  1556. m_parentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
  1557. }
  1558. // stop client-side interpolation of all joint proxy objects that have just been deleted
  1559. // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback,
  1560. // which stops client-side interpolation of deactivated joint proxy objects.
  1561. }
  1562. if (!UsePhysics && !isNew)
  1563. {
  1564. // reset velocity to 0 on physics switch-off. Without that, the client thinks the
  1565. // prim still has velocity and continues to interpolate its position along the old
  1566. // velocity-vector.
  1567. Velocity = new Vector3(0, 0, 0);
  1568. Acceleration = new Vector3(0, 0, 0);
  1569. AngularVelocity = new Vector3(0, 0, 0);
  1570. //RotationalVelocity = new Vector3(0, 0, 0);
  1571. }
  1572. PhysActor.IsPhysical = UsePhysics;
  1573. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1574. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1575. /// that's not wholesome. Had to make Scene public
  1576. //PhysActor = null;
  1577. if ((Flags & PrimFlags.Phantom) == 0)
  1578. {
  1579. if (UsePhysics)
  1580. {
  1581. ParentGroup.Scene.AddPhysicalPrim(1);
  1582. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1583. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  1584. if (_parentID != 0 && _parentID != LocalId)
  1585. {
  1586. if (ParentGroup.RootPart.PhysActor != null)
  1587. {
  1588. PhysActor.link(ParentGroup.RootPart.PhysActor);
  1589. }
  1590. }
  1591. }
  1592. }
  1593. }
  1594. // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
  1595. // mesh data.
  1596. if (Shape.SculptEntry)
  1597. CheckSculptAndLoad();
  1598. else
  1599. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1600. }
  1601. }
  1602. }
  1603. /// <summary>
  1604. /// Restore this part from the serialized xml representation.
  1605. /// </summary>
  1606. /// <param name="xmlReader"></param>
  1607. /// <returns></returns>
  1608. public static SceneObjectPart FromXml(XmlTextReader xmlReader)
  1609. {
  1610. SceneObjectPart part = SceneObjectSerializer.Xml2ToSOP(xmlReader);
  1611. // for tempOnRez objects, we have to fix the Expire date.
  1612. if ((part.Flags & PrimFlags.TemporaryOnRez) != 0)
  1613. part.ResetExpire();
  1614. return part;
  1615. }
  1616. public UUID GetAvatarOnSitTarget()
  1617. {
  1618. return m_sitTargetAvatar;
  1619. }
  1620. public bool GetDieAtEdge()
  1621. {
  1622. if (m_parentGroup.IsDeleted)
  1623. return false;
  1624. return m_parentGroup.RootPart.DIE_AT_EDGE;
  1625. }
  1626. public bool GetReturnAtEdge()
  1627. {
  1628. if (m_parentGroup.IsDeleted)
  1629. return false;
  1630. return m_parentGroup.RootPart.RETURN_AT_EDGE;
  1631. }
  1632. public void SetReturnAtEdge(bool p)
  1633. {
  1634. if (m_parentGroup.IsDeleted)
  1635. return;
  1636. m_parentGroup.RootPart.RETURN_AT_EDGE = p;
  1637. }
  1638. public bool GetBlockGrab()
  1639. {
  1640. if (m_parentGroup.IsDeleted)
  1641. return false;
  1642. return m_parentGroup.RootPart.BlockGrab;
  1643. }
  1644. public void SetBlockGrab(bool p)
  1645. {
  1646. if (m_parentGroup.IsDeleted)
  1647. return;
  1648. m_parentGroup.RootPart.BlockGrab = p;
  1649. }
  1650. public void SetStatusSandbox(bool p)
  1651. {
  1652. if (m_parentGroup.IsDeleted)
  1653. return;
  1654. StatusSandboxPos = m_parentGroup.RootPart.AbsolutePosition;
  1655. m_parentGroup.RootPart.StatusSandbox = p;
  1656. }
  1657. public bool GetStatusSandbox()
  1658. {
  1659. if (m_parentGroup.IsDeleted)
  1660. return false;
  1661. return m_parentGroup.RootPart.StatusSandbox;
  1662. }
  1663. public int GetAxisRotation(int axis)
  1664. {
  1665. //Cannot use ScriptBaseClass constants as no referance to it currently.
  1666. if (axis == 2)//STATUS_ROTATE_X
  1667. return STATUS_ROTATE_X;
  1668. if (axis == 4)//STATUS_ROTATE_Y
  1669. return STATUS_ROTATE_Y;
  1670. if (axis == 8)//STATUS_ROTATE_Z
  1671. return STATUS_ROTATE_Z;
  1672. return 0;
  1673. }
  1674. public double GetDistanceTo(Vector3 a, Vector3 b)
  1675. {
  1676. float dx = a.X - b.X;
  1677. float dy = a.Y - b.Y;
  1678. float dz = a.Z - b.Z;
  1679. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  1680. }
  1681. public uint GetEffectiveObjectFlags()
  1682. {
  1683. // Commenting this section of code out since it doesn't actually do anything, as enums are handled by
  1684. // value rather than reference
  1685. // PrimFlags f = _flags;
  1686. // if (m_parentGroup == null || m_parentGroup.RootPart == this)
  1687. // f &= ~(PrimFlags.Touch | PrimFlags.Money);
  1688. return (uint)Flags | (uint)LocalFlags;
  1689. }
  1690. public Vector3 GetGeometricCenter()
  1691. {
  1692. if (PhysActor != null)
  1693. return new Vector3(PhysActor.CenterOfMass.X, PhysActor.CenterOfMass.Y, PhysActor.CenterOfMass.Z);
  1694. else
  1695. return new Vector3(0, 0, 0);
  1696. }
  1697. public float GetMass()
  1698. {
  1699. if (PhysActor != null)
  1700. return PhysActor.Mass;
  1701. else
  1702. return 0;
  1703. }
  1704. public Vector3 GetForce()
  1705. {
  1706. if (PhysActor != null)
  1707. return PhysActor.Force;
  1708. else
  1709. return Vector3.Zero;
  1710. }
  1711. public void GetProperties(IClientAPI client)
  1712. {
  1713. client.SendObjectPropertiesReply(this);
  1714. }
  1715. /// <summary>
  1716. /// Method for a prim to get it's world position from the group.
  1717. /// </summary>
  1718. /// <remarks>
  1719. /// Remember, the Group Position simply gives the position of the group itself
  1720. /// </remarks>
  1721. /// <returns>A Linked Child Prim objects position in world</returns>
  1722. public Vector3 GetWorldPosition()
  1723. {
  1724. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1725. Vector3 axPos = OffsetPosition;
  1726. axPos *= parentRot;
  1727. Vector3 translationOffsetPosition = axPos;
  1728. // m_log.DebugFormat("[SCENE OBJECT PART]: Found group pos {0} for part {1}", GroupPosition, Name);
  1729. Vector3 worldPos = GroupPosition + translationOffsetPosition;
  1730. // m_log.DebugFormat("[SCENE OBJECT PART]: Found world pos {0} for part {1}", worldPos, Name);
  1731. return worldPos;
  1732. }
  1733. /// <summary>
  1734. /// Gets the rotation of this prim offset by the group rotation
  1735. /// </summary>
  1736. /// <returns></returns>
  1737. public Quaternion GetWorldRotation()
  1738. {
  1739. Quaternion newRot;
  1740. if (this.LinkNum == 0 || this.LinkNum == 1)
  1741. {
  1742. newRot = RotationOffset;
  1743. }
  1744. else
  1745. {
  1746. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1747. Quaternion oldRot = RotationOffset;
  1748. newRot = parentRot * oldRot;
  1749. }
  1750. return newRot;
  1751. }
  1752. public void MoveToTarget(Vector3 target, float tau)
  1753. {
  1754. if (tau > 0)
  1755. {
  1756. m_parentGroup.moveToTarget(target, tau);
  1757. }
  1758. else
  1759. {
  1760. StopMoveToTarget();
  1761. }
  1762. }
  1763. /// <summary>
  1764. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  1765. /// </summary>
  1766. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  1767. /// <param name="hoverType">Determines what the height is relative to </param>
  1768. /// <param name="tau">Number of seconds over which to reach target</param>
  1769. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  1770. {
  1771. m_parentGroup.SetHoverHeight(height, hoverType, tau);
  1772. }
  1773. public void StopHover()
  1774. {
  1775. m_parentGroup.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  1776. }
  1777. public virtual void OnGrab(Vector3 offsetPos, IClientAPI remoteClient)
  1778. {
  1779. }
  1780. public void PhysicsCollision(EventArgs e)
  1781. {
  1782. // single threaded here
  1783. if (e == null)
  1784. {
  1785. return;
  1786. }
  1787. CollisionEventUpdate a = (CollisionEventUpdate)e;
  1788. Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
  1789. List<uint> thisHitColliders = new List<uint>();
  1790. List<uint> endedColliders = new List<uint>();
  1791. List<uint> startedColliders = new List<uint>();
  1792. // calculate things that started colliding this time
  1793. // and build up list of colliders this time
  1794. foreach (uint localid in collissionswith.Keys)
  1795. {
  1796. thisHitColliders.Add(localid);
  1797. if (!m_lastColliders.Contains(localid))
  1798. {
  1799. startedColliders.Add(localid);
  1800. }
  1801. //m_log.Debug("[OBJECT]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
  1802. }
  1803. // calculate things that ended colliding
  1804. foreach (uint localID in m_lastColliders)
  1805. {
  1806. if (!thisHitColliders.Contains(localID))
  1807. {
  1808. endedColliders.Add(localID);
  1809. }
  1810. }
  1811. //add the items that started colliding this time to the last colliders list.
  1812. foreach (uint localID in startedColliders)
  1813. {
  1814. m_lastColliders.Add(localID);
  1815. }
  1816. // remove things that ended colliding from the last colliders list
  1817. foreach (uint localID in endedColliders)
  1818. {
  1819. m_lastColliders.Remove(localID);
  1820. }
  1821. if (m_parentGroup.IsDeleted)
  1822. return;
  1823. // play the sound.
  1824. if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
  1825. {
  1826. SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false);
  1827. }
  1828. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
  1829. {
  1830. // do event notification
  1831. if (startedColliders.Count > 0)
  1832. {
  1833. ColliderArgs StartCollidingMessage = new ColliderArgs();
  1834. List<DetectedObject> colliding = new List<DetectedObject>();
  1835. foreach (uint localId in startedColliders)
  1836. {
  1837. if (localId == 0)
  1838. continue;
  1839. if (m_parentGroup.Scene == null)
  1840. return;
  1841. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1842. string data = "";
  1843. if (obj != null)
  1844. {
  1845. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
  1846. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  1847. {
  1848. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1849. //If it is 1, it is to accept ONLY collisions from this object
  1850. if (found)
  1851. {
  1852. DetectedObject detobj = new DetectedObject();
  1853. detobj.keyUUID = obj.UUID;
  1854. detobj.nameStr = obj.Name;
  1855. detobj.ownerUUID = obj._ownerID;
  1856. detobj.posVector = obj.AbsolutePosition;
  1857. detobj.rotQuat = obj.GetWorldRotation();
  1858. detobj.velVector = obj.Velocity;
  1859. detobj.colliderType = 0;
  1860. detobj.groupUUID = obj._groupID;
  1861. colliding.Add(detobj);
  1862. }
  1863. //If it is 0, it is to not accept collisions from this object
  1864. else
  1865. {
  1866. }
  1867. }
  1868. else
  1869. {
  1870. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1871. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1872. if (!found)
  1873. {
  1874. DetectedObject detobj = new DetectedObject();
  1875. detobj.keyUUID = obj.UUID;
  1876. detobj.nameStr = obj.Name;
  1877. detobj.ownerUUID = obj._ownerID;
  1878. detobj.posVector = obj.AbsolutePosition;
  1879. detobj.rotQuat = obj.GetWorldRotation();
  1880. detobj.velVector = obj.Velocity;
  1881. detobj.colliderType = 0;
  1882. detobj.groupUUID = obj._groupID;
  1883. colliding.Add(detobj);
  1884. }
  1885. }
  1886. }
  1887. else
  1888. {
  1889. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  1890. {
  1891. if (av.LocalId == localId)
  1892. {
  1893. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  1894. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  1895. {
  1896. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  1897. //If it is 1, it is to accept ONLY collisions from this avatar
  1898. if (found)
  1899. {
  1900. DetectedObject detobj = new DetectedObject();
  1901. detobj.keyUUID = av.UUID;
  1902. detobj.nameStr = av.ControllingClient.Name;
  1903. detobj.ownerUUID = av.UUID;
  1904. detobj.posVector = av.AbsolutePosition;
  1905. detobj.rotQuat = av.Rotation;
  1906. detobj.velVector = av.Velocity;
  1907. detobj.colliderType = 0;
  1908. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1909. colliding.Add(detobj);
  1910. }
  1911. //If it is 0, it is to not accept collisions from this avatar
  1912. else
  1913. {
  1914. }
  1915. }
  1916. else
  1917. {
  1918. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  1919. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  1920. if (!found)
  1921. {
  1922. DetectedObject detobj = new DetectedObject();
  1923. detobj.keyUUID = av.UUID;
  1924. detobj.nameStr = av.ControllingClient.Name;
  1925. detobj.ownerUUID = av.UUID;
  1926. detobj.posVector = av.AbsolutePosition;
  1927. detobj.rotQuat = av.Rotation;
  1928. detobj.velVector = av.Velocity;
  1929. detobj.colliderType = 0;
  1930. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1931. colliding.Add(detobj);
  1932. }
  1933. }
  1934. }
  1935. });
  1936. }
  1937. }
  1938. if (colliding.Count > 0)
  1939. {
  1940. StartCollidingMessage.Colliders = colliding;
  1941. if (m_parentGroup.Scene == null)
  1942. return;
  1943. if (m_parentGroup.PassCollision == true)
  1944. {
  1945. //TODO: Add pass to root prim!
  1946. }
  1947. m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(LocalId, StartCollidingMessage);
  1948. }
  1949. }
  1950. }
  1951. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
  1952. {
  1953. if (m_lastColliders.Count > 0)
  1954. {
  1955. ColliderArgs CollidingMessage = new ColliderArgs();
  1956. List<DetectedObject> colliding = new List<DetectedObject>();
  1957. foreach (uint localId in m_lastColliders)
  1958. {
  1959. // always running this check because if the user deletes the object it would return a null reference.
  1960. if (localId == 0)
  1961. continue;
  1962. if (m_parentGroup.Scene == null)
  1963. return;
  1964. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1965. string data = "";
  1966. if (obj != null)
  1967. {
  1968. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
  1969. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  1970. {
  1971. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1972. //If it is 1, it is to accept ONLY collisions from this object
  1973. if (found)
  1974. {
  1975. DetectedObject detobj = new DetectedObject();
  1976. detobj.keyUUID = obj.UUID;
  1977. detobj.nameStr = obj.Name;
  1978. detobj.ownerUUID = obj._ownerID;
  1979. detobj.posVector = obj.AbsolutePosition;
  1980. detobj.rotQuat = obj.GetWorldRotation();
  1981. detobj.velVector = obj.Velocity;
  1982. detobj.colliderType = 0;
  1983. detobj.groupUUID = obj._groupID;
  1984. colliding.Add(detobj);
  1985. }
  1986. //If it is 0, it is to not accept collisions from this object
  1987. else
  1988. {
  1989. }
  1990. }
  1991. else
  1992. {
  1993. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1994. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1995. if (!found)
  1996. {
  1997. DetectedObject detobj = new DetectedObject();
  1998. detobj.keyUUID = obj.UUID;
  1999. detobj.nameStr = obj.Name;
  2000. detobj.ownerUUID = obj._ownerID;
  2001. detobj.posVector = obj.AbsolutePosition;
  2002. detobj.rotQuat = obj.GetWorldRotation();
  2003. detobj.velVector = obj.Velocity;
  2004. detobj.colliderType = 0;
  2005. detobj.groupUUID = obj._groupID;
  2006. colliding.Add(detobj);
  2007. }
  2008. }
  2009. }
  2010. else
  2011. {
  2012. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  2013. {
  2014. if (av.LocalId == localId)
  2015. {
  2016. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  2017. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  2018. {
  2019. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2020. //If it is 1, it is to accept ONLY collisions from this avatar
  2021. if (found)
  2022. {
  2023. DetectedObject detobj = new DetectedObject();
  2024. detobj.keyUUID = av.UUID;
  2025. detobj.nameStr = av.ControllingClient.Name;
  2026. detobj.ownerUUID = av.UUID;
  2027. detobj.posVector = av.AbsolutePosition;
  2028. detobj.rotQuat = av.Rotation;
  2029. detobj.velVector = av.Velocity;
  2030. detobj.colliderType = 0;
  2031. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2032. colliding.Add(detobj);
  2033. }
  2034. //If it is 0, it is to not accept collisions from this avatar
  2035. else
  2036. {
  2037. }
  2038. }
  2039. else
  2040. {
  2041. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2042. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  2043. if (!found)
  2044. {
  2045. DetectedObject detobj = new DetectedObject();
  2046. detobj.keyUUID = av.UUID;
  2047. detobj.nameStr = av.ControllingClient.Name;
  2048. detobj.ownerUUID = av.UUID;
  2049. detobj.posVector = av.AbsolutePosition;
  2050. detobj.rotQuat = av.Rotation;
  2051. detobj.velVector = av.Velocity;
  2052. detobj.colliderType = 0;
  2053. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2054. colliding.Add(detobj);
  2055. }
  2056. }
  2057. }
  2058. });
  2059. }
  2060. }
  2061. if (colliding.Count > 0)
  2062. {
  2063. CollidingMessage.Colliders = colliding;
  2064. if (m_parentGroup.Scene == null)
  2065. return;
  2066. m_parentGroup.Scene.EventManager.TriggerScriptColliding(LocalId, CollidingMessage);
  2067. }
  2068. }
  2069. }
  2070. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
  2071. {
  2072. if (endedColliders.Count > 0)
  2073. {
  2074. ColliderArgs EndCollidingMessage = new ColliderArgs();
  2075. List<DetectedObject> colliding = new List<DetectedObject>();
  2076. foreach (uint localId in endedColliders)
  2077. {
  2078. if (localId == 0)
  2079. continue;
  2080. if (m_parentGroup.Scene == null)
  2081. return;
  2082. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  2083. string data = "";
  2084. if (obj != null)
  2085. {
  2086. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  2087. {
  2088. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  2089. //If it is 1, it is to accept ONLY collisions from this object
  2090. if (found)
  2091. {
  2092. DetectedObject detobj = new DetectedObject();
  2093. detobj.keyUUID = obj.UUID;
  2094. detobj.nameStr = obj.Name;
  2095. detobj.ownerUUID = obj._ownerID;
  2096. detobj.posVector = obj.AbsolutePosition;
  2097. detobj.rotQuat = obj.GetWorldRotation();
  2098. detobj.velVector = obj.Velocity;
  2099. detobj.colliderType = 0;
  2100. detobj.groupUUID = obj._groupID;
  2101. colliding.Add(detobj);
  2102. }
  2103. //If it is 0, it is to not accept collisions from this object
  2104. else
  2105. {
  2106. }
  2107. }
  2108. else
  2109. {
  2110. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  2111. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  2112. if (!found)
  2113. {
  2114. DetectedObject detobj = new DetectedObject();
  2115. detobj.keyUUID = obj.UUID;
  2116. detobj.nameStr = obj.Name;
  2117. detobj.ownerUUID = obj._ownerID;
  2118. detobj.posVector = obj.AbsolutePosition;
  2119. detobj.rotQuat = obj.GetWorldRotation();
  2120. detobj.velVector = obj.Velocity;
  2121. detobj.colliderType = 0;
  2122. detobj.groupUUID = obj._groupID;
  2123. colliding.Add(detobj);
  2124. }
  2125. }
  2126. }
  2127. else
  2128. {
  2129. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  2130. {
  2131. if (av.LocalId == localId)
  2132. {
  2133. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  2134. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  2135. {
  2136. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2137. //If it is 1, it is to accept ONLY collisions from this avatar
  2138. if (found)
  2139. {
  2140. DetectedObject detobj = new DetectedObject();
  2141. detobj.keyUUID = av.UUID;
  2142. detobj.nameStr = av.ControllingClient.Name;
  2143. detobj.ownerUUID = av.UUID;
  2144. detobj.posVector = av.AbsolutePosition;
  2145. detobj.rotQuat = av.Rotation;
  2146. detobj.velVector = av.Velocity;
  2147. detobj.colliderType = 0;
  2148. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2149. colliding.Add(detobj);
  2150. }
  2151. //If it is 0, it is to not accept collisions from this avatar
  2152. else
  2153. {
  2154. }
  2155. }
  2156. else
  2157. {
  2158. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2159. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  2160. if (!found)
  2161. {
  2162. DetectedObject detobj = new DetectedObject();
  2163. detobj.keyUUID = av.UUID;
  2164. detobj.nameStr = av.ControllingClient.Name;
  2165. detobj.ownerUUID = av.UUID;
  2166. detobj.posVector = av.AbsolutePosition;
  2167. detobj.rotQuat = av.Rotation;
  2168. detobj.velVector = av.Velocity;
  2169. detobj.colliderType = 0;
  2170. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2171. colliding.Add(detobj);
  2172. }
  2173. }
  2174. }
  2175. });
  2176. }
  2177. }
  2178. if (colliding.Count > 0)
  2179. {
  2180. EndCollidingMessage.Colliders = colliding;
  2181. if (m_parentGroup.Scene == null)
  2182. return;
  2183. m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(LocalId, EndCollidingMessage);
  2184. }
  2185. }
  2186. }
  2187. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_start) != 0)
  2188. {
  2189. if (startedColliders.Count > 0)
  2190. {
  2191. ColliderArgs LandStartCollidingMessage = new ColliderArgs();
  2192. List<DetectedObject> colliding = new List<DetectedObject>();
  2193. foreach (uint localId in startedColliders)
  2194. {
  2195. if (localId == 0)
  2196. {
  2197. //Hope that all is left is ground!
  2198. DetectedObject detobj = new DetectedObject();
  2199. detobj.keyUUID = UUID.Zero;
  2200. detobj.nameStr = "";
  2201. detobj.ownerUUID = UUID.Zero;
  2202. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2203. detobj.rotQuat = Quaternion.Identity;
  2204. detobj.velVector = Vector3.Zero;
  2205. detobj.colliderType = 0;
  2206. detobj.groupUUID = UUID.Zero;
  2207. colliding.Add(detobj);
  2208. }
  2209. }
  2210. if (colliding.Count > 0)
  2211. {
  2212. LandStartCollidingMessage.Colliders = colliding;
  2213. if (m_parentGroup.Scene == null)
  2214. return;
  2215. m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(LocalId, LandStartCollidingMessage);
  2216. }
  2217. }
  2218. }
  2219. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision) != 0)
  2220. {
  2221. if (m_lastColliders.Count > 0)
  2222. {
  2223. ColliderArgs LandCollidingMessage = new ColliderArgs();
  2224. List<DetectedObject> colliding = new List<DetectedObject>();
  2225. foreach (uint localId in startedColliders)
  2226. {
  2227. if (localId == 0)
  2228. {
  2229. //Hope that all is left is ground!
  2230. DetectedObject detobj = new DetectedObject();
  2231. detobj.keyUUID = UUID.Zero;
  2232. detobj.nameStr = "";
  2233. detobj.ownerUUID = UUID.Zero;
  2234. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2235. detobj.rotQuat = Quaternion.Identity;
  2236. detobj.velVector = Vector3.Zero;
  2237. detobj.colliderType = 0;
  2238. detobj.groupUUID = UUID.Zero;
  2239. colliding.Add(detobj);
  2240. }
  2241. }
  2242. if (colliding.Count > 0)
  2243. {
  2244. LandCollidingMessage.Colliders = colliding;
  2245. if (m_parentGroup.Scene == null)
  2246. return;
  2247. m_parentGroup.Scene.EventManager.TriggerScriptLandColliding(LocalId, LandCollidingMessage);
  2248. }
  2249. }
  2250. }
  2251. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_end) != 0)
  2252. {
  2253. if (endedColliders.Count > 0)
  2254. {
  2255. ColliderArgs LandEndCollidingMessage = new ColliderArgs();
  2256. List<DetectedObject> colliding = new List<DetectedObject>();
  2257. foreach (uint localId in startedColliders)
  2258. {
  2259. if (localId == 0)
  2260. {
  2261. //Hope that all is left is ground!
  2262. DetectedObject detobj = new DetectedObject();
  2263. detobj.keyUUID = UUID.Zero;
  2264. detobj.nameStr = "";
  2265. detobj.ownerUUID = UUID.Zero;
  2266. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2267. detobj.rotQuat = Quaternion.Identity;
  2268. detobj.velVector = Vector3.Zero;
  2269. detobj.colliderType = 0;
  2270. detobj.groupUUID = UUID.Zero;
  2271. colliding.Add(detobj);
  2272. }
  2273. }
  2274. if (colliding.Count > 0)
  2275. {
  2276. LandEndCollidingMessage.Colliders = colliding;
  2277. if (m_parentGroup.Scene == null)
  2278. return;
  2279. m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(LocalId, LandEndCollidingMessage);
  2280. }
  2281. }
  2282. }
  2283. }
  2284. public void PhysicsOutOfBounds(Vector3 pos)
  2285. {
  2286. m_log.Error("[PHYSICS]: Physical Object went out of bounds.");
  2287. RemFlag(PrimFlags.Physics);
  2288. DoPhysicsPropertyUpdate(false, true);
  2289. //m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2290. }
  2291. public void PhysicsRequestingTerseUpdate()
  2292. {
  2293. if (PhysActor != null)
  2294. {
  2295. Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0);
  2296. if (m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
  2297. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
  2298. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
  2299. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
  2300. {
  2301. m_parentGroup.AbsolutePosition = newpos;
  2302. return;
  2303. }
  2304. //m_parentGroup.RootPart.m_groupPosition = newpos;
  2305. }
  2306. ScheduleTerseUpdate();
  2307. //SendTerseUpdateToAllClients();
  2308. }
  2309. public void PreloadSound(string sound)
  2310. {
  2311. // UUID ownerID = OwnerID;
  2312. UUID objectID = ParentGroup.RootPart.UUID;
  2313. UUID soundID = UUID.Zero;
  2314. if (!UUID.TryParse(sound, out soundID))
  2315. {
  2316. //Trys to fetch sound id from prim's inventory.
  2317. //Prim's inventory doesn't support non script items yet
  2318. lock (TaskInventory)
  2319. {
  2320. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  2321. {
  2322. if (item.Value.Name == sound)
  2323. {
  2324. soundID = item.Value.ItemID;
  2325. break;
  2326. }
  2327. }
  2328. }
  2329. }
  2330. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
  2331. {
  2332. if (sp.IsChildAgent)
  2333. return;
  2334. if (!(Util.GetDistanceTo(sp.AbsolutePosition, AbsolutePosition) >= 100))
  2335. sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  2336. });
  2337. }
  2338. public void RemFlag(PrimFlags flag)
  2339. {
  2340. // PrimFlags prevflag = Flags;
  2341. if ((Flags & flag) != 0)
  2342. {
  2343. //m_log.Debug("Removing flag: " + ((PrimFlags)flag).ToString());
  2344. Flags &= ~flag;
  2345. }
  2346. //m_log.Debug("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  2347. //ScheduleFullUpdate();
  2348. }
  2349. public void RemoveScriptEvents(UUID scriptid)
  2350. {
  2351. lock (m_scriptEvents)
  2352. {
  2353. if (m_scriptEvents.ContainsKey(scriptid))
  2354. {
  2355. scriptEvents oldparts = scriptEvents.None;
  2356. oldparts = (scriptEvents) m_scriptEvents[scriptid];
  2357. // remove values from aggregated script events
  2358. AggregateScriptEvents &= ~oldparts;
  2359. m_scriptEvents.Remove(scriptid);
  2360. aggregateScriptEvents();
  2361. }
  2362. }
  2363. }
  2364. /// <summary>
  2365. /// Reset UUIDs for this part. This involves generate this part's own UUID and
  2366. /// generating new UUIDs for all the items in the inventory.
  2367. /// </summary>
  2368. /// <param name="linkNum">Link number for the part</param>
  2369. public void ResetIDs(int linkNum)
  2370. {
  2371. UUID = UUID.Random();
  2372. LinkNum = linkNum;
  2373. LocalId = 0;
  2374. Inventory.ResetInventoryIDs();
  2375. }
  2376. /// <summary>
  2377. /// Set the scale of this part.
  2378. /// </summary>
  2379. /// <remarks>
  2380. /// Unlike the scale property, this checks the new size against scene limits and schedules a full property
  2381. /// update to viewers.
  2382. /// </remarks>
  2383. /// <param name="scale"></param>
  2384. public void Resize(Vector3 scale)
  2385. {
  2386. scale.X = Math.Min(scale.X, ParentGroup.Scene.m_maxNonphys);
  2387. scale.Y = Math.Min(scale.Y, ParentGroup.Scene.m_maxNonphys);
  2388. scale.Z = Math.Min(scale.Z, ParentGroup.Scene.m_maxNonphys);
  2389. if (PhysActor != null && PhysActor.IsPhysical)
  2390. {
  2391. scale.X = Math.Min(scale.X, ParentGroup.Scene.m_maxPhys);
  2392. scale.Y = Math.Min(scale.Y, ParentGroup.Scene.m_maxPhys);
  2393. scale.Z = Math.Min(scale.Z, ParentGroup.Scene.m_maxPhys);
  2394. }
  2395. // m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale);
  2396. Scale = scale;
  2397. ParentGroup.HasGroupChanged = true;
  2398. ScheduleFullUpdate();
  2399. }
  2400. public void RotLookAt(Quaternion target, float strength, float damping)
  2401. {
  2402. rotLookAt(target, strength, damping);
  2403. }
  2404. public void rotLookAt(Quaternion target, float strength, float damping)
  2405. {
  2406. if (m_parentGroup.IsAttachment)
  2407. {
  2408. /*
  2409. ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
  2410. if (avatar != null)
  2411. {
  2412. Rotate the Av?
  2413. } */
  2414. }
  2415. else
  2416. {
  2417. APIDDamp = damping;
  2418. APIDStrength = strength;
  2419. APIDTarget = target;
  2420. }
  2421. }
  2422. public void startLookAt(Quaternion rot, float damp, float strength)
  2423. {
  2424. APIDDamp = damp;
  2425. APIDStrength = strength;
  2426. APIDTarget = rot;
  2427. }
  2428. public void stopLookAt()
  2429. {
  2430. APIDTarget = Quaternion.Identity;
  2431. }
  2432. /// <summary>
  2433. /// Schedules this prim for a full update
  2434. /// </summary>
  2435. public void ScheduleFullUpdate()
  2436. {
  2437. // m_log.DebugFormat("[SCENE OBJECT PART]: Scheduling full update for {0} {1}", Name, LocalId);
  2438. if (m_parentGroup == null)
  2439. return;
  2440. m_parentGroup.QueueForUpdateCheck();
  2441. int timeNow = Util.UnixTimeSinceEpoch();
  2442. // If multiple updates are scheduled on the same second, we still need to perform all of them
  2443. // So we'll force the issue by bumping up the timestamp so that later processing sees these need
  2444. // to be performed.
  2445. if (timeNow <= TimeStampFull)
  2446. {
  2447. TimeStampFull += 1;
  2448. }
  2449. else
  2450. {
  2451. TimeStampFull = (uint)timeNow;
  2452. }
  2453. m_updateFlag = 2;
  2454. // m_log.DebugFormat(
  2455. // "[SCENE OBJECT PART]: Scheduling full update for {0}, {1} at {2}",
  2456. // UUID, Name, TimeStampFull);
  2457. }
  2458. /// <summary>
  2459. /// Schedule a terse update for this prim. Terse updates only send position,
  2460. /// rotation, velocity, rotational velocity and shape information.
  2461. /// </summary>
  2462. public void ScheduleTerseUpdate()
  2463. {
  2464. if (m_parentGroup == null)
  2465. return;
  2466. if (m_updateFlag < 1)
  2467. {
  2468. m_parentGroup.HasGroupChanged = true;
  2469. m_parentGroup.QueueForUpdateCheck();
  2470. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  2471. m_updateFlag = 1;
  2472. // m_log.DebugFormat(
  2473. // "[SCENE OBJECT PART]: Scheduling terse update for {0}, {1} at {2}",
  2474. // UUID, Name, TimeStampTerse);
  2475. }
  2476. }
  2477. public void ScriptSetPhysicsStatus(bool UsePhysics)
  2478. {
  2479. m_parentGroup.ScriptSetPhysicsStatus(UsePhysics);
  2480. }
  2481. /// <summary>
  2482. /// Set sculpt and mesh data, and tell the physics engine to process the change.
  2483. /// </summary>
  2484. /// <param name="texture">The mesh itself.</param>
  2485. public void SculptTextureCallback(AssetBase texture)
  2486. {
  2487. if (m_shape.SculptEntry)
  2488. {
  2489. // commented out for sculpt map caching test - null could mean a cached sculpt map has been found
  2490. //if (texture != null)
  2491. {
  2492. if (texture != null)
  2493. {
  2494. // m_log.DebugFormat(
  2495. // "[SCENE OBJECT PART]: Setting sculpt data for {0} on SculptTextureCallback()", Name);
  2496. m_shape.SculptData = texture.Data;
  2497. }
  2498. if (PhysActor != null)
  2499. {
  2500. // Update the physics actor with the new loaded sculpt data and set the taint signal.
  2501. PhysActor.Shape = m_shape;
  2502. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2503. }
  2504. }
  2505. }
  2506. }
  2507. /// <summary>
  2508. /// Send a full update to the client for the given part
  2509. /// </summary>
  2510. /// <param name="remoteClient"></param>
  2511. /// <param name="clientFlags"></param>
  2512. protected internal void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  2513. {
  2514. if (m_parentGroup == null)
  2515. return;
  2516. // m_log.DebugFormat(
  2517. // "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
  2518. if (IsRoot)
  2519. {
  2520. if (m_parentGroup.IsAttachment)
  2521. {
  2522. SendFullUpdateToClient(remoteClient, AttachedPos, clientFlags);
  2523. }
  2524. else
  2525. {
  2526. SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
  2527. }
  2528. }
  2529. else
  2530. {
  2531. SendFullUpdateToClient(remoteClient, clientFlags);
  2532. }
  2533. }
  2534. /// <summary>
  2535. /// Send a full update for this part to all clients.
  2536. /// </summary>
  2537. public void SendFullUpdateToAllClients()
  2538. {
  2539. if (m_parentGroup == null)
  2540. return;
  2541. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2542. {
  2543. SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
  2544. });
  2545. }
  2546. /// <summary>
  2547. /// Send a full update to all clients except the one nominated.
  2548. /// </summary>
  2549. /// <param name="agentID"></param>
  2550. public void SendFullUpdateToAllClientsExcept(UUID agentID)
  2551. {
  2552. if (m_parentGroup == null)
  2553. return;
  2554. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2555. {
  2556. // Ugly reference :(
  2557. if (avatar.UUID != agentID)
  2558. SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
  2559. });
  2560. }
  2561. /// <summary>
  2562. /// Sends a full update to the client
  2563. /// </summary>
  2564. /// <param name="remoteClient"></param>
  2565. /// <param name="clientFlags"></param>
  2566. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  2567. {
  2568. Vector3 lPos;
  2569. lPos = OffsetPosition;
  2570. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  2571. }
  2572. /// <summary>
  2573. /// Sends a full update to the client
  2574. /// </summary>
  2575. /// <param name="remoteClient"></param>
  2576. /// <param name="lPos"></param>
  2577. /// <param name="clientFlags"></param>
  2578. public void SendFullUpdateToClient(IClientAPI remoteClient, Vector3 lPos, uint clientFlags)
  2579. {
  2580. if (ParentGroup == null)
  2581. return;
  2582. // Suppress full updates during attachment editing
  2583. //
  2584. if (ParentGroup.IsSelected && ParentGroup.IsAttachment)
  2585. return;
  2586. if (ParentGroup.IsDeleted)
  2587. return;
  2588. clientFlags &= ~(uint) PrimFlags.CreateSelected;
  2589. if (remoteClient.AgentId == _ownerID)
  2590. {
  2591. if ((Flags & PrimFlags.CreateSelected) != 0)
  2592. {
  2593. clientFlags |= (uint) PrimFlags.CreateSelected;
  2594. Flags &= ~PrimFlags.CreateSelected;
  2595. }
  2596. }
  2597. //bool isattachment = IsAttachment;
  2598. //if (LocalId != ParentGroup.RootPart.LocalId)
  2599. //isattachment = ParentGroup.RootPart.IsAttachment;
  2600. remoteClient.SendPrimUpdate(this, PrimUpdateFlags.FullUpdate);
  2601. }
  2602. /// <summary>
  2603. /// Tell all the prims which have had updates scheduled
  2604. /// </summary>
  2605. public void SendScheduledUpdates()
  2606. {
  2607. const float ROTATION_TOLERANCE = 0.01f;
  2608. const float VELOCITY_TOLERANCE = 0.001f;
  2609. const float POSITION_TOLERANCE = 0.05f;
  2610. const int TIME_MS_TOLERANCE = 3000;
  2611. if (m_updateFlag == 1)
  2612. {
  2613. // Throw away duplicate or insignificant updates
  2614. if (!RotationOffset.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
  2615. !Acceleration.Equals(m_lastAcceleration) ||
  2616. !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
  2617. Velocity.ApproxEquals(Vector3.Zero, VELOCITY_TOLERANCE) ||
  2618. !AngularVelocity.ApproxEquals(m_lastAngularVelocity, VELOCITY_TOLERANCE) ||
  2619. !OffsetPosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
  2620. Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
  2621. {
  2622. AddTerseUpdateToAllAvatars();
  2623. ClearUpdateSchedule();
  2624. // This causes the Scene to 'poll' physical objects every couple of frames
  2625. // bad, so it's been replaced by an event driven method.
  2626. //if ((ObjectFlags & (uint)PrimFlags.Physics) != 0)
  2627. //{
  2628. // Only send the constant terse updates on physical objects!
  2629. //ScheduleTerseUpdate();
  2630. //}
  2631. // Update the "last" values
  2632. m_lastPosition = OffsetPosition;
  2633. m_lastRotation = RotationOffset;
  2634. m_lastVelocity = Velocity;
  2635. m_lastAcceleration = Acceleration;
  2636. m_lastAngularVelocity = AngularVelocity;
  2637. m_lastTerseSent = Environment.TickCount;
  2638. }
  2639. }
  2640. else
  2641. {
  2642. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  2643. {
  2644. AddFullUpdateToAllAvatars();
  2645. ClearUpdateSchedule();
  2646. }
  2647. }
  2648. ClearUpdateSchedule();
  2649. }
  2650. /// <summary>
  2651. /// Trigger or play an attached sound in this part's inventory.
  2652. /// </summary>
  2653. /// <param name="sound"></param>
  2654. /// <param name="volume"></param>
  2655. /// <param name="triggered"></param>
  2656. /// <param name="flags"></param>
  2657. public void SendSound(string sound, double volume, bool triggered, byte flags, float radius, bool useMaster, bool isMaster)
  2658. {
  2659. if (volume > 1)
  2660. volume = 1;
  2661. if (volume < 0)
  2662. volume = 0;
  2663. UUID ownerID = _ownerID;
  2664. UUID objectID = ParentGroup.RootPart.UUID;
  2665. UUID parentID = ParentGroup.UUID;
  2666. UUID soundID = UUID.Zero;
  2667. Vector3 position = AbsolutePosition; // region local
  2668. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  2669. if (!UUID.TryParse(sound, out soundID))
  2670. {
  2671. // search sound file from inventory
  2672. lock (TaskInventory)
  2673. {
  2674. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  2675. {
  2676. if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
  2677. {
  2678. soundID = item.Value.ItemID;
  2679. break;
  2680. }
  2681. }
  2682. }
  2683. }
  2684. if (soundID == UUID.Zero)
  2685. return;
  2686. ISoundModule soundModule = m_parentGroup.Scene.RequestModuleInterface<ISoundModule>();
  2687. if (soundModule != null)
  2688. {
  2689. if (useMaster)
  2690. {
  2691. if (isMaster)
  2692. {
  2693. if (triggered)
  2694. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2695. else
  2696. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2697. ParentGroup.PlaySoundMasterPrim = this;
  2698. ownerID = _ownerID;
  2699. objectID = ParentGroup.RootPart.UUID;
  2700. parentID = ParentGroup.UUID;
  2701. position = AbsolutePosition; // region local
  2702. regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
  2703. if (triggered)
  2704. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2705. else
  2706. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2707. foreach (SceneObjectPart prim in ParentGroup.PlaySoundSlavePrims)
  2708. {
  2709. ownerID = prim._ownerID;
  2710. objectID = prim.ParentGroup.RootPart.UUID;
  2711. parentID = prim.ParentGroup.UUID;
  2712. position = prim.AbsolutePosition; // region local
  2713. regionHandle = prim.ParentGroup.Scene.RegionInfo.RegionHandle;
  2714. if (triggered)
  2715. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2716. else
  2717. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2718. }
  2719. ParentGroup.PlaySoundSlavePrims.Clear();
  2720. ParentGroup.PlaySoundMasterPrim = null;
  2721. }
  2722. else
  2723. {
  2724. ParentGroup.PlaySoundSlavePrims.Add(this);
  2725. }
  2726. }
  2727. else
  2728. {
  2729. if (triggered)
  2730. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2731. else
  2732. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2733. }
  2734. }
  2735. }
  2736. /// <summary>
  2737. /// Send a terse update to all clients
  2738. /// </summary>
  2739. public void SendTerseUpdateToAllClients()
  2740. {
  2741. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2742. {
  2743. SendTerseUpdateToClient(avatar.ControllingClient);
  2744. });
  2745. }
  2746. public void SetAxisRotation(int axis, int rotate)
  2747. {
  2748. m_parentGroup.SetAxisRotation(axis, rotate);
  2749. //Cannot use ScriptBaseClass constants as no referance to it currently.
  2750. if (axis == 2)//STATUS_ROTATE_X
  2751. STATUS_ROTATE_X = rotate;
  2752. if (axis == 4)//STATUS_ROTATE_Y
  2753. STATUS_ROTATE_Y = rotate;
  2754. if (axis == 8)//STATUS_ROTATE_Z
  2755. STATUS_ROTATE_Z = rotate;
  2756. }
  2757. public void SetBuoyancy(float fvalue)
  2758. {
  2759. if (PhysActor != null)
  2760. {
  2761. PhysActor.Buoyancy = fvalue;
  2762. }
  2763. }
  2764. public void SetDieAtEdge(bool p)
  2765. {
  2766. if (m_parentGroup.IsDeleted)
  2767. return;
  2768. m_parentGroup.RootPart.DIE_AT_EDGE = p;
  2769. }
  2770. public void SetFloatOnWater(int floatYN)
  2771. {
  2772. if (PhysActor != null)
  2773. {
  2774. if (floatYN == 1)
  2775. {
  2776. PhysActor.FloatOnWater = true;
  2777. }
  2778. else
  2779. {
  2780. PhysActor.FloatOnWater = false;
  2781. }
  2782. }
  2783. }
  2784. public void SetForce(Vector3 force)
  2785. {
  2786. if (PhysActor != null)
  2787. {
  2788. PhysActor.Force = force;
  2789. }
  2790. }
  2791. public void SetVehicleType(int type)
  2792. {
  2793. if (PhysActor != null)
  2794. {
  2795. PhysActor.VehicleType = type;
  2796. }
  2797. }
  2798. public void SetVehicleFloatParam(int param, float value)
  2799. {
  2800. if (PhysActor != null)
  2801. {
  2802. PhysActor.VehicleFloatParam(param, value);
  2803. }
  2804. }
  2805. public void SetVehicleVectorParam(int param, Vector3 value)
  2806. {
  2807. if (PhysActor != null)
  2808. {
  2809. PhysActor.VehicleVectorParam(param, value);
  2810. }
  2811. }
  2812. public void SetVehicleRotationParam(int param, Quaternion rotation)
  2813. {
  2814. if (PhysActor != null)
  2815. {
  2816. PhysActor.VehicleRotationParam(param, rotation);
  2817. }
  2818. }
  2819. /// <summary>
  2820. /// Set the color of prim faces
  2821. /// </summary>
  2822. /// <param name="color"></param>
  2823. /// <param name="face"></param>
  2824. public void SetFaceColor(Vector3 color, int face)
  2825. {
  2826. Primitive.TextureEntry tex = Shape.Textures;
  2827. Color4 texcolor;
  2828. if (face >= 0 && face < GetNumberOfSides())
  2829. {
  2830. texcolor = tex.CreateFace((uint)face).RGBA;
  2831. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2832. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2833. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2834. tex.FaceTextures[face].RGBA = texcolor;
  2835. UpdateTexture(tex);
  2836. TriggerScriptChangedEvent(Changed.COLOR);
  2837. return;
  2838. }
  2839. else if (face == ALL_SIDES)
  2840. {
  2841. for (uint i = 0; i < GetNumberOfSides(); i++)
  2842. {
  2843. if (tex.FaceTextures[i] != null)
  2844. {
  2845. texcolor = tex.FaceTextures[i].RGBA;
  2846. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2847. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2848. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2849. tex.FaceTextures[i].RGBA = texcolor;
  2850. }
  2851. texcolor = tex.DefaultTexture.RGBA;
  2852. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2853. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2854. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2855. tex.DefaultTexture.RGBA = texcolor;
  2856. }
  2857. UpdateTexture(tex);
  2858. TriggerScriptChangedEvent(Changed.COLOR);
  2859. return;
  2860. }
  2861. }
  2862. /// <summary>
  2863. /// Get the number of sides that this part has.
  2864. /// </summary>
  2865. /// <returns></returns>
  2866. public int GetNumberOfSides()
  2867. {
  2868. int ret = 0;
  2869. bool hasCut;
  2870. bool hasHollow;
  2871. bool hasDimple;
  2872. bool hasProfileCut;
  2873. PrimType primType = GetPrimType();
  2874. HasCutHollowDimpleProfileCut(primType, Shape, out hasCut, out hasHollow, out hasDimple, out hasProfileCut);
  2875. switch (primType)
  2876. {
  2877. case PrimType.BOX:
  2878. ret = 6;
  2879. if (hasCut) ret += 2;
  2880. if (hasHollow) ret += 1;
  2881. break;
  2882. case PrimType.CYLINDER:
  2883. ret = 3;
  2884. if (hasCut) ret += 2;
  2885. if (hasHollow) ret += 1;
  2886. break;
  2887. case PrimType.PRISM:
  2888. ret = 5;
  2889. if (hasCut) ret += 2;
  2890. if (hasHollow) ret += 1;
  2891. break;
  2892. case PrimType.SPHERE:
  2893. ret = 1;
  2894. if (hasCut) ret += 2;
  2895. if (hasDimple) ret += 2;
  2896. if (hasHollow) ret += 1;
  2897. break;
  2898. case PrimType.TORUS:
  2899. ret = 1;
  2900. if (hasCut) ret += 2;
  2901. if (hasProfileCut) ret += 2;
  2902. if (hasHollow) ret += 1;
  2903. break;
  2904. case PrimType.TUBE:
  2905. ret = 4;
  2906. if (hasCut) ret += 2;
  2907. if (hasProfileCut) ret += 2;
  2908. if (hasHollow) ret += 1;
  2909. break;
  2910. case PrimType.RING:
  2911. ret = 3;
  2912. if (hasCut) ret += 2;
  2913. if (hasProfileCut) ret += 2;
  2914. if (hasHollow) ret += 1;
  2915. break;
  2916. case PrimType.SCULPT:
  2917. ret = 1;
  2918. break;
  2919. }
  2920. return ret;
  2921. }
  2922. /// <summary>
  2923. /// Tell us what type this prim is
  2924. /// </summary>
  2925. /// <param name="primShape"></param>
  2926. /// <returns></returns>
  2927. public PrimType GetPrimType()
  2928. {
  2929. if (Shape.SculptEntry)
  2930. return PrimType.SCULPT;
  2931. if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
  2932. {
  2933. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2934. return PrimType.BOX;
  2935. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2936. return PrimType.TUBE;
  2937. }
  2938. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
  2939. {
  2940. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2941. return PrimType.CYLINDER;
  2942. // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
  2943. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2944. return PrimType.TORUS;
  2945. }
  2946. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
  2947. {
  2948. if (Shape.PathCurve == (byte)Extrusion.Curve1 || Shape.PathCurve == (byte)Extrusion.Curve2)
  2949. return PrimType.SPHERE;
  2950. }
  2951. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
  2952. {
  2953. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2954. return PrimType.PRISM;
  2955. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2956. return PrimType.RING;
  2957. }
  2958. return PrimType.BOX;
  2959. }
  2960. /// <summary>
  2961. /// Tell us if this object has cut, hollow, dimple, and other factors affecting the number of faces
  2962. /// </summary>
  2963. /// <param name="primType"></param>
  2964. /// <param name="shape"></param>
  2965. /// <param name="hasCut"></param>
  2966. /// <param name="hasHollow"></param>
  2967. /// <param name="hasDimple"></param>
  2968. /// <param name="hasProfileCut"></param>
  2969. protected static void HasCutHollowDimpleProfileCut(PrimType primType, PrimitiveBaseShape shape, out bool hasCut, out bool hasHollow,
  2970. out bool hasDimple, out bool hasProfileCut)
  2971. {
  2972. if (primType == PrimType.BOX
  2973. ||
  2974. primType == PrimType.CYLINDER
  2975. ||
  2976. primType == PrimType.PRISM)
  2977. hasCut = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0);
  2978. else
  2979. hasCut = (shape.PathBegin > 0) || (shape.PathEnd > 0);
  2980. hasHollow = shape.ProfileHollow > 0;
  2981. hasDimple = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); // taken from llSetPrimitiveParms
  2982. hasProfileCut = hasDimple; // is it the same thing?
  2983. }
  2984. public void SetVehicleFlags(int param, bool remove)
  2985. {
  2986. if (PhysActor != null)
  2987. {
  2988. PhysActor.VehicleFlags(param, remove);
  2989. }
  2990. }
  2991. public void SetGroup(UUID groupID, IClientAPI client)
  2992. {
  2993. _groupID = groupID;
  2994. if (client != null)
  2995. GetProperties(client);
  2996. m_updateFlag = 2;
  2997. }
  2998. /// <summary>
  2999. /// Set the parent group of this prim.
  3000. /// </summary>
  3001. public void SetParent(SceneObjectGroup parent)
  3002. {
  3003. m_parentGroup = parent;
  3004. }
  3005. // Use this for attachments! LocalID should be avatar's localid
  3006. public void SetParentLocalId(uint localID)
  3007. {
  3008. _parentID = localID;
  3009. }
  3010. public void SetPhysicsAxisRotation()
  3011. {
  3012. if (PhysActor != null)
  3013. {
  3014. PhysActor.LockAngularMotion(RotationAxis);
  3015. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  3016. }
  3017. }
  3018. /// <summary>
  3019. /// Set the events that this part will pass on to listeners.
  3020. /// </summary>
  3021. /// <param name="scriptid"></param>
  3022. /// <param name="events"></param>
  3023. public void SetScriptEvents(UUID scriptid, int events)
  3024. {
  3025. // scriptEvents oldparts;
  3026. lock (m_scriptEvents)
  3027. {
  3028. if (m_scriptEvents.ContainsKey(scriptid))
  3029. {
  3030. // oldparts = m_scriptEvents[scriptid];
  3031. // remove values from aggregated script events
  3032. if (m_scriptEvents[scriptid] == (scriptEvents) events)
  3033. return;
  3034. m_scriptEvents[scriptid] = (scriptEvents) events;
  3035. }
  3036. else
  3037. {
  3038. m_scriptEvents.Add(scriptid, (scriptEvents) events);
  3039. }
  3040. }
  3041. aggregateScriptEvents();
  3042. }
  3043. /// <summary>
  3044. /// Set the text displayed for this part.
  3045. /// </summary>
  3046. /// <param name="text"></param>
  3047. public void SetText(string text)
  3048. {
  3049. Text = text;
  3050. if (ParentGroup != null)
  3051. {
  3052. ParentGroup.HasGroupChanged = true;
  3053. ScheduleFullUpdate();
  3054. }
  3055. }
  3056. public void StopLookAt()
  3057. {
  3058. m_parentGroup.stopLookAt();
  3059. m_parentGroup.ScheduleGroupForTerseUpdate();
  3060. }
  3061. /// <summary>
  3062. /// Set the text displayed for this part.
  3063. /// </summary>
  3064. /// <param name="text"></param>
  3065. /// <param name="color"></param>
  3066. /// <param name="alpha"></param>
  3067. public void SetText(string text, Vector3 color, double alpha)
  3068. {
  3069. Color = Color.FromArgb((int) (alpha*0xff),
  3070. (int) (color.X*0xff),
  3071. (int) (color.Y*0xff),
  3072. (int) (color.Z*0xff));
  3073. SetText(text);
  3074. }
  3075. public void StopMoveToTarget()
  3076. {
  3077. m_parentGroup.stopMoveToTarget();
  3078. m_parentGroup.ScheduleGroupForTerseUpdate();
  3079. //m_parentGroup.ScheduleGroupForFullUpdate();
  3080. }
  3081. public void StoreUndoState()
  3082. {
  3083. StoreUndoState(false);
  3084. }
  3085. public void StoreUndoState(bool forGroup)
  3086. {
  3087. if (!Undoing)
  3088. {
  3089. if (!IgnoreUndoUpdate)
  3090. {
  3091. if (ParentGroup != null)
  3092. {
  3093. lock (m_undo)
  3094. {
  3095. if (m_undo.Count > 0)
  3096. {
  3097. UndoState last = m_undo.Peek();
  3098. if (last != null)
  3099. {
  3100. // TODO: May need to fix for group comparison
  3101. if (last.Compare(this))
  3102. {
  3103. // m_log.DebugFormat(
  3104. // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
  3105. // Name, LocalId, m_undo.Count);
  3106. return;
  3107. }
  3108. }
  3109. }
  3110. // m_log.DebugFormat(
  3111. // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
  3112. // Name, LocalId, forGroup, m_undo.Count);
  3113. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3114. {
  3115. UndoState nUndo = new UndoState(this, forGroup);
  3116. m_undo.Push(nUndo);
  3117. if (m_redo.Count > 0)
  3118. m_redo.Clear();
  3119. // m_log.DebugFormat(
  3120. // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
  3121. // Name, LocalId, forGroup, m_undo.Count);
  3122. }
  3123. }
  3124. }
  3125. }
  3126. // else
  3127. // {
  3128. // m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
  3129. // }
  3130. }
  3131. // else
  3132. // {
  3133. // m_log.DebugFormat(
  3134. // "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
  3135. // }
  3136. }
  3137. /// <summary>
  3138. /// Return number of undos on the stack. Here temporarily pending a refactor.
  3139. /// </summary>
  3140. public int UndoCount
  3141. {
  3142. get
  3143. {
  3144. lock (m_undo)
  3145. return m_undo.Count;
  3146. }
  3147. }
  3148. public void Undo()
  3149. {
  3150. lock (m_undo)
  3151. {
  3152. // m_log.DebugFormat(
  3153. // "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
  3154. // Name, LocalId, m_undo.Count);
  3155. if (m_undo.Count > 0)
  3156. {
  3157. UndoState goback = m_undo.Pop();
  3158. if (goback != null)
  3159. {
  3160. UndoState nUndo = null;
  3161. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3162. {
  3163. nUndo = new UndoState(this, goback.ForGroup);
  3164. }
  3165. goback.PlaybackState(this);
  3166. if (nUndo != null)
  3167. m_redo.Push(nUndo);
  3168. }
  3169. }
  3170. // m_log.DebugFormat(
  3171. // "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}",
  3172. // Name, LocalId, m_undo.Count);
  3173. }
  3174. }
  3175. public void Redo()
  3176. {
  3177. lock (m_undo)
  3178. {
  3179. // m_log.DebugFormat(
  3180. // "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
  3181. // Name, LocalId, m_redo.Count);
  3182. if (m_redo.Count > 0)
  3183. {
  3184. UndoState gofwd = m_redo.Pop();
  3185. if (gofwd != null)
  3186. {
  3187. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3188. {
  3189. UndoState nUndo = new UndoState(this, gofwd.ForGroup);
  3190. m_undo.Push(nUndo);
  3191. }
  3192. gofwd.PlayfwdState(this);
  3193. }
  3194. // m_log.DebugFormat(
  3195. // "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}",
  3196. // Name, LocalId, m_redo.Count);
  3197. }
  3198. }
  3199. }
  3200. public void ClearUndoState()
  3201. {
  3202. // m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId);
  3203. lock (m_undo)
  3204. {
  3205. m_undo.Clear();
  3206. m_redo.Clear();
  3207. }
  3208. }
  3209. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  3210. {
  3211. // In this case we're using a sphere with a radius of the largest dimension of the prim
  3212. // TODO: Change to take shape into account
  3213. EntityIntersection result = new EntityIntersection();
  3214. Vector3 vAbsolutePosition = AbsolutePosition;
  3215. Vector3 vScale = Scale;
  3216. Vector3 rOrigin = iray.Origin;
  3217. Vector3 rDirection = iray.Direction;
  3218. //rDirection = rDirection.Normalize();
  3219. // Buidling the first part of the Quadratic equation
  3220. Vector3 r2ndDirection = rDirection*rDirection;
  3221. float itestPart1 = r2ndDirection.X + r2ndDirection.Y + r2ndDirection.Z;
  3222. // Buidling the second part of the Quadratic equation
  3223. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  3224. Vector3 r2Direction = rDirection*2.0f;
  3225. Vector3 tmVal3 = r2Direction*tmVal2;
  3226. float itestPart2 = tmVal3.X + tmVal3.Y + tmVal3.Z;
  3227. // Buidling the third part of the Quadratic equation
  3228. Vector3 tmVal4 = rOrigin*rOrigin;
  3229. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  3230. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  3231. // Set Radius to the largest dimension of the prim
  3232. float radius = 0f;
  3233. if (vScale.X > radius)
  3234. radius = vScale.X;
  3235. if (vScale.Y > radius)
  3236. radius = vScale.Y;
  3237. if (vScale.Z > radius)
  3238. radius = vScale.Z;
  3239. // the second part of this is the default prim size
  3240. // once we factor in the aabb of the prim we're adding we can
  3241. // change this to;
  3242. // radius = (radius / 2) - 0.01f;
  3243. //
  3244. radius = (radius / 2) + (0.5f / 2) - 0.1f;
  3245. //radius = radius;
  3246. float itestPart3 = tmVal4.X + tmVal4.Y + tmVal4.Z + tmVal5.X + tmVal5.Y + tmVal5.Z -
  3247. (2.0f*(tmVal6.X + tmVal6.Y + tmVal6.Z + (radius*radius)));
  3248. // Yuk Quadradrics.. Solve first
  3249. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  3250. if (rootsqr < 0.0f)
  3251. {
  3252. // No intersection
  3253. return result;
  3254. }
  3255. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  3256. if (root < 0.0f)
  3257. {
  3258. // perform second quadratic root solution
  3259. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  3260. // is there any intersection?
  3261. if (root < 0.0f)
  3262. {
  3263. // nope, no intersection
  3264. return result;
  3265. }
  3266. }
  3267. // We got an intersection. putting together an EntityIntersection object with the
  3268. // intersection information
  3269. Vector3 ipoint =
  3270. new Vector3(iray.Origin.X + (iray.Direction.X*root), iray.Origin.Y + (iray.Direction.Y*root),
  3271. iray.Origin.Z + (iray.Direction.Z*root));
  3272. result.HitTF = true;
  3273. result.ipoint = ipoint;
  3274. // Normal is calculated by the difference and then normalizing the result
  3275. Vector3 normalpart = ipoint - vAbsolutePosition;
  3276. result.normal = normalpart / normalpart.Length();
  3277. // It's funny how the Vector3 object has a Distance function, but the Axiom.Math object doesn't.
  3278. // I can write a function to do it.. but I like the fact that this one is Static.
  3279. Vector3 distanceConvert1 = new Vector3(iray.Origin.X, iray.Origin.Y, iray.Origin.Z);
  3280. Vector3 distanceConvert2 = new Vector3(ipoint.X, ipoint.Y, ipoint.Z);
  3281. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  3282. result.distance = distance;
  3283. return result;
  3284. }
  3285. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  3286. {
  3287. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  3288. // This breaks down into the ray---> plane equation.
  3289. // TODO: Change to take shape into account
  3290. Vector3[] vertexes = new Vector3[8];
  3291. // float[] distance = new float[6];
  3292. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  3293. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  3294. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  3295. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  3296. Vector3[] normals = new Vector3[6]; // Normal for Facei
  3297. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  3298. AAfacenormals[0] = new Vector3(1, 0, 0);
  3299. AAfacenormals[1] = new Vector3(0, 1, 0);
  3300. AAfacenormals[2] = new Vector3(-1, 0, 0);
  3301. AAfacenormals[3] = new Vector3(0, -1, 0);
  3302. AAfacenormals[4] = new Vector3(0, 0, 1);
  3303. AAfacenormals[5] = new Vector3(0, 0, -1);
  3304. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  3305. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  3306. Vector3 cross = new Vector3();
  3307. Vector3 pos = GetWorldPosition();
  3308. Quaternion rot = GetWorldRotation();
  3309. // Variables prefixed with AX are Axiom.Math copies of the LL variety.
  3310. Quaternion AXrot = rot;
  3311. AXrot.Normalize();
  3312. Vector3 AXpos = pos;
  3313. // tScale is the offset to derive the vertex based on the scale.
  3314. // it's different for each vertex because we've got to rotate it
  3315. // to get the world position of the vertex to produce the Oriented Bounding Box
  3316. Vector3 tScale = Vector3.Zero;
  3317. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  3318. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  3319. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  3320. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  3321. Vector3 rScale = new Vector3();
  3322. // Get Vertexes for Faces Stick them into ABCD for each Face
  3323. // Form: Face<vertex>[face] that corresponds to the below diagram
  3324. #region ABCD Face Vertex Map Comment Diagram
  3325. // A _________ B
  3326. // | |
  3327. // | 4 top |
  3328. // |_________|
  3329. // C D
  3330. // A _________ B
  3331. // | Back |
  3332. // | 3 |
  3333. // |_________|
  3334. // C D
  3335. // A _________ B B _________ A
  3336. // | Left | | Right |
  3337. // | 0 | | 2 |
  3338. // |_________| |_________|
  3339. // C D D C
  3340. // A _________ B
  3341. // | Front |
  3342. // | 1 |
  3343. // |_________|
  3344. // C D
  3345. // C _________ D
  3346. // | |
  3347. // | 5 bot |
  3348. // |_________|
  3349. // A B
  3350. #endregion
  3351. #region Plane Decomposition of Oriented Bounding Box
  3352. tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
  3353. rScale = tScale * AXrot;
  3354. vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3355. // vertexes[0].X = pos.X + vertexes[0].X;
  3356. //vertexes[0].Y = pos.Y + vertexes[0].Y;
  3357. //vertexes[0].Z = pos.Z + vertexes[0].Z;
  3358. FaceA[0] = vertexes[0];
  3359. FaceB[3] = vertexes[0];
  3360. FaceA[4] = vertexes[0];
  3361. tScale = AXscale;
  3362. rScale = tScale * AXrot;
  3363. vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3364. // vertexes[1].X = pos.X + vertexes[1].X;
  3365. // vertexes[1].Y = pos.Y + vertexes[1].Y;
  3366. //vertexes[1].Z = pos.Z + vertexes[1].Z;
  3367. FaceB[0] = vertexes[1];
  3368. FaceA[1] = vertexes[1];
  3369. FaceC[4] = vertexes[1];
  3370. tScale = new Vector3(AXscale.X, -AXscale.Y, -AXscale.Z);
  3371. rScale = tScale * AXrot;
  3372. vertexes[2] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3373. //vertexes[2].X = pos.X + vertexes[2].X;
  3374. //vertexes[2].Y = pos.Y + vertexes[2].Y;
  3375. //vertexes[2].Z = pos.Z + vertexes[2].Z;
  3376. FaceC[0] = vertexes[2];
  3377. FaceD[3] = vertexes[2];
  3378. FaceC[5] = vertexes[2];
  3379. tScale = new Vector3(AXscale.X, AXscale.Y, -AXscale.Z);
  3380. rScale = tScale * AXrot;
  3381. vertexes[3] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3382. //vertexes[3].X = pos.X + vertexes[3].X;
  3383. // vertexes[3].Y = pos.Y + vertexes[3].Y;
  3384. // vertexes[3].Z = pos.Z + vertexes[3].Z;
  3385. FaceD[0] = vertexes[3];
  3386. FaceC[1] = vertexes[3];
  3387. FaceA[5] = vertexes[3];
  3388. tScale = new Vector3(-AXscale.X, AXscale.Y, AXscale.Z);
  3389. rScale = tScale * AXrot;
  3390. vertexes[4] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3391. // vertexes[4].X = pos.X + vertexes[4].X;
  3392. // vertexes[4].Y = pos.Y + vertexes[4].Y;
  3393. // vertexes[4].Z = pos.Z + vertexes[4].Z;
  3394. FaceB[1] = vertexes[4];
  3395. FaceA[2] = vertexes[4];
  3396. FaceD[4] = vertexes[4];
  3397. tScale = new Vector3(-AXscale.X, AXscale.Y, -AXscale.Z);
  3398. rScale = tScale * AXrot;
  3399. vertexes[5] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3400. // vertexes[5].X = pos.X + vertexes[5].X;
  3401. // vertexes[5].Y = pos.Y + vertexes[5].Y;
  3402. // vertexes[5].Z = pos.Z + vertexes[5].Z;
  3403. FaceD[1] = vertexes[5];
  3404. FaceC[2] = vertexes[5];
  3405. FaceB[5] = vertexes[5];
  3406. tScale = new Vector3(-AXscale.X, -AXscale.Y, AXscale.Z);
  3407. rScale = tScale * AXrot;
  3408. vertexes[6] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3409. // vertexes[6].X = pos.X + vertexes[6].X;
  3410. // vertexes[6].Y = pos.Y + vertexes[6].Y;
  3411. // vertexes[6].Z = pos.Z + vertexes[6].Z;
  3412. FaceB[2] = vertexes[6];
  3413. FaceA[3] = vertexes[6];
  3414. FaceB[4] = vertexes[6];
  3415. tScale = new Vector3(-AXscale.X, -AXscale.Y, -AXscale.Z);
  3416. rScale = tScale * AXrot;
  3417. vertexes[7] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3418. // vertexes[7].X = pos.X + vertexes[7].X;
  3419. // vertexes[7].Y = pos.Y + vertexes[7].Y;
  3420. // vertexes[7].Z = pos.Z + vertexes[7].Z;
  3421. FaceD[2] = vertexes[7];
  3422. FaceC[3] = vertexes[7];
  3423. FaceD[5] = vertexes[7];
  3424. #endregion
  3425. // Get our plane normals
  3426. for (int i = 0; i < 6; i++)
  3427. {
  3428. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  3429. // Our Plane direction
  3430. AmBa = FaceA[i] - FaceB[i];
  3431. AmBb = FaceB[i] - FaceC[i];
  3432. cross = Vector3.Cross(AmBb, AmBa);
  3433. // normalize the cross product to get the normal.
  3434. normals[i] = cross / cross.Length();
  3435. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  3436. //distance[i] = (normals[i].X * AmBa.X + normals[i].Y * AmBa.Y + normals[i].Z * AmBa.Z) * -1;
  3437. }
  3438. EntityIntersection result = new EntityIntersection();
  3439. result.distance = 1024;
  3440. float c = 0;
  3441. float a = 0;
  3442. float d = 0;
  3443. Vector3 q = new Vector3();
  3444. #region OBB Version 2 Experiment
  3445. //float fmin = 999999;
  3446. //float fmax = -999999;
  3447. //float s = 0;
  3448. //for (int i=0;i<6;i++)
  3449. //{
  3450. //s = iray.Direction.Dot(normals[i]);
  3451. //d = normals[i].Dot(FaceB[i]);
  3452. //if (s == 0)
  3453. //{
  3454. //if (iray.Origin.Dot(normals[i]) > d)
  3455. //{
  3456. //return result;
  3457. //}
  3458. // else
  3459. //{
  3460. //continue;
  3461. //}
  3462. //}
  3463. //a = (d - iray.Origin.Dot(normals[i])) / s;
  3464. //if (iray.Direction.Dot(normals[i]) < 0)
  3465. //{
  3466. //if (a > fmax)
  3467. //{
  3468. //if (a > fmin)
  3469. //{
  3470. //return result;
  3471. //}
  3472. //fmax = a;
  3473. //}
  3474. //}
  3475. //else
  3476. //{
  3477. //if (a < fmin)
  3478. //{
  3479. //if (a < 0 || a < fmax)
  3480. //{
  3481. //return result;
  3482. //}
  3483. //fmin = a;
  3484. //}
  3485. //}
  3486. //}
  3487. //if (fmax > 0)
  3488. // a= fmax;
  3489. //else
  3490. // a=fmin;
  3491. //q = iray.Origin + a * iray.Direction;
  3492. #endregion
  3493. // Loop over faces (6 of them)
  3494. for (int i = 0; i < 6; i++)
  3495. {
  3496. AmBa = FaceA[i] - FaceB[i];
  3497. AmBb = FaceB[i] - FaceC[i];
  3498. d = Vector3.Dot(normals[i], FaceB[i]);
  3499. //if (faceCenters)
  3500. //{
  3501. // c = normals[i].Dot(normals[i]);
  3502. //}
  3503. //else
  3504. //{
  3505. c = Vector3.Dot(iray.Direction, normals[i]);
  3506. //}
  3507. if (c == 0)
  3508. continue;
  3509. a = (d - Vector3.Dot(iray.Origin, normals[i])) / c;
  3510. if (a < 0)
  3511. continue;
  3512. // If the normal is pointing outside the object
  3513. if (Vector3.Dot(iray.Direction, normals[i]) < 0 || !frontFacesOnly)
  3514. {
  3515. //if (faceCenters)
  3516. //{ //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  3517. // q = iray.Origin + a * normals[i];
  3518. //}
  3519. //else
  3520. //{
  3521. q = iray.Origin + iray.Direction * a;
  3522. //}
  3523. float distance2 = (float)GetDistanceTo(q, AXpos);
  3524. // Is this the closest hit to the object's origin?
  3525. //if (faceCenters)
  3526. //{
  3527. // distance2 = (float)GetDistanceTo(q, iray.Origin);
  3528. //}
  3529. if (distance2 < result.distance)
  3530. {
  3531. result.distance = distance2;
  3532. result.HitTF = true;
  3533. result.ipoint = q;
  3534. //m_log.Info("[FACE]:" + i.ToString());
  3535. //m_log.Info("[POINT]: " + q.ToString());
  3536. //m_log.Info("[DIST]: " + distance2.ToString());
  3537. if (faceCenters)
  3538. {
  3539. result.normal = AAfacenormals[i] * AXrot;
  3540. Vector3 scaleComponent = AAfacenormals[i];
  3541. float ScaleOffset = 0.5f;
  3542. if (scaleComponent.X != 0) ScaleOffset = AXscale.X;
  3543. if (scaleComponent.Y != 0) ScaleOffset = AXscale.Y;
  3544. if (scaleComponent.Z != 0) ScaleOffset = AXscale.Z;
  3545. ScaleOffset = Math.Abs(ScaleOffset);
  3546. Vector3 offset = result.normal * ScaleOffset;
  3547. result.ipoint = AXpos + offset;
  3548. ///pos = (intersectionpoint + offset);
  3549. }
  3550. else
  3551. {
  3552. result.normal = normals[i];
  3553. }
  3554. result.AAfaceNormal = AAfacenormals[i];
  3555. }
  3556. }
  3557. }
  3558. return result;
  3559. }
  3560. /// <summary>
  3561. /// Serialize this part to xml.
  3562. /// </summary>
  3563. /// <param name="xmlWriter"></param>
  3564. public void ToXml(XmlTextWriter xmlWriter)
  3565. {
  3566. SceneObjectSerializer.SOPToXml2(xmlWriter, this, new Dictionary<string, object>());
  3567. }
  3568. public void TriggerScriptChangedEvent(Changed val)
  3569. {
  3570. if (m_parentGroup != null && m_parentGroup.Scene != null)
  3571. m_parentGroup.Scene.EventManager.TriggerOnScriptChangedEvent(LocalId, (uint)val);
  3572. }
  3573. public void TrimPermissions()
  3574. {
  3575. _baseMask &= (uint)PermissionMask.All;
  3576. _ownerMask &= (uint)PermissionMask.All;
  3577. _groupMask &= (uint)PermissionMask.All;
  3578. _everyoneMask &= (uint)PermissionMask.All;
  3579. _nextOwnerMask &= (uint)PermissionMask.All;
  3580. }
  3581. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  3582. {
  3583. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  3584. if (type == 0x30)
  3585. {
  3586. if (m_shape.SculptEntry && m_shape.SculptTexture != UUID.Zero)
  3587. {
  3588. m_parentGroup.Scene.AssetService.Get(m_shape.SculptTexture.ToString(), this, AssetReceived);
  3589. }
  3590. }
  3591. if (ParentGroup != null)
  3592. {
  3593. ParentGroup.HasGroupChanged = true;
  3594. ScheduleFullUpdate();
  3595. }
  3596. }
  3597. public void UpdateGroupPosition(Vector3 pos)
  3598. {
  3599. if ((pos.X != GroupPosition.X) ||
  3600. (pos.Y != GroupPosition.Y) ||
  3601. (pos.Z != GroupPosition.Z))
  3602. {
  3603. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  3604. GroupPosition = newPos;
  3605. ScheduleTerseUpdate();
  3606. }
  3607. }
  3608. public virtual void UpdateMovement()
  3609. {
  3610. }
  3611. /// <summary>
  3612. ///
  3613. /// </summary>
  3614. /// <param name="pos"></param>
  3615. public void UpdateOffSet(Vector3 pos)
  3616. {
  3617. if ((pos.X != OffsetPosition.X) ||
  3618. (pos.Y != OffsetPosition.Y) ||
  3619. (pos.Z != OffsetPosition.Z))
  3620. {
  3621. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  3622. if (ParentGroup.RootPart.GetStatusSandbox())
  3623. {
  3624. if (Util.GetDistanceTo(ParentGroup.RootPart.StatusSandboxPos, newPos) > 10)
  3625. {
  3626. ParentGroup.RootPart.ScriptSetPhysicsStatus(false);
  3627. newPos = OffsetPosition;
  3628. ParentGroup.Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3629. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, ParentGroup.RootPart.AbsolutePosition, Name, UUID, false);
  3630. }
  3631. }
  3632. OffsetPosition = newPos;
  3633. ScheduleTerseUpdate();
  3634. }
  3635. }
  3636. public void UpdatePermissions(UUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  3637. {
  3638. bool set = addRemTF == 1;
  3639. bool god = m_parentGroup.Scene.Permissions.IsGod(AgentID);
  3640. uint baseMask = _baseMask;
  3641. if (god)
  3642. baseMask = 0x7ffffff0;
  3643. // Are we the owner?
  3644. if ((AgentID == _ownerID) || god)
  3645. {
  3646. switch (field)
  3647. {
  3648. case 1:
  3649. if (god)
  3650. {
  3651. _baseMask = ApplyMask(_baseMask, set, mask);
  3652. Inventory.ApplyGodPermissions(_baseMask);
  3653. }
  3654. break;
  3655. case 2:
  3656. _ownerMask = ApplyMask(_ownerMask, set, mask) &
  3657. baseMask;
  3658. break;
  3659. case 4:
  3660. _groupMask = ApplyMask(_groupMask, set, mask) &
  3661. baseMask;
  3662. break;
  3663. case 8:
  3664. _everyoneMask = ApplyMask(_everyoneMask, set, mask) &
  3665. baseMask;
  3666. break;
  3667. case 16:
  3668. _nextOwnerMask = ApplyMask(_nextOwnerMask, set, mask) &
  3669. baseMask;
  3670. // Prevent the client from creating no mod, no copy
  3671. // objects
  3672. if ((_nextOwnerMask & (uint)PermissionMask.Copy) == 0)
  3673. _nextOwnerMask |= (uint)PermissionMask.Transfer;
  3674. _nextOwnerMask |= (uint)PermissionMask.Move;
  3675. break;
  3676. }
  3677. SendFullUpdateToAllClients();
  3678. SendObjectPropertiesToClient(AgentID);
  3679. }
  3680. }
  3681. public bool IsHingeJoint()
  3682. {
  3683. // For now, we use the NINJA naming scheme for identifying joints.
  3684. // In the future, we can support other joint specification schemes such as a
  3685. // custom checkbox in the viewer GUI.
  3686. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3687. {
  3688. string hingeString = "hingejoint";
  3689. return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
  3690. }
  3691. else
  3692. {
  3693. return false;
  3694. }
  3695. }
  3696. public bool IsBallJoint()
  3697. {
  3698. // For now, we use the NINJA naming scheme for identifying joints.
  3699. // In the future, we can support other joint specification schemes such as a
  3700. // custom checkbox in the viewer GUI.
  3701. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3702. {
  3703. string ballString = "balljoint";
  3704. return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
  3705. }
  3706. else
  3707. {
  3708. return false;
  3709. }
  3710. }
  3711. public bool IsJoint()
  3712. {
  3713. // For now, we use the NINJA naming scheme for identifying joints.
  3714. // In the future, we can support other joint specification schemes such as a
  3715. // custom checkbox in the viewer GUI.
  3716. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3717. {
  3718. return IsHingeJoint() || IsBallJoint();
  3719. }
  3720. else
  3721. {
  3722. return false;
  3723. }
  3724. }
  3725. /// <summary>
  3726. /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
  3727. /// </summary>
  3728. /// <param name="UsePhysics"></param>
  3729. /// <param name="SetTemporary"></param>
  3730. /// <param name="SetPhantom"></param>
  3731. /// <param name="SetVD"></param>
  3732. public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD)
  3733. {
  3734. bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
  3735. bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
  3736. bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0);
  3737. bool wasVD = VolumeDetectActive;
  3738. if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
  3739. {
  3740. return;
  3741. }
  3742. // Special cases for VD. VD can only be called from a script
  3743. // and can't be combined with changes to other states. So we can rely
  3744. // that...
  3745. // ... if VD is changed, all others are not.
  3746. // ... if one of the others is changed, VD is not.
  3747. if (SetVD) // VD is active, special logic applies
  3748. {
  3749. // State machine logic for VolumeDetect
  3750. // More logic below
  3751. bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
  3752. if (phanReset) // Phantom changes from on to off switch VD off too
  3753. {
  3754. SetVD = false; // Switch it of for the course of this routine
  3755. VolumeDetectActive = false; // and also permanently
  3756. if (PhysActor != null)
  3757. PhysActor.SetVolumeDetect(0); // Let physics know about it too
  3758. }
  3759. else
  3760. {
  3761. // If volumedetect is active we don't want phantom to be applied.
  3762. // If this is a new call to VD out of the state "phantom"
  3763. // this will also cause the prim to be visible to physics
  3764. SetPhantom = false;
  3765. }
  3766. }
  3767. if (UsePhysics && IsJoint())
  3768. {
  3769. SetPhantom = true;
  3770. }
  3771. if (UsePhysics)
  3772. {
  3773. AddFlag(PrimFlags.Physics);
  3774. if (!wasUsingPhysics)
  3775. {
  3776. DoPhysicsPropertyUpdate(UsePhysics, false);
  3777. if (!m_parentGroup.IsDeleted)
  3778. {
  3779. if (LocalId == m_parentGroup.RootPart.LocalId)
  3780. {
  3781. m_parentGroup.CheckSculptAndLoad();
  3782. }
  3783. }
  3784. }
  3785. }
  3786. else
  3787. {
  3788. RemFlag(PrimFlags.Physics);
  3789. if (wasUsingPhysics)
  3790. {
  3791. DoPhysicsPropertyUpdate(UsePhysics, false);
  3792. }
  3793. }
  3794. if (SetPhantom
  3795. || ParentGroup.IsAttachment
  3796. || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
  3797. {
  3798. AddFlag(PrimFlags.Phantom);
  3799. if (PhysActor != null)
  3800. {
  3801. m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  3802. /// that's not wholesome. Had to make Scene public
  3803. PhysActor = null;
  3804. }
  3805. }
  3806. else // Not phantom
  3807. {
  3808. RemFlag(PrimFlags.Phantom);
  3809. if (ParentGroup.Scene == null)
  3810. return;
  3811. PhysicsActor pa = PhysActor;
  3812. if (pa == null)
  3813. {
  3814. // It's not phantom anymore. So make sure the physics engine get's knowledge of it
  3815. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  3816. string.Format("{0}/{1}", Name, UUID),
  3817. Shape,
  3818. AbsolutePosition,
  3819. Scale,
  3820. RotationOffset,
  3821. UsePhysics,
  3822. m_localId);
  3823. pa = PhysActor;
  3824. if (pa != null)
  3825. {
  3826. PhysActor.SetMaterial(Material);
  3827. DoPhysicsPropertyUpdate(UsePhysics, true);
  3828. if (!m_parentGroup.IsDeleted)
  3829. {
  3830. if (LocalId == m_parentGroup.RootPart.LocalId)
  3831. {
  3832. m_parentGroup.CheckSculptAndLoad();
  3833. }
  3834. }
  3835. if (
  3836. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  3837. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  3838. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  3839. ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
  3840. ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
  3841. ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
  3842. (CollisionSound != UUID.Zero)
  3843. )
  3844. {
  3845. PhysActor.OnCollisionUpdate += PhysicsCollision;
  3846. PhysActor.SubscribeEvents(1000);
  3847. }
  3848. }
  3849. }
  3850. else // it already has a physical representation
  3851. {
  3852. pa.IsPhysical = UsePhysics;
  3853. DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
  3854. if (!m_parentGroup.IsDeleted)
  3855. {
  3856. if (LocalId == m_parentGroup.RootPart.LocalId)
  3857. {
  3858. m_parentGroup.CheckSculptAndLoad();
  3859. }
  3860. }
  3861. }
  3862. }
  3863. if (SetVD)
  3864. {
  3865. // If the above logic worked (this is urgent candidate to unit tests!)
  3866. // we now have a physicsactor.
  3867. // Defensive programming calls for a check here.
  3868. // Better would be throwing an exception that could be catched by a unit test as the internal
  3869. // logic should make sure, this Physactor is always here.
  3870. if (this.PhysActor != null)
  3871. {
  3872. PhysActor.SetVolumeDetect(1);
  3873. AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
  3874. this.VolumeDetectActive = true;
  3875. }
  3876. }
  3877. else
  3878. {
  3879. // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
  3880. // (mumbles, well, at least if you have infinte CPU powers :-))
  3881. PhysicsActor pa = this.PhysActor;
  3882. if (pa != null)
  3883. {
  3884. PhysActor.SetVolumeDetect(0);
  3885. }
  3886. this.VolumeDetectActive = false;
  3887. }
  3888. if (SetTemporary)
  3889. {
  3890. AddFlag(PrimFlags.TemporaryOnRez);
  3891. }
  3892. else
  3893. {
  3894. RemFlag(PrimFlags.TemporaryOnRez);
  3895. }
  3896. // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  3897. if (ParentGroup != null)
  3898. {
  3899. ParentGroup.HasGroupChanged = true;
  3900. ScheduleFullUpdate();
  3901. }
  3902. // m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
  3903. }
  3904. public void UpdateRotation(Quaternion rot)
  3905. {
  3906. if ((rot.X != RotationOffset.X) ||
  3907. (rot.Y != RotationOffset.Y) ||
  3908. (rot.Z != RotationOffset.Z) ||
  3909. (rot.W != RotationOffset.W))
  3910. {
  3911. RotationOffset = rot;
  3912. if (ParentGroup != null)
  3913. {
  3914. ParentGroup.HasGroupChanged = true;
  3915. ScheduleTerseUpdate();
  3916. }
  3917. }
  3918. }
  3919. /// <summary>
  3920. /// Update the shape of this part.
  3921. /// </summary>
  3922. /// <param name="shapeBlock"></param>
  3923. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  3924. {
  3925. m_shape.PathBegin = shapeBlock.PathBegin;
  3926. m_shape.PathEnd = shapeBlock.PathEnd;
  3927. m_shape.PathScaleX = shapeBlock.PathScaleX;
  3928. m_shape.PathScaleY = shapeBlock.PathScaleY;
  3929. m_shape.PathShearX = shapeBlock.PathShearX;
  3930. m_shape.PathShearY = shapeBlock.PathShearY;
  3931. m_shape.PathSkew = shapeBlock.PathSkew;
  3932. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  3933. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  3934. m_shape.PathCurve = shapeBlock.PathCurve;
  3935. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  3936. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  3937. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  3938. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  3939. m_shape.PathTaperX = shapeBlock.PathTaperX;
  3940. m_shape.PathTaperY = shapeBlock.PathTaperY;
  3941. m_shape.PathTwist = shapeBlock.PathTwist;
  3942. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  3943. if (PhysActor != null)
  3944. {
  3945. PhysActor.Shape = m_shape;
  3946. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  3947. }
  3948. // This is what makes vehicle trailers work
  3949. // A script in a child prim re-issues
  3950. // llSetPrimitiveParams(PRIM_TYPE) every few seconds. That
  3951. // prevents autoreturn. This is not well known. It also works
  3952. // in SL.
  3953. //
  3954. if (ParentGroup.RootPart != this)
  3955. ParentGroup.RootPart.Rezzed = DateTime.UtcNow;
  3956. ParentGroup.HasGroupChanged = true;
  3957. TriggerScriptChangedEvent(Changed.SHAPE);
  3958. ScheduleFullUpdate();
  3959. }
  3960. /// <summary>
  3961. /// If the part is a sculpt/mesh, retrieve the mesh data and reinsert it into the shape so that the physics
  3962. /// engine can use it.
  3963. /// </summary>
  3964. /// <remarks>
  3965. /// When the physics engine has finished with it, the sculpt data is discarded to save memory.
  3966. /// </remarks>
  3967. public void CheckSculptAndLoad()
  3968. {
  3969. // m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
  3970. if (ParentGroup.IsDeleted)
  3971. return;
  3972. if ((ParentGroup.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  3973. return;
  3974. if (Shape.SculptEntry && Shape.SculptTexture != UUID.Zero)
  3975. {
  3976. // check if a previously decoded sculpt map has been cached
  3977. // We don't read the file here - the meshmerizer will do that later.
  3978. // TODO: Could we simplify the meshmerizer code by reading and setting the data here?
  3979. if (File.Exists(System.IO.Path.Combine("j2kDecodeCache", "smap_" + Shape.SculptTexture.ToString())))
  3980. {
  3981. SculptTextureCallback(null);
  3982. }
  3983. else
  3984. {
  3985. ParentGroup.Scene.AssetService.Get(Shape.SculptTexture.ToString(), this, AssetReceived);
  3986. }
  3987. }
  3988. }
  3989. /// <summary>
  3990. /// Update the textures on the part.
  3991. /// </summary>
  3992. /// <remarks>
  3993. /// Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  3994. /// not handling RGBA properly. Cycles through, and "fixes" the color
  3995. /// info
  3996. /// </remarks>
  3997. /// <param name="tex"></param>
  3998. public void UpdateTexture(Primitive.TextureEntry tex)
  3999. {
  4000. //Color4 tmpcolor;
  4001. //for (uint i = 0; i < 32; i++)
  4002. //{
  4003. // if (tex.FaceTextures[i] != null)
  4004. // {
  4005. // tmpcolor = tex.GetFace((uint) i).RGBA;
  4006. // tmpcolor.A = tmpcolor.A*255;
  4007. // tmpcolor.R = tmpcolor.R*255;
  4008. // tmpcolor.G = tmpcolor.G*255;
  4009. // tmpcolor.B = tmpcolor.B*255;
  4010. // tex.FaceTextures[i].RGBA = tmpcolor;
  4011. // }
  4012. //}
  4013. //tmpcolor = tex.DefaultTexture.RGBA;
  4014. //tmpcolor.A = tmpcolor.A*255;
  4015. //tmpcolor.R = tmpcolor.R*255;
  4016. //tmpcolor.G = tmpcolor.G*255;
  4017. //tmpcolor.B = tmpcolor.B*255;
  4018. //tex.DefaultTexture.RGBA = tmpcolor;
  4019. UpdateTextureEntry(tex.GetBytes());
  4020. }
  4021. /// <summary>
  4022. /// Update the texture entry for this part.
  4023. /// </summary>
  4024. /// <param name="textureEntry"></param>
  4025. public void UpdateTextureEntry(byte[] textureEntry)
  4026. {
  4027. m_shape.TextureEntry = textureEntry;
  4028. TriggerScriptChangedEvent(Changed.TEXTURE);
  4029. ParentGroup.HasGroupChanged = true;
  4030. //This is madness..
  4031. //ParentGroup.ScheduleGroupForFullUpdate();
  4032. //This is sparta
  4033. ScheduleFullUpdate();
  4034. }
  4035. public void aggregateScriptEvents()
  4036. {
  4037. AggregateScriptEvents = 0;
  4038. // Aggregate script events
  4039. lock (m_scriptEvents)
  4040. {
  4041. foreach (scriptEvents s in m_scriptEvents.Values)
  4042. {
  4043. AggregateScriptEvents |= s;
  4044. }
  4045. }
  4046. uint objectflagupdate = 0;
  4047. if (
  4048. ((AggregateScriptEvents & scriptEvents.touch) != 0) ||
  4049. ((AggregateScriptEvents & scriptEvents.touch_end) != 0) ||
  4050. ((AggregateScriptEvents & scriptEvents.touch_start) != 0)
  4051. )
  4052. {
  4053. objectflagupdate |= (uint) PrimFlags.Touch;
  4054. }
  4055. if ((AggregateScriptEvents & scriptEvents.money) != 0)
  4056. {
  4057. objectflagupdate |= (uint) PrimFlags.Money;
  4058. }
  4059. if (AllowedDrop)
  4060. {
  4061. objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
  4062. }
  4063. if (
  4064. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  4065. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  4066. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  4067. ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
  4068. ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
  4069. ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
  4070. (CollisionSound != UUID.Zero)
  4071. )
  4072. {
  4073. // subscribe to physics updates.
  4074. if (PhysActor != null)
  4075. {
  4076. PhysActor.OnCollisionUpdate += PhysicsCollision;
  4077. PhysActor.SubscribeEvents(1000);
  4078. }
  4079. }
  4080. else
  4081. {
  4082. if (PhysActor != null)
  4083. {
  4084. PhysActor.UnSubscribeEvents();
  4085. PhysActor.OnCollisionUpdate -= PhysicsCollision;
  4086. }
  4087. }
  4088. //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
  4089. //{
  4090. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting;
  4091. //}
  4092. //else
  4093. //{
  4094. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent -= handleTimerAccounting;
  4095. //}
  4096. LocalFlags = (PrimFlags)objectflagupdate;
  4097. if (m_parentGroup != null && m_parentGroup.RootPart == this)
  4098. {
  4099. m_parentGroup.aggregateScriptEvents();
  4100. }
  4101. else
  4102. {
  4103. // m_log.DebugFormat(
  4104. // "[SCENE OBJECT PART]: Scheduling part {0} {1} for full update in aggregateScriptEvents()", Name, LocalId);
  4105. ScheduleFullUpdate();
  4106. }
  4107. }
  4108. public void SetCameraAtOffset(Vector3 v)
  4109. {
  4110. m_cameraAtOffset = v;
  4111. }
  4112. public void SetCameraEyeOffset(Vector3 v)
  4113. {
  4114. m_cameraEyeOffset = v;
  4115. }
  4116. public void SetForceMouselook(bool force)
  4117. {
  4118. m_forceMouselook = force;
  4119. }
  4120. public Vector3 GetCameraAtOffset()
  4121. {
  4122. return m_cameraAtOffset;
  4123. }
  4124. public Vector3 GetCameraEyeOffset()
  4125. {
  4126. return m_cameraEyeOffset;
  4127. }
  4128. public bool GetForceMouselook()
  4129. {
  4130. return m_forceMouselook;
  4131. }
  4132. public override string ToString()
  4133. {
  4134. return String.Format("{0} {1} (parent {2}))", Name, UUID, ParentGroup);
  4135. }
  4136. #endregion Public Methods
  4137. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  4138. {
  4139. if (ParentGroup.IsDeleted)
  4140. return;
  4141. if (ParentGroup.IsAttachment && ParentGroup.RootPart != this)
  4142. return;
  4143. // Causes this thread to dig into the Client Thread Data.
  4144. // Remember your locking here!
  4145. remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity);
  4146. }
  4147. public void AddScriptLPS(int count)
  4148. {
  4149. m_parentGroup.AddScriptLPS(count);
  4150. }
  4151. public void ApplyNextOwnerPermissions()
  4152. {
  4153. _baseMask &= _nextOwnerMask;
  4154. _ownerMask &= _nextOwnerMask;
  4155. _everyoneMask &= _nextOwnerMask;
  4156. Inventory.ApplyNextOwnerPermissions();
  4157. }
  4158. public void UpdateLookAt()
  4159. {
  4160. try
  4161. {
  4162. if (APIDTarget != Quaternion.Identity)
  4163. {
  4164. if (Single.IsNaN(APIDTarget.W) == true)
  4165. {
  4166. APIDTarget = Quaternion.Identity;
  4167. return;
  4168. }
  4169. Quaternion rot = RotationOffset;
  4170. Quaternion dir = (rot - APIDTarget);
  4171. float speed = ((APIDStrength / APIDDamp) * (float)(Math.PI / 180.0f));
  4172. if (dir.Z > speed)
  4173. {
  4174. rot.Z -= speed;
  4175. }
  4176. if (dir.Z < -speed)
  4177. {
  4178. rot.Z += speed;
  4179. }
  4180. rot.Normalize();
  4181. UpdateRotation(rot);
  4182. }
  4183. }
  4184. catch (Exception ex)
  4185. {
  4186. m_log.Error("[Physics] " + ex);
  4187. }
  4188. }
  4189. public Color4 GetTextColor()
  4190. {
  4191. Color color = Color;
  4192. return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
  4193. }
  4194. }
  4195. }