SceneObjectPart.cs 194 KB

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