SceneObjectPart.cs 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858
  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.Threading;
  33. using System.Text;
  34. using System.Xml;
  35. using System.Xml.Serialization;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using OpenSim.Region.PhysicsModules.SharedBase;
  43. using PermissionMask = OpenSim.Framework.PermissionMask;
  44. namespace OpenSim.Region.Framework.Scenes
  45. {
  46. #region Enumerations
  47. [Flags]
  48. public enum Changed : uint
  49. {
  50. INVENTORY = 1,
  51. COLOR = 2,
  52. SHAPE = 4,
  53. SCALE = 8,
  54. TEXTURE = 16,
  55. LINK = 32,
  56. ALLOWED_DROP = 64,
  57. OWNER = 128,
  58. REGION = 256,
  59. TELEPORT = 512,
  60. REGION_RESTART = 1024,
  61. MEDIA = 2048,
  62. ANIMATION = 16384,
  63. POSITION = 32768
  64. }
  65. [Flags]
  66. public enum TextureAnimFlags : byte
  67. {
  68. NONE = 0x00,
  69. ANIM_ON = 0x01,
  70. LOOP = 0x02,
  71. REVERSE = 0x04,
  72. PING_PONG = 0x08,
  73. SMOOTH = 0x10,
  74. ROTATE = 0x20,
  75. SCALE = 0x40
  76. }
  77. public enum PrimType : int
  78. {
  79. BOX = 0,
  80. CYLINDER = 1,
  81. PRISM = 2,
  82. SPHERE = 3,
  83. TORUS = 4,
  84. TUBE = 5,
  85. RING = 6,
  86. SCULPT = 7
  87. }
  88. #endregion Enumerations
  89. public class SceneObjectPart : ISceneEntity, IDisposable
  90. {
  91. /// <value>
  92. /// Denote all sides of the prim
  93. /// </value>
  94. public const int ALL_SIDES = -1;
  95. private const scriptEvents PhysicsNeededSubsEvents = (
  96. scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
  97. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
  98. );
  99. private const scriptEvents PhyscicsPhantonSubsEvents = (
  100. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
  101. );
  102. private const scriptEvents PhyscicsVolumeDtcSubsEvents = (
  103. scriptEvents.collision_start | scriptEvents.collision_end
  104. );
  105. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  106. /// <summary>
  107. /// Dynamic attributes can be created and deleted as required.
  108. /// </summary>
  109. public DAMap DynAttrs { get; set; }
  110. private DOMap m_dynObjs;
  111. /// <summary>
  112. /// Dynamic objects that can be created and deleted as required.
  113. /// </summary>
  114. public DOMap DynObjs
  115. {
  116. get
  117. {
  118. if (m_dynObjs == null)
  119. m_dynObjs = new DOMap();
  120. return m_dynObjs;
  121. }
  122. set
  123. {
  124. m_dynObjs = value;
  125. }
  126. }
  127. /// <value>
  128. /// Is this a root part?
  129. /// </value>
  130. /// <remarks>
  131. /// This will return true even if the whole object is attached to an avatar.
  132. /// </remarks>
  133. public bool IsRoot
  134. {
  135. get { return Object.ReferenceEquals(ParentGroup.RootPart, this); }
  136. }
  137. /// <summary>
  138. /// Is an explicit sit target set for this part?
  139. /// </summary>
  140. public bool IsSitTargetSet
  141. {
  142. get
  143. {
  144. // assume SitTargetOrientation is normalized (as needed elsewhere)
  145. if( SitTargetPosition != Vector3.Zero ||
  146. SitTargetOrientation.X != 0f ||
  147. SitTargetOrientation.Y != 0f ||
  148. SitTargetOrientation.Z != 0f)
  149. return true;
  150. return false;
  151. }
  152. }
  153. #region Fields
  154. public bool AllowedDrop;
  155. public bool DIE_AT_EDGE;
  156. public bool RETURN_AT_EDGE;
  157. public bool BlockGrab { get; set; }
  158. public bool StatusSandbox;
  159. public Vector3 StatusSandboxPos;
  160. [XmlIgnore]
  161. public int PseudoCRC; // this is local to region. should only be stored on its db.
  162. // This is just a number that needs to change to invalidate prim data caches
  163. [XmlIgnore]
  164. public int[] PayPrice = {-2,-2,-2,-2,-2};
  165. [XmlIgnore]
  166. /// <summary>
  167. /// The representation of this part in the physics scene.
  168. /// </summary>
  169. /// <remarks>
  170. /// If you use this property more than once in a section of code then you must take a reference and use that.
  171. /// If another thread is simultaneously turning physics off on this part then this refernece could become
  172. /// null at any time.
  173. /// </remarks>
  174. public PhysicsActor PhysActor { get; set; }
  175. //Xantor 20080528 Sound stuff:
  176. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  177. // Not a big problem as long as the script that sets it remains in the prim on startup.
  178. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  179. public UUID Sound;
  180. public byte SoundFlags;
  181. public double SoundGain;
  182. public double SoundRadius;
  183. /// <summary>
  184. /// Should sounds played from this prim be queued?
  185. /// </summary>
  186. /// <remarks>
  187. /// This should only be changed by sound modules. It is up to sound modules as to how they interpret this setting.
  188. /// </remarks>
  189. public bool SoundQueueing { get; set; }
  190. [XmlIgnore]
  191. public Quaternion AttachRotation = Quaternion.Identity;
  192. [XmlIgnore]
  193. public int STATUS_ROTATE_X; // this should not be used
  194. [XmlIgnore]
  195. public int STATUS_ROTATE_Y; // this should not be used
  196. [XmlIgnore]
  197. public int STATUS_ROTATE_Z; // this should not be used
  198. private Dictionary<int, string> m_CollisionFilter = new Dictionary<int, string>();
  199. /// <value>
  200. /// The UUID of the user inventory item from which this object was rezzed if this is a root part.
  201. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item.
  202. /// </value>
  203. private UUID m_fromUserInventoryItemID;
  204. public UUID FromUserInventoryItemID
  205. {
  206. get { return m_fromUserInventoryItemID; }
  207. set { m_fromUserInventoryItemID = value; }
  208. }
  209. public scriptEvents AggregatedScriptEvents;
  210. public Vector3 AttachedPos { get; set; }
  211. // rotation locks on local X,Y and or Z axis bit flags
  212. // bits are as in llSetStatus defined in SceneObjectGroup.axisSelect enum
  213. // but reversed logic: bit cleared means free to rotate
  214. public byte RotationAxisLocks = 0;
  215. // WRONG flag in libOmvPrimFlags
  216. private const uint primFlagVolumeDetect = (uint)PrimFlags.JointLP2P;
  217. public bool VolumeDetectActive
  218. {
  219. get
  220. {
  221. return (Flags & (PrimFlags)primFlagVolumeDetect) != 0;
  222. }
  223. set
  224. {
  225. if(value)
  226. Flags |= (PrimFlags)primFlagVolumeDetect;
  227. else
  228. Flags &= (PrimFlags)(~primFlagVolumeDetect);
  229. }
  230. }
  231. public bool IsWaitingForFirstSpinUpdatePacket;
  232. public Quaternion SpinOldOrientation = Quaternion.Identity;
  233. protected bool m_APIDActive = false;
  234. protected Quaternion m_APIDTarget = Quaternion.Identity;
  235. protected float m_APIDDamp = 0;
  236. protected float m_APIDStrength = 0;
  237. /// <summary>
  238. /// This part's inventory
  239. /// </summary>
  240. public IEntityInventory Inventory
  241. {
  242. get { return m_inventory; }
  243. }
  244. protected SceneObjectPartInventory m_inventory;
  245. public bool Undoing;
  246. public bool IgnoreUndoUpdate = false;
  247. public PrimFlags LocalFlags;
  248. private float m_damage = -1.0f;
  249. private byte[] m_TextureAnimation;
  250. private byte m_clickAction;
  251. private Color m_color = Color.Black;
  252. private List<uint> m_lastColliders = new List<uint>();
  253. private bool m_lastLandCollide;
  254. private int m_linkNum;
  255. private int m_scriptAccessPin;
  256. private readonly Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  257. private string m_sitName = String.Empty;
  258. private Quaternion m_sitTargetOrientation = Quaternion.Identity;
  259. private Vector3 m_sitTargetPosition;
  260. private string m_sitAnimation = "SIT";
  261. private string m_text = String.Empty;
  262. private string m_touchName = String.Empty;
  263. private UndoRedoState m_UndoRedo = null;
  264. private object m_UndoLock = new object();
  265. private bool m_passTouches = false;
  266. private bool m_passCollisions = false;
  267. protected Vector3 m_acceleration;
  268. protected Vector3 m_angularVelocity;
  269. //unkown if this will be kept, added as a way of removing the group position from the group class
  270. protected Vector3 m_groupPosition;
  271. protected uint m_localId;
  272. protected Material m_material = OpenMetaverse.Material.Wood;
  273. protected string m_name;
  274. protected Vector3 m_offsetPosition;
  275. protected SceneObjectGroup m_parentGroup;
  276. protected byte[] m_particleSystem = Utils.EmptyBytes;
  277. protected ulong m_regionHandle;
  278. protected Quaternion m_rotationOffset = Quaternion.Identity;
  279. protected PrimitiveBaseShape m_shape;
  280. protected UUID m_uuid;
  281. protected Vector3 m_velocity;
  282. protected Vector3 m_lastPosition;
  283. protected Quaternion m_lastRotation;
  284. protected Vector3 m_lastVelocity;
  285. protected Vector3 m_lastAcceleration; // acceleration is a derived var with high noise
  286. protected Vector3 m_lastAngularVelocity;
  287. protected double m_lastUpdateSentTime;
  288. protected float m_buoyancy = 0.0f;
  289. protected Vector3 m_force;
  290. protected Vector3 m_torque;
  291. protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
  292. protected float m_density = 1000.0f; // in kg/m^3
  293. protected float m_gravitymod = 1.0f;
  294. protected float m_friction = 0.6f; // wood
  295. protected float m_bounce = 0.5f; // wood
  296. protected bool m_isSelected = false;
  297. /// <summary>
  298. /// Stores media texture data
  299. /// </summary>
  300. protected string m_mediaUrl;
  301. // TODO: Those have to be changed into persistent properties at some later point,
  302. // or sit-camera on vehicles will break on sim-crossing.
  303. private Vector3 m_cameraEyeOffset;
  304. private Vector3 m_cameraAtOffset;
  305. private bool m_forceMouselook;
  306. // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
  307. private sbyte m_collisionSoundType = 0;
  308. private UUID m_collisionSound;
  309. private float m_collisionSoundVolume;
  310. private int LastColSoundSentTime;
  311. private SOPVehicle m_vehicleParams = null;
  312. private PhysicsInertiaData m_physicsInertia;
  313. public KeyframeMotion KeyframeMotion
  314. {
  315. get; set;
  316. }
  317. #endregion Fields
  318. // ~SceneObjectPart()
  319. // {
  320. // Console.WriteLine(
  321. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  322. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  323. // m_log.DebugFormat(
  324. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  325. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  326. // }
  327. #region Constructors
  328. /// <summary>
  329. /// No arg constructor called by region restore db code
  330. /// </summary>
  331. public SceneObjectPart()
  332. {
  333. m_TextureAnimation = Utils.EmptyBytes;
  334. m_particleSystem = Utils.EmptyBytes;
  335. Rezzed = DateTime.UtcNow;
  336. Description = String.Empty;
  337. PseudoCRC = (int)DateTime.UtcNow.Ticks; // random could be as good; fallbak if not on region db
  338. m_inventory = new SceneObjectPartInventory(this);
  339. LastColSoundSentTime = Util.EnvironmentTickCount();
  340. }
  341. /// <summary>
  342. /// Create a completely new SceneObjectPart (prim). This will need to be added separately to a SceneObjectGroup
  343. /// </summary>
  344. /// <param name="ownerID"></param>
  345. /// <param name="shape"></param>
  346. /// <param name="position"></param>
  347. /// <param name="rotationOffset"></param>
  348. /// <param name="offsetPosition"></param>
  349. public SceneObjectPart(
  350. UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
  351. Quaternion rotationOffset, Vector3 offsetPosition) : this()
  352. {
  353. m_name = "Object";
  354. CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
  355. RezzerID = LastOwnerID = CreatorID = OwnerID = ownerID;
  356. UUID = UUID.Random();
  357. Shape = shape;
  358. OwnershipCost = 0;
  359. ObjectSaleType = 0;
  360. SalePrice = 0;
  361. Category = 0;
  362. GroupPosition = groupPosition;
  363. OffsetPosition = offsetPosition;
  364. RotationOffset = rotationOffset;
  365. Velocity = Vector3.Zero;
  366. AngularVelocity = Vector3.Zero;
  367. Acceleration = Vector3.Zero;
  368. APIDActive = false;
  369. Flags = 0;
  370. CreateSelected = false;
  371. TrimPermissions();
  372. AggregateInnerPerms();
  373. }
  374. ~SceneObjectPart()
  375. {
  376. Dispose(false);
  377. }
  378. private bool disposed = false;
  379. public void Dispose()
  380. {
  381. Dispose(true);
  382. GC.SuppressFinalize(this);
  383. }
  384. protected void Dispose(bool disposing)
  385. {
  386. // Check to see if Dispose has already been called.
  387. if (!disposed)
  388. {
  389. if (KeyframeMotion != null)
  390. {
  391. KeyframeMotion.Delete();
  392. KeyframeMotion = null;
  393. }
  394. if (PhysActor != null)
  395. RemoveFromPhysics();
  396. if (m_inventory != null)
  397. {
  398. m_inventory.Dispose();
  399. m_inventory = null;
  400. }
  401. disposed = true;
  402. }
  403. }
  404. #endregion Constructors
  405. #region XML Schema
  406. private UUID _rezzerID;
  407. private UUID _lastOwnerID;
  408. private UUID _ownerID;
  409. private UUID _groupID;
  410. private int _ownershipCost;
  411. private byte _objectSaleType;
  412. private int _salePrice;
  413. private uint _category;
  414. private Int32 _creationDate;
  415. private uint _parentID = 0;
  416. private uint _baseMask = (uint)(PermissionMask.All | PermissionMask.Export);
  417. private uint _ownerMask = (uint)(PermissionMask.All | PermissionMask.Export);
  418. private uint _groupMask = (uint)PermissionMask.None;
  419. private uint _everyoneMask = (uint)PermissionMask.None;
  420. private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Transfer);
  421. private PrimFlags _flags = PrimFlags.None;
  422. private DateTime m_expires;
  423. private DateTime m_rezzed;
  424. private bool m_createSelected = false;
  425. private UUID _creatorID;
  426. public UUID CreatorID
  427. {
  428. get { return _creatorID; }
  429. set { _creatorID = value; }
  430. }
  431. private string m_creatorData = string.Empty;
  432. /// <summary>
  433. /// Data about the creator in the form home_url;name
  434. /// </summary>
  435. public string CreatorData
  436. {
  437. get { return m_creatorData; }
  438. set { m_creatorData = value; }
  439. }
  440. /// <summary>
  441. /// Used by the DB layer to retrieve / store the entire user identification.
  442. /// The identification can either be a simple UUID or a string of the form
  443. /// uuid[;home_url[;name]]
  444. /// </summary>
  445. public string CreatorIdentification
  446. {
  447. get
  448. {
  449. if (!string.IsNullOrEmpty(CreatorData))
  450. return CreatorID.ToString() + ';' + CreatorData;
  451. else
  452. return CreatorID.ToString();
  453. }
  454. set
  455. {
  456. CreatorData = string.Empty;
  457. if ((value == null) || (value != null && value == string.Empty))
  458. return;
  459. // value is uuid or uuid;homeuri;firstname lastname
  460. string[] parts = value.Split(';');
  461. if (parts.Length > 0)
  462. {
  463. UUID uuid = UUID.Zero;
  464. UUID.TryParse(parts[0], out uuid);
  465. CreatorID = uuid;
  466. if (parts.Length > 1)
  467. {
  468. CreatorData = parts[1];
  469. if (!CreatorData.EndsWith("/"))
  470. CreatorData += "/";
  471. if (parts.Length > 2)
  472. CreatorData += ';' + parts[2];
  473. else
  474. CreatorData += ";Unknown User";
  475. }
  476. }
  477. }
  478. }
  479. /// <summary>
  480. /// A relic from when we we thought that prims contained folder objects. In
  481. /// reality, prim == folder
  482. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  483. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  484. /// </summary>
  485. public UUID FolderID
  486. {
  487. get { return UUID; }
  488. set { } // Don't allow assignment, or legacy prims wil b0rk - but we need the setter for legacy serialization.
  489. }
  490. /// <value>
  491. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  492. /// </value>
  493. public uint InventorySerial
  494. {
  495. get { return m_inventory.Serial; }
  496. set { m_inventory.Serial = value; }
  497. }
  498. /// <value>
  499. /// Get the inventory list
  500. /// </value>
  501. public TaskInventoryDictionary TaskInventory
  502. {
  503. get {
  504. return m_inventory.Items;
  505. }
  506. set {
  507. m_inventory.Items = value;
  508. }
  509. }
  510. /// <summary>
  511. /// This is idential to the Flags property, except that the returned value is uint rather than PrimFlags
  512. /// </summary>
  513. [Obsolete("Use Flags property instead")]
  514. public uint ObjectFlags
  515. {
  516. get { return (uint)Flags; }
  517. set { Flags = (PrimFlags)value; }
  518. }
  519. public UUID UUID
  520. {
  521. get { return m_uuid; }
  522. set
  523. {
  524. m_uuid = value;
  525. // This is necessary so that TaskInventoryItem parent ids correctly reference the new uuid of this part
  526. if (Inventory != null)
  527. Inventory.ResetObjectID();
  528. }
  529. }
  530. public uint LocalId
  531. {
  532. get { return m_localId; }
  533. set
  534. {
  535. m_localId = value;
  536. // m_log.DebugFormat("[SCENE OBJECT PART]: Set part {0} to local id {1}", Name, m_localId);
  537. }
  538. }
  539. public virtual string Name
  540. {
  541. get { return m_name; }
  542. set
  543. {
  544. m_name = value;
  545. if(ParentGroup != null)
  546. ParentGroup.InvalidatePartsLinkMaps();
  547. PhysicsActor pa = PhysActor;
  548. if (pa != null)
  549. pa.SOPName = value;
  550. }
  551. }
  552. [XmlIgnore]
  553. public bool PassTouches
  554. {
  555. get { return m_passTouches; }
  556. set
  557. {
  558. m_passTouches = value;
  559. if (ParentGroup != null)
  560. ParentGroup.HasGroupChanged = true;
  561. }
  562. }
  563. public bool PassCollisions
  564. {
  565. get { return m_passCollisions; }
  566. set
  567. {
  568. m_passCollisions = value;
  569. if (ParentGroup != null)
  570. ParentGroup.HasGroupChanged = true;
  571. }
  572. }
  573. public bool IsSelected
  574. {
  575. get { return m_isSelected; }
  576. set
  577. {
  578. m_isSelected = value;
  579. if (ParentGroup != null)
  580. ParentGroup.PartSelectChanged(value);
  581. }
  582. }
  583. public Dictionary<int, string> CollisionFilter
  584. {
  585. get { return m_CollisionFilter; }
  586. set
  587. {
  588. m_CollisionFilter = value;
  589. }
  590. }
  591. protected bool APIDActive
  592. {
  593. get { return m_APIDActive; }
  594. set { m_APIDActive = value; }
  595. }
  596. protected Quaternion APIDTarget
  597. {
  598. get { return m_APIDTarget; }
  599. set { m_APIDTarget = value; }
  600. }
  601. protected float APIDDamp
  602. {
  603. get { return m_APIDDamp; }
  604. set { m_APIDDamp = value; }
  605. }
  606. protected float APIDStrength
  607. {
  608. get { return m_APIDStrength; }
  609. set { m_APIDStrength = value; }
  610. }
  611. public ulong RegionHandle
  612. {
  613. get { return m_regionHandle; }
  614. set { m_regionHandle = value; }
  615. }
  616. public int ScriptAccessPin
  617. {
  618. get { return m_scriptAccessPin; }
  619. set { m_scriptAccessPin = (int)value; }
  620. }
  621. public Byte[] TextureAnimation
  622. {
  623. get { return m_TextureAnimation; }
  624. set { m_TextureAnimation = value; }
  625. }
  626. public Byte[] ParticleSystem
  627. {
  628. get { return m_particleSystem; }
  629. set { m_particleSystem = value; }
  630. }
  631. public DateTime Expires
  632. {
  633. get { return m_expires; }
  634. set { m_expires = value; }
  635. }
  636. public DateTime Rezzed
  637. {
  638. get { return m_rezzed; }
  639. set { m_rezzed = value; }
  640. }
  641. public float Damage
  642. {
  643. get { return m_damage; }
  644. set { m_damage = value; }
  645. }
  646. public void setGroupPosition(Vector3 pos)
  647. {
  648. m_groupPosition = pos;
  649. }
  650. /// <summary>
  651. /// The position of the entire group that this prim belongs to.
  652. /// </summary>
  653. ///
  654. public Vector3 GroupPosition
  655. {
  656. get
  657. {
  658. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  659. PhysicsActor actor = PhysActor;
  660. if (_parentID == 0)
  661. {
  662. if (actor != null)
  663. m_groupPosition = actor.Position;
  664. return m_groupPosition;
  665. }
  666. // If I'm an attachment, my position is reported as the position of who I'm attached to
  667. if (ParentGroup.IsAttachment)
  668. {
  669. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  670. if (sp != null)
  671. return sp.AbsolutePosition;
  672. }
  673. // use root prim's group position. Physics may have updated it
  674. if (ParentGroup.RootPart != this)
  675. m_groupPosition = ParentGroup.RootPart.GroupPosition;
  676. return m_groupPosition;
  677. }
  678. set
  679. {
  680. m_groupPosition = value;
  681. PhysicsActor actor = PhysActor;
  682. if (actor != null && ParentGroup.Scene.PhysicsScene != null)
  683. {
  684. try
  685. {
  686. // Root prim actually goes at Position
  687. if (_parentID == 0)
  688. {
  689. actor.Position = value;
  690. }
  691. else
  692. {
  693. // The physics engine always sees all objects (root or linked) in world coordinates.
  694. actor.Position = GetWorldPosition();
  695. actor.Orientation = GetWorldRotation();
  696. }
  697. // Tell the physics engines that this prim changed.
  698. if (ParentGroup != null && ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  699. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  700. }
  701. catch (Exception e)
  702. {
  703. m_log.ErrorFormat("[SCENEOBJECTPART]: GROUP POSITION. {0}", e);
  704. }
  705. }
  706. }
  707. }
  708. public void setOffsetPosition(Vector3 pos)
  709. {
  710. m_offsetPosition = pos;
  711. }
  712. public Vector3 OffsetPosition
  713. {
  714. get { return m_offsetPosition; }
  715. set
  716. {
  717. Vector3 oldpos = m_offsetPosition;
  718. m_offsetPosition = value;
  719. if (ParentGroup != null && !ParentGroup.IsDeleted)
  720. {
  721. if((oldpos - m_offsetPosition).LengthSquared() > 1.0f)
  722. ParentGroup.InvalidBoundsRadius();
  723. PhysicsActor actor = PhysActor;
  724. if (_parentID != 0 && actor != null)
  725. {
  726. actor.Position = GetWorldPosition();
  727. actor.Orientation = GetWorldRotation();
  728. // Tell the physics engines that this prim changed.
  729. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  730. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  731. }
  732. if (!m_parentGroup.m_dupeInProgress)
  733. {
  734. List<ScenePresence> avs = ParentGroup.GetSittingAvatars();
  735. foreach (ScenePresence av in avs)
  736. {
  737. if (av.ParentID == m_localId)
  738. {
  739. Vector3 offset = (m_offsetPosition - oldpos);
  740. av.AbsolutePosition += offset;
  741. // av.SendAvatarDataToAllAgents();
  742. av.SendTerseUpdateToAllClients();
  743. }
  744. }
  745. }
  746. }
  747. TriggerScriptChangedEvent(Changed.POSITION);
  748. }
  749. }
  750. public Vector3 RelativePosition
  751. {
  752. get
  753. {
  754. if (IsRoot)
  755. {
  756. if (ParentGroup.IsAttachment)
  757. return AttachedPos;
  758. else
  759. return AbsolutePosition;
  760. }
  761. else
  762. {
  763. return OffsetPosition;
  764. }
  765. }
  766. }
  767. public void setRotationOffset(Quaternion q)
  768. {
  769. m_rotationOffset = q;
  770. }
  771. public Quaternion RotationOffset
  772. {
  773. get
  774. {
  775. // We don't want the physics engine mucking up the rotations in a linkset
  776. PhysicsActor actor = PhysActor;
  777. // If this is a root of a linkset, the real rotation is what the physics engine thinks.
  778. // If not a root prim, the offset rotation is computed by SOG and is relative to the root.
  779. if (_parentID == 0 && (Shape.PCode != 9 || Shape.State == 0) && actor != null)
  780. m_rotationOffset = actor.Orientation;
  781. return m_rotationOffset;
  782. }
  783. set
  784. {
  785. // StoreUndoState();
  786. m_rotationOffset = value;
  787. PhysicsActor actor = PhysActor;
  788. if (actor != null)
  789. {
  790. try
  791. {
  792. // Root prim gets value directly
  793. if (_parentID == 0)
  794. {
  795. actor.Orientation = value;
  796. //m_log.Info("[PART]: RO1:" + actor.Orientation.ToString());
  797. }
  798. else
  799. {
  800. // Child prim we have to calculate it's world rotationwel
  801. Quaternion resultingrotation = GetWorldRotation();
  802. actor.Orientation = resultingrotation;
  803. //m_log.Info("[PART]: RO2:" + actor.Orientation.ToString());
  804. }
  805. if (ParentGroup != null && ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  806. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  807. //}
  808. }
  809. catch (Exception ex)
  810. {
  811. m_log.Error("[SCENEOBJECTPART]: ROTATIONOFFSET" + ex.Message);
  812. }
  813. }
  814. }
  815. }
  816. /// <summary></summary>
  817. public Vector3 Velocity
  818. {
  819. get
  820. {
  821. PhysicsActor actor = PhysActor;
  822. if (actor != null)
  823. {
  824. if (actor.IsPhysical)
  825. {
  826. m_velocity = actor.Velocity;
  827. }
  828. }
  829. return m_velocity;
  830. }
  831. set
  832. {
  833. if (Util.IsNanOrInfinity(value))
  834. m_velocity = Vector3.Zero;
  835. else
  836. m_velocity = value;
  837. PhysicsActor actor = PhysActor;
  838. if (actor != null)
  839. {
  840. if (actor.IsPhysical)
  841. {
  842. actor.Velocity = m_velocity;
  843. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  844. }
  845. }
  846. }
  847. }
  848. /// <summary>Update angular velocity and schedule terse update.</summary>
  849. public void UpdateAngularVelocity(Vector3 avel)
  850. {
  851. AngularVelocity = avel;
  852. ScheduleTerseUpdate();
  853. ParentGroup.HasGroupChanged = true;
  854. }
  855. /// <summary>Get or set angular velocity. Does not schedule update.</summary>
  856. public Vector3 AngularVelocity
  857. {
  858. get
  859. {
  860. PhysicsActor actor = PhysActor;
  861. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  862. {
  863. m_angularVelocity = actor.RotationalVelocity;
  864. }
  865. return m_angularVelocity;
  866. }
  867. set
  868. {
  869. if (Util.IsNanOrInfinity(value))
  870. m_angularVelocity = Vector3.Zero;
  871. else
  872. m_angularVelocity = value;
  873. PhysicsActor actor = PhysActor;
  874. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  875. {
  876. actor.RotationalVelocity = m_angularVelocity;
  877. }
  878. }
  879. }
  880. /// <summary></summary>
  881. public Vector3 Acceleration
  882. {
  883. get
  884. {
  885. PhysicsActor actor = PhysActor;
  886. if (actor != null && actor.IsPhysical)
  887. {
  888. m_acceleration = actor.Acceleration;
  889. }
  890. return m_acceleration;
  891. }
  892. set
  893. {
  894. if (Util.IsNanOrInfinity(value))
  895. m_acceleration = Vector3.Zero;
  896. else
  897. m_acceleration = value;
  898. PhysicsActor actor = PhysActor;
  899. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  900. {
  901. actor.Acceleration = m_acceleration;
  902. }
  903. }
  904. }
  905. public string Description { get; set; }
  906. /// <value>
  907. /// Text color.
  908. /// </value>
  909. public Color Color
  910. {
  911. get { return m_color; }
  912. set { m_color = value; }
  913. }
  914. public string Text
  915. {
  916. get
  917. {
  918. if (m_text.Length > 254)
  919. return m_text.Substring(0, 254);
  920. return m_text;
  921. }
  922. set { m_text = value; }
  923. }
  924. public string SitName
  925. {
  926. get { return m_sitName; }
  927. set { m_sitName = value; }
  928. }
  929. public string TouchName
  930. {
  931. get { return m_touchName; }
  932. set { m_touchName = value; }
  933. }
  934. public int LinkNum
  935. {
  936. get { return m_linkNum; }
  937. set
  938. {
  939. // if (ParentGroup != null)
  940. // {
  941. // m_log.DebugFormat(
  942. // "[SCENE OBJECT PART]: Setting linknum of {0}@{1} to {2} from {3}",
  943. // Name, AbsolutePosition, value, m_linkNum);
  944. // Util.PrintCallStack();
  945. // }
  946. m_linkNum = value;
  947. }
  948. }
  949. public byte ClickAction
  950. {
  951. get { return m_clickAction; }
  952. set
  953. {
  954. m_clickAction = value;
  955. }
  956. }
  957. public PrimitiveBaseShape Shape
  958. {
  959. get { return m_shape; }
  960. set
  961. {
  962. m_shape = value;
  963. }
  964. }
  965. /// <summary>
  966. /// Change the scale of this part.
  967. /// </summary>
  968. public Vector3 Scale
  969. {
  970. get { return m_shape.Scale; }
  971. set
  972. {
  973. if (m_shape != null)
  974. {
  975. Vector3 oldscale = m_shape.Scale;
  976. m_shape.Scale = value;
  977. if (ParentGroup != null && ((value - oldscale).LengthSquared() >1.0f))
  978. ParentGroup.InvalidBoundsRadius();
  979. PhysicsActor actor = PhysActor;
  980. if (actor != null)
  981. {
  982. if (ParentGroup.Scene != null)
  983. {
  984. if (ParentGroup.Scene.PhysicsScene != null)
  985. {
  986. actor.Size = m_shape.Scale;
  987. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  988. }
  989. }
  990. }
  991. }
  992. TriggerScriptChangedEvent(Changed.SCALE);
  993. }
  994. }
  995. public float maxSimpleArea()
  996. {
  997. float a,b;
  998. float sx = m_shape.Scale.X;
  999. float sy = m_shape.Scale.Y;
  1000. float sz = m_shape.Scale.Z;
  1001. if( sx > sy)
  1002. {
  1003. a = sx;
  1004. if(sy > sz)
  1005. b = sy;
  1006. else
  1007. b = sz;
  1008. }
  1009. else
  1010. {
  1011. a = sy;
  1012. if(sx > sz)
  1013. b = sx;
  1014. else
  1015. b = sz;
  1016. }
  1017. return a * b;
  1018. }
  1019. public PrimUpdateFlags UpdateFlag { get; set; }
  1020. public PrimUpdateFlags GetAndClearUpdateFlag()
  1021. {
  1022. lock(UpdateFlagLock)
  1023. {
  1024. PrimUpdateFlags ret = UpdateFlag;
  1025. UpdateFlag = PrimUpdateFlags.None;
  1026. return ret;
  1027. }
  1028. }
  1029. private object UpdateFlagLock = new object();
  1030. /// <summary>
  1031. /// Used for media on a prim.
  1032. /// </summary>
  1033. /// Do not change this value directly - always do it through an IMoapModule.
  1034. public string MediaUrl
  1035. {
  1036. get
  1037. {
  1038. return m_mediaUrl;
  1039. }
  1040. set
  1041. {
  1042. string old = m_mediaUrl;
  1043. m_mediaUrl = value;
  1044. if (ParentGroup != null && old != m_mediaUrl)
  1045. ParentGroup.HasGroupChanged = true;
  1046. }
  1047. }
  1048. public bool CreateSelected
  1049. {
  1050. get { return m_createSelected; }
  1051. set
  1052. {
  1053. // m_log.DebugFormat("[SOP]: Setting CreateSelected to {0} for {1} {2}", value, Name, UUID);
  1054. m_createSelected = value;
  1055. }
  1056. }
  1057. #endregion
  1058. //---------------
  1059. #region Public Properties with only Get
  1060. public Vector3 AbsolutePosition
  1061. {
  1062. get
  1063. {
  1064. if (_parentID == 0)
  1065. return GroupPosition;
  1066. return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
  1067. }
  1068. }
  1069. public SceneObjectGroup ParentGroup
  1070. {
  1071. get { return m_parentGroup; }
  1072. private set { m_parentGroup = value; }
  1073. }
  1074. public scriptEvents ScriptEvents
  1075. {
  1076. get { return AggregatedScriptEvents; }
  1077. }
  1078. public Quaternion SitTargetOrientation
  1079. {
  1080. get { return m_sitTargetOrientation; }
  1081. set
  1082. {
  1083. m_sitTargetOrientation = value;
  1084. // m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target orientation {0} for {1} {2}", m_sitTargetOrientation, Name, LocalId);
  1085. }
  1086. }
  1087. public Vector3 SitTargetPosition
  1088. {
  1089. get { return m_sitTargetPosition; }
  1090. set
  1091. {
  1092. m_sitTargetPosition = value;
  1093. // m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target position to {0} for {1} {2}", m_sitTargetPosition, Name, LocalId);
  1094. }
  1095. }
  1096. // This sort of sucks, but I'm adding these in to make some of
  1097. // the mappings more consistant.
  1098. public Vector3 SitTargetPositionLL
  1099. {
  1100. get { return m_sitTargetPosition; }
  1101. set { m_sitTargetPosition = value; }
  1102. }
  1103. public Quaternion SitTargetOrientationLL
  1104. {
  1105. get { return m_sitTargetOrientation; }
  1106. set { m_sitTargetOrientation = value; }
  1107. }
  1108. public float SitActiveRange { get; set;}
  1109. public Vector3 StandOffset { get; set;}
  1110. public bool Stopped
  1111. {
  1112. get {
  1113. double threshold = 0.02;
  1114. return (Math.Abs(Velocity.X) < threshold &&
  1115. Math.Abs(Velocity.Y) < threshold &&
  1116. Math.Abs(Velocity.Z) < threshold &&
  1117. Math.Abs(AngularVelocity.X) < threshold &&
  1118. Math.Abs(AngularVelocity.Y) < threshold &&
  1119. Math.Abs(AngularVelocity.Z) < threshold);
  1120. }
  1121. }
  1122. /// <summary>
  1123. /// The parent ID of this part.
  1124. /// </summary>
  1125. /// <remarks>
  1126. /// If this is a root part which is not attached to an avatar then the value will be 0.
  1127. /// If this is a root part which is attached to an avatar then the value is the local id of that avatar.
  1128. /// If this is a child part then the value is the local ID of the root part.
  1129. /// </remarks>
  1130. public uint ParentID
  1131. {
  1132. get { return _parentID; }
  1133. set { _parentID = value; }
  1134. }
  1135. public int CreationDate
  1136. {
  1137. get { return _creationDate; }
  1138. set { _creationDate = value; }
  1139. }
  1140. public uint Category
  1141. {
  1142. get { return _category; }
  1143. set { _category = value; }
  1144. }
  1145. public int SalePrice
  1146. {
  1147. get { return _salePrice; }
  1148. set { _salePrice = value; }
  1149. }
  1150. public byte ObjectSaleType
  1151. {
  1152. get { return _objectSaleType; }
  1153. set { _objectSaleType = value; }
  1154. }
  1155. public int OwnershipCost
  1156. {
  1157. get { return _ownershipCost; }
  1158. set { _ownershipCost = value; }
  1159. }
  1160. public UUID GroupID
  1161. {
  1162. get { return _groupID; }
  1163. set { _groupID = value; }
  1164. }
  1165. public UUID OwnerID
  1166. {
  1167. get { return _ownerID; }
  1168. set { _ownerID = value; }
  1169. }
  1170. public UUID LastOwnerID
  1171. {
  1172. get { return _lastOwnerID; }
  1173. set {
  1174. _lastOwnerID = value; }
  1175. }
  1176. public UUID RezzerID
  1177. {
  1178. get { return _rezzerID; }
  1179. set { _rezzerID = value; }
  1180. }
  1181. public uint BaseMask
  1182. {
  1183. get { return _baseMask; }
  1184. set { _baseMask = value; }
  1185. }
  1186. public uint OwnerMask
  1187. {
  1188. get { return _ownerMask; }
  1189. set { _ownerMask = value; }
  1190. }
  1191. public uint GroupMask
  1192. {
  1193. get { return _groupMask; }
  1194. set { _groupMask = value; }
  1195. }
  1196. public uint EveryoneMask
  1197. {
  1198. get { return _everyoneMask; }
  1199. set { _everyoneMask = value; }
  1200. }
  1201. public uint NextOwnerMask
  1202. {
  1203. get { return _nextOwnerMask; }
  1204. set { _nextOwnerMask = value; }
  1205. }
  1206. /// <summary>
  1207. /// Property flags. See OpenMetaverse.PrimFlags
  1208. /// </summary>
  1209. /// <remarks>
  1210. /// Example properties are PrimFlags.Phantom and PrimFlags.DieAtEdge
  1211. /// </remarks>
  1212. public PrimFlags Flags
  1213. {
  1214. get { return _flags; }
  1215. set
  1216. {
  1217. // m_log.DebugFormat("[SOP]: Setting flags for {0} {1} to {2}", UUID, Name, value);
  1218. _flags = value;
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// 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
  1223. /// </summary>
  1224. public UUID SitTargetAvatar { get; set; }
  1225. /// <summary>
  1226. /// IDs of all avatars sat on this part.
  1227. /// </summary>
  1228. /// <remarks>
  1229. /// We need to track this so that we can stop sat upon prims from being attached.
  1230. /// </remarks>
  1231. /// <value>
  1232. /// null if there are no sitting avatars. This is to save us create a hashset for every prim in a scene.
  1233. /// </value>
  1234. private HashSet<ScenePresence> m_sittingAvatars;
  1235. public virtual UUID RegionID
  1236. {
  1237. get
  1238. {
  1239. if (ParentGroup.Scene != null)
  1240. return ParentGroup.Scene.RegionInfo.RegionID;
  1241. else
  1242. return UUID.Zero;
  1243. }
  1244. set {} // read only
  1245. }
  1246. private UUID _parentUUID = UUID.Zero;
  1247. public UUID ParentUUID
  1248. {
  1249. get
  1250. {
  1251. if (ParentGroup != null)
  1252. _parentUUID = ParentGroup.UUID;
  1253. return _parentUUID;
  1254. }
  1255. set { _parentUUID = value; }
  1256. }
  1257. public string SitAnimation
  1258. {
  1259. get { return m_sitAnimation; }
  1260. set { m_sitAnimation = value; }
  1261. }
  1262. public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
  1263. // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
  1264. // runtime thing.. do not persist
  1265. [XmlIgnore]
  1266. public sbyte CollisionSoundType
  1267. {
  1268. get
  1269. {
  1270. return m_collisionSoundType;
  1271. }
  1272. set
  1273. {
  1274. UUID old = m_collisionSound;
  1275. m_collisionSoundType = value;
  1276. if (value == -1)
  1277. m_collisionSound = invalidCollisionSoundUUID;
  1278. else if (value == 0)
  1279. m_collisionSound = UUID.Zero;
  1280. if(m_collisionSound != old && ParentGroup != null)
  1281. ParentGroup.HasGroupChanged = true;
  1282. }
  1283. }
  1284. public UUID CollisionSound
  1285. {
  1286. get { return m_collisionSound; }
  1287. set
  1288. {
  1289. UUID olds = m_collisionSound;
  1290. m_collisionSound = value;
  1291. if (value == invalidCollisionSoundUUID)
  1292. m_collisionSoundType = -1;
  1293. else if (value == UUID.Zero)
  1294. m_collisionSoundType = 0;
  1295. else
  1296. m_collisionSoundType = 1;
  1297. if(m_collisionSound != olds && ParentGroup != null)
  1298. ParentGroup.HasGroupChanged = true;
  1299. }
  1300. }
  1301. public float CollisionSoundVolume
  1302. {
  1303. get { return m_collisionSoundVolume; }
  1304. set
  1305. {
  1306. float oldvalue = m_collisionSoundVolume;
  1307. if(value >= 0)
  1308. m_collisionSoundVolume = value;
  1309. else
  1310. m_collisionSoundVolume = 0.0f;
  1311. if(m_collisionSoundVolume != oldvalue && ParentGroup != null)
  1312. ParentGroup.HasGroupChanged = true;
  1313. }
  1314. }
  1315. public float Buoyancy
  1316. {
  1317. get
  1318. {
  1319. if (ParentGroup.RootPart == this)
  1320. return m_buoyancy;
  1321. return ParentGroup.RootPart.Buoyancy;
  1322. }
  1323. set
  1324. {
  1325. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1326. {
  1327. ParentGroup.RootPart.Buoyancy = value;
  1328. return;
  1329. }
  1330. m_buoyancy = value;
  1331. if (PhysActor != null)
  1332. PhysActor.Buoyancy = value;
  1333. }
  1334. }
  1335. public Vector3 Force
  1336. {
  1337. get
  1338. {
  1339. if (ParentGroup.RootPart == this)
  1340. return m_force;
  1341. return ParentGroup.RootPart.Force;
  1342. }
  1343. set
  1344. {
  1345. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1346. {
  1347. ParentGroup.RootPart.Force = value;
  1348. return;
  1349. }
  1350. m_force = value;
  1351. if (PhysActor != null)
  1352. PhysActor.Force = value;
  1353. }
  1354. }
  1355. public Vector3 Torque
  1356. {
  1357. get
  1358. {
  1359. if (ParentGroup.RootPart == this)
  1360. return m_torque;
  1361. return ParentGroup.RootPart.Torque;
  1362. }
  1363. set
  1364. {
  1365. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1366. {
  1367. ParentGroup.RootPart.Torque = value;
  1368. return;
  1369. }
  1370. m_torque = value;
  1371. if (PhysActor != null)
  1372. PhysActor.Torque = value;
  1373. }
  1374. }
  1375. public byte Material
  1376. {
  1377. get { return (byte)m_material; }
  1378. set
  1379. {
  1380. if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
  1381. {
  1382. bool update = false;
  1383. if (m_material != (Material)value)
  1384. {
  1385. update = true;
  1386. m_material = (Material)value;
  1387. }
  1388. if (m_friction != SOPMaterialData.friction(m_material))
  1389. {
  1390. update = true;
  1391. m_friction = SOPMaterialData.friction(m_material);
  1392. }
  1393. if (m_bounce != SOPMaterialData.bounce(m_material))
  1394. {
  1395. update = true;
  1396. m_bounce = SOPMaterialData.bounce(m_material);
  1397. }
  1398. if (update)
  1399. {
  1400. if (PhysActor != null)
  1401. {
  1402. PhysActor.SetMaterial((int)value);
  1403. }
  1404. if(ParentGroup != null)
  1405. {
  1406. ParentGroup.HasGroupChanged = true;
  1407. ScheduleFullUpdate();
  1408. }
  1409. }
  1410. }
  1411. }
  1412. }
  1413. // not a propriety to move to methods place later
  1414. private bool HasMesh()
  1415. {
  1416. if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
  1417. return true;
  1418. return false;
  1419. }
  1420. // not a propriety to move to methods place later
  1421. public byte DefaultPhysicsShapeType()
  1422. {
  1423. byte type;
  1424. if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
  1425. type = (byte)PhysShapeType.convex;
  1426. else
  1427. type = (byte)PhysShapeType.prim;
  1428. return type;
  1429. }
  1430. [XmlIgnore]
  1431. public bool UsesComplexCost
  1432. {
  1433. get
  1434. {
  1435. byte pst = PhysicsShapeType;
  1436. if(pst == (byte) PhysShapeType.none || HasMesh())
  1437. return true;
  1438. return false;
  1439. }
  1440. }
  1441. [XmlIgnore]
  1442. public float PhysicsCost
  1443. {
  1444. get
  1445. {
  1446. if(PhysicsShapeType == (byte)PhysShapeType.none)
  1447. return 0;
  1448. float cost = 0.1f;
  1449. if (PhysActor != null)
  1450. cost = PhysActor.PhysicsCost;
  1451. else
  1452. cost = 0.1f;
  1453. if ((Flags & PrimFlags.Physics) != 0)
  1454. cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
  1455. return cost;
  1456. }
  1457. }
  1458. [XmlIgnore]
  1459. public float StreamingCost
  1460. {
  1461. get
  1462. {
  1463. float cost;
  1464. if (PhysActor != null)
  1465. cost = PhysActor.StreamCost;
  1466. else
  1467. cost = 1.0f;
  1468. return 1.0f;
  1469. }
  1470. }
  1471. [XmlIgnore]
  1472. public float SimulationCost
  1473. {
  1474. get
  1475. {
  1476. // ignoring scripts. Don't like considering them for this
  1477. if((Flags & PrimFlags.Physics) != 0)
  1478. return 1.0f;
  1479. return 0.5f;
  1480. }
  1481. }
  1482. public byte PhysicsShapeType
  1483. {
  1484. get
  1485. {
  1486. // if (PhysActor != null)
  1487. // m_physicsShapeType = PhysActor.PhysicsShapeType;
  1488. return m_physicsShapeType;
  1489. }
  1490. set
  1491. {
  1492. byte oldv = m_physicsShapeType;
  1493. if (value >= 0 && value <= (byte)PhysShapeType.convex)
  1494. {
  1495. if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
  1496. m_physicsShapeType = DefaultPhysicsShapeType();
  1497. else
  1498. m_physicsShapeType = value;
  1499. }
  1500. else
  1501. m_physicsShapeType = DefaultPhysicsShapeType();
  1502. if (m_physicsShapeType != oldv && ParentGroup != null)
  1503. {
  1504. if (m_physicsShapeType == (byte)PhysShapeType.none)
  1505. {
  1506. if (PhysActor != null)
  1507. {
  1508. ParentGroup.Scene.RemovePhysicalPrim(1);
  1509. RemoveFromPhysics();
  1510. // Stop();
  1511. }
  1512. }
  1513. else if (PhysActor == null)
  1514. {
  1515. if(oldv == (byte)PhysShapeType.none)
  1516. {
  1517. ApplyPhysics((uint)Flags, VolumeDetectActive, false);
  1518. UpdatePhysicsSubscribedEvents();
  1519. }
  1520. }
  1521. else
  1522. PhysActor.PhysicsShapeType = m_physicsShapeType;
  1523. ParentGroup.HasGroupChanged = true;
  1524. }
  1525. }
  1526. }
  1527. public float Density // in kg/m^3
  1528. {
  1529. get { return m_density; }
  1530. set
  1531. {
  1532. if (value >=1 && value <= 22587.0)
  1533. {
  1534. m_density = value;
  1535. if (ParentGroup != null)
  1536. {
  1537. ParentGroup.HasGroupChanged = true;
  1538. ScheduleFullUpdate();
  1539. }
  1540. PhysicsActor pa = PhysActor;
  1541. if (pa != null)
  1542. pa.Density = m_density;
  1543. }
  1544. }
  1545. }
  1546. public float GravityModifier
  1547. {
  1548. get { return m_gravitymod; }
  1549. set
  1550. {
  1551. if( value >= -1 && value <=28.0f)
  1552. {
  1553. m_gravitymod = value;
  1554. if (ParentGroup != null)
  1555. {
  1556. ParentGroup.HasGroupChanged = true;
  1557. ScheduleFullUpdate();
  1558. }
  1559. PhysicsActor pa = PhysActor;
  1560. if (pa != null)
  1561. pa.GravModifier = m_gravitymod;
  1562. }
  1563. }
  1564. }
  1565. public float Friction
  1566. {
  1567. get { return m_friction; }
  1568. set
  1569. {
  1570. if (value >= 0 && value <= 255.0f)
  1571. {
  1572. m_friction = value;
  1573. if (ParentGroup != null)
  1574. {
  1575. ParentGroup.HasGroupChanged = true;
  1576. ScheduleFullUpdate();
  1577. }
  1578. PhysicsActor pa = PhysActor;
  1579. if (pa != null)
  1580. pa.Friction = m_friction;
  1581. }
  1582. }
  1583. }
  1584. public float Restitution
  1585. {
  1586. get { return m_bounce; }
  1587. set
  1588. {
  1589. if (value >= 0 && value <= 1.0f)
  1590. {
  1591. m_bounce = value;
  1592. if (ParentGroup != null)
  1593. {
  1594. ParentGroup.HasGroupChanged = true;
  1595. ScheduleFullUpdate();
  1596. }
  1597. PhysicsActor pa = PhysActor;
  1598. if (pa != null)
  1599. pa.Restitution = m_bounce;
  1600. }
  1601. }
  1602. }
  1603. #endregion Public Properties with only Get
  1604. private uint ApplyMask(uint val, bool set, uint mask)
  1605. {
  1606. if (set)
  1607. {
  1608. return val |= mask;
  1609. }
  1610. else
  1611. {
  1612. return val &= ~mask;
  1613. }
  1614. }
  1615. /// <summary>
  1616. /// Clear all pending updates of parts to clients
  1617. /// </summary>
  1618. public void ClearUpdateSchedule()
  1619. {
  1620. lock(UpdateFlagLock)
  1621. UpdateFlag = PrimUpdateFlags.None;
  1622. }
  1623. /// <summary>
  1624. /// Send this part's properties (name, description, inventory serial, base mask, etc.) to a client
  1625. /// </summary>
  1626. /// <param name="client"></param>
  1627. public void SendPropertiesToClient(IClientAPI client)
  1628. {
  1629. client.SendObjectPropertiesReply(this);
  1630. }
  1631. // TODO: unused:
  1632. // private void handleTimerAccounting(uint localID, double interval)
  1633. // {
  1634. // if (localID == LocalId)
  1635. // {
  1636. // float sec = (float)interval;
  1637. // if (m_parentGroup != null)
  1638. // {
  1639. // if (sec == 0)
  1640. // {
  1641. // if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  1642. // m_parentGroup.scriptScore = 0;
  1643. //
  1644. // m_parentGroup.scriptScore += 0.001f;
  1645. // return;
  1646. // }
  1647. //
  1648. // if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  1649. // m_parentGroup.scriptScore = 0;
  1650. // m_parentGroup.scriptScore += (0.001f / sec);
  1651. // }
  1652. // }
  1653. // }
  1654. #region Public Methods
  1655. public void ResetExpire()
  1656. {
  1657. Expires = DateTime.UtcNow + new TimeSpan(600000000);
  1658. }
  1659. public void AddFlag(PrimFlags flag)
  1660. {
  1661. // PrimFlags prevflag = Flags;
  1662. if ((Flags & flag) == 0)
  1663. {
  1664. //m_log.Debug("Adding flag: " + ((PrimFlags) flag).ToString());
  1665. Flags |= flag;
  1666. if (flag == PrimFlags.TemporaryOnRez)
  1667. ResetExpire();
  1668. }
  1669. // m_log.Debug("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1670. }
  1671. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1672. {
  1673. m_particleSystem = pSystem.GetBytes();
  1674. }
  1675. public void RemoveParticleSystem()
  1676. {
  1677. m_particleSystem = new byte[0];
  1678. }
  1679. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1680. {
  1681. byte[] data;
  1682. if (pTexAnim.Flags == Primitive.TextureAnimMode.ANIM_OFF)
  1683. {
  1684. data = Utils.EmptyBytes;
  1685. }
  1686. else
  1687. {
  1688. data = new byte[16];
  1689. data[0] = (byte)pTexAnim.Flags;
  1690. data[1] = (byte)pTexAnim.Face;
  1691. data[2] = (byte)pTexAnim.SizeX;
  1692. data[3] = (byte)pTexAnim.SizeY;
  1693. Utils.FloatToBytesSafepos(pTexAnim.Start, data, 4);
  1694. Utils.FloatToBytesSafepos(pTexAnim.Length, data, 8);
  1695. Utils.FloatToBytesSafepos(pTexAnim.Rate, data, 12);
  1696. }
  1697. m_TextureAnimation = data;
  1698. }
  1699. public void AdjustSoundGain(double volume)
  1700. {
  1701. if (volume > 1)
  1702. volume = 1;
  1703. if (volume < 0)
  1704. volume = 0;
  1705. ParentGroup.Scene.ForEachRootClient(delegate(IClientAPI client)
  1706. {
  1707. client.SendAttachedSoundGainChange(UUID, (float)volume);
  1708. });
  1709. }
  1710. /// <summary>
  1711. /// hook to the physics scene to apply impulse
  1712. /// This is sent up to the group, which then finds the root prim
  1713. /// and applies the force on the root prim of the group
  1714. /// </summary>
  1715. /// <param name="impulsei">Vector force</param>
  1716. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1717. public void ApplyImpulse(Vector3 impulse, bool localGlobalTF)
  1718. {
  1719. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1720. return;
  1721. if (localGlobalTF)
  1722. impulse *= GetWorldRotation();
  1723. ParentGroup.applyImpulse(impulse);
  1724. }
  1725. // SetVelocity for LSL llSetVelocity.. may need revision if having other uses in future
  1726. public void SetVelocity(Vector3 pVel, bool localGlobalTF)
  1727. {
  1728. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1729. return;
  1730. if (ParentGroup.IsAttachment)
  1731. return; // don't work on attachments (for now ??)
  1732. SceneObjectPart root = ParentGroup.RootPart;
  1733. if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
  1734. return;
  1735. PhysicsActor pa = root.PhysActor;
  1736. if (pa == null || !pa.IsPhysical)
  1737. return;
  1738. if (localGlobalTF)
  1739. pVel *= GetWorldRotation();
  1740. ParentGroup.Velocity = pVel;
  1741. }
  1742. // SetAngularVelocity for LSL llSetAngularVelocity.. may need revision if having other uses in future
  1743. public void SetAngularVelocity(Vector3 pAngVel, bool localGlobalTF)
  1744. {
  1745. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1746. return;
  1747. if (ParentGroup.IsAttachment)
  1748. return; // don't work on attachments (for now ??)
  1749. SceneObjectPart root = ParentGroup.RootPart;
  1750. if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
  1751. return;
  1752. PhysicsActor pa = root.PhysActor;
  1753. if (pa == null || !pa.IsPhysical)
  1754. return;
  1755. if (localGlobalTF)
  1756. pAngVel *= GetWorldRotation();
  1757. root.AngularVelocity = pAngVel;
  1758. }
  1759. /// <summary>
  1760. /// hook to the physics scene to apply angular impulse
  1761. /// This is sent up to the group, which then finds the root prim
  1762. /// and applies the force on the root prim of the group
  1763. /// </summary>
  1764. /// <param name="impulsei">Vector force</param>
  1765. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1766. public void ApplyAngularImpulse(Vector3 impulse, bool localGlobalTF)
  1767. {
  1768. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1769. return;
  1770. if (localGlobalTF)
  1771. ParentGroup.ApplyAngularImpulse(impulse * GetWorldRotation());
  1772. else
  1773. ParentGroup.ApplyAngularImpulse(impulse);
  1774. }
  1775. /// <summary>
  1776. /// hook to the physics scene to apply angular impulse
  1777. /// This is sent up to the group, which then finds the root prim
  1778. /// and applies the force on the root prim of the group
  1779. /// </summary>
  1780. /// <param name="impulsei">Vector force</param>
  1781. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1782. // this is actualy Set Torque.. keeping naming so not to edit lslapi also
  1783. public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
  1784. {
  1785. Vector3 torque = torquei;
  1786. if (localGlobalTF)
  1787. torque *= GetWorldRotation();
  1788. Torque = torque;
  1789. }
  1790. /// <summary>
  1791. /// Apply physics to this part.
  1792. /// </summary>
  1793. /// <param name="rootObjectFlags"></param>
  1794. /// <param name="VolumeDetectActive"></param>
  1795. /// <param name="building"></param>
  1796. public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
  1797. {
  1798. VolumeDetectActive = _VolumeDetectActive;
  1799. if (!ParentGroup.Scene.CollidablePrims)
  1800. return;
  1801. if (PhysicsShapeType == (byte)PhysShapeType.none)
  1802. {
  1803. if(ParentID == 0)
  1804. m_physicsShapeType = DefaultPhysicsShapeType();
  1805. else
  1806. return;
  1807. }
  1808. bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
  1809. bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
  1810. if (_VolumeDetectActive)
  1811. isPhantom = true;
  1812. if (IsJoint())
  1813. {
  1814. DoPhysicsPropertyUpdate(isPhysical, true);
  1815. }
  1816. else
  1817. {
  1818. if ((!isPhantom || isPhysical || _VolumeDetectActive)
  1819. && !ParentGroup.IsAttachmentCheckFull()
  1820. && !(Shape.PathCurve == (byte)Extrusion.Flexible))
  1821. {
  1822. AddToPhysics(isPhysical, isPhantom, building, isPhysical);
  1823. UpdatePhysicsSubscribedEvents(); // not sure if appliable here
  1824. }
  1825. else
  1826. {
  1827. PhysActor = null; // just to be sure
  1828. RemFlag(PrimFlags.CameraDecoupled);
  1829. }
  1830. }
  1831. }
  1832. /// <summary>
  1833. /// Duplicates this part.
  1834. /// </summary>
  1835. /// <param name="localID"></param>
  1836. /// <param name="AgentID"></param>
  1837. /// <param name="GroupID"></param>
  1838. /// <param name="linkNum"></param>
  1839. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  1840. /// <returns></returns>
  1841. public SceneObjectPart Copy(uint plocalID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
  1842. {
  1843. // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up
  1844. // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator
  1845. // but not between regions on different simulators). Really, all copying should be done explicitly.
  1846. SceneObjectPart dupe = (SceneObjectPart)MemberwiseClone();
  1847. dupe.m_shape = m_shape.Copy();
  1848. dupe.m_regionHandle = m_regionHandle;
  1849. if (userExposed)
  1850. dupe.UUID = UUID.Random();
  1851. dupe.PhysActor = null;
  1852. dupe.OwnerID = AgentID;
  1853. dupe.GroupID = GroupID;
  1854. dupe.GroupPosition = GroupPosition;
  1855. dupe.OffsetPosition = OffsetPosition;
  1856. dupe.RotationOffset = RotationOffset;
  1857. dupe.Velocity = Velocity;
  1858. dupe.Acceleration = Acceleration;
  1859. dupe.AngularVelocity = AngularVelocity;
  1860. dupe.Flags = Flags;
  1861. dupe.OwnershipCost = OwnershipCost;
  1862. dupe.ObjectSaleType = ObjectSaleType;
  1863. dupe.SalePrice = SalePrice;
  1864. dupe.Category = Category;
  1865. dupe.m_rezzed = m_rezzed;
  1866. dupe.m_UndoRedo = null;
  1867. dupe.m_isSelected = false;
  1868. dupe.IgnoreUndoUpdate = false;
  1869. dupe.Undoing = false;
  1870. dupe.m_inventory = new SceneObjectPartInventory(dupe);
  1871. dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
  1872. if (userExposed)
  1873. {
  1874. dupe.ResetIDs(linkNum);
  1875. dupe.m_inventory.HasInventoryChanged = true;
  1876. }
  1877. else
  1878. {
  1879. dupe.m_inventory.HasInventoryChanged = m_inventory.HasInventoryChanged;
  1880. }
  1881. // Move afterwards ResetIDs as it clears the localID
  1882. dupe.LocalId = plocalID;
  1883. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1884. if(OwnerID != GroupID)
  1885. dupe.LastOwnerID = OwnerID;
  1886. else
  1887. dupe.LastOwnerID = LastOwnerID; // redundant ?
  1888. dupe.RezzerID = RezzerID;
  1889. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1890. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1891. dupe.Shape.ExtraParams = extraP;
  1892. dupe.m_sittingAvatars = new HashSet<ScenePresence>();
  1893. dupe.SitTargetAvatar = UUID.Zero;
  1894. // safeguard actual copy is done in sog.copy
  1895. dupe.KeyframeMotion = null;
  1896. dupe.PayPrice = (int[])PayPrice.Clone();
  1897. if(DynAttrs != null)
  1898. dupe.DynAttrs.CopyFrom(DynAttrs);
  1899. if (userExposed)
  1900. {
  1901. bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
  1902. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1903. }
  1904. if (dupe.PhysActor != null)
  1905. dupe.PhysActor.LocalID = plocalID;
  1906. dupe.PseudoCRC = (int)(DateTime.UtcNow.Ticks);
  1907. ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
  1908. // m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
  1909. return dupe;
  1910. }
  1911. /// <summary>
  1912. /// Do a physics property update for a NINJA joint.
  1913. /// </summary>
  1914. /// <param name="UsePhysics"></param>
  1915. /// <param name="isNew"></param>
  1916. protected void DoPhysicsPropertyUpdateForNinjaJoint(bool UsePhysics, bool isNew)
  1917. {
  1918. if (UsePhysics)
  1919. {
  1920. // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
  1921. // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.
  1922. PhysicsJointType jointType;
  1923. if (IsHingeJoint())
  1924. {
  1925. jointType = PhysicsJointType.Hinge;
  1926. }
  1927. else if (IsBallJoint())
  1928. {
  1929. jointType = PhysicsJointType.Ball;
  1930. }
  1931. else
  1932. {
  1933. jointType = PhysicsJointType.Ball;
  1934. }
  1935. List<string> bodyNames = new List<string>();
  1936. string RawParams = Description;
  1937. string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
  1938. string trackedBodyName = null;
  1939. if (jointParams.Length >= 2)
  1940. {
  1941. for (int iBodyName = 0; iBodyName < 2; iBodyName++)
  1942. {
  1943. string bodyName = jointParams[iBodyName];
  1944. bodyNames.Add(bodyName);
  1945. if (bodyName != "NULL")
  1946. {
  1947. if (trackedBodyName == null)
  1948. {
  1949. trackedBodyName = bodyName;
  1950. }
  1951. }
  1952. }
  1953. }
  1954. SceneObjectPart trackedBody = ParentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
  1955. Quaternion localRotation = Quaternion.Identity;
  1956. if (trackedBody != null)
  1957. {
  1958. localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
  1959. }
  1960. else
  1961. {
  1962. // error, output it below
  1963. }
  1964. PhysicsJoint joint;
  1965. joint = ParentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
  1966. AbsolutePosition,
  1967. this.RotationOffset,
  1968. Description,
  1969. bodyNames,
  1970. trackedBodyName,
  1971. localRotation);
  1972. if (trackedBody == null)
  1973. {
  1974. ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
  1975. }
  1976. }
  1977. else
  1978. {
  1979. if (isNew)
  1980. {
  1981. // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
  1982. // delete, and if we try to delete it, due to asynchronous processing, the deletion request
  1983. // will get processed later at an indeterminate time, which could cancel a later-arriving
  1984. // joint creation request.
  1985. }
  1986. else
  1987. {
  1988. // here we turn off the joint object, so remove the joint from the physics scene
  1989. ParentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?
  1990. // make sure client isn't interpolating the joint proxy object
  1991. Stop();
  1992. }
  1993. }
  1994. }
  1995. /// <summary>
  1996. /// Do a physics propery update for this part.
  1997. /// now also updates phantom and volume detector
  1998. /// </summary>
  1999. /// <param name="UsePhysics"></param>
  2000. /// <param name="isNew"></param>
  2001. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  2002. {
  2003. if (ParentGroup.Scene == null)
  2004. return;
  2005. if (!ParentGroup.Scene.PhysicalPrims && UsePhysics)
  2006. return;
  2007. if (IsJoint())
  2008. {
  2009. DoPhysicsPropertyUpdateForNinjaJoint(UsePhysics, isNew);
  2010. }
  2011. else
  2012. {
  2013. PhysicsActor pa = PhysActor;
  2014. if (pa != null)
  2015. {
  2016. if (UsePhysics != pa.IsPhysical)
  2017. ClampScale(UsePhysics);
  2018. if (UsePhysics != pa.IsPhysical || isNew)
  2019. {
  2020. if (pa.IsPhysical) // implies UsePhysics==false for this block
  2021. {
  2022. if (!isNew) // implies UsePhysics==false for this block
  2023. {
  2024. ParentGroup.Scene.RemovePhysicalPrim(1);
  2025. Stop();
  2026. if (pa.Phantom && !VolumeDetectActive)
  2027. {
  2028. RemoveFromPhysics();
  2029. return;
  2030. }
  2031. pa.IsPhysical = UsePhysics;
  2032. pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  2033. pa.OnOutOfBounds -= PhysicsOutOfBounds;
  2034. pa.delink();
  2035. if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  2036. {
  2037. // destroy all joints connected to this now deactivated body
  2038. ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
  2039. }
  2040. }
  2041. }
  2042. if (pa.IsPhysical != UsePhysics)
  2043. pa.IsPhysical = UsePhysics;
  2044. if (UsePhysics)
  2045. {
  2046. if (ParentGroup.RootPart.KeyframeMotion != null)
  2047. ParentGroup.RootPart.KeyframeMotion.Stop();
  2048. ParentGroup.RootPart.KeyframeMotion = null;
  2049. ParentGroup.Scene.AddPhysicalPrim(1);
  2050. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  2051. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  2052. if (_parentID != 0 && _parentID != LocalId)
  2053. {
  2054. PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
  2055. if (parentPa != null)
  2056. {
  2057. pa.link(parentPa);
  2058. }
  2059. }
  2060. }
  2061. }
  2062. bool phan = ((Flags & PrimFlags.Phantom) != 0);
  2063. if (pa.Phantom != phan)
  2064. pa.Phantom = phan;
  2065. // some engines dont' have this check still
  2066. // if (VolumeDetectActive != pa.IsVolumeDtc)
  2067. {
  2068. if (VolumeDetectActive)
  2069. pa.SetVolumeDetect(1);
  2070. else
  2071. pa.SetVolumeDetect(0);
  2072. }
  2073. // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
  2074. // mesh data.
  2075. // if (Shape.SculptEntry)
  2076. // CheckSculptAndLoad();
  2077. // else
  2078. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2079. }
  2080. }
  2081. }
  2082. /// <summary>
  2083. /// Restore this part from the serialized xml representation.
  2084. /// </summary>
  2085. /// <param name="xmlReader"></param>
  2086. /// <returns></returns>
  2087. public static SceneObjectPart FromXml(XmlReader xmlReader)
  2088. {
  2089. SceneObjectPart part = SceneObjectSerializer.Xml2ToSOP(xmlReader);
  2090. // for tempOnRez objects, we have to fix the Expire date.
  2091. if ((part.Flags & PrimFlags.TemporaryOnRez) != 0)
  2092. part.ResetExpire();
  2093. return part;
  2094. }
  2095. public bool GetDieAtEdge()
  2096. {
  2097. if (ParentGroup.IsDeleted)
  2098. return false;
  2099. return ParentGroup.RootPart.DIE_AT_EDGE;
  2100. }
  2101. public bool GetReturnAtEdge()
  2102. {
  2103. if (ParentGroup.IsDeleted)
  2104. return false;
  2105. return ParentGroup.RootPart.RETURN_AT_EDGE;
  2106. }
  2107. public void SetReturnAtEdge(bool p)
  2108. {
  2109. if (ParentGroup.IsDeleted)
  2110. return;
  2111. ParentGroup.RootPart.RETURN_AT_EDGE = p;
  2112. }
  2113. public void SetStatusSandbox(bool p)
  2114. {
  2115. if (ParentGroup.IsDeleted)
  2116. return;
  2117. StatusSandboxPos = ParentGroup.RootPart.AbsolutePosition;
  2118. ParentGroup.RootPart.StatusSandbox = p;
  2119. }
  2120. public bool GetStatusSandbox()
  2121. {
  2122. if (ParentGroup.IsDeleted)
  2123. return false;
  2124. return ParentGroup.RootPart.StatusSandbox;
  2125. }
  2126. public int GetAxisRotation(int axis)
  2127. {
  2128. if (!ParentGroup.IsDeleted)
  2129. return ParentGroup.GetAxisRotation(axis);
  2130. return 0;
  2131. }
  2132. public uint GetEffectiveObjectFlags()
  2133. {
  2134. uint eff = (uint)Flags | (uint)LocalFlags;
  2135. if(m_inventory == null || m_inventory.Count == 0)
  2136. eff |= (uint)PrimFlags.InventoryEmpty;
  2137. return eff;
  2138. }
  2139. // some of this lines need be moved to other place later
  2140. // effective permitions considering only this part inventory contents perms
  2141. public uint AggregatedInnerOwnerPerms {get; private set; }
  2142. public uint AggregatedInnerGroupPerms {get; private set; }
  2143. public uint AggregatedInnerEveryonePerms {get; private set; }
  2144. private object InnerPermsLock = new object();
  2145. public void AggregateInnerPerms()
  2146. {
  2147. // assuming child prims permissions masks are irrelevant on a linkset
  2148. // root part is handle at SOG since its masks are the sog masks
  2149. const uint mask = (uint)PermissionMask.AllEffective;
  2150. uint owner = mask;
  2151. uint group = mask;
  2152. uint everyone = mask;
  2153. lock(InnerPermsLock) // do we really need this?
  2154. {
  2155. if(Inventory != null)
  2156. Inventory.AggregateInnerPerms(ref owner, ref group, ref everyone);
  2157. AggregatedInnerOwnerPerms = owner & mask;
  2158. AggregatedInnerGroupPerms = group & mask;
  2159. AggregatedInnerEveryonePerms = everyone & mask;
  2160. }
  2161. if(ParentGroup != null)
  2162. ParentGroup.InvalidateEffectivePerms();
  2163. }
  2164. // same as above but called during group Effective Permission validation
  2165. public void AggregatedInnerPermsForGroup()
  2166. {
  2167. // assuming child prims permissions masks are irrelevant on a linkset
  2168. // root part is handle at SOG since its masks are the sog masks
  2169. const uint mask = (uint)PermissionMask.AllEffective;
  2170. uint owner = mask;
  2171. uint group = mask;
  2172. uint everyone = mask;
  2173. lock(InnerPermsLock) // do we really need this?
  2174. {
  2175. if(Inventory != null)
  2176. Inventory.AggregateInnerPerms(ref owner, ref group, ref everyone);
  2177. AggregatedInnerOwnerPerms = owner & mask;
  2178. AggregatedInnerGroupPerms = group & mask;
  2179. AggregatedInnerEveryonePerms = everyone & mask;
  2180. }
  2181. }
  2182. public Vector3 GetGeometricCenter()
  2183. {
  2184. // this is not real geometric center but a average of positions relative to root prim acording to
  2185. // http://wiki.secondlife.com/wiki/llGetGeometricCenter
  2186. // ignoring tortured prims details since sl also seems to ignore
  2187. // so no real use in doing it on physics
  2188. if (ParentGroup.IsDeleted)
  2189. return new Vector3(0, 0, 0);
  2190. return ParentGroup.GetGeometricCenter();
  2191. }
  2192. public float GetMass()
  2193. {
  2194. PhysicsActor pa = PhysActor;
  2195. if (pa != null)
  2196. return pa.Mass;
  2197. else
  2198. return 0;
  2199. }
  2200. public Vector3 GetCenterOfMass()
  2201. {
  2202. if (ParentGroup.RootPart == this)
  2203. {
  2204. if (ParentGroup.IsDeleted)
  2205. return AbsolutePosition;
  2206. return ParentGroup.GetCenterOfMass();
  2207. }
  2208. PhysicsActor pa = PhysActor;
  2209. if (pa != null)
  2210. {
  2211. Vector3 tmp = pa.CenterOfMass;
  2212. return tmp;
  2213. }
  2214. else
  2215. return AbsolutePosition;
  2216. }
  2217. public Vector3 GetPartCenterOfMass()
  2218. {
  2219. PhysicsActor pa = PhysActor;
  2220. if (pa != null)
  2221. {
  2222. Vector3 tmp = pa.CenterOfMass;
  2223. return tmp;
  2224. }
  2225. else
  2226. return AbsolutePosition;
  2227. }
  2228. public Vector3 GetForce()
  2229. {
  2230. return Force;
  2231. }
  2232. /// <summary>
  2233. /// Method for a prim to get it's world position from the group.
  2234. /// </summary>
  2235. /// <remarks>
  2236. /// Remember, the Group Position simply gives the position of the group itself
  2237. /// </remarks>
  2238. /// <returns>A Linked Child Prim objects position in world</returns>
  2239. public Vector3 GetWorldPosition()
  2240. {
  2241. if (_parentID == 0)
  2242. return GroupPosition;
  2243. // If a child SOP, my position is relative to the root SOP so take
  2244. // my info and add the root's position and rotation to
  2245. // get my world position.
  2246. return ParentGroup.AbsolutePosition + OffsetPosition * ParentGroup.RootPart.RotationOffset;
  2247. }
  2248. /// <summary>
  2249. /// Gets the rotation of this prim offset by the group rotation
  2250. /// </summary>
  2251. /// <returns></returns>
  2252. public Quaternion GetWorldRotation()
  2253. {
  2254. if (_parentID == 0)
  2255. return RotationOffset;
  2256. // A child SOP's rotation is relative to the root SOP's rotation.
  2257. // Combine them to get my absolute rotation.
  2258. return ParentGroup.RootPart.RotationOffset * RotationOffset;
  2259. }
  2260. /// <summary>
  2261. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2262. /// </summary>
  2263. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2264. /// <param name="hoverType">Determines what the height is relative to </param>
  2265. /// <param name="tau">Number of seconds over which to reach target</param>
  2266. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2267. {
  2268. ParentGroup.SetHoverHeight(height, hoverType, tau);
  2269. }
  2270. public void StopHover()
  2271. {
  2272. ParentGroup.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  2273. }
  2274. public virtual void OnGrab(Vector3 offsetPos, IClientAPI remoteClient)
  2275. {
  2276. }
  2277. public bool CollisionFilteredOut(UUID objectID, string objectName)
  2278. {
  2279. if(CollisionFilter.Count == 0)
  2280. return false;
  2281. if (CollisionFilter.ContainsValue(objectID.ToString()) ||
  2282. CollisionFilter.ContainsValue(objectID.ToString() + objectName) ||
  2283. CollisionFilter.ContainsValue(UUID.Zero.ToString() + objectName))
  2284. {
  2285. if (CollisionFilter.ContainsKey(1))
  2286. return false;
  2287. return true;
  2288. }
  2289. if (CollisionFilter.ContainsKey(1))
  2290. return true;
  2291. return false;
  2292. }
  2293. private DetectedObject CreateDetObject(SceneObjectPart obj)
  2294. {
  2295. DetectedObject detobj = new DetectedObject();
  2296. detobj.keyUUID = obj.UUID;
  2297. detobj.nameStr = obj.Name;
  2298. detobj.ownerUUID = obj.OwnerID;
  2299. detobj.posVector = obj.AbsolutePosition;
  2300. detobj.rotQuat = obj.GetWorldRotation();
  2301. detobj.velVector = obj.Velocity;
  2302. detobj.colliderType = 0;
  2303. detobj.groupUUID = obj.GroupID;
  2304. // allow detector link number to be seen, unlike spec
  2305. //if (VolumeDetectActive)
  2306. // detobj.linkNumber = 0;
  2307. //else
  2308. detobj.linkNumber = LinkNum;
  2309. return detobj;
  2310. }
  2311. private DetectedObject CreateDetObject(ScenePresence av)
  2312. {
  2313. DetectedObject detobj = new DetectedObject();
  2314. detobj.keyUUID = av.UUID;
  2315. detobj.nameStr = av.ControllingClient.Name;
  2316. detobj.ownerUUID = av.UUID;
  2317. detobj.posVector = av.AbsolutePosition;
  2318. detobj.rotQuat = av.Rotation;
  2319. detobj.velVector = av.Velocity;
  2320. detobj.colliderType = av.IsNPC ? 0x20 : 0x1; // OpenSim\Region\ScriptEngine\Shared\Helpers.cs
  2321. if(av.IsSatOnObject)
  2322. detobj.colliderType |= 0x4; //passive
  2323. else if(detobj.velVector != Vector3.Zero)
  2324. detobj.colliderType |= 0x2; //active
  2325. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2326. //if (VolumeDetectActive)
  2327. // detobj.linkNumber = 0;
  2328. //else
  2329. detobj.linkNumber = LinkNum;
  2330. return detobj;
  2331. }
  2332. private DetectedObject CreateDetObjectForGround()
  2333. {
  2334. DetectedObject detobj = new DetectedObject();
  2335. detobj.keyUUID = UUID.Zero;
  2336. detobj.nameStr = "";
  2337. detobj.ownerUUID = UUID.Zero;
  2338. detobj.posVector = ParentGroup.RootPart.AbsolutePosition;
  2339. detobj.rotQuat = Quaternion.Identity;
  2340. detobj.velVector = Vector3.Zero;
  2341. detobj.colliderType = 0;
  2342. detobj.groupUUID = UUID.Zero;
  2343. detobj.linkNumber = LinkNum;
  2344. return detobj;
  2345. }
  2346. private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
  2347. {
  2348. ColliderArgs colliderArgs = new ColliderArgs();
  2349. List<DetectedObject> colliding = new List<DetectedObject>();
  2350. Scene parentScene = ParentGroup.Scene;
  2351. foreach (uint localId in colliders)
  2352. {
  2353. if (localId == 0)
  2354. continue;
  2355. SceneObjectPart obj = parentScene.GetSceneObjectPart(localId);
  2356. if (obj != null)
  2357. {
  2358. if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
  2359. colliding.Add(CreateDetObject(obj));
  2360. }
  2361. else
  2362. {
  2363. ScenePresence av = parentScene.GetScenePresence(localId);
  2364. if (av != null && (!av.IsChildAgent))
  2365. {
  2366. if (!dest.CollisionFilteredOut(av.UUID, av.Name))
  2367. colliding.Add(CreateDetObject(av));
  2368. }
  2369. }
  2370. }
  2371. colliderArgs.Colliders = colliding;
  2372. return colliderArgs;
  2373. }
  2374. private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
  2375. private void SendCollisionEvent(scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
  2376. {
  2377. bool sendToRoot = false;
  2378. ColliderArgs CollidingMessage;
  2379. if (colliders.Count > 0)
  2380. {
  2381. if ((ScriptEvents & ev) != 0)
  2382. {
  2383. CollidingMessage = CreateColliderArgs(this, colliders);
  2384. if (CollidingMessage.Colliders.Count > 0)
  2385. notify(LocalId, CollidingMessage);
  2386. if (PassCollisions)
  2387. sendToRoot = true;
  2388. }
  2389. else
  2390. {
  2391. if ((ParentGroup.RootPart.ScriptEvents & ev) != 0)
  2392. sendToRoot = true;
  2393. }
  2394. if (sendToRoot && ParentGroup.RootPart != this)
  2395. {
  2396. CollidingMessage = CreateColliderArgs(ParentGroup.RootPart, colliders);
  2397. if (CollidingMessage.Colliders.Count > 0)
  2398. notify(ParentGroup.RootPart.LocalId, CollidingMessage);
  2399. }
  2400. }
  2401. }
  2402. private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
  2403. {
  2404. bool sendToRoot = true;
  2405. ColliderArgs LandCollidingMessage = new ColliderArgs();
  2406. List<DetectedObject> colliding = new List<DetectedObject>();
  2407. colliding.Add(CreateDetObjectForGround());
  2408. LandCollidingMessage.Colliders = colliding;
  2409. if (Inventory.ContainsScripts())
  2410. {
  2411. if (!PassCollisions)
  2412. sendToRoot = false;
  2413. }
  2414. if ((ScriptEvents & ev) != 0)
  2415. notify(LocalId, LandCollidingMessage);
  2416. if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
  2417. {
  2418. notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
  2419. }
  2420. }
  2421. public void PhysicsCollision(EventArgs e)
  2422. {
  2423. if (ParentGroup.Scene == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  2424. return;
  2425. // this a thread from physics ( heartbeat )
  2426. bool thisHitLand = false;
  2427. bool startLand = false;
  2428. bool endedLand = false;
  2429. CollisionEventUpdate a = (CollisionEventUpdate)e;
  2430. Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
  2431. List<uint> thisHitColliders = new List<uint>();
  2432. List<uint> endedColliders = new List<uint>();
  2433. List<uint> startedColliders = new List<uint>();
  2434. if (collissionswith.Count == 0)
  2435. {
  2436. if (m_lastColliders.Count == 0 && !m_lastLandCollide)
  2437. return; // nothing to do
  2438. endedLand = m_lastLandCollide;
  2439. m_lastLandCollide = false;
  2440. foreach (uint localID in m_lastColliders)
  2441. {
  2442. endedColliders.Add(localID);
  2443. }
  2444. m_lastColliders.Clear();
  2445. }
  2446. else
  2447. {
  2448. List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
  2449. // calculate things that started colliding this time
  2450. // and build up list of colliders this time
  2451. if (!VolumeDetectActive && CollisionSoundType >= 0)
  2452. {
  2453. CollisionForSoundInfo soundinfo;
  2454. ContactPoint curcontact;
  2455. foreach (uint id in collissionswith.Keys)
  2456. {
  2457. if(id == 0)
  2458. {
  2459. thisHitLand = true;
  2460. if (!m_lastLandCollide)
  2461. {
  2462. startLand = true;
  2463. curcontact = collissionswith[id];
  2464. if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
  2465. {
  2466. soundinfo = new CollisionForSoundInfo();
  2467. soundinfo.colliderID = id;
  2468. soundinfo.position = curcontact.Position;
  2469. soundinfo.relativeVel = curcontact.RelativeSpeed;
  2470. soundinfolist.Add(soundinfo);
  2471. }
  2472. }
  2473. }
  2474. else
  2475. {
  2476. thisHitColliders.Add(id);
  2477. if (!m_lastColliders.Contains(id))
  2478. {
  2479. startedColliders.Add(id);
  2480. curcontact = collissionswith[id];
  2481. if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
  2482. {
  2483. soundinfo = new CollisionForSoundInfo();
  2484. soundinfo.colliderID = id;
  2485. soundinfo.position = curcontact.Position;
  2486. soundinfo.relativeVel = curcontact.RelativeSpeed;
  2487. soundinfolist.Add(soundinfo);
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. else
  2494. {
  2495. foreach (uint id in collissionswith.Keys)
  2496. {
  2497. if(id == 0)
  2498. {
  2499. thisHitLand = true;
  2500. if (!m_lastLandCollide)
  2501. startLand = true;
  2502. }
  2503. else
  2504. {
  2505. thisHitColliders.Add(id);
  2506. if (!m_lastColliders.Contains(id))
  2507. startedColliders.Add(id);
  2508. }
  2509. }
  2510. }
  2511. // calculate things that ended colliding
  2512. foreach (uint localID in m_lastColliders)
  2513. {
  2514. if (!thisHitColliders.Contains(localID))
  2515. endedColliders.Add(localID);
  2516. }
  2517. //add the items that started colliding this time to the last colliders list.
  2518. foreach (uint localID in startedColliders)
  2519. m_lastColliders.Add(localID);
  2520. // remove things that ended colliding from the last colliders list
  2521. foreach (uint localID in endedColliders)
  2522. m_lastColliders.Remove(localID);
  2523. if(m_lastLandCollide && !thisHitLand)
  2524. endedLand = true;
  2525. m_lastLandCollide = thisHitLand;
  2526. // play sounds.
  2527. if (soundinfolist.Count > 0)
  2528. CollisionSounds.PartCollisionSound(this, soundinfolist);
  2529. }
  2530. EventManager eventmanager = ParentGroup.Scene.EventManager;
  2531. SendCollisionEvent(scriptEvents.collision_start, startedColliders, eventmanager.TriggerScriptCollidingStart);
  2532. if (!VolumeDetectActive)
  2533. SendCollisionEvent(scriptEvents.collision , m_lastColliders , eventmanager.TriggerScriptColliding);
  2534. SendCollisionEvent(scriptEvents.collision_end , endedColliders , eventmanager.TriggerScriptCollidingEnd);
  2535. if (!VolumeDetectActive)
  2536. {
  2537. if (startLand)
  2538. SendLandCollisionEvent(scriptEvents.land_collision_start, eventmanager.TriggerScriptLandCollidingStart);
  2539. if (m_lastLandCollide)
  2540. SendLandCollisionEvent(scriptEvents.land_collision, eventmanager.TriggerScriptLandColliding);
  2541. if (endedLand)
  2542. SendLandCollisionEvent(scriptEvents.land_collision_end, eventmanager.TriggerScriptLandCollidingEnd);
  2543. }
  2544. }
  2545. // The Collision sounds code calls this
  2546. public void SendCollisionSound(UUID soundID, double volume, Vector3 position)
  2547. {
  2548. if (soundID == UUID.Zero)
  2549. return;
  2550. ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
  2551. if (soundModule == null)
  2552. return;
  2553. if (volume > 1)
  2554. volume = 1;
  2555. if (volume < 0)
  2556. volume = 0;
  2557. int now = Util.EnvironmentTickCount();
  2558. if(Util.EnvironmentTickCountSubtract(now, LastColSoundSentTime) < 200)
  2559. return;
  2560. LastColSoundSentTime = now;
  2561. UUID ownerID = OwnerID;
  2562. UUID objectID = ParentGroup.RootPart.UUID;
  2563. UUID parentID = ParentGroup.UUID;
  2564. ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
  2565. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle);
  2566. }
  2567. public void PhysicsOutOfBounds(Vector3 pos)
  2568. {
  2569. // Note: This is only being called on the root prim at this time.
  2570. m_log.ErrorFormat(
  2571. "[SCENE OBJECT PART]: Physical object {0}, localID {1} went out of bounds at {2} in {3}. Stopping at {4} and making non-physical.",
  2572. Name, LocalId, pos, ParentGroup.Scene.Name, AbsolutePosition);
  2573. RemFlag(PrimFlags.Physics);
  2574. DoPhysicsPropertyUpdate(false, true);
  2575. }
  2576. public void PhysicsRequestingTerseUpdate()
  2577. {
  2578. PhysicsActor pa = PhysActor;
  2579. if (pa != null)
  2580. {
  2581. Vector3 newpos = pa.Position;
  2582. if (!ParentGroup.Scene.PositionIsInCurrentRegion(newpos))
  2583. {
  2584. // Setting position outside current region will start region crossing
  2585. ParentGroup.AbsolutePosition = newpos;
  2586. return;
  2587. }
  2588. //ParentGroup.RootPart.m_groupPosition = newpos;
  2589. }
  2590. ScheduleTerseUpdate();
  2591. }
  2592. public void RemFlag(PrimFlags flag)
  2593. {
  2594. // PrimFlags prevflag = Flags;
  2595. if ((Flags & flag) != 0)
  2596. {
  2597. //m_log.Debug("Removing flag: " + ((PrimFlags)flag).ToString());
  2598. Flags &= ~flag;
  2599. }
  2600. //m_log.Debug("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  2601. //ScheduleFullUpdate();
  2602. }
  2603. public void RemoveScriptEvents(UUID scriptid)
  2604. {
  2605. lock (m_scriptEvents)
  2606. {
  2607. if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev))
  2608. {
  2609. if((ev & (scriptEvents.anyTarget)) != 0 && ParentGroup != null)
  2610. ParentGroup.RemoveScriptTargets(scriptid);
  2611. m_scriptEvents.Remove(scriptid);
  2612. aggregateScriptEvents();
  2613. }
  2614. }
  2615. }
  2616. public void RemoveScriptTargets(UUID scriptid)
  2617. {
  2618. if(ParentGroup != null)
  2619. ParentGroup.RemoveScriptTargets(scriptid);
  2620. }
  2621. /// <summary>
  2622. /// Reset UUIDs for this part. This involves generate this part's own UUID and
  2623. /// generating new UUIDs for all the items in the inventory.
  2624. /// </summary>
  2625. /// <param name="linkNum">Link number for the part</param>
  2626. public void ResetIDs(int linkNum)
  2627. {
  2628. UUID = UUID.Random();
  2629. LinkNum = linkNum;
  2630. LocalId = 0;
  2631. Inventory.ResetInventoryIDs();
  2632. ++PseudoCRC;
  2633. }
  2634. private void ClampScale(bool isPhysical)
  2635. {
  2636. float minsize = isPhysical ? ParentGroup.Scene.m_minPhys : ParentGroup.Scene.m_minNonphys;
  2637. float maxsize = isPhysical ? ParentGroup.Scene.m_maxPhys : ParentGroup.Scene.m_maxNonphys;
  2638. Vector3 scale = Scale;
  2639. bool changed = false;
  2640. if (scale.X < minsize)
  2641. {
  2642. scale.X = minsize;
  2643. changed = true;
  2644. }
  2645. else if (scale.X > maxsize)
  2646. {
  2647. scale.X = maxsize;
  2648. changed = true;
  2649. }
  2650. if (scale.Y < minsize)
  2651. {
  2652. scale.Y = minsize;
  2653. changed = true;
  2654. }
  2655. else if (scale.Y > maxsize)
  2656. {
  2657. scale.Y = maxsize;
  2658. changed = true;
  2659. }
  2660. if (scale.Z < minsize)
  2661. {
  2662. scale.Z = minsize;
  2663. changed = true;
  2664. }
  2665. else if (scale.Z > maxsize)
  2666. {
  2667. scale.Z = maxsize;
  2668. changed = true;
  2669. }
  2670. if (changed)
  2671. Scale = scale;
  2672. }
  2673. /// <summary>
  2674. /// Set the scale of this part.
  2675. /// </summary>
  2676. /// <remarks>
  2677. /// Unlike the scale property, this checks the new size against scene limits and schedules a full property
  2678. /// update to viewers.
  2679. /// </remarks>
  2680. /// <param name="scale"></param>
  2681. public void Resize(Vector3 scale)
  2682. {
  2683. PhysicsActor pa = PhysActor;
  2684. if (ParentGroup.Scene != null)
  2685. {
  2686. float minsize = ParentGroup.Scene.m_minNonphys;
  2687. float maxsize = ParentGroup.Scene.m_maxNonphys;
  2688. if (pa != null && pa.IsPhysical)
  2689. {
  2690. minsize = ParentGroup.Scene.m_minPhys;
  2691. maxsize = ParentGroup.Scene.m_maxPhys;
  2692. }
  2693. scale.X = Util.Clamp(scale.X, minsize, maxsize);
  2694. scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
  2695. scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
  2696. }
  2697. // m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale);
  2698. Scale = scale;
  2699. ParentGroup.HasGroupChanged = true;
  2700. ScheduleFullUpdate();
  2701. }
  2702. public void RotLookAt(Quaternion target, float strength, float damping)
  2703. {
  2704. if(ParentGroup.IsDeleted)
  2705. return;
  2706. // for now we only handle physics case
  2707. if(!ParentGroup.UsesPhysics || ParentGroup.IsAttachment)
  2708. return;
  2709. // physical is SOG
  2710. if(ParentGroup.RootPart != this)
  2711. {
  2712. ParentGroup.RotLookAt(target, strength, damping);
  2713. return;
  2714. }
  2715. APIDDamp = damping;
  2716. APIDStrength = strength;
  2717. APIDTarget = target;
  2718. if (APIDStrength <= 0)
  2719. {
  2720. m_log.WarnFormat("[SceneObjectPart] Invalid rotation strength {0}",APIDStrength);
  2721. return;
  2722. }
  2723. APIDActive = true;
  2724. // Necessary to get the lookat deltas applied
  2725. ParentGroup.QueueForUpdateCheck();
  2726. }
  2727. public void StartLookAt(Quaternion target, float strength, float damping)
  2728. {
  2729. if(ParentGroup.IsDeleted)
  2730. return;
  2731. // non physical is done on LSL
  2732. if(ParentGroup.IsAttachment || !ParentGroup.UsesPhysics)
  2733. return;
  2734. // physical is SOG
  2735. if(ParentGroup.RootPart != this)
  2736. ParentGroup.RotLookAt(target, strength, damping);
  2737. else
  2738. RotLookAt(target,strength,damping);
  2739. }
  2740. public void StopLookAt()
  2741. {
  2742. if(ParentGroup.IsDeleted)
  2743. return;
  2744. if(ParentGroup.RootPart != this && ParentGroup.UsesPhysics)
  2745. ParentGroup.StopLookAt();
  2746. // just in case do this always
  2747. if(APIDActive)
  2748. AngularVelocity = Vector3.Zero;
  2749. APIDActive = false;
  2750. }
  2751. /// <summary>
  2752. /// Schedules this prim for a full update
  2753. /// </summary>
  2754. public void ScheduleFullUpdate()
  2755. {
  2756. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2757. return;
  2758. ++PseudoCRC;
  2759. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2760. return;
  2761. ParentGroup.QueueForUpdateCheck(); // just in case
  2762. lock(UpdateFlagLock)
  2763. UpdateFlag |= PrimUpdateFlags.FullUpdate;
  2764. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, true);
  2765. }
  2766. public void ScheduleFullAnimUpdate()
  2767. {
  2768. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2769. return;
  2770. ++PseudoCRC;
  2771. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2772. return;
  2773. PrimUpdateFlags update = PrimUpdateFlags.FullUpdatewithAnim;
  2774. if (Animations == null || !ParentGroup.RootPart.Shape.MeshFlagEntry)
  2775. update = PrimUpdateFlags.FullUpdate;
  2776. ParentGroup.QueueForUpdateCheck(); // just in case
  2777. lock (UpdateFlagLock)
  2778. UpdateFlag |= update;
  2779. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, true);
  2780. }
  2781. /// <summary>
  2782. /// Schedule a terse update for this prim. Terse updates only send position,
  2783. /// rotation, velocity and rotational velocity information.
  2784. /// </summary>
  2785. public void ScheduleTerseUpdate()
  2786. {
  2787. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2788. return;
  2789. ++PseudoCRC;
  2790. ParentGroup.HasGroupChanged = true;
  2791. if(ParentGroup.Scene.GetNumberOfClients() == 0)
  2792. return;
  2793. ParentGroup.QueueForUpdateCheck();
  2794. bool isfull = false;
  2795. PrimUpdateFlags update;
  2796. if (ParentGroup.IsAttachment)
  2797. {
  2798. update = PrimUpdateFlags.FullUpdate;
  2799. isfull = true;
  2800. }
  2801. else
  2802. update = PrimUpdateFlags.TerseUpdate;
  2803. lock (UpdateFlagLock)
  2804. UpdateFlag |= update;
  2805. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, isfull);
  2806. }
  2807. public void ScheduleUpdate(PrimUpdateFlags update)
  2808. {
  2809. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2810. return;
  2811. if (Animations == null)
  2812. update &= ~PrimUpdateFlags.Animations;
  2813. if (update == PrimUpdateFlags.None)
  2814. return;
  2815. ++PseudoCRC;
  2816. ParentGroup.HasGroupChanged = true;
  2817. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2818. return;
  2819. bool isfull = false;
  2820. if (ParentGroup.IsAttachment)
  2821. {
  2822. update |= PrimUpdateFlags.FullUpdate;
  2823. isfull = true;
  2824. }
  2825. lock (UpdateFlagLock)
  2826. UpdateFlag |= update;
  2827. ParentGroup.QueueForUpdateCheck();
  2828. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, isfull);
  2829. }
  2830. public void ScriptSetPhysicsStatus(bool UsePhysics)
  2831. {
  2832. ParentGroup.ScriptSetPhysicsStatus(UsePhysics);
  2833. }
  2834. /// <summary>
  2835. /// Send a full update to the client for the given part
  2836. /// </summary>
  2837. /// <param name="remoteClient"></param>
  2838. protected internal void SendFullUpdate(IClientAPI remoteClient)
  2839. {
  2840. if (ParentGroup == null)
  2841. return;
  2842. if (ParentGroup.IsAttachment)
  2843. {
  2844. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2845. if (sp != null)
  2846. sp.SendAttachmentUpdate(this, PrimUpdateFlags.FullUpdate);
  2847. }
  2848. else
  2849. {
  2850. SendUpdateToClient(remoteClient, PrimUpdateFlags.FullUpdate);
  2851. }
  2852. }
  2853. protected internal void SendUpdate(IClientAPI remoteClient, PrimUpdateFlags update)
  2854. {
  2855. if (ParentGroup == null)
  2856. return;
  2857. if (ParentGroup.IsAttachment)
  2858. {
  2859. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2860. if (sp != null)
  2861. sp.SendAttachmentUpdate(this, update);
  2862. }
  2863. else
  2864. {
  2865. SendUpdateToClient(remoteClient, update);
  2866. }
  2867. }
  2868. /// <summary>
  2869. /// Send a full update for this part to all clients.
  2870. /// </summary>
  2871. public void SendFullUpdateToAllClientsNoAttachment()
  2872. {
  2873. if (ParentGroup == null)
  2874. return;
  2875. ++PseudoCRC;
  2876. // Update the "last" values
  2877. lock (UpdateFlagLock)
  2878. {
  2879. m_lastPosition = AbsolutePosition;
  2880. m_lastRotation = RotationOffset;
  2881. m_lastVelocity = Velocity;
  2882. m_lastAcceleration = Acceleration;
  2883. m_lastAngularVelocity = AngularVelocity;
  2884. m_lastUpdateSentTime = Util.GetTimeStampMS();
  2885. UpdateFlag &= ~PrimUpdateFlags.FullUpdate;
  2886. }
  2887. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2888. {
  2889. SendUpdateToClient(avatar.ControllingClient, PrimUpdateFlags.FullUpdate);
  2890. });
  2891. }
  2892. public void SendFullUpdateToAllClients()
  2893. {
  2894. if (ParentGroup == null)
  2895. return;
  2896. ++PseudoCRC;
  2897. // Update the "last" values
  2898. lock (UpdateFlagLock)
  2899. {
  2900. m_lastPosition = AbsolutePosition;
  2901. m_lastRotation = RotationOffset;
  2902. m_lastVelocity = Velocity;
  2903. m_lastAcceleration = Acceleration;
  2904. m_lastAngularVelocity = AngularVelocity;
  2905. m_lastUpdateSentTime = Util.GetTimeStampMS();
  2906. UpdateFlag &= ~PrimUpdateFlags.FullUpdate;
  2907. }
  2908. if (ParentGroup.IsAttachment)
  2909. {
  2910. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2911. if (sp != null)
  2912. sp.SendAttachmentUpdate(this, PrimUpdateFlags.FullUpdate);
  2913. }
  2914. else
  2915. {
  2916. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2917. {
  2918. SendUpdateToClient(avatar.ControllingClient, PrimUpdateFlags.FullUpdate);
  2919. });
  2920. }
  2921. }
  2922. private const float ROTATION_TOLERANCE = 0.01f;
  2923. private const float VELOCITY_TOLERANCE = 0.1f;
  2924. private const float ANGVELOCITY_TOLERANCE = 0.005f;
  2925. private const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
  2926. private const double TIME_MS_TOLERANCE = 250.0; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
  2927. private Vector3 ClampVectorForTerseUpdate(Vector3 v, float max)
  2928. {
  2929. float a, b;
  2930. a = Math.Abs(v.X);
  2931. b = Math.Abs(v.Y);
  2932. if (b > a)
  2933. a = b;
  2934. b = Math.Abs(v.Z);
  2935. if (b > a)
  2936. a = b;
  2937. if (a > max)
  2938. {
  2939. a = max / a;
  2940. v.X *= a;
  2941. v.Y *= a;
  2942. v.Z *= a;
  2943. }
  2944. return v;
  2945. }
  2946. /// <summary>
  2947. /// Tell all the prims which have had updates scheduled
  2948. /// </summary>
  2949. public void SendScheduledUpdates(double now)
  2950. {
  2951. PrimUpdateFlags current;
  2952. lock (UpdateFlagLock)
  2953. {
  2954. current = UpdateFlag;
  2955. if (current == PrimUpdateFlags.None)
  2956. return;
  2957. if(current == PrimUpdateFlags.TerseUpdate)
  2958. {
  2959. while(true) // just to avoid ugly goto
  2960. {
  2961. double elapsed = now - m_lastUpdateSentTime;
  2962. if (elapsed > TIME_MS_TOLERANCE)
  2963. break;
  2964. if ( !Acceleration.ApproxEquals(m_lastAcceleration, VELOCITY_TOLERANCE))
  2965. break;
  2966. Vector3 curvel = ClampVectorForTerseUpdate(Velocity, 128f);
  2967. Vector3 tmp = ClampVectorForTerseUpdate(m_lastVelocity, 128f);
  2968. if (!curvel.ApproxEquals(tmp, VELOCITY_TOLERANCE))
  2969. break;
  2970. if (Math.Abs(curvel.X) < 1e-4 && Math.Abs(curvel.Y) < 1e-4 && Math.Abs(curvel.Z) < 1e-4)
  2971. {
  2972. if (!AbsolutePosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
  2973. break;
  2974. if ( Math.Abs(m_lastVelocity.X) > 1e-4 ||
  2975. Math.Abs(m_lastVelocity.Y) > 1e-4 ||
  2976. Math.Abs(m_lastVelocity.Z) > 1e-4
  2977. )
  2978. break;
  2979. }
  2980. Vector3 angvel = ClampVectorForTerseUpdate(AngularVelocity, 64f);
  2981. tmp = ClampVectorForTerseUpdate(m_lastAngularVelocity, 64f);
  2982. if (!angvel.ApproxEquals(tmp, ANGVELOCITY_TOLERANCE))
  2983. break;
  2984. if ( Math.Abs(AngularVelocity.X) < 1e-4 &&
  2985. Math.Abs(AngularVelocity.Y) < 1e-4 &&
  2986. Math.Abs(AngularVelocity.Z) < 1e-4 &&
  2987. !RotationOffset.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
  2988. )
  2989. break;
  2990. return;
  2991. }
  2992. }
  2993. if((current & PrimUpdateFlags.TerseUpdate) != 0)
  2994. {
  2995. m_lastPosition = AbsolutePosition;
  2996. m_lastRotation = RotationOffset;
  2997. m_lastVelocity = Velocity;
  2998. m_lastAcceleration = Acceleration;
  2999. m_lastAngularVelocity = AngularVelocity;
  3000. m_lastUpdateSentTime = now;
  3001. }
  3002. UpdateFlag = PrimUpdateFlags.None;
  3003. }
  3004. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  3005. {
  3006. SendUpdateToClient(avatar.ControllingClient, current);
  3007. });
  3008. }
  3009. /// <summary>
  3010. /// Send a terse update to all clients
  3011. /// </summary>
  3012. public void SendTerseUpdateToAllClientsInternal()
  3013. {
  3014. if (ParentGroup == null || ParentGroup.Scene == null)
  3015. return;
  3016. lock(UpdateFlagLock)
  3017. {
  3018. UpdateFlag &= ~PrimUpdateFlags.TerseUpdate;
  3019. // Update the "last" values
  3020. m_lastPosition = AbsolutePosition;
  3021. m_lastRotation = RotationOffset;
  3022. m_lastVelocity = Velocity;
  3023. m_lastAcceleration = Acceleration;
  3024. m_lastAngularVelocity = AngularVelocity;
  3025. m_lastUpdateSentTime = Util.GetTimeStampMS();
  3026. }
  3027. ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
  3028. {
  3029. SendTerseUpdateToClient(client);
  3030. });
  3031. }
  3032. public void SendTerseUpdateToAllClients()
  3033. {
  3034. if (ParentGroup == null || ParentGroup.Scene == null)
  3035. return;
  3036. lock(UpdateFlagLock)
  3037. {
  3038. UpdateFlag &= ~PrimUpdateFlags.TerseUpdate;
  3039. // Update the "last" values
  3040. m_lastPosition = AbsolutePosition;
  3041. m_lastRotation = RotationOffset;
  3042. m_lastVelocity = Velocity;
  3043. m_lastAcceleration = Acceleration;
  3044. m_lastAngularVelocity = AngularVelocity;
  3045. m_lastUpdateSentTime = Util.GetTimeStampMS();
  3046. }
  3047. if (ParentGroup.IsAttachment)
  3048. {
  3049. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  3050. if (sp != null)
  3051. {
  3052. sp.SendAttachmentUpdate(this, PrimUpdateFlags.TerseUpdate);
  3053. }
  3054. }
  3055. else
  3056. {
  3057. ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
  3058. {
  3059. SendTerseUpdateToClient(client);
  3060. });
  3061. }
  3062. }
  3063. public void SetAxisRotation(int axis, int rotate)
  3064. {
  3065. ParentGroup.SetAxisRotation(axis, rotate);
  3066. //Cannot use ScriptBaseClass constants as no referance to it currently.
  3067. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  3068. STATUS_ROTATE_X = rotate;
  3069. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  3070. STATUS_ROTATE_Y = rotate;
  3071. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  3072. STATUS_ROTATE_Z = rotate;
  3073. }
  3074. public void SetBuoyancy(float fvalue)
  3075. {
  3076. Buoyancy = fvalue;
  3077. }
  3078. public void SetDieAtEdge(bool p)
  3079. {
  3080. if (ParentGroup.IsDeleted)
  3081. return;
  3082. ParentGroup.RootPart.DIE_AT_EDGE = p;
  3083. }
  3084. public void SetFloatOnWater(int floatYN)
  3085. {
  3086. PhysicsActor pa = PhysActor;
  3087. if (pa != null)
  3088. pa.FloatOnWater = (floatYN == 1);
  3089. }
  3090. public void SetForce(Vector3 force)
  3091. {
  3092. Force = force;
  3093. }
  3094. public PhysicsInertiaData PhysicsInertia
  3095. {
  3096. get
  3097. {
  3098. return m_physicsInertia;
  3099. }
  3100. set
  3101. {
  3102. m_physicsInertia = value;
  3103. }
  3104. }
  3105. public SOPVehicle VehicleParams
  3106. {
  3107. get
  3108. {
  3109. return m_vehicleParams;
  3110. }
  3111. set
  3112. {
  3113. m_vehicleParams = value;
  3114. }
  3115. }
  3116. public int VehicleType
  3117. {
  3118. get
  3119. {
  3120. if (m_vehicleParams == null)
  3121. return (int)Vehicle.TYPE_NONE;
  3122. else
  3123. return (int)m_vehicleParams.Type;
  3124. }
  3125. set
  3126. {
  3127. SetVehicleType(value);
  3128. }
  3129. }
  3130. public void SetVehicleType(int type)
  3131. {
  3132. m_vehicleParams = null;
  3133. if (type == (int)Vehicle.TYPE_NONE)
  3134. {
  3135. if (_parentID ==0 && PhysActor != null)
  3136. PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
  3137. return;
  3138. }
  3139. m_vehicleParams = new SOPVehicle();
  3140. m_vehicleParams.ProcessTypeChange((Vehicle)type);
  3141. {
  3142. if (_parentID ==0 && PhysActor != null)
  3143. PhysActor.VehicleType = type;
  3144. return;
  3145. }
  3146. }
  3147. public void SetVehicleFlags(int param, bool remove)
  3148. {
  3149. if (m_vehicleParams == null)
  3150. return;
  3151. m_vehicleParams.ProcessVehicleFlags(param, remove);
  3152. if (_parentID == 0 && PhysActor != null)
  3153. {
  3154. PhysActor.VehicleFlags(param, remove);
  3155. }
  3156. }
  3157. public void SetVehicleFloatParam(int param, float value)
  3158. {
  3159. if (m_vehicleParams == null)
  3160. return;
  3161. m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
  3162. if (_parentID == 0 && PhysActor != null)
  3163. {
  3164. PhysActor.VehicleFloatParam(param, value);
  3165. }
  3166. }
  3167. public void SetVehicleVectorParam(int param, Vector3 value)
  3168. {
  3169. if (m_vehicleParams == null)
  3170. return;
  3171. m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
  3172. if (_parentID == 0 && PhysActor != null)
  3173. {
  3174. PhysActor.VehicleVectorParam(param, value);
  3175. }
  3176. }
  3177. public void SetVehicleRotationParam(int param, Quaternion rotation)
  3178. {
  3179. if (m_vehicleParams == null)
  3180. return;
  3181. m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
  3182. if (_parentID == 0 && PhysActor != null)
  3183. {
  3184. PhysActor.VehicleRotationParam(param, rotation);
  3185. }
  3186. }
  3187. /// <summary>
  3188. /// Set the color & alpha of prim faces
  3189. /// </summary>
  3190. /// <param name="face"></param>
  3191. /// <param name="color"></param>
  3192. /// <param name="alpha"></param>
  3193. public void SetFaceColorAlpha(int face, Vector3 color, double ?alpha)
  3194. {
  3195. Vector3 clippedColor = Util.Clip(color, 0.0f, 1.0f);
  3196. float clippedAlpha = alpha.HasValue ?
  3197. Util.Clip((float)alpha.Value, 0.0f, 1.0f) : 0;
  3198. // The only way to get a deep copy/ If we don't do this, we can
  3199. // never detect color changes further down.
  3200. Byte[] buf = Shape.Textures.GetBytes();
  3201. Primitive.TextureEntry tex = new Primitive.TextureEntry(buf, 0, buf.Length);
  3202. Color4 texcolor;
  3203. int nsides = GetNumberOfSides();
  3204. if (face >= 0 && face < nsides)
  3205. {
  3206. texcolor = tex.CreateFace((uint)face).RGBA;
  3207. texcolor.R = clippedColor.X;
  3208. texcolor.G = clippedColor.Y;
  3209. texcolor.B = clippedColor.Z;
  3210. if (alpha.HasValue)
  3211. {
  3212. texcolor.A = clippedAlpha;
  3213. }
  3214. tex.FaceTextures[face].RGBA = texcolor;
  3215. UpdateTextureEntry(tex);
  3216. return;
  3217. }
  3218. else if (face == ALL_SIDES)
  3219. {
  3220. for (uint i = 0; i < nsides; i++)
  3221. {
  3222. if (tex.FaceTextures[i] != null)
  3223. {
  3224. texcolor = tex.FaceTextures[i].RGBA;
  3225. texcolor.R = clippedColor.X;
  3226. texcolor.G = clippedColor.Y;
  3227. texcolor.B = clippedColor.Z;
  3228. if (alpha.HasValue)
  3229. {
  3230. texcolor.A = clippedAlpha;
  3231. }
  3232. tex.FaceTextures[i].RGBA = texcolor;
  3233. }
  3234. texcolor = tex.DefaultTexture.RGBA;
  3235. texcolor.R = clippedColor.X;
  3236. texcolor.G = clippedColor.Y;
  3237. texcolor.B = clippedColor.Z;
  3238. if (alpha.HasValue)
  3239. {
  3240. texcolor.A = clippedAlpha;
  3241. }
  3242. tex.DefaultTexture.RGBA = texcolor;
  3243. }
  3244. UpdateTextureEntry(tex);
  3245. return;
  3246. }
  3247. }
  3248. /// <summary>
  3249. /// Get the number of sides that this part has.
  3250. /// </summary>
  3251. /// <returns></returns>
  3252. public int GetNumberOfSides()
  3253. {
  3254. int ret = 0;
  3255. int cut;
  3256. if(Shape.SculptEntry)
  3257. {
  3258. if (Shape.SculptType != (byte)SculptType.Mesh)
  3259. return 1; // sculp
  3260. //hack to detect new upload with faces data enconded on pbs
  3261. if ((Shape.ProfileCurve & 0xf0) != (byte)HollowShape.Triangle)
  3262. // old broken upload TODO
  3263. return 8;
  3264. }
  3265. PrimType primType = GetPrimType(true);
  3266. switch (primType)
  3267. {
  3268. case PrimType.BOX:
  3269. ret = 6;
  3270. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut case
  3271. {
  3272. // removed sides
  3273. if (Shape.ProfileBegin > 0)
  3274. {
  3275. cut = Shape.ProfileBegin;
  3276. cut /= 12500;
  3277. ret -= cut;
  3278. }
  3279. if (Shape.ProfileEnd > 0)
  3280. {
  3281. cut = Shape.ProfileEnd;
  3282. cut /= 12500;
  3283. ret -= cut;
  3284. }
  3285. ret += 2;
  3286. }
  3287. break;
  3288. case PrimType.PRISM:
  3289. ret = 5;
  3290. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut case
  3291. {
  3292. // removed sides
  3293. if (Shape.ProfileBegin > 0)
  3294. {
  3295. cut = (Shape.ProfileBegin);
  3296. if(cut >= 16667 )
  3297. ret--;
  3298. if(cut >= 33333 )
  3299. ret--;
  3300. }
  3301. if (Shape.ProfileEnd > 0)
  3302. {
  3303. cut = (Shape.ProfileEnd);
  3304. if(cut >= 16667 )
  3305. ret--;
  3306. if(cut >= 33333 )
  3307. ret--;
  3308. }
  3309. ret += 2; // both cut faces
  3310. }
  3311. break;
  3312. case PrimType.CYLINDER:
  3313. ret = 3;
  3314. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut
  3315. ret += 2;
  3316. break;
  3317. case PrimType.SPHERE:
  3318. ret = 1;
  3319. // cut faces exist if cut or skew or unequal twist limits
  3320. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3321. ret += 2;
  3322. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0 || Shape.ProfileHollow > 0) // dimple also if hollow
  3323. ret += 2;
  3324. break;
  3325. case PrimType.TORUS:
  3326. ret = 1;
  3327. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3328. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3329. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3330. ret += 2;
  3331. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3332. ret += 2;
  3333. break;
  3334. case PrimType.TUBE:
  3335. ret = 4;
  3336. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3337. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3338. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3339. ret += 2;
  3340. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3341. {
  3342. if (Shape.ProfileBegin > 0)
  3343. {
  3344. cut = Shape.ProfileBegin;
  3345. cut /= 12500;
  3346. ret -= cut;
  3347. }
  3348. if (Shape.ProfileEnd > 0)
  3349. {
  3350. cut = Shape.ProfileEnd;
  3351. cut /= 12500;
  3352. ret -= cut;
  3353. }
  3354. ret += 2;
  3355. }
  3356. break;
  3357. case PrimType.RING:
  3358. ret = 3;
  3359. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3360. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3361. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3362. ret += 2;
  3363. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3364. {
  3365. if (Shape.ProfileBegin > 0)
  3366. {
  3367. cut = Shape.ProfileBegin;
  3368. if(cut >= 16667 )
  3369. ret--;
  3370. if(cut >= 33333 )
  3371. ret--;
  3372. }
  3373. if (Shape.ProfileEnd > 0)
  3374. {
  3375. cut = Shape.ProfileEnd;
  3376. if(cut >= 16667 )
  3377. ret--;
  3378. if(cut >= 33333 )
  3379. ret--;
  3380. }
  3381. ret += 2;
  3382. }
  3383. break;
  3384. }
  3385. // hollow face commum to all
  3386. if (Shape.ProfileHollow > 0)
  3387. ret += 1;
  3388. return ret;
  3389. }
  3390. /// <summary>
  3391. /// Tell us what type this prim is
  3392. /// </summary>
  3393. /// <param name="primShape"></param>
  3394. /// <returns></returns>
  3395. public PrimType GetPrimType(bool ignoreSculpt = false)
  3396. {
  3397. if (Shape.SculptEntry && !ignoreSculpt)
  3398. return PrimType.SCULPT;
  3399. ProfileShape ps = (ProfileShape)(Shape.ProfileCurve & 0x07);
  3400. if (ps == ProfileShape.Square)
  3401. {
  3402. if (Shape.PathCurve == (byte)Extrusion.Straight)
  3403. return PrimType.BOX;
  3404. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3405. return PrimType.TUBE;
  3406. }
  3407. else if (ps == ProfileShape.Circle)
  3408. {
  3409. if (Shape.PathCurve == (byte)Extrusion.Straight || Shape.PathCurve == (byte)Extrusion.Flexible)
  3410. return PrimType.CYLINDER;
  3411. // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
  3412. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3413. return PrimType.TORUS;
  3414. }
  3415. else if (ps == ProfileShape.HalfCircle)
  3416. {
  3417. if (Shape.PathCurve == (byte)Extrusion.Curve1 || Shape.PathCurve == (byte)Extrusion.Curve2)
  3418. return PrimType.SPHERE;
  3419. }
  3420. else if (ps == ProfileShape.EquilateralTriangle)
  3421. {
  3422. if (Shape.PathCurve == (byte)Extrusion.Straight || Shape.PathCurve == (byte)Extrusion.Flexible)
  3423. return PrimType.PRISM;
  3424. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3425. return PrimType.RING;
  3426. }
  3427. return PrimType.BOX;
  3428. }
  3429. public void SetGroup(UUID groupID, IClientAPI client)
  3430. {
  3431. // Scene.AddNewPrims() calls with client == null so can't use this.
  3432. // m_log.DebugFormat(
  3433. // "[SCENE OBJECT PART]: Setting group for {0} to {1} for {2}",
  3434. // Name, groupID, OwnerID);
  3435. ++PseudoCRC;
  3436. GroupID = groupID;
  3437. // if (client != null)
  3438. // SendPropertiesToClient(client);
  3439. lock(UpdateFlagLock)
  3440. UpdateFlag |= PrimUpdateFlags.FullUpdate;
  3441. }
  3442. /// <summary>
  3443. /// Set the parent group of this prim.
  3444. /// </summary>
  3445. public void SetParent(SceneObjectGroup parent)
  3446. {
  3447. ParentGroup = parent;
  3448. }
  3449. // Use this for attachments! LocalID should be avatar's localid
  3450. public void SetParentLocalId(uint localID)
  3451. {
  3452. ParentID = localID;
  3453. }
  3454. public void SetPhysicsAxisRotation()
  3455. {
  3456. PhysicsActor pa = PhysActor;
  3457. if (pa != null)
  3458. {
  3459. pa.LockAngularMotion(RotationAxisLocks);
  3460. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3461. }
  3462. }
  3463. /// <summary>
  3464. /// Set the events that this part will pass on to listeners.
  3465. /// </summary>
  3466. /// <param name="scriptid"></param>
  3467. /// <param name="events"></param>
  3468. public void SetScriptEvents(UUID scriptid, int events)
  3469. {
  3470. // m_log.DebugFormat(
  3471. // "[SCENE OBJECT PART]: Set script events for script with id {0} on {1}/{2} to {3} in {4}",
  3472. // scriptid, Name, ParentGroup.Name, events, ParentGroup.Scene.Name);
  3473. // scriptEvents oldparts;
  3474. lock (m_scriptEvents)
  3475. {
  3476. if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev))
  3477. {
  3478. if (ev == (scriptEvents)events)
  3479. return;
  3480. }
  3481. m_scriptEvents[scriptid] = (scriptEvents) events;
  3482. }
  3483. aggregateScriptEvents();
  3484. }
  3485. /// <summary>
  3486. /// Set the text displayed for this part.
  3487. /// </summary>
  3488. /// <param name="text"></param>
  3489. public void SetText(string text)
  3490. {
  3491. string oldtext = m_text;
  3492. m_text = text;
  3493. if (ParentGroup != null && oldtext != text)
  3494. {
  3495. ParentGroup.HasGroupChanged = true;
  3496. ScheduleFullUpdate();
  3497. }
  3498. }
  3499. /// <summary>
  3500. /// Set the text displayed for this part.
  3501. /// </summary>
  3502. /// <param name="text"></param>
  3503. /// <param name="color"></param>
  3504. /// <param name="alpha"></param>
  3505. public void SetText(string text, Vector3 color, double alpha)
  3506. {
  3507. Color oldcolor = Color;
  3508. string oldtext = m_text;
  3509. Color = Color.FromArgb((int) (alpha*0xff),
  3510. (int) (color.X*0xff),
  3511. (int) (color.Y*0xff),
  3512. (int) (color.Z*0xff));
  3513. m_text = text;
  3514. if(ParentGroup != null && (oldcolor != Color || oldtext != m_text))
  3515. {
  3516. ParentGroup.HasGroupChanged = true;
  3517. ScheduleFullUpdate();
  3518. }
  3519. }
  3520. public void StoreUndoState(ObjectChangeType change)
  3521. {
  3522. lock (m_UndoLock)
  3523. {
  3524. if (m_UndoRedo == null)
  3525. m_UndoRedo = new UndoRedoState(5);
  3526. if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
  3527. {
  3528. m_UndoRedo.StoreUndo(this, change);
  3529. }
  3530. }
  3531. }
  3532. /// <summary>
  3533. /// Return number of undos on the stack. Here temporarily pending a refactor.
  3534. /// </summary>
  3535. public int UndoCount
  3536. {
  3537. get
  3538. {
  3539. if (m_UndoRedo == null)
  3540. return 0;
  3541. return m_UndoRedo.Count;
  3542. }
  3543. }
  3544. public void Undo()
  3545. {
  3546. lock (m_UndoLock)
  3547. {
  3548. if (m_UndoRedo == null || Undoing || ParentGroup == null)
  3549. return;
  3550. Undoing = true;
  3551. m_UndoRedo.Undo(this);
  3552. Undoing = false;
  3553. }
  3554. }
  3555. public void Redo()
  3556. {
  3557. lock (m_UndoLock)
  3558. {
  3559. if (m_UndoRedo == null || Undoing || ParentGroup == null)
  3560. return;
  3561. Undoing = true;
  3562. m_UndoRedo.Redo(this);
  3563. Undoing = false;
  3564. }
  3565. }
  3566. public void ClearUndoState()
  3567. {
  3568. lock (m_UndoLock)
  3569. {
  3570. if (m_UndoRedo == null || Undoing)
  3571. return;
  3572. m_UndoRedo.Clear();
  3573. }
  3574. }
  3575. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  3576. {
  3577. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  3578. // This breaks down into the ray---> plane equation.
  3579. // TODO: Change to take shape into account
  3580. Vector3[] vertexes = new Vector3[8];
  3581. // float[] distance = new float[6];
  3582. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  3583. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  3584. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  3585. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  3586. Vector3[] normals = new Vector3[6]; // Normal for Facei
  3587. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  3588. AAfacenormals[0] = new Vector3(1, 0, 0);
  3589. AAfacenormals[1] = new Vector3(0, 1, 0);
  3590. AAfacenormals[2] = new Vector3(-1, 0, 0);
  3591. AAfacenormals[3] = new Vector3(0, -1, 0);
  3592. AAfacenormals[4] = new Vector3(0, 0, 1);
  3593. AAfacenormals[5] = new Vector3(0, 0, -1);
  3594. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  3595. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  3596. Vector3 cross = new Vector3();
  3597. Vector3 pos = GetWorldPosition();
  3598. Quaternion rot = GetWorldRotation();
  3599. Quaternion AXrot = rot;
  3600. AXrot.Normalize();
  3601. Vector3 AXpos = pos;
  3602. // tScale is the offset to derive the vertex based on the scale.
  3603. // it's different for each vertex because we've got to rotate it
  3604. // to get the world position of the vertex to produce the Oriented Bounding Box
  3605. Vector3 tScale = Vector3.Zero;
  3606. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  3607. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  3608. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  3609. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  3610. Vector3 rScale = new Vector3();
  3611. // Get Vertexes for Faces Stick them into ABCD for each Face
  3612. // Form: Face<vertex>[face] that corresponds to the below diagram
  3613. #region ABCD Face Vertex Map Comment Diagram
  3614. // A _________ B
  3615. // | |
  3616. // | 4 top |
  3617. // |_________|
  3618. // C D
  3619. // A _________ B
  3620. // | Back |
  3621. // | 3 |
  3622. // |_________|
  3623. // C D
  3624. // A _________ B B _________ A
  3625. // | Left | | Right |
  3626. // | 0 | | 2 |
  3627. // |_________| |_________|
  3628. // C D D C
  3629. // A _________ B
  3630. // | Front |
  3631. // | 1 |
  3632. // |_________|
  3633. // C D
  3634. // C _________ D
  3635. // | |
  3636. // | 5 bot |
  3637. // |_________|
  3638. // A B
  3639. #endregion
  3640. #region Plane Decomposition of Oriented Bounding Box
  3641. tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
  3642. rScale = tScale * AXrot;
  3643. vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3644. // vertexes[0].X = pos.X + vertexes[0].X;
  3645. //vertexes[0].Y = pos.Y + vertexes[0].Y;
  3646. //vertexes[0].Z = pos.Z + vertexes[0].Z;
  3647. FaceA[0] = vertexes[0];
  3648. FaceB[3] = vertexes[0];
  3649. FaceA[4] = vertexes[0];
  3650. tScale = AXscale;
  3651. rScale = tScale * AXrot;
  3652. vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3653. // vertexes[1].X = pos.X + vertexes[1].X;
  3654. // vertexes[1].Y = pos.Y + vertexes[1].Y;
  3655. //vertexes[1].Z = pos.Z + vertexes[1].Z;
  3656. FaceB[0] = vertexes[1];
  3657. FaceA[1] = vertexes[1];
  3658. FaceC[4] = vertexes[1];
  3659. tScale = new Vector3(AXscale.X, -AXscale.Y, -AXscale.Z);
  3660. rScale = tScale * AXrot;
  3661. vertexes[2] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3662. //vertexes[2].X = pos.X + vertexes[2].X;
  3663. //vertexes[2].Y = pos.Y + vertexes[2].Y;
  3664. //vertexes[2].Z = pos.Z + vertexes[2].Z;
  3665. FaceC[0] = vertexes[2];
  3666. FaceD[3] = vertexes[2];
  3667. FaceC[5] = vertexes[2];
  3668. tScale = new Vector3(AXscale.X, AXscale.Y, -AXscale.Z);
  3669. rScale = tScale * AXrot;
  3670. vertexes[3] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3671. //vertexes[3].X = pos.X + vertexes[3].X;
  3672. // vertexes[3].Y = pos.Y + vertexes[3].Y;
  3673. // vertexes[3].Z = pos.Z + vertexes[3].Z;
  3674. FaceD[0] = vertexes[3];
  3675. FaceC[1] = vertexes[3];
  3676. FaceA[5] = vertexes[3];
  3677. tScale = new Vector3(-AXscale.X, AXscale.Y, AXscale.Z);
  3678. rScale = tScale * AXrot;
  3679. vertexes[4] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3680. // vertexes[4].X = pos.X + vertexes[4].X;
  3681. // vertexes[4].Y = pos.Y + vertexes[4].Y;
  3682. // vertexes[4].Z = pos.Z + vertexes[4].Z;
  3683. FaceB[1] = vertexes[4];
  3684. FaceA[2] = vertexes[4];
  3685. FaceD[4] = vertexes[4];
  3686. tScale = new Vector3(-AXscale.X, AXscale.Y, -AXscale.Z);
  3687. rScale = tScale * AXrot;
  3688. vertexes[5] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3689. // vertexes[5].X = pos.X + vertexes[5].X;
  3690. // vertexes[5].Y = pos.Y + vertexes[5].Y;
  3691. // vertexes[5].Z = pos.Z + vertexes[5].Z;
  3692. FaceD[1] = vertexes[5];
  3693. FaceC[2] = vertexes[5];
  3694. FaceB[5] = vertexes[5];
  3695. tScale = new Vector3(-AXscale.X, -AXscale.Y, AXscale.Z);
  3696. rScale = tScale * AXrot;
  3697. vertexes[6] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3698. // vertexes[6].X = pos.X + vertexes[6].X;
  3699. // vertexes[6].Y = pos.Y + vertexes[6].Y;
  3700. // vertexes[6].Z = pos.Z + vertexes[6].Z;
  3701. FaceB[2] = vertexes[6];
  3702. FaceA[3] = vertexes[6];
  3703. FaceB[4] = vertexes[6];
  3704. tScale = new Vector3(-AXscale.X, -AXscale.Y, -AXscale.Z);
  3705. rScale = tScale * AXrot;
  3706. vertexes[7] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3707. // vertexes[7].X = pos.X + vertexes[7].X;
  3708. // vertexes[7].Y = pos.Y + vertexes[7].Y;
  3709. // vertexes[7].Z = pos.Z + vertexes[7].Z;
  3710. FaceD[2] = vertexes[7];
  3711. FaceC[3] = vertexes[7];
  3712. FaceD[5] = vertexes[7];
  3713. #endregion
  3714. // Get our plane normals
  3715. for (int i = 0; i < 6; i++)
  3716. {
  3717. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  3718. // Our Plane direction
  3719. AmBa = FaceA[i] - FaceB[i];
  3720. AmBb = FaceB[i] - FaceC[i];
  3721. cross = Vector3.Cross(AmBb, AmBa);
  3722. // normalize the cross product to get the normal.
  3723. normals[i] = cross / cross.Length();
  3724. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  3725. //distance[i] = (normals[i].X * AmBa.X + normals[i].Y * AmBa.Y + normals[i].Z * AmBa.Z) * -1;
  3726. }
  3727. EntityIntersection result = new EntityIntersection();
  3728. result.distance = 1024;
  3729. float c = 0;
  3730. float a = 0;
  3731. float d = 0;
  3732. Vector3 q = new Vector3();
  3733. #region OBB Version 2 Experiment
  3734. //float fmin = 999999;
  3735. //float fmax = -999999;
  3736. //float s = 0;
  3737. //for (int i=0;i<6;i++)
  3738. //{
  3739. //s = iray.Direction.Dot(normals[i]);
  3740. //d = normals[i].Dot(FaceB[i]);
  3741. //if (s == 0)
  3742. //{
  3743. //if (iray.Origin.Dot(normals[i]) > d)
  3744. //{
  3745. //return result;
  3746. //}
  3747. // else
  3748. //{
  3749. //continue;
  3750. //}
  3751. //}
  3752. //a = (d - iray.Origin.Dot(normals[i])) / s;
  3753. //if (iray.Direction.Dot(normals[i]) < 0)
  3754. //{
  3755. //if (a > fmax)
  3756. //{
  3757. //if (a > fmin)
  3758. //{
  3759. //return result;
  3760. //}
  3761. //fmax = a;
  3762. //}
  3763. //}
  3764. //else
  3765. //{
  3766. //if (a < fmin)
  3767. //{
  3768. //if (a < 0 || a < fmax)
  3769. //{
  3770. //return result;
  3771. //}
  3772. //fmin = a;
  3773. //}
  3774. //}
  3775. //}
  3776. //if (fmax > 0)
  3777. // a= fmax;
  3778. //else
  3779. // a=fmin;
  3780. //q = iray.Origin + a * iray.Direction;
  3781. #endregion
  3782. // Loop over faces (6 of them)
  3783. for (int i = 0; i < 6; i++)
  3784. {
  3785. AmBa = FaceA[i] - FaceB[i];
  3786. AmBb = FaceB[i] - FaceC[i];
  3787. d = Vector3.Dot(normals[i], FaceB[i]);
  3788. //if (faceCenters)
  3789. //{
  3790. // c = normals[i].Dot(normals[i]);
  3791. //}
  3792. //else
  3793. //{
  3794. c = Vector3.Dot(iray.Direction, normals[i]);
  3795. //}
  3796. if (c == 0)
  3797. continue;
  3798. a = (d - Vector3.Dot(iray.Origin, normals[i])) / c;
  3799. if (a < 0)
  3800. continue;
  3801. // If the normal is pointing outside the object
  3802. if (Vector3.Dot(iray.Direction, normals[i]) < 0 || !frontFacesOnly)
  3803. {
  3804. //if (faceCenters)
  3805. //{ //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  3806. // q = iray.Origin + a * normals[i];
  3807. //}
  3808. //else
  3809. //{
  3810. q = iray.Origin + iray.Direction * a;
  3811. //}
  3812. float distance2 = Vector3.Distance(q, AXpos);
  3813. // Is this the closest hit to the object's origin?
  3814. //if (faceCenters)
  3815. //{
  3816. // distance2 = (float)GetDistanceTo(q, iray.Origin);
  3817. //}
  3818. if (distance2 < result.distance)
  3819. {
  3820. result.distance = distance2;
  3821. result.HitTF = true;
  3822. result.ipoint = q;
  3823. result.face = i;
  3824. //m_log.Info("[FACE]:" + i.ToString());
  3825. //m_log.Info("[POINT]: " + q.ToString());
  3826. //m_log.Info("[DIST]: " + distance2.ToString());
  3827. if (faceCenters)
  3828. {
  3829. result.normal = AAfacenormals[i] * AXrot;
  3830. Vector3 scaleComponent = AAfacenormals[i];
  3831. float ScaleOffset = 0.5f;
  3832. if (scaleComponent.X != 0) ScaleOffset = AXscale.X;
  3833. if (scaleComponent.Y != 0) ScaleOffset = AXscale.Y;
  3834. if (scaleComponent.Z != 0) ScaleOffset = AXscale.Z;
  3835. ScaleOffset = Math.Abs(ScaleOffset);
  3836. Vector3 offset = result.normal * ScaleOffset;
  3837. result.ipoint = AXpos + offset;
  3838. ///pos = (intersectionpoint + offset);
  3839. }
  3840. else
  3841. {
  3842. result.normal = normals[i];
  3843. }
  3844. result.AAfaceNormal = AAfacenormals[i];
  3845. }
  3846. }
  3847. }
  3848. return result;
  3849. }
  3850. /// <summary>
  3851. /// Serialize this part to xml.
  3852. /// </summary>
  3853. /// <param name="xmlWriter"></param>
  3854. public void ToXml(XmlTextWriter xmlWriter)
  3855. {
  3856. SceneObjectSerializer.SOPToXml2(xmlWriter, this, new Dictionary<string, object>());
  3857. }
  3858. public void TriggerScriptChangedEvent(Changed val, object data = null)
  3859. {
  3860. if (ParentGroup != null && ParentGroup.Scene != null)
  3861. ParentGroup.Scene.EventManager.TriggerOnScriptChangedEvent(LocalId, (uint)val, data);
  3862. }
  3863. public void TrimPermissions()
  3864. {
  3865. BaseMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3866. OwnerMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3867. GroupMask &= (uint)PermissionMask.All;
  3868. EveryoneMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3869. NextOwnerMask &= (uint)PermissionMask.All;
  3870. }
  3871. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  3872. {
  3873. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  3874. if (ParentGroup != null)
  3875. {
  3876. ParentGroup.HasGroupChanged = true;
  3877. ScheduleFullAnimUpdate();
  3878. }
  3879. }
  3880. public void UpdateGroupPosition(Vector3 newPos)
  3881. {
  3882. Vector3 oldPos = GroupPosition;
  3883. if ((newPos.X != oldPos.X) ||
  3884. (newPos.Y != oldPos.Y) ||
  3885. (newPos.Z != oldPos.Z))
  3886. {
  3887. GroupPosition = newPos;
  3888. ScheduleTerseUpdate();
  3889. }
  3890. }
  3891. /// <summary>
  3892. /// Update this part's offset position.
  3893. /// </summary>
  3894. /// <param name="pos"></param>
  3895. public void UpdateOffSet(Vector3 newPos)
  3896. {
  3897. Vector3 oldPos = OffsetPosition;
  3898. if ((newPos.X != oldPos.X) ||
  3899. (newPos.Y != oldPos.Y) ||
  3900. (newPos.Z != oldPos.Z))
  3901. {
  3902. if (ParentGroup.RootPart.GetStatusSandbox())
  3903. {
  3904. if (Vector3.DistanceSquared(ParentGroup.RootPart.StatusSandboxPos, newPos) > 100)
  3905. {
  3906. ParentGroup.RootPart.ScriptSetPhysicsStatus(false);
  3907. newPos = OffsetPosition;
  3908. ParentGroup.Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3909. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, ParentGroup.RootPart.AbsolutePosition, Name, UUID, false);
  3910. }
  3911. }
  3912. OffsetPosition = newPos;
  3913. ScheduleTerseUpdate();
  3914. }
  3915. }
  3916. /// <summary>
  3917. /// Update permissions on the SOP. Should only be called from SOG.UpdatePermissions because the SOG
  3918. /// will handle the client notifications once all of its parts are updated.
  3919. /// </summary>
  3920. /// <param name="AgentID"></param>
  3921. /// <param name="field"></param>
  3922. /// <param name="localID"></param>
  3923. /// <param name="mask"></param>
  3924. /// <param name="addRemTF"></param>
  3925. public void UpdatePermissions(UUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  3926. {
  3927. bool set = addRemTF == 1;
  3928. bool god = ParentGroup.Scene.Permissions.IsGod(AgentID);
  3929. uint baseMask = BaseMask;
  3930. if (god)
  3931. baseMask = 0x7ffffff0;
  3932. bool canChange = (AgentID == OwnerID) || god;
  3933. if(!canChange)
  3934. canChange = ParentGroup.Scene.Permissions.CanEditObjectPermissions(ParentGroup, AgentID);
  3935. if (canChange)
  3936. {
  3937. switch (field)
  3938. {
  3939. case 1:
  3940. if (god)
  3941. {
  3942. BaseMask = ApplyMask(BaseMask, set, mask);
  3943. Inventory.ApplyGodPermissions(BaseMask);
  3944. }
  3945. break;
  3946. case 2:
  3947. OwnerMask = ApplyMask(OwnerMask, set, mask) &
  3948. baseMask;
  3949. break;
  3950. case 4:
  3951. GroupMask = ApplyMask(GroupMask, set, mask) &
  3952. baseMask;
  3953. break;
  3954. case 8:
  3955. // Trying to set export permissions - extra checks
  3956. if (set && (mask & (uint)PermissionMask.Export) != 0)
  3957. {
  3958. if ((OwnerMask & (uint)PermissionMask.Export) == 0 || (BaseMask & (uint)PermissionMask.Export) == 0 || (NextOwnerMask & (uint)PermissionMask.All) != (uint)PermissionMask.All)
  3959. mask &= ~(uint)PermissionMask.Export;
  3960. }
  3961. EveryoneMask = ApplyMask(EveryoneMask, set, mask) &
  3962. baseMask;
  3963. break;
  3964. case 16:
  3965. // Force full perm if export
  3966. if ((EveryoneMask & (uint)PermissionMask.Export) != 0)
  3967. {
  3968. NextOwnerMask = (uint)PermissionMask.All;
  3969. break;
  3970. }
  3971. NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) &
  3972. baseMask;
  3973. // Prevent the client from creating no copy, no transfer
  3974. // objects
  3975. if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0)
  3976. NextOwnerMask |= (uint)PermissionMask.Transfer;
  3977. NextOwnerMask |= (uint)PermissionMask.Move;
  3978. break;
  3979. }
  3980. AggregateInnerPerms();
  3981. SendFullUpdateToAllClients();
  3982. }
  3983. }
  3984. public void ClonePermissions(SceneObjectPart source)
  3985. {
  3986. uint prevOwnerMask = OwnerMask;
  3987. uint prevGroupMask = GroupMask;
  3988. uint prevEveryoneMask = EveryoneMask;
  3989. uint prevNextOwnerMask = NextOwnerMask;
  3990. OwnerMask = source.OwnerMask & BaseMask;
  3991. GroupMask = source.GroupMask & BaseMask;
  3992. EveryoneMask = source.EveryoneMask & BaseMask;
  3993. NextOwnerMask = source.NextOwnerMask & BaseMask;
  3994. AggregateInnerPerms();
  3995. if (OwnerMask != prevOwnerMask || GroupMask != prevGroupMask ||
  3996. EveryoneMask != prevEveryoneMask || NextOwnerMask != prevNextOwnerMask)
  3997. SendFullUpdateToAllClients();
  3998. }
  3999. public bool IsHingeJoint()
  4000. {
  4001. // For now, we use the NINJA naming scheme for identifying joints.
  4002. // In the future, we can support other joint specification schemes such as a
  4003. // custom checkbox in the viewer GUI.
  4004. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  4005. {
  4006. string hingeString = "hingejoint";
  4007. return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
  4008. }
  4009. else
  4010. {
  4011. return false;
  4012. }
  4013. }
  4014. public bool IsBallJoint()
  4015. {
  4016. // For now, we use the NINJA naming scheme for identifying joints.
  4017. // In the future, we can support other joint specification schemes such as a
  4018. // custom checkbox in the viewer GUI.
  4019. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  4020. {
  4021. string ballString = "balljoint";
  4022. return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
  4023. }
  4024. else
  4025. {
  4026. return false;
  4027. }
  4028. }
  4029. public bool IsJoint()
  4030. {
  4031. // For now, we use the NINJA naming scheme for identifying joints.
  4032. // In the future, we can support other joint specification schemes such as a
  4033. // custom checkbox in the viewer GUI.
  4034. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  4035. {
  4036. return IsHingeJoint() || IsBallJoint();
  4037. }
  4038. else
  4039. {
  4040. return false;
  4041. }
  4042. }
  4043. public void UpdateExtraPhysics(ExtraPhysicsData physdata)
  4044. {
  4045. if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
  4046. return;
  4047. byte newtype = (byte)physdata.PhysShapeType;
  4048. if (PhysicsShapeType != newtype)
  4049. PhysicsShapeType = newtype;
  4050. if(Density != physdata.Density)
  4051. Density = physdata.Density;
  4052. if(GravityModifier != physdata.GravitationModifier)
  4053. GravityModifier = physdata.GravitationModifier;
  4054. if(Friction != physdata.Friction)
  4055. Friction = physdata.Friction;
  4056. if(Restitution != physdata.Bounce)
  4057. Restitution = physdata.Bounce;
  4058. }
  4059. /// <summary>
  4060. /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
  4061. /// </summary>
  4062. /// <param name="UsePhysics"></param>
  4063. /// <param name="SetTemporary"></param>
  4064. /// <param name="SetPhantom"></param>
  4065. /// <param name="SetVD"></param>
  4066. public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
  4067. {
  4068. bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
  4069. bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
  4070. bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0);
  4071. bool wasVD = VolumeDetectActive;
  4072. if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
  4073. {
  4074. UpdatePhysicsSubscribedEvents();
  4075. return;
  4076. }
  4077. VolumeDetectActive = SetVD;
  4078. // volume detector implies phantom we need to decouple this mess
  4079. if (SetVD)
  4080. SetPhantom = true;
  4081. else if(wasVD)
  4082. SetPhantom = false;
  4083. if (UsePhysics)
  4084. AddFlag(PrimFlags.Physics);
  4085. else
  4086. RemFlag(PrimFlags.Physics);
  4087. if (SetPhantom)
  4088. AddFlag(PrimFlags.Phantom);
  4089. else
  4090. RemFlag(PrimFlags.Phantom);
  4091. if (SetTemporary)
  4092. AddFlag(PrimFlags.TemporaryOnRez);
  4093. else
  4094. RemFlag(PrimFlags.TemporaryOnRez);
  4095. if (ParentGroup.Scene == null)
  4096. return;
  4097. PhysicsActor pa = PhysActor;
  4098. if (pa != null && building && pa.Building != building)
  4099. pa.Building = building;
  4100. if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
  4101. || (Shape.PathCurve == (byte)Extrusion.Flexible))
  4102. {
  4103. Stop();
  4104. if (pa != null)
  4105. {
  4106. if(wasUsingPhysics)
  4107. ParentGroup.Scene.RemovePhysicalPrim(1);
  4108. RemoveFromPhysics();
  4109. }
  4110. }
  4111. else
  4112. {
  4113. if (ParentGroup.Scene.CollidablePrims)
  4114. {
  4115. if (pa == null)
  4116. {
  4117. AddToPhysics(UsePhysics, SetPhantom, building, false);
  4118. pa = PhysActor;
  4119. if (pa != null)
  4120. {
  4121. pa.SetMaterial(Material);
  4122. DoPhysicsPropertyUpdate(UsePhysics, true);
  4123. }
  4124. }
  4125. else // it already has a physical representation
  4126. {
  4127. DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
  4128. if(UsePhysics && !SetPhantom && m_localId == ParentGroup.RootPart.LocalId &&
  4129. m_vehicleParams != null && m_vehicleParams.CameraDecoupled)
  4130. AddFlag(PrimFlags.CameraDecoupled);
  4131. else
  4132. RemFlag(PrimFlags.CameraDecoupled);
  4133. if (pa.Building != building)
  4134. pa.Building = building;
  4135. }
  4136. UpdatePhysicsSubscribedEvents();
  4137. }
  4138. }
  4139. // and last in case we have a new actor and not building
  4140. if (ParentGroup != null)
  4141. {
  4142. ParentGroup.HasGroupChanged = true;
  4143. ScheduleFullUpdate();
  4144. }
  4145. // m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
  4146. }
  4147. /// <summary>
  4148. /// Adds this part to the physics scene.
  4149. /// and sets the PhysActor property
  4150. /// </summary>
  4151. /// <param name="isPhysical">Add this prim as physical.</param>
  4152. /// <param name="isPhantom">Add this prim as phantom.</param>
  4153. /// <param name="building">tells physics to delay full construction of object</param>
  4154. /// <param name="applyDynamics">applies velocities, force and torque</param>
  4155. private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
  4156. {
  4157. if (ParentGroup.Scene != null)
  4158. ClampScale(isPhysical);
  4159. PhysicsActor pa;
  4160. Vector3 velocity = Velocity;
  4161. Vector3 rotationalVelocity = AngularVelocity; ;
  4162. try
  4163. {
  4164. pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
  4165. string.Format("{0}/{1}", Name, UUID),
  4166. Shape,
  4167. AbsolutePosition,
  4168. Scale,
  4169. GetWorldRotation(),
  4170. isPhysical,
  4171. isPhantom,
  4172. PhysicsShapeType,
  4173. m_localId);
  4174. }
  4175. catch (Exception e)
  4176. {
  4177. m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom. e={1}", m_uuid, e);
  4178. pa = null;
  4179. }
  4180. if (pa != null)
  4181. {
  4182. pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
  4183. pa.SetMaterial(Material);
  4184. pa.Density = Density;
  4185. pa.GravModifier = GravityModifier;
  4186. pa.Friction = Friction;
  4187. pa.Restitution = Restitution;
  4188. pa.Buoyancy = Buoyancy;
  4189. if(LocalId == ParentGroup.RootPart.LocalId)
  4190. {
  4191. pa.LockAngularMotion(RotationAxisLocks);
  4192. }
  4193. if (VolumeDetectActive) // change if not the default only
  4194. pa.SetVolumeDetect(1);
  4195. bool isroot = (m_localId == ParentGroup.RootPart.LocalId);
  4196. if(isroot && m_physicsInertia != null)
  4197. pa.SetInertiaData(m_physicsInertia);
  4198. if (isroot && m_vehicleParams != null )
  4199. {
  4200. m_vehicleParams.SetVehicle(pa);
  4201. if(isPhysical && !isPhantom && m_vehicleParams.CameraDecoupled)
  4202. AddFlag(PrimFlags.CameraDecoupled);
  4203. else
  4204. RemFlag(PrimFlags.CameraDecoupled);
  4205. }
  4206. else
  4207. RemFlag(PrimFlags.CameraDecoupled);
  4208. // we are going to tell rest of code about physics so better have this here
  4209. PhysActor = pa;
  4210. // DoPhysicsPropertyUpdate(isPhysical, true);
  4211. // lets expand it here just with what it really needs to do
  4212. if (isPhysical)
  4213. {
  4214. if (ParentGroup.RootPart.KeyframeMotion != null)
  4215. ParentGroup.RootPart.KeyframeMotion.Stop();
  4216. ParentGroup.RootPart.KeyframeMotion = null;
  4217. ParentGroup.Scene.AddPhysicalPrim(1);
  4218. pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  4219. pa.OnOutOfBounds += PhysicsOutOfBounds;
  4220. if (_parentID != 0 && _parentID != LocalId)
  4221. {
  4222. PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
  4223. if (parentPa != null)
  4224. {
  4225. pa.link(parentPa);
  4226. }
  4227. }
  4228. }
  4229. if (applyDynamics && LocalId == ParentGroup.RootPart.LocalId)
  4230. // do independent of isphysical so parameters get setted (at least some)
  4231. {
  4232. Velocity = velocity;
  4233. AngularVelocity = rotationalVelocity;
  4234. // if not vehicle and root part apply force and torque
  4235. if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE))
  4236. {
  4237. pa.Force = Force;
  4238. pa.Torque = Torque;
  4239. }
  4240. }
  4241. // if (Shape.SculptEntry)
  4242. // CheckSculptAndLoad();
  4243. // else
  4244. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4245. if (!building)
  4246. pa.Building = false;
  4247. }
  4248. PhysActor = pa;
  4249. ParentGroup.Scene.EventManager.TriggerObjectAddedToPhysicalScene(this);
  4250. }
  4251. /// <summary>
  4252. /// This removes the part from the physics scene.
  4253. /// </summary>
  4254. /// <remarks>
  4255. /// This isn't the same as turning off physical, since even without being physical the prim has a physics
  4256. /// representation for collision detection.
  4257. /// </remarks>
  4258. public void RemoveFromPhysics()
  4259. {
  4260. PhysicsActor pa = PhysActor;
  4261. if (pa != null)
  4262. {
  4263. pa.OnCollisionUpdate -= PhysicsCollision;
  4264. pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  4265. pa.OnOutOfBounds -= PhysicsOutOfBounds;
  4266. ParentGroup.Scene.PhysicsScene.RemovePrim(pa);
  4267. ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this);
  4268. }
  4269. RemFlag(PrimFlags.CameraDecoupled);
  4270. PhysActor = null;
  4271. }
  4272. /// <summary>
  4273. /// This updates the part's rotation and sends out an update to clients if necessary.
  4274. /// </summary>
  4275. /// <param name="rot"></param>
  4276. public void UpdateRotation(Quaternion rot)
  4277. {
  4278. if (rot != RotationOffset)
  4279. {
  4280. RotationOffset = rot;
  4281. if (ParentGroup != null)
  4282. {
  4283. ParentGroup.HasGroupChanged = true;
  4284. ScheduleTerseUpdate();
  4285. }
  4286. }
  4287. }
  4288. /// <summary>
  4289. /// Update the shape of this part.
  4290. /// </summary>
  4291. /// <param name="shapeBlock"></param>
  4292. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  4293. {
  4294. m_shape.PathBegin = shapeBlock.PathBegin;
  4295. m_shape.PathEnd = shapeBlock.PathEnd;
  4296. m_shape.PathScaleX = shapeBlock.PathScaleX;
  4297. m_shape.PathScaleY = shapeBlock.PathScaleY;
  4298. m_shape.PathShearX = shapeBlock.PathShearX;
  4299. m_shape.PathShearY = shapeBlock.PathShearY;
  4300. m_shape.PathSkew = shapeBlock.PathSkew;
  4301. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  4302. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  4303. m_shape.PathCurve = shapeBlock.PathCurve;
  4304. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  4305. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  4306. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  4307. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  4308. m_shape.PathTaperX = shapeBlock.PathTaperX;
  4309. m_shape.PathTaperY = shapeBlock.PathTaperY;
  4310. m_shape.PathTwist = shapeBlock.PathTwist;
  4311. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  4312. PhysicsActor pa = PhysActor;
  4313. if (pa != null)
  4314. {
  4315. pa.Shape = m_shape;
  4316. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4317. }
  4318. // This is what makes vehicle trailers work
  4319. // A script in a child prim re-issues
  4320. // llSetPrimitiveParams(PRIM_TYPE) every few seconds. That
  4321. // prevents autoreturn. This is not well known. It also works
  4322. // in SL.
  4323. //
  4324. if (ParentGroup.RootPart != this)
  4325. ParentGroup.RootPart.Rezzed = DateTime.UtcNow;
  4326. ParentGroup.HasGroupChanged = true;
  4327. TriggerScriptChangedEvent(Changed.SHAPE);
  4328. ScheduleFullUpdate();
  4329. }
  4330. public void UpdateSlice(float begin, float end)
  4331. {
  4332. if (end < begin)
  4333. {
  4334. float temp = begin;
  4335. begin = end;
  4336. end = temp;
  4337. }
  4338. end = Math.Min(1f, Math.Max(0f, end));
  4339. begin = Math.Min(Math.Min(1f, Math.Max(0f, begin)), end - 0.02f);
  4340. if (begin < 0.02f && end < 0.02f)
  4341. {
  4342. begin = 0f;
  4343. end = 0.02f;
  4344. }
  4345. ushort uBegin = (ushort)(50000.0 * begin);
  4346. ushort uEnd = (ushort)(50000.0 * (1f - end));
  4347. bool updatePossiblyNeeded = false;
  4348. PrimType primType = GetPrimType();
  4349. if (primType == PrimType.SPHERE || primType == PrimType.TORUS || primType == PrimType.TUBE || primType == PrimType.RING)
  4350. {
  4351. if (m_shape.ProfileBegin != uBegin || m_shape.ProfileEnd != uEnd)
  4352. {
  4353. m_shape.ProfileBegin = uBegin;
  4354. m_shape.ProfileEnd = uEnd;
  4355. updatePossiblyNeeded = true;
  4356. }
  4357. }
  4358. else if (m_shape.PathBegin != uBegin || m_shape.PathEnd != uEnd)
  4359. {
  4360. m_shape.PathBegin = uBegin;
  4361. m_shape.PathEnd = uEnd;
  4362. updatePossiblyNeeded = true;
  4363. }
  4364. if (updatePossiblyNeeded && ParentGroup != null)
  4365. {
  4366. ParentGroup.HasGroupChanged = true;
  4367. }
  4368. if (updatePossiblyNeeded && PhysActor != null)
  4369. {
  4370. PhysActor.Shape = m_shape;
  4371. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  4372. }
  4373. if (updatePossiblyNeeded)
  4374. {
  4375. ScheduleFullUpdate();
  4376. }
  4377. }
  4378. /// <summary>
  4379. /// Update the texture entry for this part.
  4380. /// </summary>
  4381. /// <param name="serializedTextureEntry"></param>
  4382. public void UpdateTextureEntry(byte[] serializedTextureEntry)
  4383. {
  4384. Primitive.TextureEntry newTex = new Primitive.TextureEntry(serializedTextureEntry, 0, serializedTextureEntry.Length);
  4385. Primitive.TextureEntry oldTex = Shape.Textures;
  4386. Changed changeFlags = 0;
  4387. Primitive.TextureEntryFace defaultNewFace = newTex.DefaultTexture;
  4388. Primitive.TextureEntryFace defaultOldFace = oldTex.DefaultTexture;
  4389. // On Incoming packets, sometimes newText.DefaultTexture is null. The assumption is that all
  4390. // other prim-sides are set, but apparently that's not always the case. Lets assume packet/data corruption at this point.
  4391. if (defaultNewFace == null)
  4392. {
  4393. defaultNewFace = new Primitive.TextureEntry(Util.BLANK_TEXTURE_UUID).CreateFace(0);
  4394. newTex.DefaultTexture = defaultNewFace;
  4395. }
  4396. if (defaultOldFace == null)
  4397. {
  4398. defaultOldFace = new Primitive.TextureEntry(Util.BLANK_TEXTURE_UUID).CreateFace(0);
  4399. oldTex.DefaultTexture = defaultOldFace;
  4400. }
  4401. // Materials capable viewers can send a ObjectImage packet
  4402. // when nothing in TE has changed. MaterialID should be updated
  4403. // by the RenderMaterials CAP handler, so updating it here may cause a
  4404. // race condtion. Therefore, if no non-materials TE fields have not changed,
  4405. // we should ignore any changes and not update Shape.TextureEntry
  4406. bool otherFieldsChanged = false;
  4407. int nsides = GetNumberOfSides();
  4408. for (int i = 0; i < nsides; i++)
  4409. {
  4410. Primitive.TextureEntryFace newFace = defaultNewFace;
  4411. Primitive.TextureEntryFace oldFace = defaultOldFace;
  4412. if (oldTex.FaceTextures[i] != null)
  4413. oldFace = oldTex.FaceTextures[i];
  4414. if (newTex.FaceTextures[i] != null)
  4415. newFace = newTex.FaceTextures[i];
  4416. if (oldFace.TextureID != newFace.TextureID)
  4417. changeFlags |= Changed.TEXTURE;
  4418. Color4 oldRGBA = oldFace.RGBA;
  4419. Color4 newRGBA = newFace.RGBA;
  4420. if (oldRGBA.R != newRGBA.R ||
  4421. oldRGBA.G != newRGBA.G ||
  4422. oldRGBA.B != newRGBA.B ||
  4423. oldRGBA.A != newRGBA.A)
  4424. changeFlags |= Changed.COLOR;
  4425. // Max change, skip the rest of testing
  4426. if (changeFlags == (Changed.TEXTURE | Changed.COLOR))
  4427. break;
  4428. if (!otherFieldsChanged)
  4429. {
  4430. if (oldFace.Bump != newFace.Bump) otherFieldsChanged = true;
  4431. if (oldFace.Fullbright != newFace.Fullbright) otherFieldsChanged = true;
  4432. if (oldFace.Glow != newFace.Glow) otherFieldsChanged = true;
  4433. if (oldFace.MediaFlags != newFace.MediaFlags) otherFieldsChanged = true;
  4434. if (oldFace.OffsetU != newFace.OffsetU) otherFieldsChanged = true;
  4435. if (oldFace.OffsetV != newFace.OffsetV) otherFieldsChanged = true;
  4436. if (oldFace.RepeatU != newFace.RepeatU) otherFieldsChanged = true;
  4437. if (oldFace.RepeatV != newFace.RepeatV) otherFieldsChanged = true;
  4438. if (oldFace.Rotation != newFace.Rotation) otherFieldsChanged = true;
  4439. if (oldFace.Shiny != newFace.Shiny) otherFieldsChanged = true;
  4440. if (oldFace.TexMapType != newFace.TexMapType) otherFieldsChanged = true;
  4441. if (otherFieldsChanged)
  4442. changeFlags |= Changed.TEXTURE;
  4443. }
  4444. }
  4445. if (changeFlags == 0)
  4446. return;
  4447. // we do need better compacter do just the trivial case
  4448. if(nsides == 1 && newTex.FaceTextures[0] != null)
  4449. {
  4450. newTex.DefaultTexture = newTex.GetFace(0);
  4451. newTex.FaceTextures[0] = null;
  4452. }
  4453. m_shape.TextureEntry = newTex.GetBytes(nsides);
  4454. TriggerScriptChangedEvent(changeFlags);
  4455. ParentGroup.HasGroupChanged = true;
  4456. ScheduleUpdate(PrimUpdateFlags.Textures);
  4457. }
  4458. /// <summary>
  4459. /// Update the texture entry for this part.
  4460. /// </summary>
  4461. /// <param name="newTex"></param>
  4462. public void UpdateTextureEntry(Primitive.TextureEntry newTex)
  4463. {
  4464. TextureAttributes dirty = newTex.GetDirtyFlags(32, true);
  4465. dirty &= ~TextureAttributes.MaterialID;
  4466. if(dirty == TextureAttributes.None)
  4467. return;
  4468. Changed changeFlags = 0;
  4469. if((dirty & TextureAttributes.RGBA) != 0)
  4470. {
  4471. changeFlags = Changed.COLOR;
  4472. dirty &= ~TextureAttributes.RGBA;
  4473. }
  4474. if (dirty != TextureAttributes.None)
  4475. changeFlags |= Changed.TEXTURE;
  4476. if (changeFlags == 0)
  4477. return;
  4478. m_shape.TextureEntry = newTex.GetBytes(9);
  4479. TriggerScriptChangedEvent(changeFlags);
  4480. ParentGroup.HasGroupChanged = true;
  4481. ScheduleUpdate(PrimUpdateFlags.Textures);
  4482. }
  4483. internal void UpdatePhysicsSubscribedEvents()
  4484. {
  4485. PhysicsActor pa = PhysActor;
  4486. if (pa == null)
  4487. return;
  4488. pa.OnCollisionUpdate -= PhysicsCollision;
  4489. bool hassound = (!VolumeDetectActive && CollisionSoundType >= 0 && ((Flags & PrimFlags.Physics) != 0));
  4490. scriptEvents CombinedEvents = AggregatedScriptEvents;
  4491. // merge with root part
  4492. if (ParentGroup != null && ParentGroup.RootPart != null)
  4493. CombinedEvents |= ParentGroup.RootPart.AggregatedScriptEvents;
  4494. // submit to this part case
  4495. if (VolumeDetectActive)
  4496. CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
  4497. else if ((Flags & PrimFlags.Phantom) != 0)
  4498. CombinedEvents &= PhyscicsPhantonSubsEvents;
  4499. else
  4500. CombinedEvents &= PhysicsNeededSubsEvents;
  4501. if (hassound || CombinedEvents != 0)
  4502. {
  4503. // subscribe to physics updates.
  4504. pa.OnCollisionUpdate += PhysicsCollision;
  4505. pa.SubscribeEvents(50); // 20 reports per second
  4506. }
  4507. else
  4508. {
  4509. pa.UnSubscribeEvents();
  4510. }
  4511. }
  4512. public void aggregateScriptEvents()
  4513. {
  4514. if (ParentGroup == null || ParentGroup.RootPart == null)
  4515. return;
  4516. AggregatedScriptEvents = 0;
  4517. // Aggregate script events
  4518. lock (m_scriptEvents)
  4519. {
  4520. foreach (scriptEvents s in m_scriptEvents.Values)
  4521. {
  4522. AggregatedScriptEvents |= s;
  4523. }
  4524. }
  4525. uint objectflagupdate = 0;
  4526. if (
  4527. ((AggregatedScriptEvents & scriptEvents.touch) != 0) ||
  4528. ((AggregatedScriptEvents & scriptEvents.touch_end) != 0) ||
  4529. ((AggregatedScriptEvents & scriptEvents.touch_start) != 0)
  4530. )
  4531. {
  4532. objectflagupdate |= (uint) PrimFlags.Touch;
  4533. }
  4534. if ((AggregatedScriptEvents & scriptEvents.money) != 0)
  4535. {
  4536. objectflagupdate |= (uint) PrimFlags.Money;
  4537. }
  4538. if (AllowedDrop)
  4539. {
  4540. objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
  4541. }
  4542. LocalFlags = (PrimFlags)objectflagupdate;
  4543. if (ParentGroup != null && ParentGroup.RootPart == this)
  4544. {
  4545. ParentGroup.aggregateScriptEvents();
  4546. }
  4547. else
  4548. {
  4549. // m_log.DebugFormat(
  4550. // "[SCENE OBJECT PART]: Scheduling part {0} {1} for full update in aggregateScriptEvents()", Name, LocalId);
  4551. UpdatePhysicsSubscribedEvents();
  4552. ScheduleFullUpdate();
  4553. }
  4554. }
  4555. public void SetCameraAtOffset(Vector3 v)
  4556. {
  4557. m_cameraAtOffset = v;
  4558. }
  4559. public void SetCameraEyeOffset(Vector3 v)
  4560. {
  4561. m_cameraEyeOffset = v;
  4562. }
  4563. public void SetForceMouselook(bool force)
  4564. {
  4565. m_forceMouselook = force;
  4566. }
  4567. public Vector3 GetCameraAtOffset()
  4568. {
  4569. return m_cameraAtOffset;
  4570. }
  4571. public Vector3 GetCameraEyeOffset()
  4572. {
  4573. return m_cameraEyeOffset;
  4574. }
  4575. public bool GetForceMouselook()
  4576. {
  4577. return m_forceMouselook;
  4578. }
  4579. public override string ToString()
  4580. {
  4581. return String.Format("{0} {1} (parent {2}))", Name, UUID, ParentGroup);
  4582. }
  4583. #endregion Public Methods
  4584. public void SendUpdateToClient(IClientAPI remoteClient, PrimUpdateFlags update)
  4585. {
  4586. if (ParentGroup.IsDeleted)
  4587. return;
  4588. if (Animations == null)
  4589. {
  4590. update &= ~PrimUpdateFlags.Animations;
  4591. if (update == PrimUpdateFlags.None)
  4592. return;
  4593. }
  4594. if (ParentGroup.IsAttachment &&
  4595. (ParentGroup.RootPart != this || ParentGroup.AttachedAvatar != remoteClient.AgentId && ParentGroup.HasPrivateAttachmentPoint))
  4596. return;
  4597. remoteClient.SendEntityUpdate(this, update);
  4598. ParentGroup.Scene.StatsReporter.AddObjectUpdates(1);
  4599. }
  4600. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  4601. {
  4602. if (ParentGroup.IsDeleted)
  4603. return;
  4604. if (ParentGroup.IsAttachment
  4605. && (ParentGroup.RootPart != this
  4606. || ParentGroup.AttachedAvatar != remoteClient.AgentId && ParentGroup.HasPrivateAttachmentPoint))
  4607. return;
  4608. // Causes this thread to dig into the Client Thread Data.
  4609. // Remember your locking here!
  4610. remoteClient.SendEntityUpdate(this, PrimUpdateFlags.TerseUpdate);
  4611. ParentGroup.Scene.StatsReporter.AddObjectUpdates(1);
  4612. }
  4613. public void AddScriptLPS(int count)
  4614. {
  4615. ParentGroup.AddScriptLPS(count);
  4616. }
  4617. /// <summary>
  4618. /// Sets a prim's owner and permissions when it's rezzed.
  4619. /// </summary>
  4620. /// <param name="item">The inventory item from which the item was rezzed</param>
  4621. /// <param name="userInventory">True: the item is being rezzed from the user's inventory. False: from a prim's inventory.</param>
  4622. /// <param name="scene">The scene the prim is being rezzed into</param>
  4623. public void ApplyPermissionsOnRez(InventoryItemBase item, bool userInventory, Scene scene)
  4624. {
  4625. if ((OwnerID != item.Owner) || ((item.CurrentPermissions & (uint)PermissionMask.Slam) != 0) || ((item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0))
  4626. {
  4627. if (scene.Permissions.PropagatePermissions())
  4628. {
  4629. if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
  4630. {
  4631. // Apply the item's permissions to the object
  4632. //LogPermissions("Before applying item permissions");
  4633. if (userInventory)
  4634. {
  4635. EveryoneMask = item.EveryOnePermissions;
  4636. NextOwnerMask = item.NextPermissions;
  4637. }
  4638. else
  4639. {
  4640. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
  4641. EveryoneMask = item.EveryOnePermissions;
  4642. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
  4643. NextOwnerMask = item.NextPermissions;
  4644. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
  4645. GroupMask = item.GroupPermissions;
  4646. }
  4647. //LogPermissions("After applying item permissions");
  4648. }
  4649. }
  4650. GroupMask = 0; // DO NOT propagate here
  4651. }
  4652. if (OwnerID != item.Owner)
  4653. {
  4654. if(OwnerID != GroupID)
  4655. LastOwnerID = OwnerID;
  4656. OwnerID = item.Owner;
  4657. Inventory.ChangeInventoryOwner(item.Owner);
  4658. if (scene.Permissions.PropagatePermissions())
  4659. ApplyNextOwnerPermissions();
  4660. }
  4661. }
  4662. /// <summary>
  4663. /// Logs the prim's permissions. Useful when debugging permission problems.
  4664. /// </summary>
  4665. /// <param name="message"></param>
  4666. private void LogPermissions(String message)
  4667. {
  4668. PermissionsUtil.LogPermissions(Name, message, BaseMask, OwnerMask, NextOwnerMask);
  4669. }
  4670. public void ApplyNextOwnerPermissions()
  4671. {
  4672. // Export needs to be preserved in the base and everyone
  4673. // mask, but removed in the owner mask as a next owner
  4674. // can never change the export status
  4675. BaseMask &= (NextOwnerMask | (uint)PermissionMask.Export);
  4676. OwnerMask &= NextOwnerMask;
  4677. EveryoneMask &= (NextOwnerMask | (uint)PermissionMask.Export);
  4678. GroupMask = 0; // Giving an object zaps group permissions
  4679. Inventory.ApplyNextOwnerPermissions();
  4680. AggregateInnerPerms();
  4681. }
  4682. public void UpdateLookAt()
  4683. {
  4684. try
  4685. {
  4686. if (APIDActive)
  4687. {
  4688. PhysicsActor pa = ParentGroup.RootPart.PhysActor;
  4689. if (pa == null || !pa.IsPhysical || APIDStrength < 0.04)
  4690. {
  4691. StopLookAt();
  4692. return;
  4693. }
  4694. Quaternion currRot = GetWorldRotation();
  4695. currRot.Normalize();
  4696. // difference between current orientation and desired orientation
  4697. Quaternion dR = currRot / APIDTarget;
  4698. // find axis and angle of rotation to rotate to desired orientation
  4699. Vector3 axis = Vector3.UnitX;
  4700. float angle;
  4701. dR.GetAxisAngle(out axis, out angle);
  4702. axis = axis * currRot;
  4703. // clamp strength to avoid overshoot
  4704. float strength = 1.0f / APIDStrength;
  4705. if (strength > 1.0) strength = 1.0f;
  4706. // set angular velocity to rotate to desired orientation
  4707. // with velocity proportional to strength and angle
  4708. AngularVelocity = axis * angle * strength * (float)Math.PI;
  4709. // This ensures that we'll check this object on the next iteration
  4710. ParentGroup.QueueForUpdateCheck();
  4711. }
  4712. }
  4713. catch (Exception ex)
  4714. {
  4715. m_log.Error("[Physics] " + ex);
  4716. }
  4717. }
  4718. public Color4 GetTextColor()
  4719. {
  4720. Color color = Color;
  4721. return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
  4722. }
  4723. public void ResetOwnerChangeFlag()
  4724. {
  4725. List<UUID> inv = Inventory.GetInventoryList();
  4726. foreach (UUID itemID in inv)
  4727. {
  4728. TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
  4729. item.OwnerChanged = false;
  4730. Inventory.UpdateInventoryItem(item, false, false);
  4731. }
  4732. AggregateInnerPerms();
  4733. }
  4734. /// <summary>
  4735. /// Record an avatar sitting on this part.
  4736. /// </summary>
  4737. /// <remarks>This is called for all the sitting avatars whether there is a sit target set or not.</remarks>
  4738. /// <returns>
  4739. /// true if the avatar was not already recorded, false otherwise.
  4740. /// </returns>
  4741. /// <param name='avatarId'></param>
  4742. protected internal bool AddSittingAvatar(ScenePresence sp)
  4743. {
  4744. lock (ParentGroup.m_sittingAvatars)
  4745. {
  4746. if (IsSitTargetSet && SitTargetAvatar == UUID.Zero)
  4747. SitTargetAvatar = sp.UUID;
  4748. if (m_sittingAvatars == null)
  4749. m_sittingAvatars = new HashSet<ScenePresence>();
  4750. if (m_sittingAvatars.Add(sp))
  4751. {
  4752. if(!ParentGroup.m_sittingAvatars.Contains(sp))
  4753. ParentGroup.m_sittingAvatars.Add(sp);
  4754. return true;
  4755. }
  4756. return false;
  4757. }
  4758. }
  4759. /// <summary>
  4760. /// Remove an avatar recorded as sitting on this part.
  4761. /// </summary>
  4762. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4763. /// <returns>
  4764. /// true if the avatar was present and removed, false if it was not present.
  4765. /// </returns>
  4766. /// <param name='avatarId'></param>
  4767. protected internal bool RemoveSittingAvatar(ScenePresence sp)
  4768. {
  4769. lock (ParentGroup.m_sittingAvatars)
  4770. {
  4771. if (SitTargetAvatar == sp.UUID)
  4772. SitTargetAvatar = UUID.Zero;
  4773. if (m_sittingAvatars == null)
  4774. return false;
  4775. if (m_sittingAvatars.Remove(sp))
  4776. {
  4777. if (m_sittingAvatars.Count == 0)
  4778. m_sittingAvatars = null;
  4779. if(ParentGroup.m_sittingAvatars.Remove(sp))
  4780. ParentGroup.InvalidatePartsLinkMaps(false);
  4781. return true;
  4782. }
  4783. return false;
  4784. }
  4785. }
  4786. /// <summary>
  4787. /// Get a copy of the list of sitting avatars.
  4788. /// </summary>
  4789. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4790. /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns>
  4791. public HashSet<ScenePresence> GetSittingAvatars()
  4792. {
  4793. lock (ParentGroup.m_sittingAvatars)
  4794. {
  4795. if (m_sittingAvatars == null)
  4796. return null;
  4797. else
  4798. return new HashSet<ScenePresence>(m_sittingAvatars);
  4799. }
  4800. }
  4801. /// <summary>
  4802. /// Gets the number of sitting avatars.
  4803. /// </summary>
  4804. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4805. /// <returns></returns>
  4806. public int GetSittingAvatarsCount()
  4807. {
  4808. lock (ParentGroup.m_sittingAvatars)
  4809. {
  4810. if (m_sittingAvatars == null)
  4811. return 0;
  4812. else
  4813. return m_sittingAvatars.Count;
  4814. }
  4815. }
  4816. public void Stop()
  4817. {
  4818. Velocity = Vector3.Zero;
  4819. AngularVelocity = Vector3.Zero;
  4820. Acceleration = Vector3.Zero;
  4821. APIDActive = false;
  4822. }
  4823. // handle osVolumeDetect
  4824. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  4825. {
  4826. if(ParentGroup.IsDeleted)
  4827. return;
  4828. if(_parentID == 0)
  4829. {
  4830. // if root prim do it is like llVolumeDetect
  4831. ParentGroup.ScriptSetVolumeDetect(makeVolumeDetect);
  4832. return;
  4833. }
  4834. if(ParentGroup.IsVolumeDetect)
  4835. return; // entire linkset is phantom already
  4836. bool wasUsingPhysics = ParentGroup.UsesPhysics;
  4837. bool wasTemporary = ParentGroup.IsTemporary;
  4838. bool wasPhantom = ParentGroup.IsPhantom;
  4839. if(PhysActor != null)
  4840. PhysActor.Building = true;
  4841. UpdatePrimFlags(wasUsingPhysics, wasTemporary, wasPhantom, makeVolumeDetect, false);
  4842. }
  4843. protected static int m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0x5fffafL);
  4844. public static int NextObjectAnimationSequenceNumber
  4845. {
  4846. get
  4847. {
  4848. int ret = Interlocked.Increment(ref m_animationSequenceNumber);
  4849. if (ret <= 0)
  4850. {
  4851. m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0xafff5fL);
  4852. ret = Interlocked.Increment(ref m_animationSequenceNumber);
  4853. }
  4854. return ret;
  4855. }
  4856. }
  4857. private object animsLock = new object();
  4858. public Dictionary<UUID, int> Animations = null;
  4859. public Dictionary<UUID, string> AnimationsNames = null;
  4860. public bool AddAnimation(UUID animId, string animName)
  4861. {
  4862. if (animId == UUID.Zero || string.IsNullOrEmpty(animName) ||
  4863. ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4864. return false;
  4865. lock (animsLock)
  4866. {
  4867. if (Animations == null)
  4868. Animations = new Dictionary<UUID, int>(1);
  4869. if (AnimationsNames == null)
  4870. AnimationsNames = new Dictionary<UUID, string>(1);
  4871. if (Animations.ContainsKey(animId))
  4872. return false;
  4873. Animations[animId] = NextObjectAnimationSequenceNumber;
  4874. AnimationsNames[animId] = animName;
  4875. ScheduleUpdate(PrimUpdateFlags.Animations);
  4876. }
  4877. return true;
  4878. }
  4879. public bool RemoveAnimation(UUID animId)
  4880. {
  4881. if (animId == UUID.Zero || ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4882. return false;
  4883. lock (animsLock)
  4884. {
  4885. if (Animations == null)
  4886. return false;
  4887. if (Animations.ContainsKey(animId))
  4888. {
  4889. Animations.Remove(animId);
  4890. if(AnimationsNames!=null)
  4891. AnimationsNames.Remove(animId);
  4892. ScheduleUpdate(PrimUpdateFlags.Animations);
  4893. return true;
  4894. }
  4895. }
  4896. return false;
  4897. }
  4898. public int ClearObjectAnimations()
  4899. {
  4900. int ret = 0;
  4901. if(Animations != null)
  4902. {
  4903. ret = Animations.Count;
  4904. Animations.Clear();
  4905. AnimationsNames.Clear();
  4906. }
  4907. else
  4908. {
  4909. Animations = new Dictionary<UUID, int>();
  4910. AnimationsNames = new Dictionary<UUID, string>();
  4911. }
  4912. ScheduleUpdate(PrimUpdateFlags.Animations);
  4913. return ret;
  4914. }
  4915. public int GetAnimations(out UUID[] ids, out int[] seqs)
  4916. {
  4917. ids = null;
  4918. seqs = null;
  4919. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4920. return -1;
  4921. lock (animsLock)
  4922. {
  4923. if (Animations == null)
  4924. return -1;
  4925. if(Animations.Count == 0)
  4926. return 0;
  4927. ids = new UUID[Animations.Count];
  4928. Animations.Keys.CopyTo(ids, 0);
  4929. seqs = new int[Animations.Count];
  4930. Animations.Values.CopyTo(seqs, 0);
  4931. return Animations.Count;
  4932. }
  4933. }
  4934. public Byte[] SerializeAnimations()
  4935. {
  4936. if (AnimationsNames == null)
  4937. return null;
  4938. lock (animsLock)
  4939. {
  4940. if (AnimationsNames.Count == 0)
  4941. return new byte[] { 0 };
  4942. using (MemoryStream ms = new MemoryStream())
  4943. {
  4944. byte[] tmp = Utils.UInt16ToBytes((ushort)Animations.Count);
  4945. ms.Write(tmp, 0, 2);
  4946. foreach(KeyValuePair<UUID,string> kvp in AnimationsNames)
  4947. {
  4948. tmp = kvp.Key.GetBytes();
  4949. ms.Write(tmp, 0, 16);
  4950. if(string.IsNullOrEmpty(kvp.Value))
  4951. ms.WriteByte(0);
  4952. else
  4953. {
  4954. byte[] str = Util.StringToBytes(kvp.Value, 64);
  4955. int len = str.Length - 1;
  4956. ms.WriteByte((byte)len);
  4957. ms.Write(str, 0 , len);
  4958. }
  4959. }
  4960. return ms.ToArray();
  4961. }
  4962. }
  4963. }
  4964. public void DeSerializeAnimations(Byte[] data)
  4965. {
  4966. if(data == null)
  4967. {
  4968. Animations = null;
  4969. AnimationsNames = null;
  4970. return;
  4971. }
  4972. if (data.Length < 2)
  4973. {
  4974. Animations = new Dictionary<UUID, int>();
  4975. AnimationsNames = new Dictionary<UUID, string>();
  4976. return;
  4977. }
  4978. try
  4979. {
  4980. int count = (int)Utils.BytesToUInt16(data, 0);
  4981. if(count == 0)
  4982. return;
  4983. Animations = new Dictionary<UUID, int>(count);
  4984. AnimationsNames = new Dictionary<UUID, string>(count);
  4985. int pos = 2;
  4986. while(--count >= 0)
  4987. {
  4988. UUID id = new UUID(data, pos);
  4989. if(id == UUID.Zero)
  4990. break;
  4991. pos += 16;
  4992. int strlen = data[pos++];
  4993. string name = UTF8Encoding.UTF8.GetString(data, pos, strlen);
  4994. if(string.IsNullOrEmpty(name))
  4995. break;
  4996. pos += strlen;
  4997. Animations[id] = NextObjectAnimationSequenceNumber;
  4998. AnimationsNames[id] = name;
  4999. }
  5000. return;
  5001. }
  5002. catch { }
  5003. Animations = null;
  5004. AnimationsNames = null;
  5005. }
  5006. }
  5007. }