SceneObjectPart.cs 185 KB

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