SceneObjectGroup.cs 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552
  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 (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
  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. doc.XmlResolver=null;
  1710. Dictionary<UUID,string> states = new Dictionary<UUID,string>();
  1711. SceneObjectPart[] parts = m_parts.GetArray();
  1712. for (int i = 0; i < parts.Length; i++)
  1713. {
  1714. Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
  1715. foreach (KeyValuePair<UUID, string> kvp in pstates)
  1716. states[kvp.Key] = kvp.Value;
  1717. }
  1718. if (states.Count > 0)
  1719. {
  1720. // Now generate the necessary XML wrappings
  1721. writer.WriteStartElement(String.Empty, "GroupScriptStates", String.Empty);
  1722. foreach (UUID itemid in states.Keys)
  1723. {
  1724. doc.LoadXml(states[itemid]);
  1725. writer.WriteStartElement(String.Empty, "SavedScriptState", String.Empty);
  1726. writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
  1727. writer.WriteRaw(doc.DocumentElement.OuterXml); // Writes ScriptState element
  1728. writer.WriteEndElement(); // End of SavedScriptState
  1729. }
  1730. writer.WriteEndElement(); // End of GroupScriptStates
  1731. }
  1732. }
  1733. public byte GetAttachmentPoint()
  1734. {
  1735. return m_rootPart.Shape.State;
  1736. }
  1737. public void DetachToGround()
  1738. {
  1739. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1740. if (avatar == null)
  1741. return;
  1742. m_rootPart.Shape.LastAttachPoint = m_rootPart.Shape.State;
  1743. m_rootPart.AttachedPos = m_rootPart.OffsetPosition;
  1744. avatar.RemoveAttachment(this);
  1745. Vector3 detachedpos = new Vector3(127f,127f,127f);
  1746. if (avatar == null)
  1747. return;
  1748. detachedpos = avatar.AbsolutePosition;
  1749. FromItemID = UUID.Zero;
  1750. AbsolutePosition = detachedpos;
  1751. AttachedAvatar = UUID.Zero;
  1752. //SceneObjectPart[] parts = m_parts.GetArray();
  1753. //for (int i = 0; i < parts.Length; i++)
  1754. // parts[i].AttachedAvatar = UUID.Zero;
  1755. m_rootPart.SetParentLocalId(0);
  1756. AttachmentPoint = (byte)0;
  1757. // must check if buildind should be true or false here
  1758. // m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false);
  1759. ApplyPhysics();
  1760. HasGroupChanged = true;
  1761. RootPart.Rezzed = DateTime.Now;
  1762. RootPart.RemFlag(PrimFlags.TemporaryOnRez);
  1763. AttachToBackup();
  1764. m_scene.EventManager.TriggerParcelPrimCountTainted();
  1765. m_rootPart.ScheduleFullUpdate();
  1766. m_rootPart.ClearUndoState();
  1767. }
  1768. public void DetachToInventoryPrep()
  1769. {
  1770. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1771. //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
  1772. if (avatar != null)
  1773. {
  1774. //detachedpos = avatar.AbsolutePosition;
  1775. avatar.RemoveAttachment(this);
  1776. }
  1777. AttachedAvatar = UUID.Zero;
  1778. /*SceneObjectPart[] parts = m_parts.GetArray();
  1779. for (int i = 0; i < parts.Length; i++)
  1780. parts[i].AttachedAvatar = UUID.Zero;*/
  1781. m_rootPart.SetParentLocalId(0);
  1782. //m_rootPart.SetAttachmentPoint((byte)0);
  1783. IsAttachment = false;
  1784. AbsolutePosition = m_rootPart.AttachedPos;
  1785. //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
  1786. //AttachToBackup();
  1787. //m_rootPart.ScheduleFullUpdate();
  1788. }
  1789. /// <summary>
  1790. ///
  1791. /// </summary>
  1792. /// <param name="part"></param>
  1793. private void SetPartAsNonRoot(SceneObjectPart part)
  1794. {
  1795. part.ParentID = m_rootPart.LocalId;
  1796. part.ClearUndoState();
  1797. }
  1798. public ushort GetTimeDilation()
  1799. {
  1800. return Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  1801. }
  1802. /// <summary>
  1803. /// Set a part to act as the root part for this scene object
  1804. /// </summary>
  1805. /// <param name="part"></param>
  1806. public void SetRootPart(SceneObjectPart part)
  1807. {
  1808. if (part == null)
  1809. throw new ArgumentNullException("Cannot give SceneObjectGroup a null root SceneObjectPart");
  1810. part.SetParent(this);
  1811. m_rootPart = part;
  1812. if (!IsAttachment)
  1813. part.ParentID = 0;
  1814. part.LinkNum = 0;
  1815. m_parts.Add(m_rootPart.UUID, m_rootPart);
  1816. }
  1817. /// <summary>
  1818. /// Add a new part to this scene object. The part must already be correctly configured.
  1819. /// </summary>
  1820. /// <param name="part"></param>
  1821. public void AddPart(SceneObjectPart part)
  1822. {
  1823. part.SetParent(this);
  1824. m_parts.Add(part.UUID, part);
  1825. part.LinkNum = m_parts.Count;
  1826. if (part.LinkNum == 2)
  1827. RootPart.LinkNum = 1;
  1828. InvalidatePartsLinkMaps();
  1829. }
  1830. /// <summary>
  1831. /// Make sure that every non root part has the proper parent root part local id
  1832. /// </summary>
  1833. private void UpdateParentIDs()
  1834. {
  1835. SceneObjectPart[] parts = m_parts.GetArray();
  1836. for (int i = 0; i < parts.Length; i++)
  1837. {
  1838. SceneObjectPart part = parts[i];
  1839. if (part.UUID != m_rootPart.UUID)
  1840. part.ParentID = m_rootPart.LocalId;
  1841. }
  1842. }
  1843. public void RegenerateFullIDs()
  1844. {
  1845. SceneObjectPart[] parts = m_parts.GetArray();
  1846. for (int i = 0; i < parts.Length; i++)
  1847. parts[i].UUID = UUID.Random();
  1848. }
  1849. // helper provided for parts.
  1850. public int GetSceneMaxUndo()
  1851. {
  1852. if (m_scene != null)
  1853. return m_scene.MaxUndoCount;
  1854. return 5;
  1855. }
  1856. // justincc: I don't believe this hack is needed any longer, especially since the physics
  1857. // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
  1858. // this method was preventing proper reload of scene objects.
  1859. // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects
  1860. // at region startup
  1861. // teravus: After this was removed from the linking algorithm, Linked prims no longer collided
  1862. // properly when non-physical if they havn't been moved. This breaks ALL builds.
  1863. // see: http://opensimulator.org/mantis/view.php?id=3108
  1864. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1865. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1866. // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute
  1867. // Position has been set!
  1868. public void ResetChildPrimPhysicsPositions()
  1869. {
  1870. // Setting this SOG's absolute position also loops through and sets the positions
  1871. // of the SOP's in this SOG's linkset. This has the side affect of making sure
  1872. // the physics world matches the simulated world.
  1873. // AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
  1874. // teravus: AbsolutePosition is NOT a normal property!
  1875. // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
  1876. // jhurliman: Then why is it a property instead of two methods?
  1877. // do only what is supposed to do
  1878. Vector3 groupPosition = m_rootPart.GroupPosition;
  1879. SceneObjectPart[] parts = m_parts.GetArray();
  1880. foreach (SceneObjectPart part in parts)
  1881. {
  1882. if (part != m_rootPart)
  1883. part.GroupPosition = groupPosition;
  1884. }
  1885. }
  1886. public UUID GetPartsFullID(uint localID)
  1887. {
  1888. SceneObjectPart part = GetPart(localID);
  1889. if (part != null)
  1890. {
  1891. return part.UUID;
  1892. }
  1893. return UUID.Zero;
  1894. }
  1895. public void ObjectGrabHandler(uint localId, Vector3 offsetPos, IClientAPI remoteClient)
  1896. {
  1897. if (m_rootPart.LocalId == localId)
  1898. {
  1899. OnGrabGroup(offsetPos, remoteClient);
  1900. }
  1901. else
  1902. {
  1903. SceneObjectPart part = GetPart(localId);
  1904. OnGrabPart(part, offsetPos, remoteClient);
  1905. }
  1906. }
  1907. public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient)
  1908. {
  1909. // m_log.DebugFormat(
  1910. // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}",
  1911. // remoteClient.Name, part.Name, part.LocalId, offsetPos);
  1912. // part.StoreUndoState();
  1913. part.OnGrab(offsetPos, remoteClient);
  1914. }
  1915. public virtual void OnGrabGroup(Vector3 offsetPos, IClientAPI remoteClient)
  1916. {
  1917. m_scene.EventManager.TriggerGroupGrab(UUID, offsetPos, remoteClient.AgentId);
  1918. }
  1919. /// <summary>
  1920. /// Delete this group from its scene.
  1921. /// </summary>
  1922. /// <remarks>
  1923. /// This only handles the in-world consequences of deletion (e.g. any avatars sitting on it are forcibly stood
  1924. /// up and all avatars receive notification of its removal. Removal of the scene object from database backup
  1925. /// must be handled by the caller.
  1926. /// </remarks>
  1927. /// <param name="silent">If true then deletion is not broadcast to clients</param>
  1928. public void DeleteGroupFromScene(bool silent)
  1929. {
  1930. // We need to keep track of this state in case this group is still queued for backup.
  1931. IsDeleted = true;
  1932. DetachFromBackup();
  1933. if(Scene == null) // should not happen unless restart/shutdown ?
  1934. return;
  1935. SceneObjectPart[] parts = m_parts.GetArray();
  1936. for (int i = 0; i < parts.Length; i++)
  1937. {
  1938. SceneObjectPart part = parts[i];
  1939. Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1940. {
  1941. if (!avatar.IsChildAgent && avatar.ParentID == part.LocalId && avatar.ParentUUID == UUID.Zero)
  1942. avatar.StandUp();
  1943. if (!silent)
  1944. {
  1945. part.ClearUpdateSchedule();
  1946. if (part == m_rootPart)
  1947. {
  1948. if (!IsAttachment
  1949. || AttachedAvatar == avatar.ControllingClient.AgentId
  1950. || !HasPrivateAttachmentPoint)
  1951. {
  1952. // Send a kill object immediately
  1953. avatar.ControllingClient.SendKillObject(new List<uint> { part.LocalId });
  1954. //direct enqueue another delayed kill
  1955. avatar.ControllingClient.SendEntityUpdate(part,PrimUpdateFlags.Kill);
  1956. }
  1957. }
  1958. }
  1959. });
  1960. }
  1961. }
  1962. public void AddScriptLPS(int count)
  1963. {
  1964. m_scene.SceneGraph.AddToScriptLPS(count);
  1965. }
  1966. public void AddActiveScriptCount(int count)
  1967. {
  1968. SceneGraph d = m_scene.SceneGraph;
  1969. d.AddActiveScripts(count);
  1970. }
  1971. private const scriptEvents PhysicsNeeedSubsEvents = (
  1972. scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
  1973. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end);
  1974. private scriptEvents lastRootPartPhysEvents = 0;
  1975. public void aggregateScriptEvents()
  1976. {
  1977. PrimFlags objectflagupdate = (PrimFlags)RootPart.GetEffectiveObjectFlags();
  1978. scriptEvents aggregateScriptEvents = 0;
  1979. SceneObjectPart[] parts = m_parts.GetArray();
  1980. for (int i = 0; i < parts.Length; i++)
  1981. {
  1982. SceneObjectPart part = parts[i];
  1983. if (part == null)
  1984. continue;
  1985. if (part != RootPart)
  1986. part.Flags = objectflagupdate;
  1987. aggregateScriptEvents |= part.AggregateScriptEvents;
  1988. }
  1989. m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
  1990. m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
  1991. if (!m_scriptListens_atTarget && !m_scriptListens_notAtTarget)
  1992. {
  1993. lock (m_targets)
  1994. m_targets.Clear();
  1995. m_scene.RemoveGroupTarget(this);
  1996. }
  1997. m_scriptListens_atRotTarget = ((aggregateScriptEvents & scriptEvents.at_rot_target) != 0);
  1998. m_scriptListens_notAtRotTarget = ((aggregateScriptEvents & scriptEvents.not_at_rot_target) != 0);
  1999. if (!m_scriptListens_atRotTarget && !m_scriptListens_notAtRotTarget)
  2000. {
  2001. lock (m_rotTargets)
  2002. m_rotTargets.Clear();
  2003. m_scene.RemoveGroupTarget(this);
  2004. }
  2005. scriptEvents rootPartPhysEvents = RootPart.AggregateScriptEvents;
  2006. rootPartPhysEvents &= PhysicsNeeedSubsEvents;
  2007. if (rootPartPhysEvents != lastRootPartPhysEvents)
  2008. {
  2009. lastRootPartPhysEvents = rootPartPhysEvents;
  2010. for (int i = 0; i < parts.Length; i++)
  2011. {
  2012. SceneObjectPart part = parts[i];
  2013. if (part == null)
  2014. continue;
  2015. part.UpdatePhysicsSubscribedEvents();
  2016. }
  2017. }
  2018. ScheduleGroupForFullUpdate();
  2019. }
  2020. public void SetText(string text, Vector3 color, double alpha)
  2021. {
  2022. Color = Color.FromArgb(0xff - (int) (alpha * 0xff),
  2023. (int) (color.X * 0xff),
  2024. (int) (color.Y * 0xff),
  2025. (int) (color.Z * 0xff));
  2026. Text = text;
  2027. HasGroupChanged = true;
  2028. m_rootPart.ScheduleFullUpdate();
  2029. }
  2030. /// <summary>
  2031. /// Apply physics to this group
  2032. /// </summary>
  2033. public void ApplyPhysics()
  2034. {
  2035. SceneObjectPart[] parts = m_parts.GetArray();
  2036. if (parts.Length > 1)
  2037. {
  2038. ResetChildPrimPhysicsPositions();
  2039. // Apply physics to the root prim
  2040. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true);
  2041. for (int i = 0; i < parts.Length; i++)
  2042. {
  2043. SceneObjectPart part = parts[i];
  2044. if (part.LocalId != m_rootPart.LocalId)
  2045. part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true);
  2046. }
  2047. // Hack to get the physics scene geometries in the right spot
  2048. // ResetChildPrimPhysicsPositions();
  2049. if (m_rootPart.PhysActor != null)
  2050. m_rootPart.PhysActor.Building = false;
  2051. }
  2052. else
  2053. {
  2054. // Apply physics to the root prim
  2055. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false);
  2056. }
  2057. }
  2058. public void SetOwnerId(UUID userId)
  2059. {
  2060. ForEachPart(delegate(SceneObjectPart part)
  2061. {
  2062. if (part.OwnerID != userId)
  2063. {
  2064. if(part.GroupID != part.OwnerID)
  2065. part.LastOwnerID = part.OwnerID;
  2066. part.OwnerID = userId;
  2067. }
  2068. });
  2069. }
  2070. public void ForEachPart(Action<SceneObjectPart> whatToDo)
  2071. {
  2072. SceneObjectPart[] parts = m_parts.GetArray();
  2073. for (int i = 0; i < parts.Length; i++)
  2074. whatToDo(parts[i]);
  2075. }
  2076. #region Events
  2077. /// <summary>
  2078. /// Processes backup.
  2079. /// </summary>
  2080. /// <param name="datastore"></param>
  2081. public virtual void ProcessBackup(ISimulationDataService datastore, bool forcedBackup)
  2082. {
  2083. if (!Backup)
  2084. {
  2085. // m_log.DebugFormat(
  2086. // "[WATER WARS]: Ignoring backup of {0} {1} since object is not marked to be backed up", Name, UUID);
  2087. return;
  2088. }
  2089. if (IsDeleted || inTransit || UUID == UUID.Zero)
  2090. {
  2091. // m_log.DebugFormat(
  2092. // "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID);
  2093. return;
  2094. }
  2095. if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2096. return;
  2097. // Since this is the top of the section of call stack for backing up a particular scene object, don't let
  2098. // any exception propogate upwards.
  2099. try
  2100. {
  2101. // if shutting down then there will be nothing to handle the return so leave till next restart
  2102. if (!m_scene.ShuttingDown &&
  2103. m_scene.LoginsEnabled && // We're starting up or doing maintenance, don't mess with things
  2104. !m_scene.LoadingPrims) // Land may not be valid yet
  2105. {
  2106. ILandObject parcel = m_scene.LandChannel.GetLandObject(
  2107. m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
  2108. if (parcel != null && parcel.LandData != null &&
  2109. parcel.LandData.OtherCleanTime != 0)
  2110. {
  2111. if (parcel.LandData.OwnerID != OwnerID &&
  2112. (parcel.LandData.GroupID != GroupID ||
  2113. parcel.LandData.GroupID == UUID.Zero))
  2114. {
  2115. if ((DateTime.UtcNow - RootPart.Rezzed).TotalMinutes >
  2116. parcel.LandData.OtherCleanTime)
  2117. {
  2118. // don't autoreturn if we have a sitting avatar
  2119. // mantis 7828 (but none the provided patchs)
  2120. if(GetSittingAvatarsCount() > 0)
  2121. {
  2122. // do not respect npcs
  2123. List<ScenePresence> sitters = GetSittingAvatars();
  2124. foreach(ScenePresence sp in sitters)
  2125. {
  2126. if(!sp.IsDeleted && !sp.IsNPC && sp.IsSatOnObject)
  2127. return;
  2128. }
  2129. }
  2130. DetachFromBackup();
  2131. m_log.DebugFormat(
  2132. "[SCENE OBJECT GROUP]: Returning object {0} due to parcel autoreturn",
  2133. RootPart.UUID);
  2134. m_scene.AddReturn(OwnerID == GroupID ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn");
  2135. m_scene.DeRezObjects(null, new List<uint>() { RootPart.LocalId }, UUID.Zero,
  2136. DeRezAction.Return, UUID.Zero, false);
  2137. return;
  2138. }
  2139. }
  2140. }
  2141. }
  2142. if (m_scene.UseBackup && HasGroupChanged)
  2143. {
  2144. // don't backup while it's selected or you're asking for changes mid stream.
  2145. if (isTimeToPersist() || forcedBackup)
  2146. {
  2147. if (m_rootPart.PhysActor != null &&
  2148. (!m_rootPart.PhysActor.IsPhysical))
  2149. {
  2150. // Possible ghost prim
  2151. if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
  2152. {
  2153. foreach (SceneObjectPart part in m_parts.GetArray())
  2154. {
  2155. // Re-set physics actor positions and
  2156. // orientations
  2157. part.GroupPosition = m_rootPart.GroupPosition;
  2158. }
  2159. }
  2160. }
  2161. // m_log.DebugFormat(
  2162. // "[SCENE]: Storing {0}, {1} in {2}",
  2163. // Name, UUID, m_scene.RegionInfo.RegionName);
  2164. if (RootPart.Shape.PCode == 9 && RootPart.Shape.State != 0)
  2165. {
  2166. RootPart.Shape.LastAttachPoint = RootPart.Shape.State;
  2167. RootPart.Shape.State = 0;
  2168. ScheduleGroupForFullUpdate();
  2169. }
  2170. SceneObjectGroup backup_group = Copy(false);
  2171. backup_group.RootPart.Velocity = RootPart.Velocity;
  2172. backup_group.RootPart.Acceleration = RootPart.Acceleration;
  2173. backup_group.RootPart.AngularVelocity = RootPart.AngularVelocity;
  2174. backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
  2175. HasGroupChanged = false;
  2176. GroupContainsForeignPrims = false;
  2177. m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
  2178. datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
  2179. backup_group.ForEachPart(delegate(SceneObjectPart part)
  2180. {
  2181. part.Inventory.ProcessInventoryBackup(datastore);
  2182. if(part.KeyframeMotion != null)
  2183. {
  2184. part.KeyframeMotion.Delete();
  2185. part.KeyframeMotion = null;
  2186. }
  2187. });
  2188. backup_group.Clear();
  2189. backup_group = null;
  2190. }
  2191. // else
  2192. // {
  2193. // m_log.DebugFormat(
  2194. // "[SCENE]: Did not update persistence of object {0} {1}, selected = {2}",
  2195. // Name, UUID, IsSelected);
  2196. // }
  2197. }
  2198. }
  2199. catch (Exception e)
  2200. {
  2201. m_log.ErrorFormat(
  2202. "[SCENE]: Storing of {0}, {1} in {2} failed with exception {3}{4}",
  2203. Name, UUID, m_scene.RegionInfo.RegionName, e.Message, e.StackTrace);
  2204. }
  2205. }
  2206. #endregion
  2207. /// <summary>
  2208. /// Send the parts of this SOG to a single client
  2209. /// </summary>
  2210. /// <remarks>
  2211. /// Used when the client initially connects and when client sends RequestPrim packet
  2212. /// </remarks>
  2213. /// <param name="remoteClient"></param>
  2214. public void SendFullUpdateToClient(IClientAPI remoteClient)
  2215. {
  2216. RootPart.SendFullUpdate(remoteClient);
  2217. SceneObjectPart[] parts = m_parts.GetArray();
  2218. for (int i = 0; i < parts.Length; i++)
  2219. {
  2220. SceneObjectPart part = parts[i];
  2221. if (part != RootPart)
  2222. part.SendFullUpdate(remoteClient);
  2223. }
  2224. }
  2225. #region Copying
  2226. /// <summary>
  2227. /// Duplicates this object, including operations such as physics set up and attaching to the backup event.
  2228. /// </summary>
  2229. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  2230. /// <returns></returns>
  2231. public SceneObjectGroup Copy(bool userExposed)
  2232. {
  2233. m_dupeInProgress = true;
  2234. SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone();
  2235. dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
  2236. // a copy isnt backedup
  2237. dupe.Backup = false;
  2238. dupe.InvalidBoundsRadius();
  2239. // a copy is not in transit hopefully
  2240. dupe.inTransit = false;
  2241. // new group as no sitting avatars
  2242. dupe.m_sittingAvatars = new List<ScenePresence>();
  2243. dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
  2244. dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
  2245. if (userExposed)
  2246. dupe.m_rootPart.TrimPermissions();
  2247. List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
  2248. partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
  2249. {
  2250. return p1.LinkNum.CompareTo(p2.LinkNum);
  2251. }
  2252. );
  2253. foreach (SceneObjectPart part in partList)
  2254. {
  2255. SceneObjectPart newPart;
  2256. if (part.UUID != m_rootPart.UUID)
  2257. {
  2258. newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed);
  2259. newPart.LinkNum = part.LinkNum;
  2260. // if (userExposed)
  2261. newPart.ParentID = dupe.m_rootPart.LocalId;
  2262. }
  2263. else
  2264. {
  2265. newPart = dupe.m_rootPart;
  2266. }
  2267. /*
  2268. bool isphys = ((newPart.Flags & PrimFlags.Physics) != 0);
  2269. bool isphan = ((newPart.Flags & PrimFlags.Phantom) != 0);
  2270. // Need to duplicate the physics actor as well
  2271. if (userExposed && (isphys || !isphan || newPart.VolumeDetectActive))
  2272. {
  2273. PrimitiveBaseShape pbs = newPart.Shape;
  2274. newPart.PhysActor
  2275. = m_scene.PhysicsScene.AddPrimShape(
  2276. string.Format("{0}/{1}", newPart.Name, newPart.UUID),
  2277. pbs,
  2278. newPart.AbsolutePosition,
  2279. newPart.Scale,
  2280. newPart.GetWorldRotation(),
  2281. isphys,
  2282. isphan,
  2283. newPart.LocalId);
  2284. newPart.DoPhysicsPropertyUpdate(isphys, true);
  2285. */
  2286. if (userExposed)
  2287. newPart.ApplyPhysics((uint)newPart.Flags,newPart.VolumeDetectActive,true);
  2288. // }
  2289. // copy keyframemotion
  2290. if (part.KeyframeMotion != null)
  2291. newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe);
  2292. }
  2293. if (userExposed)
  2294. {
  2295. // done above dupe.UpdateParentIDs();
  2296. if (dupe.m_rootPart.PhysActor != null)
  2297. dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building
  2298. dupe.InvalidateDeepEffectivePerms();
  2299. dupe.HasGroupChanged = true;
  2300. dupe.AttachToBackup();
  2301. dupe.ScheduleGroupForFullUpdate();
  2302. }
  2303. dupe.InvalidatePartsLinkMaps();
  2304. m_dupeInProgress = false;
  2305. return dupe;
  2306. }
  2307. /// <summary>
  2308. /// Copy the given part as the root part of this scene object.
  2309. /// </summary>
  2310. /// <param name="part"></param>
  2311. /// <param name="cAgentID"></param>
  2312. /// <param name="cGroupID"></param>
  2313. public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2314. {
  2315. SceneObjectPart newpart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed);
  2316. // SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed);
  2317. // newpart.LocalId = m_scene.AllocateLocalId();
  2318. SetRootPart(newpart);
  2319. if (userExposed)
  2320. RootPart.Velocity = Vector3.Zero; // In case source is moving
  2321. }
  2322. public void ScriptSetPhysicsStatus(bool usePhysics)
  2323. {
  2324. if (usePhysics)
  2325. {
  2326. if (RootPart.KeyframeMotion != null)
  2327. RootPart.KeyframeMotion.Stop();
  2328. RootPart.KeyframeMotion = null;
  2329. }
  2330. UpdateFlags(usePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
  2331. }
  2332. public void ScriptSetTemporaryStatus(bool makeTemporary)
  2333. {
  2334. UpdateFlags(UsesPhysics, makeTemporary, IsPhantom, IsVolumeDetect);
  2335. }
  2336. public void ScriptSetPhantomStatus(bool makePhantom)
  2337. {
  2338. UpdateFlags(UsesPhysics, IsTemporary, makePhantom, IsVolumeDetect);
  2339. }
  2340. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  2341. {
  2342. UpdateFlags(UsesPhysics, IsTemporary, IsPhantom, makeVolumeDetect);
  2343. }
  2344. public void applyImpulse(Vector3 impulse)
  2345. {
  2346. if (IsAttachment)
  2347. {
  2348. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2349. if (avatar != null)
  2350. {
  2351. avatar.PushForce(impulse);
  2352. }
  2353. }
  2354. else
  2355. {
  2356. PhysicsActor pa = RootPart.PhysActor;
  2357. if (pa != null)
  2358. {
  2359. // false to be applied as a impulse
  2360. pa.AddForce(impulse, false);
  2361. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2362. }
  2363. }
  2364. }
  2365. public void ApplyAngularImpulse(Vector3 impulse)
  2366. {
  2367. PhysicsActor pa = RootPart.PhysActor;
  2368. if (pa != null)
  2369. {
  2370. if (!IsAttachment)
  2371. {
  2372. // false to be applied as a impulse
  2373. pa.AddAngularForce(impulse, false);
  2374. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2375. }
  2376. }
  2377. }
  2378. public Vector3 GetTorque()
  2379. {
  2380. return RootPart.Torque;
  2381. }
  2382. // This is used by llMoveToTarget() in an attached object
  2383. public void MoveToTarget(Vector3 target, float tau)
  2384. {
  2385. if (IsAttachment)
  2386. {
  2387. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2388. if (avatar != null)
  2389. avatar.MoveToTarget(target, false, false, tau);
  2390. }
  2391. else
  2392. {
  2393. PhysicsActor pa = RootPart.PhysActor;
  2394. if (pa != null)
  2395. {
  2396. pa.PIDTarget = target;
  2397. pa.PIDTau = tau;
  2398. pa.PIDActive = true;
  2399. }
  2400. }
  2401. }
  2402. public void StopMoveToTarget()
  2403. {
  2404. if (IsAttachment)
  2405. {
  2406. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2407. if (avatar != null)
  2408. {
  2409. avatar.ResetMoveToTarget();
  2410. }
  2411. }
  2412. else
  2413. {
  2414. PhysicsActor pa = RootPart.PhysActor;
  2415. if (pa != null)
  2416. pa.PIDActive = false;
  2417. RootPart.ScheduleTerseUpdate(); // send a stop information
  2418. }
  2419. }
  2420. public void RotLookAt(Quaternion target, float strength, float damping)
  2421. {
  2422. if(IsDeleted)
  2423. return;
  2424. // non physical is handle in LSL api
  2425. if(!UsesPhysics || IsAttachment)
  2426. return;
  2427. SceneObjectPart rootpart = m_rootPart;
  2428. if (rootpart != null)
  2429. {
  2430. /* physics still doesnt suport this
  2431. if (rootpart.PhysActor != null)
  2432. {
  2433. rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
  2434. rootpart.PhysActor.APIDStrength = strength;
  2435. rootpart.PhysActor.APIDDamping = damping;
  2436. rootpart.PhysActor.APIDActive = true;
  2437. }
  2438. */
  2439. // so do it in rootpart
  2440. rootpart.RotLookAt(target, strength, damping);
  2441. }
  2442. }
  2443. public void StartLookAt(Quaternion target, float strength, float damping)
  2444. {
  2445. if(IsDeleted)
  2446. return;
  2447. // non physical is done by LSL APi
  2448. if(!UsesPhysics || IsAttachment)
  2449. return;
  2450. if (m_rootPart != null)
  2451. m_rootPart.RotLookAt(target, strength, damping);
  2452. }
  2453. public void StopLookAt()
  2454. {
  2455. SceneObjectPart rootpart = m_rootPart;
  2456. if (rootpart != null)
  2457. {
  2458. if (rootpart.PhysActor != null)
  2459. {
  2460. rootpart.PhysActor.APIDActive = false;
  2461. }
  2462. rootpart.StopLookAt();
  2463. }
  2464. }
  2465. /// <summary>
  2466. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2467. /// </summary>
  2468. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2469. /// <param name="hoverType">Determines what the height is relative to </param>
  2470. /// <param name="tau">Number of seconds over which to reach target</param>
  2471. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2472. {
  2473. PhysicsActor pa = null;
  2474. if(IsAttachment)
  2475. {
  2476. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2477. if (avatar != null)
  2478. pa = avatar.PhysicsActor;
  2479. }
  2480. else
  2481. pa = RootPart.PhysActor;
  2482. if (pa != null)
  2483. {
  2484. if (height != 0f)
  2485. {
  2486. pa.PIDHoverHeight = height;
  2487. pa.PIDHoverType = hoverType;
  2488. pa.PIDHoverTau = tau;
  2489. pa.PIDHoverActive = true;
  2490. }
  2491. else
  2492. {
  2493. pa.PIDHoverActive = false;
  2494. }
  2495. }
  2496. }
  2497. /// <summary>
  2498. /// Set the owner of all linkset.
  2499. /// </summary>
  2500. /// <param name="cAgentID"></param>
  2501. /// <param name="cGroupID"></param>
  2502. public void SetOwner(UUID cAgentID, UUID cGroupID)
  2503. {
  2504. SceneObjectPart rpart = RootPart;
  2505. UUID oldowner = rpart.OwnerID;
  2506. ForEachPart(delegate(SceneObjectPart part)
  2507. {
  2508. if(part.GroupID != part.OwnerID)
  2509. part.LastOwnerID = part.OwnerID;
  2510. part.OwnerID = cAgentID;
  2511. part.GroupID = cGroupID;
  2512. });
  2513. if (oldowner != cAgentID)
  2514. {
  2515. // Apply Next Owner Permissions if we're not bypassing permissions
  2516. if (!m_scene.Permissions.BypassPermissions())
  2517. {
  2518. ApplyNextOwnerPermissions();
  2519. InvalidateEffectivePerms();
  2520. }
  2521. }
  2522. rpart.ScheduleFullUpdate();
  2523. }
  2524. /// <summary>
  2525. /// Make a copy of the given part.
  2526. /// </summary>
  2527. /// <param name="part"></param>
  2528. /// <param name="cAgentID"></param>
  2529. /// <param name="cGroupID"></param>
  2530. public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2531. {
  2532. SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
  2533. // SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed);
  2534. // newPart.LocalId = m_scene.AllocateLocalId();
  2535. AddPart(newPart);
  2536. SetPartAsNonRoot(newPart);
  2537. return newPart;
  2538. }
  2539. /// <summary>
  2540. /// Reset the UUIDs for all the prims that make up this group.
  2541. /// </summary>
  2542. /// <remarks>
  2543. /// This is called by methods which want to add a new group to an existing scene, in order
  2544. /// to ensure that there are no clashes with groups already present.
  2545. /// </remarks>
  2546. public void ResetIDs()
  2547. {
  2548. lock (m_parts.SyncRoot)
  2549. {
  2550. List<SceneObjectPart> partsList = new List<SceneObjectPart>(m_parts.GetArray());
  2551. m_parts.Clear();
  2552. foreach (SceneObjectPart part in partsList)
  2553. {
  2554. part.ResetIDs(part.LinkNum); // Don't change link nums
  2555. m_parts.Add(part.UUID, part);
  2556. }
  2557. }
  2558. }
  2559. /// <summary>
  2560. ///
  2561. /// </summary>
  2562. /// <param name="part"></param>
  2563. public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags)
  2564. {
  2565. remoteClient.SendObjectPropertiesFamilyData(RootPart, RequestFlags);
  2566. // remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask,
  2567. // RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask,
  2568. // RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category,
  2569. // RootPart.CreatorID, RootPart.Name, RootPart.Description);
  2570. }
  2571. public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  2572. {
  2573. part.OwnerID = cAgentID;
  2574. part.GroupID = cGroupID;
  2575. }
  2576. #endregion
  2577. public override void Update()
  2578. {
  2579. // Check that the group was not deleted before the scheduled update
  2580. // FIXME: This is merely a temporary measure to reduce the incidence of failure when
  2581. // an object has been deleted from a scene before update was processed.
  2582. // A more fundamental overhaul of the update mechanism is required to eliminate all
  2583. // the race conditions.
  2584. if (IsDeleted || inTransit)
  2585. return;
  2586. // Even temporary objects take part in physics (e.g. temp-on-rez bullets)
  2587. //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2588. // return;
  2589. // If we somehow got here to updating the SOG and its root part is not scheduled for update,
  2590. // check to see if the physical position or rotation warrant an update.
  2591. /*
  2592. if (m_rootPart.UpdateFlag == UpdateRequired.NONE)
  2593. {
  2594. // rootpart SendScheduledUpdates will check if a update is needed
  2595. m_rootPart.UpdateFlag = UpdateRequired.TERSE;
  2596. }
  2597. */
  2598. if (IsAttachment)
  2599. {
  2600. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2601. if (sp != null)
  2602. {
  2603. sp.SendAttachmentScheduleUpdate(this);
  2604. return;
  2605. }
  2606. }
  2607. // while physics doesn't suports LookAt, we do it in RootPart
  2608. if (!IsSelected)
  2609. RootPart.UpdateLookAt();
  2610. double now = Util.GetTimeStampMS();
  2611. RootPart.SendScheduledUpdates(now);
  2612. SceneObjectPart[] parts = m_parts.GetArray();
  2613. for (int i = 0; i < parts.Length; i++)
  2614. {
  2615. SceneObjectPart part = parts[i];
  2616. if(part != RootPart)
  2617. part.SendScheduledUpdates(now);
  2618. }
  2619. }
  2620. /// <summary>
  2621. /// Schedule a full update for this scene object to all interested viewers.
  2622. /// </summary>
  2623. /// <remarks>
  2624. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2625. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2626. /// code will set this anyway when some object properties are changed.
  2627. /// </remarks>
  2628. public void ScheduleGroupForFullUpdate()
  2629. {
  2630. // if (IsAttachment)
  2631. // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
  2632. checkAtTargets();
  2633. RootPart.ScheduleFullUpdate();
  2634. SceneObjectPart[] parts = m_parts.GetArray();
  2635. for (int i = 0; i < parts.Length; i++)
  2636. {
  2637. SceneObjectPart part = parts[i];
  2638. if (part != RootPart)
  2639. part.ScheduleFullUpdate();
  2640. }
  2641. }
  2642. /// <summary>
  2643. /// Schedule a terse update for this scene object to all interested viewers.
  2644. /// </summary>
  2645. /// <remarks>
  2646. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2647. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2648. /// code will set this anyway when some object properties are changed.
  2649. /// </remarks>
  2650. public void ScheduleGroupForTerseUpdate()
  2651. {
  2652. // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID);
  2653. SceneObjectPart[] parts = m_parts.GetArray();
  2654. for (int i = 0; i < parts.Length; i++)
  2655. parts[i].ScheduleTerseUpdate();
  2656. }
  2657. /// <summary>
  2658. /// Immediately send a full update for this scene object.
  2659. /// </summary>
  2660. public void SendGroupFullUpdate()
  2661. {
  2662. if (IsDeleted)
  2663. return;
  2664. // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
  2665. if (IsAttachment)
  2666. {
  2667. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2668. if (sp != null)
  2669. {
  2670. sp.SendAttachmentUpdate(this,UpdateRequired.FULL);
  2671. return;
  2672. }
  2673. }
  2674. RootPart.SendFullUpdateToAllClientsInternal();
  2675. SceneObjectPart[] parts = m_parts.GetArray();
  2676. for (int i = 0; i < parts.Length; i++)
  2677. {
  2678. SceneObjectPart part = parts[i];
  2679. if (part != RootPart)
  2680. part.SendFullUpdateToAllClientsInternal();
  2681. }
  2682. }
  2683. /// <summary>
  2684. /// Immediately send an update for this scene object's root prim only.
  2685. /// This is for updates regarding the object as a whole, and none of its parts in particular.
  2686. /// Note: this may not be used by opensim (it probably should) but it's used by
  2687. /// external modules.
  2688. /// </summary>
  2689. public void SendGroupRootTerseUpdate()
  2690. {
  2691. if (IsDeleted || inTransit)
  2692. return;
  2693. RootPart.SendTerseUpdateToAllClients();
  2694. }
  2695. public void QueueForUpdateCheck()
  2696. {
  2697. if (m_scene == null) // Need to check here as it's null during object creation
  2698. return;
  2699. m_scene.SceneGraph.AddToUpdateList(this);
  2700. }
  2701. /// <summary>
  2702. /// Immediately send a terse update for this scene object.
  2703. /// </summary>
  2704. public void SendGroupTerseUpdate()
  2705. {
  2706. if (IsDeleted || inTransit)
  2707. return;
  2708. if (IsAttachment)
  2709. {
  2710. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2711. if (sp != null)
  2712. {
  2713. sp.SendAttachmentUpdate(this, UpdateRequired.TERSE);
  2714. return;
  2715. }
  2716. }
  2717. SceneObjectPart[] parts = m_parts.GetArray();
  2718. for (int i = 0; i < parts.Length; i++)
  2719. parts[i].SendTerseUpdateToAllClientsInternal();
  2720. }
  2721. /// <summary>
  2722. /// Send metadata about the root prim (name, description, sale price, permissions, etc.) to a client.
  2723. /// </summary>
  2724. /// <param name="client"></param>
  2725. public void SendPropertiesToClient(IClientAPI client)
  2726. {
  2727. m_rootPart.SendPropertiesToClient(client);
  2728. }
  2729. #region SceneGroupPart Methods
  2730. /// <summary>
  2731. /// Get the child part by LinkNum
  2732. /// </summary>
  2733. /// <param name="linknum"></param>
  2734. /// <returns>null if no child part with that linknum or child part</returns>
  2735. public SceneObjectPart GetLinkNumPart(int linknum)
  2736. {
  2737. SceneObjectPart[] parts = m_parts.GetArray();
  2738. for (int i = 0; i < parts.Length; i++)
  2739. {
  2740. if (parts[i].LinkNum == linknum)
  2741. return parts[i];
  2742. }
  2743. return null;
  2744. }
  2745. /// <summary>
  2746. /// Get a part with a given UUID
  2747. /// </summary>
  2748. /// <param name="primID"></param>
  2749. /// <returns>null if a part with the primID was not found</returns>
  2750. public SceneObjectPart GetPart(UUID primID)
  2751. {
  2752. SceneObjectPart childPart;
  2753. m_parts.TryGetValue(primID, out childPart);
  2754. return childPart;
  2755. }
  2756. /// <summary>
  2757. /// Get a part with a given local ID
  2758. /// </summary>
  2759. /// <param name="localID"></param>
  2760. /// <returns>null if a part with the local ID was not found</returns>
  2761. public SceneObjectPart GetPart(uint localID)
  2762. {
  2763. SceneObjectPart[] parts = m_parts.GetArray();
  2764. for (int i = 0; i < parts.Length; i++)
  2765. {
  2766. if (parts[i].LocalId == localID)
  2767. return parts[i];
  2768. }
  2769. return null;
  2770. }
  2771. #endregion
  2772. #region Packet Handlers
  2773. /// <summary>
  2774. /// Link the prims in a given group to this group
  2775. /// </summary>
  2776. /// <remarks>
  2777. /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads.
  2778. /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition.
  2779. /// </remarks>
  2780. /// <param name="objectGroup">The group of prims which should be linked to this group</param>
  2781. public void LinkToGroup(SceneObjectGroup objectGroup)
  2782. {
  2783. LinkToGroup(objectGroup, false);
  2784. }
  2785. // Link an existing group to this group.
  2786. // The group being linked need not be a linkset -- it can have just one prim.
  2787. public void LinkToGroup(SceneObjectGroup objectGroup, bool insert)
  2788. {
  2789. // m_log.DebugFormat(
  2790. // "[SCENE OBJECT GROUP]: Linking group with root part {0}, {1} to group with root part {2}, {3}",
  2791. // objectGroup.RootPart.Name, objectGroup.RootPart.UUID, RootPart.Name, RootPart.UUID);
  2792. // Linking to ourselves is not a valid operation.
  2793. if (objectGroup == this)
  2794. return;
  2795. // If the configured linkset capacity is greater than zero,
  2796. // and the new linkset would have a prim count higher than this
  2797. // value, do not link it.
  2798. if (m_scene.m_linksetCapacity > 0 &&
  2799. (PrimCount + objectGroup.PrimCount) >
  2800. m_scene.m_linksetCapacity)
  2801. {
  2802. m_log.DebugFormat(
  2803. "[SCENE OBJECT GROUP]: Cannot link group with root" +
  2804. " part {0}, {1} ({2} prims) to group with root part" +
  2805. " {3}, {4} ({5} prims) because the new linkset" +
  2806. " would exceed the configured maximum of {6}",
  2807. objectGroup.RootPart.Name, objectGroup.RootPart.UUID,
  2808. objectGroup.PrimCount, RootPart.Name, RootPart.UUID,
  2809. PrimCount, m_scene.m_linksetCapacity);
  2810. return;
  2811. }
  2812. // physical prims count limit
  2813. // not very eficient :(
  2814. if (UsesPhysics && m_scene.m_linksetPhysCapacity > 0 && (PrimCount + objectGroup.PrimCount) >
  2815. m_scene.m_linksetPhysCapacity)
  2816. {
  2817. int cntr = 0;
  2818. foreach (SceneObjectPart part in Parts)
  2819. {
  2820. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2821. cntr++;
  2822. }
  2823. foreach (SceneObjectPart part in objectGroup.Parts)
  2824. {
  2825. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2826. cntr++;
  2827. }
  2828. if (cntr > m_scene.m_linksetPhysCapacity)
  2829. {
  2830. // cancel physics
  2831. RootPart.Flags &= ~PrimFlags.Physics;
  2832. ApplyPhysics();
  2833. }
  2834. }
  2835. // 'linkPart' == the root of the group being linked into this group
  2836. SceneObjectPart linkPart = objectGroup.m_rootPart;
  2837. if (m_rootPart.PhysActor != null)
  2838. m_rootPart.PhysActor.Building = true;
  2839. if (linkPart.PhysActor != null)
  2840. linkPart.PhysActor.Building = true;
  2841. // physics flags from group to be applied to linked parts
  2842. bool grpusephys = UsesPhysics;
  2843. bool grptemporary = IsTemporary;
  2844. // Remember where the group being linked thought it was
  2845. Vector3 oldGroupPosition = linkPart.GroupPosition;
  2846. Quaternion oldRootRotation = linkPart.RotationOffset;
  2847. // A linked SOP remembers its location and rotation relative to the root of a group.
  2848. // Convert the root of the group being linked to be relative to the
  2849. // root of the group being linked to.
  2850. // Note: Some of the assignments have complex side effects.
  2851. // First move the new group's root SOP's position to be relative to ours
  2852. // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not,
  2853. // this code can be reordered to have a more logical flow.)
  2854. linkPart.setOffsetPosition(linkPart.GroupPosition - AbsolutePosition);
  2855. // Assign the new parent to the root of the old group
  2856. linkPart.ParentID = m_rootPart.LocalId;
  2857. // Now that it's a child, it's group position is our root position
  2858. linkPart.setGroupPosition(AbsolutePosition);
  2859. // Rotate the linking root SOP's position to be relative to the new root prim
  2860. Quaternion parentRot = m_rootPart.RotationOffset;
  2861. // Make the linking root SOP's rotation relative to the new root prim
  2862. Quaternion oldRot = linkPart.RotationOffset;
  2863. Quaternion newRot = Quaternion.Conjugate(parentRot) * oldRot;
  2864. linkPart.setRotationOffset(newRot);
  2865. Vector3 axPos = linkPart.OffsetPosition;
  2866. axPos *= Quaternion.Conjugate(parentRot);
  2867. linkPart.OffsetPosition = axPos;
  2868. // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset.
  2869. // Now that we know this SOG has at least two SOPs in it, the new root
  2870. // SOP becomes the first in the linkset.
  2871. if (m_rootPart.LinkNum == 0)
  2872. m_rootPart.LinkNum = 1;
  2873. lock (m_parts.SyncRoot)
  2874. {
  2875. // Calculate the new link number for the old root SOP
  2876. int linkNum;
  2877. if (insert)
  2878. {
  2879. linkNum = 2;
  2880. int insertSize = objectGroup.PrimCount;
  2881. foreach (SceneObjectPart part in Parts)
  2882. {
  2883. if (part.LinkNum > 1)
  2884. part.LinkNum += insertSize;
  2885. }
  2886. }
  2887. else
  2888. {
  2889. linkNum = PrimCount + 1;
  2890. }
  2891. // Add the old root SOP as a part in our group's list
  2892. m_parts.Add(linkPart.UUID, linkPart);
  2893. linkPart.SetParent(this);
  2894. m_scene.updateScenePartGroup(linkPart, this);
  2895. linkPart.CreateSelected = true;
  2896. // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
  2897. linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true);
  2898. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2899. if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2900. {
  2901. linkPart.PhysActor.link(m_rootPart.PhysActor);
  2902. this.Scene.PhysicsScene.AddPhysicsActorTaint(linkPart.PhysActor);
  2903. }
  2904. linkPart.LinkNum = linkNum++;
  2905. linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  2906. // Get a list of the SOP's in the source group in order of their linknum's.
  2907. SceneObjectPart[] ogParts = objectGroup.Parts;
  2908. Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b)
  2909. {
  2910. return a.LinkNum - b.LinkNum;
  2911. });
  2912. // Add each of the SOP's from the source linkset to our linkset
  2913. for (int i = 0; i < ogParts.Length; i++)
  2914. {
  2915. SceneObjectPart part = ogParts[i];
  2916. if (part.UUID != objectGroup.m_rootPart.UUID)
  2917. {
  2918. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  2919. // Update the physics flags for the newly added SOP
  2920. // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??)
  2921. part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true);
  2922. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2923. if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2924. {
  2925. part.PhysActor.link(m_rootPart.PhysActor);
  2926. this.Scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
  2927. }
  2928. }
  2929. part.ClearUndoState();
  2930. }
  2931. }
  2932. // Now that we've aquired all of the old SOG's parts, remove the old SOG from the scene.
  2933. m_scene.UnlinkSceneObject(objectGroup, true);
  2934. objectGroup.IsDeleted = true;
  2935. objectGroup.m_parts.Clear();
  2936. // Can't do this yet since backup still makes use of the root part without any synchronization
  2937. // objectGroup.m_rootPart = null;
  2938. // If linking prims with different permissions, fix them
  2939. AdjustChildPrimPermissions(false);
  2940. GroupContainsForeignPrims = true;
  2941. AttachToBackup();
  2942. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  2943. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  2944. // unmoved prims!
  2945. ResetChildPrimPhysicsPositions();
  2946. InvalidBoundsRadius();
  2947. InvalidatePartsLinkMaps();
  2948. if (m_rootPart.PhysActor != null)
  2949. m_rootPart.PhysActor.Building = false;
  2950. //HasGroupChanged = true;
  2951. //ScheduleGroupForFullUpdate();
  2952. }
  2953. /// <summary>
  2954. /// Delink the given prim from this group. The delinked prim is established as
  2955. /// an independent SceneObjectGroup.
  2956. /// </summary>
  2957. /// <remarks>
  2958. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2959. /// condition. But currently there is no
  2960. /// alternative method that does take a lonk to delink a single prim.
  2961. /// </remarks>
  2962. /// <param name="partID"></param>
  2963. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2964. public SceneObjectGroup DelinkFromGroup(uint partID)
  2965. {
  2966. return DelinkFromGroup(partID, true);
  2967. }
  2968. /// <summary>
  2969. /// Delink the given prim from this group. The delinked prim is established as
  2970. /// an independent SceneObjectGroup.
  2971. /// </summary>
  2972. /// <remarks>
  2973. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2974. /// condition. But currently there is no
  2975. /// alternative method that does take a lonk to delink a single prim.
  2976. /// </remarks>
  2977. /// <param name="partID"></param>
  2978. /// <param name="sendEvents"></param>
  2979. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2980. public SceneObjectGroup DelinkFromGroup(uint partID, bool sendEvents)
  2981. {
  2982. SceneObjectPart linkPart = GetPart(partID);
  2983. if (linkPart != null)
  2984. {
  2985. return DelinkFromGroup(linkPart, sendEvents);
  2986. }
  2987. else
  2988. {
  2989. m_log.WarnFormat("[SCENE OBJECT GROUP]: " +
  2990. "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}",
  2991. partID, LocalId, UUID);
  2992. return null;
  2993. }
  2994. }
  2995. /// <summary>
  2996. /// Delink the given prim from this group. The delinked prim is established as
  2997. /// an independent SceneObjectGroup.
  2998. /// </summary>
  2999. /// <remarks>
  3000. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  3001. /// condition. But currently there is no
  3002. /// alternative method that does take a lock to delink a single prim.
  3003. /// </remarks>
  3004. /// <param name="partID"></param>
  3005. /// <param name="sendEvents"></param>
  3006. /// <returns>The object group of the newly delinked prim.</returns>
  3007. public SceneObjectGroup DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents)
  3008. {
  3009. // m_log.DebugFormat(
  3010. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3011. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3012. if (m_rootPart.PhysActor != null)
  3013. m_rootPart.PhysActor.Building = true;
  3014. linkPart.ClearUndoState();
  3015. Vector3 worldPos = linkPart.GetWorldPosition();
  3016. Quaternion worldRot = linkPart.GetWorldRotation();
  3017. // Remove the part from this object
  3018. lock (m_parts.SyncRoot)
  3019. {
  3020. m_parts.Remove(linkPart.UUID);
  3021. SceneObjectPart[] parts = m_parts.GetArray();
  3022. // Rejigger the linknum's of the remaining SOP's to fill any gap
  3023. if (parts.Length == 1 && RootPart != null)
  3024. {
  3025. // Single prim left
  3026. RootPart.LinkNum = 0;
  3027. }
  3028. else
  3029. {
  3030. for (int i = 0; i < parts.Length; i++)
  3031. {
  3032. SceneObjectPart part = parts[i];
  3033. if (part.LinkNum > linkPart.LinkNum)
  3034. part.LinkNum--;
  3035. }
  3036. }
  3037. }
  3038. linkPart.ParentID = 0;
  3039. linkPart.LinkNum = 0;
  3040. PhysicsActor linkPartPa = linkPart.PhysActor;
  3041. // Remove the SOP from the physical scene.
  3042. // If the new SOG is physical, it is re-created later.
  3043. // (There is a problem here in that we have not yet told the physics
  3044. // engine about the delink. Someday, linksets should be made first
  3045. // class objects in the physics engine interface).
  3046. if (linkPartPa != null)
  3047. {
  3048. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3049. linkPart.PhysActor = null;
  3050. }
  3051. // We need to reset the child part's position
  3052. // ready for life as a separate object after being a part of another object
  3053. /* This commented out code seems to recompute what GetWorldPosition already does.
  3054. * Replace with a call to GetWorldPosition (before unlinking)
  3055. Quaternion parentRot = m_rootPart.RotationOffset;
  3056. Vector3 axPos = linkPart.OffsetPosition;
  3057. axPos *= parentRot;
  3058. linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z);
  3059. linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition;
  3060. linkPart.OffsetPosition = new Vector3(0, 0, 0);
  3061. */
  3062. linkPart.setGroupPosition(worldPos);
  3063. linkPart.setOffsetPosition(Vector3.Zero);
  3064. linkPart.setRotationOffset(worldRot);
  3065. // Create a new SOG to go around this unlinked and unattached SOP
  3066. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3067. m_scene.AddNewSceneObject(objectGroup, true);
  3068. linkPart.Rezzed = RootPart.Rezzed;
  3069. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3070. // (since delete works by deleting all rows which have a given object id)
  3071. // this is as it seems to be in sl now
  3072. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3073. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3074. if (m_rootPart.PhysActor != null)
  3075. m_rootPart.PhysActor.Building = false;
  3076. objectGroup.HasGroupChangedDueToDelink = true;
  3077. InvalidBoundsRadius();
  3078. InvalidatePartsLinkMaps();
  3079. objectGroup.InvalidateEffectivePerms();
  3080. if (sendEvents)
  3081. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3082. return objectGroup;
  3083. }
  3084. /* working on it
  3085. public void DelinkFromGroup(List<SceneObjectPart> linkParts, bool sendEvents)
  3086. {
  3087. // m_log.DebugFormat(
  3088. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3089. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3090. if(PrimCount == 1)
  3091. return;
  3092. if (m_rootPart.PhysActor != null)
  3093. m_rootPart.PhysActor.Building = true;
  3094. bool unlinkroot = false;
  3095. foreach(SceneObjectPart linkPart in linkParts)
  3096. {
  3097. // first we only remove child parts
  3098. if(linkPart.LocalId == m_rootPart.LocalId)
  3099. {
  3100. unlinkroot = true;
  3101. continue;
  3102. }
  3103. lock (m_parts.SyncRoot)
  3104. if(!m_parts.Remove(linkPart.UUID))
  3105. continue;
  3106. linkPart.ClearUndoState();
  3107. Vector3 worldPos = linkPart.GetWorldPosition();
  3108. Quaternion worldRot = linkPart.GetWorldRotation();
  3109. linkPart.ParentID = 0;
  3110. linkPart.LinkNum = 0;
  3111. PhysicsActor linkPartPa = linkPart.PhysActor;
  3112. // Remove the SOP from the physical scene.
  3113. // If the new SOG is physical, it is re-created later.
  3114. // (There is a problem here in that we have not yet told the physics
  3115. // engine about the delink. Someday, linksets should be made first
  3116. // class objects in the physics engine interface).
  3117. if (linkPartPa != null)
  3118. {
  3119. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3120. linkPart.PhysActor = null;
  3121. }
  3122. linkPart.setGroupPosition(worldPos);
  3123. linkPart.setOffsetPosition(Vector3.Zero);
  3124. linkPart.setRotationOffset(worldRot);
  3125. // Create a new SOG to go around this unlinked and unattached SOP
  3126. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3127. m_scene.AddNewSceneObject(objectGroup, true);
  3128. linkPart.Rezzed = RootPart.Rezzed;
  3129. // this is as it seems to be in sl now
  3130. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3131. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3132. objectGroup.HasGroupChangedDueToDelink = true;
  3133. if (sendEvents)
  3134. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3135. }
  3136. if(unlinkroot)
  3137. {
  3138. //TODO
  3139. }
  3140. lock (m_parts.SyncRoot)
  3141. {
  3142. SceneObjectPart[] parts = m_parts.GetArray();
  3143. if (parts.Length == 1)
  3144. {
  3145. // Single prim left
  3146. m_rootPart.LinkNum = 0;
  3147. }
  3148. else
  3149. {
  3150. m_rootPart.LinkNum = 1;
  3151. int linknum = 2;
  3152. for (int i = 1; i < parts.Length; i++)
  3153. parts[i].LinkNum = linknum++;
  3154. }
  3155. }
  3156. InvalidBoundsRadius();
  3157. if (m_rootPart.PhysActor != null)
  3158. m_rootPart.PhysActor.Building = false;
  3159. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3160. // (since delete works by deleting all rows which have a given object id)
  3161. Scene.SimulationDataService.RemoveObject(UUID, Scene.RegionInfo.RegionID);
  3162. HasGroupChangedDueToDelink = true;
  3163. TriggerScriptChangedEvent(Changed.LINK);
  3164. return;
  3165. }
  3166. */
  3167. /// <summary>
  3168. /// Stop this object from being persisted over server restarts.
  3169. /// </summary>
  3170. /// <param name="objectGroup"></param>
  3171. public virtual void DetachFromBackup()
  3172. {
  3173. if (m_scene != null)
  3174. {
  3175. m_scene.SceneGraph.FireDetachFromBackup(this);
  3176. if (Backup)
  3177. m_scene.EventManager.OnBackup -= ProcessBackup;
  3178. }
  3179. Backup = false;
  3180. }
  3181. // This links an SOP from a previous linkset into my linkset.
  3182. // The trick is that the SOP's position and rotation are relative to the old root SOP's
  3183. // so we are passed in the position and rotation of the old linkset so this can
  3184. // unjigger this SOP's position and rotation from the previous linkset and
  3185. // then make them relative to my linkset root.
  3186. private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation, int linkNum)
  3187. {
  3188. Quaternion parentRot = oldGroupRotation;
  3189. Quaternion oldRot = part.RotationOffset;
  3190. // Move our position in world
  3191. Vector3 axPos = part.OffsetPosition;
  3192. axPos *= parentRot;
  3193. Vector3 newPos = oldGroupPosition + axPos;
  3194. part.setGroupPosition(newPos);
  3195. part.setOffsetPosition(Vector3.Zero);
  3196. // Compution our rotation in world
  3197. Quaternion worldRot = parentRot * oldRot;
  3198. part.RotationOffset = worldRot;
  3199. // Add this SOP to our linkset
  3200. part.SetParent(this);
  3201. part.ParentID = m_rootPart.LocalId;
  3202. m_parts.Add(part.UUID, part);
  3203. part.LinkNum = linkNum;
  3204. m_scene.updateScenePartGroup(part, this);
  3205. // Compute the new position of this SOP relative to the group position
  3206. part.setOffsetPosition(newPos - AbsolutePosition);
  3207. // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times.
  3208. // It would have the affect of setting the physics engine position multiple
  3209. // times. In theory, that is not necessary but I don't have a good linkset
  3210. // test to know that cleaning up this code wouldn't break things.)
  3211. // Compute the SOP's rotation relative to the rotation of the group.
  3212. parentRot = m_rootPart.RotationOffset;
  3213. oldRot = part.RotationOffset;
  3214. Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot;
  3215. part.setRotationOffset(newRot);
  3216. Vector3 pos = part.OffsetPosition;
  3217. pos *= Quaternion.Conjugate(parentRot);
  3218. part.OffsetPosition = pos; // update position and orientation on physics also
  3219. // Since this SOP's state has changed, push those changes into the physics engine
  3220. // and the simulator.
  3221. // done on caller
  3222. // part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  3223. }
  3224. /// <summary>
  3225. /// If object is physical, apply force to move it around
  3226. /// If object is not physical, just put it at the resulting location
  3227. /// </summary>
  3228. /// <param name="partID">Part ID to check for grab</param>
  3229. /// <param name="offset">Always seems to be 0,0,0, so ignoring</param>
  3230. /// <param name="pos">New position. We do the math here to turn it into a force</param>
  3231. /// <param name="remoteClient"></param>
  3232. public void GrabMovement(UUID partID, Vector3 offset, Vector3 pos, IClientAPI remoteClient)
  3233. {
  3234. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3235. {
  3236. if (BlockGrabOverride)
  3237. return;
  3238. SceneObjectPart part = GetPart(partID);
  3239. if (part == null)
  3240. return;
  3241. if (part.BlockGrab)
  3242. return;
  3243. PhysicsActor pa = m_rootPart.PhysActor;
  3244. if (pa != null && pa.IsPhysical)
  3245. {
  3246. // empirically convert distance diference to a impulse
  3247. Vector3 grabforce = pos - AbsolutePosition;
  3248. grabforce = grabforce * (pa.Mass * 0.1f);
  3249. pa.AddForce(grabforce, false);
  3250. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3251. }
  3252. else
  3253. {
  3254. NonPhysicalGrabMovement(pos);
  3255. }
  3256. }
  3257. }
  3258. /// <summary>
  3259. /// Apply possition for grabbing non-physical linksets (Ctrl+Drag)
  3260. /// This MUST be blocked for linksets that contain touch scripts because the viewer triggers grab on the touch
  3261. /// event (Viewer Bug?) This would allow anyone to drag a linkset with a touch script. SL behaviour is also to
  3262. /// block grab on prims with touch events.
  3263. /// </summary>
  3264. /// <param name="pos">New Position</param>
  3265. public void NonPhysicalGrabMovement(Vector3 pos)
  3266. {
  3267. if(!IsAttachment && ScriptCount() == 0)
  3268. UpdateGroupPosition(pos);
  3269. }
  3270. /// <summary>
  3271. /// If object is physical, prepare for spinning torques (set flag to save old orientation)
  3272. /// </summary>
  3273. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3274. /// <param name="remoteClient"></param>
  3275. public void SpinStart(IClientAPI remoteClient)
  3276. {
  3277. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3278. return;
  3279. if (m_scene.EventManager.TriggerGroupSpinStart(UUID))
  3280. {
  3281. PhysicsActor pa = m_rootPart.PhysActor;
  3282. if (pa != null)
  3283. {
  3284. if (pa.IsPhysical)
  3285. {
  3286. m_rootPart.IsWaitingForFirstSpinUpdatePacket = true;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. /// <summary>
  3292. /// If object is physical, apply torque to spin it around
  3293. /// </summary>
  3294. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3295. /// <param name="remoteClient"></param>
  3296. public void SpinMovement(Quaternion newOrientation, IClientAPI remoteClient)
  3297. {
  3298. // The incoming newOrientation, sent by the client, "seems" to be the
  3299. // desired target orientation. This needs further verification; in particular,
  3300. // one would expect that the initial incoming newOrientation should be
  3301. // fairly close to the original prim's physical orientation,
  3302. // m_rootPart.PhysActor.Orientation. This however does not seem to be the
  3303. // case (might just be an issue with different quaternions representing the
  3304. // same rotation, or it might be a coordinate system issue).
  3305. //
  3306. // Since it's not clear what the relationship is between the PhysActor.Orientation
  3307. // and the incoming orientations sent by the client, we take an alternative approach
  3308. // of calculating the delta rotation between the orientations being sent by the
  3309. // client. (Since a spin is invoked by ctrl+shift+drag in the client, we expect
  3310. // a steady stream of several new orientations coming in from the client.)
  3311. // This ensures that the delta rotations are being calculated from self-consistent
  3312. // pairs of old/new rotations. Given the delta rotation, we apply a torque around
  3313. // the delta rotation axis, scaled by the object mass times an arbitrary scaling
  3314. // factor (to ensure the resulting torque is not "too strong" or "too weak").
  3315. //
  3316. // Ideally we need to calculate (probably iteratively) the exact torque or series
  3317. // of torques needed to arrive exactly at the destination orientation. However, since
  3318. // it is not yet clear how to map the destination orientation (provided by the viewer)
  3319. // into PhysActor orientations (needed by the physics engine), we omit this step.
  3320. // This means that the resulting torque will at least be in the correct direction,
  3321. // but it will result in over-shoot or under-shoot of the target orientation.
  3322. // For the end user, this means that ctrl+shift+drag can be used for relative,
  3323. // but not absolute, adjustments of orientation for physical prims.
  3324. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3325. return;
  3326. if (m_scene.EventManager.TriggerGroupSpin(UUID, newOrientation))
  3327. {
  3328. PhysicsActor pa = m_rootPart.PhysActor;
  3329. if (pa != null && pa.IsPhysical)
  3330. {
  3331. if (m_rootPart.IsWaitingForFirstSpinUpdatePacket)
  3332. {
  3333. // first time initialization of "old" orientation for calculation of delta rotations
  3334. m_rootPart.SpinOldOrientation = newOrientation;
  3335. m_rootPart.IsWaitingForFirstSpinUpdatePacket = false;
  3336. }
  3337. else
  3338. {
  3339. // save and update old orientation
  3340. Quaternion old = m_rootPart.SpinOldOrientation;
  3341. m_rootPart.SpinOldOrientation = newOrientation;
  3342. //m_log.Error("[SCENE OBJECT GROUP]: Old orientation is " + old);
  3343. //m_log.Error("[SCENE OBJECT GROUP]: Incoming new orientation is " + newOrientation);
  3344. // compute difference between previous old rotation and new incoming rotation
  3345. Quaternion minimalRotationFromQ1ToQ2 = newOrientation * Quaternion.Inverse(old);
  3346. float rotationAngle;
  3347. Vector3 spinforce;
  3348. minimalRotationFromQ1ToQ2.GetAxisAngle(out spinforce, out rotationAngle);
  3349. if(Math.Abs(rotationAngle)< 0.001)
  3350. return;
  3351. spinforce.Normalize();
  3352. //m_log.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis);
  3353. if(rotationAngle > 0)
  3354. spinforce = spinforce * pa.Mass * 0.1f; // 0.1 is an arbitrary torque scaling factor
  3355. else
  3356. spinforce = spinforce * pa.Mass * -0.1f; // 0.1 is an arbitrary torque scaling
  3357. pa.AddAngularForce(spinforce,true);
  3358. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3359. }
  3360. }
  3361. else
  3362. {
  3363. NonPhysicalSpinMovement(newOrientation);
  3364. }
  3365. }
  3366. }
  3367. /// <summary>
  3368. /// Apply rotation for spinning non-physical linksets (Ctrl+Shift+Drag)
  3369. /// As with dragging, scripted objects must be blocked from spinning
  3370. /// </summary>
  3371. /// <param name="newOrientation">New Rotation</param>
  3372. private void NonPhysicalSpinMovement(Quaternion newOrientation)
  3373. {
  3374. if(!IsAttachment && ScriptCount() == 0)
  3375. UpdateGroupRotationR(newOrientation);
  3376. }
  3377. /// <summary>
  3378. /// Set the name of a prim
  3379. /// </summary>
  3380. /// <param name="name"></param>
  3381. /// <param name="localID"></param>
  3382. public void SetPartName(string name, uint localID)
  3383. {
  3384. SceneObjectPart part = GetPart(localID);
  3385. if (part != null)
  3386. {
  3387. part.Name = name;
  3388. }
  3389. }
  3390. public void SetPartDescription(string des, uint localID)
  3391. {
  3392. SceneObjectPart part = GetPart(localID);
  3393. if (part != null)
  3394. {
  3395. part.Description = des;
  3396. }
  3397. }
  3398. public void SetPartText(string text, uint localID)
  3399. {
  3400. SceneObjectPart part = GetPart(localID);
  3401. if (part != null)
  3402. {
  3403. part.SetText(text);
  3404. }
  3405. }
  3406. public void SetPartText(string text, UUID partID)
  3407. {
  3408. SceneObjectPart part = GetPart(partID);
  3409. if (part != null)
  3410. {
  3411. part.SetText(text);
  3412. }
  3413. }
  3414. public string GetPartName(uint localID)
  3415. {
  3416. SceneObjectPart part = GetPart(localID);
  3417. if (part != null)
  3418. {
  3419. return part.Name;
  3420. }
  3421. return String.Empty;
  3422. }
  3423. public string GetPartDescription(uint localID)
  3424. {
  3425. SceneObjectPart part = GetPart(localID);
  3426. if (part != null)
  3427. {
  3428. return part.Description;
  3429. }
  3430. return String.Empty;
  3431. }
  3432. /// <summary>
  3433. /// Update prim flags for this group.
  3434. /// </summary>
  3435. /// <param name="localID"></param>
  3436. /// <param name="UsePhysics"></param>
  3437. /// <param name="SetTemporary"></param>
  3438. /// <param name="SetPhantom"></param>
  3439. /// <param name="SetVolumeDetect"></param>
  3440. public void UpdateFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect)
  3441. {
  3442. if (m_scene == null || IsDeleted)
  3443. return;
  3444. HasGroupChanged = true;
  3445. if (SetTemporary)
  3446. {
  3447. DetachFromBackup();
  3448. // Remove from database and parcel prim count
  3449. //
  3450. m_scene.DeleteFromStorage(UUID);
  3451. }
  3452. else if (!Backup)
  3453. {
  3454. // Previously been temporary now switching back so make it
  3455. // available for persisting again
  3456. AttachToBackup();
  3457. }
  3458. SceneObjectPart[] parts = m_parts.GetArray();
  3459. if (UsePhysics)
  3460. {
  3461. int maxprims = m_scene.m_linksetPhysCapacity;
  3462. bool checkShape = (maxprims > 0 &&
  3463. parts.Length > maxprims);
  3464. for (int i = 0; i < parts.Length; i++)
  3465. {
  3466. SceneObjectPart part = parts[i];
  3467. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  3468. continue; // assuming root type was checked elsewhere
  3469. if (checkShape)
  3470. {
  3471. if (--maxprims < 0)
  3472. {
  3473. UsePhysics = false;
  3474. break;
  3475. }
  3476. }
  3477. if (part.Scale.X > m_scene.m_maxPhys ||
  3478. part.Scale.Y > m_scene.m_maxPhys ||
  3479. part.Scale.Z > m_scene.m_maxPhys )
  3480. {
  3481. UsePhysics = false; // Reset physics
  3482. break;
  3483. }
  3484. }
  3485. }
  3486. if (parts.Length > 1)
  3487. {
  3488. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3489. for (int i = 0; i < parts.Length; i++)
  3490. {
  3491. if (parts[i].UUID != m_rootPart.UUID)
  3492. parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3493. }
  3494. if (m_rootPart.PhysActor != null)
  3495. m_rootPart.PhysActor.Building = false;
  3496. }
  3497. else
  3498. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false);
  3499. m_scene.EventManager.TriggerParcelPrimCountTainted();
  3500. }
  3501. public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data)
  3502. {
  3503. SceneObjectPart part = GetPart(localID);
  3504. if (part != null)
  3505. {
  3506. part.UpdateExtraParam(type, inUse, data);
  3507. }
  3508. }
  3509. /// <summary>
  3510. /// Gets the number of parts
  3511. /// </summary>
  3512. /// <returns></returns>
  3513. public int GetPartCount()
  3514. {
  3515. return Parts.Count();
  3516. }
  3517. public void AdjustChildPrimPermissions(bool forceTaskInventoryPermissive)
  3518. {
  3519. uint newOwnerMask = (uint)(PermissionMask.All | PermissionMask.Export) & 0xfffffff0; // Mask folded bits
  3520. uint foldedPerms = RootPart.OwnerMask & (uint)PermissionMask.FoldedMask;
  3521. ForEachPart(part =>
  3522. {
  3523. newOwnerMask &= part.BaseMask;
  3524. if (part != RootPart)
  3525. part.ClonePermissions(RootPart);
  3526. if (forceTaskInventoryPermissive)
  3527. part.Inventory.ApplyGodPermissions(part.BaseMask);
  3528. });
  3529. uint lockMask = ~(uint)(PermissionMask.Move);
  3530. uint lockBit = RootPart.OwnerMask & (uint)(PermissionMask.Move);
  3531. RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask);
  3532. // m_log.DebugFormat(
  3533. // "[SCENE OBJECT GROUP]: RootPart.OwnerMask now {0} for {1} in {2}",
  3534. // (OpenMetaverse.PermissionMask)RootPart.OwnerMask, Name, Scene.Name);
  3535. InvalidateEffectivePerms();
  3536. RootPart.ScheduleFullUpdate();
  3537. }
  3538. public void UpdatePermissions(UUID AgentID, byte field, uint localID,
  3539. uint mask, byte addRemTF)
  3540. {
  3541. RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF);
  3542. bool god = Scene.Permissions.IsGod(AgentID);
  3543. if (field == 1 && god)
  3544. {
  3545. ForEachPart(part =>
  3546. {
  3547. part.BaseMask = RootPart.BaseMask;
  3548. });
  3549. }
  3550. AdjustChildPrimPermissions(false);
  3551. if (field == 1 && god) // Base mask was set. Update all child part inventories
  3552. {
  3553. foreach (SceneObjectPart part in Parts)
  3554. part.Inventory.ApplyGodPermissions(RootPart.BaseMask);
  3555. InvalidateEffectivePerms();
  3556. }
  3557. HasGroupChanged = true;
  3558. // Send the group's properties to all clients once all parts are updated
  3559. IClientAPI client;
  3560. if (Scene.TryGetClient(AgentID, out client))
  3561. SendPropertiesToClient(client);
  3562. }
  3563. #endregion
  3564. #region Shape
  3565. /// <summary>
  3566. ///
  3567. /// </summary>
  3568. /// <param name="shapeBlock"></param>
  3569. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock, uint localID)
  3570. {
  3571. SceneObjectPart part = GetPart(localID);
  3572. if (part != null)
  3573. {
  3574. part.UpdateShape(shapeBlock);
  3575. PhysicsActor pa = m_rootPart.PhysActor;
  3576. if (pa != null)
  3577. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3578. }
  3579. InvalidBoundsRadius();
  3580. }
  3581. #endregion
  3582. #region Resize
  3583. /// <summary>
  3584. /// Resize the entire group of prims.
  3585. /// </summary>
  3586. /// <param name="scale"></param>
  3587. public void GroupResize(Vector3 scale)
  3588. {
  3589. // m_log.DebugFormat(
  3590. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
  3591. if (Scene == null)
  3592. return;
  3593. PhysicsActor pa = m_rootPart.PhysActor;
  3594. float minsize = Scene.m_minNonphys;
  3595. float maxsize = Scene.m_maxNonphys;
  3596. if (pa != null && pa.IsPhysical)
  3597. {
  3598. minsize = Scene.m_minPhys;
  3599. maxsize = Scene.m_maxPhys;
  3600. }
  3601. scale.X = Util.Clamp(scale.X, minsize, maxsize);
  3602. scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
  3603. scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
  3604. // requested scaling factors
  3605. float x = (scale.X / RootPart.Scale.X);
  3606. float y = (scale.Y / RootPart.Scale.Y);
  3607. float z = (scale.Z / RootPart.Scale.Z);
  3608. SceneObjectPart[] parts = m_parts.GetArray();
  3609. // fix scaling factors so parts don't violate dimensions
  3610. for(int i = 0;i < parts.Length;i++)
  3611. {
  3612. SceneObjectPart obPart = parts[i];
  3613. if(obPart.UUID != m_rootPart.UUID)
  3614. {
  3615. Vector3 oldSize = new Vector3(obPart.Scale);
  3616. float f = 1.0f;
  3617. float a = 1.0f;
  3618. if(oldSize.X * x > maxsize)
  3619. {
  3620. f = maxsize / oldSize.X;
  3621. a = f / x;
  3622. x *= a;
  3623. y *= a;
  3624. z *= a;
  3625. }
  3626. else if(oldSize.X * x < minsize)
  3627. {
  3628. f = minsize / oldSize.X;
  3629. a = f / x;
  3630. x *= a;
  3631. y *= a;
  3632. z *= a;
  3633. }
  3634. if(oldSize.Y * y > maxsize)
  3635. {
  3636. f = maxsize / oldSize.Y;
  3637. a = f / y;
  3638. x *= a;
  3639. y *= a;
  3640. z *= a;
  3641. }
  3642. else if(oldSize.Y * y < minsize)
  3643. {
  3644. f = minsize / oldSize.Y;
  3645. a = f / y;
  3646. x *= a;
  3647. y *= a;
  3648. z *= a;
  3649. }
  3650. if(oldSize.Z * z > maxsize)
  3651. {
  3652. f = maxsize / oldSize.Z;
  3653. a = f / z;
  3654. x *= a;
  3655. y *= a;
  3656. z *= a;
  3657. }
  3658. else if(oldSize.Z * z < minsize)
  3659. {
  3660. f = minsize / oldSize.Z;
  3661. a = f / z;
  3662. x *= a;
  3663. y *= a;
  3664. z *= a;
  3665. }
  3666. }
  3667. }
  3668. Vector3 rootScale = RootPart.Scale;
  3669. rootScale.X *= x;
  3670. rootScale.Y *= y;
  3671. rootScale.Z *= z;
  3672. RootPart.Scale = rootScale;
  3673. for (int i = 0; i < parts.Length; i++)
  3674. {
  3675. SceneObjectPart obPart = parts[i];
  3676. if (obPart.UUID != m_rootPart.UUID)
  3677. {
  3678. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  3679. currentpos.X *= x;
  3680. currentpos.Y *= y;
  3681. currentpos.Z *= z;
  3682. Vector3 newSize = new Vector3(obPart.Scale);
  3683. newSize.X *= x;
  3684. newSize.Y *= y;
  3685. newSize.Z *= z;
  3686. obPart.Scale = newSize;
  3687. obPart.UpdateOffSet(currentpos);
  3688. }
  3689. }
  3690. InvalidBoundsRadius();
  3691. HasGroupChanged = true;
  3692. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3693. ScheduleGroupForFullUpdate();
  3694. }
  3695. public bool GroupResize(double fscale)
  3696. {
  3697. // m_log.DebugFormat(
  3698. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, fscale);
  3699. if (Scene == null || IsDeleted || inTransit || fscale < 0)
  3700. return false;
  3701. // ignore lsl restrictions. let them be done a LSL
  3702. PhysicsActor pa = m_rootPart.PhysActor;
  3703. if(RootPart.KeyframeMotion != null)
  3704. RootPart.KeyframeMotion.Suspend();
  3705. float minsize = Scene.m_minNonphys;
  3706. float maxsize = Scene.m_maxNonphys;
  3707. // assuming physics is more restrictive
  3708. if (pa != null && pa.IsPhysical)
  3709. {
  3710. minsize = Scene.m_minPhys;
  3711. maxsize = Scene.m_maxPhys;
  3712. }
  3713. SceneObjectPart[] parts = m_parts.GetArray();
  3714. float tmp;
  3715. // check scaling factor so parts don't violate dimensions
  3716. for(int i = 0; i < parts.Length; i++)
  3717. {
  3718. SceneObjectPart obPart = parts[i];
  3719. Vector3 oldSize = new Vector3(obPart.Scale);
  3720. tmp = (float)(oldSize.X * fscale);
  3721. if(tmp > maxsize)
  3722. return false;
  3723. if(tmp < minsize)
  3724. return false;
  3725. tmp = (float)(oldSize.Y * fscale);
  3726. if(tmp > maxsize)
  3727. return false;
  3728. if(tmp < minsize)
  3729. return false;
  3730. tmp = (float)(oldSize.Z * fscale);
  3731. if(tmp > maxsize)
  3732. return false;
  3733. if(tmp < minsize)
  3734. return false;
  3735. }
  3736. Vector3 newSize = RootPart.Scale;
  3737. newSize.X = (float)(newSize.X * fscale);
  3738. newSize.Y = (float)(newSize.Y * fscale);
  3739. newSize.Z = (float)(newSize.Z * fscale);
  3740. if(pa != null)
  3741. pa.Building = true;
  3742. RootPart.Scale = newSize;
  3743. Vector3 currentpos;
  3744. for (int i = 0; i < parts.Length; i++)
  3745. {
  3746. SceneObjectPart obPart = parts[i];
  3747. if (obPart.UUID != m_rootPart.UUID)
  3748. {
  3749. currentpos = obPart.OffsetPosition;
  3750. currentpos.X = (float)(currentpos.X * fscale);
  3751. currentpos.Y = (float)(currentpos.Y * fscale);
  3752. currentpos.Z = (float)(currentpos.Z * fscale);
  3753. newSize = obPart.Scale;
  3754. newSize.X = (float)(newSize.X * fscale);
  3755. newSize.Y = (float)(newSize.Y * fscale);
  3756. newSize.Z = (float)(newSize.Z * fscale);
  3757. obPart.Scale = newSize;
  3758. obPart.UpdateOffSet(currentpos);
  3759. }
  3760. }
  3761. if(pa != null)
  3762. pa.Building = false;
  3763. InvalidBoundsRadius();
  3764. HasGroupChanged = true;
  3765. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3766. ScheduleGroupForFullUpdate();
  3767. if(RootPart.KeyframeMotion != null)
  3768. RootPart.KeyframeMotion.Resume();
  3769. return true;
  3770. }
  3771. public float GetMaxGroupResizeScale()
  3772. {
  3773. if (Scene == null || IsDeleted || inTransit)
  3774. return 1.0f;
  3775. float maxsize = Scene.m_maxNonphys;
  3776. PhysicsActor pa = m_rootPart.PhysActor;
  3777. // assuming physics is more restrictive
  3778. if (pa != null && pa.IsPhysical)
  3779. maxsize = Scene.m_maxPhys;
  3780. SceneObjectPart[] parts = m_parts.GetArray();
  3781. float larger = float.MinValue;
  3782. for(int i = 0; i < parts.Length; i++)
  3783. {
  3784. SceneObjectPart obPart = parts[i];
  3785. Vector3 oldSize = new Vector3(obPart.Scale);
  3786. if(larger < oldSize.X)
  3787. larger = oldSize.X;
  3788. if(larger < oldSize.Y)
  3789. larger = oldSize.Y;
  3790. if(larger < oldSize.Z)
  3791. larger = oldSize.Z;
  3792. }
  3793. if(larger >= maxsize)
  3794. return 1.0f;
  3795. larger += 1e-3f;
  3796. float fscale = maxsize / larger;
  3797. return fscale;
  3798. }
  3799. public float GetMinGroupResizeScale()
  3800. {
  3801. if (Scene == null || IsDeleted || inTransit)
  3802. return 1.0f;
  3803. float minsize = Scene.m_minNonphys;
  3804. PhysicsActor pa = m_rootPart.PhysActor;
  3805. // assuming physics is more restrictive
  3806. if (pa != null && pa.IsPhysical)
  3807. minsize = Scene.m_minPhys;
  3808. SceneObjectPart[] parts = m_parts.GetArray();
  3809. float smaller = float.MaxValue;
  3810. for(int i = 0; i < parts.Length; i++)
  3811. {
  3812. SceneObjectPart obPart = parts[i];
  3813. Vector3 oldSize = new Vector3(obPart.Scale);
  3814. if(smaller > oldSize.X)
  3815. smaller = oldSize.X;
  3816. if(smaller > oldSize.Y)
  3817. smaller = oldSize.Y;
  3818. if(smaller > oldSize.Z)
  3819. smaller = oldSize.Z;
  3820. }
  3821. if(smaller <= minsize)
  3822. return 1.0f;
  3823. if(smaller > 2e-3f)
  3824. smaller -= 1e-3f;
  3825. float fscale = minsize / smaller;
  3826. if(fscale < 1e-8f)
  3827. fscale = 1e-8f;
  3828. return fscale;
  3829. }
  3830. #endregion
  3831. #region Position
  3832. /// <summary>
  3833. /// Move this scene object
  3834. /// </summary>
  3835. /// <param name="pos"></param>
  3836. public void UpdateGroupPosition(Vector3 pos)
  3837. {
  3838. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3839. {
  3840. if (IsAttachment)
  3841. {
  3842. m_rootPart.AttachedPos = pos;
  3843. }
  3844. if (RootPart.GetStatusSandbox())
  3845. {
  3846. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, pos) > 10)
  3847. {
  3848. RootPart.ScriptSetPhysicsStatus(false);
  3849. pos = AbsolutePosition;
  3850. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3851. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  3852. }
  3853. }
  3854. AbsolutePosition = pos;
  3855. HasGroupChanged = true;
  3856. }
  3857. //we need to do a terse update even if the move wasn't allowed
  3858. // so that the position is reset in the client (the object snaps back)
  3859. RootPart.ScheduleTerseUpdate();
  3860. }
  3861. /// <summary>
  3862. /// Update the position of a single part of this scene object
  3863. /// </summary>
  3864. /// <param name="pos"></param>
  3865. /// <param name="localID"></param>
  3866. ///
  3867. public void UpdateSinglePosition(Vector3 pos, uint localID)
  3868. {
  3869. SceneObjectPart part = GetPart(localID);
  3870. if (part != null)
  3871. {
  3872. // unlock parts position change
  3873. if (m_rootPart.PhysActor != null)
  3874. m_rootPart.PhysActor.Building = true;
  3875. if (part.UUID == m_rootPart.UUID)
  3876. {
  3877. UpdateRootPosition(pos);
  3878. }
  3879. else
  3880. {
  3881. part.UpdateOffSet(pos);
  3882. }
  3883. if (m_rootPart.PhysActor != null)
  3884. m_rootPart.PhysActor.Building = false;
  3885. HasGroupChanged = true;
  3886. }
  3887. }
  3888. /// <summary>
  3889. /// Update just the root prim position in a linkset
  3890. /// </summary>
  3891. /// <param name="newPos"></param>
  3892. public void UpdateRootPosition(Vector3 newPos)
  3893. {
  3894. // needs to be called with phys building true
  3895. Vector3 oldPos;
  3896. if (IsAttachment)
  3897. oldPos = m_rootPart.AttachedPos + m_rootPart.OffsetPosition; // OffsetPosition should always be 0 in an attachments's root prim
  3898. else
  3899. oldPos = AbsolutePosition + m_rootPart.OffsetPosition;
  3900. Vector3 diff = oldPos - newPos;
  3901. Quaternion partRotation = m_rootPart.RotationOffset;
  3902. diff *= Quaternion.Inverse(partRotation);
  3903. SceneObjectPart[] parts = m_parts.GetArray();
  3904. for (int i = 0; i < parts.Length; i++)
  3905. {
  3906. SceneObjectPart obPart = parts[i];
  3907. if (obPart.UUID != m_rootPart.UUID)
  3908. obPart.OffsetPosition = obPart.OffsetPosition + diff;
  3909. }
  3910. AbsolutePosition = newPos;
  3911. if (IsAttachment)
  3912. m_rootPart.AttachedPos = newPos;
  3913. HasGroupChanged = true;
  3914. if (m_rootPart.Undoing)
  3915. {
  3916. ScheduleGroupForFullUpdate();
  3917. }
  3918. else
  3919. {
  3920. ScheduleGroupForTerseUpdate();
  3921. }
  3922. }
  3923. #endregion
  3924. #region Rotation
  3925. /// <summary>
  3926. /// Update the rotation of the group.
  3927. /// </summary>
  3928. /// <param name="rot"></param>
  3929. public void UpdateGroupRotationR(Quaternion rot)
  3930. {
  3931. m_rootPart.UpdateRotation(rot);
  3932. /* this is done by rootpart RotationOffset set called by UpdateRotation
  3933. PhysicsActor actor = m_rootPart.PhysActor;
  3934. if (actor != null)
  3935. {
  3936. actor.Orientation = m_rootPart.RotationOffset;
  3937. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3938. }
  3939. */
  3940. HasGroupChanged = true;
  3941. ScheduleGroupForTerseUpdate();
  3942. }
  3943. /// <summary>
  3944. /// Update the position and rotation of a group simultaneously.
  3945. /// </summary>
  3946. /// <param name="pos"></param>
  3947. /// <param name="rot"></param>
  3948. public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
  3949. {
  3950. m_rootPart.UpdateRotation(rot);
  3951. PhysicsActor actor = m_rootPart.PhysActor;
  3952. if (actor != null)
  3953. {
  3954. actor.Orientation = m_rootPart.RotationOffset;
  3955. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3956. }
  3957. if (IsAttachment)
  3958. {
  3959. m_rootPart.AttachedPos = pos;
  3960. }
  3961. AbsolutePosition = pos;
  3962. HasGroupChanged = true;
  3963. ScheduleGroupForTerseUpdate();
  3964. }
  3965. /// <summary>
  3966. /// Update the rotation of a single prim within the group.
  3967. /// </summary>
  3968. /// <param name="rot"></param>
  3969. /// <param name="localID"></param>
  3970. public void UpdateSingleRotation(Quaternion rot, uint localID)
  3971. {
  3972. SceneObjectPart part = GetPart(localID);
  3973. SceneObjectPart[] parts = m_parts.GetArray();
  3974. if (part != null)
  3975. {
  3976. if (m_rootPart.PhysActor != null)
  3977. m_rootPart.PhysActor.Building = true;
  3978. if (part.UUID == m_rootPart.UUID)
  3979. {
  3980. UpdateRootRotation(rot);
  3981. }
  3982. else
  3983. {
  3984. part.UpdateRotation(rot);
  3985. }
  3986. if (m_rootPart.PhysActor != null)
  3987. m_rootPart.PhysActor.Building = false;
  3988. }
  3989. }
  3990. /// <summary>
  3991. /// Update the position and rotation simultaneously of a single prim within the group.
  3992. /// </summary>
  3993. /// <param name="rot"></param>
  3994. /// <param name="localID"></param>
  3995. public void UpdateSingleRotation(Quaternion rot, Vector3 pos, uint localID)
  3996. {
  3997. SceneObjectPart part = GetPart(localID);
  3998. if (part != null)
  3999. {
  4000. if (m_rootPart.PhysActor != null)
  4001. m_rootPart.PhysActor.Building = true;
  4002. if (part.UUID == m_rootPart.UUID)
  4003. {
  4004. UpdateRootRotation(rot);
  4005. AbsolutePosition = pos;
  4006. }
  4007. else
  4008. {
  4009. part.UpdateRotation(rot);
  4010. part.OffsetPosition = pos;
  4011. }
  4012. if (m_rootPart.PhysActor != null)
  4013. m_rootPart.PhysActor.Building = false;
  4014. }
  4015. }
  4016. /// <summary>
  4017. /// Update the rotation of just the root prim of a linkset.
  4018. /// </summary>
  4019. /// <param name="rot"></param>
  4020. public void UpdateRootRotation(Quaternion rot)
  4021. {
  4022. // needs to be called with phys building true
  4023. Quaternion axRot = rot;
  4024. Quaternion oldParentRot = m_rootPart.RotationOffset;
  4025. //Don't use UpdateRotation because it schedules an update prematurely
  4026. m_rootPart.RotationOffset = rot;
  4027. PhysicsActor pa = m_rootPart.PhysActor;
  4028. if (pa != null)
  4029. {
  4030. pa.Orientation = m_rootPart.RotationOffset;
  4031. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4032. }
  4033. SceneObjectPart[] parts = m_parts.GetArray();
  4034. for (int i = 0; i < parts.Length; i++)
  4035. {
  4036. SceneObjectPart prim = parts[i];
  4037. if (prim.UUID != m_rootPart.UUID)
  4038. {
  4039. Quaternion NewRot = oldParentRot * prim.RotationOffset;
  4040. NewRot = Quaternion.Inverse(axRot) * NewRot;
  4041. prim.RotationOffset = NewRot;
  4042. Vector3 axPos = prim.OffsetPosition;
  4043. axPos *= oldParentRot;
  4044. axPos *= Quaternion.Inverse(axRot);
  4045. prim.OffsetPosition = axPos;
  4046. }
  4047. }
  4048. HasGroupChanged = true;
  4049. ScheduleGroupForFullUpdate();
  4050. }
  4051. private enum updatetype :int
  4052. {
  4053. none = 0,
  4054. partterse = 1,
  4055. partfull = 2,
  4056. groupterse = 3,
  4057. groupfull = 4
  4058. }
  4059. public void doChangeObject(SceneObjectPart part, ObjectChangeData data)
  4060. {
  4061. // TODO this still as excessive *.Schedule*Update()s
  4062. if (part != null && part.ParentGroup != null)
  4063. {
  4064. ObjectChangeType change = data.change;
  4065. bool togroup = ((change & ObjectChangeType.Group) != 0);
  4066. // bool uniform = ((what & ObjectChangeType.UniformScale) != 0); not in use
  4067. SceneObjectGroup group = part.ParentGroup;
  4068. PhysicsActor pha = group.RootPart.PhysActor;
  4069. updatetype updateType = updatetype.none;
  4070. if (togroup)
  4071. {
  4072. // related to group
  4073. if ((change & (ObjectChangeType.Rotation | ObjectChangeType.Position)) != 0)
  4074. {
  4075. if ((change & ObjectChangeType.Rotation) != 0)
  4076. {
  4077. group.RootPart.UpdateRotation(data.rotation);
  4078. updateType = updatetype.none;
  4079. }
  4080. if ((change & ObjectChangeType.Position) != 0)
  4081. {
  4082. if (IsAttachment || m_scene.Permissions.CanObjectEntry(group, false, data.position))
  4083. UpdateGroupPosition(data.position);
  4084. updateType = updatetype.groupterse;
  4085. }
  4086. else
  4087. // ugly rotation update of all parts
  4088. {
  4089. group.ResetChildPrimPhysicsPositions();
  4090. }
  4091. }
  4092. if ((change & ObjectChangeType.Scale) != 0)
  4093. {
  4094. if (pha != null)
  4095. pha.Building = true;
  4096. group.GroupResize(data.scale);
  4097. updateType = updatetype.none;
  4098. if (pha != null)
  4099. pha.Building = false;
  4100. }
  4101. }
  4102. else
  4103. {
  4104. // related to single prim in a link-set ( ie group)
  4105. if (pha != null)
  4106. pha.Building = true;
  4107. // root part is special
  4108. // parts offset positions or rotations need to change also
  4109. if (part == group.RootPart)
  4110. {
  4111. if ((change & ObjectChangeType.Rotation) != 0)
  4112. group.UpdateRootRotation(data.rotation);
  4113. if ((change & ObjectChangeType.Position) != 0)
  4114. group.UpdateRootPosition(data.position);
  4115. if ((change & ObjectChangeType.Scale) != 0)
  4116. part.Resize(data.scale);
  4117. }
  4118. else
  4119. {
  4120. if ((change & ObjectChangeType.Position) != 0)
  4121. {
  4122. part.OffsetPosition = data.position;
  4123. updateType = updatetype.partterse;
  4124. }
  4125. if ((change & ObjectChangeType.Rotation) != 0)
  4126. {
  4127. part.UpdateRotation(data.rotation);
  4128. updateType = updatetype.none;
  4129. }
  4130. if ((change & ObjectChangeType.Scale) != 0)
  4131. {
  4132. part.Resize(data.scale);
  4133. updateType = updatetype.none;
  4134. }
  4135. }
  4136. if (pha != null)
  4137. pha.Building = false;
  4138. }
  4139. if (updateType != updatetype.none)
  4140. {
  4141. group.HasGroupChanged = true;
  4142. switch (updateType)
  4143. {
  4144. case updatetype.partterse:
  4145. part.ScheduleTerseUpdate();
  4146. break;
  4147. case updatetype.partfull:
  4148. part.ScheduleFullUpdate();
  4149. break;
  4150. case updatetype.groupterse:
  4151. group.ScheduleGroupForTerseUpdate();
  4152. break;
  4153. case updatetype.groupfull:
  4154. group.ScheduleGroupForFullUpdate();
  4155. break;
  4156. default:
  4157. break;
  4158. }
  4159. }
  4160. }
  4161. }
  4162. #endregion
  4163. internal void SetAxisRotation(int axis, int rotate10)
  4164. {
  4165. bool setX = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0);
  4166. bool setY = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0);
  4167. bool setZ = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0);
  4168. if (setX || setY || setZ)
  4169. {
  4170. bool lockaxis = (rotate10 == 0); // zero means axis locked
  4171. byte locks = RootPart.RotationAxisLocks;
  4172. if (setX)
  4173. {
  4174. if(lockaxis)
  4175. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X;
  4176. else
  4177. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_X;
  4178. }
  4179. if (setY)
  4180. {
  4181. if(lockaxis)
  4182. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y;
  4183. else
  4184. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Y;
  4185. }
  4186. if (setZ)
  4187. {
  4188. if(lockaxis)
  4189. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z;
  4190. else
  4191. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Z;
  4192. }
  4193. RootPart.RotationAxisLocks = locks;
  4194. RootPart.SetPhysicsAxisRotation();
  4195. }
  4196. }
  4197. public int GetAxisRotation(int axis)
  4198. {
  4199. byte rotAxislocks = RootPart.RotationAxisLocks;
  4200. // if multiple return the one with higher id
  4201. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z)
  4202. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) == 0 ? 1:0;
  4203. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y)
  4204. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) == 0 ? 1:0;
  4205. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X)
  4206. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) == 0 ? 1:0;
  4207. return 0;
  4208. }
  4209. public int registerRotTargetWaypoint(Quaternion target, float tolerance)
  4210. {
  4211. scriptRotTarget waypoint = new scriptRotTarget();
  4212. waypoint.targetRot = target;
  4213. waypoint.tolerance = tolerance;
  4214. uint handle = m_scene.AllocateLocalId();
  4215. waypoint.handle = handle;
  4216. lock (m_rotTargets)
  4217. {
  4218. if (m_rotTargets.Count >= 8)
  4219. m_rotTargets.Remove(m_rotTargets.ElementAt(0).Key);
  4220. m_rotTargets.Add(handle, waypoint);
  4221. }
  4222. m_scene.AddGroupTarget(this);
  4223. return (int)handle;
  4224. }
  4225. public void unregisterRotTargetWaypoint(int handle)
  4226. {
  4227. lock (m_targets)
  4228. {
  4229. m_rotTargets.Remove((uint)handle);
  4230. if (m_targets.Count == 0)
  4231. m_scene.RemoveGroupTarget(this);
  4232. }
  4233. }
  4234. public int registerTargetWaypoint(Vector3 target, float tolerance)
  4235. {
  4236. scriptPosTarget waypoint = new scriptPosTarget();
  4237. waypoint.targetPos = target;
  4238. waypoint.tolerance = tolerance;
  4239. uint handle = m_scene.AllocateLocalId();
  4240. waypoint.handle = handle;
  4241. lock (m_targets)
  4242. {
  4243. if (m_targets.Count >= 8)
  4244. m_targets.Remove(m_targets.ElementAt(0).Key);
  4245. m_targets.Add(handle, waypoint);
  4246. }
  4247. m_scene.AddGroupTarget(this);
  4248. return (int)handle;
  4249. }
  4250. public void unregisterTargetWaypoint(int handle)
  4251. {
  4252. lock (m_targets)
  4253. {
  4254. m_targets.Remove((uint)handle);
  4255. if (m_targets.Count == 0)
  4256. m_scene.RemoveGroupTarget(this);
  4257. }
  4258. }
  4259. public void checkAtTargets()
  4260. {
  4261. if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
  4262. {
  4263. if (m_targets.Count > 0)
  4264. {
  4265. bool at_target = false;
  4266. //Vector3 targetPos;
  4267. //uint targetHandle;
  4268. Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
  4269. lock (m_targets)
  4270. {
  4271. foreach (uint idx in m_targets.Keys)
  4272. {
  4273. scriptPosTarget target = m_targets[idx];
  4274. if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
  4275. {
  4276. at_target = true;
  4277. // trigger at_target
  4278. if (m_scriptListens_atTarget)
  4279. {
  4280. scriptPosTarget att = new scriptPosTarget();
  4281. att.targetPos = target.targetPos;
  4282. att.tolerance = target.tolerance;
  4283. att.handle = target.handle;
  4284. atTargets.Add(idx, att);
  4285. }
  4286. }
  4287. }
  4288. }
  4289. if (atTargets.Count > 0)
  4290. {
  4291. SceneObjectPart[] parts = m_parts.GetArray();
  4292. uint[] localids = new uint[parts.Length];
  4293. for (int i = 0; i < parts.Length; i++)
  4294. localids[i] = parts[i].LocalId;
  4295. for (int ctr = 0; ctr < localids.Length; ctr++)
  4296. {
  4297. foreach (uint target in atTargets.Keys)
  4298. {
  4299. scriptPosTarget att = atTargets[target];
  4300. m_scene.EventManager.TriggerAtTargetEvent(
  4301. localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
  4302. }
  4303. }
  4304. return;
  4305. }
  4306. if (m_scriptListens_notAtTarget && !at_target)
  4307. {
  4308. //trigger not_at_target
  4309. SceneObjectPart[] parts = m_parts.GetArray();
  4310. uint[] localids = new uint[parts.Length];
  4311. for (int i = 0; i < parts.Length; i++)
  4312. localids[i] = parts[i].LocalId;
  4313. for (int ctr = 0; ctr < localids.Length; ctr++)
  4314. {
  4315. m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
  4316. }
  4317. }
  4318. }
  4319. }
  4320. if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
  4321. {
  4322. if (m_rotTargets.Count > 0)
  4323. {
  4324. bool at_Rottarget = false;
  4325. Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
  4326. lock (m_rotTargets)
  4327. {
  4328. foreach (uint idx in m_rotTargets.Keys)
  4329. {
  4330. scriptRotTarget target = m_rotTargets[idx];
  4331. double angle
  4332. = Math.Acos(
  4333. target.targetRot.X * m_rootPart.RotationOffset.X
  4334. + target.targetRot.Y * m_rootPart.RotationOffset.Y
  4335. + target.targetRot.Z * m_rootPart.RotationOffset.Z
  4336. + target.targetRot.W * m_rootPart.RotationOffset.W)
  4337. * 2;
  4338. if (angle < 0) angle = -angle;
  4339. if (angle > Math.PI) angle = (Math.PI * 2 - angle);
  4340. if (angle <= target.tolerance)
  4341. {
  4342. // trigger at_rot_target
  4343. if (m_scriptListens_atRotTarget)
  4344. {
  4345. at_Rottarget = true;
  4346. scriptRotTarget att = new scriptRotTarget();
  4347. att.targetRot = target.targetRot;
  4348. att.tolerance = target.tolerance;
  4349. att.handle = target.handle;
  4350. atRotTargets.Add(idx, att);
  4351. }
  4352. }
  4353. }
  4354. }
  4355. if (atRotTargets.Count > 0)
  4356. {
  4357. SceneObjectPart[] parts = m_parts.GetArray();
  4358. uint[] localids = new uint[parts.Length];
  4359. for (int i = 0; i < parts.Length; i++)
  4360. localids[i] = parts[i].LocalId;
  4361. for (int ctr = 0; ctr < localids.Length; ctr++)
  4362. {
  4363. foreach (uint target in atRotTargets.Keys)
  4364. {
  4365. scriptRotTarget att = atRotTargets[target];
  4366. m_scene.EventManager.TriggerAtRotTargetEvent(
  4367. localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
  4368. }
  4369. }
  4370. return;
  4371. }
  4372. if (m_scriptListens_notAtRotTarget && !at_Rottarget)
  4373. {
  4374. //trigger not_at_target
  4375. SceneObjectPart[] parts = m_parts.GetArray();
  4376. uint[] localids = new uint[parts.Length];
  4377. for (int i = 0; i < parts.Length; i++)
  4378. localids[i] = parts[i].LocalId;
  4379. for (int ctr = 0; ctr < localids.Length; ctr++)
  4380. {
  4381. m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
  4382. }
  4383. }
  4384. }
  4385. }
  4386. }
  4387. public Vector3 GetGeometricCenter()
  4388. {
  4389. // this is not real geometric center but a average of positions relative to root prim acording to
  4390. // http://wiki.secondlife.com/wiki/llGetGeometricCenter
  4391. // ignoring tortured prims details since sl also seems to ignore
  4392. // so no real use in doing it on physics
  4393. Vector3 gc = Vector3.Zero;
  4394. SceneObjectPart[] parts = m_parts.GetArray();
  4395. int nparts = parts.Length;
  4396. if (nparts < 2)
  4397. return gc;
  4398. // average all parts positions
  4399. for (int i = 0; i < nparts; i++)
  4400. {
  4401. if (parts[i] != RootPart)
  4402. gc += parts[i].OffsetPosition;
  4403. }
  4404. gc /= nparts;
  4405. return gc;
  4406. }
  4407. public float GetMass()
  4408. {
  4409. float retmass = 0f;
  4410. SceneObjectPart[] parts = m_parts.GetArray();
  4411. for (int i = 0; i < parts.Length; i++)
  4412. retmass += parts[i].GetMass();
  4413. return retmass;
  4414. }
  4415. // center of mass of full object
  4416. public Vector3 GetCenterOfMass()
  4417. {
  4418. PhysicsActor pa = RootPart.PhysActor;
  4419. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4420. {
  4421. // physics knows better about center of mass of physical prims
  4422. Vector3 tmp = pa.CenterOfMass;
  4423. return tmp;
  4424. }
  4425. Vector3 Ptot = Vector3.Zero;
  4426. float totmass = 0f;
  4427. float m;
  4428. SceneObjectPart[] parts = m_parts.GetArray();
  4429. for (int i = 0; i < parts.Length; i++)
  4430. {
  4431. m = parts[i].GetMass();
  4432. Ptot += parts[i].GetPartCenterOfMass() * m;
  4433. totmass += m;
  4434. }
  4435. if (totmass == 0)
  4436. totmass = 0;
  4437. else
  4438. totmass = 1 / totmass;
  4439. Ptot *= totmass;
  4440. return Ptot;
  4441. }
  4442. public void GetInertiaData(out float TotalMass, out Vector3 CenterOfMass, out Vector3 Inertia, out Vector4 aux )
  4443. {
  4444. PhysicsActor pa = RootPart.PhysActor;
  4445. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4446. {
  4447. PhysicsInertiaData inertia;
  4448. inertia = pa.GetInertiaData();
  4449. TotalMass = inertia.TotalMass;
  4450. CenterOfMass = inertia.CenterOfMass;
  4451. Inertia = inertia.Inertia;
  4452. aux = inertia.InertiaRotation;
  4453. return;
  4454. }
  4455. TotalMass = GetMass();
  4456. CenterOfMass = GetCenterOfMass() - AbsolutePosition;
  4457. CenterOfMass *= Quaternion.Conjugate(RootPart.RotationOffset);
  4458. Inertia = Vector3.Zero;
  4459. aux = Vector4.Zero;
  4460. }
  4461. public void SetInertiaData(float TotalMass, Vector3 CenterOfMass, Vector3 Inertia, Vector4 aux )
  4462. {
  4463. PhysicsInertiaData inertia = new PhysicsInertiaData();
  4464. inertia.TotalMass = TotalMass;
  4465. inertia.CenterOfMass = CenterOfMass;
  4466. inertia.Inertia = Inertia;
  4467. inertia.InertiaRotation = aux;
  4468. if(TotalMass < 0)
  4469. RootPart.PhysicsInertia = null;
  4470. else
  4471. RootPart.PhysicsInertia = new PhysicsInertiaData(inertia);
  4472. PhysicsActor pa = RootPart.PhysActor;
  4473. if(pa !=null)
  4474. pa.SetInertiaData(inertia);
  4475. }
  4476. /// <summary>
  4477. /// Set the user group to which this scene object belongs.
  4478. /// </summary>
  4479. /// <param name="GroupID"></param>
  4480. /// <param name="client"></param>
  4481. public void SetGroup(UUID GroupID, IClientAPI client)
  4482. {
  4483. SceneObjectPart[] parts = m_parts.GetArray();
  4484. for (int i = 0; i < parts.Length; i++)
  4485. {
  4486. SceneObjectPart part = parts[i];
  4487. part.SetGroup(GroupID, client);
  4488. part.Inventory.ChangeInventoryGroup(GroupID);
  4489. }
  4490. HasGroupChanged = true;
  4491. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  4492. // for the same object with very different properties. The caller must schedule the update.
  4493. //ScheduleGroupForFullUpdate();
  4494. }
  4495. public void TriggerScriptChangedEvent(Changed val)
  4496. {
  4497. SceneObjectPart[] parts = m_parts.GetArray();
  4498. for (int i = 0; i < parts.Length; i++)
  4499. parts[i].TriggerScriptChangedEvent(val);
  4500. }
  4501. /// <summary>
  4502. /// Returns a count of the number of scripts in this groups parts.
  4503. /// </summary>
  4504. public int ScriptCount()
  4505. {
  4506. int count = 0;
  4507. SceneObjectPart[] parts = m_parts.GetArray();
  4508. for (int i = 0; i < parts.Length; i++)
  4509. count += parts[i].Inventory.ScriptCount();
  4510. return count;
  4511. }
  4512. /// <summary>
  4513. /// A float the value is a representative execution time in milliseconds of all scripts in the link set.
  4514. /// </summary>
  4515. public float ScriptExecutionTime()
  4516. {
  4517. IScriptModule[] engines = Scene.RequestModuleInterfaces<IScriptModule>();
  4518. if (engines.Length == 0) // No engine at all
  4519. return 0.0f;
  4520. float time = 0.0f;
  4521. // get all the scripts in all parts
  4522. SceneObjectPart[] parts = m_parts.GetArray();
  4523. List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
  4524. for (int i = 0; i < parts.Length; i++)
  4525. {
  4526. scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
  4527. }
  4528. // extract the UUIDs
  4529. List<UUID> ids = new List<UUID>(scripts.Count);
  4530. foreach (TaskInventoryItem script in scripts)
  4531. {
  4532. if (!ids.Contains(script.ItemID))
  4533. {
  4534. ids.Add(script.ItemID);
  4535. }
  4536. }
  4537. // Offer the list of script UUIDs to each engine found and accumulate the time
  4538. foreach (IScriptModule e in engines)
  4539. {
  4540. if (e != null)
  4541. {
  4542. time += e.GetScriptExecutionTime(ids);
  4543. }
  4544. }
  4545. return time;
  4546. }
  4547. /// <summary>
  4548. /// Returns a count of the number of running scripts in this groups parts.
  4549. /// </summary>
  4550. public int RunningScriptCount()
  4551. {
  4552. int count = 0;
  4553. SceneObjectPart[] parts = m_parts.GetArray();
  4554. for (int i = 0; i < parts.Length; i++)
  4555. count += parts[i].Inventory.RunningScriptCount();
  4556. return count;
  4557. }
  4558. /// <summary>
  4559. /// Get a copy of the list of sitting avatars on all prims of this object.
  4560. /// </summary>
  4561. /// <remarks>
  4562. /// This is sorted by the order in which avatars sat down. If an avatar stands up then all avatars that sat
  4563. /// down after it move one place down the list.
  4564. /// </remarks>
  4565. /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns>
  4566. public List<ScenePresence> GetSittingAvatars()
  4567. {
  4568. lock (m_sittingAvatars)
  4569. return new List<ScenePresence>(m_sittingAvatars);
  4570. }
  4571. /// <summary>
  4572. /// Gets the number of sitting avatars.
  4573. /// </summary>
  4574. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4575. /// <returns></returns>
  4576. public int GetSittingAvatarsCount()
  4577. {
  4578. lock (m_sittingAvatars)
  4579. return m_sittingAvatars.Count;
  4580. }
  4581. public override string ToString()
  4582. {
  4583. return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
  4584. }
  4585. #region ISceneObject
  4586. public virtual ISceneObject CloneForNewScene()
  4587. {
  4588. SceneObjectGroup sog = Copy(false);
  4589. sog.IsDeleted = false;
  4590. return sog;
  4591. }
  4592. public virtual string ToXml2()
  4593. {
  4594. return SceneObjectSerializer.ToXml2Format(this);
  4595. }
  4596. public virtual string ExtraToXmlString()
  4597. {
  4598. return "<ExtraFromItemID>" + FromItemID.ToString() + "</ExtraFromItemID>";
  4599. }
  4600. public virtual void ExtraFromXmlString(string xmlstr)
  4601. {
  4602. string id = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromItemID>"));
  4603. id = xmlstr.Replace("<ExtraFromItemID>", "");
  4604. id = id.Replace("</ExtraFromItemID>", "");
  4605. UUID uuid = UUID.Zero;
  4606. UUID.TryParse(id, out uuid);
  4607. FromItemID = uuid;
  4608. }
  4609. public void ResetOwnerChangeFlag()
  4610. {
  4611. ForEachPart(delegate(SceneObjectPart part)
  4612. {
  4613. part.ResetOwnerChangeFlag();
  4614. });
  4615. InvalidateEffectivePerms();
  4616. }
  4617. // clear some references to easy cg
  4618. public void Clear()
  4619. {
  4620. m_parts.Clear();
  4621. m_sittingAvatars.Clear();
  4622. // m_rootPart = null;
  4623. m_PlaySoundMasterPrim = null;
  4624. m_PlaySoundSlavePrims.Clear();
  4625. m_LoopSoundMasterPrim = null;
  4626. m_targets.Clear();
  4627. m_partsNameToLinkMap.Clear();
  4628. }
  4629. private Dictionary<string,int> m_partsNameToLinkMap = new Dictionary<string, int>();
  4630. private string GetLinkNumber_lastname;
  4631. private int GetLinkNumber_lastnumber;
  4632. // this scales bad but so does GetLinkNumPart
  4633. public int GetLinkNumber(string name)
  4634. {
  4635. if(String.IsNullOrEmpty(name) || name == "Object")
  4636. return -1;
  4637. lock(m_partsNameToLinkMap)
  4638. {
  4639. if(m_partsNameToLinkMap.Count == 0)
  4640. {
  4641. GetLinkNumber_lastname = String.Empty;
  4642. GetLinkNumber_lastnumber = -1;
  4643. SceneObjectPart[] parts = m_parts.GetArray();
  4644. for (int i = 0; i < parts.Length; i++)
  4645. {
  4646. string s = parts[i].Name;
  4647. if(String.IsNullOrEmpty(s) || s == "Object" || s == "Primitive")
  4648. continue;
  4649. if(m_partsNameToLinkMap.ContainsKey(s))
  4650. {
  4651. int ol = parts[i].LinkNum;
  4652. if(ol < m_partsNameToLinkMap[s])
  4653. m_partsNameToLinkMap[s] = ol;
  4654. }
  4655. else
  4656. m_partsNameToLinkMap[s] = parts[i].LinkNum;
  4657. }
  4658. }
  4659. if(name == GetLinkNumber_lastname)
  4660. return GetLinkNumber_lastnumber;
  4661. if(m_partsNameToLinkMap.ContainsKey(name))
  4662. {
  4663. lock(m_partsNameToLinkMap)
  4664. {
  4665. GetLinkNumber_lastname = name;
  4666. GetLinkNumber_lastnumber = m_partsNameToLinkMap[name];
  4667. return GetLinkNumber_lastnumber;
  4668. }
  4669. }
  4670. }
  4671. if(m_sittingAvatars.Count > 0)
  4672. {
  4673. int j = m_parts.Count + 1;
  4674. ScenePresence[] avs = m_sittingAvatars.ToArray();
  4675. for (int i = 0; i < avs.Length; i++, j++)
  4676. {
  4677. if (avs[i].Name == name)
  4678. {
  4679. GetLinkNumber_lastname = name;
  4680. GetLinkNumber_lastnumber = j;
  4681. return j;
  4682. }
  4683. }
  4684. }
  4685. return -1;
  4686. }
  4687. public void InvalidatePartsLinkMaps()
  4688. {
  4689. lock(m_partsNameToLinkMap)
  4690. {
  4691. m_partsNameToLinkMap.Clear();
  4692. GetLinkNumber_lastname = String.Empty;
  4693. GetLinkNumber_lastnumber = -1;
  4694. }
  4695. }
  4696. public bool CollisionSoundThrottled(int collisionSoundType)
  4697. {
  4698. double time = m_lastCollisionSoundMS;
  4699. // m_lastCollisionSoundMS = Util.GetTimeStampMS();
  4700. // time = m_lastCollisionSoundMS - time;
  4701. double now = Util.GetTimeStampMS();
  4702. time = now - time;
  4703. switch (collisionSoundType)
  4704. {
  4705. case 0: // default sounds
  4706. case 2: // default sounds with volume set by script
  4707. if(time < 300.0)
  4708. return true;
  4709. break;
  4710. case 1: // selected sound
  4711. if(time < 200.0)
  4712. return true;
  4713. break;
  4714. default:
  4715. break;
  4716. }
  4717. m_lastCollisionSoundMS = now;
  4718. return false;
  4719. }
  4720. #endregion
  4721. }
  4722. }