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