SceneObjectGroup.cs 203 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551
  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.ComponentModel;
  29. using System.Collections.Generic;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Diagnostics;
  33. using System.Linq;
  34. using System.Threading;
  35. using System.Xml;
  36. using System.Xml.Serialization;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.PhysicsModules.SharedBase;
  42. using OpenSim.Region.Framework.Scenes.Serialization;
  43. using PermissionMask = OpenSim.Framework.PermissionMask;
  44. using OpenSim.Services.Interfaces;
  45. namespace OpenSim.Region.Framework.Scenes
  46. {
  47. [Flags]
  48. public enum scriptEvents
  49. {
  50. None = 0,
  51. attach = 1,
  52. collision = 16,
  53. collision_end = 32,
  54. collision_start = 64,
  55. control = 128,
  56. dataserver = 256,
  57. email = 512,
  58. http_response = 1024,
  59. land_collision = 2048,
  60. land_collision_end = 4096,
  61. land_collision_start = 8192,
  62. at_target = 16384,
  63. at_rot_target = 16777216,
  64. listen = 32768,
  65. money = 65536,
  66. moving_end = 131072,
  67. moving_start = 262144,
  68. not_at_rot_target = 524288,
  69. not_at_target = 1048576,
  70. remote_data = 8388608,
  71. run_time_permissions = 268435456,
  72. state_entry = 1073741824,
  73. state_exit = 2,
  74. timer = 4,
  75. touch = 8,
  76. touch_end = 536870912,
  77. touch_start = 2097152,
  78. transaction_result = 33554432,
  79. object_rez = 4194304,
  80. anytouch = touch | touch_end | touch_start
  81. }
  82. public struct scriptPosTarget
  83. {
  84. public Vector3 targetPos;
  85. public float tolerance;
  86. public uint handle;
  87. }
  88. public struct scriptRotTarget
  89. {
  90. public Quaternion targetRot;
  91. public float tolerance;
  92. public uint handle;
  93. }
  94. public delegate void PrimCountTaintedDelegate();
  95. /// <summary>
  96. /// A scene object group is conceptually an object in the scene. The object is constituted of SceneObjectParts
  97. /// (often known as prims), one of which is considered the root part.
  98. /// </summary>
  99. public partial class SceneObjectGroup : EntityBase, ISceneObject
  100. {
  101. // Axis selection bitmask used by SetAxisRotation()
  102. // Just happen to be the same bits used by llSetStatus() and defined in ScriptBaseClass.
  103. public enum axisSelect : int
  104. {
  105. STATUS_ROTATE_X = 0x002,
  106. STATUS_ROTATE_Y = 0x004,
  107. STATUS_ROTATE_Z = 0x008,
  108. NOT_STATUS_ROTATE_X = 0xFD,
  109. NOT_STATUS_ROTATE_Y = 0xFB,
  110. NOT_STATUS_ROTATE_Z = 0xF7
  111. }
  112. // private PrimCountTaintedDelegate handlerPrimCountTainted = null;
  113. /// <summary>
  114. /// Signal whether the non-inventory attributes of any prims in the group have changed
  115. /// since the group's last persistent backup
  116. /// </summary>
  117. private bool m_hasGroupChanged = false;
  118. private long timeFirstChanged = 0;
  119. private long timeLastChanged = 0;
  120. private long m_maxPersistTime = 0;
  121. private long m_minPersistTime = 0;
  122. // private Random m_rand;
  123. /// <summary>
  124. /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage
  125. /// (the database).
  126. /// </summary>
  127. /// <remarks>
  128. /// Ultimately, this should be managed such that region modules can change it at the end of a set of operations
  129. /// so that either all changes are preserved or none at all. However, currently, a large amount of internal
  130. /// code will set this anyway when some object properties are changed.
  131. /// </remarks>
  132. public bool HasGroupChanged
  133. {
  134. set
  135. {
  136. if (value)
  137. {
  138. if (Backup)
  139. {
  140. m_scene.SceneGraph.FireChangeBackup(this);
  141. }
  142. timeLastChanged = DateTime.UtcNow.Ticks;
  143. if (!m_hasGroupChanged)
  144. timeFirstChanged = DateTime.UtcNow.Ticks;
  145. if (m_rootPart != null && m_scene != null)
  146. {
  147. /*
  148. if (m_rand == null)
  149. {
  150. byte[] val = new byte[16];
  151. m_rootPart.UUID.ToBytes(val, 0);
  152. m_rand = new Random(BitConverter.ToInt32(val, 0));
  153. }
  154. */
  155. if (m_scene.GetRootAgentCount() == 0)
  156. {
  157. //If the region is empty, this change has been made by an automated process
  158. //and thus we delay the persist time by a random amount between 1.5 and 2.5.
  159. // float factor = 1.5f + (float)(m_rand.NextDouble());
  160. float factor = 2.0f;
  161. m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
  162. m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
  163. }
  164. else
  165. {
  166. //If the region is not empty, we want to obey the minimum and maximum persist times
  167. //but add a random factor so we stagger the object persistance a little
  168. // m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
  169. // m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
  170. m_maxPersistTime = m_scene.m_persistAfter;
  171. m_minPersistTime = m_scene.m_dontPersistBefore;
  172. }
  173. }
  174. }
  175. m_hasGroupChanged = value;
  176. // m_log.DebugFormat(
  177. // "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId);
  178. }
  179. get { return m_hasGroupChanged; }
  180. }
  181. private bool m_groupContainsForeignPrims = false;
  182. /// <summary>
  183. /// Whether the group contains prims that came from a different group. This happens when
  184. /// linking or delinking groups. The implication is that until the group is persisted,
  185. /// the prims in the database still use the old SceneGroupID. That's a problem if the group
  186. /// is deleted, because we delete groups by searching for prims by their SceneGroupID.
  187. /// </summary>
  188. public bool GroupContainsForeignPrims
  189. {
  190. private set
  191. {
  192. m_groupContainsForeignPrims = value;
  193. if (m_groupContainsForeignPrims)
  194. HasGroupChanged = true;
  195. }
  196. get { return m_groupContainsForeignPrims; }
  197. }
  198. public bool HasGroupChangedDueToDelink { get; set; }
  199. private bool isTimeToPersist()
  200. {
  201. if (IsSelected || IsDeleted || IsAttachment)
  202. return false;
  203. if (!m_hasGroupChanged)
  204. return false;
  205. if (m_scene.ShuttingDown)
  206. return true;
  207. if (m_minPersistTime == 0 || m_maxPersistTime == 0)
  208. {
  209. m_maxPersistTime = m_scene.m_persistAfter;
  210. m_minPersistTime = m_scene.m_dontPersistBefore;
  211. }
  212. long currentTime = DateTime.UtcNow.Ticks;
  213. if (timeLastChanged == 0) timeLastChanged = currentTime;
  214. if (timeFirstChanged == 0) timeFirstChanged = currentTime;
  215. if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
  216. return true;
  217. return false;
  218. }
  219. /// <summary>
  220. /// Is this scene object acting as an attachment?
  221. /// </summary>
  222. public bool IsAttachment { get; set; }
  223. /// <summary>
  224. /// The avatar to which this scene object is attached.
  225. /// </summary>
  226. /// <remarks>
  227. /// If we're not attached to an avatar then this is UUID.Zero
  228. /// </remarks>
  229. public UUID AttachedAvatar { get; set; }
  230. /// <summary>
  231. /// Attachment point of this scene object to an avatar.
  232. /// </summary>
  233. /// <remarks>
  234. /// 0 if we're not attached to anything
  235. /// </remarks>
  236. public uint AttachmentPoint
  237. {
  238. get
  239. {
  240. return m_rootPart.Shape.State;
  241. }
  242. set
  243. {
  244. IsAttachment = value != 0;
  245. m_rootPart.Shape.State = (byte)value;
  246. }
  247. }
  248. /// <summary>
  249. /// If this scene object has an attachment point then indicate whether there is a point where
  250. /// attachments are perceivable by avatars other than the avatar to which this object is attached.
  251. /// </summary>
  252. /// <remarks>
  253. /// HUDs are not perceivable by other avatars.
  254. /// </remarks>
  255. public bool HasPrivateAttachmentPoint
  256. {
  257. get
  258. {
  259. return AttachmentPoint >= (uint)OpenMetaverse.AttachmentPoint.HUDCenter2
  260. && AttachmentPoint <= (uint)OpenMetaverse.AttachmentPoint.HUDBottomRight;
  261. }
  262. }
  263. public void ClearPartAttachmentData()
  264. {
  265. AttachmentPoint = 0;
  266. // Don't zap trees
  267. if (RootPart.Shape.PCode == (byte)PCode.Tree ||
  268. RootPart.Shape.PCode == (byte)PCode.NewTree)
  269. return;
  270. // Even though we don't use child part state parameters for attachments any more, we still need to set
  271. // these to zero since having them non-zero in rezzed scene objects will crash some clients. Even if
  272. // we store them correctly, scene objects that we receive from elsewhere might not.
  273. foreach (SceneObjectPart part in Parts)
  274. part.Shape.State = 0;
  275. }
  276. /// <summary>
  277. /// Is this scene object phantom?
  278. /// </summary>
  279. /// <remarks>
  280. /// Updating must currently take place through UpdatePrimFlags()
  281. /// </remarks>
  282. public bool IsPhantom
  283. {
  284. get { return (RootPart.Flags & PrimFlags.Phantom) != 0; }
  285. }
  286. /// <summary>
  287. /// Does this scene object use physics?
  288. /// </summary>
  289. /// <remarks>
  290. /// Updating must currently take place through UpdatePrimFlags()
  291. /// </remarks>
  292. public bool UsesPhysics
  293. {
  294. get { return (RootPart.Flags & PrimFlags.Physics) != 0; }
  295. }
  296. /// <summary>
  297. /// Is this scene object temporary?
  298. /// </summary>
  299. /// <remarks>
  300. /// Updating must currently take place through UpdatePrimFlags()
  301. /// </remarks>
  302. public bool IsTemporary
  303. {
  304. get { return (RootPart.Flags & PrimFlags.TemporaryOnRez) != 0; }
  305. }
  306. public bool IsVolumeDetect
  307. {
  308. get { return RootPart.VolumeDetectActive; }
  309. }
  310. /// <summary>
  311. /// Is this entity set to be saved in persistent storage?
  312. /// </summary>
  313. public bool Backup { get; private set; }
  314. protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>();
  315. protected ulong m_regionHandle;
  316. protected SceneObjectPart m_rootPart;
  317. // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  318. private SortedDictionary<uint, scriptPosTarget> m_targets = new SortedDictionary<uint, scriptPosTarget>();
  319. private SortedDictionary<uint, scriptRotTarget> m_rotTargets = new SortedDictionary<uint, scriptRotTarget>();
  320. public SortedDictionary<uint, scriptPosTarget> AtTargets
  321. {
  322. get { return m_targets; }
  323. }
  324. public SortedDictionary<uint, scriptRotTarget> RotTargets
  325. {
  326. get { return m_rotTargets; }
  327. }
  328. private bool m_scriptListens_atTarget;
  329. private bool m_scriptListens_notAtTarget;
  330. private bool m_scriptListens_atRotTarget;
  331. private bool m_scriptListens_notAtRotTarget;
  332. public bool m_dupeInProgress = false;
  333. internal Dictionary<UUID, string> m_savedScriptState;
  334. public UUID MonitoringObject { get; set; }
  335. #region Properties
  336. /// <summary>
  337. /// The name of an object grouping is always the same as its root part
  338. /// </summary>
  339. public override string Name
  340. {
  341. get { return RootPart.Name; }
  342. set { RootPart.Name = value; }
  343. }
  344. public string Description
  345. {
  346. get { return RootPart.Description; }
  347. set { RootPart.Description = value; }
  348. }
  349. /// <summary>
  350. /// Added because the Parcel code seems to use it
  351. /// but not sure a object should have this
  352. /// as what does it tell us? that some avatar has selected it (but not what Avatar/user)
  353. /// think really there should be a list (or whatever) in each scenepresence
  354. /// saying what prim(s) that user has selected.
  355. /// </summary>
  356. protected bool m_isSelected = false;
  357. /// <summary>
  358. /// Number of prims in this group
  359. /// </summary>
  360. public int PrimCount
  361. {
  362. get { return m_parts.Count; }
  363. }
  364. // protected Quaternion m_rotation = Quaternion.Identity;
  365. //
  366. // public virtual Quaternion Rotation
  367. // {
  368. // get { return m_rotation; }
  369. // set {
  370. // m_rotation = value;
  371. // }
  372. // }
  373. public Quaternion GroupRotation
  374. {
  375. get { return m_rootPart.RotationOffset; }
  376. }
  377. public Vector3 GroupScale
  378. {
  379. get
  380. {
  381. Vector3 minScale = new Vector3(Constants.MaximumRegionSize, Constants.MaximumRegionSize, Constants.MaximumRegionSize);
  382. Vector3 maxScale = Vector3.Zero;
  383. Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
  384. SceneObjectPart[] parts = m_parts.GetArray();
  385. for (int i = 0; i < parts.Length; i++)
  386. {
  387. SceneObjectPart part = parts[i];
  388. Vector3 partscale = part.Scale;
  389. Vector3 partoffset = part.OffsetPosition;
  390. minScale.X = (partscale.X + partoffset.X < minScale.X) ? partscale.X + partoffset.X : minScale.X;
  391. minScale.Y = (partscale.Y + partoffset.Y < minScale.Y) ? partscale.Y + partoffset.Y : minScale.Y;
  392. minScale.Z = (partscale.Z + partoffset.Z < minScale.Z) ? partscale.Z + partoffset.Z : minScale.Z;
  393. maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X;
  394. maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y;
  395. maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
  396. }
  397. finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
  398. finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
  399. finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
  400. return finalScale;
  401. }
  402. }
  403. public UUID GroupID
  404. {
  405. get { return m_rootPart.GroupID; }
  406. set { m_rootPart.GroupID = value; }
  407. }
  408. public SceneObjectPart[] Parts
  409. {
  410. get { return m_parts.GetArray(); }
  411. }
  412. public bool ContainsPart(UUID partID)
  413. {
  414. return m_parts.ContainsKey(partID);
  415. }
  416. /// <summary>
  417. /// Does this group contain the given part?
  418. /// should be able to remove these methods once we have a entity index in scene
  419. /// </summary>
  420. /// <param name="localID"></param>
  421. /// <returns></returns>
  422. public bool ContainsPart(uint localID)
  423. {
  424. SceneObjectPart[] parts = m_parts.GetArray();
  425. for (int i = 0; i < parts.Length; i++)
  426. {
  427. if (parts[i].LocalId == localID)
  428. return true;
  429. }
  430. return false;
  431. }
  432. /// <value>
  433. /// The root part of this scene object
  434. /// </value>
  435. public SceneObjectPart RootPart
  436. {
  437. get { return m_rootPart; }
  438. }
  439. public ulong RegionHandle
  440. {
  441. get { return m_regionHandle; }
  442. set
  443. {
  444. m_regionHandle = value;
  445. SceneObjectPart[] parts = m_parts.GetArray();
  446. for (int i = 0; i < parts.Length; i++)
  447. parts[i].RegionHandle = value;
  448. }
  449. }
  450. /// <summary>
  451. /// Check both the attachment property and the relevant properties of the underlying root part.
  452. /// </summary>
  453. /// <remarks>
  454. /// This is necessary in some cases, particularly when a scene object has just crossed into a region and doesn't
  455. /// have the IsAttachment property yet checked.
  456. ///
  457. /// FIXME: However, this should be fixed so that this property
  458. /// propertly reflects the underlying status.
  459. /// </remarks>
  460. /// <returns></returns>
  461. public bool IsAttachmentCheckFull()
  462. {
  463. return (IsAttachment ||
  464. (m_rootPart.Shape.PCode == (byte)PCodeEnum.Primitive && m_rootPart.Shape.State != 0));
  465. }
  466. private struct avtocrossInfo
  467. {
  468. public ScenePresence av;
  469. public uint ParentID;
  470. }
  471. public bool inTransit = false;
  472. private delegate SceneObjectGroup SOGCrossDelegate(SceneObjectGroup sog,Vector3 pos, TeleportObjectData tpData);
  473. /// <summary>
  474. /// The absolute position of this scene object in the scene
  475. /// </summary>
  476. public override Vector3 AbsolutePosition
  477. {
  478. get { return m_rootPart.GroupPosition; }
  479. set
  480. {
  481. Vector3 val = value;
  482. if (Scene != null
  483. && !Scene.PositionIsInCurrentRegion(val)
  484. && !IsAttachmentCheckFull()
  485. && !Scene.LoadingPrims
  486. && !Scene.DisableObjectTransfer
  487. )
  488. {
  489. if (!inTransit)
  490. {
  491. inTransit = true;
  492. SOGCrossDelegate d = CrossAsync;
  493. d.BeginInvoke(this, val, null, CrossAsyncCompleted, d);
  494. }
  495. return;
  496. }
  497. if (RootPart.GetStatusSandbox())
  498. {
  499. if (Vector3.DistanceSquared(RootPart.StatusSandboxPos, value) > 100)
  500. {
  501. RootPart.ScriptSetPhysicsStatus(false);
  502. if (Scene != null)
  503. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  504. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  505. return;
  506. }
  507. }
  508. bool triggerScriptEvent = m_rootPart.GroupPosition != val;
  509. if (m_dupeInProgress || IsDeleted)
  510. triggerScriptEvent = false;
  511. m_rootPart.GroupPosition = val;
  512. // Restuff the new GroupPosition into each child SOP of the linkset.
  513. // this is needed because physics may not have linksets but just loose SOPs in world
  514. SceneObjectPart[] parts = m_parts.GetArray();
  515. foreach (SceneObjectPart part in parts)
  516. {
  517. if (part != m_rootPart)
  518. part.GroupPosition = val;
  519. }
  520. foreach (ScenePresence av in m_sittingAvatars)
  521. {
  522. av.sitSOGmoved();
  523. }
  524. // now that position is changed tell it to scripts
  525. if (triggerScriptEvent)
  526. {
  527. foreach (SceneObjectPart part in parts)
  528. {
  529. part.TriggerScriptChangedEvent(Changed.POSITION);
  530. }
  531. }
  532. if (Scene != null)
  533. Scene.EventManager.TriggerParcelPrimCountTainted();
  534. }
  535. }
  536. private SceneObjectGroup CrossAsync(SceneObjectGroup sog, Vector3 val, TeleportObjectData tpdata)
  537. {
  538. Scene sogScene = sog.m_scene;
  539. SceneObjectPart root = sog.RootPart;
  540. bool isTeleport = tpdata != null;
  541. if(!isTeleport)
  542. {
  543. if (root.DIE_AT_EDGE)
  544. {
  545. try
  546. {
  547. sogScene.DeleteSceneObject(sog, false);
  548. }
  549. catch (Exception)
  550. {
  551. m_log.Warn("[SCENE]: exception when trying to remove the prim that crossed the border.");
  552. }
  553. return sog;
  554. }
  555. if (root.RETURN_AT_EDGE)
  556. {
  557. // We remove the object here
  558. try
  559. {
  560. List<uint> localIDs = new List<uint>();
  561. localIDs.Add(root.LocalId);
  562. sogScene.AddReturn(sog.OwnerID, sog.Name, sog.AbsolutePosition,
  563. "Returned at region cross");
  564. sogScene.DeRezObjects(null, localIDs, UUID.Zero, DeRezAction.Return, UUID.Zero, false);
  565. }
  566. catch (Exception)
  567. {
  568. m_log.Warn("[SCENE]: exception when trying to return the prim that crossed the border.");
  569. }
  570. return sog;
  571. }
  572. }
  573. // if(!m_scene.IsRunning)
  574. // return sog;
  575. if (root.KeyframeMotion != null)
  576. root.KeyframeMotion.StartCrossingCheck();
  577. if(root.PhysActor != null)
  578. root.PhysActor.CrossingStart();
  579. IEntityTransferModule entityTransfer = sogScene.RequestModuleInterface<IEntityTransferModule>();
  580. if (entityTransfer == null)
  581. return sog;
  582. Vector3 newpos = Vector3.Zero;
  583. OpenSim.Services.Interfaces.GridRegion destination = null;
  584. destination = entityTransfer.GetObjectDestination(sog, val, out newpos);
  585. if (destination == null)
  586. return sog;
  587. if (sog.m_sittingAvatars.Count == 0)
  588. {
  589. entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, !isTeleport, true);
  590. return sog;
  591. }
  592. string reason = String.Empty;
  593. EntityTransferContext ctx = new EntityTransferContext();
  594. Vector3 curPos = root.GroupPosition;
  595. foreach (ScenePresence av in sog.m_sittingAvatars)
  596. {
  597. // We need to cross these agents. First, let's find
  598. // out if any of them can't cross for some reason.
  599. // We have to deny the crossing entirely if any
  600. // of them are banned. Alternatively, we could
  601. // unsit banned agents....
  602. // We set the avatar position as being the object
  603. // position to get the region to send to
  604. if(av.IsNPC)
  605. continue;
  606. if(av.IsInTransit)
  607. return sog;
  608. if(!entityTransfer.checkAgentAccessToRegion(av, destination, newpos, ctx, out reason))
  609. return sog;
  610. m_log.DebugFormat("[SCENE OBJECT]: Avatar {0} needs to be crossed to {1}", av.Name, destination.RegionName);
  611. }
  612. // We unparent the SP quietly so that it won't
  613. // be made to stand up
  614. List<avtocrossInfo> avsToCross = new List<avtocrossInfo>();
  615. List<ScenePresence> avsToCrossFar = new List<ScenePresence>();
  616. ulong destHandle = destination.RegionHandle;
  617. List<ScenePresence> sittingAvatars = GetSittingAvatars();
  618. foreach (ScenePresence av in sittingAvatars)
  619. {
  620. byte cflags = 1;
  621. avtocrossInfo avinfo = new avtocrossInfo();
  622. SceneObjectPart parentPart = sogScene.GetSceneObjectPart(av.ParentID);
  623. if (parentPart != null)
  624. {
  625. av.ParentUUID = parentPart.UUID;
  626. if(parentPart.SitTargetAvatar == av.UUID)
  627. cflags = 7; // low 3 bits set
  628. else
  629. cflags = 3;
  630. }
  631. if(!av.knowsNeighbourRegion(destHandle))
  632. cflags |= 8;
  633. // 1 is crossing
  634. // 2 is sitting
  635. // 4 is sitting at sittarget
  636. // 8 far crossing
  637. avinfo.av = av;
  638. avinfo.ParentID = av.ParentID;
  639. avsToCross.Add(avinfo);
  640. if(!av.knowsNeighbourRegion(destHandle))
  641. {
  642. cflags |= 8;
  643. avsToCrossFar.Add(av);
  644. }
  645. if(av.IsNPC)
  646. av.crossingFlags = 0;
  647. else
  648. av.crossingFlags = cflags;
  649. av.PrevSitOffset = av.OffsetPosition;
  650. av.ParentID = 0;
  651. }
  652. Vector3 vel = root.Velocity;
  653. Vector3 avel = root.AngularVelocity;
  654. Vector3 acc = root.Acceleration;
  655. Quaternion ori = root.RotationOffset;
  656. if(isTeleport)
  657. {
  658. root.Stop();
  659. sogScene.ForEachScenePresence(delegate(ScenePresence av)
  660. {
  661. av.ControllingClient.SendEntityUpdate(root,PrimUpdateFlags.SendInTransit);
  662. av.ControllingClient.SendEntityTerseUpdateImmediate(root);
  663. });
  664. root.Velocity = tpdata.vel;
  665. root.AngularVelocity = tpdata.avel;
  666. root.Acceleration = tpdata.acc;
  667. root.RotationOffset = tpdata.ori;
  668. }
  669. if (entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, true, false))
  670. {
  671. if(isTeleport)
  672. {
  673. sogScene.ForEachScenePresence(delegate(ScenePresence oav)
  674. {
  675. if(sittingAvatars.Contains(oav))
  676. return;
  677. if(oav.knowsNeighbourRegion(destHandle))
  678. return;
  679. oav.ControllingClient.SendEntityUpdate(root, PrimUpdateFlags.Kill);
  680. foreach (ScenePresence sav in sittingAvatars)
  681. {
  682. sav.SendKillTo(oav);
  683. }
  684. });
  685. }
  686. bool crossedfar = false;
  687. foreach (ScenePresence av in avsToCrossFar)
  688. {
  689. if(entityTransfer.CrossAgentCreateFarChild(av,destination, newpos, ctx))
  690. crossedfar = true;
  691. else
  692. av.crossingFlags = 0;
  693. }
  694. if(crossedfar)
  695. Thread.Sleep(1000);
  696. foreach (avtocrossInfo avinfo in avsToCross)
  697. {
  698. ScenePresence av = avinfo.av;
  699. av.IsInLocalTransit = true;
  700. av.IsInTransit = true;
  701. m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar {0} to {1}", av.Name, val);
  702. if(av.crossingFlags > 0)
  703. entityTransfer.CrossAgentToNewRegionAsync(av, newpos, destination, false, ctx);
  704. if (av.IsChildAgent)
  705. {
  706. // avatar crossed do some extra cleanup
  707. if (av.ParentUUID != UUID.Zero)
  708. {
  709. av.ClearControls();
  710. av.ParentPart = null;
  711. }
  712. av.ParentUUID = UUID.Zero;
  713. av.ParentPart = null;
  714. // In any case
  715. av.IsInTransit = false;
  716. av.crossingFlags = 0;
  717. m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", av.Firstname, av.Lastname);
  718. }
  719. else
  720. {
  721. // avatar cross failed we need do dedicated standUp
  722. // part of it was done at CrossAgentToNewRegionAsync
  723. // so for now just remove the sog controls
  724. // this may need extra care
  725. av.UnRegisterSeatControls(sog.UUID);
  726. av.ParentUUID = UUID.Zero;
  727. av.ParentPart = null;
  728. Vector3 oldp = curPos;
  729. oldp.X = Util.Clamp<float>(oldp.X, 0.5f, sog.m_scene.RegionInfo.RegionSizeX - 0.5f);
  730. oldp.Y = Util.Clamp<float>(oldp.Y, 0.5f, sog.m_scene.RegionInfo.RegionSizeY - 0.5f);
  731. av.AbsolutePosition = oldp;
  732. av.crossingFlags = 0;
  733. av.sitAnimation = "SIT";
  734. av.IsInTransit = false;
  735. if(av.Animator!= null)
  736. av.Animator.SetMovementAnimations("STAND");
  737. av.AddToPhysicalScene(false);
  738. sogScene.ForEachScenePresence(delegate(ScenePresence oav)
  739. {
  740. if(sittingAvatars.Contains(oav))
  741. return;
  742. if(oav.knowsNeighbourRegion(destHandle))
  743. av.SendAvatarDataToAgent(oav);
  744. else
  745. {
  746. av.SendAvatarDataToAgent(oav);
  747. av.SendAppearanceToAgent(oav);
  748. if (av.Animator != null)
  749. av.Animator.SendAnimPackToClient(oav.ControllingClient);
  750. av.SendAttachmentsToAgentNF(oav); // not ok
  751. }
  752. });
  753. m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} failed.", av.Firstname, av.Lastname);
  754. }
  755. }
  756. if(crossedfar)
  757. {
  758. Thread.Sleep(10000);
  759. foreach (ScenePresence av in avsToCrossFar)
  760. {
  761. if(av.IsChildAgent)
  762. {
  763. av.Scene.CloseAgent(av.UUID, false);
  764. }
  765. else
  766. av.RemoveNeighbourRegion(destHandle);
  767. }
  768. }
  769. avsToCrossFar.Clear();
  770. avsToCross.Clear();
  771. sog.RemoveScriptInstances(true);
  772. sog.Clear();
  773. return sog;
  774. }
  775. else
  776. {
  777. if(isTeleport)
  778. {
  779. if((tpdata.flags & OSTPOBJ_STOPONFAIL) == 0)
  780. {
  781. root.Velocity = vel;
  782. root.AngularVelocity = avel;
  783. root.Acceleration = acc;
  784. }
  785. root.RotationOffset = ori;
  786. }
  787. foreach (avtocrossInfo avinfo in avsToCross)
  788. {
  789. ScenePresence av = avinfo.av;
  790. av.ParentUUID = UUID.Zero;
  791. av.ParentID = avinfo.ParentID;
  792. av.crossingFlags = 0;
  793. }
  794. }
  795. avsToCross.Clear();
  796. return sog;
  797. }
  798. public void CrossAsyncCompleted(IAsyncResult iar)
  799. {
  800. SOGCrossDelegate icon = (SOGCrossDelegate)iar.AsyncState;
  801. SceneObjectGroup sog = icon.EndInvoke(iar);
  802. if (!sog.IsDeleted)
  803. {
  804. SceneObjectPart rootp = sog.m_rootPart;
  805. Vector3 oldp = rootp.GroupPosition;
  806. oldp.X = Util.Clamp<float>(oldp.X, 0.5f, sog.m_scene.RegionInfo.RegionSizeX - 0.5f);
  807. oldp.Y = Util.Clamp<float>(oldp.Y, 0.5f, sog.m_scene.RegionInfo.RegionSizeY - 0.5f);
  808. rootp.GroupPosition = oldp;
  809. rootp.Stop();
  810. SceneObjectPart[] parts = sog.m_parts.GetArray();
  811. foreach (SceneObjectPart part in parts)
  812. {
  813. if (part != rootp)
  814. part.GroupPosition = oldp;
  815. }
  816. foreach (ScenePresence av in sog.m_sittingAvatars)
  817. {
  818. av.sitSOGmoved();
  819. }
  820. if (sog.m_rootPart.KeyframeMotion != null)
  821. sog.m_rootPart.KeyframeMotion.CrossingFailure();
  822. if (sog.RootPart.PhysActor != null)
  823. sog.RootPart.PhysActor.CrossingFailure();
  824. sog.inTransit = false;
  825. AttachToBackup();
  826. sog.ScheduleGroupForFullUpdate();
  827. }
  828. }
  829. private class TeleportObjectData
  830. {
  831. public int flags;
  832. public Vector3 vel;
  833. public Vector3 avel;
  834. public Vector3 acc;
  835. public Quaternion ori;
  836. public UUID sourceID;
  837. }
  838. // copy from LSL_constants.cs
  839. const int OSTPOBJ_STOPATTARGET = 0x1; // stops at destination
  840. const int OSTPOBJ_STOPONFAIL = 0x2; // stops at start if tp fails
  841. const int OSTPOBJ_SETROT = 0x4; // the rotation is the final rotation, otherwise is a added rotation
  842. public int TeleportObject(UUID sourceID, Vector3 targetPosition, Quaternion rotation, int flags)
  843. {
  844. if(inTransit || IsDeleted || IsAttachmentCheckFull() || IsSelected || Scene == null)
  845. return -1;
  846. inTransit = true;
  847. PhysicsActor pa = RootPart.PhysActor;
  848. if(pa == null || RootPart.KeyframeMotion != null /*|| m_sittingAvatars.Count == 0*/)
  849. {
  850. inTransit = false;
  851. return -1;
  852. }
  853. bool stop = (flags & OSTPOBJ_STOPATTARGET) != 0;
  854. bool setrot = (flags & OSTPOBJ_SETROT) != 0;
  855. rotation.Normalize();
  856. Quaternion currentRot = RootPart.RotationOffset;
  857. if(setrot)
  858. rotation = Quaternion.Conjugate(currentRot) * rotation;
  859. bool dorot = setrot | (Math.Abs(rotation.W) < 0.99999);
  860. Vector3 vel = Vector3.Zero;
  861. Vector3 avel = Vector3.Zero;
  862. Vector3 acc = Vector3.Zero;
  863. if(!stop)
  864. {
  865. vel = RootPart.Velocity;
  866. avel = RootPart.AngularVelocity;
  867. acc = RootPart.Acceleration;
  868. }
  869. Quaternion ori = RootPart.RotationOffset;
  870. if(dorot)
  871. {
  872. if(!stop)
  873. {
  874. vel *= rotation;
  875. avel *= rotation;
  876. acc *= rotation;
  877. }
  878. ori *= rotation;
  879. }
  880. if(Scene.PositionIsInCurrentRegion(targetPosition))
  881. {
  882. if(Scene.InTeleportTargetsCoolDown(UUID, sourceID, 1.0))
  883. {
  884. inTransit = false;
  885. return -2;
  886. }
  887. Vector3 curPos = AbsolutePosition;
  888. ILandObject curLand = Scene.LandChannel.GetLandObject(curPos.X, curPos.Y);
  889. float posX = targetPosition.X;
  890. float posY = targetPosition.Y;
  891. ILandObject land = Scene.LandChannel.GetLandObject(posX, posY);
  892. if(land != null && land != curLand)
  893. {
  894. if(!Scene.Permissions.CanObjectEnterWithScripts(this, land))
  895. {
  896. inTransit = false;
  897. return -3;
  898. }
  899. UUID agentID;
  900. foreach (ScenePresence av in m_sittingAvatars)
  901. {
  902. agentID = av.UUID;
  903. if(land.IsRestrictedFromLand(agentID) || land.IsBannedFromLand(agentID))
  904. {
  905. inTransit = false;
  906. return -4;
  907. }
  908. }
  909. }
  910. RootPart.Velocity = vel;
  911. RootPart.AngularVelocity = avel;
  912. RootPart.Acceleration = acc;
  913. RootPart.RotationOffset = ori;
  914. Vector3 s = RootPart.Scale * RootPart.RotationOffset;
  915. float h = Scene.GetGroundHeight(posX, posY) + 0.5f * (float)Math.Abs(s.Z) + 0.01f;
  916. if(targetPosition.Z < h)
  917. targetPosition.Z = h;
  918. inTransit = false;
  919. AbsolutePosition = targetPosition;
  920. RootPart.ScheduleTerseUpdate();
  921. return 1;
  922. }
  923. if(Scene.InTeleportTargetsCoolDown(UUID, sourceID, 20.0))
  924. {
  925. inTransit = false;
  926. return -1;
  927. }
  928. TeleportObjectData tdata = new TeleportObjectData();
  929. tdata.flags = flags;
  930. tdata.vel = vel;
  931. tdata.avel = avel;
  932. tdata.acc = acc;
  933. tdata.ori = ori;
  934. tdata.sourceID = sourceID;
  935. SOGCrossDelegate d = CrossAsync;
  936. d.BeginInvoke(this, targetPosition, tdata, CrossAsyncCompleted, d);
  937. return 0;
  938. }
  939. public override Vector3 Velocity
  940. {
  941. get { return RootPart.Velocity; }
  942. set { RootPart.Velocity = value; }
  943. }
  944. public override uint LocalId
  945. {
  946. get { return m_rootPart.LocalId; }
  947. set { m_rootPart.LocalId = value; }
  948. }
  949. public override UUID UUID
  950. {
  951. get { return m_rootPart.UUID; }
  952. set
  953. {
  954. lock (m_parts.SyncRoot)
  955. {
  956. m_parts.Remove(m_rootPart.UUID);
  957. m_rootPart.UUID = value;
  958. m_parts.Add(value, m_rootPart);
  959. }
  960. }
  961. }
  962. public UUID LastOwnerID
  963. {
  964. get { return m_rootPart.LastOwnerID; }
  965. set { m_rootPart.LastOwnerID = value; }
  966. }
  967. public UUID RezzerID
  968. {
  969. get { return m_rootPart.RezzerID; }
  970. set { m_rootPart.RezzerID = value; }
  971. }
  972. public UUID OwnerID
  973. {
  974. get { return m_rootPart.OwnerID; }
  975. set { m_rootPart.OwnerID = value; }
  976. }
  977. public float Damage
  978. {
  979. get { return m_rootPart.Damage; }
  980. set { m_rootPart.Damage = value; }
  981. }
  982. public Color Color
  983. {
  984. get { return m_rootPart.Color; }
  985. set { m_rootPart.Color = value; }
  986. }
  987. public string Text
  988. {
  989. get {
  990. string returnstr = m_rootPart.Text;
  991. if (returnstr.Length > 255)
  992. {
  993. returnstr = returnstr.Substring(0, 255);
  994. }
  995. return returnstr;
  996. }
  997. set { m_rootPart.Text = value; }
  998. }
  999. /// <summary>
  1000. /// If set to true then the scene object can be backed up in principle, though this will only actually occur
  1001. /// if Backup is set. If false then the scene object will never be backed up, Backup will always be false.
  1002. /// </summary>
  1003. protected virtual bool CanBeBackedUp
  1004. {
  1005. get { return true; }
  1006. }
  1007. public bool IsSelected
  1008. {
  1009. get { return m_isSelected; }
  1010. set
  1011. {
  1012. m_isSelected = value;
  1013. // Tell physics engine that group is selected
  1014. // this is not right
  1015. // but ode engines should only really need to know about root part
  1016. // so they can put entire object simulation on hold and not colliding
  1017. // keep as was for now
  1018. PhysicsActor pa = m_rootPart.PhysActor;
  1019. if (pa != null)
  1020. {
  1021. pa.Selected = value;
  1022. // Pass it on to the children.
  1023. SceneObjectPart[] parts = m_parts.GetArray();
  1024. for (int i = 0; i < parts.Length; i++)
  1025. {
  1026. SceneObjectPart child = parts[i];
  1027. PhysicsActor childPa = child.PhysActor;
  1028. if (childPa != null)
  1029. childPa.Selected = value;
  1030. }
  1031. }
  1032. if (RootPart.KeyframeMotion != null)
  1033. RootPart.KeyframeMotion.Selected = value;
  1034. }
  1035. }
  1036. public void PartSelectChanged(bool partSelect)
  1037. {
  1038. // any part selected makes group selected
  1039. if (m_isSelected == partSelect)
  1040. return;
  1041. if (partSelect)
  1042. {
  1043. IsSelected = partSelect;
  1044. // if (!IsAttachment)
  1045. // ScheduleGroupForFullUpdate();
  1046. }
  1047. else
  1048. {
  1049. // bad bad bad 2 heavy for large linksets
  1050. // since viewer does send lot of (un)selects
  1051. // this needs to be replaced by a specific list or count ?
  1052. // but that will require extra code in several places
  1053. SceneObjectPart[] parts = m_parts.GetArray();
  1054. for (int i = 0; i < parts.Length; i++)
  1055. {
  1056. SceneObjectPart part = parts[i];
  1057. if (part.IsSelected)
  1058. return;
  1059. }
  1060. IsSelected = partSelect;
  1061. // if (!IsAttachment)
  1062. // {
  1063. // ScheduleGroupForFullUpdate();
  1064. // }
  1065. }
  1066. }
  1067. // PlaySoundMasterPrim no longer in use to remove
  1068. private SceneObjectPart m_PlaySoundMasterPrim = null;
  1069. public SceneObjectPart PlaySoundMasterPrim
  1070. {
  1071. get { return m_PlaySoundMasterPrim; }
  1072. set { m_PlaySoundMasterPrim = value; }
  1073. }
  1074. // PlaySoundSlavePrims no longer in use to remove
  1075. private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
  1076. public List<SceneObjectPart> PlaySoundSlavePrims
  1077. {
  1078. get { return m_PlaySoundSlavePrims; }
  1079. set { m_PlaySoundSlavePrims = value; }
  1080. }
  1081. // LoopSoundMasterPrim no longer in use to remove
  1082. private SceneObjectPart m_LoopSoundMasterPrim = null;
  1083. public SceneObjectPart LoopSoundMasterPrim
  1084. {
  1085. get { return m_LoopSoundMasterPrim; }
  1086. set { m_LoopSoundMasterPrim = value; }
  1087. }
  1088. // m_LoopSoundSlavePrims no longer in use to remove
  1089. private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
  1090. public List<SceneObjectPart> LoopSoundSlavePrims
  1091. {
  1092. get { return m_LoopSoundSlavePrims; }
  1093. set { m_LoopSoundSlavePrims = value; }
  1094. }
  1095. private double m_lastCollisionSoundMS;
  1096. /// <summary>
  1097. /// The UUID for the region this object is in.
  1098. /// </summary>
  1099. public UUID RegionUUID
  1100. {
  1101. get
  1102. {
  1103. if (m_scene != null)
  1104. {
  1105. return m_scene.RegionInfo.RegionID;
  1106. }
  1107. return UUID.Zero;
  1108. }
  1109. }
  1110. /// <summary>
  1111. /// The item ID that this object was rezzed from, if applicable.
  1112. /// </summary>
  1113. /// <remarks>
  1114. /// If not applicable will be UUID.Zero
  1115. /// </remarks>
  1116. public UUID FromItemID { get; set; }
  1117. /// <summary>
  1118. /// Refers to the SceneObjectPart.UUID property of the object that this object was rezzed from, if applicable.
  1119. /// </summary>
  1120. /// <remarks>
  1121. /// If not applicable will be UUID.Zero
  1122. /// </remarks>
  1123. /// obsolete use RezzerID
  1124. public UUID FromPartID
  1125. {
  1126. get { return RezzerID; }
  1127. set {RezzerID = value; }
  1128. }
  1129. /// <summary>
  1130. /// The folder ID that this object was rezzed from, if applicable.
  1131. /// </summary>
  1132. /// <remarks>
  1133. /// If not applicable will be UUID.Zero
  1134. /// </remarks>
  1135. public UUID FromFolderID { get; set; }
  1136. /// <summary>
  1137. /// If true then grabs are blocked no matter what the individual part BlockGrab setting.
  1138. /// </summary>
  1139. /// <value><c>true</c> if block grab override; otherwise, <c>false</c>.</value>
  1140. public bool BlockGrabOverride { get; set; }
  1141. /// <summary>
  1142. /// IDs of all avatars sat on this scene object.
  1143. /// </summary>
  1144. /// <remarks>
  1145. /// We need this so that we can maintain a linkset wide ordering of avatars sat on different parts.
  1146. /// This must be locked before it is read or written.
  1147. /// SceneObjectPart sitting avatar add/remove code also locks on this object to avoid race conditions.
  1148. /// No avatar should appear more than once in this list.
  1149. /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart.
  1150. /// </remarks>
  1151. protected internal List<ScenePresence> m_sittingAvatars = new List<ScenePresence>();
  1152. #endregion
  1153. // ~SceneObjectGroup()
  1154. // {
  1155. // //m_log.DebugFormat("[SCENE OBJECT GROUP]: Destructor called for {0}, local id {1}", Name, LocalId);
  1156. // Console.WriteLine("Destructor called for {0}, local id {1}", Name, LocalId);
  1157. // }
  1158. #region Constructors
  1159. /// <summary>
  1160. /// Constructor
  1161. /// </summary>
  1162. public SceneObjectGroup()
  1163. {
  1164. m_lastCollisionSoundMS = Util.GetTimeStampMS() + 1000.0;
  1165. }
  1166. /// <summary>
  1167. /// This constructor creates a SceneObjectGroup using a pre-existing SceneObjectPart.
  1168. /// The original SceneObjectPart will be used rather than a copy, preserving
  1169. /// its existing localID and UUID.
  1170. /// </summary>
  1171. /// <param name='part'>Root part for this scene object.</param>
  1172. public SceneObjectGroup(SceneObjectPart part) : this()
  1173. {
  1174. SetRootPart(part);
  1175. }
  1176. /// <summary>
  1177. /// Constructor. This object is added to the scene later via AttachToScene()
  1178. /// </summary>
  1179. public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
  1180. {
  1181. SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
  1182. }
  1183. /// <summary>
  1184. /// Constructor.
  1185. /// </summary>
  1186. public SceneObjectGroup(UUID ownerID, Vector3 pos, PrimitiveBaseShape shape)
  1187. : this(ownerID, pos, Quaternion.Identity, shape)
  1188. {
  1189. }
  1190. public void LoadScriptState(XmlDocument doc)
  1191. {
  1192. XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState");
  1193. if (nodes.Count > 0)
  1194. {
  1195. if (m_savedScriptState == null)
  1196. m_savedScriptState = new Dictionary<UUID, string>();
  1197. foreach (XmlNode node in nodes)
  1198. {
  1199. if (node.Attributes["UUID"] != null)
  1200. {
  1201. UUID itemid = new UUID(node.Attributes["UUID"].Value);
  1202. if (itemid != UUID.Zero)
  1203. m_savedScriptState[itemid] = node.InnerXml;
  1204. }
  1205. }
  1206. }
  1207. }
  1208. public void LoadScriptState(XmlReader reader)
  1209. {
  1210. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Looking for script state for {0}", Name);
  1211. while (true)
  1212. {
  1213. if (reader.Name == "SavedScriptState" && reader.NodeType == XmlNodeType.Element)
  1214. {
  1215. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Loading script state for {0}", Name);
  1216. if (m_savedScriptState == null)
  1217. m_savedScriptState = new Dictionary<UUID, string>();
  1218. string uuid = reader.GetAttribute("UUID");
  1219. // Even if there is no UUID attribute for some strange reason, we must always read the inner XML
  1220. // so we don't continually keep checking the same SavedScriptedState element.
  1221. string innerXml = reader.ReadInnerXml();
  1222. if (uuid != null)
  1223. {
  1224. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Found state for item ID {0} in object {1}", uuid, Name);
  1225. UUID itemid = new UUID(uuid);
  1226. if (itemid != UUID.Zero)
  1227. m_savedScriptState[itemid] = innerXml;
  1228. }
  1229. else
  1230. {
  1231. m_log.WarnFormat("[SCENE OBJECT GROUP]: SavedScriptState element had no UUID in object {0} id: {1}", Name,UUID);
  1232. }
  1233. }
  1234. else
  1235. {
  1236. if (!reader.Read())
  1237. break;
  1238. }
  1239. }
  1240. }
  1241. /// <summary>
  1242. /// Hooks this object up to the backup event so that it is persisted to the database when the update thread executes.
  1243. /// </summary>
  1244. public virtual void AttachToBackup()
  1245. {
  1246. if (IsAttachment) return;
  1247. m_scene.SceneGraph.FireAttachToBackup(this);
  1248. // if (InSceneBackup)
  1249. {
  1250. // m_log.DebugFormat(
  1251. // "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID);
  1252. if (!Backup)
  1253. m_scene.EventManager.OnBackup += ProcessBackup;
  1254. Backup = true;
  1255. }
  1256. }
  1257. /// <summary>
  1258. /// Attach this object to a scene. It will also now appear to agents.
  1259. /// </summary>
  1260. /// <param name="scene"></param>
  1261. public void AttachToScene(Scene scene)
  1262. {
  1263. m_scene = scene;
  1264. RegionHandle = m_scene.RegionInfo.RegionHandle;
  1265. if (m_rootPart.Shape.PCode != 9 || m_rootPart.Shape.State == 0)
  1266. m_rootPart.ParentID = 0;
  1267. if (m_rootPart.LocalId == 0)
  1268. m_rootPart.LocalId = m_scene.AllocateLocalId();
  1269. SceneObjectPart[] parts = m_parts.GetArray();
  1270. for (int i = 0; i < parts.Length; i++)
  1271. {
  1272. SceneObjectPart part = parts[i];
  1273. if (part.KeyframeMotion != null)
  1274. {
  1275. part.KeyframeMotion.UpdateSceneObject(this);
  1276. }
  1277. if (Object.ReferenceEquals(part, m_rootPart))
  1278. continue;
  1279. if (part.LocalId == 0)
  1280. part.LocalId = m_scene.AllocateLocalId();
  1281. part.ParentID = m_rootPart.LocalId;
  1282. //m_log.DebugFormat("[SCENE]: Given local id {0} to part {1}, linknum {2}, parent {3} {4}", part.LocalId, part.UUID, part.LinkNum, part.ParentID, part.ParentUUID);
  1283. }
  1284. ApplyPhysics();
  1285. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  1286. // for the same object with very different properties. The caller must schedule the update.
  1287. //ScheduleGroupForFullUpdate();
  1288. }
  1289. public EntityIntersection TestIntersection(Ray hRay, bool frontFacesOnly, bool faceCenters)
  1290. {
  1291. // We got a request from the inner_scene to raytrace along the Ray hRay
  1292. // We're going to check all of the prim in this group for intersection with the ray
  1293. // If we get a result, we're going to find the closest result to the origin of the ray
  1294. // and send back the intersection information back to the innerscene.
  1295. EntityIntersection result = new EntityIntersection();
  1296. SceneObjectPart[] parts = m_parts.GetArray();
  1297. // Find closest hit here
  1298. float idist = float.MaxValue;
  1299. for (int i = 0; i < parts.Length; i++)
  1300. {
  1301. SceneObjectPart part = parts[i];
  1302. // Temporary commented to stop compiler warning
  1303. //Vector3 partPosition =
  1304. // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
  1305. Quaternion parentrotation = GroupRotation;
  1306. // Telling the prim to raytrace.
  1307. //EntityIntersection inter = part.TestIntersection(hRay, parentrotation);
  1308. EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
  1309. if (inter.HitTF)
  1310. {
  1311. // We need to find the closest prim to return to the testcaller along the ray
  1312. if (inter.distance < idist)
  1313. {
  1314. result.HitTF = true;
  1315. result.ipoint = inter.ipoint;
  1316. result.obj = part;
  1317. result.normal = inter.normal;
  1318. result.distance = inter.distance;
  1319. idist = inter.distance;
  1320. }
  1321. }
  1322. }
  1323. return result;
  1324. }
  1325. /// <summary>
  1326. /// Gets a vector representing the size of the bounding box containing all the prims in the group
  1327. /// Treats all prims as rectangular, so no shape (cut etc) is taken into account
  1328. /// offsetHeight is the offset in the Z axis from the centre of the bounding box to the centre of the root prim
  1329. /// </summary>
  1330. /// <returns></returns>
  1331. public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ)
  1332. {
  1333. maxX = float.MinValue;
  1334. maxY = float.MinValue;
  1335. maxZ = float.MinValue;
  1336. minX = float.MaxValue;
  1337. minY = float.MaxValue;
  1338. minZ = float.MaxValue;
  1339. SceneObjectPart[] parts = m_parts.GetArray();
  1340. foreach (SceneObjectPart part in parts)
  1341. {
  1342. Vector3 worldPos = part.GetWorldPosition();
  1343. Vector3 offset = worldPos - AbsolutePosition;
  1344. Quaternion worldRot;
  1345. if (part.ParentID == 0)
  1346. {
  1347. worldRot = part.RotationOffset;
  1348. }
  1349. else
  1350. {
  1351. worldRot = part.GetWorldRotation();
  1352. }
  1353. Vector3 frontTopLeft;
  1354. Vector3 frontTopRight;
  1355. Vector3 frontBottomLeft;
  1356. Vector3 frontBottomRight;
  1357. Vector3 backTopLeft;
  1358. Vector3 backTopRight;
  1359. Vector3 backBottomLeft;
  1360. Vector3 backBottomRight;
  1361. // Vector3[] corners = new Vector3[8];
  1362. Vector3 orig = Vector3.Zero;
  1363. frontTopLeft.X = orig.X - (part.Scale.X / 2);
  1364. frontTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  1365. frontTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  1366. frontTopRight.X = orig.X - (part.Scale.X / 2);
  1367. frontTopRight.Y = orig.Y + (part.Scale.Y / 2);
  1368. frontTopRight.Z = orig.Z + (part.Scale.Z / 2);
  1369. frontBottomLeft.X = orig.X - (part.Scale.X / 2);
  1370. frontBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  1371. frontBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  1372. frontBottomRight.X = orig.X - (part.Scale.X / 2);
  1373. frontBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  1374. frontBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  1375. backTopLeft.X = orig.X + (part.Scale.X / 2);
  1376. backTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  1377. backTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  1378. backTopRight.X = orig.X + (part.Scale.X / 2);
  1379. backTopRight.Y = orig.Y + (part.Scale.Y / 2);
  1380. backTopRight.Z = orig.Z + (part.Scale.Z / 2);
  1381. backBottomLeft.X = orig.X + (part.Scale.X / 2);
  1382. backBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  1383. backBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  1384. backBottomRight.X = orig.X + (part.Scale.X / 2);
  1385. backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  1386. backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  1387. //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
  1388. //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
  1389. //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
  1390. //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
  1391. //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
  1392. //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
  1393. //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
  1394. //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
  1395. //for (int i = 0; i < 8; i++)
  1396. //{
  1397. // corners[i] = corners[i] * worldRot;
  1398. // corners[i] += offset;
  1399. // if (corners[i].X > maxX)
  1400. // maxX = corners[i].X;
  1401. // if (corners[i].X < minX)
  1402. // minX = corners[i].X;
  1403. // if (corners[i].Y > maxY)
  1404. // maxY = corners[i].Y;
  1405. // if (corners[i].Y < minY)
  1406. // minY = corners[i].Y;
  1407. // if (corners[i].Z > maxZ)
  1408. // maxZ = corners[i].Y;
  1409. // if (corners[i].Z < minZ)
  1410. // minZ = corners[i].Z;
  1411. //}
  1412. frontTopLeft = frontTopLeft * worldRot;
  1413. frontTopRight = frontTopRight * worldRot;
  1414. frontBottomLeft = frontBottomLeft * worldRot;
  1415. frontBottomRight = frontBottomRight * worldRot;
  1416. backBottomLeft = backBottomLeft * worldRot;
  1417. backBottomRight = backBottomRight * worldRot;
  1418. backTopLeft = backTopLeft * worldRot;
  1419. backTopRight = backTopRight * worldRot;
  1420. frontTopLeft += offset;
  1421. frontTopRight += offset;
  1422. frontBottomLeft += offset;
  1423. frontBottomRight += offset;
  1424. backBottomLeft += offset;
  1425. backBottomRight += offset;
  1426. backTopLeft += offset;
  1427. backTopRight += offset;
  1428. //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
  1429. //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
  1430. //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
  1431. //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
  1432. //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
  1433. //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
  1434. //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
  1435. //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
  1436. if (frontTopRight.X > maxX)
  1437. maxX = frontTopRight.X;
  1438. if (frontTopLeft.X > maxX)
  1439. maxX = frontTopLeft.X;
  1440. if (frontBottomRight.X > maxX)
  1441. maxX = frontBottomRight.X;
  1442. if (frontBottomLeft.X > maxX)
  1443. maxX = frontBottomLeft.X;
  1444. if (backTopRight.X > maxX)
  1445. maxX = backTopRight.X;
  1446. if (backTopLeft.X > maxX)
  1447. maxX = backTopLeft.X;
  1448. if (backBottomRight.X > maxX)
  1449. maxX = backBottomRight.X;
  1450. if (backBottomLeft.X > maxX)
  1451. maxX = backBottomLeft.X;
  1452. if (frontTopRight.X < minX)
  1453. minX = frontTopRight.X;
  1454. if (frontTopLeft.X < minX)
  1455. minX = frontTopLeft.X;
  1456. if (frontBottomRight.X < minX)
  1457. minX = frontBottomRight.X;
  1458. if (frontBottomLeft.X < minX)
  1459. minX = frontBottomLeft.X;
  1460. if (backTopRight.X < minX)
  1461. minX = backTopRight.X;
  1462. if (backTopLeft.X < minX)
  1463. minX = backTopLeft.X;
  1464. if (backBottomRight.X < minX)
  1465. minX = backBottomRight.X;
  1466. if (backBottomLeft.X < minX)
  1467. minX = backBottomLeft.X;
  1468. //
  1469. if (frontTopRight.Y > maxY)
  1470. maxY = frontTopRight.Y;
  1471. if (frontTopLeft.Y > maxY)
  1472. maxY = frontTopLeft.Y;
  1473. if (frontBottomRight.Y > maxY)
  1474. maxY = frontBottomRight.Y;
  1475. if (frontBottomLeft.Y > maxY)
  1476. maxY = frontBottomLeft.Y;
  1477. if (backTopRight.Y > maxY)
  1478. maxY = backTopRight.Y;
  1479. if (backTopLeft.Y > maxY)
  1480. maxY = backTopLeft.Y;
  1481. if (backBottomRight.Y > maxY)
  1482. maxY = backBottomRight.Y;
  1483. if (backBottomLeft.Y > maxY)
  1484. maxY = backBottomLeft.Y;
  1485. if (frontTopRight.Y < minY)
  1486. minY = frontTopRight.Y;
  1487. if (frontTopLeft.Y < minY)
  1488. minY = frontTopLeft.Y;
  1489. if (frontBottomRight.Y < minY)
  1490. minY = frontBottomRight.Y;
  1491. if (frontBottomLeft.Y < minY)
  1492. minY = frontBottomLeft.Y;
  1493. if (backTopRight.Y < minY)
  1494. minY = backTopRight.Y;
  1495. if (backTopLeft.Y < minY)
  1496. minY = backTopLeft.Y;
  1497. if (backBottomRight.Y < minY)
  1498. minY = backBottomRight.Y;
  1499. if (backBottomLeft.Y < minY)
  1500. minY = backBottomLeft.Y;
  1501. //
  1502. if (frontTopRight.Z > maxZ)
  1503. maxZ = frontTopRight.Z;
  1504. if (frontTopLeft.Z > maxZ)
  1505. maxZ = frontTopLeft.Z;
  1506. if (frontBottomRight.Z > maxZ)
  1507. maxZ = frontBottomRight.Z;
  1508. if (frontBottomLeft.Z > maxZ)
  1509. maxZ = frontBottomLeft.Z;
  1510. if (backTopRight.Z > maxZ)
  1511. maxZ = backTopRight.Z;
  1512. if (backTopLeft.Z > maxZ)
  1513. maxZ = backTopLeft.Z;
  1514. if (backBottomRight.Z > maxZ)
  1515. maxZ = backBottomRight.Z;
  1516. if (backBottomLeft.Z > maxZ)
  1517. maxZ = backBottomLeft.Z;
  1518. if (frontTopRight.Z < minZ)
  1519. minZ = frontTopRight.Z;
  1520. if (frontTopLeft.Z < minZ)
  1521. minZ = frontTopLeft.Z;
  1522. if (frontBottomRight.Z < minZ)
  1523. minZ = frontBottomRight.Z;
  1524. if (frontBottomLeft.Z < minZ)
  1525. minZ = frontBottomLeft.Z;
  1526. if (backTopRight.Z < minZ)
  1527. minZ = backTopRight.Z;
  1528. if (backTopLeft.Z < minZ)
  1529. minZ = backTopLeft.Z;
  1530. if (backBottomRight.Z < minZ)
  1531. minZ = backBottomRight.Z;
  1532. if (backBottomLeft.Z < minZ)
  1533. minZ = backBottomLeft.Z;
  1534. }
  1535. }
  1536. public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
  1537. {
  1538. float minX;
  1539. float maxX;
  1540. float minY;
  1541. float maxY;
  1542. float minZ;
  1543. float maxZ;
  1544. GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  1545. Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
  1546. offsetHeight = 0;
  1547. float lower = (minZ * -1);
  1548. if (lower > maxZ)
  1549. {
  1550. offsetHeight = lower - (boundingBox.Z / 2);
  1551. }
  1552. else if (maxZ > lower)
  1553. {
  1554. offsetHeight = maxZ - (boundingBox.Z / 2);
  1555. offsetHeight *= -1;
  1556. }
  1557. // m_log.InfoFormat("BoundingBox is {0} , {1} , {2} ", boundingBox.X, boundingBox.Y, boundingBox.Z);
  1558. return boundingBox;
  1559. }
  1560. #endregion
  1561. private float? m_boundsRadius = null;
  1562. public void InvalidBoundsRadius()
  1563. {
  1564. m_boundsRadius = null;
  1565. }
  1566. private Vector3 m_boundsCenter;
  1567. public Vector3 getBoundsCenter()
  1568. {
  1569. // math is done in GetBoundsRadius();
  1570. if(m_boundsRadius == null)
  1571. GetBoundsRadius();
  1572. return m_boundsCenter;
  1573. }
  1574. private float m_areaFactor;
  1575. public float getAreaFactor()
  1576. {
  1577. // math is done in GetBoundsRadius();
  1578. if(m_boundsRadius == null)
  1579. GetBoundsRadius();
  1580. return m_areaFactor;
  1581. }
  1582. public float GetBoundsRadius()
  1583. {
  1584. // this may need more threading work
  1585. if(m_boundsRadius == null)
  1586. {
  1587. float res = 0;
  1588. float areaF = 0;
  1589. SceneObjectPart p;
  1590. SceneObjectPart[] parts;
  1591. float partR;
  1592. Vector3 offset = Vector3.Zero;
  1593. lock (m_parts)
  1594. {
  1595. parts = m_parts.GetArray();
  1596. }
  1597. int nparts = parts.Length;
  1598. for (int i = 0; i < nparts; i++)
  1599. {
  1600. p = parts[i];
  1601. partR = 0.5f * p.Scale.Length();
  1602. if(p != RootPart)
  1603. {
  1604. partR += p.OffsetPosition.Length();
  1605. offset += p.OffsetPosition;
  1606. }
  1607. if(partR > res)
  1608. res = partR;
  1609. if(p.maxSimpleArea() > areaF)
  1610. areaF = p.maxSimpleArea();
  1611. }
  1612. if(parts.Length > 1)
  1613. {
  1614. offset /= parts.Length; // basicly geometric center
  1615. offset = offset * RootPart.RotationOffset;
  1616. }
  1617. areaF = 10.0f / areaF; // scale it
  1618. areaF = Util.Clamp(areaF, 0.001f, 1000f); // clamp it
  1619. m_areaFactor = (float)Math.Sqrt(areaF);
  1620. m_boundsCenter = offset;
  1621. m_boundsRadius = res;
  1622. return res;
  1623. }
  1624. return m_boundsRadius.Value;
  1625. }
  1626. public void GetResourcesCosts(SceneObjectPart apart,
  1627. out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost)
  1628. {
  1629. // this information may need to be cached
  1630. float cost;
  1631. float tmpcost;
  1632. bool ComplexCost = false;
  1633. SceneObjectPart p;
  1634. SceneObjectPart[] parts;
  1635. lock (m_parts)
  1636. {
  1637. parts = m_parts.GetArray();
  1638. }
  1639. int nparts = parts.Length;
  1640. for (int i = 0; i < nparts; i++)
  1641. {
  1642. p = parts[i];
  1643. if (p.UsesComplexCost)
  1644. {
  1645. ComplexCost = true;
  1646. break;
  1647. }
  1648. }
  1649. if (ComplexCost)
  1650. {
  1651. linksetResCost = 0;
  1652. linksetPhysCost = 0;
  1653. partCost = 0;
  1654. partPhysCost = 0;
  1655. for (int i = 0; i < nparts; i++)
  1656. {
  1657. p = parts[i];
  1658. cost = p.StreamingCost;
  1659. tmpcost = p.SimulationCost;
  1660. if (tmpcost > cost)
  1661. cost = tmpcost;
  1662. tmpcost = p.PhysicsCost;
  1663. if (tmpcost > cost)
  1664. cost = tmpcost;
  1665. linksetPhysCost += tmpcost;
  1666. linksetResCost += cost;
  1667. if (p == apart)
  1668. {
  1669. partCost = cost;
  1670. partPhysCost = tmpcost;
  1671. }
  1672. }
  1673. }
  1674. else
  1675. {
  1676. partPhysCost = 1.0f;
  1677. partCost = 1.0f;
  1678. linksetResCost = (float)nparts;
  1679. linksetPhysCost = linksetResCost;
  1680. }
  1681. }
  1682. public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost)
  1683. {
  1684. SceneObjectPart p;
  1685. SceneObjectPart[] parts;
  1686. lock (m_parts)
  1687. {
  1688. parts = m_parts.GetArray();
  1689. }
  1690. int nparts = parts.Length;
  1691. PhysCost = 0;
  1692. StreamCost = 0;
  1693. SimulCost = 0;
  1694. for (int i = 0; i < nparts; i++)
  1695. {
  1696. p = parts[i];
  1697. StreamCost += p.StreamingCost;
  1698. SimulCost += p.SimulationCost;
  1699. PhysCost += p.PhysicsCost;
  1700. }
  1701. }
  1702. public void SaveScriptedState(XmlTextWriter writer)
  1703. {
  1704. SaveScriptedState(writer, false);
  1705. }
  1706. public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
  1707. {
  1708. XmlDocument doc = new XmlDocument();
  1709. Dictionary<UUID,string> states = new Dictionary<UUID,string>();
  1710. SceneObjectPart[] parts = m_parts.GetArray();
  1711. for (int i = 0; i < parts.Length; i++)
  1712. {
  1713. Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
  1714. foreach (KeyValuePair<UUID, string> kvp in pstates)
  1715. states[kvp.Key] = kvp.Value;
  1716. }
  1717. if (states.Count > 0)
  1718. {
  1719. // Now generate the necessary XML wrappings
  1720. writer.WriteStartElement(String.Empty, "GroupScriptStates", String.Empty);
  1721. foreach (UUID itemid in states.Keys)
  1722. {
  1723. doc.LoadXml(states[itemid]);
  1724. writer.WriteStartElement(String.Empty, "SavedScriptState", String.Empty);
  1725. writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
  1726. writer.WriteRaw(doc.DocumentElement.OuterXml); // Writes ScriptState element
  1727. writer.WriteEndElement(); // End of SavedScriptState
  1728. }
  1729. writer.WriteEndElement(); // End of GroupScriptStates
  1730. }
  1731. }
  1732. public byte GetAttachmentPoint()
  1733. {
  1734. return m_rootPart.Shape.State;
  1735. }
  1736. public void DetachToGround()
  1737. {
  1738. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1739. if (avatar == null)
  1740. return;
  1741. m_rootPart.Shape.LastAttachPoint = m_rootPart.Shape.State;
  1742. m_rootPart.AttachedPos = m_rootPart.OffsetPosition;
  1743. avatar.RemoveAttachment(this);
  1744. Vector3 detachedpos = new Vector3(127f,127f,127f);
  1745. if (avatar == null)
  1746. return;
  1747. detachedpos = avatar.AbsolutePosition;
  1748. FromItemID = UUID.Zero;
  1749. AbsolutePosition = detachedpos;
  1750. AttachedAvatar = UUID.Zero;
  1751. //SceneObjectPart[] parts = m_parts.GetArray();
  1752. //for (int i = 0; i < parts.Length; i++)
  1753. // parts[i].AttachedAvatar = UUID.Zero;
  1754. m_rootPart.SetParentLocalId(0);
  1755. AttachmentPoint = (byte)0;
  1756. // must check if buildind should be true or false here
  1757. // m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false);
  1758. ApplyPhysics();
  1759. HasGroupChanged = true;
  1760. RootPart.Rezzed = DateTime.Now;
  1761. RootPart.RemFlag(PrimFlags.TemporaryOnRez);
  1762. AttachToBackup();
  1763. m_scene.EventManager.TriggerParcelPrimCountTainted();
  1764. m_rootPart.ScheduleFullUpdate();
  1765. m_rootPart.ClearUndoState();
  1766. }
  1767. public void DetachToInventoryPrep()
  1768. {
  1769. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1770. //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
  1771. if (avatar != null)
  1772. {
  1773. //detachedpos = avatar.AbsolutePosition;
  1774. avatar.RemoveAttachment(this);
  1775. }
  1776. AttachedAvatar = UUID.Zero;
  1777. /*SceneObjectPart[] parts = m_parts.GetArray();
  1778. for (int i = 0; i < parts.Length; i++)
  1779. parts[i].AttachedAvatar = UUID.Zero;*/
  1780. m_rootPart.SetParentLocalId(0);
  1781. //m_rootPart.SetAttachmentPoint((byte)0);
  1782. IsAttachment = false;
  1783. AbsolutePosition = m_rootPart.AttachedPos;
  1784. //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
  1785. //AttachToBackup();
  1786. //m_rootPart.ScheduleFullUpdate();
  1787. }
  1788. /// <summary>
  1789. ///
  1790. /// </summary>
  1791. /// <param name="part"></param>
  1792. private void SetPartAsNonRoot(SceneObjectPart part)
  1793. {
  1794. part.ParentID = m_rootPart.LocalId;
  1795. part.ClearUndoState();
  1796. }
  1797. public ushort GetTimeDilation()
  1798. {
  1799. return Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  1800. }
  1801. /// <summary>
  1802. /// Set a part to act as the root part for this scene object
  1803. /// </summary>
  1804. /// <param name="part"></param>
  1805. public void SetRootPart(SceneObjectPart part)
  1806. {
  1807. if (part == null)
  1808. throw new ArgumentNullException("Cannot give SceneObjectGroup a null root SceneObjectPart");
  1809. part.SetParent(this);
  1810. m_rootPart = part;
  1811. if (!IsAttachment)
  1812. part.ParentID = 0;
  1813. part.LinkNum = 0;
  1814. m_parts.Add(m_rootPart.UUID, m_rootPart);
  1815. }
  1816. /// <summary>
  1817. /// Add a new part to this scene object. The part must already be correctly configured.
  1818. /// </summary>
  1819. /// <param name="part"></param>
  1820. public void AddPart(SceneObjectPart part)
  1821. {
  1822. part.SetParent(this);
  1823. m_parts.Add(part.UUID, part);
  1824. part.LinkNum = m_parts.Count;
  1825. if (part.LinkNum == 2)
  1826. RootPart.LinkNum = 1;
  1827. InvalidatePartsLinkMaps();
  1828. }
  1829. /// <summary>
  1830. /// Make sure that every non root part has the proper parent root part local id
  1831. /// </summary>
  1832. private void UpdateParentIDs()
  1833. {
  1834. SceneObjectPart[] parts = m_parts.GetArray();
  1835. for (int i = 0; i < parts.Length; i++)
  1836. {
  1837. SceneObjectPart part = parts[i];
  1838. if (part.UUID != m_rootPart.UUID)
  1839. part.ParentID = m_rootPart.LocalId;
  1840. }
  1841. }
  1842. public void RegenerateFullIDs()
  1843. {
  1844. SceneObjectPart[] parts = m_parts.GetArray();
  1845. for (int i = 0; i < parts.Length; i++)
  1846. parts[i].UUID = UUID.Random();
  1847. }
  1848. // helper provided for parts.
  1849. public int GetSceneMaxUndo()
  1850. {
  1851. if (m_scene != null)
  1852. return m_scene.MaxUndoCount;
  1853. return 5;
  1854. }
  1855. // justincc: I don't believe this hack is needed any longer, especially since the physics
  1856. // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
  1857. // this method was preventing proper reload of scene objects.
  1858. // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects
  1859. // at region startup
  1860. // teravus: After this was removed from the linking algorithm, Linked prims no longer collided
  1861. // properly when non-physical if they havn't been moved. This breaks ALL builds.
  1862. // see: http://opensimulator.org/mantis/view.php?id=3108
  1863. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1864. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1865. // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute
  1866. // Position has been set!
  1867. public void ResetChildPrimPhysicsPositions()
  1868. {
  1869. // Setting this SOG's absolute position also loops through and sets the positions
  1870. // of the SOP's in this SOG's linkset. This has the side affect of making sure
  1871. // the physics world matches the simulated world.
  1872. // AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
  1873. // teravus: AbsolutePosition is NOT a normal property!
  1874. // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
  1875. // jhurliman: Then why is it a property instead of two methods?
  1876. // do only what is supposed to do
  1877. Vector3 groupPosition = m_rootPart.GroupPosition;
  1878. SceneObjectPart[] parts = m_parts.GetArray();
  1879. foreach (SceneObjectPart part in parts)
  1880. {
  1881. if (part != m_rootPart)
  1882. part.GroupPosition = groupPosition;
  1883. }
  1884. }
  1885. public UUID GetPartsFullID(uint localID)
  1886. {
  1887. SceneObjectPart part = GetPart(localID);
  1888. if (part != null)
  1889. {
  1890. return part.UUID;
  1891. }
  1892. return UUID.Zero;
  1893. }
  1894. public void ObjectGrabHandler(uint localId, Vector3 offsetPos, IClientAPI remoteClient)
  1895. {
  1896. if (m_rootPart.LocalId == localId)
  1897. {
  1898. OnGrabGroup(offsetPos, remoteClient);
  1899. }
  1900. else
  1901. {
  1902. SceneObjectPart part = GetPart(localId);
  1903. OnGrabPart(part, offsetPos, remoteClient);
  1904. }
  1905. }
  1906. public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient)
  1907. {
  1908. // m_log.DebugFormat(
  1909. // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}",
  1910. // remoteClient.Name, part.Name, part.LocalId, offsetPos);
  1911. // part.StoreUndoState();
  1912. part.OnGrab(offsetPos, remoteClient);
  1913. }
  1914. public virtual void OnGrabGroup(Vector3 offsetPos, IClientAPI remoteClient)
  1915. {
  1916. m_scene.EventManager.TriggerGroupGrab(UUID, offsetPos, remoteClient.AgentId);
  1917. }
  1918. /// <summary>
  1919. /// Delete this group from its scene.
  1920. /// </summary>
  1921. /// <remarks>
  1922. /// This only handles the in-world consequences of deletion (e.g. any avatars sitting on it are forcibly stood
  1923. /// up and all avatars receive notification of its removal. Removal of the scene object from database backup
  1924. /// must be handled by the caller.
  1925. /// </remarks>
  1926. /// <param name="silent">If true then deletion is not broadcast to clients</param>
  1927. public void DeleteGroupFromScene(bool silent)
  1928. {
  1929. // We need to keep track of this state in case this group is still queued for backup.
  1930. IsDeleted = true;
  1931. DetachFromBackup();
  1932. if(Scene == null) // should not happen unless restart/shutdown ?
  1933. return;
  1934. SceneObjectPart[] parts = m_parts.GetArray();
  1935. for (int i = 0; i < parts.Length; i++)
  1936. {
  1937. SceneObjectPart part = parts[i];
  1938. Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1939. {
  1940. if (!avatar.IsChildAgent && avatar.ParentID == part.LocalId && avatar.ParentUUID == UUID.Zero)
  1941. avatar.StandUp();
  1942. if (!silent)
  1943. {
  1944. part.ClearUpdateSchedule();
  1945. if (part == m_rootPart)
  1946. {
  1947. if (!IsAttachment
  1948. || AttachedAvatar == avatar.ControllingClient.AgentId
  1949. || !HasPrivateAttachmentPoint)
  1950. {
  1951. // Send a kill object immediately
  1952. avatar.ControllingClient.SendKillObject(new List<uint> { part.LocalId });
  1953. //direct enqueue another delayed kill
  1954. avatar.ControllingClient.SendEntityUpdate(part,PrimUpdateFlags.Kill);
  1955. }
  1956. }
  1957. }
  1958. });
  1959. }
  1960. }
  1961. public void AddScriptLPS(int count)
  1962. {
  1963. m_scene.SceneGraph.AddToScriptLPS(count);
  1964. }
  1965. public void AddActiveScriptCount(int count)
  1966. {
  1967. SceneGraph d = m_scene.SceneGraph;
  1968. d.AddActiveScripts(count);
  1969. }
  1970. private const scriptEvents PhysicsNeeedSubsEvents = (
  1971. scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
  1972. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end);
  1973. private scriptEvents lastRootPartPhysEvents = 0;
  1974. public void aggregateScriptEvents()
  1975. {
  1976. PrimFlags objectflagupdate = (PrimFlags)RootPart.GetEffectiveObjectFlags();
  1977. scriptEvents aggregateScriptEvents = 0;
  1978. SceneObjectPart[] parts = m_parts.GetArray();
  1979. for (int i = 0; i < parts.Length; i++)
  1980. {
  1981. SceneObjectPart part = parts[i];
  1982. if (part == null)
  1983. continue;
  1984. if (part != RootPart)
  1985. part.Flags = objectflagupdate;
  1986. aggregateScriptEvents |= part.AggregateScriptEvents;
  1987. }
  1988. m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
  1989. m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
  1990. if (!m_scriptListens_atTarget && !m_scriptListens_notAtTarget)
  1991. {
  1992. lock (m_targets)
  1993. m_targets.Clear();
  1994. m_scene.RemoveGroupTarget(this);
  1995. }
  1996. m_scriptListens_atRotTarget = ((aggregateScriptEvents & scriptEvents.at_rot_target) != 0);
  1997. m_scriptListens_notAtRotTarget = ((aggregateScriptEvents & scriptEvents.not_at_rot_target) != 0);
  1998. if (!m_scriptListens_atRotTarget && !m_scriptListens_notAtRotTarget)
  1999. {
  2000. lock (m_rotTargets)
  2001. m_rotTargets.Clear();
  2002. m_scene.RemoveGroupTarget(this);
  2003. }
  2004. scriptEvents rootPartPhysEvents = RootPart.AggregateScriptEvents;
  2005. rootPartPhysEvents &= PhysicsNeeedSubsEvents;
  2006. if (rootPartPhysEvents != lastRootPartPhysEvents)
  2007. {
  2008. lastRootPartPhysEvents = rootPartPhysEvents;
  2009. for (int i = 0; i < parts.Length; i++)
  2010. {
  2011. SceneObjectPart part = parts[i];
  2012. if (part == null)
  2013. continue;
  2014. part.UpdatePhysicsSubscribedEvents();
  2015. }
  2016. }
  2017. ScheduleGroupForFullUpdate();
  2018. }
  2019. public void SetText(string text, Vector3 color, double alpha)
  2020. {
  2021. Color = Color.FromArgb(0xff - (int) (alpha * 0xff),
  2022. (int) (color.X * 0xff),
  2023. (int) (color.Y * 0xff),
  2024. (int) (color.Z * 0xff));
  2025. Text = text;
  2026. HasGroupChanged = true;
  2027. m_rootPart.ScheduleFullUpdate();
  2028. }
  2029. /// <summary>
  2030. /// Apply physics to this group
  2031. /// </summary>
  2032. public void ApplyPhysics()
  2033. {
  2034. SceneObjectPart[] parts = m_parts.GetArray();
  2035. if (parts.Length > 1)
  2036. {
  2037. ResetChildPrimPhysicsPositions();
  2038. // Apply physics to the root prim
  2039. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true);
  2040. for (int i = 0; i < parts.Length; i++)
  2041. {
  2042. SceneObjectPart part = parts[i];
  2043. if (part.LocalId != m_rootPart.LocalId)
  2044. part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true);
  2045. }
  2046. // Hack to get the physics scene geometries in the right spot
  2047. // ResetChildPrimPhysicsPositions();
  2048. if (m_rootPart.PhysActor != null)
  2049. m_rootPart.PhysActor.Building = false;
  2050. }
  2051. else
  2052. {
  2053. // Apply physics to the root prim
  2054. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false);
  2055. }
  2056. }
  2057. public void SetOwnerId(UUID userId)
  2058. {
  2059. ForEachPart(delegate(SceneObjectPart part)
  2060. {
  2061. if (part.OwnerID != userId)
  2062. {
  2063. if(part.GroupID != part.OwnerID)
  2064. part.LastOwnerID = part.OwnerID;
  2065. part.OwnerID = userId;
  2066. }
  2067. });
  2068. }
  2069. public void ForEachPart(Action<SceneObjectPart> whatToDo)
  2070. {
  2071. SceneObjectPart[] parts = m_parts.GetArray();
  2072. for (int i = 0; i < parts.Length; i++)
  2073. whatToDo(parts[i]);
  2074. }
  2075. #region Events
  2076. /// <summary>
  2077. /// Processes backup.
  2078. /// </summary>
  2079. /// <param name="datastore"></param>
  2080. public virtual void ProcessBackup(ISimulationDataService datastore, bool forcedBackup)
  2081. {
  2082. if (!Backup)
  2083. {
  2084. // m_log.DebugFormat(
  2085. // "[WATER WARS]: Ignoring backup of {0} {1} since object is not marked to be backed up", Name, UUID);
  2086. return;
  2087. }
  2088. if (IsDeleted || inTransit || UUID == UUID.Zero)
  2089. {
  2090. // m_log.DebugFormat(
  2091. // "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID);
  2092. return;
  2093. }
  2094. if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2095. return;
  2096. // Since this is the top of the section of call stack for backing up a particular scene object, don't let
  2097. // any exception propogate upwards.
  2098. try
  2099. {
  2100. // if shutting down then there will be nothing to handle the return so leave till next restart
  2101. if (!m_scene.ShuttingDown &&
  2102. m_scene.LoginsEnabled && // We're starting up or doing maintenance, don't mess with things
  2103. !m_scene.LoadingPrims) // Land may not be valid yet
  2104. {
  2105. ILandObject parcel = m_scene.LandChannel.GetLandObject(
  2106. m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
  2107. if (parcel != null && parcel.LandData != null &&
  2108. parcel.LandData.OtherCleanTime != 0)
  2109. {
  2110. if (parcel.LandData.OwnerID != OwnerID &&
  2111. (parcel.LandData.GroupID != GroupID ||
  2112. parcel.LandData.GroupID == UUID.Zero))
  2113. {
  2114. if ((DateTime.UtcNow - RootPart.Rezzed).TotalMinutes >
  2115. parcel.LandData.OtherCleanTime)
  2116. {
  2117. // don't autoreturn if we have a sitting avatar
  2118. // mantis 7828 (but none the provided patchs)
  2119. if(GetSittingAvatarsCount() > 0)
  2120. {
  2121. // do not respect npcs
  2122. List<ScenePresence> sitters = GetSittingAvatars();
  2123. foreach(ScenePresence sp in sitters)
  2124. {
  2125. if(!sp.IsDeleted && !sp.IsNPC && sp.IsSatOnObject)
  2126. return;
  2127. }
  2128. }
  2129. DetachFromBackup();
  2130. m_log.DebugFormat(
  2131. "[SCENE OBJECT GROUP]: Returning object {0} due to parcel autoreturn",
  2132. RootPart.UUID);
  2133. m_scene.AddReturn(OwnerID == GroupID ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn");
  2134. m_scene.DeRezObjects(null, new List<uint>() { RootPart.LocalId }, UUID.Zero,
  2135. DeRezAction.Return, UUID.Zero, false);
  2136. return;
  2137. }
  2138. }
  2139. }
  2140. }
  2141. if (m_scene.UseBackup && HasGroupChanged)
  2142. {
  2143. // don't backup while it's selected or you're asking for changes mid stream.
  2144. if (isTimeToPersist() || forcedBackup)
  2145. {
  2146. if (m_rootPart.PhysActor != null &&
  2147. (!m_rootPart.PhysActor.IsPhysical))
  2148. {
  2149. // Possible ghost prim
  2150. if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
  2151. {
  2152. foreach (SceneObjectPart part in m_parts.GetArray())
  2153. {
  2154. // Re-set physics actor positions and
  2155. // orientations
  2156. part.GroupPosition = m_rootPart.GroupPosition;
  2157. }
  2158. }
  2159. }
  2160. // m_log.DebugFormat(
  2161. // "[SCENE]: Storing {0}, {1} in {2}",
  2162. // Name, UUID, m_scene.RegionInfo.RegionName);
  2163. if (RootPart.Shape.PCode == 9 && RootPart.Shape.State != 0)
  2164. {
  2165. RootPart.Shape.LastAttachPoint = RootPart.Shape.State;
  2166. RootPart.Shape.State = 0;
  2167. ScheduleGroupForFullUpdate();
  2168. }
  2169. SceneObjectGroup backup_group = Copy(false);
  2170. backup_group.RootPart.Velocity = RootPart.Velocity;
  2171. backup_group.RootPart.Acceleration = RootPart.Acceleration;
  2172. backup_group.RootPart.AngularVelocity = RootPart.AngularVelocity;
  2173. backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
  2174. HasGroupChanged = false;
  2175. GroupContainsForeignPrims = false;
  2176. m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
  2177. datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
  2178. backup_group.ForEachPart(delegate(SceneObjectPart part)
  2179. {
  2180. part.Inventory.ProcessInventoryBackup(datastore);
  2181. if(part.KeyframeMotion != null)
  2182. {
  2183. part.KeyframeMotion.Delete();
  2184. part.KeyframeMotion = null;
  2185. }
  2186. });
  2187. backup_group.Clear();
  2188. backup_group = null;
  2189. }
  2190. // else
  2191. // {
  2192. // m_log.DebugFormat(
  2193. // "[SCENE]: Did not update persistence of object {0} {1}, selected = {2}",
  2194. // Name, UUID, IsSelected);
  2195. // }
  2196. }
  2197. }
  2198. catch (Exception e)
  2199. {
  2200. m_log.ErrorFormat(
  2201. "[SCENE]: Storing of {0}, {1} in {2} failed with exception {3}{4}",
  2202. Name, UUID, m_scene.RegionInfo.RegionName, e.Message, e.StackTrace);
  2203. }
  2204. }
  2205. #endregion
  2206. /// <summary>
  2207. /// Send the parts of this SOG to a single client
  2208. /// </summary>
  2209. /// <remarks>
  2210. /// Used when the client initially connects and when client sends RequestPrim packet
  2211. /// </remarks>
  2212. /// <param name="remoteClient"></param>
  2213. public void SendFullUpdateToClient(IClientAPI remoteClient)
  2214. {
  2215. RootPart.SendFullUpdate(remoteClient);
  2216. SceneObjectPart[] parts = m_parts.GetArray();
  2217. for (int i = 0; i < parts.Length; i++)
  2218. {
  2219. SceneObjectPart part = parts[i];
  2220. if (part != RootPart)
  2221. part.SendFullUpdate(remoteClient);
  2222. }
  2223. }
  2224. #region Copying
  2225. /// <summary>
  2226. /// Duplicates this object, including operations such as physics set up and attaching to the backup event.
  2227. /// </summary>
  2228. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  2229. /// <returns></returns>
  2230. public SceneObjectGroup Copy(bool userExposed)
  2231. {
  2232. m_dupeInProgress = true;
  2233. SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone();
  2234. dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
  2235. // a copy isnt backedup
  2236. dupe.Backup = false;
  2237. dupe.InvalidBoundsRadius();
  2238. // a copy is not in transit hopefully
  2239. dupe.inTransit = false;
  2240. // new group as no sitting avatars
  2241. dupe.m_sittingAvatars = new List<ScenePresence>();
  2242. dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
  2243. dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
  2244. if (userExposed)
  2245. dupe.m_rootPart.TrimPermissions();
  2246. List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
  2247. partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
  2248. {
  2249. return p1.LinkNum.CompareTo(p2.LinkNum);
  2250. }
  2251. );
  2252. foreach (SceneObjectPart part in partList)
  2253. {
  2254. SceneObjectPart newPart;
  2255. if (part.UUID != m_rootPart.UUID)
  2256. {
  2257. newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed);
  2258. newPart.LinkNum = part.LinkNum;
  2259. // if (userExposed)
  2260. newPart.ParentID = dupe.m_rootPart.LocalId;
  2261. }
  2262. else
  2263. {
  2264. newPart = dupe.m_rootPart;
  2265. }
  2266. /*
  2267. bool isphys = ((newPart.Flags & PrimFlags.Physics) != 0);
  2268. bool isphan = ((newPart.Flags & PrimFlags.Phantom) != 0);
  2269. // Need to duplicate the physics actor as well
  2270. if (userExposed && (isphys || !isphan || newPart.VolumeDetectActive))
  2271. {
  2272. PrimitiveBaseShape pbs = newPart.Shape;
  2273. newPart.PhysActor
  2274. = m_scene.PhysicsScene.AddPrimShape(
  2275. string.Format("{0}/{1}", newPart.Name, newPart.UUID),
  2276. pbs,
  2277. newPart.AbsolutePosition,
  2278. newPart.Scale,
  2279. newPart.GetWorldRotation(),
  2280. isphys,
  2281. isphan,
  2282. newPart.LocalId);
  2283. newPart.DoPhysicsPropertyUpdate(isphys, true);
  2284. */
  2285. if (userExposed)
  2286. newPart.ApplyPhysics((uint)newPart.Flags,newPart.VolumeDetectActive,true);
  2287. // }
  2288. // copy keyframemotion
  2289. if (part.KeyframeMotion != null)
  2290. newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe);
  2291. }
  2292. if (userExposed)
  2293. {
  2294. // done above dupe.UpdateParentIDs();
  2295. if (dupe.m_rootPart.PhysActor != null)
  2296. dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building
  2297. dupe.InvalidateDeepEffectivePerms();
  2298. dupe.HasGroupChanged = true;
  2299. dupe.AttachToBackup();
  2300. dupe.ScheduleGroupForFullUpdate();
  2301. }
  2302. dupe.InvalidatePartsLinkMaps();
  2303. m_dupeInProgress = false;
  2304. return dupe;
  2305. }
  2306. /// <summary>
  2307. /// Copy the given part as the root part of this scene object.
  2308. /// </summary>
  2309. /// <param name="part"></param>
  2310. /// <param name="cAgentID"></param>
  2311. /// <param name="cGroupID"></param>
  2312. public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2313. {
  2314. SceneObjectPart newpart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed);
  2315. // SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed);
  2316. // newpart.LocalId = m_scene.AllocateLocalId();
  2317. SetRootPart(newpart);
  2318. if (userExposed)
  2319. RootPart.Velocity = Vector3.Zero; // In case source is moving
  2320. }
  2321. public void ScriptSetPhysicsStatus(bool usePhysics)
  2322. {
  2323. if (usePhysics)
  2324. {
  2325. if (RootPart.KeyframeMotion != null)
  2326. RootPart.KeyframeMotion.Stop();
  2327. RootPart.KeyframeMotion = null;
  2328. }
  2329. UpdateFlags(usePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
  2330. }
  2331. public void ScriptSetTemporaryStatus(bool makeTemporary)
  2332. {
  2333. UpdateFlags(UsesPhysics, makeTemporary, IsPhantom, IsVolumeDetect);
  2334. }
  2335. public void ScriptSetPhantomStatus(bool makePhantom)
  2336. {
  2337. UpdateFlags(UsesPhysics, IsTemporary, makePhantom, IsVolumeDetect);
  2338. }
  2339. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  2340. {
  2341. UpdateFlags(UsesPhysics, IsTemporary, IsPhantom, makeVolumeDetect);
  2342. }
  2343. public void applyImpulse(Vector3 impulse)
  2344. {
  2345. if (IsAttachment)
  2346. {
  2347. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2348. if (avatar != null)
  2349. {
  2350. avatar.PushForce(impulse);
  2351. }
  2352. }
  2353. else
  2354. {
  2355. PhysicsActor pa = RootPart.PhysActor;
  2356. if (pa != null)
  2357. {
  2358. // false to be applied as a impulse
  2359. pa.AddForce(impulse, false);
  2360. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2361. }
  2362. }
  2363. }
  2364. public void ApplyAngularImpulse(Vector3 impulse)
  2365. {
  2366. PhysicsActor pa = RootPart.PhysActor;
  2367. if (pa != null)
  2368. {
  2369. if (!IsAttachment)
  2370. {
  2371. // false to be applied as a impulse
  2372. pa.AddAngularForce(impulse, false);
  2373. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2374. }
  2375. }
  2376. }
  2377. public Vector3 GetTorque()
  2378. {
  2379. return RootPart.Torque;
  2380. }
  2381. // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object
  2382. public void MoveToTarget(Vector3 target, float tau)
  2383. {
  2384. if (IsAttachment)
  2385. {
  2386. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2387. if (avatar != null && !avatar.IsSatOnObject)
  2388. avatar.MoveToTarget(target, false, false, tau);
  2389. }
  2390. else
  2391. {
  2392. PhysicsActor pa = RootPart.PhysActor;
  2393. if (pa != null)
  2394. {
  2395. pa.PIDTarget = target;
  2396. pa.PIDTau = tau;
  2397. pa.PIDActive = true;
  2398. }
  2399. }
  2400. }
  2401. public void StopMoveToTarget()
  2402. {
  2403. if (IsAttachment)
  2404. {
  2405. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2406. if (avatar != null)
  2407. {
  2408. avatar.ResetMoveToTarget();
  2409. }
  2410. }
  2411. else
  2412. {
  2413. PhysicsActor pa = RootPart.PhysActor;
  2414. if (pa != null)
  2415. pa.PIDActive = false;
  2416. RootPart.ScheduleTerseUpdate(); // send a stop information
  2417. }
  2418. }
  2419. public void RotLookAt(Quaternion target, float strength, float damping)
  2420. {
  2421. if(IsDeleted)
  2422. return;
  2423. // non physical is handle in LSL api
  2424. if(!UsesPhysics || IsAttachment)
  2425. return;
  2426. SceneObjectPart rootpart = m_rootPart;
  2427. if (rootpart != null)
  2428. {
  2429. /* physics still doesnt suport this
  2430. if (rootpart.PhysActor != null)
  2431. {
  2432. rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
  2433. rootpart.PhysActor.APIDStrength = strength;
  2434. rootpart.PhysActor.APIDDamping = damping;
  2435. rootpart.PhysActor.APIDActive = true;
  2436. }
  2437. */
  2438. // so do it in rootpart
  2439. rootpart.RotLookAt(target, strength, damping);
  2440. }
  2441. }
  2442. public void StartLookAt(Quaternion target, float strength, float damping)
  2443. {
  2444. if(IsDeleted)
  2445. return;
  2446. // non physical is done by LSL APi
  2447. if(!UsesPhysics || IsAttachment)
  2448. return;
  2449. if (m_rootPart != null)
  2450. m_rootPart.RotLookAt(target, strength, damping);
  2451. }
  2452. public void StopLookAt()
  2453. {
  2454. SceneObjectPart rootpart = m_rootPart;
  2455. if (rootpart != null)
  2456. {
  2457. if (rootpart.PhysActor != null)
  2458. {
  2459. rootpart.PhysActor.APIDActive = false;
  2460. }
  2461. rootpart.StopLookAt();
  2462. }
  2463. }
  2464. /// <summary>
  2465. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2466. /// </summary>
  2467. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2468. /// <param name="hoverType">Determines what the height is relative to </param>
  2469. /// <param name="tau">Number of seconds over which to reach target</param>
  2470. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2471. {
  2472. PhysicsActor pa = null;
  2473. if(IsAttachment)
  2474. {
  2475. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2476. if (avatar != null)
  2477. pa = avatar.PhysicsActor;
  2478. }
  2479. else
  2480. pa = RootPart.PhysActor;
  2481. if (pa != null)
  2482. {
  2483. if (height != 0f)
  2484. {
  2485. pa.PIDHoverHeight = height;
  2486. pa.PIDHoverType = hoverType;
  2487. pa.PIDHoverTau = tau;
  2488. pa.PIDHoverActive = true;
  2489. }
  2490. else
  2491. {
  2492. pa.PIDHoverActive = false;
  2493. }
  2494. }
  2495. }
  2496. /// <summary>
  2497. /// Set the owner of all linkset.
  2498. /// </summary>
  2499. /// <param name="cAgentID"></param>
  2500. /// <param name="cGroupID"></param>
  2501. public void SetOwner(UUID cAgentID, UUID cGroupID)
  2502. {
  2503. SceneObjectPart rpart = RootPart;
  2504. UUID oldowner = rpart.OwnerID;
  2505. ForEachPart(delegate(SceneObjectPart part)
  2506. {
  2507. if(part.GroupID != part.OwnerID)
  2508. part.LastOwnerID = part.OwnerID;
  2509. part.OwnerID = cAgentID;
  2510. part.GroupID = cGroupID;
  2511. });
  2512. if (oldowner != cAgentID)
  2513. {
  2514. // Apply Next Owner Permissions if we're not bypassing permissions
  2515. if (!m_scene.Permissions.BypassPermissions())
  2516. {
  2517. ApplyNextOwnerPermissions();
  2518. InvalidateEffectivePerms();
  2519. }
  2520. }
  2521. rpart.ScheduleFullUpdate();
  2522. }
  2523. /// <summary>
  2524. /// Make a copy of the given part.
  2525. /// </summary>
  2526. /// <param name="part"></param>
  2527. /// <param name="cAgentID"></param>
  2528. /// <param name="cGroupID"></param>
  2529. public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2530. {
  2531. SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
  2532. // SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed);
  2533. // newPart.LocalId = m_scene.AllocateLocalId();
  2534. AddPart(newPart);
  2535. SetPartAsNonRoot(newPart);
  2536. return newPart;
  2537. }
  2538. /// <summary>
  2539. /// Reset the UUIDs for all the prims that make up this group.
  2540. /// </summary>
  2541. /// <remarks>
  2542. /// This is called by methods which want to add a new group to an existing scene, in order
  2543. /// to ensure that there are no clashes with groups already present.
  2544. /// </remarks>
  2545. public void ResetIDs()
  2546. {
  2547. lock (m_parts.SyncRoot)
  2548. {
  2549. List<SceneObjectPart> partsList = new List<SceneObjectPart>(m_parts.GetArray());
  2550. m_parts.Clear();
  2551. foreach (SceneObjectPart part in partsList)
  2552. {
  2553. part.ResetIDs(part.LinkNum); // Don't change link nums
  2554. m_parts.Add(part.UUID, part);
  2555. }
  2556. }
  2557. }
  2558. /// <summary>
  2559. ///
  2560. /// </summary>
  2561. /// <param name="part"></param>
  2562. public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags)
  2563. {
  2564. remoteClient.SendObjectPropertiesFamilyData(RootPart, RequestFlags);
  2565. // remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask,
  2566. // RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask,
  2567. // RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category,
  2568. // RootPart.CreatorID, RootPart.Name, RootPart.Description);
  2569. }
  2570. public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  2571. {
  2572. part.OwnerID = cAgentID;
  2573. part.GroupID = cGroupID;
  2574. }
  2575. #endregion
  2576. public override void Update()
  2577. {
  2578. // Check that the group was not deleted before the scheduled update
  2579. // FIXME: This is merely a temporary measure to reduce the incidence of failure when
  2580. // an object has been deleted from a scene before update was processed.
  2581. // A more fundamental overhaul of the update mechanism is required to eliminate all
  2582. // the race conditions.
  2583. if (IsDeleted || inTransit)
  2584. return;
  2585. // Even temporary objects take part in physics (e.g. temp-on-rez bullets)
  2586. //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2587. // return;
  2588. // If we somehow got here to updating the SOG and its root part is not scheduled for update,
  2589. // check to see if the physical position or rotation warrant an update.
  2590. /*
  2591. if (m_rootPart.UpdateFlag == UpdateRequired.NONE)
  2592. {
  2593. // rootpart SendScheduledUpdates will check if a update is needed
  2594. m_rootPart.UpdateFlag = UpdateRequired.TERSE;
  2595. }
  2596. */
  2597. if (IsAttachment)
  2598. {
  2599. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2600. if (sp != null)
  2601. {
  2602. sp.SendAttachmentScheduleUpdate(this);
  2603. return;
  2604. }
  2605. }
  2606. // while physics doesn't suports LookAt, we do it in RootPart
  2607. if (!IsSelected)
  2608. RootPart.UpdateLookAt();
  2609. double now = Util.GetTimeStampMS();
  2610. RootPart.SendScheduledUpdates(now);
  2611. SceneObjectPart[] parts = m_parts.GetArray();
  2612. for (int i = 0; i < parts.Length; i++)
  2613. {
  2614. SceneObjectPart part = parts[i];
  2615. if(part != RootPart)
  2616. part.SendScheduledUpdates(now);
  2617. }
  2618. }
  2619. /// <summary>
  2620. /// Schedule a full update for this scene object to all interested viewers.
  2621. /// </summary>
  2622. /// <remarks>
  2623. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2624. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2625. /// code will set this anyway when some object properties are changed.
  2626. /// </remarks>
  2627. public void ScheduleGroupForFullUpdate()
  2628. {
  2629. // if (IsAttachment)
  2630. // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
  2631. checkAtTargets();
  2632. RootPart.ScheduleFullUpdate();
  2633. SceneObjectPart[] parts = m_parts.GetArray();
  2634. for (int i = 0; i < parts.Length; i++)
  2635. {
  2636. SceneObjectPart part = parts[i];
  2637. if (part != RootPart)
  2638. part.ScheduleFullUpdate();
  2639. }
  2640. }
  2641. /// <summary>
  2642. /// Schedule a terse update for this scene object to all interested viewers.
  2643. /// </summary>
  2644. /// <remarks>
  2645. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2646. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2647. /// code will set this anyway when some object properties are changed.
  2648. /// </remarks>
  2649. public void ScheduleGroupForTerseUpdate()
  2650. {
  2651. // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID);
  2652. SceneObjectPart[] parts = m_parts.GetArray();
  2653. for (int i = 0; i < parts.Length; i++)
  2654. parts[i].ScheduleTerseUpdate();
  2655. }
  2656. /// <summary>
  2657. /// Immediately send a full update for this scene object.
  2658. /// </summary>
  2659. public void SendGroupFullUpdate()
  2660. {
  2661. if (IsDeleted)
  2662. return;
  2663. // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
  2664. if (IsAttachment)
  2665. {
  2666. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2667. if (sp != null)
  2668. {
  2669. sp.SendAttachmentUpdate(this,UpdateRequired.FULL);
  2670. return;
  2671. }
  2672. }
  2673. RootPart.SendFullUpdateToAllClientsInternal();
  2674. SceneObjectPart[] parts = m_parts.GetArray();
  2675. for (int i = 0; i < parts.Length; i++)
  2676. {
  2677. SceneObjectPart part = parts[i];
  2678. if (part != RootPart)
  2679. part.SendFullUpdateToAllClientsInternal();
  2680. }
  2681. }
  2682. /// <summary>
  2683. /// Immediately send an update for this scene object's root prim only.
  2684. /// This is for updates regarding the object as a whole, and none of its parts in particular.
  2685. /// Note: this may not be used by opensim (it probably should) but it's used by
  2686. /// external modules.
  2687. /// </summary>
  2688. public void SendGroupRootTerseUpdate()
  2689. {
  2690. if (IsDeleted || inTransit)
  2691. return;
  2692. RootPart.SendTerseUpdateToAllClients();
  2693. }
  2694. public void QueueForUpdateCheck()
  2695. {
  2696. if (m_scene == null) // Need to check here as it's null during object creation
  2697. return;
  2698. m_scene.SceneGraph.AddToUpdateList(this);
  2699. }
  2700. /// <summary>
  2701. /// Immediately send a terse update for this scene object.
  2702. /// </summary>
  2703. public void SendGroupTerseUpdate()
  2704. {
  2705. if (IsDeleted || inTransit)
  2706. return;
  2707. if (IsAttachment)
  2708. {
  2709. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2710. if (sp != null)
  2711. {
  2712. sp.SendAttachmentUpdate(this, UpdateRequired.TERSE);
  2713. return;
  2714. }
  2715. }
  2716. SceneObjectPart[] parts = m_parts.GetArray();
  2717. for (int i = 0; i < parts.Length; i++)
  2718. parts[i].SendTerseUpdateToAllClientsInternal();
  2719. }
  2720. /// <summary>
  2721. /// Send metadata about the root prim (name, description, sale price, permissions, etc.) to a client.
  2722. /// </summary>
  2723. /// <param name="client"></param>
  2724. public void SendPropertiesToClient(IClientAPI client)
  2725. {
  2726. m_rootPart.SendPropertiesToClient(client);
  2727. }
  2728. #region SceneGroupPart Methods
  2729. /// <summary>
  2730. /// Get the child part by LinkNum
  2731. /// </summary>
  2732. /// <param name="linknum"></param>
  2733. /// <returns>null if no child part with that linknum or child part</returns>
  2734. public SceneObjectPart GetLinkNumPart(int linknum)
  2735. {
  2736. SceneObjectPart[] parts = m_parts.GetArray();
  2737. for (int i = 0; i < parts.Length; i++)
  2738. {
  2739. if (parts[i].LinkNum == linknum)
  2740. return parts[i];
  2741. }
  2742. return null;
  2743. }
  2744. /// <summary>
  2745. /// Get a part with a given UUID
  2746. /// </summary>
  2747. /// <param name="primID"></param>
  2748. /// <returns>null if a part with the primID was not found</returns>
  2749. public SceneObjectPart GetPart(UUID primID)
  2750. {
  2751. SceneObjectPart childPart;
  2752. m_parts.TryGetValue(primID, out childPart);
  2753. return childPart;
  2754. }
  2755. /// <summary>
  2756. /// Get a part with a given local ID
  2757. /// </summary>
  2758. /// <param name="localID"></param>
  2759. /// <returns>null if a part with the local ID was not found</returns>
  2760. public SceneObjectPart GetPart(uint localID)
  2761. {
  2762. SceneObjectPart[] parts = m_parts.GetArray();
  2763. for (int i = 0; i < parts.Length; i++)
  2764. {
  2765. if (parts[i].LocalId == localID)
  2766. return parts[i];
  2767. }
  2768. return null;
  2769. }
  2770. #endregion
  2771. #region Packet Handlers
  2772. /// <summary>
  2773. /// Link the prims in a given group to this group
  2774. /// </summary>
  2775. /// <remarks>
  2776. /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads.
  2777. /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition.
  2778. /// </remarks>
  2779. /// <param name="objectGroup">The group of prims which should be linked to this group</param>
  2780. public void LinkToGroup(SceneObjectGroup objectGroup)
  2781. {
  2782. LinkToGroup(objectGroup, false);
  2783. }
  2784. // Link an existing group to this group.
  2785. // The group being linked need not be a linkset -- it can have just one prim.
  2786. public void LinkToGroup(SceneObjectGroup objectGroup, bool insert)
  2787. {
  2788. // m_log.DebugFormat(
  2789. // "[SCENE OBJECT GROUP]: Linking group with root part {0}, {1} to group with root part {2}, {3}",
  2790. // objectGroup.RootPart.Name, objectGroup.RootPart.UUID, RootPart.Name, RootPart.UUID);
  2791. // Linking to ourselves is not a valid operation.
  2792. if (objectGroup == this)
  2793. return;
  2794. // If the configured linkset capacity is greater than zero,
  2795. // and the new linkset would have a prim count higher than this
  2796. // value, do not link it.
  2797. if (m_scene.m_linksetCapacity > 0 &&
  2798. (PrimCount + objectGroup.PrimCount) >
  2799. m_scene.m_linksetCapacity)
  2800. {
  2801. m_log.DebugFormat(
  2802. "[SCENE OBJECT GROUP]: Cannot link group with root" +
  2803. " part {0}, {1} ({2} prims) to group with root part" +
  2804. " {3}, {4} ({5} prims) because the new linkset" +
  2805. " would exceed the configured maximum of {6}",
  2806. objectGroup.RootPart.Name, objectGroup.RootPart.UUID,
  2807. objectGroup.PrimCount, RootPart.Name, RootPart.UUID,
  2808. PrimCount, m_scene.m_linksetCapacity);
  2809. return;
  2810. }
  2811. // physical prims count limit
  2812. // not very eficient :(
  2813. if (UsesPhysics && m_scene.m_linksetPhysCapacity > 0 && (PrimCount + objectGroup.PrimCount) >
  2814. m_scene.m_linksetPhysCapacity)
  2815. {
  2816. int cntr = 0;
  2817. foreach (SceneObjectPart part in Parts)
  2818. {
  2819. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2820. cntr++;
  2821. }
  2822. foreach (SceneObjectPart part in objectGroup.Parts)
  2823. {
  2824. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2825. cntr++;
  2826. }
  2827. if (cntr > m_scene.m_linksetPhysCapacity)
  2828. {
  2829. // cancel physics
  2830. RootPart.Flags &= ~PrimFlags.Physics;
  2831. ApplyPhysics();
  2832. }
  2833. }
  2834. // 'linkPart' == the root of the group being linked into this group
  2835. SceneObjectPart linkPart = objectGroup.m_rootPart;
  2836. if (m_rootPart.PhysActor != null)
  2837. m_rootPart.PhysActor.Building = true;
  2838. if (linkPart.PhysActor != null)
  2839. linkPart.PhysActor.Building = true;
  2840. // physics flags from group to be applied to linked parts
  2841. bool grpusephys = UsesPhysics;
  2842. bool grptemporary = IsTemporary;
  2843. // Remember where the group being linked thought it was
  2844. Vector3 oldGroupPosition = linkPart.GroupPosition;
  2845. Quaternion oldRootRotation = linkPart.RotationOffset;
  2846. // A linked SOP remembers its location and rotation relative to the root of a group.
  2847. // Convert the root of the group being linked to be relative to the
  2848. // root of the group being linked to.
  2849. // Note: Some of the assignments have complex side effects.
  2850. // First move the new group's root SOP's position to be relative to ours
  2851. // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not,
  2852. // this code can be reordered to have a more logical flow.)
  2853. linkPart.setOffsetPosition(linkPart.GroupPosition - AbsolutePosition);
  2854. // Assign the new parent to the root of the old group
  2855. linkPart.ParentID = m_rootPart.LocalId;
  2856. // Now that it's a child, it's group position is our root position
  2857. linkPart.setGroupPosition(AbsolutePosition);
  2858. // Rotate the linking root SOP's position to be relative to the new root prim
  2859. Quaternion parentRot = m_rootPart.RotationOffset;
  2860. // Make the linking root SOP's rotation relative to the new root prim
  2861. Quaternion oldRot = linkPart.RotationOffset;
  2862. Quaternion newRot = Quaternion.Conjugate(parentRot) * oldRot;
  2863. linkPart.setRotationOffset(newRot);
  2864. Vector3 axPos = linkPart.OffsetPosition;
  2865. axPos *= Quaternion.Conjugate(parentRot);
  2866. linkPart.OffsetPosition = axPos;
  2867. // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset.
  2868. // Now that we know this SOG has at least two SOPs in it, the new root
  2869. // SOP becomes the first in the linkset.
  2870. if (m_rootPart.LinkNum == 0)
  2871. m_rootPart.LinkNum = 1;
  2872. lock (m_parts.SyncRoot)
  2873. {
  2874. // Calculate the new link number for the old root SOP
  2875. int linkNum;
  2876. if (insert)
  2877. {
  2878. linkNum = 2;
  2879. int insertSize = objectGroup.PrimCount;
  2880. foreach (SceneObjectPart part in Parts)
  2881. {
  2882. if (part.LinkNum > 1)
  2883. part.LinkNum += insertSize;
  2884. }
  2885. }
  2886. else
  2887. {
  2888. linkNum = PrimCount + 1;
  2889. }
  2890. // Add the old root SOP as a part in our group's list
  2891. m_parts.Add(linkPart.UUID, linkPart);
  2892. linkPart.SetParent(this);
  2893. m_scene.updateScenePartGroup(linkPart, this);
  2894. linkPart.CreateSelected = true;
  2895. // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
  2896. linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true);
  2897. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2898. if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2899. {
  2900. linkPart.PhysActor.link(m_rootPart.PhysActor);
  2901. this.Scene.PhysicsScene.AddPhysicsActorTaint(linkPart.PhysActor);
  2902. }
  2903. linkPart.LinkNum = linkNum++;
  2904. linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  2905. // Get a list of the SOP's in the source group in order of their linknum's.
  2906. SceneObjectPart[] ogParts = objectGroup.Parts;
  2907. Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b)
  2908. {
  2909. return a.LinkNum - b.LinkNum;
  2910. });
  2911. // Add each of the SOP's from the source linkset to our linkset
  2912. for (int i = 0; i < ogParts.Length; i++)
  2913. {
  2914. SceneObjectPart part = ogParts[i];
  2915. if (part.UUID != objectGroup.m_rootPart.UUID)
  2916. {
  2917. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  2918. // Update the physics flags for the newly added SOP
  2919. // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??)
  2920. part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true);
  2921. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2922. if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2923. {
  2924. part.PhysActor.link(m_rootPart.PhysActor);
  2925. this.Scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
  2926. }
  2927. }
  2928. part.ClearUndoState();
  2929. }
  2930. }
  2931. // Now that we've aquired all of the old SOG's parts, remove the old SOG from the scene.
  2932. m_scene.UnlinkSceneObject(objectGroup, true);
  2933. objectGroup.IsDeleted = true;
  2934. objectGroup.m_parts.Clear();
  2935. // Can't do this yet since backup still makes use of the root part without any synchronization
  2936. // objectGroup.m_rootPart = null;
  2937. // If linking prims with different permissions, fix them
  2938. AdjustChildPrimPermissions(false);
  2939. GroupContainsForeignPrims = true;
  2940. AttachToBackup();
  2941. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  2942. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  2943. // unmoved prims!
  2944. ResetChildPrimPhysicsPositions();
  2945. InvalidBoundsRadius();
  2946. InvalidatePartsLinkMaps();
  2947. if (m_rootPart.PhysActor != null)
  2948. m_rootPart.PhysActor.Building = false;
  2949. //HasGroupChanged = true;
  2950. //ScheduleGroupForFullUpdate();
  2951. }
  2952. /// <summary>
  2953. /// Delink the given prim from this group. The delinked prim is established as
  2954. /// an independent SceneObjectGroup.
  2955. /// </summary>
  2956. /// <remarks>
  2957. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2958. /// condition. But currently there is no
  2959. /// alternative method that does take a lonk to delink a single prim.
  2960. /// </remarks>
  2961. /// <param name="partID"></param>
  2962. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2963. public SceneObjectGroup DelinkFromGroup(uint partID)
  2964. {
  2965. return DelinkFromGroup(partID, true);
  2966. }
  2967. /// <summary>
  2968. /// Delink the given prim from this group. The delinked prim is established as
  2969. /// an independent SceneObjectGroup.
  2970. /// </summary>
  2971. /// <remarks>
  2972. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2973. /// condition. But currently there is no
  2974. /// alternative method that does take a lonk to delink a single prim.
  2975. /// </remarks>
  2976. /// <param name="partID"></param>
  2977. /// <param name="sendEvents"></param>
  2978. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2979. public SceneObjectGroup DelinkFromGroup(uint partID, bool sendEvents)
  2980. {
  2981. SceneObjectPart linkPart = GetPart(partID);
  2982. if (linkPart != null)
  2983. {
  2984. return DelinkFromGroup(linkPart, sendEvents);
  2985. }
  2986. else
  2987. {
  2988. m_log.WarnFormat("[SCENE OBJECT GROUP]: " +
  2989. "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}",
  2990. partID, LocalId, UUID);
  2991. return null;
  2992. }
  2993. }
  2994. /// <summary>
  2995. /// Delink the given prim from this group. The delinked prim is established as
  2996. /// an independent SceneObjectGroup.
  2997. /// </summary>
  2998. /// <remarks>
  2999. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  3000. /// condition. But currently there is no
  3001. /// alternative method that does take a lock to delink a single prim.
  3002. /// </remarks>
  3003. /// <param name="partID"></param>
  3004. /// <param name="sendEvents"></param>
  3005. /// <returns>The object group of the newly delinked prim.</returns>
  3006. public SceneObjectGroup DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents)
  3007. {
  3008. // m_log.DebugFormat(
  3009. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3010. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3011. if (m_rootPart.PhysActor != null)
  3012. m_rootPart.PhysActor.Building = true;
  3013. linkPart.ClearUndoState();
  3014. Vector3 worldPos = linkPart.GetWorldPosition();
  3015. Quaternion worldRot = linkPart.GetWorldRotation();
  3016. // Remove the part from this object
  3017. lock (m_parts.SyncRoot)
  3018. {
  3019. m_parts.Remove(linkPart.UUID);
  3020. SceneObjectPart[] parts = m_parts.GetArray();
  3021. // Rejigger the linknum's of the remaining SOP's to fill any gap
  3022. if (parts.Length == 1 && RootPart != null)
  3023. {
  3024. // Single prim left
  3025. RootPart.LinkNum = 0;
  3026. }
  3027. else
  3028. {
  3029. for (int i = 0; i < parts.Length; i++)
  3030. {
  3031. SceneObjectPart part = parts[i];
  3032. if (part.LinkNum > linkPart.LinkNum)
  3033. part.LinkNum--;
  3034. }
  3035. }
  3036. }
  3037. linkPart.ParentID = 0;
  3038. linkPart.LinkNum = 0;
  3039. PhysicsActor linkPartPa = linkPart.PhysActor;
  3040. // Remove the SOP from the physical scene.
  3041. // If the new SOG is physical, it is re-created later.
  3042. // (There is a problem here in that we have not yet told the physics
  3043. // engine about the delink. Someday, linksets should be made first
  3044. // class objects in the physics engine interface).
  3045. if (linkPartPa != null)
  3046. {
  3047. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3048. linkPart.PhysActor = null;
  3049. }
  3050. // We need to reset the child part's position
  3051. // ready for life as a separate object after being a part of another object
  3052. /* This commented out code seems to recompute what GetWorldPosition already does.
  3053. * Replace with a call to GetWorldPosition (before unlinking)
  3054. Quaternion parentRot = m_rootPart.RotationOffset;
  3055. Vector3 axPos = linkPart.OffsetPosition;
  3056. axPos *= parentRot;
  3057. linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z);
  3058. linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition;
  3059. linkPart.OffsetPosition = new Vector3(0, 0, 0);
  3060. */
  3061. linkPart.setGroupPosition(worldPos);
  3062. linkPart.setOffsetPosition(Vector3.Zero);
  3063. linkPart.setRotationOffset(worldRot);
  3064. // Create a new SOG to go around this unlinked and unattached SOP
  3065. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3066. m_scene.AddNewSceneObject(objectGroup, true);
  3067. linkPart.Rezzed = RootPart.Rezzed;
  3068. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3069. // (since delete works by deleting all rows which have a given object id)
  3070. // this is as it seems to be in sl now
  3071. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3072. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3073. if (m_rootPart.PhysActor != null)
  3074. m_rootPart.PhysActor.Building = false;
  3075. objectGroup.HasGroupChangedDueToDelink = true;
  3076. InvalidBoundsRadius();
  3077. InvalidatePartsLinkMaps();
  3078. objectGroup.InvalidateEffectivePerms();
  3079. if (sendEvents)
  3080. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3081. return objectGroup;
  3082. }
  3083. /* working on it
  3084. public void DelinkFromGroup(List<SceneObjectPart> linkParts, bool sendEvents)
  3085. {
  3086. // m_log.DebugFormat(
  3087. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3088. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3089. if(PrimCount == 1)
  3090. return;
  3091. if (m_rootPart.PhysActor != null)
  3092. m_rootPart.PhysActor.Building = true;
  3093. bool unlinkroot = false;
  3094. foreach(SceneObjectPart linkPart in linkParts)
  3095. {
  3096. // first we only remove child parts
  3097. if(linkPart.LocalId == m_rootPart.LocalId)
  3098. {
  3099. unlinkroot = true;
  3100. continue;
  3101. }
  3102. lock (m_parts.SyncRoot)
  3103. if(!m_parts.Remove(linkPart.UUID))
  3104. continue;
  3105. linkPart.ClearUndoState();
  3106. Vector3 worldPos = linkPart.GetWorldPosition();
  3107. Quaternion worldRot = linkPart.GetWorldRotation();
  3108. linkPart.ParentID = 0;
  3109. linkPart.LinkNum = 0;
  3110. PhysicsActor linkPartPa = linkPart.PhysActor;
  3111. // Remove the SOP from the physical scene.
  3112. // If the new SOG is physical, it is re-created later.
  3113. // (There is a problem here in that we have not yet told the physics
  3114. // engine about the delink. Someday, linksets should be made first
  3115. // class objects in the physics engine interface).
  3116. if (linkPartPa != null)
  3117. {
  3118. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3119. linkPart.PhysActor = null;
  3120. }
  3121. linkPart.setGroupPosition(worldPos);
  3122. linkPart.setOffsetPosition(Vector3.Zero);
  3123. linkPart.setRotationOffset(worldRot);
  3124. // Create a new SOG to go around this unlinked and unattached SOP
  3125. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3126. m_scene.AddNewSceneObject(objectGroup, true);
  3127. linkPart.Rezzed = RootPart.Rezzed;
  3128. // this is as it seems to be in sl now
  3129. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3130. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3131. objectGroup.HasGroupChangedDueToDelink = true;
  3132. if (sendEvents)
  3133. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3134. }
  3135. if(unlinkroot)
  3136. {
  3137. //TODO
  3138. }
  3139. lock (m_parts.SyncRoot)
  3140. {
  3141. SceneObjectPart[] parts = m_parts.GetArray();
  3142. if (parts.Length == 1)
  3143. {
  3144. // Single prim left
  3145. m_rootPart.LinkNum = 0;
  3146. }
  3147. else
  3148. {
  3149. m_rootPart.LinkNum = 1;
  3150. int linknum = 2;
  3151. for (int i = 1; i < parts.Length; i++)
  3152. parts[i].LinkNum = linknum++;
  3153. }
  3154. }
  3155. InvalidBoundsRadius();
  3156. if (m_rootPart.PhysActor != null)
  3157. m_rootPart.PhysActor.Building = false;
  3158. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3159. // (since delete works by deleting all rows which have a given object id)
  3160. Scene.SimulationDataService.RemoveObject(UUID, Scene.RegionInfo.RegionID);
  3161. HasGroupChangedDueToDelink = true;
  3162. TriggerScriptChangedEvent(Changed.LINK);
  3163. return;
  3164. }
  3165. */
  3166. /// <summary>
  3167. /// Stop this object from being persisted over server restarts.
  3168. /// </summary>
  3169. /// <param name="objectGroup"></param>
  3170. public virtual void DetachFromBackup()
  3171. {
  3172. if (m_scene != null)
  3173. {
  3174. m_scene.SceneGraph.FireDetachFromBackup(this);
  3175. if (Backup)
  3176. m_scene.EventManager.OnBackup -= ProcessBackup;
  3177. }
  3178. Backup = false;
  3179. }
  3180. // This links an SOP from a previous linkset into my linkset.
  3181. // The trick is that the SOP's position and rotation are relative to the old root SOP's
  3182. // so we are passed in the position and rotation of the old linkset so this can
  3183. // unjigger this SOP's position and rotation from the previous linkset and
  3184. // then make them relative to my linkset root.
  3185. private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation, int linkNum)
  3186. {
  3187. Quaternion parentRot = oldGroupRotation;
  3188. Quaternion oldRot = part.RotationOffset;
  3189. // Move our position in world
  3190. Vector3 axPos = part.OffsetPosition;
  3191. axPos *= parentRot;
  3192. Vector3 newPos = oldGroupPosition + axPos;
  3193. part.setGroupPosition(newPos);
  3194. part.setOffsetPosition(Vector3.Zero);
  3195. // Compution our rotation in world
  3196. Quaternion worldRot = parentRot * oldRot;
  3197. part.RotationOffset = worldRot;
  3198. // Add this SOP to our linkset
  3199. part.SetParent(this);
  3200. part.ParentID = m_rootPart.LocalId;
  3201. m_parts.Add(part.UUID, part);
  3202. part.LinkNum = linkNum;
  3203. m_scene.updateScenePartGroup(part, this);
  3204. // Compute the new position of this SOP relative to the group position
  3205. part.setOffsetPosition(newPos - AbsolutePosition);
  3206. // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times.
  3207. // It would have the affect of setting the physics engine position multiple
  3208. // times. In theory, that is not necessary but I don't have a good linkset
  3209. // test to know that cleaning up this code wouldn't break things.)
  3210. // Compute the SOP's rotation relative to the rotation of the group.
  3211. parentRot = m_rootPart.RotationOffset;
  3212. oldRot = part.RotationOffset;
  3213. Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot;
  3214. part.setRotationOffset(newRot);
  3215. Vector3 pos = part.OffsetPosition;
  3216. pos *= Quaternion.Conjugate(parentRot);
  3217. part.OffsetPosition = pos; // update position and orientation on physics also
  3218. // Since this SOP's state has changed, push those changes into the physics engine
  3219. // and the simulator.
  3220. // done on caller
  3221. // part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  3222. }
  3223. /// <summary>
  3224. /// If object is physical, apply force to move it around
  3225. /// If object is not physical, just put it at the resulting location
  3226. /// </summary>
  3227. /// <param name="partID">Part ID to check for grab</param>
  3228. /// <param name="offset">Always seems to be 0,0,0, so ignoring</param>
  3229. /// <param name="pos">New position. We do the math here to turn it into a force</param>
  3230. /// <param name="remoteClient"></param>
  3231. public void GrabMovement(UUID partID, Vector3 offset, Vector3 pos, IClientAPI remoteClient)
  3232. {
  3233. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3234. {
  3235. if (BlockGrabOverride)
  3236. return;
  3237. SceneObjectPart part = GetPart(partID);
  3238. if (part == null)
  3239. return;
  3240. if (part.BlockGrab)
  3241. return;
  3242. PhysicsActor pa = m_rootPart.PhysActor;
  3243. if (pa != null && pa.IsPhysical)
  3244. {
  3245. // empirically convert distance diference to a impulse
  3246. Vector3 grabforce = pos - AbsolutePosition;
  3247. grabforce = grabforce * (pa.Mass * 0.1f);
  3248. pa.AddForce(grabforce, false);
  3249. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3250. }
  3251. else
  3252. {
  3253. NonPhysicalGrabMovement(pos);
  3254. }
  3255. }
  3256. }
  3257. /// <summary>
  3258. /// Apply possition for grabbing non-physical linksets (Ctrl+Drag)
  3259. /// This MUST be blocked for linksets that contain touch scripts because the viewer triggers grab on the touch
  3260. /// event (Viewer Bug?) This would allow anyone to drag a linkset with a touch script. SL behaviour is also to
  3261. /// block grab on prims with touch events.
  3262. /// </summary>
  3263. /// <param name="pos">New Position</param>
  3264. public void NonPhysicalGrabMovement(Vector3 pos)
  3265. {
  3266. if(!IsAttachment && ScriptCount() == 0)
  3267. UpdateGroupPosition(pos);
  3268. }
  3269. /// <summary>
  3270. /// If object is physical, prepare for spinning torques (set flag to save old orientation)
  3271. /// </summary>
  3272. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3273. /// <param name="remoteClient"></param>
  3274. public void SpinStart(IClientAPI remoteClient)
  3275. {
  3276. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3277. return;
  3278. if (m_scene.EventManager.TriggerGroupSpinStart(UUID))
  3279. {
  3280. PhysicsActor pa = m_rootPart.PhysActor;
  3281. if (pa != null)
  3282. {
  3283. if (pa.IsPhysical)
  3284. {
  3285. m_rootPart.IsWaitingForFirstSpinUpdatePacket = true;
  3286. }
  3287. }
  3288. }
  3289. }
  3290. /// <summary>
  3291. /// If object is physical, apply torque to spin it around
  3292. /// </summary>
  3293. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3294. /// <param name="remoteClient"></param>
  3295. public void SpinMovement(Quaternion newOrientation, IClientAPI remoteClient)
  3296. {
  3297. // The incoming newOrientation, sent by the client, "seems" to be the
  3298. // desired target orientation. This needs further verification; in particular,
  3299. // one would expect that the initial incoming newOrientation should be
  3300. // fairly close to the original prim's physical orientation,
  3301. // m_rootPart.PhysActor.Orientation. This however does not seem to be the
  3302. // case (might just be an issue with different quaternions representing the
  3303. // same rotation, or it might be a coordinate system issue).
  3304. //
  3305. // Since it's not clear what the relationship is between the PhysActor.Orientation
  3306. // and the incoming orientations sent by the client, we take an alternative approach
  3307. // of calculating the delta rotation between the orientations being sent by the
  3308. // client. (Since a spin is invoked by ctrl+shift+drag in the client, we expect
  3309. // a steady stream of several new orientations coming in from the client.)
  3310. // This ensures that the delta rotations are being calculated from self-consistent
  3311. // pairs of old/new rotations. Given the delta rotation, we apply a torque around
  3312. // the delta rotation axis, scaled by the object mass times an arbitrary scaling
  3313. // factor (to ensure the resulting torque is not "too strong" or "too weak").
  3314. //
  3315. // Ideally we need to calculate (probably iteratively) the exact torque or series
  3316. // of torques needed to arrive exactly at the destination orientation. However, since
  3317. // it is not yet clear how to map the destination orientation (provided by the viewer)
  3318. // into PhysActor orientations (needed by the physics engine), we omit this step.
  3319. // This means that the resulting torque will at least be in the correct direction,
  3320. // but it will result in over-shoot or under-shoot of the target orientation.
  3321. // For the end user, this means that ctrl+shift+drag can be used for relative,
  3322. // but not absolute, adjustments of orientation for physical prims.
  3323. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3324. return;
  3325. if (m_scene.EventManager.TriggerGroupSpin(UUID, newOrientation))
  3326. {
  3327. PhysicsActor pa = m_rootPart.PhysActor;
  3328. if (pa != null && pa.IsPhysical)
  3329. {
  3330. if (m_rootPart.IsWaitingForFirstSpinUpdatePacket)
  3331. {
  3332. // first time initialization of "old" orientation for calculation of delta rotations
  3333. m_rootPart.SpinOldOrientation = newOrientation;
  3334. m_rootPart.IsWaitingForFirstSpinUpdatePacket = false;
  3335. }
  3336. else
  3337. {
  3338. // save and update old orientation
  3339. Quaternion old = m_rootPart.SpinOldOrientation;
  3340. m_rootPart.SpinOldOrientation = newOrientation;
  3341. //m_log.Error("[SCENE OBJECT GROUP]: Old orientation is " + old);
  3342. //m_log.Error("[SCENE OBJECT GROUP]: Incoming new orientation is " + newOrientation);
  3343. // compute difference between previous old rotation and new incoming rotation
  3344. Quaternion minimalRotationFromQ1ToQ2 = newOrientation * Quaternion.Inverse(old);
  3345. float rotationAngle;
  3346. Vector3 spinforce;
  3347. minimalRotationFromQ1ToQ2.GetAxisAngle(out spinforce, out rotationAngle);
  3348. if(Math.Abs(rotationAngle)< 0.001)
  3349. return;
  3350. spinforce.Normalize();
  3351. //m_log.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis);
  3352. if(rotationAngle > 0)
  3353. spinforce = spinforce * pa.Mass * 0.1f; // 0.1 is an arbitrary torque scaling factor
  3354. else
  3355. spinforce = spinforce * pa.Mass * -0.1f; // 0.1 is an arbitrary torque scaling
  3356. pa.AddAngularForce(spinforce,true);
  3357. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3358. }
  3359. }
  3360. else
  3361. {
  3362. NonPhysicalSpinMovement(newOrientation);
  3363. }
  3364. }
  3365. }
  3366. /// <summary>
  3367. /// Apply rotation for spinning non-physical linksets (Ctrl+Shift+Drag)
  3368. /// As with dragging, scripted objects must be blocked from spinning
  3369. /// </summary>
  3370. /// <param name="newOrientation">New Rotation</param>
  3371. private void NonPhysicalSpinMovement(Quaternion newOrientation)
  3372. {
  3373. if(!IsAttachment && ScriptCount() == 0)
  3374. UpdateGroupRotationR(newOrientation);
  3375. }
  3376. /// <summary>
  3377. /// Set the name of a prim
  3378. /// </summary>
  3379. /// <param name="name"></param>
  3380. /// <param name="localID"></param>
  3381. public void SetPartName(string name, uint localID)
  3382. {
  3383. SceneObjectPart part = GetPart(localID);
  3384. if (part != null)
  3385. {
  3386. part.Name = name;
  3387. }
  3388. }
  3389. public void SetPartDescription(string des, uint localID)
  3390. {
  3391. SceneObjectPart part = GetPart(localID);
  3392. if (part != null)
  3393. {
  3394. part.Description = des;
  3395. }
  3396. }
  3397. public void SetPartText(string text, uint localID)
  3398. {
  3399. SceneObjectPart part = GetPart(localID);
  3400. if (part != null)
  3401. {
  3402. part.SetText(text);
  3403. }
  3404. }
  3405. public void SetPartText(string text, UUID partID)
  3406. {
  3407. SceneObjectPart part = GetPart(partID);
  3408. if (part != null)
  3409. {
  3410. part.SetText(text);
  3411. }
  3412. }
  3413. public string GetPartName(uint localID)
  3414. {
  3415. SceneObjectPart part = GetPart(localID);
  3416. if (part != null)
  3417. {
  3418. return part.Name;
  3419. }
  3420. return String.Empty;
  3421. }
  3422. public string GetPartDescription(uint localID)
  3423. {
  3424. SceneObjectPart part = GetPart(localID);
  3425. if (part != null)
  3426. {
  3427. return part.Description;
  3428. }
  3429. return String.Empty;
  3430. }
  3431. /// <summary>
  3432. /// Update prim flags for this group.
  3433. /// </summary>
  3434. /// <param name="localID"></param>
  3435. /// <param name="UsePhysics"></param>
  3436. /// <param name="SetTemporary"></param>
  3437. /// <param name="SetPhantom"></param>
  3438. /// <param name="SetVolumeDetect"></param>
  3439. public void UpdateFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect)
  3440. {
  3441. if (m_scene == null || IsDeleted)
  3442. return;
  3443. HasGroupChanged = true;
  3444. if (SetTemporary)
  3445. {
  3446. DetachFromBackup();
  3447. // Remove from database and parcel prim count
  3448. //
  3449. m_scene.DeleteFromStorage(UUID);
  3450. }
  3451. else if (!Backup)
  3452. {
  3453. // Previously been temporary now switching back so make it
  3454. // available for persisting again
  3455. AttachToBackup();
  3456. }
  3457. SceneObjectPart[] parts = m_parts.GetArray();
  3458. if (UsePhysics)
  3459. {
  3460. int maxprims = m_scene.m_linksetPhysCapacity;
  3461. bool checkShape = (maxprims > 0 &&
  3462. parts.Length > maxprims);
  3463. for (int i = 0; i < parts.Length; i++)
  3464. {
  3465. SceneObjectPart part = parts[i];
  3466. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  3467. continue; // assuming root type was checked elsewhere
  3468. if (checkShape)
  3469. {
  3470. if (--maxprims < 0)
  3471. {
  3472. UsePhysics = false;
  3473. break;
  3474. }
  3475. }
  3476. if (part.Scale.X > m_scene.m_maxPhys ||
  3477. part.Scale.Y > m_scene.m_maxPhys ||
  3478. part.Scale.Z > m_scene.m_maxPhys )
  3479. {
  3480. UsePhysics = false; // Reset physics
  3481. break;
  3482. }
  3483. }
  3484. }
  3485. if (parts.Length > 1)
  3486. {
  3487. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3488. for (int i = 0; i < parts.Length; i++)
  3489. {
  3490. if (parts[i].UUID != m_rootPart.UUID)
  3491. parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3492. }
  3493. if (m_rootPart.PhysActor != null)
  3494. m_rootPart.PhysActor.Building = false;
  3495. }
  3496. else
  3497. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false);
  3498. m_scene.EventManager.TriggerParcelPrimCountTainted();
  3499. }
  3500. public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data)
  3501. {
  3502. SceneObjectPart part = GetPart(localID);
  3503. if (part != null)
  3504. {
  3505. part.UpdateExtraParam(type, inUse, data);
  3506. }
  3507. }
  3508. /// <summary>
  3509. /// Gets the number of parts
  3510. /// </summary>
  3511. /// <returns></returns>
  3512. public int GetPartCount()
  3513. {
  3514. return Parts.Count();
  3515. }
  3516. public void AdjustChildPrimPermissions(bool forceTaskInventoryPermissive)
  3517. {
  3518. uint newOwnerMask = (uint)(PermissionMask.All | PermissionMask.Export) & 0xfffffff0; // Mask folded bits
  3519. uint foldedPerms = RootPart.OwnerMask & (uint)PermissionMask.FoldedMask;
  3520. ForEachPart(part =>
  3521. {
  3522. newOwnerMask &= part.BaseMask;
  3523. if (part != RootPart)
  3524. part.ClonePermissions(RootPart);
  3525. if (forceTaskInventoryPermissive)
  3526. part.Inventory.ApplyGodPermissions(part.BaseMask);
  3527. });
  3528. uint lockMask = ~(uint)(PermissionMask.Move);
  3529. uint lockBit = RootPart.OwnerMask & (uint)(PermissionMask.Move);
  3530. RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask);
  3531. // m_log.DebugFormat(
  3532. // "[SCENE OBJECT GROUP]: RootPart.OwnerMask now {0} for {1} in {2}",
  3533. // (OpenMetaverse.PermissionMask)RootPart.OwnerMask, Name, Scene.Name);
  3534. InvalidateEffectivePerms();
  3535. RootPart.ScheduleFullUpdate();
  3536. }
  3537. public void UpdatePermissions(UUID AgentID, byte field, uint localID,
  3538. uint mask, byte addRemTF)
  3539. {
  3540. RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF);
  3541. bool god = Scene.Permissions.IsGod(AgentID);
  3542. if (field == 1 && god)
  3543. {
  3544. ForEachPart(part =>
  3545. {
  3546. part.BaseMask = RootPart.BaseMask;
  3547. });
  3548. }
  3549. AdjustChildPrimPermissions(false);
  3550. if (field == 1 && god) // Base mask was set. Update all child part inventories
  3551. {
  3552. foreach (SceneObjectPart part in Parts)
  3553. part.Inventory.ApplyGodPermissions(RootPart.BaseMask);
  3554. InvalidateEffectivePerms();
  3555. }
  3556. HasGroupChanged = true;
  3557. // Send the group's properties to all clients once all parts are updated
  3558. IClientAPI client;
  3559. if (Scene.TryGetClient(AgentID, out client))
  3560. SendPropertiesToClient(client);
  3561. }
  3562. #endregion
  3563. #region Shape
  3564. /// <summary>
  3565. ///
  3566. /// </summary>
  3567. /// <param name="shapeBlock"></param>
  3568. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock, uint localID)
  3569. {
  3570. SceneObjectPart part = GetPart(localID);
  3571. if (part != null)
  3572. {
  3573. part.UpdateShape(shapeBlock);
  3574. PhysicsActor pa = m_rootPart.PhysActor;
  3575. if (pa != null)
  3576. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3577. }
  3578. InvalidBoundsRadius();
  3579. }
  3580. #endregion
  3581. #region Resize
  3582. /// <summary>
  3583. /// Resize the entire group of prims.
  3584. /// </summary>
  3585. /// <param name="scale"></param>
  3586. public void GroupResize(Vector3 scale)
  3587. {
  3588. // m_log.DebugFormat(
  3589. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
  3590. if (Scene == null)
  3591. return;
  3592. PhysicsActor pa = m_rootPart.PhysActor;
  3593. float minsize = Scene.m_minNonphys;
  3594. float maxsize = Scene.m_maxNonphys;
  3595. if (pa != null && pa.IsPhysical)
  3596. {
  3597. minsize = Scene.m_minPhys;
  3598. maxsize = Scene.m_maxPhys;
  3599. }
  3600. scale.X = Util.Clamp(scale.X, minsize, maxsize);
  3601. scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
  3602. scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
  3603. // requested scaling factors
  3604. float x = (scale.X / RootPart.Scale.X);
  3605. float y = (scale.Y / RootPart.Scale.Y);
  3606. float z = (scale.Z / RootPart.Scale.Z);
  3607. SceneObjectPart[] parts = m_parts.GetArray();
  3608. // fix scaling factors so parts don't violate dimensions
  3609. for(int i = 0;i < parts.Length;i++)
  3610. {
  3611. SceneObjectPart obPart = parts[i];
  3612. if(obPart.UUID != m_rootPart.UUID)
  3613. {
  3614. Vector3 oldSize = new Vector3(obPart.Scale);
  3615. float f = 1.0f;
  3616. float a = 1.0f;
  3617. if(oldSize.X * x > maxsize)
  3618. {
  3619. f = maxsize / oldSize.X;
  3620. a = f / x;
  3621. x *= a;
  3622. y *= a;
  3623. z *= a;
  3624. }
  3625. else if(oldSize.X * x < minsize)
  3626. {
  3627. f = minsize / oldSize.X;
  3628. a = f / x;
  3629. x *= a;
  3630. y *= a;
  3631. z *= a;
  3632. }
  3633. if(oldSize.Y * y > maxsize)
  3634. {
  3635. f = maxsize / oldSize.Y;
  3636. a = f / y;
  3637. x *= a;
  3638. y *= a;
  3639. z *= a;
  3640. }
  3641. else if(oldSize.Y * y < minsize)
  3642. {
  3643. f = minsize / oldSize.Y;
  3644. a = f / y;
  3645. x *= a;
  3646. y *= a;
  3647. z *= a;
  3648. }
  3649. if(oldSize.Z * z > maxsize)
  3650. {
  3651. f = maxsize / oldSize.Z;
  3652. a = f / z;
  3653. x *= a;
  3654. y *= a;
  3655. z *= a;
  3656. }
  3657. else if(oldSize.Z * z < minsize)
  3658. {
  3659. f = minsize / oldSize.Z;
  3660. a = f / z;
  3661. x *= a;
  3662. y *= a;
  3663. z *= a;
  3664. }
  3665. }
  3666. }
  3667. Vector3 rootScale = RootPart.Scale;
  3668. rootScale.X *= x;
  3669. rootScale.Y *= y;
  3670. rootScale.Z *= z;
  3671. RootPart.Scale = rootScale;
  3672. for (int i = 0; i < parts.Length; i++)
  3673. {
  3674. SceneObjectPart obPart = parts[i];
  3675. if (obPart.UUID != m_rootPart.UUID)
  3676. {
  3677. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  3678. currentpos.X *= x;
  3679. currentpos.Y *= y;
  3680. currentpos.Z *= z;
  3681. Vector3 newSize = new Vector3(obPart.Scale);
  3682. newSize.X *= x;
  3683. newSize.Y *= y;
  3684. newSize.Z *= z;
  3685. obPart.Scale = newSize;
  3686. obPart.UpdateOffSet(currentpos);
  3687. }
  3688. }
  3689. InvalidBoundsRadius();
  3690. HasGroupChanged = true;
  3691. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3692. ScheduleGroupForFullUpdate();
  3693. }
  3694. public bool GroupResize(double fscale)
  3695. {
  3696. // m_log.DebugFormat(
  3697. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, fscale);
  3698. if (Scene == null || IsDeleted || inTransit || fscale < 0)
  3699. return false;
  3700. // ignore lsl restrictions. let them be done a LSL
  3701. PhysicsActor pa = m_rootPart.PhysActor;
  3702. if(RootPart.KeyframeMotion != null)
  3703. RootPart.KeyframeMotion.Suspend();
  3704. float minsize = Scene.m_minNonphys;
  3705. float maxsize = Scene.m_maxNonphys;
  3706. // assuming physics is more restrictive
  3707. if (pa != null && pa.IsPhysical)
  3708. {
  3709. minsize = Scene.m_minPhys;
  3710. maxsize = Scene.m_maxPhys;
  3711. }
  3712. SceneObjectPart[] parts = m_parts.GetArray();
  3713. float tmp;
  3714. // check scaling factor so parts don't violate dimensions
  3715. for(int i = 0; i < parts.Length; i++)
  3716. {
  3717. SceneObjectPart obPart = parts[i];
  3718. Vector3 oldSize = new Vector3(obPart.Scale);
  3719. tmp = (float)(oldSize.X * fscale);
  3720. if(tmp > maxsize)
  3721. return false;
  3722. if(tmp < minsize)
  3723. return false;
  3724. tmp = (float)(oldSize.Y * fscale);
  3725. if(tmp > maxsize)
  3726. return false;
  3727. if(tmp < minsize)
  3728. return false;
  3729. tmp = (float)(oldSize.Z * fscale);
  3730. if(tmp > maxsize)
  3731. return false;
  3732. if(tmp < minsize)
  3733. return false;
  3734. }
  3735. Vector3 newSize = RootPart.Scale;
  3736. newSize.X = (float)(newSize.X * fscale);
  3737. newSize.Y = (float)(newSize.Y * fscale);
  3738. newSize.Z = (float)(newSize.Z * fscale);
  3739. if(pa != null)
  3740. pa.Building = true;
  3741. RootPart.Scale = newSize;
  3742. Vector3 currentpos;
  3743. for (int i = 0; i < parts.Length; i++)
  3744. {
  3745. SceneObjectPart obPart = parts[i];
  3746. if (obPart.UUID != m_rootPart.UUID)
  3747. {
  3748. currentpos = obPart.OffsetPosition;
  3749. currentpos.X = (float)(currentpos.X * fscale);
  3750. currentpos.Y = (float)(currentpos.Y * fscale);
  3751. currentpos.Z = (float)(currentpos.Z * fscale);
  3752. newSize = obPart.Scale;
  3753. newSize.X = (float)(newSize.X * fscale);
  3754. newSize.Y = (float)(newSize.Y * fscale);
  3755. newSize.Z = (float)(newSize.Z * fscale);
  3756. obPart.Scale = newSize;
  3757. obPart.UpdateOffSet(currentpos);
  3758. }
  3759. }
  3760. if(pa != null)
  3761. pa.Building = false;
  3762. InvalidBoundsRadius();
  3763. HasGroupChanged = true;
  3764. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3765. ScheduleGroupForFullUpdate();
  3766. if(RootPart.KeyframeMotion != null)
  3767. RootPart.KeyframeMotion.Resume();
  3768. return true;
  3769. }
  3770. public float GetMaxGroupResizeScale()
  3771. {
  3772. if (Scene == null || IsDeleted || inTransit)
  3773. return 1.0f;
  3774. float maxsize = Scene.m_maxNonphys;
  3775. PhysicsActor pa = m_rootPart.PhysActor;
  3776. // assuming physics is more restrictive
  3777. if (pa != null && pa.IsPhysical)
  3778. maxsize = Scene.m_maxPhys;
  3779. SceneObjectPart[] parts = m_parts.GetArray();
  3780. float larger = float.MinValue;
  3781. for(int i = 0; i < parts.Length; i++)
  3782. {
  3783. SceneObjectPart obPart = parts[i];
  3784. Vector3 oldSize = new Vector3(obPart.Scale);
  3785. if(larger < oldSize.X)
  3786. larger = oldSize.X;
  3787. if(larger < oldSize.Y)
  3788. larger = oldSize.Y;
  3789. if(larger < oldSize.Z)
  3790. larger = oldSize.Z;
  3791. }
  3792. if(larger >= maxsize)
  3793. return 1.0f;
  3794. larger += 1e-3f;
  3795. float fscale = maxsize / larger;
  3796. return fscale;
  3797. }
  3798. public float GetMinGroupResizeScale()
  3799. {
  3800. if (Scene == null || IsDeleted || inTransit)
  3801. return 1.0f;
  3802. float minsize = Scene.m_minNonphys;
  3803. PhysicsActor pa = m_rootPart.PhysActor;
  3804. // assuming physics is more restrictive
  3805. if (pa != null && pa.IsPhysical)
  3806. minsize = Scene.m_minPhys;
  3807. SceneObjectPart[] parts = m_parts.GetArray();
  3808. float smaller = float.MaxValue;
  3809. for(int i = 0; i < parts.Length; i++)
  3810. {
  3811. SceneObjectPart obPart = parts[i];
  3812. Vector3 oldSize = new Vector3(obPart.Scale);
  3813. if(smaller > oldSize.X)
  3814. smaller = oldSize.X;
  3815. if(smaller > oldSize.Y)
  3816. smaller = oldSize.Y;
  3817. if(smaller > oldSize.Z)
  3818. smaller = oldSize.Z;
  3819. }
  3820. if(smaller <= minsize)
  3821. return 1.0f;
  3822. if(smaller > 2e-3f)
  3823. smaller -= 1e-3f;
  3824. float fscale = minsize / smaller;
  3825. if(fscale < 1e-8f)
  3826. fscale = 1e-8f;
  3827. return fscale;
  3828. }
  3829. #endregion
  3830. #region Position
  3831. /// <summary>
  3832. /// Move this scene object
  3833. /// </summary>
  3834. /// <param name="pos"></param>
  3835. public void UpdateGroupPosition(Vector3 pos)
  3836. {
  3837. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3838. {
  3839. if (IsAttachment)
  3840. {
  3841. m_rootPart.AttachedPos = pos;
  3842. }
  3843. if (RootPart.GetStatusSandbox())
  3844. {
  3845. if (Vector3.DistanceSquared(RootPart.StatusSandboxPos, pos) > 100)
  3846. {
  3847. RootPart.ScriptSetPhysicsStatus(false);
  3848. pos = AbsolutePosition;
  3849. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3850. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  3851. }
  3852. }
  3853. AbsolutePosition = pos;
  3854. HasGroupChanged = true;
  3855. }
  3856. //we need to do a terse update even if the move wasn't allowed
  3857. // so that the position is reset in the client (the object snaps back)
  3858. RootPart.ScheduleTerseUpdate();
  3859. }
  3860. /// <summary>
  3861. /// Update the position of a single part of this scene object
  3862. /// </summary>
  3863. /// <param name="pos"></param>
  3864. /// <param name="localID"></param>
  3865. ///
  3866. public void UpdateSinglePosition(Vector3 pos, uint localID)
  3867. {
  3868. SceneObjectPart part = GetPart(localID);
  3869. if (part != null)
  3870. {
  3871. // unlock parts position change
  3872. if (m_rootPart.PhysActor != null)
  3873. m_rootPart.PhysActor.Building = true;
  3874. if (part.UUID == m_rootPart.UUID)
  3875. {
  3876. UpdateRootPosition(pos);
  3877. }
  3878. else
  3879. {
  3880. part.UpdateOffSet(pos);
  3881. }
  3882. if (m_rootPart.PhysActor != null)
  3883. m_rootPart.PhysActor.Building = false;
  3884. HasGroupChanged = true;
  3885. }
  3886. }
  3887. /// <summary>
  3888. /// Update just the root prim position in a linkset
  3889. /// </summary>
  3890. /// <param name="newPos"></param>
  3891. public void UpdateRootPosition(Vector3 newPos)
  3892. {
  3893. // needs to be called with phys building true
  3894. Vector3 oldPos;
  3895. if (IsAttachment)
  3896. oldPos = m_rootPart.AttachedPos + m_rootPart.OffsetPosition; // OffsetPosition should always be 0 in an attachments's root prim
  3897. else
  3898. oldPos = AbsolutePosition + m_rootPart.OffsetPosition;
  3899. Vector3 diff = oldPos - newPos;
  3900. Quaternion partRotation = m_rootPart.RotationOffset;
  3901. diff *= Quaternion.Inverse(partRotation);
  3902. SceneObjectPart[] parts = m_parts.GetArray();
  3903. for (int i = 0; i < parts.Length; i++)
  3904. {
  3905. SceneObjectPart obPart = parts[i];
  3906. if (obPart.UUID != m_rootPart.UUID)
  3907. obPart.OffsetPosition = obPart.OffsetPosition + diff;
  3908. }
  3909. AbsolutePosition = newPos;
  3910. if (IsAttachment)
  3911. m_rootPart.AttachedPos = newPos;
  3912. HasGroupChanged = true;
  3913. if (m_rootPart.Undoing)
  3914. {
  3915. ScheduleGroupForFullUpdate();
  3916. }
  3917. else
  3918. {
  3919. ScheduleGroupForTerseUpdate();
  3920. }
  3921. }
  3922. #endregion
  3923. #region Rotation
  3924. /// <summary>
  3925. /// Update the rotation of the group.
  3926. /// </summary>
  3927. /// <param name="rot"></param>
  3928. public void UpdateGroupRotationR(Quaternion rot)
  3929. {
  3930. m_rootPart.UpdateRotation(rot);
  3931. /* this is done by rootpart RotationOffset set called by UpdateRotation
  3932. PhysicsActor actor = m_rootPart.PhysActor;
  3933. if (actor != null)
  3934. {
  3935. actor.Orientation = m_rootPart.RotationOffset;
  3936. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3937. }
  3938. */
  3939. HasGroupChanged = true;
  3940. ScheduleGroupForTerseUpdate();
  3941. }
  3942. /// <summary>
  3943. /// Update the position and rotation of a group simultaneously.
  3944. /// </summary>
  3945. /// <param name="pos"></param>
  3946. /// <param name="rot"></param>
  3947. public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
  3948. {
  3949. m_rootPart.UpdateRotation(rot);
  3950. PhysicsActor actor = m_rootPart.PhysActor;
  3951. if (actor != null)
  3952. {
  3953. actor.Orientation = m_rootPart.RotationOffset;
  3954. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3955. }
  3956. if (IsAttachment)
  3957. {
  3958. m_rootPart.AttachedPos = pos;
  3959. }
  3960. AbsolutePosition = pos;
  3961. HasGroupChanged = true;
  3962. ScheduleGroupForTerseUpdate();
  3963. }
  3964. /// <summary>
  3965. /// Update the rotation of a single prim within the group.
  3966. /// </summary>
  3967. /// <param name="rot"></param>
  3968. /// <param name="localID"></param>
  3969. public void UpdateSingleRotation(Quaternion rot, uint localID)
  3970. {
  3971. SceneObjectPart part = GetPart(localID);
  3972. SceneObjectPart[] parts = m_parts.GetArray();
  3973. if (part != null)
  3974. {
  3975. if (m_rootPart.PhysActor != null)
  3976. m_rootPart.PhysActor.Building = true;
  3977. if (part.UUID == m_rootPart.UUID)
  3978. {
  3979. UpdateRootRotation(rot);
  3980. }
  3981. else
  3982. {
  3983. part.UpdateRotation(rot);
  3984. }
  3985. if (m_rootPart.PhysActor != null)
  3986. m_rootPart.PhysActor.Building = false;
  3987. }
  3988. }
  3989. /// <summary>
  3990. /// Update the position and rotation simultaneously of a single prim within the group.
  3991. /// </summary>
  3992. /// <param name="rot"></param>
  3993. /// <param name="localID"></param>
  3994. public void UpdateSingleRotation(Quaternion rot, Vector3 pos, uint localID)
  3995. {
  3996. SceneObjectPart part = GetPart(localID);
  3997. if (part != null)
  3998. {
  3999. if (m_rootPart.PhysActor != null)
  4000. m_rootPart.PhysActor.Building = true;
  4001. if (part.UUID == m_rootPart.UUID)
  4002. {
  4003. UpdateRootRotation(rot);
  4004. AbsolutePosition = pos;
  4005. }
  4006. else
  4007. {
  4008. part.UpdateRotation(rot);
  4009. part.OffsetPosition = pos;
  4010. }
  4011. if (m_rootPart.PhysActor != null)
  4012. m_rootPart.PhysActor.Building = false;
  4013. }
  4014. }
  4015. /// <summary>
  4016. /// Update the rotation of just the root prim of a linkset.
  4017. /// </summary>
  4018. /// <param name="rot"></param>
  4019. public void UpdateRootRotation(Quaternion rot)
  4020. {
  4021. // needs to be called with phys building true
  4022. Quaternion axRot = rot;
  4023. Quaternion oldParentRot = m_rootPart.RotationOffset;
  4024. //Don't use UpdateRotation because it schedules an update prematurely
  4025. m_rootPart.RotationOffset = rot;
  4026. PhysicsActor pa = m_rootPart.PhysActor;
  4027. if (pa != null)
  4028. {
  4029. pa.Orientation = m_rootPart.RotationOffset;
  4030. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4031. }
  4032. SceneObjectPart[] parts = m_parts.GetArray();
  4033. for (int i = 0; i < parts.Length; i++)
  4034. {
  4035. SceneObjectPart prim = parts[i];
  4036. if (prim.UUID != m_rootPart.UUID)
  4037. {
  4038. Quaternion NewRot = oldParentRot * prim.RotationOffset;
  4039. NewRot = Quaternion.Inverse(axRot) * NewRot;
  4040. prim.RotationOffset = NewRot;
  4041. Vector3 axPos = prim.OffsetPosition;
  4042. axPos *= oldParentRot;
  4043. axPos *= Quaternion.Inverse(axRot);
  4044. prim.OffsetPosition = axPos;
  4045. }
  4046. }
  4047. HasGroupChanged = true;
  4048. ScheduleGroupForFullUpdate();
  4049. }
  4050. private enum updatetype :int
  4051. {
  4052. none = 0,
  4053. partterse = 1,
  4054. partfull = 2,
  4055. groupterse = 3,
  4056. groupfull = 4
  4057. }
  4058. public void doChangeObject(SceneObjectPart part, ObjectChangeData data)
  4059. {
  4060. // TODO this still as excessive *.Schedule*Update()s
  4061. if (part != null && part.ParentGroup != null)
  4062. {
  4063. ObjectChangeType change = data.change;
  4064. bool togroup = ((change & ObjectChangeType.Group) != 0);
  4065. // bool uniform = ((what & ObjectChangeType.UniformScale) != 0); not in use
  4066. SceneObjectGroup group = part.ParentGroup;
  4067. PhysicsActor pha = group.RootPart.PhysActor;
  4068. updatetype updateType = updatetype.none;
  4069. if (togroup)
  4070. {
  4071. // related to group
  4072. if ((change & (ObjectChangeType.Rotation | ObjectChangeType.Position)) != 0)
  4073. {
  4074. if ((change & ObjectChangeType.Rotation) != 0)
  4075. {
  4076. group.RootPart.UpdateRotation(data.rotation);
  4077. updateType = updatetype.none;
  4078. }
  4079. if ((change & ObjectChangeType.Position) != 0)
  4080. {
  4081. if (IsAttachment || m_scene.Permissions.CanObjectEntry(group, false, data.position))
  4082. UpdateGroupPosition(data.position);
  4083. updateType = updatetype.groupterse;
  4084. }
  4085. else
  4086. // ugly rotation update of all parts
  4087. {
  4088. group.ResetChildPrimPhysicsPositions();
  4089. }
  4090. }
  4091. if ((change & ObjectChangeType.Scale) != 0)
  4092. {
  4093. if (pha != null)
  4094. pha.Building = true;
  4095. group.GroupResize(data.scale);
  4096. updateType = updatetype.none;
  4097. if (pha != null)
  4098. pha.Building = false;
  4099. }
  4100. }
  4101. else
  4102. {
  4103. // related to single prim in a link-set ( ie group)
  4104. if (pha != null)
  4105. pha.Building = true;
  4106. // root part is special
  4107. // parts offset positions or rotations need to change also
  4108. if (part == group.RootPart)
  4109. {
  4110. if ((change & ObjectChangeType.Rotation) != 0)
  4111. group.UpdateRootRotation(data.rotation);
  4112. if ((change & ObjectChangeType.Position) != 0)
  4113. group.UpdateRootPosition(data.position);
  4114. if ((change & ObjectChangeType.Scale) != 0)
  4115. part.Resize(data.scale);
  4116. }
  4117. else
  4118. {
  4119. if ((change & ObjectChangeType.Position) != 0)
  4120. {
  4121. part.OffsetPosition = data.position;
  4122. updateType = updatetype.partterse;
  4123. }
  4124. if ((change & ObjectChangeType.Rotation) != 0)
  4125. {
  4126. part.UpdateRotation(data.rotation);
  4127. updateType = updatetype.none;
  4128. }
  4129. if ((change & ObjectChangeType.Scale) != 0)
  4130. {
  4131. part.Resize(data.scale);
  4132. updateType = updatetype.none;
  4133. }
  4134. }
  4135. if (pha != null)
  4136. pha.Building = false;
  4137. }
  4138. if (updateType != updatetype.none)
  4139. {
  4140. group.HasGroupChanged = true;
  4141. switch (updateType)
  4142. {
  4143. case updatetype.partterse:
  4144. part.ScheduleTerseUpdate();
  4145. break;
  4146. case updatetype.partfull:
  4147. part.ScheduleFullUpdate();
  4148. break;
  4149. case updatetype.groupterse:
  4150. group.ScheduleGroupForTerseUpdate();
  4151. break;
  4152. case updatetype.groupfull:
  4153. group.ScheduleGroupForFullUpdate();
  4154. break;
  4155. default:
  4156. break;
  4157. }
  4158. }
  4159. }
  4160. }
  4161. #endregion
  4162. internal void SetAxisRotation(int axis, int rotate10)
  4163. {
  4164. bool setX = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0);
  4165. bool setY = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0);
  4166. bool setZ = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0);
  4167. if (setX || setY || setZ)
  4168. {
  4169. bool lockaxis = (rotate10 == 0); // zero means axis locked
  4170. byte locks = RootPart.RotationAxisLocks;
  4171. if (setX)
  4172. {
  4173. if(lockaxis)
  4174. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X;
  4175. else
  4176. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_X;
  4177. }
  4178. if (setY)
  4179. {
  4180. if(lockaxis)
  4181. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y;
  4182. else
  4183. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Y;
  4184. }
  4185. if (setZ)
  4186. {
  4187. if(lockaxis)
  4188. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z;
  4189. else
  4190. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Z;
  4191. }
  4192. RootPart.RotationAxisLocks = locks;
  4193. RootPart.SetPhysicsAxisRotation();
  4194. }
  4195. }
  4196. public int GetAxisRotation(int axis)
  4197. {
  4198. byte rotAxislocks = RootPart.RotationAxisLocks;
  4199. // if multiple return the one with higher id
  4200. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z)
  4201. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) == 0 ? 1:0;
  4202. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y)
  4203. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) == 0 ? 1:0;
  4204. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X)
  4205. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) == 0 ? 1:0;
  4206. return 0;
  4207. }
  4208. public int registerRotTargetWaypoint(Quaternion target, float tolerance)
  4209. {
  4210. scriptRotTarget waypoint = new scriptRotTarget();
  4211. waypoint.targetRot = target;
  4212. waypoint.tolerance = tolerance;
  4213. uint handle = m_scene.AllocateLocalId();
  4214. waypoint.handle = handle;
  4215. lock (m_rotTargets)
  4216. {
  4217. if (m_rotTargets.Count >= 8)
  4218. m_rotTargets.Remove(m_rotTargets.ElementAt(0).Key);
  4219. m_rotTargets.Add(handle, waypoint);
  4220. }
  4221. m_scene.AddGroupTarget(this);
  4222. return (int)handle;
  4223. }
  4224. public void unregisterRotTargetWaypoint(int handle)
  4225. {
  4226. lock (m_targets)
  4227. {
  4228. m_rotTargets.Remove((uint)handle);
  4229. if (m_targets.Count == 0)
  4230. m_scene.RemoveGroupTarget(this);
  4231. }
  4232. }
  4233. public int registerTargetWaypoint(Vector3 target, float tolerance)
  4234. {
  4235. scriptPosTarget waypoint = new scriptPosTarget();
  4236. waypoint.targetPos = target;
  4237. waypoint.tolerance = tolerance;
  4238. uint handle = m_scene.AllocateLocalId();
  4239. waypoint.handle = handle;
  4240. lock (m_targets)
  4241. {
  4242. if (m_targets.Count >= 8)
  4243. m_targets.Remove(m_targets.ElementAt(0).Key);
  4244. m_targets.Add(handle, waypoint);
  4245. }
  4246. m_scene.AddGroupTarget(this);
  4247. return (int)handle;
  4248. }
  4249. public void unregisterTargetWaypoint(int handle)
  4250. {
  4251. lock (m_targets)
  4252. {
  4253. m_targets.Remove((uint)handle);
  4254. if (m_targets.Count == 0)
  4255. m_scene.RemoveGroupTarget(this);
  4256. }
  4257. }
  4258. public void checkAtTargets()
  4259. {
  4260. if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
  4261. {
  4262. if (m_targets.Count > 0)
  4263. {
  4264. bool at_target = false;
  4265. //Vector3 targetPos;
  4266. //uint targetHandle;
  4267. Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
  4268. lock (m_targets)
  4269. {
  4270. foreach (uint idx in m_targets.Keys)
  4271. {
  4272. scriptPosTarget target = m_targets[idx];
  4273. if (Vector3.DistanceSquared(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance * target.tolerance)
  4274. {
  4275. at_target = true;
  4276. // trigger at_target
  4277. if (m_scriptListens_atTarget)
  4278. {
  4279. scriptPosTarget att = new scriptPosTarget();
  4280. att.targetPos = target.targetPos;
  4281. att.tolerance = target.tolerance;
  4282. att.handle = target.handle;
  4283. atTargets.Add(idx, att);
  4284. }
  4285. }
  4286. }
  4287. }
  4288. if (atTargets.Count > 0)
  4289. {
  4290. SceneObjectPart[] parts = m_parts.GetArray();
  4291. uint[] localids = new uint[parts.Length];
  4292. for (int i = 0; i < parts.Length; i++)
  4293. localids[i] = parts[i].LocalId;
  4294. for (int ctr = 0; ctr < localids.Length; ctr++)
  4295. {
  4296. foreach (uint target in atTargets.Keys)
  4297. {
  4298. scriptPosTarget att = atTargets[target];
  4299. m_scene.EventManager.TriggerAtTargetEvent(
  4300. localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
  4301. }
  4302. }
  4303. return;
  4304. }
  4305. if (m_scriptListens_notAtTarget && !at_target)
  4306. {
  4307. //trigger not_at_target
  4308. SceneObjectPart[] parts = m_parts.GetArray();
  4309. uint[] localids = new uint[parts.Length];
  4310. for (int i = 0; i < parts.Length; i++)
  4311. localids[i] = parts[i].LocalId;
  4312. for (int ctr = 0; ctr < localids.Length; ctr++)
  4313. {
  4314. m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
  4315. }
  4316. }
  4317. }
  4318. }
  4319. if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
  4320. {
  4321. if (m_rotTargets.Count > 0)
  4322. {
  4323. bool at_Rottarget = false;
  4324. Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
  4325. lock (m_rotTargets)
  4326. {
  4327. foreach (uint idx in m_rotTargets.Keys)
  4328. {
  4329. scriptRotTarget target = m_rotTargets[idx];
  4330. double angle
  4331. = Math.Acos(
  4332. target.targetRot.X * m_rootPart.RotationOffset.X
  4333. + target.targetRot.Y * m_rootPart.RotationOffset.Y
  4334. + target.targetRot.Z * m_rootPart.RotationOffset.Z
  4335. + target.targetRot.W * m_rootPart.RotationOffset.W)
  4336. * 2;
  4337. if (angle < 0) angle = -angle;
  4338. if (angle > Math.PI) angle = (Math.PI * 2 - angle);
  4339. if (angle <= target.tolerance)
  4340. {
  4341. // trigger at_rot_target
  4342. if (m_scriptListens_atRotTarget)
  4343. {
  4344. at_Rottarget = true;
  4345. scriptRotTarget att = new scriptRotTarget();
  4346. att.targetRot = target.targetRot;
  4347. att.tolerance = target.tolerance;
  4348. att.handle = target.handle;
  4349. atRotTargets.Add(idx, att);
  4350. }
  4351. }
  4352. }
  4353. }
  4354. if (atRotTargets.Count > 0)
  4355. {
  4356. SceneObjectPart[] parts = m_parts.GetArray();
  4357. uint[] localids = new uint[parts.Length];
  4358. for (int i = 0; i < parts.Length; i++)
  4359. localids[i] = parts[i].LocalId;
  4360. for (int ctr = 0; ctr < localids.Length; ctr++)
  4361. {
  4362. foreach (uint target in atRotTargets.Keys)
  4363. {
  4364. scriptRotTarget att = atRotTargets[target];
  4365. m_scene.EventManager.TriggerAtRotTargetEvent(
  4366. localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
  4367. }
  4368. }
  4369. return;
  4370. }
  4371. if (m_scriptListens_notAtRotTarget && !at_Rottarget)
  4372. {
  4373. //trigger not_at_target
  4374. SceneObjectPart[] parts = m_parts.GetArray();
  4375. uint[] localids = new uint[parts.Length];
  4376. for (int i = 0; i < parts.Length; i++)
  4377. localids[i] = parts[i].LocalId;
  4378. for (int ctr = 0; ctr < localids.Length; ctr++)
  4379. {
  4380. m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
  4381. }
  4382. }
  4383. }
  4384. }
  4385. }
  4386. public Vector3 GetGeometricCenter()
  4387. {
  4388. // this is not real geometric center but a average of positions relative to root prim acording to
  4389. // http://wiki.secondlife.com/wiki/llGetGeometricCenter
  4390. // ignoring tortured prims details since sl also seems to ignore
  4391. // so no real use in doing it on physics
  4392. Vector3 gc = Vector3.Zero;
  4393. SceneObjectPart[] parts = m_parts.GetArray();
  4394. int nparts = parts.Length;
  4395. if (nparts < 2)
  4396. return gc;
  4397. // average all parts positions
  4398. for (int i = 0; i < nparts; i++)
  4399. {
  4400. if (parts[i] != RootPart)
  4401. gc += parts[i].OffsetPosition;
  4402. }
  4403. gc /= nparts;
  4404. return gc;
  4405. }
  4406. public float GetMass()
  4407. {
  4408. float retmass = 0f;
  4409. SceneObjectPart[] parts = m_parts.GetArray();
  4410. for (int i = 0; i < parts.Length; i++)
  4411. retmass += parts[i].GetMass();
  4412. return retmass;
  4413. }
  4414. // center of mass of full object
  4415. public Vector3 GetCenterOfMass()
  4416. {
  4417. PhysicsActor pa = RootPart.PhysActor;
  4418. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4419. {
  4420. // physics knows better about center of mass of physical prims
  4421. Vector3 tmp = pa.CenterOfMass;
  4422. return tmp;
  4423. }
  4424. Vector3 Ptot = Vector3.Zero;
  4425. float totmass = 0f;
  4426. float m;
  4427. SceneObjectPart[] parts = m_parts.GetArray();
  4428. for (int i = 0; i < parts.Length; i++)
  4429. {
  4430. m = parts[i].GetMass();
  4431. Ptot += parts[i].GetPartCenterOfMass() * m;
  4432. totmass += m;
  4433. }
  4434. if (totmass == 0)
  4435. totmass = 0;
  4436. else
  4437. totmass = 1 / totmass;
  4438. Ptot *= totmass;
  4439. return Ptot;
  4440. }
  4441. public void GetInertiaData(out float TotalMass, out Vector3 CenterOfMass, out Vector3 Inertia, out Vector4 aux )
  4442. {
  4443. PhysicsActor pa = RootPart.PhysActor;
  4444. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4445. {
  4446. PhysicsInertiaData inertia;
  4447. inertia = pa.GetInertiaData();
  4448. TotalMass = inertia.TotalMass;
  4449. CenterOfMass = inertia.CenterOfMass;
  4450. Inertia = inertia.Inertia;
  4451. aux = inertia.InertiaRotation;
  4452. return;
  4453. }
  4454. TotalMass = GetMass();
  4455. CenterOfMass = GetCenterOfMass() - AbsolutePosition;
  4456. CenterOfMass *= Quaternion.Conjugate(RootPart.RotationOffset);
  4457. Inertia = Vector3.Zero;
  4458. aux = Vector4.Zero;
  4459. }
  4460. public void SetInertiaData(float TotalMass, Vector3 CenterOfMass, Vector3 Inertia, Vector4 aux )
  4461. {
  4462. PhysicsInertiaData inertia = new PhysicsInertiaData();
  4463. inertia.TotalMass = TotalMass;
  4464. inertia.CenterOfMass = CenterOfMass;
  4465. inertia.Inertia = Inertia;
  4466. inertia.InertiaRotation = aux;
  4467. if(TotalMass < 0)
  4468. RootPart.PhysicsInertia = null;
  4469. else
  4470. RootPart.PhysicsInertia = new PhysicsInertiaData(inertia);
  4471. PhysicsActor pa = RootPart.PhysActor;
  4472. if(pa !=null)
  4473. pa.SetInertiaData(inertia);
  4474. }
  4475. /// <summary>
  4476. /// Set the user group to which this scene object belongs.
  4477. /// </summary>
  4478. /// <param name="GroupID"></param>
  4479. /// <param name="client"></param>
  4480. public void SetGroup(UUID GroupID, IClientAPI client)
  4481. {
  4482. SceneObjectPart[] parts = m_parts.GetArray();
  4483. for (int i = 0; i < parts.Length; i++)
  4484. {
  4485. SceneObjectPart part = parts[i];
  4486. part.SetGroup(GroupID, client);
  4487. part.Inventory.ChangeInventoryGroup(GroupID);
  4488. }
  4489. HasGroupChanged = true;
  4490. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  4491. // for the same object with very different properties. The caller must schedule the update.
  4492. //ScheduleGroupForFullUpdate();
  4493. }
  4494. public void TriggerScriptChangedEvent(Changed val)
  4495. {
  4496. SceneObjectPart[] parts = m_parts.GetArray();
  4497. for (int i = 0; i < parts.Length; i++)
  4498. parts[i].TriggerScriptChangedEvent(val);
  4499. }
  4500. /// <summary>
  4501. /// Returns a count of the number of scripts in this groups parts.
  4502. /// </summary>
  4503. public int ScriptCount()
  4504. {
  4505. int count = 0;
  4506. SceneObjectPart[] parts = m_parts.GetArray();
  4507. for (int i = 0; i < parts.Length; i++)
  4508. count += parts[i].Inventory.ScriptCount();
  4509. return count;
  4510. }
  4511. /// <summary>
  4512. /// A float the value is a representative execution time in milliseconds of all scripts in the link set.
  4513. /// </summary>
  4514. public float ScriptExecutionTime()
  4515. {
  4516. IScriptModule[] engines = Scene.RequestModuleInterfaces<IScriptModule>();
  4517. if (engines.Length == 0) // No engine at all
  4518. return 0.0f;
  4519. float time = 0.0f;
  4520. // get all the scripts in all parts
  4521. SceneObjectPart[] parts = m_parts.GetArray();
  4522. List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
  4523. for (int i = 0; i < parts.Length; i++)
  4524. {
  4525. scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
  4526. }
  4527. // extract the UUIDs
  4528. List<UUID> ids = new List<UUID>(scripts.Count);
  4529. foreach (TaskInventoryItem script in scripts)
  4530. {
  4531. if (!ids.Contains(script.ItemID))
  4532. {
  4533. ids.Add(script.ItemID);
  4534. }
  4535. }
  4536. // Offer the list of script UUIDs to each engine found and accumulate the time
  4537. foreach (IScriptModule e in engines)
  4538. {
  4539. if (e != null)
  4540. {
  4541. time += e.GetScriptExecutionTime(ids);
  4542. }
  4543. }
  4544. return time;
  4545. }
  4546. /// <summary>
  4547. /// Returns a count of the number of running scripts in this groups parts.
  4548. /// </summary>
  4549. public int RunningScriptCount()
  4550. {
  4551. int count = 0;
  4552. SceneObjectPart[] parts = m_parts.GetArray();
  4553. for (int i = 0; i < parts.Length; i++)
  4554. count += parts[i].Inventory.RunningScriptCount();
  4555. return count;
  4556. }
  4557. /// <summary>
  4558. /// Get a copy of the list of sitting avatars on all prims of this object.
  4559. /// </summary>
  4560. /// <remarks>
  4561. /// This is sorted by the order in which avatars sat down. If an avatar stands up then all avatars that sat
  4562. /// down after it move one place down the list.
  4563. /// </remarks>
  4564. /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns>
  4565. public List<ScenePresence> GetSittingAvatars()
  4566. {
  4567. lock (m_sittingAvatars)
  4568. return new List<ScenePresence>(m_sittingAvatars);
  4569. }
  4570. /// <summary>
  4571. /// Gets the number of sitting avatars.
  4572. /// </summary>
  4573. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4574. /// <returns></returns>
  4575. public int GetSittingAvatarsCount()
  4576. {
  4577. lock (m_sittingAvatars)
  4578. return m_sittingAvatars.Count;
  4579. }
  4580. public override string ToString()
  4581. {
  4582. return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
  4583. }
  4584. #region ISceneObject
  4585. public virtual ISceneObject CloneForNewScene()
  4586. {
  4587. SceneObjectGroup sog = Copy(false);
  4588. sog.IsDeleted = false;
  4589. return sog;
  4590. }
  4591. public virtual string ToXml2()
  4592. {
  4593. return SceneObjectSerializer.ToXml2Format(this);
  4594. }
  4595. public virtual string ExtraToXmlString()
  4596. {
  4597. return "<ExtraFromItemID>" + FromItemID.ToString() + "</ExtraFromItemID>";
  4598. }
  4599. public virtual void ExtraFromXmlString(string xmlstr)
  4600. {
  4601. string id = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromItemID>"));
  4602. id = xmlstr.Replace("<ExtraFromItemID>", "");
  4603. id = id.Replace("</ExtraFromItemID>", "");
  4604. UUID uuid = UUID.Zero;
  4605. UUID.TryParse(id, out uuid);
  4606. FromItemID = uuid;
  4607. }
  4608. public void ResetOwnerChangeFlag()
  4609. {
  4610. ForEachPart(delegate(SceneObjectPart part)
  4611. {
  4612. part.ResetOwnerChangeFlag();
  4613. });
  4614. InvalidateEffectivePerms();
  4615. }
  4616. // clear some references to easy cg
  4617. public void Clear()
  4618. {
  4619. m_parts.Clear();
  4620. m_sittingAvatars.Clear();
  4621. // m_rootPart = null;
  4622. m_PlaySoundMasterPrim = null;
  4623. m_PlaySoundSlavePrims.Clear();
  4624. m_LoopSoundMasterPrim = null;
  4625. m_targets.Clear();
  4626. m_partsNameToLinkMap.Clear();
  4627. }
  4628. private Dictionary<string,int> m_partsNameToLinkMap = new Dictionary<string, int>();
  4629. private string GetLinkNumber_lastname;
  4630. private int GetLinkNumber_lastnumber;
  4631. // this scales bad but so does GetLinkNumPart
  4632. public int GetLinkNumber(string name)
  4633. {
  4634. if(String.IsNullOrEmpty(name) || name == "Object")
  4635. return -1;
  4636. lock(m_partsNameToLinkMap)
  4637. {
  4638. if(m_partsNameToLinkMap.Count == 0)
  4639. {
  4640. GetLinkNumber_lastname = String.Empty;
  4641. GetLinkNumber_lastnumber = -1;
  4642. SceneObjectPart[] parts = m_parts.GetArray();
  4643. for (int i = 0; i < parts.Length; i++)
  4644. {
  4645. string s = parts[i].Name;
  4646. if(String.IsNullOrEmpty(s) || s == "Object" || s == "Primitive")
  4647. continue;
  4648. if(m_partsNameToLinkMap.ContainsKey(s))
  4649. {
  4650. int ol = parts[i].LinkNum;
  4651. if(ol < m_partsNameToLinkMap[s])
  4652. m_partsNameToLinkMap[s] = ol;
  4653. }
  4654. else
  4655. m_partsNameToLinkMap[s] = parts[i].LinkNum;
  4656. }
  4657. }
  4658. if(name == GetLinkNumber_lastname)
  4659. return GetLinkNumber_lastnumber;
  4660. if(m_partsNameToLinkMap.ContainsKey(name))
  4661. {
  4662. lock(m_partsNameToLinkMap)
  4663. {
  4664. GetLinkNumber_lastname = name;
  4665. GetLinkNumber_lastnumber = m_partsNameToLinkMap[name];
  4666. return GetLinkNumber_lastnumber;
  4667. }
  4668. }
  4669. }
  4670. if(m_sittingAvatars.Count > 0)
  4671. {
  4672. int j = m_parts.Count + 1;
  4673. ScenePresence[] avs = m_sittingAvatars.ToArray();
  4674. for (int i = 0; i < avs.Length; i++, j++)
  4675. {
  4676. if (avs[i].Name == name)
  4677. {
  4678. GetLinkNumber_lastname = name;
  4679. GetLinkNumber_lastnumber = j;
  4680. return j;
  4681. }
  4682. }
  4683. }
  4684. return -1;
  4685. }
  4686. public void InvalidatePartsLinkMaps()
  4687. {
  4688. lock(m_partsNameToLinkMap)
  4689. {
  4690. m_partsNameToLinkMap.Clear();
  4691. GetLinkNumber_lastname = String.Empty;
  4692. GetLinkNumber_lastnumber = -1;
  4693. }
  4694. }
  4695. public bool CollisionSoundThrottled(int collisionSoundType)
  4696. {
  4697. double time = m_lastCollisionSoundMS;
  4698. // m_lastCollisionSoundMS = Util.GetTimeStampMS();
  4699. // time = m_lastCollisionSoundMS - time;
  4700. double now = Util.GetTimeStampMS();
  4701. time = now - time;
  4702. switch (collisionSoundType)
  4703. {
  4704. case 0: // default sounds
  4705. case 2: // default sounds with volume set by script
  4706. if(time < 300.0)
  4707. return true;
  4708. break;
  4709. case 1: // selected sound
  4710. if(time < 200.0)
  4711. return true;
  4712. break;
  4713. default:
  4714. break;
  4715. }
  4716. m_lastCollisionSoundMS = now;
  4717. return false;
  4718. }
  4719. #endregion
  4720. }
  4721. }