SceneObjectPart.cs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693
  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 OpenSim 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.Runtime.Serialization;
  31. using System.Security.Permissions;
  32. using System.Xml;
  33. using System.Xml.Serialization;
  34. using Axiom.Math;
  35. using libsecondlife;
  36. using libsecondlife.Packets;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Environment.Scenes.Scripting;
  39. using OpenSim.Region.Physics.Manager;
  40. namespace OpenSim.Region.Environment.Scenes
  41. {
  42. // I don't really know where to put this except here.
  43. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  44. [Flags]
  45. public enum ExtraParamType
  46. {
  47. Something1 = 1,
  48. Something2 = 2,
  49. Something3 = 4,
  50. Something4 = 8,
  51. Flexible = 16,
  52. Light = 32,
  53. Sculpt = 48,
  54. Something5 = 64,
  55. Something6 = 128
  56. }
  57. [Flags]
  58. public enum Changed : uint
  59. {
  60. INVENTORY = 1,
  61. COLOR = 2,
  62. SHAPE = 4,
  63. SCALE = 8,
  64. TEXTURE = 16,
  65. LINK = 32,
  66. ALLOWED_DROP = 64,
  67. OWNER = 128
  68. }
  69. [Flags]
  70. public enum TextureAnimFlags : byte
  71. {
  72. NONE = 0x00,
  73. ANIM_ON = 0x01,
  74. LOOP = 0x02,
  75. REVERSE = 0x04,
  76. PING_PONG = 0x08,
  77. SMOOTH = 0x10,
  78. ROTATE = 0x20,
  79. SCALE = 0x40
  80. }
  81. [Serializable]
  82. public partial class SceneObjectPart : IScriptHost, ISerializable
  83. {
  84. [XmlIgnore] public PhysicsActor PhysActor = null;
  85. public LLUUID LastOwnerID;
  86. public LLUUID OwnerID;
  87. public LLUUID GroupID;
  88. public int OwnershipCost;
  89. public byte ObjectSaleType;
  90. public int SalePrice;
  91. public uint Category;
  92. // TODO: This needs to be persisted in next XML version update!
  93. [XmlIgnore] public int[] PayPrice = {-2,-2,-2,-2,-2};
  94. [XmlIgnore] private Dictionary<LLUUID, scriptEvents> m_scriptEvents = new Dictionary<LLUUID, scriptEvents>();
  95. [XmlIgnore] public scriptEvents m_aggregateScriptEvents=0;
  96. [XmlIgnore] private LLObject.ObjectFlags LocalFlags = LLObject.ObjectFlags.None;
  97. [XmlIgnore] public bool m_IsAttachment = false;
  98. [XmlIgnore] public uint m_attachmentPoint = (byte)0;
  99. [XmlIgnore] public LLUUID m_attachedAvatar = LLUUID.Zero;
  100. [XmlIgnore] public LLVector3 m_attachedPos = LLVector3.Zero;
  101. [XmlIgnore] public LLUUID fromAssetID = LLUUID.Zero;
  102. [XmlIgnore] public bool m_undoing = false;
  103. public Int32 CreationDate;
  104. public uint ParentID = 0;
  105. private PhysicsVector m_lastRotationalVelocity = PhysicsVector.Zero;
  106. private Vector3 m_sitTargetPosition = new Vector3(0, 0, 0);
  107. private Quaternion m_sitTargetOrientation = new Quaternion(0, 0, 0, 1);
  108. public LLUUID m_sitTargetAvatar = LLUUID.Zero;
  109. [XmlIgnore] public PhysicsVector m_rotationAxis = new PhysicsVector(1f,1f,1f);
  110. #region Permissions
  111. public uint BaseMask = (uint)PermissionMask.All;
  112. public uint OwnerMask = (uint)PermissionMask.All;
  113. public uint GroupMask = (uint)PermissionMask.None;
  114. public uint EveryoneMask = (uint)PermissionMask.None;
  115. public uint NextOwnerMask = (uint)PermissionMask.All;
  116. private UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5);
  117. public LLObject.ObjectFlags Flags = LLObject.ObjectFlags.None;
  118. public uint ObjectFlags
  119. {
  120. get { return (uint)Flags; }
  121. set { Flags = (LLObject.ObjectFlags)value; }
  122. }
  123. #endregion
  124. protected byte[] m_particleSystem = new byte[0];
  125. [XmlIgnore] public uint TimeStampFull = 0;
  126. [XmlIgnore] public uint TimeStampTerse = 0;
  127. [XmlIgnore] public uint TimeStampLastActivity = 0; // Will be used for AutoReturn
  128. /// <summary>
  129. /// Only used internally to schedule client updates.
  130. /// 0 - no update is scheduled
  131. /// 1 - terse update scheduled
  132. /// 2 - full update scheduled
  133. ///
  134. /// TODO - This should be an enumeration
  135. /// </summary>
  136. private byte m_updateFlag;
  137. #region Properties
  138. public LLUUID CreatorID;
  139. public LLUUID ObjectCreator
  140. {
  141. get { return CreatorID; }
  142. }
  143. protected LLUUID m_uuid;
  144. public LLUUID UUID
  145. {
  146. get { return m_uuid; }
  147. set { m_uuid = value; }
  148. }
  149. protected uint m_localId;
  150. public uint LocalId
  151. {
  152. get { return m_localId; }
  153. set { m_localId = value; }
  154. }
  155. protected string m_name;
  156. public virtual string Name
  157. {
  158. get { return m_name; }
  159. set { m_name = value; }
  160. }
  161. public scriptEvents ScriptEvents
  162. {
  163. get { return m_aggregateScriptEvents; }
  164. }
  165. protected LLObject.MaterialType m_material = 0;
  166. public byte Material
  167. {
  168. get { return (byte) m_material; }
  169. set { m_material = (LLObject.MaterialType) value; }
  170. }
  171. protected ulong m_regionHandle;
  172. public ulong RegionHandle
  173. {
  174. get { return m_regionHandle; }
  175. set { m_regionHandle = value; }
  176. }
  177. public uint GetEffectiveObjectFlags()
  178. {
  179. LLObject.ObjectFlags f=Flags;
  180. if(m_parentGroup == null || m_parentGroup.RootPart == this)
  181. f &= ~(LLObject.ObjectFlags.Touch | LLObject.ObjectFlags.Money);
  182. return (uint)Flags | (uint)LocalFlags;
  183. }
  184. //unkown if this will be kept, added as a way of removing the group position from the group class
  185. protected LLVector3 m_groupPosition;
  186. /// <summary>
  187. /// Method for a prim to get it's world position from the group.
  188. /// Remember, the Group Position simply gives the position of the group itself
  189. /// </summary>
  190. /// <returns>A Linked Child Prim objects position in world</returns>
  191. public LLVector3 GetWorldPosition()
  192. {
  193. Quaternion parentRot = new Quaternion(
  194. ParentGroup.RootPart.RotationOffset.W,
  195. ParentGroup.RootPart.RotationOffset.X,
  196. ParentGroup.RootPart.RotationOffset.Y,
  197. ParentGroup.RootPart.RotationOffset.Z);
  198. Vector3 axPos
  199. = new Vector3(
  200. OffsetPosition.X,
  201. OffsetPosition.Y,
  202. OffsetPosition.Z);
  203. axPos = parentRot * axPos;
  204. LLVector3 translationOffsetPosition = new LLVector3(axPos.x, axPos.y, axPos.z);
  205. return GroupPosition + translationOffsetPosition;
  206. //return (new LLVector3(axiomPos.x, axiomPos.y, axiomPos.z) + AbsolutePosition);
  207. }
  208. /// <summary>
  209. /// Gets the rotation of this prim offset by the group rotation
  210. /// </summary>
  211. /// <returns></returns>
  212. public LLQuaternion GetWorldRotation()
  213. {
  214. Quaternion newRot;
  215. if (this.LinkNum == 0)
  216. {
  217. newRot = new Quaternion(RotationOffset.W,RotationOffset.X,RotationOffset.Y,RotationOffset.Z);
  218. }
  219. else
  220. {
  221. Quaternion parentRot = new Quaternion(
  222. ParentGroup.RootPart.RotationOffset.W,
  223. ParentGroup.RootPart.RotationOffset.X,
  224. ParentGroup.RootPart.RotationOffset.Y,
  225. ParentGroup.RootPart.RotationOffset.Z);
  226. Quaternion oldRot
  227. = new Quaternion(
  228. RotationOffset.W,
  229. RotationOffset.X,
  230. RotationOffset.Y,
  231. RotationOffset.Z);
  232. newRot = parentRot * oldRot;
  233. }
  234. return new LLQuaternion(newRot.x, newRot.y, newRot.z, newRot.w);
  235. //return new LLQuaternion(axiomPartRotation.x, axiomPartRotation.y, axiomPartRotation.z, axiomPartRotation.w);
  236. }
  237. public void StoreUndoState()
  238. {
  239. if (!m_undoing)
  240. {
  241. if (m_parentGroup != null)
  242. {
  243. if (m_undo.Count > 0)
  244. {
  245. UndoState last = m_undo.Peek();
  246. if (last != null)
  247. {
  248. if (last.Compare(this))
  249. return;
  250. }
  251. }
  252. if (m_parentGroup.GetSceneMaxUndo() > 0)
  253. {
  254. UndoState nUndo = new UndoState(this);
  255. m_undo.Push(nUndo);
  256. }
  257. }
  258. }
  259. }
  260. public void ClearUndoState()
  261. {
  262. m_undo.Clear();
  263. StoreUndoState();
  264. }
  265. public LLVector3 GroupPosition
  266. {
  267. get
  268. {
  269. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  270. if (PhysActor != null && ParentID == 0)
  271. {
  272. m_groupPosition.X = PhysActor.Position.X;
  273. m_groupPosition.Y = PhysActor.Position.Y;
  274. m_groupPosition.Z = PhysActor.Position.Z;
  275. }
  276. if (m_IsAttachment)
  277. {
  278. ScenePresence sp = m_parentGroup.Scene.GetScenePresence(m_attachedAvatar);
  279. if (sp != null)
  280. {
  281. return sp.AbsolutePosition;
  282. }
  283. }
  284. return m_groupPosition;
  285. }
  286. set
  287. {
  288. StoreUndoState();
  289. m_groupPosition = value;
  290. if (PhysActor != null)
  291. {
  292. try
  293. {
  294. // Root prim actually goes at Position
  295. if (ParentID == 0)
  296. {
  297. PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  298. }
  299. else
  300. {
  301. // To move the child prim in respect to the group position and rotation we have to calculate
  302. LLVector3 resultingposition = GetWorldPosition();
  303. PhysActor.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z);
  304. LLQuaternion resultingrot = GetWorldRotation();
  305. PhysActor.Orientation = new Quaternion(resultingrot.W, resultingrot.X, resultingrot.Y, resultingrot.Z);
  306. }
  307. // Tell the physics engines that this prim changed.
  308. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  309. }
  310. catch (Exception e)
  311. {
  312. Console.WriteLine(e.Message);
  313. }
  314. }
  315. }
  316. }
  317. private byte[] m_TextureAnimation;
  318. protected LLVector3 m_offsetPosition;
  319. public LLVector3 OffsetPosition
  320. {
  321. get { return m_offsetPosition; }
  322. set
  323. {
  324. StoreUndoState();
  325. m_offsetPosition = value;
  326. try
  327. {
  328. // Hack to get the child prim to update world positions in the physics engine
  329. ParentGroup.ResetChildPrimPhysicsPositions();
  330. }
  331. catch (NullReferenceException)
  332. {
  333. // Ignore, and skip over.
  334. }
  335. //m_log.Info("[PART]: OFFSET:" + m_offsetPosition.ToString());
  336. }
  337. }
  338. public LLVector3 AbsolutePosition
  339. {
  340. get {
  341. if (m_IsAttachment)
  342. return GroupPosition;
  343. return m_offsetPosition + m_groupPosition; }
  344. }
  345. protected LLQuaternion m_rotationOffset;
  346. public LLQuaternion RotationOffset
  347. {
  348. get
  349. {
  350. // We don't want the physics engine mucking up the rotations in a linkset
  351. if (PhysActor != null && ParentID == 0)
  352. {
  353. if (PhysActor.Orientation.x != 0 || PhysActor.Orientation.y != 0
  354. || PhysActor.Orientation.z != 0 || PhysActor.Orientation.w != 0)
  355. {
  356. m_rotationOffset.X = PhysActor.Orientation.x;
  357. m_rotationOffset.Y = PhysActor.Orientation.y;
  358. m_rotationOffset.Z = PhysActor.Orientation.z;
  359. m_rotationOffset.W = PhysActor.Orientation.w;
  360. }
  361. }
  362. return m_rotationOffset;
  363. }
  364. set
  365. {
  366. StoreUndoState();
  367. m_rotationOffset = value;
  368. if (PhysActor != null)
  369. {
  370. try
  371. {
  372. // Root prim gets value directly
  373. if (ParentID == 0)
  374. {
  375. PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z);
  376. //m_log.Info("[PART]: RO1:" + PhysActor.Orientation.ToString());
  377. }
  378. else
  379. {
  380. // Child prim we have to calculate it's world rotationwel
  381. LLQuaternion resultingrotation = GetWorldRotation();
  382. PhysActor.Orientation = new Quaternion(resultingrotation.W, resultingrotation.X, resultingrotation.Y, resultingrotation.Z);
  383. //m_log.Info("[PART]: RO2:" + PhysActor.Orientation.ToString());
  384. }
  385. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  386. //}
  387. }
  388. catch (Exception ex)
  389. {
  390. Console.WriteLine(ex.Message);
  391. }
  392. }
  393. }
  394. }
  395. protected LLVector3 m_velocity;
  396. protected LLVector3 m_rotationalvelocity;
  397. /// <summary></summary>
  398. public LLVector3 Velocity
  399. {
  400. get
  401. {
  402. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  403. //|| PhysActor.Velocity.z != 0)
  404. //{
  405. if (PhysActor != null)
  406. {
  407. if (PhysActor.IsPhysical)
  408. {
  409. m_velocity.X = PhysActor.Velocity.X;
  410. m_velocity.Y = PhysActor.Velocity.Y;
  411. m_velocity.Z = PhysActor.Velocity.Z;
  412. }
  413. }
  414. return m_velocity;
  415. }
  416. set {
  417. m_velocity = value;
  418. if (PhysActor != null)
  419. {
  420. if (PhysActor.IsPhysical)
  421. {
  422. PhysActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  423. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  424. }
  425. }
  426. }
  427. }
  428. public LLVector3 RotationalVelocity
  429. {
  430. get
  431. {
  432. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  433. //|| PhysActor.Velocity.z != 0)
  434. //{
  435. if (PhysActor != null)
  436. {
  437. if (PhysActor.IsPhysical)
  438. {
  439. m_rotationalvelocity.FromBytes(PhysActor.RotationalVelocity.GetBytes(),0);
  440. }
  441. }
  442. return m_rotationalvelocity;
  443. }
  444. set { m_rotationalvelocity = value; }
  445. }
  446. protected LLVector3 m_angularVelocity;
  447. /// <summary></summary>
  448. public LLVector3 AngularVelocity
  449. {
  450. get { return m_angularVelocity; }
  451. set { m_angularVelocity = value; }
  452. }
  453. protected LLVector3 m_acceleration;
  454. /// <summary></summary>
  455. public LLVector3 Acceleration
  456. {
  457. get { return m_acceleration; }
  458. set { m_acceleration = value; }
  459. }
  460. private string m_description = String.Empty;
  461. public string Description
  462. {
  463. get { return m_description; }
  464. set { m_description = value; }
  465. }
  466. private Color m_color = Color.Black;
  467. public Color Color
  468. {
  469. get { return m_color; }
  470. set
  471. {
  472. m_color = value;
  473. TriggerScriptChangedEvent(Changed.COLOR);
  474. /* ScheduleFullUpdate() need not be called b/c after
  475. * setting the color, the text will be set, so then
  476. * ScheduleFullUpdate() will be called. */
  477. //ScheduleFullUpdate();
  478. }
  479. }
  480. private string m_text = String.Empty;
  481. public Vector3 SitTargetPosition
  482. {
  483. get { return m_sitTargetPosition; }
  484. }
  485. public Quaternion SitTargetOrientation
  486. {
  487. get { return m_sitTargetOrientation; }
  488. }
  489. public string Text
  490. {
  491. get { return m_text; }
  492. set
  493. {
  494. m_text = value;
  495. }
  496. }
  497. private string m_sitName = String.Empty;
  498. public string SitName
  499. {
  500. get { return m_sitName; }
  501. set { m_sitName = value; }
  502. }
  503. private string m_touchName = String.Empty;
  504. public string TouchName
  505. {
  506. get { return m_touchName; }
  507. set { m_touchName = value; }
  508. }
  509. private int m_linkNum = 0;
  510. public int LinkNum
  511. {
  512. get { return m_linkNum; }
  513. set
  514. {
  515. m_linkNum = value;
  516. TriggerScriptChangedEvent(Changed.LINK);
  517. }
  518. }
  519. private byte m_clickAction = 0;
  520. public byte ClickAction
  521. {
  522. get { return m_clickAction; }
  523. set
  524. {
  525. m_clickAction = value;
  526. }
  527. }
  528. protected PrimitiveBaseShape m_shape;
  529. /// <summary>
  530. /// hook to the physics scene to apply impulse
  531. /// This is sent up to the group, which then finds the root prim
  532. /// and applies the force on the root prim of the group
  533. /// </summary>
  534. /// <param name="impulsei">Vector force</param>
  535. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  536. public void ApplyImpulse(LLVector3 impulsei, bool localGlobalTF)
  537. {
  538. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  539. if (localGlobalTF)
  540. {
  541. LLQuaternion grot = GetWorldRotation();
  542. Quaternion AXgrot = new Quaternion(grot.W,grot.X,grot.Y,grot.Z);
  543. Vector3 AXimpulsei = new Vector3(impulsei.X, impulsei.Y, impulsei.Z);
  544. Vector3 newimpulse = AXgrot * AXimpulsei;
  545. impulse = new PhysicsVector(newimpulse.x, newimpulse.y, newimpulse.z);
  546. }
  547. else
  548. {
  549. if (m_parentGroup != null)
  550. {
  551. m_parentGroup.applyImpulse(impulse);
  552. }
  553. }
  554. }
  555. public void MoveToTarget(LLVector3 target, float tau)
  556. {
  557. if (tau > 0)
  558. {
  559. m_parentGroup.moveToTarget(target, tau);
  560. }
  561. else
  562. {
  563. StopMoveToTarget();
  564. }
  565. }
  566. public void StopMoveToTarget()
  567. {
  568. m_parentGroup.stopMoveToTarget();
  569. }
  570. public void TriggerScriptChangedEvent(Changed val)
  571. {
  572. if (m_parentGroup != null)
  573. {
  574. if (m_parentGroup.Scene != null)
  575. m_parentGroup.Scene.TriggerObjectChanged(LocalId, (uint)val);
  576. }
  577. }
  578. public PrimitiveBaseShape Shape
  579. {
  580. get { return m_shape; }
  581. set
  582. {
  583. m_shape = value;
  584. TriggerScriptChangedEvent(Changed.SHAPE);
  585. }
  586. }
  587. public LLVector3 Scale
  588. {
  589. get { return m_shape.Scale; }
  590. set
  591. {
  592. StoreUndoState();
  593. m_shape.Scale = value;
  594. TriggerScriptChangedEvent(Changed.SCALE);
  595. }
  596. }
  597. public bool Stopped
  598. {
  599. get {
  600. double threshold = 0.02;
  601. return (Math.Abs(Velocity.X) < threshold &&
  602. Math.Abs(Velocity.Y) < threshold &&
  603. Math.Abs(Velocity.Z) < threshold &&
  604. Math.Abs(AngularVelocity.X) < threshold &&
  605. Math.Abs(AngularVelocity.Y) < threshold &&
  606. Math.Abs(AngularVelocity.Z) < threshold);
  607. }
  608. }
  609. #endregion
  610. public LLUUID ObjectOwner
  611. {
  612. get { return OwnerID; }
  613. }
  614. // FIXME, TODO, ERROR: 'ParentGroup' can't be in here, move it out.
  615. protected SceneObjectGroup m_parentGroup;
  616. public SceneObjectGroup ParentGroup
  617. {
  618. get { return m_parentGroup; }
  619. }
  620. public byte UpdateFlag
  621. {
  622. get { return m_updateFlag; }
  623. set { m_updateFlag = value; }
  624. }
  625. #region Constructors
  626. /// <summary>
  627. /// No arg constructor called by region restore db code
  628. /// </summary>
  629. public SceneObjectPart()
  630. {
  631. // It's not necessary to persist this
  632. m_inventoryFileName = "inventory_" + LLUUID.Random().ToString() + ".tmp";
  633. m_TextureAnimation = new byte[0];
  634. }
  635. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  636. PrimitiveBaseShape shape, LLVector3 groupPosition, LLVector3 offsetPosition)
  637. : this(regionHandle, parent, ownerID, localID, shape, groupPosition, LLQuaternion.Identity, offsetPosition)
  638. {
  639. }
  640. /// <summary>
  641. /// Create a completely new SceneObjectPart (prim)
  642. /// </summary>
  643. /// <param name="regionHandle"></param>
  644. /// <param name="parent"></param>
  645. /// <param name="ownerID"></param>
  646. /// <param name="localID"></param>
  647. /// <param name="shape"></param>
  648. /// <param name="position"></param>
  649. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  650. PrimitiveBaseShape shape, LLVector3 groupPosition, LLQuaternion rotationOffset,
  651. LLVector3 offsetPosition)
  652. {
  653. m_name = "Primitive";
  654. m_regionHandle = regionHandle;
  655. m_parentGroup = parent;
  656. CreationDate = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  657. OwnerID = ownerID;
  658. CreatorID = OwnerID;
  659. LastOwnerID = LLUUID.Zero;
  660. UUID = LLUUID.Random();
  661. LocalId = (uint) (localID);
  662. Shape = shape;
  663. // Todo: Add More Object Parameter from above!
  664. OwnershipCost = 0;
  665. ObjectSaleType = (byte) 0;
  666. SalePrice = 0;
  667. Category = (uint) 0;
  668. LastOwnerID = CreatorID;
  669. // End Todo: ///
  670. GroupPosition = groupPosition;
  671. OffsetPosition = offsetPosition;
  672. RotationOffset = rotationOffset;
  673. Velocity = new LLVector3(0, 0, 0);
  674. m_rotationalvelocity = new LLVector3(0, 0, 0);
  675. AngularVelocity = new LLVector3(0, 0, 0);
  676. Acceleration = new LLVector3(0, 0, 0);
  677. m_TextureAnimation = new byte[0];
  678. m_inventoryFileName = "inventory_" + LLUUID.Random().ToString() + ".tmp";
  679. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  680. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  681. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  682. m_folderID = UUID;
  683. Flags = 0;
  684. Flags |= LLObject.ObjectFlags.AllowInventoryDrop |
  685. LLObject.ObjectFlags.CreateSelected;
  686. TrimPermissions();
  687. //m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo());
  688. ScheduleFullUpdate();
  689. }
  690. /// <summary>
  691. /// Re/create a SceneObjectPart (prim)
  692. /// currently not used, and maybe won't be
  693. /// </summary>
  694. /// <param name="regionHandle"></param>
  695. /// <param name="parent"></param>
  696. /// <param name="ownerID"></param>
  697. /// <param name="localID"></param>
  698. /// <param name="shape"></param>
  699. /// <param name="position"></param>
  700. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, int creationDate, LLUUID ownerID,
  701. LLUUID creatorID, LLUUID lastOwnerID, uint localID, PrimitiveBaseShape shape,
  702. LLVector3 position, LLQuaternion rotation, uint flags)
  703. {
  704. m_regionHandle = regionHandle;
  705. m_parentGroup = parent;
  706. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  707. CreationDate = creationDate;
  708. OwnerID = ownerID;
  709. CreatorID = creatorID;
  710. LastOwnerID = lastOwnerID;
  711. UUID = LLUUID.Random();
  712. LocalId = (uint) (localID);
  713. Shape = shape;
  714. OwnershipCost = 0;
  715. ObjectSaleType = (byte) 0;
  716. SalePrice = 0;
  717. Category = (uint) 0;
  718. LastOwnerID = CreatorID;
  719. OffsetPosition = position;
  720. RotationOffset = rotation;
  721. ObjectFlags = flags;
  722. // Since we don't store script state, this is only a 'temporary' objectflag now
  723. // If the object is scripted, the script will get loaded and this will be set again
  724. ObjectFlags &= ~(uint)(LLObject.ObjectFlags.Scripted | LLObject.ObjectFlags.Touch);
  725. TrimPermissions();
  726. // ApplyPhysics();
  727. ScheduleFullUpdate();
  728. }
  729. #endregion
  730. /// <summary>
  731. /// Restore this part from the serialized xml representation.
  732. /// </summary>
  733. /// <param name="xmlreader"></param>
  734. /// <returns></returns>
  735. public static SceneObjectPart FromXml(XmlReader xmlReader)
  736. {
  737. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  738. SceneObjectPart newobject = (SceneObjectPart) serializer.Deserialize(xmlReader);
  739. return newobject;
  740. }
  741. public void ApplyPhysics(uint rootObjectFlags, bool m_physicalPrim)
  742. {
  743. bool isPhysical = (((rootObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0) && m_physicalPrim);
  744. bool isPhantom = ((rootObjectFlags & (uint) LLObject.ObjectFlags.Phantom) != 0);
  745. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  746. bool RigidBody = isPhysical && !isPhantom;
  747. // The only time the physics scene shouldn't know about the prim is if it's phantom
  748. if (!isPhantom)
  749. {
  750. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  751. Name,
  752. Shape,
  753. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  754. AbsolutePosition.Z),
  755. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  756. new Quaternion(RotationOffset.W, RotationOffset.X,
  757. RotationOffset.Y, RotationOffset.Z), RigidBody);
  758. // Basic Physics returns null.. joy joy joy.
  759. if (PhysActor != null)
  760. {
  761. PhysActor.LocalID = LocalId;
  762. DoPhysicsPropertyUpdate(RigidBody, true);
  763. }
  764. }
  765. }
  766. public void ApplyNextOwnerPermissions()
  767. {
  768. BaseMask = NextOwnerMask;
  769. OwnerMask = NextOwnerMask;
  770. TriggerScriptChangedEvent(Changed.OWNER);
  771. }
  772. public void TrimPermissions()
  773. {
  774. BaseMask &= (uint)PermissionMask.All;
  775. OwnerMask &= (uint)PermissionMask.All;
  776. GroupMask &= (uint)PermissionMask.All;
  777. EveryoneMask &= (uint)PermissionMask.All;
  778. NextOwnerMask &= (uint)PermissionMask.All;
  779. }
  780. /// <summary>
  781. /// Serialize this part to xml.
  782. /// </summary>
  783. /// <param name="xmlWriter"></param>
  784. public void ToXml(XmlWriter xmlWriter)
  785. {
  786. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  787. serializer.Serialize(xmlWriter, this);
  788. }
  789. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  790. {
  791. // In this case we're using a sphere with a radius of the largest dimention of the prim
  792. // TODO: Change to take shape into account
  793. EntityIntersection returnresult = new EntityIntersection();
  794. Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z);
  795. Vector3 vScale = new Vector3(Scale.X, Scale.Y, Scale.Z);
  796. Quaternion qRotation =
  797. new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
  798. //Quaternion worldRotation = (qRotation*parentrot);
  799. //Matrix3 worldRotM = worldRotation.ToRotationMatrix();
  800. Vector3 rOrigin = iray.Origin;
  801. Vector3 rDirection = iray.Direction;
  802. //rDirection = rDirection.Normalize();
  803. // Buidling the first part of the Quadratic equation
  804. Vector3 r2ndDirection = rDirection*rDirection;
  805. float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z;
  806. // Buidling the second part of the Quadratic equation
  807. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  808. Vector3 r2Direction = rDirection*2.0f;
  809. Vector3 tmVal3 = r2Direction*tmVal2;
  810. float itestPart2 = tmVal3.x + tmVal3.y + tmVal3.z;
  811. // Buidling the third part of the Quadratic equation
  812. Vector3 tmVal4 = rOrigin*rOrigin;
  813. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  814. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  815. // Set Radius to the largest dimention of the prim
  816. float radius = 0f;
  817. if (vScale.x > radius)
  818. radius = vScale.x;
  819. if (vScale.y > radius)
  820. radius = vScale.y;
  821. if (vScale.z > radius)
  822. radius = vScale.z;
  823. // the second part of this is the default prim size
  824. // once we factor in the aabb of the prim we're adding we can
  825. // change this to;
  826. // radius = (radius / 2) - 0.01f;
  827. //
  828. radius = (radius / 2) + (0.5f / 2) - 0.1f;
  829. //radius = radius;
  830. float itestPart3 = tmVal4.x + tmVal4.y + tmVal4.z + tmVal5.x + tmVal5.y + tmVal5.z -
  831. (2.0f*(tmVal6.x + tmVal6.y + tmVal6.z + (radius*radius)));
  832. // Yuk Quadradrics.. Solve first
  833. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  834. if (rootsqr < 0.0f)
  835. {
  836. // No intersection
  837. return returnresult;
  838. }
  839. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  840. if (root < 0.0f)
  841. {
  842. // perform second quadratic root solution
  843. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  844. // is there any intersection?
  845. if (root < 0.0f)
  846. {
  847. // nope, no intersection
  848. return returnresult;
  849. }
  850. }
  851. // We got an intersection. putting together an EntityIntersection object with the
  852. // intersection information
  853. Vector3 ipoint =
  854. new Vector3(iray.Origin.x + (iray.Direction.x*root), iray.Origin.y + (iray.Direction.y*root),
  855. iray.Origin.z + (iray.Direction.z*root));
  856. returnresult.HitTF = true;
  857. returnresult.ipoint = ipoint;
  858. // Normal is calculated by the difference and then normalizing the result
  859. Vector3 normalpart = ipoint - vAbsolutePosition;
  860. returnresult.normal = normalpart / normalpart.Length;
  861. // It's funny how the LLVector3 object has a Distance function, but the Axiom.Math object doesnt.
  862. // I can write a function to do it.. but I like the fact that this one is Static.
  863. LLVector3 distanceConvert1 = new LLVector3(iray.Origin.x, iray.Origin.y, iray.Origin.z);
  864. LLVector3 distanceConvert2 = new LLVector3(ipoint.x, ipoint.y, ipoint.z);
  865. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  866. returnresult.distance = distance;
  867. return returnresult;
  868. }
  869. public double GetDistanceTo(Vector3 a, Vector3 b)
  870. {
  871. float dx = a.x - b.x;
  872. float dy = a.y - b.y;
  873. float dz = a.z - b.z;
  874. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  875. }
  876. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  877. {
  878. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  879. // This breaks down into the ray---> plane equation.
  880. // TODO: Change to take shape into account
  881. Vector3[] vertexes = new Vector3[8];
  882. float[] distance = new float[6];
  883. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  884. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  885. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  886. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  887. Vector3[] normals = new Vector3[6]; // Normal for Facei
  888. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  889. AAfacenormals[0] = new Vector3(1, 0, 0);
  890. AAfacenormals[1] = new Vector3(0, 1, 0);
  891. AAfacenormals[2] = new Vector3(-1, 0, 0);
  892. AAfacenormals[3] = new Vector3(0, -1, 0);
  893. AAfacenormals[4] = new Vector3(0, 0, 1);
  894. AAfacenormals[5] = new Vector3(0, 0, -1);
  895. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  896. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  897. Vector3 cross = new Vector3();
  898. LLVector3 pos = GetWorldPosition();
  899. LLQuaternion rot = GetWorldRotation();
  900. // Variables prefixed with AX are Axiom.Math copies of the LL variety.
  901. Quaternion AXrot = new Quaternion(rot.W,rot.X,rot.Y,rot.Z);
  902. AXrot.Normalize();
  903. Vector3 AXpos = new Vector3(pos.X, pos.Y, pos.Z);
  904. // tScale is the offset to derive the vertex based on the scale.
  905. // it's different for each vertex because we've got to rotate it
  906. // to get the world position of the vertex to produce the Oriented Bounding Box
  907. Vector3 tScale = new Vector3();
  908. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  909. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  910. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  911. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  912. Vector3 rScale = new Vector3();
  913. // Get Vertexes for Faces Stick them into ABCD for each Face
  914. // Form: Face<vertex>[face] that corresponds to the below diagram
  915. #region ABCD Face Vertex Map Comment Diagram
  916. // A _________ B
  917. // | |
  918. // | 4 top |
  919. // |_________|
  920. // C D
  921. // A _________ B
  922. // | Back |
  923. // | 3 |
  924. // |_________|
  925. // C D
  926. // A _________ B B _________ A
  927. // | Left | | Right |
  928. // | 0 | | 2 |
  929. // |_________| |_________|
  930. // C D D C
  931. // A _________ B
  932. // | Front |
  933. // | 1 |
  934. // |_________|
  935. // C D
  936. // C _________ D
  937. // | |
  938. // | 5 bot |
  939. // |_________|
  940. // A B
  941. #endregion
  942. #region Plane Decomposition of Oriented Bounding Box
  943. tScale = new Vector3(AXscale.x, -AXscale.y, AXscale.z);
  944. rScale = ((AXrot * tScale));
  945. vertexes[0] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  946. // vertexes[0].x = pos.X + vertexes[0].x;
  947. //vertexes[0].y = pos.Y + vertexes[0].y;
  948. //vertexes[0].z = pos.Z + vertexes[0].z;
  949. FaceA[0] = vertexes[0];
  950. FaceB[3] = vertexes[0];
  951. FaceA[4] = vertexes[0];
  952. tScale = AXscale;
  953. rScale = ((AXrot * tScale));
  954. vertexes[1] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  955. // vertexes[1].x = pos.X + vertexes[1].x;
  956. // vertexes[1].y = pos.Y + vertexes[1].y;
  957. //vertexes[1].z = pos.Z + vertexes[1].z;
  958. FaceB[0] = vertexes[1];
  959. FaceA[1] = vertexes[1];
  960. FaceC[4] = vertexes[1];
  961. tScale = new Vector3(AXscale.x, -AXscale.y, -AXscale.z);
  962. rScale = ((AXrot * tScale));
  963. vertexes[2] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  964. //vertexes[2].x = pos.X + vertexes[2].x;
  965. //vertexes[2].y = pos.Y + vertexes[2].y;
  966. //vertexes[2].z = pos.Z + vertexes[2].z;
  967. FaceC[0] = vertexes[2];
  968. FaceD[3] = vertexes[2];
  969. FaceC[5] = vertexes[2];
  970. tScale = new Vector3(AXscale.x, AXscale.y, -AXscale.z);
  971. rScale = ((AXrot * tScale));
  972. vertexes[3] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  973. //vertexes[3].x = pos.X + vertexes[3].x;
  974. // vertexes[3].y = pos.Y + vertexes[3].y;
  975. // vertexes[3].z = pos.Z + vertexes[3].z;
  976. FaceD[0] = vertexes[3];
  977. FaceC[1] = vertexes[3];
  978. FaceA[5] = vertexes[3];
  979. tScale = new Vector3(-AXscale.x, AXscale.y, AXscale.z);
  980. rScale = ((AXrot * tScale));
  981. vertexes[4] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  982. // vertexes[4].x = pos.X + vertexes[4].x;
  983. // vertexes[4].y = pos.Y + vertexes[4].y;
  984. // vertexes[4].z = pos.Z + vertexes[4].z;
  985. FaceB[1] = vertexes[4];
  986. FaceA[2] = vertexes[4];
  987. FaceD[4] = vertexes[4];
  988. tScale = new Vector3(-AXscale.x, AXscale.y, -AXscale.z);
  989. rScale = ((AXrot * tScale));
  990. vertexes[5] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  991. // vertexes[5].x = pos.X + vertexes[5].x;
  992. // vertexes[5].y = pos.Y + vertexes[5].y;
  993. // vertexes[5].z = pos.Z + vertexes[5].z;
  994. FaceD[1] = vertexes[5];
  995. FaceC[2] = vertexes[5];
  996. FaceB[5] = vertexes[5];
  997. tScale = new Vector3(-AXscale.x, -AXscale.y, AXscale.z);
  998. rScale = ((AXrot * tScale));
  999. vertexes[6] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  1000. // vertexes[6].x = pos.X + vertexes[6].x;
  1001. // vertexes[6].y = pos.Y + vertexes[6].y;
  1002. // vertexes[6].z = pos.Z + vertexes[6].z;
  1003. FaceB[2] = vertexes[6];
  1004. FaceA[3] = vertexes[6];
  1005. FaceB[4] = vertexes[6];
  1006. tScale = new Vector3(-AXscale.x, -AXscale.y, -AXscale.z);
  1007. rScale = ((AXrot * tScale));
  1008. vertexes[7] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  1009. // vertexes[7].x = pos.X + vertexes[7].x;
  1010. // vertexes[7].y = pos.Y + vertexes[7].y;
  1011. // vertexes[7].z = pos.Z + vertexes[7].z;
  1012. FaceD[2] = vertexes[7];
  1013. FaceC[3] = vertexes[7];
  1014. FaceD[5] = vertexes[7];
  1015. #endregion
  1016. // Get our plane normals
  1017. for (int i = 0; i < 6; i++)
  1018. {
  1019. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  1020. // Our Plane direction
  1021. AmBa = FaceA[i] - FaceB[i];
  1022. AmBb = FaceB[i] - FaceC[i];
  1023. cross = AmBb.Cross(AmBa);
  1024. // normalize the cross product to get the normal.
  1025. normals[i] = cross / cross.Length;
  1026. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  1027. //distance[i] = (normals[i].x * AmBa.x + normals[i].y * AmBa.y + normals[i].z * AmBa.z) * -1;
  1028. }
  1029. EntityIntersection returnresult = new EntityIntersection();
  1030. returnresult.distance = 1024;
  1031. float c = 0;
  1032. float a = 0;
  1033. float d = 0;
  1034. Vector3 q = new Vector3();
  1035. #region OBB Version 2 Experiment
  1036. //float fmin = 999999;
  1037. //float fmax = -999999;
  1038. //float s = 0;
  1039. //for (int i=0;i<6;i++)
  1040. //{
  1041. //s = iray.Direction.Dot(normals[i]);
  1042. //d = normals[i].Dot(FaceB[i]);
  1043. //if (s == 0)
  1044. //{
  1045. //if (iray.Origin.Dot(normals[i]) > d)
  1046. //{
  1047. //return returnresult;
  1048. //}
  1049. // else
  1050. //{
  1051. //continue;
  1052. //}
  1053. //}
  1054. //a = (d - iray.Origin.Dot(normals[i])) / s;
  1055. //if ( iray.Direction.Dot(normals[i]) < 0)
  1056. //{
  1057. //if (a > fmax)
  1058. //{
  1059. //if (a > fmin)
  1060. //{
  1061. //return returnresult;
  1062. //}
  1063. //fmax = a;
  1064. //}
  1065. //}
  1066. //else
  1067. //{
  1068. //if (a < fmin)
  1069. //{
  1070. //if (a < 0 || a < fmax)
  1071. //{
  1072. //return returnresult;
  1073. //}
  1074. //fmin = a;
  1075. //}
  1076. //}
  1077. //}
  1078. //if (fmax > 0)
  1079. // a= fmax;
  1080. //else
  1081. // a=fmin;
  1082. //q = iray.Origin + a * iray.Direction;
  1083. #endregion
  1084. // Loop over faces (6 of them)
  1085. for (int i = 0; i < 6; i++)
  1086. {
  1087. AmBa = FaceA[i] - FaceB[i];
  1088. AmBb = FaceB[i] - FaceC[i];
  1089. d = normals[i].Dot(FaceB[i]);
  1090. c = iray.Direction.Dot(normals[i]);
  1091. if (c == 0)
  1092. continue;
  1093. a = (d - iray.Origin.Dot(normals[i])) / c;
  1094. if (a < 0)
  1095. continue;
  1096. // If the normal is pointing outside the object
  1097. if (iray.Direction.Dot(normals[i]) < 0 || !frontFacesOnly)
  1098. {
  1099. if (faceCenters)
  1100. {
  1101. q = AXpos + a * AAfacenormals[i]; //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  1102. }
  1103. else
  1104. {
  1105. q = iray.Origin + a * iray.Direction;
  1106. }
  1107. float distance2 = (float)GetDistanceTo(q, AXpos);
  1108. // Is this the closest hit to the object's origin?
  1109. if (faceCenters)
  1110. {
  1111. distance2 = (float)GetDistanceTo(q, iray.Origin);
  1112. }
  1113. if (distance2 < returnresult.distance)
  1114. {
  1115. returnresult.distance = distance2;
  1116. returnresult.HitTF = true;
  1117. returnresult.ipoint = q;
  1118. //m_log.Info("[FACE]:" + i.ToString());
  1119. //m_log.Info("[POINT]: " + q.ToString());
  1120. returnresult.normal = normals[i];
  1121. returnresult.AAfaceNormal = AAfacenormals[i];
  1122. }
  1123. }
  1124. }
  1125. return returnresult;
  1126. }
  1127. // Use this for attachments! LocalID should be avatar's localid
  1128. public void SetParentLocalId(uint localID)
  1129. {
  1130. ParentID = localID;
  1131. }
  1132. public void SetAttachmentPoint(uint AttachmentPoint)
  1133. {
  1134. m_attachmentPoint = AttachmentPoint;
  1135. // save the attachment point.
  1136. //if (AttachmentPoint != 0)
  1137. //{
  1138. m_shape.State = (byte)AttachmentPoint;
  1139. //}
  1140. }
  1141. /// <summary>
  1142. ///
  1143. /// </summary>
  1144. public void SetParent(SceneObjectGroup parent)
  1145. {
  1146. m_parentGroup = parent;
  1147. }
  1148. public void SetSitTarget(Vector3 offset, Quaternion orientation)
  1149. {
  1150. m_sitTargetPosition = offset;
  1151. m_sitTargetOrientation = orientation;
  1152. }
  1153. public void SetBuoyancy(float fvalue)
  1154. {
  1155. if (PhysActor != null)
  1156. {
  1157. PhysActor.Buoyancy = fvalue;
  1158. }
  1159. }
  1160. public void SetAxisRotation(int axis, int rotate)
  1161. {
  1162. if (m_parentGroup != null)
  1163. {
  1164. m_parentGroup.SetAxisRotation(axis, rotate);
  1165. }
  1166. }
  1167. public void SetPhysicsAxisRotation()
  1168. {
  1169. PhysActor.LockAngularMotion(m_rotationAxis);
  1170. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1171. }
  1172. public void SetFloatOnWater(int floatYN)
  1173. {
  1174. if (PhysActor != null)
  1175. {
  1176. if (floatYN == 1)
  1177. {
  1178. PhysActor.FloatOnWater = true;
  1179. }
  1180. else
  1181. {
  1182. PhysActor.FloatOnWater = false;
  1183. }
  1184. }
  1185. }
  1186. public LLVector3 GetSitTargetPositionLL()
  1187. {
  1188. return new LLVector3(m_sitTargetPosition.x, m_sitTargetPosition.y, m_sitTargetPosition.z);
  1189. }
  1190. public LLQuaternion GetSitTargetOrientationLL()
  1191. {
  1192. return
  1193. new LLQuaternion(m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z,
  1194. m_sitTargetOrientation.w);
  1195. }
  1196. // Utility function so the databases don't have to reference axiom.math
  1197. public void SetSitTargetLL(LLVector3 offset, LLQuaternion orientation)
  1198. {
  1199. if (
  1200. !(offset.X == 0 && offset.Y == 0 && offset.Z == 0 && (orientation.W == 0 || orientation.W == 1) &&
  1201. orientation.X == 0 && orientation.Y == 0 && orientation.Z == 0))
  1202. {
  1203. m_sitTargetPosition = new Vector3(offset.X, offset.Y, offset.Z);
  1204. m_sitTargetOrientation = new Quaternion(orientation.W, orientation.X, orientation.Y, orientation.Z);
  1205. }
  1206. }
  1207. public Vector3 GetSitTargetPosition()
  1208. {
  1209. return m_sitTargetPosition;
  1210. }
  1211. public Quaternion GetSitTargetOrientation()
  1212. {
  1213. return m_sitTargetOrientation;
  1214. }
  1215. public void SetAvatarOnSitTarget(LLUUID avatarID)
  1216. {
  1217. m_sitTargetAvatar = avatarID;
  1218. TriggerScriptChangedEvent(Changed.LINK);
  1219. }
  1220. public LLUUID GetAvatarOnSitTarget()
  1221. {
  1222. return m_sitTargetAvatar;
  1223. }
  1224. public LLUUID GetRootPartUUID()
  1225. {
  1226. if (m_parentGroup != null)
  1227. {
  1228. return m_parentGroup.UUID;
  1229. }
  1230. return LLUUID.Zero;
  1231. }
  1232. public static SceneObjectPart Create()
  1233. {
  1234. SceneObjectPart part = new SceneObjectPart();
  1235. part.UUID = LLUUID.Random();
  1236. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  1237. part.Shape = shape;
  1238. part.Name = "Primitive";
  1239. part.OwnerID = LLUUID.Random();
  1240. return part;
  1241. }
  1242. #region Copying
  1243. /// <summary>
  1244. /// Duplicates this part.
  1245. /// </summary>
  1246. /// <returns></returns>
  1247. public SceneObjectPart Copy(uint localID, LLUUID AgentID, LLUUID GroupID, int linkNum)
  1248. {
  1249. SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone();
  1250. dupe.m_shape = m_shape.Copy();
  1251. dupe.m_regionHandle = m_regionHandle;
  1252. dupe.UUID = LLUUID.Random();
  1253. dupe.LocalId = localID;
  1254. dupe.OwnerID = AgentID;
  1255. dupe.GroupID = GroupID;
  1256. dupe.GroupPosition = new LLVector3(GroupPosition.X, GroupPosition.Y, GroupPosition.Z);
  1257. dupe.OffsetPosition = new LLVector3(OffsetPosition.X, OffsetPosition.Y, OffsetPosition.Z);
  1258. dupe.RotationOffset =
  1259. new LLQuaternion(RotationOffset.X, RotationOffset.Y, RotationOffset.Z, RotationOffset.W);
  1260. dupe.Velocity = new LLVector3(0, 0, 0);
  1261. dupe.Acceleration = new LLVector3(0, 0, 0);
  1262. dupe.AngularVelocity = new LLVector3(0, 0, 0);
  1263. dupe.ObjectFlags = ObjectFlags;
  1264. dupe.OwnershipCost = OwnershipCost;
  1265. dupe.ObjectSaleType = ObjectSaleType;
  1266. dupe.SalePrice = SalePrice;
  1267. dupe.Category = Category;
  1268. dupe.TaskInventory = (TaskInventoryDictionary)dupe.TaskInventory.Clone();
  1269. dupe.ResetIDs(linkNum);
  1270. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1271. dupe.LastOwnerID = ObjectOwner;
  1272. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1273. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1274. dupe.Shape.ExtraParams = extraP;
  1275. bool UsePhysics = ((dupe.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
  1276. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1277. return dupe;
  1278. }
  1279. #endregion
  1280. /// <summary>
  1281. /// Reset LLUUIDs for this part. This involves generate this part's own LLUUID and
  1282. /// generating new LLUUIDs for all the items in the inventory.
  1283. /// </summary>
  1284. /// <param name="linkNum">Link number for the part</param>
  1285. public void ResetIDs(int linkNum)
  1286. {
  1287. UUID = LLUUID.Random();
  1288. LinkNum = linkNum;
  1289. ResetInventoryIDs();
  1290. }
  1291. #region Update Scheduling
  1292. /// <summary>
  1293. /// Clear all pending updates
  1294. /// </summary>
  1295. private void ClearUpdateSchedule()
  1296. {
  1297. m_updateFlag = 0;
  1298. }
  1299. /// <summary>
  1300. /// Schedules this prim for a full update
  1301. /// </summary>
  1302. public void ScheduleFullUpdate()
  1303. {
  1304. if (m_parentGroup != null)
  1305. {
  1306. m_parentGroup.HasGroupChanged = true;
  1307. m_parentGroup.QueueForUpdateCheck();
  1308. }
  1309. int timeNow = Util.UnixTimeSinceEpoch();
  1310. // If multiple updates are scheduled on the same second, we still need to perform all of them
  1311. // So we'll force the issue by bumping up the timestamp so that later processing sees these need
  1312. // to be performed.
  1313. if (timeNow <= TimeStampFull)
  1314. {
  1315. TimeStampFull += 1;
  1316. }
  1317. else
  1318. {
  1319. TimeStampFull = (uint)timeNow;
  1320. }
  1321. m_updateFlag = 2;
  1322. // m_log.DebugFormat(
  1323. // "[SCENE OBJECT PART]: Scheduling full update for {0}, {1} at {2}",
  1324. // UUID, Name, TimeStampFull);
  1325. }
  1326. public void AddFlag(LLObject.ObjectFlags flag)
  1327. {
  1328. LLObject.ObjectFlags prevflag = Flags;
  1329. //uint objflags = Flags;
  1330. if ((ObjectFlags & (uint) flag) == 0)
  1331. {
  1332. //Console.WriteLine("Adding flag: " + ((LLObject.ObjectFlags) flag).ToString());
  1333. Flags |= flag;
  1334. }
  1335. //uint currflag = (uint)Flags;
  1336. //System.Console.WriteLine("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1337. //ScheduleFullUpdate();
  1338. }
  1339. public void RemFlag(LLObject.ObjectFlags flag)
  1340. {
  1341. LLObject.ObjectFlags prevflag = Flags;
  1342. if ((ObjectFlags & (uint) flag) != 0)
  1343. {
  1344. //Console.WriteLine("Removing flag: " + ((LLObject.ObjectFlags)flag).ToString());
  1345. Flags &= ~flag;
  1346. }
  1347. //System.Console.WriteLine("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1348. //ScheduleFullUpdate();
  1349. }
  1350. /// <summary>
  1351. /// Schedule a terse update for this prim. Terse updates only send position,
  1352. /// rotation, velocity, rotational velocity and shape information.
  1353. /// </summary>
  1354. public void ScheduleTerseUpdate()
  1355. {
  1356. if (m_updateFlag < 1)
  1357. {
  1358. if (m_parentGroup != null)
  1359. {
  1360. m_parentGroup.HasGroupChanged = true;
  1361. m_parentGroup.QueueForUpdateCheck();
  1362. }
  1363. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  1364. m_updateFlag = 1;
  1365. // m_log.DebugFormat(
  1366. // "[SCENE OBJECT PART]: Scheduling terse update for {0}, {1} at {2}",
  1367. // UUID, Name, TimeStampTerse);
  1368. }
  1369. }
  1370. /// <summary>
  1371. /// Tell all the prims which have had updates scheduled
  1372. /// </summary>
  1373. public void SendScheduledUpdates()
  1374. {
  1375. if (m_updateFlag == 1) //some change has been made so update the clients
  1376. {
  1377. AddTerseUpdateToAllAvatars();
  1378. ClearUpdateSchedule();
  1379. // This causes the Scene to 'poll' physical objects every couple of frames
  1380. // bad, so it's been replaced by an event driven method.
  1381. //if ((ObjectFlags & (uint)LLObject.ObjectFlags.Physics) != 0)
  1382. //{
  1383. // Only send the constant terse updates on physical objects!
  1384. //ScheduleTerseUpdate();
  1385. //}
  1386. }
  1387. else
  1388. {
  1389. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  1390. {
  1391. AddFullUpdateToAllAvatars();
  1392. ClearUpdateSchedule();
  1393. }
  1394. }
  1395. }
  1396. #endregion
  1397. #region Shape
  1398. /// <summary>
  1399. ///
  1400. /// </summary>
  1401. /// <param name="shapeBlock"></param>
  1402. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  1403. {
  1404. m_shape.PathBegin = shapeBlock.PathBegin;
  1405. m_shape.PathEnd = shapeBlock.PathEnd;
  1406. m_shape.PathScaleX = shapeBlock.PathScaleX;
  1407. m_shape.PathScaleY = shapeBlock.PathScaleY;
  1408. m_shape.PathShearX = shapeBlock.PathShearX;
  1409. m_shape.PathShearY = shapeBlock.PathShearY;
  1410. m_shape.PathSkew = shapeBlock.PathSkew;
  1411. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  1412. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  1413. m_shape.PathCurve = shapeBlock.PathCurve;
  1414. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  1415. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  1416. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  1417. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  1418. m_shape.PathTaperX = shapeBlock.PathTaperX;
  1419. m_shape.PathTaperY = shapeBlock.PathTaperY;
  1420. m_shape.PathTwist = shapeBlock.PathTwist;
  1421. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  1422. if (PhysActor != null)
  1423. {
  1424. PhysActor.Shape = m_shape;
  1425. }
  1426. ScheduleFullUpdate();
  1427. }
  1428. #endregion
  1429. #region ExtraParams
  1430. public void UpdatePrimFlags(ushort type, bool inUse, byte[] data)
  1431. {
  1432. //m_log.Info("TSomething1:" + ((type & (ushort)ExtraParamType.Something1) == (ushort)ExtraParamType.Something1));
  1433. //m_log.Info("TSomething2:" + ((type & (ushort)ExtraParamType.Something2) == (ushort)ExtraParamType.Something2));
  1434. //m_log.Info("TSomething3:" + ((type & (ushort)ExtraParamType.Something3) == (ushort)ExtraParamType.Something3));
  1435. //m_log.Info("TSomething4:" + ((type & (ushort)ExtraParamType.Something4) == (ushort)ExtraParamType.Something4));
  1436. //m_log.Info("TSomething5:" + ((type & (ushort)ExtraParamType.Something5) == (ushort)ExtraParamType.Something5));
  1437. //m_log.Info("TSomething6:" + ((type & (ushort)ExtraParamType.Something6) == (ushort)ExtraParamType.Something6));
  1438. bool usePhysics = false;
  1439. bool IsTemporary = false;
  1440. bool IsPhantom = false;
  1441. bool castsShadows = false;
  1442. bool wasUsingPhysics = ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
  1443. //bool IsLocked = false;
  1444. int i = 0;
  1445. try
  1446. {
  1447. i += 46;
  1448. //IsLocked = (data[i++] != 0) ? true : false;
  1449. usePhysics = ((data[i++] != 0) && m_parentGroup.Scene.m_physicalPrim) ? true : false;
  1450. //System.Console.WriteLine("U" + packet.ToBytes().Length.ToString());
  1451. IsTemporary = (data[i++] != 0) ? true : false;
  1452. IsPhantom = (data[i++] != 0) ? true : false;
  1453. castsShadows = (data[i++] != 0) ? true : false;
  1454. }
  1455. catch (Exception)
  1456. {
  1457. Console.WriteLine("Ignoring invalid Packet:");
  1458. //Silently ignore it - TODO: FIXME Quick
  1459. }
  1460. if (usePhysics)
  1461. {
  1462. AddFlag(LLObject.ObjectFlags.Physics);
  1463. if (!wasUsingPhysics)
  1464. {
  1465. DoPhysicsPropertyUpdate(usePhysics, false);
  1466. }
  1467. }
  1468. else
  1469. {
  1470. RemFlag(LLObject.ObjectFlags.Physics);
  1471. if (wasUsingPhysics)
  1472. {
  1473. DoPhysicsPropertyUpdate(usePhysics, false);
  1474. }
  1475. }
  1476. if (IsPhantom)
  1477. {
  1478. AddFlag(LLObject.ObjectFlags.Phantom);
  1479. if (PhysActor != null)
  1480. {
  1481. m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1482. /// that's not wholesome. Had to make Scene public
  1483. PhysActor = null;
  1484. }
  1485. }
  1486. else
  1487. {
  1488. RemFlag(LLObject.ObjectFlags.Phantom);
  1489. if (PhysActor == null)
  1490. {
  1491. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1492. Name,
  1493. Shape,
  1494. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1495. AbsolutePosition.Z),
  1496. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1497. new Quaternion(RotationOffset.W, RotationOffset.X,
  1498. RotationOffset.Y, RotationOffset.Z), usePhysics);
  1499. if (PhysActor != null)
  1500. {
  1501. PhysActor.LocalID = LocalId;
  1502. DoPhysicsPropertyUpdate(usePhysics, true);
  1503. }
  1504. }
  1505. else
  1506. {
  1507. PhysActor.IsPhysical = usePhysics;
  1508. DoPhysicsPropertyUpdate(usePhysics, false);
  1509. }
  1510. }
  1511. if (IsTemporary)
  1512. {
  1513. AddFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1514. }
  1515. else
  1516. {
  1517. RemFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1518. }
  1519. // System.Console.WriteLine("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  1520. ScheduleFullUpdate();
  1521. }
  1522. public void ScriptSetPhysicsStatus(bool UsePhysics)
  1523. {
  1524. if (m_parentGroup != null)
  1525. {
  1526. m_parentGroup.ScriptSetPhysicsStatus(UsePhysics);
  1527. }
  1528. }
  1529. public void ScriptSetPhantomStatus(bool Phantom)
  1530. {
  1531. if (m_parentGroup != null)
  1532. {
  1533. m_parentGroup.ScriptSetPhantomStatus(Phantom);
  1534. }
  1535. }
  1536. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1537. {
  1538. if (PhysActor != null)
  1539. {
  1540. if (UsePhysics != PhysActor.IsPhysical || isNew)
  1541. {
  1542. if (PhysActor.IsPhysical)
  1543. {
  1544. if (!isNew)
  1545. ParentGroup.Scene.RemovePhysicalPrim(1);
  1546. PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1547. PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
  1548. PhysActor.delink();
  1549. }
  1550. PhysActor.IsPhysical = UsePhysics;
  1551. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1552. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1553. /// that's not wholesome. Had to make Scene public
  1554. //PhysActor = null;
  1555. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
  1556. {
  1557. //PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1558. //Name,
  1559. //Shape,
  1560. //new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1561. //AbsolutePosition.Z),
  1562. //new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1563. //new Quaternion(RotationOffset.W, RotationOffset.X,
  1564. //RotationOffset.Y, RotationOffset.Z), UsePhysics);
  1565. if (UsePhysics)
  1566. {
  1567. ParentGroup.Scene.AddPhysicalPrim(1);
  1568. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1569. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  1570. if (ParentID != 0 && ParentID != LocalId)
  1571. {
  1572. if (ParentGroup.RootPart.PhysActor != null)
  1573. {
  1574. PhysActor.link(ParentGroup.RootPart.PhysActor);
  1575. }
  1576. }
  1577. }
  1578. }
  1579. }
  1580. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1581. }
  1582. }
  1583. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  1584. {
  1585. m_shape.ExtraParams = new byte[data.Length + 7];
  1586. int i = 0;
  1587. uint length = (uint) data.Length;
  1588. m_shape.ExtraParams[i++] = 1;
  1589. m_shape.ExtraParams[i++] = (byte) (type%256);
  1590. m_shape.ExtraParams[i++] = (byte) ((type >> 8)%256);
  1591. m_shape.ExtraParams[i++] = (byte) (length%256);
  1592. m_shape.ExtraParams[i++] = (byte) ((length >> 8)%256);
  1593. m_shape.ExtraParams[i++] = (byte) ((length >> 16)%256);
  1594. m_shape.ExtraParams[i++] = (byte) ((length >> 24)%256);
  1595. Array.Copy(data, 0, m_shape.ExtraParams, i, data.Length);
  1596. ScheduleFullUpdate();
  1597. }
  1598. #endregion
  1599. #region Physics
  1600. public float GetMass()
  1601. {
  1602. if (PhysActor != null)
  1603. {
  1604. return PhysActor.Mass;
  1605. }
  1606. else
  1607. {
  1608. return 0;
  1609. }
  1610. }
  1611. public LLVector3 GetGeometricCenter()
  1612. {
  1613. if (PhysActor != null)
  1614. {
  1615. return new LLVector3(PhysActor.CenterOfMass.X, PhysActor.CenterOfMass.Y, PhysActor.CenterOfMass.Z);
  1616. }
  1617. else
  1618. {
  1619. return new LLVector3(0, 0, 0);
  1620. }
  1621. }
  1622. #endregion
  1623. #region Texture
  1624. /// <summary>
  1625. ///
  1626. /// </summary>
  1627. /// <param name="textureEntry"></param>
  1628. public void UpdateTextureEntry(byte[] textureEntry)
  1629. {
  1630. m_shape.TextureEntry = textureEntry;
  1631. TriggerScriptChangedEvent(Changed.TEXTURE);
  1632. ScheduleFullUpdate();
  1633. }
  1634. // Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  1635. // not handling RGBA properly. Cycles through, and "fixes" the color
  1636. // info
  1637. public void UpdateTexture(LLObject.TextureEntry tex)
  1638. {
  1639. //LLColor tmpcolor;
  1640. //for (uint i = 0; i < 32; i++)
  1641. //{
  1642. // if (tex.FaceTextures[i] != null)
  1643. // {
  1644. // tmpcolor = tex.GetFace((uint) i).RGBA;
  1645. // tmpcolor.A = tmpcolor.A*255;
  1646. // tmpcolor.R = tmpcolor.R*255;
  1647. // tmpcolor.G = tmpcolor.G*255;
  1648. // tmpcolor.B = tmpcolor.B*255;
  1649. // tex.FaceTextures[i].RGBA = tmpcolor;
  1650. // }
  1651. //}
  1652. //tmpcolor = tex.DefaultTexture.RGBA;
  1653. //tmpcolor.A = tmpcolor.A*255;
  1654. //tmpcolor.R = tmpcolor.R*255;
  1655. //tmpcolor.G = tmpcolor.G*255;
  1656. //tmpcolor.B = tmpcolor.B*255;
  1657. //tex.DefaultTexture.RGBA = tmpcolor;
  1658. UpdateTextureEntry(tex.ToBytes());
  1659. }
  1660. public byte ConvertScriptUintToByte(uint indata)
  1661. {
  1662. byte outdata = (byte)TextureAnimFlags.NONE;
  1663. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1664. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1665. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1666. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1667. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1668. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1669. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1670. return outdata;
  1671. }
  1672. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1673. {
  1674. byte[] data = new byte[16];
  1675. int pos = 0;
  1676. // The flags don't like conversion from uint to byte, so we have to do
  1677. // it the crappy way. See the above function :(
  1678. data[pos] = ConvertScriptUintToByte(pTexAnim.Flags); pos++;
  1679. data[pos] = (byte)pTexAnim.Face; pos++;
  1680. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1681. data[pos] = (byte)pTexAnim.SizeY; pos++;
  1682. Helpers.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1683. Helpers.FloatToBytes(pTexAnim.Length ).CopyTo(data, pos + 4);
  1684. Helpers.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1685. m_TextureAnimation = data;
  1686. }
  1687. #endregion
  1688. #region ParticleSystem
  1689. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1690. {
  1691. m_particleSystem = pSystem.GetBytes();
  1692. }
  1693. #endregion
  1694. #region Position
  1695. /// <summary>
  1696. ///
  1697. /// </summary>
  1698. /// <param name="pos"></param>
  1699. public void UpdateOffSet(LLVector3 pos)
  1700. {
  1701. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1702. OffsetPosition = newPos;
  1703. ScheduleTerseUpdate();
  1704. }
  1705. public void UpdateGroupPosition(LLVector3 pos)
  1706. {
  1707. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1708. GroupPosition = newPos;
  1709. ScheduleTerseUpdate();
  1710. }
  1711. #endregion
  1712. #region rotation
  1713. public void UpdateRotation(LLQuaternion rot)
  1714. {
  1715. //StoreUndoState();
  1716. RotationOffset = new LLQuaternion(rot.X, rot.Y, rot.Z, rot.W);
  1717. ScheduleTerseUpdate();
  1718. }
  1719. #endregion
  1720. #region Sound
  1721. public void PreloadSound(string sound)
  1722. {
  1723. LLUUID ownerID = OwnerID;
  1724. LLUUID objectID = UUID;
  1725. LLUUID soundID = LLUUID.Zero;
  1726. if (!LLUUID.TryParse(sound, out soundID))
  1727. {
  1728. //Trys to fetch sound id from prim's inventory.
  1729. //Prim's inventory doesn't support non script items yet
  1730. SceneObjectPart op = this;
  1731. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1732. {
  1733. if (item.Value.Name == sound)
  1734. {
  1735. soundID = item.Value.ItemID;
  1736. break;
  1737. }
  1738. }
  1739. }
  1740. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1741. foreach (ScenePresence p in avatarts)
  1742. {
  1743. // TODO: some filtering by distance of avatar
  1744. p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  1745. }
  1746. }
  1747. public void AdjustSoundGain(double volume)
  1748. {
  1749. if (volume > 1)
  1750. volume = 1;
  1751. if (volume < 0)
  1752. volume = 0;
  1753. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1754. foreach (ScenePresence p in avatarts)
  1755. {
  1756. p.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
  1757. }
  1758. }
  1759. public void SendSound(string sound, double volume, bool triggered, byte flags)
  1760. {
  1761. if (volume > 1)
  1762. volume = 1;
  1763. if (volume < 0)
  1764. volume = 0;
  1765. LLUUID ownerID = OwnerID;
  1766. LLUUID objectID = UUID;
  1767. LLUUID parentID = GetRootPartUUID();
  1768. LLUUID soundID = LLUUID.Zero;
  1769. LLVector3 position = AbsolutePosition; // region local
  1770. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  1771. //byte flags = 0;
  1772. if (!LLUUID.TryParse(sound, out soundID))
  1773. {
  1774. // search sound file from inventory
  1775. SceneObjectPart op = this;
  1776. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1777. {
  1778. if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
  1779. {
  1780. soundID = item.Value.ItemID;
  1781. break;
  1782. }
  1783. }
  1784. }
  1785. if(soundID == LLUUID.Zero)
  1786. return;
  1787. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1788. foreach (ScenePresence p in avatarts)
  1789. {
  1790. double dis=Util.GetDistanceTo(p.AbsolutePosition, position);
  1791. if(dis > 100.0) // Max audio distance
  1792. continue;
  1793. // Scale by distance
  1794. volume*=((100.0-dis)/100.0);
  1795. if (triggered)
  1796. {
  1797. p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume);
  1798. }
  1799. else
  1800. {
  1801. p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags);
  1802. }
  1803. }
  1804. }
  1805. #endregion
  1806. #region Resizing/Scale
  1807. /// <summary>
  1808. ///
  1809. /// </summary>
  1810. /// <param name="scale"></param>
  1811. public void Resize(LLVector3 scale)
  1812. {
  1813. StoreUndoState();
  1814. m_shape.Scale = scale;
  1815. ScheduleFullUpdate();
  1816. }
  1817. #endregion
  1818. public void UpdatePermissions(LLUUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  1819. {
  1820. bool set = addRemTF == 1;
  1821. // Are we the owner?
  1822. if (AgentID == OwnerID)
  1823. {
  1824. switch (field)
  1825. {
  1826. case 2:
  1827. OwnerMask = ApplyMask(OwnerMask, set, mask);
  1828. break;
  1829. case 4:
  1830. GroupMask = ApplyMask(GroupMask, set, mask);
  1831. break;
  1832. case 8:
  1833. EveryoneMask = ApplyMask(EveryoneMask, set, mask);
  1834. break;
  1835. case 16:
  1836. NextOwnerMask = ApplyMask(NextOwnerMask, set, mask);
  1837. break;
  1838. }
  1839. SendFullUpdateToAllClients();
  1840. SendObjectPropertiesToClient(AgentID);
  1841. }
  1842. }
  1843. private void SendObjectPropertiesToClient(LLUUID AgentID)
  1844. {
  1845. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1846. for (int i = 0; i < avatars.Count; i++)
  1847. {
  1848. // Ugly reference :(
  1849. if (avatars[i].UUID == AgentID)
  1850. {
  1851. m_parentGroup.GetProperties(avatars[i].ControllingClient);
  1852. }
  1853. }
  1854. }
  1855. private uint ApplyMask(uint val, bool set, uint mask)
  1856. {
  1857. if (set)
  1858. {
  1859. return val |= mask;
  1860. }
  1861. else
  1862. {
  1863. return val &= ~mask;
  1864. }
  1865. }
  1866. #region Client Update Methods
  1867. /// <summary>
  1868. /// Tell all scene presences that they should send updates for this part to their clients
  1869. /// </summary>
  1870. public void AddFullUpdateToAllAvatars()
  1871. {
  1872. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1873. for (int i = 0; i < avatars.Count; i++)
  1874. {
  1875. avatars[i].QueuePartForUpdate(this);
  1876. }
  1877. }
  1878. public void SendFullUpdateToAllClientsExcept(LLUUID agentID)
  1879. {
  1880. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1881. for (int i = 0; i < avatars.Count; i++)
  1882. {
  1883. // Ugly reference :(
  1884. if (avatars[i].UUID != agentID)
  1885. {
  1886. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1887. avatars[i].GenerateClientFlags(UUID));
  1888. }
  1889. }
  1890. }
  1891. public void AddFullUpdateToAvatar(ScenePresence presence)
  1892. {
  1893. presence.QueuePartForUpdate(this);
  1894. }
  1895. /// <summary>
  1896. ///
  1897. /// </summary>
  1898. public void SendFullUpdateToAllClients()
  1899. {
  1900. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1901. for (int i = 0; i < avatars.Count; i++)
  1902. {
  1903. // Ugly reference :(
  1904. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1905. avatars[i].GenerateClientFlags(UUID));
  1906. }
  1907. }
  1908. /// <summary>
  1909. ///
  1910. /// </summary>
  1911. /// <param name="remoteClient"></param>
  1912. public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  1913. {
  1914. m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
  1915. }
  1916. /// <summary>
  1917. /// Sends a full update to the client
  1918. /// </summary>
  1919. /// <param name="remoteClient"></param>
  1920. /// <param name="clientFlags"></param>
  1921. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  1922. {
  1923. LLVector3 lPos;
  1924. lPos = OffsetPosition;
  1925. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  1926. }
  1927. /// <summary>
  1928. /// Sends a full update to the client
  1929. /// </summary>
  1930. /// <param name="remoteClient"></param>
  1931. /// <param name="lPos"></param>
  1932. /// <param name="clientFlags"></param>
  1933. public void SendFullUpdateToClient(IClientAPI remoteClient, LLVector3 lPos, uint clientFlags)
  1934. {
  1935. LLQuaternion lRot;
  1936. lRot = RotationOffset;
  1937. clientFlags &= ~(uint) LLObject.ObjectFlags.CreateSelected;
  1938. if (remoteClient.AgentId == OwnerID)
  1939. {
  1940. if ((uint) (Flags & LLObject.ObjectFlags.CreateSelected) != 0)
  1941. {
  1942. clientFlags |= (uint) LLObject.ObjectFlags.CreateSelected;
  1943. Flags &= ~LLObject.ObjectFlags.CreateSelected;
  1944. }
  1945. }
  1946. byte[] color = new byte[] {m_color.R, m_color.G, m_color.B, m_color.A};
  1947. remoteClient.SendPrimitiveToClient(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, m_shape, lPos, clientFlags, m_uuid,
  1948. OwnerID,
  1949. m_text, color, ParentID, m_particleSystem, lRot, m_clickAction, m_TextureAnimation, m_IsAttachment, m_attachmentPoint,fromAssetID);
  1950. }
  1951. /// Terse updates
  1952. public void AddTerseUpdateToAllAvatars()
  1953. {
  1954. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1955. for (int i = 0; i < avatars.Count; i++)
  1956. {
  1957. avatars[i].QueuePartForUpdate(this);
  1958. }
  1959. }
  1960. public void AddTerseUpdateToAvatar(ScenePresence presence)
  1961. {
  1962. presence.QueuePartForUpdate(this);
  1963. }
  1964. /// <summary>
  1965. ///
  1966. /// </summary>
  1967. public void SendTerseUpdateToAllClients()
  1968. {
  1969. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1970. for (int i = 0; i < avatars.Count; i++)
  1971. {
  1972. m_parentGroup.SendPartTerseUpdate(avatars[i].ControllingClient, this);
  1973. }
  1974. }
  1975. /// <summary>
  1976. /// Send a terse update to the client.
  1977. /// </summary>
  1978. /// <param name="remoteClient"></param>
  1979. public void SendTerseUpdate(IClientAPI remoteClient)
  1980. {
  1981. m_parentGroup.SendPartTerseUpdate(remoteClient, this);
  1982. }
  1983. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  1984. {
  1985. LLVector3 lPos;
  1986. lPos = OffsetPosition;
  1987. LLQuaternion mRot = RotationOffset;
  1988. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) == 0)
  1989. {
  1990. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Shape.State, fromAssetID);
  1991. }
  1992. else
  1993. {
  1994. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity,
  1995. RotationalVelocity);
  1996. //System.Console.WriteLine("LID: " + LocalID + " RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  1997. }
  1998. }
  1999. public void SendTerseUpdateToClient(IClientAPI remoteClient, LLVector3 lPos)
  2000. {
  2001. LLQuaternion mRot = RotationOffset;
  2002. if (m_IsAttachment)
  2003. {
  2004. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, (byte)((m_attachmentPoint % 16) * 16 + (m_attachmentPoint / 16)),fromAssetID);
  2005. }
  2006. else
  2007. {
  2008. if ((ObjectFlags & (uint)LLObject.ObjectFlags.Physics) == 0)
  2009. {
  2010. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Shape.State, fromAssetID);
  2011. }
  2012. else
  2013. {
  2014. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity,
  2015. RotationalVelocity);
  2016. //System.Console.WriteLine("LID: " + LocalID + "RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  2017. }
  2018. }
  2019. }
  2020. #endregion
  2021. public virtual void UpdateMovement()
  2022. {
  2023. }
  2024. #region Events
  2025. public void PhysicsRequestingTerseUpdate()
  2026. {
  2027. if (PhysActor != null)
  2028. {
  2029. LLVector3 newpos = new LLVector3(PhysActor.Position.GetBytes(), 0);
  2030. if (newpos.X > 257f || newpos.X < -1f || newpos.Y > 257f || newpos.Y < -1f)
  2031. {
  2032. m_parentGroup.AbsolutePosition = newpos;
  2033. return;
  2034. }
  2035. }
  2036. ScheduleTerseUpdate();
  2037. //SendTerseUpdateToAllClients();
  2038. }
  2039. #endregion
  2040. public void PhysicsOutOfBounds(PhysicsVector pos)
  2041. {
  2042. m_log.Info("[PHYSICS]: Physical Object went out of bounds.");
  2043. RemFlag(LLObject.ObjectFlags.Physics);
  2044. DoPhysicsPropertyUpdate(false, true);
  2045. //m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2046. }
  2047. public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient)
  2048. {
  2049. }
  2050. public void SetText(string text)
  2051. {
  2052. Text = text;
  2053. ScheduleFullUpdate();
  2054. }
  2055. public void SetText(string text, Vector3 color, double alpha)
  2056. {
  2057. Color = Color.FromArgb(0xff - (int) (alpha*0xff),
  2058. (int) (color.x*0xff),
  2059. (int) (color.y*0xff),
  2060. (int) (color.z*0xff));
  2061. SetText( text );
  2062. }
  2063. public int registerTargetWaypoint(LLVector3 target, float tolerance)
  2064. {
  2065. if (m_parentGroup != null)
  2066. {
  2067. return m_parentGroup.registerTargetWaypoint(target, tolerance);
  2068. }
  2069. return 0;
  2070. }
  2071. public void unregisterTargetWaypoint(int handle)
  2072. {
  2073. if (m_parentGroup != null)
  2074. {
  2075. m_parentGroup.unregisterTargetWaypoint(handle);
  2076. }
  2077. }
  2078. protected SceneObjectPart(SerializationInfo info, StreamingContext context)
  2079. {
  2080. //System.Console.WriteLine("SceneObjectPart Deserialize BGN");
  2081. if (info == null)
  2082. {
  2083. throw new ArgumentNullException("info");
  2084. }
  2085. /*
  2086. m_queue = (Queue<SceneObjectPart>)info.GetValue("m_queue", typeof(Queue<SceneObjectPart>));
  2087. m_ids = (List<LLUUID>)info.GetValue("m_ids", typeof(List<LLUUID>));
  2088. */
  2089. //System.Console.WriteLine("SceneObjectPart Deserialize END");
  2090. }
  2091. [SecurityPermission(SecurityAction.LinkDemand,
  2092. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2093. public virtual void GetObjectData(
  2094. SerializationInfo info, StreamingContext context)
  2095. {
  2096. if (info == null)
  2097. {
  2098. throw new ArgumentNullException("info");
  2099. }
  2100. info.AddValue("m_inventoryFileName", m_inventoryFileName);
  2101. info.AddValue("m_folderID", m_folderID.UUID);
  2102. info.AddValue("PhysActor", PhysActor);
  2103. Dictionary<Guid, TaskInventoryItem> TaskInventory_work = new Dictionary<Guid, TaskInventoryItem>();
  2104. foreach (LLUUID id in TaskInventory.Keys)
  2105. {
  2106. TaskInventory_work.Add(id.UUID, TaskInventory[id]);
  2107. }
  2108. info.AddValue("TaskInventory", TaskInventory_work);
  2109. info.AddValue("LastOwnerID", LastOwnerID.UUID);
  2110. info.AddValue("OwnerID", OwnerID.UUID);
  2111. info.AddValue("GroupID", GroupID.UUID);
  2112. info.AddValue("OwnershipCost", OwnershipCost);
  2113. info.AddValue("ObjectSaleType", ObjectSaleType);
  2114. info.AddValue("SalePrice", SalePrice);
  2115. info.AddValue("Category", Category);
  2116. info.AddValue("CreationDate", CreationDate);
  2117. info.AddValue("ParentID", ParentID);
  2118. info.AddValue("OwnerMask", OwnerMask);
  2119. info.AddValue("NextOwnerMask", NextOwnerMask);
  2120. info.AddValue("GroupMask", GroupMask);
  2121. info.AddValue("EveryoneMask", EveryoneMask);
  2122. info.AddValue("BaseMask", BaseMask);
  2123. info.AddValue("m_particleSystem", m_particleSystem);
  2124. info.AddValue("TimeStampFull", TimeStampFull);
  2125. info.AddValue("TimeStampTerse", TimeStampTerse);
  2126. info.AddValue("TimeStampLastActivity", TimeStampLastActivity);
  2127. info.AddValue("m_updateFlag", m_updateFlag);
  2128. info.AddValue("CreatorID", CreatorID.UUID);
  2129. info.AddValue("m_inventorySerial", m_inventorySerial);
  2130. info.AddValue("m_uuid", m_uuid.UUID);
  2131. info.AddValue("m_localID", m_localId);
  2132. info.AddValue("m_name", m_name);
  2133. info.AddValue("m_flags", Flags);
  2134. info.AddValue("m_material", m_material);
  2135. info.AddValue("m_regionHandle", m_regionHandle);
  2136. info.AddValue("m_groupPosition.X", m_groupPosition.X);
  2137. info.AddValue("m_groupPosition.Y", m_groupPosition.Y);
  2138. info.AddValue("m_groupPosition.Z", m_groupPosition.Z);
  2139. info.AddValue("m_offsetPosition.X", m_offsetPosition.X);
  2140. info.AddValue("m_offsetPosition.Y", m_offsetPosition.Y);
  2141. info.AddValue("m_offsetPosition.Z", m_offsetPosition.Z);
  2142. info.AddValue("m_rotationOffset.W", m_rotationOffset.W);
  2143. info.AddValue("m_rotationOffset.X", m_rotationOffset.X);
  2144. info.AddValue("m_rotationOffset.Y", m_rotationOffset.Y);
  2145. info.AddValue("m_rotationOffset.Z", m_rotationOffset.Z);
  2146. info.AddValue("m_velocity.X", m_velocity.X);
  2147. info.AddValue("m_velocity.Y", m_velocity.Y);
  2148. info.AddValue("m_velocity.Z", m_velocity.Z);
  2149. info.AddValue("m_rotationalvelocity.X", m_rotationalvelocity.X);
  2150. info.AddValue("m_rotationalvelocity.Y", m_rotationalvelocity.Y);
  2151. info.AddValue("m_rotationalvelocity.Z", m_rotationalvelocity.Z);
  2152. info.AddValue("m_angularVelocity.X", m_angularVelocity.X);
  2153. info.AddValue("m_angularVelocity.Y", m_angularVelocity.Y);
  2154. info.AddValue("m_angularVelocity.Z", m_angularVelocity.Z);
  2155. info.AddValue("m_acceleration.X", m_acceleration.X);
  2156. info.AddValue("m_acceleration.Y", m_acceleration.Y);
  2157. info.AddValue("m_acceleration.Z", m_acceleration.Z);
  2158. info.AddValue("m_description", m_description);
  2159. info.AddValue("m_color", m_color);
  2160. info.AddValue("m_text", m_text);
  2161. info.AddValue("m_sitName", m_sitName);
  2162. info.AddValue("m_touchName", m_touchName);
  2163. info.AddValue("m_clickAction", m_clickAction);
  2164. info.AddValue("m_shape", m_shape);
  2165. info.AddValue("m_parentGroup", m_parentGroup);
  2166. info.AddValue("PayPrice", PayPrice);
  2167. }
  2168. public void Undo()
  2169. {
  2170. if (m_undo.Count > 0)
  2171. {
  2172. UndoState goback = m_undo.Pop();
  2173. if (goback != null)
  2174. goback.PlaybackState(this);
  2175. }
  2176. }
  2177. public void SetScriptEvents(LLUUID scriptid, int events)
  2178. {
  2179. scriptEvents oldparts;
  2180. lock (m_scriptEvents)
  2181. {
  2182. if (m_scriptEvents.ContainsKey(scriptid))
  2183. {
  2184. oldparts = m_scriptEvents[scriptid];
  2185. // remove values from aggregated script events
  2186. m_scriptEvents[scriptid] = (scriptEvents) events;
  2187. }
  2188. else
  2189. {
  2190. m_scriptEvents.Add(scriptid, (scriptEvents) events);
  2191. }
  2192. }
  2193. aggregateScriptEvents();
  2194. }
  2195. public void RemoveScriptEvents(LLUUID scriptid)
  2196. {
  2197. lock (m_scriptEvents)
  2198. {
  2199. if (m_scriptEvents.ContainsKey(scriptid))
  2200. {
  2201. scriptEvents oldparts = scriptEvents.None;
  2202. oldparts = (scriptEvents) m_scriptEvents[scriptid];
  2203. // remove values from aggregated script events
  2204. m_aggregateScriptEvents &= ~oldparts;
  2205. m_scriptEvents.Remove(scriptid);
  2206. }
  2207. }
  2208. aggregateScriptEvents();
  2209. }
  2210. public void aggregateScriptEvents()
  2211. {
  2212. // Aggregate script events
  2213. lock (m_scriptEvents)
  2214. {
  2215. foreach (scriptEvents s in m_scriptEvents.Values)
  2216. {
  2217. m_aggregateScriptEvents |= s;
  2218. }
  2219. }
  2220. uint objectflagupdate = 0;
  2221. if (
  2222. ((m_aggregateScriptEvents & scriptEvents.touch) != 0) ||
  2223. ((m_aggregateScriptEvents & scriptEvents.touch_end) != 0) ||
  2224. ((m_aggregateScriptEvents & scriptEvents.touch_start) != 0)
  2225. )
  2226. {
  2227. objectflagupdate |= (uint) LLObject.ObjectFlags.Touch;
  2228. }
  2229. if ((m_aggregateScriptEvents & scriptEvents.money) != 0)
  2230. {
  2231. objectflagupdate |= (uint) LLObject.ObjectFlags.Money;
  2232. }
  2233. if (
  2234. ((m_aggregateScriptEvents & scriptEvents.collision) != 0) ||
  2235. ((m_aggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  2236. ((m_aggregateScriptEvents & scriptEvents.collision_start) != 0)
  2237. )
  2238. {
  2239. // subscribe to physics updates.
  2240. }
  2241. LocalFlags=(LLObject.ObjectFlags)objectflagupdate;
  2242. if(m_parentGroup != null && m_parentGroup.RootPart == this)
  2243. m_parentGroup.aggregateScriptEvents();
  2244. else
  2245. ScheduleFullUpdate();
  2246. }
  2247. }
  2248. }