1
0

SceneObjectPart.cs 201 KB

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