SceneObjectPart.cs 196 KB

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