1
0

SceneObjectPart.cs 175 KB

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