SceneObjectPart.cs 171 KB

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