SceneObjectPart.cs 175 KB

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