SceneObjectPart.cs 195 KB

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