SceneObjectPart.cs 180 KB

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