SceneObjectPart.cs 193 KB

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