PrimitiveBaseShape.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  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.Drawing.Imaging;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Xml;
  34. using System.Xml.Schema;
  35. using System.Xml.Serialization;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.StructuredData;
  39. namespace OpenSim.Framework
  40. {
  41. public enum ProfileShape : byte
  42. {
  43. Circle = 0,
  44. Square = 1,
  45. IsometricTriangle = 2,
  46. EquilateralTriangle = 3,
  47. RightTriangle = 4,
  48. HalfCircle = 5
  49. }
  50. public enum HollowShape : byte
  51. {
  52. Same = 0,
  53. Circle = 16,
  54. Square = 32,
  55. Triangle = 48
  56. }
  57. public enum PCodeEnum : byte
  58. {
  59. Primitive = 9,
  60. Avatar = 47,
  61. Grass = 95,
  62. NewTree = 111,
  63. ParticleSystem = 143,
  64. Tree = 255
  65. }
  66. public enum Extrusion : byte
  67. {
  68. Straight = 16,
  69. Curve1 = 32,
  70. Curve2 = 48,
  71. Flexible = 128
  72. }
  73. [Serializable]
  74. public class PrimitiveBaseShape
  75. {
  76. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  77. private static readonly byte[] DEFAULT_TEXTURE = new Primitive.TextureEntry(new UUID("89556747-24cb-43ed-920b-47caed15465f")).GetBytes();
  78. private byte[] m_textureEntry;
  79. private ushort _pathBegin;
  80. private byte _pathCurve;
  81. private ushort _pathEnd;
  82. private sbyte _pathRadiusOffset;
  83. private byte _pathRevolutions;
  84. private byte _pathScaleX;
  85. private byte _pathScaleY;
  86. private byte _pathShearX;
  87. private byte _pathShearY;
  88. private sbyte _pathSkew;
  89. private sbyte _pathTaperX;
  90. private sbyte _pathTaperY;
  91. private sbyte _pathTwist;
  92. private sbyte _pathTwistBegin;
  93. private byte _pCode;
  94. private ushort _profileBegin;
  95. private ushort _profileEnd;
  96. private ushort _profileHollow;
  97. private Vector3 _scale;
  98. private byte _state;
  99. private byte _lastattach;
  100. private ProfileShape _profileShape;
  101. private HollowShape _hollowShape;
  102. // Sculpted
  103. [XmlIgnore] private UUID _sculptTexture;
  104. [XmlIgnore] private byte _sculptType;
  105. [XmlIgnore] private byte[] _sculptData = Utils.EmptyBytes;
  106. // Flexi
  107. [XmlIgnore] private int _flexiSoftness;
  108. [XmlIgnore] private float _flexiTension;
  109. [XmlIgnore] private float _flexiDrag;
  110. [XmlIgnore] private float _flexiGravity;
  111. [XmlIgnore] private float _flexiWind;
  112. [XmlIgnore] private float _flexiForceX;
  113. [XmlIgnore] private float _flexiForceY;
  114. [XmlIgnore] private float _flexiForceZ;
  115. //Bright n sparkly
  116. [XmlIgnore] private float _lightColorR;
  117. [XmlIgnore] private float _lightColorG;
  118. [XmlIgnore] private float _lightColorB;
  119. [XmlIgnore] private float _lightColorA = 1.0f;
  120. [XmlIgnore] private float _lightRadius;
  121. [XmlIgnore] private float _lightCutoff;
  122. [XmlIgnore] private float _lightFalloff;
  123. [XmlIgnore] private float _lightIntensity = 1.0f;
  124. // Light Projection Filter
  125. [XmlIgnore] private UUID _projectionTextureID;
  126. [XmlIgnore] private float _projectionFOV;
  127. [XmlIgnore] private float _projectionFocus;
  128. [XmlIgnore] private float _projectionAmb;
  129. [XmlIgnore] private uint _meshFlags;
  130. [XmlIgnore] private bool _flexiEntry;
  131. [XmlIgnore] private bool _lightEntry;
  132. [XmlIgnore] private bool _sculptEntry;
  133. [XmlIgnore] private bool _projectionEntry;
  134. [XmlIgnore] private bool _meshFlagsEntry;
  135. public bool MeshFlagEntry
  136. {
  137. get { return _meshFlagsEntry;}
  138. }
  139. public byte ProfileCurve
  140. {
  141. get { return (byte)((byte)HollowShape | (byte)ProfileShape); }
  142. set
  143. {
  144. // Handle hollow shape component
  145. byte hollowShapeByte = (byte)(value & 0xf0);
  146. if (!Enum.IsDefined(typeof(HollowShape), hollowShapeByte))
  147. {
  148. m_log.WarnFormat(
  149. "[SHAPE]: Attempt to set a ProfileCurve with a hollow shape value of {0}, which isn't a valid enum. Replacing with default shape.",
  150. hollowShapeByte);
  151. this._hollowShape = HollowShape.Same;
  152. }
  153. else
  154. {
  155. this._hollowShape = (HollowShape)hollowShapeByte;
  156. }
  157. // Handle profile shape component
  158. byte profileShapeByte = (byte)(value & 0xf);
  159. if (!Enum.IsDefined(typeof(ProfileShape), profileShapeByte))
  160. {
  161. m_log.WarnFormat(
  162. "[SHAPE]: Attempt to set a ProfileCurve with a profile shape value of {0}, which isn't a valid enum. Replacing with square.",
  163. profileShapeByte);
  164. this._profileShape = ProfileShape.Square;
  165. }
  166. else
  167. {
  168. this._profileShape = (ProfileShape)profileShapeByte;
  169. }
  170. }
  171. }
  172. /// <summary>
  173. /// Entries to store media textures on each face
  174. /// </summary>
  175. /// Do not change this value directly - always do it through an IMoapModule.
  176. /// Lock before manipulating.
  177. public MediaList Media { get; set; }
  178. public PrimitiveBaseShape()
  179. {
  180. PCode = (byte)PCodeEnum.Primitive;
  181. m_textureEntry = DEFAULT_TEXTURE;
  182. }
  183. /// <summary>
  184. /// Construct a PrimitiveBaseShape object from a OpenMetaverse.Primitive object
  185. /// </summary>
  186. /// <param name="prim"></param>
  187. public PrimitiveBaseShape(Primitive prim)
  188. {
  189. // m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: Creating from {0}", prim.ID);
  190. PCode = (byte)prim.PrimData.PCode;
  191. State = prim.PrimData.State;
  192. LastAttachPoint = prim.PrimData.State;
  193. PathBegin = Primitive.PackBeginCut(prim.PrimData.PathBegin);
  194. PathEnd = Primitive.PackEndCut(prim.PrimData.PathEnd);
  195. PathScaleX = Primitive.PackPathScale(prim.PrimData.PathScaleX);
  196. PathScaleY = Primitive.PackPathScale(prim.PrimData.PathScaleY);
  197. PathShearX = (byte)Primitive.PackPathShear(prim.PrimData.PathShearX);
  198. PathShearY = (byte)Primitive.PackPathShear(prim.PrimData.PathShearY);
  199. PathSkew = Primitive.PackPathTwist(prim.PrimData.PathSkew);
  200. ProfileBegin = Primitive.PackBeginCut(prim.PrimData.ProfileBegin);
  201. ProfileEnd = Primitive.PackEndCut(prim.PrimData.ProfileEnd);
  202. Scale = prim.Scale;
  203. PathCurve = (byte)prim.PrimData.PathCurve;
  204. ProfileCurve = (byte)prim.PrimData.ProfileCurve;
  205. ProfileHollow = Primitive.PackProfileHollow(prim.PrimData.ProfileHollow);
  206. PathRadiusOffset = Primitive.PackPathTwist(prim.PrimData.PathRadiusOffset);
  207. PathRevolutions = Primitive.PackPathRevolutions(prim.PrimData.PathRevolutions);
  208. PathTaperX = Primitive.PackPathTaper(prim.PrimData.PathTaperX);
  209. PathTaperY = Primitive.PackPathTaper(prim.PrimData.PathTaperY);
  210. PathTwist = Primitive.PackPathTwist(prim.PrimData.PathTwist);
  211. PathTwistBegin = Primitive.PackPathTwist(prim.PrimData.PathTwistBegin);
  212. m_textureEntry = prim.Textures.GetBytes();
  213. if (prim.Sculpt != null)
  214. {
  215. SculptEntry = (prim.Sculpt.Type != OpenMetaverse.SculptType.None);
  216. SculptData = prim.Sculpt.GetBytes();
  217. SculptTexture = prim.Sculpt.SculptTexture;
  218. SculptType = (byte)prim.Sculpt.Type;
  219. }
  220. else
  221. {
  222. SculptType = (byte)OpenMetaverse.SculptType.None;
  223. }
  224. }
  225. [XmlIgnore]
  226. public Primitive.TextureEntry Textures
  227. {
  228. get
  229. {
  230. // m_log.DebugFormat("[SHAPE]: get m_textureEntry length {0}", m_textureEntry.Length);
  231. try { return new Primitive.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); }
  232. catch { }
  233. m_log.Warn("[SHAPE]: Failed to decode texture, length=" + ((m_textureEntry != null) ? m_textureEntry.Length : 0));
  234. return new Primitive.TextureEntry(UUID.Zero);
  235. }
  236. set { m_textureEntry = value.GetBytes(); }
  237. }
  238. public byte[] TextureEntry
  239. {
  240. get { return m_textureEntry; }
  241. set
  242. {
  243. if (value == null)
  244. m_textureEntry = new byte[1];
  245. else
  246. m_textureEntry = value;
  247. }
  248. }
  249. public static PrimitiveBaseShape Default
  250. {
  251. get
  252. {
  253. PrimitiveBaseShape boxShape = CreateBox();
  254. boxShape.SetScale(0.5f);
  255. return boxShape;
  256. }
  257. }
  258. public static PrimitiveBaseShape Create()
  259. {
  260. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  261. return shape;
  262. }
  263. public static PrimitiveBaseShape CreateBox()
  264. {
  265. PrimitiveBaseShape shape = Create();
  266. shape._pathCurve = (byte) Extrusion.Straight;
  267. shape._profileShape = ProfileShape.Square;
  268. shape._pathScaleX = 100;
  269. shape._pathScaleY = 100;
  270. return shape;
  271. }
  272. public static PrimitiveBaseShape CreateSphere()
  273. {
  274. PrimitiveBaseShape shape = Create();
  275. shape._pathCurve = (byte) Extrusion.Curve1;
  276. shape._profileShape = ProfileShape.HalfCircle;
  277. shape._pathScaleX = 100;
  278. shape._pathScaleY = 100;
  279. return shape;
  280. }
  281. public static PrimitiveBaseShape CreateCylinder()
  282. {
  283. PrimitiveBaseShape shape = Create();
  284. shape._pathCurve = (byte) Extrusion.Curve1;
  285. shape._profileShape = ProfileShape.Square;
  286. shape._pathScaleX = 100;
  287. shape._pathScaleY = 100;
  288. return shape;
  289. }
  290. public static PrimitiveBaseShape CreateMesh(int numberOfFaces, UUID meshAssetID)
  291. {
  292. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  293. shape._pathScaleX = 100;
  294. shape._pathScaleY = 100;
  295. if(numberOfFaces <= 0) // oops ?
  296. numberOfFaces = 1;
  297. switch(numberOfFaces)
  298. {
  299. case 1: // torus
  300. shape.ProfileCurve = (byte)ProfileShape.Circle | (byte)HollowShape.Triangle;
  301. shape.PathCurve = (byte)Extrusion.Curve1;
  302. shape._pathScaleY = 150;
  303. break;
  304. case 2: // torus with hollow (a sl viewer whould see 4 faces on a hollow sphere)
  305. shape.ProfileCurve = (byte)ProfileShape.Circle | (byte)HollowShape.Triangle;
  306. shape.PathCurve = (byte)Extrusion.Curve1;
  307. shape.ProfileHollow = 27500;
  308. shape._pathScaleY = 150;
  309. break;
  310. case 3: // cylinder
  311. shape.ProfileCurve = (byte)ProfileShape.Circle | (byte)HollowShape.Triangle;
  312. shape.PathCurve = (byte)Extrusion.Straight;
  313. break;
  314. case 4: // cylinder with hollow
  315. shape.ProfileCurve = (byte)ProfileShape.Circle | (byte)HollowShape.Triangle;
  316. shape.PathCurve = (byte)Extrusion.Straight;
  317. shape.ProfileHollow = 27500;
  318. break;
  319. case 5: // prism
  320. shape.ProfileCurve = (byte)ProfileShape.EquilateralTriangle | (byte)HollowShape.Triangle;
  321. shape.PathCurve = (byte)Extrusion.Straight;
  322. break;
  323. case 6: // box
  324. shape.ProfileCurve = (byte)ProfileShape.Square | (byte)HollowShape.Triangle;
  325. shape.PathCurve = (byte)Extrusion.Straight;
  326. break;
  327. case 7: // box with hollow
  328. shape.ProfileCurve = (byte)ProfileShape.Square | (byte)HollowShape.Triangle;
  329. shape.PathCurve = (byte)Extrusion.Straight;
  330. shape.ProfileHollow = 27500;
  331. break;
  332. default: // 8 faces box with cut
  333. shape.ProfileCurve = (byte)ProfileShape.Square | (byte)HollowShape.Triangle;
  334. shape.PathCurve = (byte)Extrusion.Straight;
  335. shape.ProfileBegin = 9375;
  336. break;
  337. }
  338. shape.SculptEntry = true;
  339. shape.SculptType = (byte)OpenMetaverse.SculptType.Mesh;
  340. shape.SculptTexture = meshAssetID;
  341. return shape;
  342. }
  343. public void SetScale(float side)
  344. {
  345. _scale = new Vector3(side, side, side);
  346. }
  347. public void SetHeigth(float height)
  348. {
  349. _scale.Z = height;
  350. }
  351. public void SetRadius(float radius)
  352. {
  353. _scale.X = _scale.Y = radius * 2f;
  354. }
  355. // TODO: void returns need to change of course
  356. public virtual void GetMesh()
  357. {
  358. }
  359. public PrimitiveBaseShape Copy()
  360. {
  361. return (PrimitiveBaseShape) MemberwiseClone();
  362. }
  363. public static PrimitiveBaseShape CreateCylinder(float radius, float heigth)
  364. {
  365. PrimitiveBaseShape shape = CreateCylinder();
  366. shape.SetHeigth(heigth);
  367. shape.SetRadius(radius);
  368. return shape;
  369. }
  370. public void SetPathRange(Vector3 pathRange)
  371. {
  372. _pathBegin = Primitive.PackBeginCut(pathRange.X);
  373. _pathEnd = Primitive.PackEndCut(pathRange.Y);
  374. }
  375. public void SetPathRange(float begin, float end)
  376. {
  377. _pathBegin = Primitive.PackBeginCut(begin);
  378. _pathEnd = Primitive.PackEndCut(end);
  379. }
  380. public void SetSculptProperties(byte sculptType, UUID SculptTextureUUID)
  381. {
  382. _sculptType = sculptType;
  383. _sculptTexture = SculptTextureUUID;
  384. }
  385. public void SetProfileRange(Vector3 profileRange)
  386. {
  387. _profileBegin = Primitive.PackBeginCut(profileRange.X);
  388. _profileEnd = Primitive.PackEndCut(profileRange.Y);
  389. }
  390. public void SetProfileRange(float begin, float end)
  391. {
  392. _profileBegin = Primitive.PackBeginCut(begin);
  393. _profileEnd = Primitive.PackEndCut(end);
  394. }
  395. public byte[] ExtraParams
  396. {
  397. get
  398. {
  399. return ExtraParamsToBytes();
  400. }
  401. set
  402. {
  403. ReadInExtraParamsBytes(value);
  404. }
  405. }
  406. public ushort PathBegin {
  407. get {
  408. return _pathBegin;
  409. }
  410. set {
  411. _pathBegin = value;
  412. }
  413. }
  414. public byte PathCurve {
  415. get {
  416. return _pathCurve;
  417. }
  418. set {
  419. _pathCurve = value;
  420. }
  421. }
  422. public ushort PathEnd {
  423. get {
  424. return _pathEnd;
  425. }
  426. set {
  427. _pathEnd = value;
  428. }
  429. }
  430. public sbyte PathRadiusOffset {
  431. get {
  432. return _pathRadiusOffset;
  433. }
  434. set {
  435. _pathRadiusOffset = value;
  436. }
  437. }
  438. public byte PathRevolutions {
  439. get {
  440. return _pathRevolutions;
  441. }
  442. set {
  443. _pathRevolutions = value;
  444. }
  445. }
  446. public byte PathScaleX {
  447. get {
  448. return _pathScaleX;
  449. }
  450. set {
  451. _pathScaleX = value;
  452. }
  453. }
  454. public byte PathScaleY {
  455. get {
  456. return _pathScaleY;
  457. }
  458. set {
  459. _pathScaleY = value;
  460. }
  461. }
  462. public byte PathShearX {
  463. get {
  464. return _pathShearX;
  465. }
  466. set {
  467. _pathShearX = value;
  468. }
  469. }
  470. public byte PathShearY {
  471. get {
  472. return _pathShearY;
  473. }
  474. set {
  475. _pathShearY = value;
  476. }
  477. }
  478. public sbyte PathSkew {
  479. get {
  480. return _pathSkew;
  481. }
  482. set {
  483. _pathSkew = value;
  484. }
  485. }
  486. public sbyte PathTaperX {
  487. get {
  488. return _pathTaperX;
  489. }
  490. set {
  491. _pathTaperX = value;
  492. }
  493. }
  494. public sbyte PathTaperY {
  495. get {
  496. return _pathTaperY;
  497. }
  498. set {
  499. _pathTaperY = value;
  500. }
  501. }
  502. public sbyte PathTwist {
  503. get {
  504. return _pathTwist;
  505. }
  506. set {
  507. _pathTwist = value;
  508. }
  509. }
  510. public sbyte PathTwistBegin {
  511. get {
  512. return _pathTwistBegin;
  513. }
  514. set {
  515. _pathTwistBegin = value;
  516. }
  517. }
  518. public byte PCode {
  519. get {
  520. return _pCode;
  521. }
  522. set {
  523. _pCode = value;
  524. }
  525. }
  526. public ushort ProfileBegin {
  527. get {
  528. return _profileBegin;
  529. }
  530. set {
  531. _profileBegin = value;
  532. }
  533. }
  534. public ushort ProfileEnd {
  535. get {
  536. return _profileEnd;
  537. }
  538. set {
  539. _profileEnd = value;
  540. }
  541. }
  542. public ushort ProfileHollow {
  543. get {
  544. return _profileHollow;
  545. }
  546. set {
  547. _profileHollow = value;
  548. }
  549. }
  550. public Vector3 Scale {
  551. get {
  552. return _scale;
  553. }
  554. set {
  555. _scale = value;
  556. }
  557. }
  558. public byte State {
  559. get {
  560. return _state;
  561. }
  562. set {
  563. _state = value;
  564. }
  565. }
  566. public byte LastAttachPoint {
  567. get {
  568. return _lastattach;
  569. }
  570. set {
  571. _lastattach = value;
  572. }
  573. }
  574. public ProfileShape ProfileShape {
  575. get {
  576. return _profileShape;
  577. }
  578. set {
  579. _profileShape = value;
  580. }
  581. }
  582. public HollowShape HollowShape {
  583. get {
  584. return _hollowShape;
  585. }
  586. set {
  587. _hollowShape = value;
  588. }
  589. }
  590. public UUID SculptTexture {
  591. get {
  592. return _sculptTexture;
  593. }
  594. set {
  595. _sculptTexture = value;
  596. }
  597. }
  598. public byte SculptType
  599. {
  600. get
  601. {
  602. return _sculptType;
  603. }
  604. set
  605. {
  606. _sculptType = value;
  607. }
  608. }
  609. // This is only used at runtime. For sculpties this holds the texture data, and for meshes
  610. // the mesh data.
  611. public byte[] SculptData
  612. {
  613. get
  614. {
  615. return _sculptData;
  616. }
  617. set
  618. {
  619. // m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: Setting SculptData to data with length {0}", value.Length);
  620. _sculptData = value;
  621. }
  622. }
  623. public int FlexiSoftness
  624. {
  625. get
  626. {
  627. return _flexiSoftness;
  628. }
  629. set
  630. {
  631. _flexiSoftness = value;
  632. }
  633. }
  634. public float FlexiTension {
  635. get {
  636. return _flexiTension;
  637. }
  638. set {
  639. _flexiTension = value;
  640. }
  641. }
  642. public float FlexiDrag {
  643. get {
  644. return _flexiDrag;
  645. }
  646. set {
  647. _flexiDrag = value;
  648. }
  649. }
  650. public float FlexiGravity {
  651. get {
  652. return _flexiGravity;
  653. }
  654. set {
  655. _flexiGravity = value;
  656. }
  657. }
  658. public float FlexiWind {
  659. get {
  660. return _flexiWind;
  661. }
  662. set {
  663. _flexiWind = value;
  664. }
  665. }
  666. public float FlexiForceX {
  667. get {
  668. return _flexiForceX;
  669. }
  670. set {
  671. _flexiForceX = value;
  672. }
  673. }
  674. public float FlexiForceY {
  675. get {
  676. return _flexiForceY;
  677. }
  678. set {
  679. _flexiForceY = value;
  680. }
  681. }
  682. public float FlexiForceZ {
  683. get {
  684. return _flexiForceZ;
  685. }
  686. set {
  687. _flexiForceZ = value;
  688. }
  689. }
  690. public float LightColorR {
  691. get {
  692. return _lightColorR;
  693. }
  694. set {
  695. if (value < 0)
  696. _lightColorR = 0;
  697. else if (value > 1.0f)
  698. _lightColorR = 1.0f;
  699. else
  700. _lightColorR = value;
  701. }
  702. }
  703. public float LightColorG {
  704. get {
  705. return _lightColorG;
  706. }
  707. set {
  708. if (value < 0)
  709. _lightColorG = 0;
  710. else if (value > 1.0f)
  711. _lightColorG = 1.0f;
  712. else
  713. _lightColorG = value;
  714. }
  715. }
  716. public float LightColorB {
  717. get {
  718. return _lightColorB;
  719. }
  720. set {
  721. if (value < 0)
  722. _lightColorB = 0;
  723. else if (value > 1.0f)
  724. _lightColorB = 1.0f;
  725. else
  726. _lightColorB = value;
  727. }
  728. }
  729. public float LightColorA {
  730. get {
  731. return _lightColorA;
  732. }
  733. set {
  734. if (value < 0)
  735. _lightColorA = 0;
  736. else if (value > 1.0f)
  737. _lightColorA = 1.0f;
  738. else
  739. _lightColorA = value;
  740. }
  741. }
  742. public float LightRadius {
  743. get {
  744. return _lightRadius;
  745. }
  746. set {
  747. _lightRadius = value;
  748. }
  749. }
  750. public float LightCutoff {
  751. get {
  752. return _lightCutoff;
  753. }
  754. set {
  755. _lightCutoff = value;
  756. }
  757. }
  758. public float LightFalloff {
  759. get {
  760. return _lightFalloff;
  761. }
  762. set {
  763. _lightFalloff = value;
  764. }
  765. }
  766. public float LightIntensity {
  767. get {
  768. return _lightIntensity;
  769. }
  770. set {
  771. _lightIntensity = value;
  772. }
  773. }
  774. public bool FlexiEntry {
  775. get {
  776. return _flexiEntry;
  777. }
  778. set {
  779. _flexiEntry = value;
  780. }
  781. }
  782. public bool LightEntry {
  783. get {
  784. return _lightEntry;
  785. }
  786. set {
  787. _lightEntry = value;
  788. }
  789. }
  790. public bool SculptEntry {
  791. get {
  792. return _sculptEntry;
  793. }
  794. set {
  795. _sculptEntry = value;
  796. }
  797. }
  798. public bool ProjectionEntry {
  799. get {
  800. return _projectionEntry;
  801. }
  802. set {
  803. _projectionEntry = value;
  804. }
  805. }
  806. public UUID ProjectionTextureUUID {
  807. get {
  808. return _projectionTextureID;
  809. }
  810. set {
  811. _projectionTextureID = value;
  812. }
  813. }
  814. public float ProjectionFOV {
  815. get {
  816. return _projectionFOV;
  817. }
  818. set {
  819. _projectionFOV = value;
  820. }
  821. }
  822. public float ProjectionFocus {
  823. get {
  824. return _projectionFocus;
  825. }
  826. set {
  827. _projectionFocus = value;
  828. }
  829. }
  830. public float ProjectionAmbiance {
  831. get {
  832. return _projectionAmb;
  833. }
  834. set {
  835. _projectionAmb = value;
  836. }
  837. }
  838. public ulong GetMeshKey(Vector3 size, float lod)
  839. {
  840. return GetMeshKey(size, lod, false);
  841. }
  842. public ulong GetMeshKey(Vector3 size, float lod, bool convex)
  843. {
  844. ulong hash = 5381;
  845. hash = djb2(hash, this.PathCurve);
  846. hash = djb2(hash, (byte)((byte)this.HollowShape | (byte)this.ProfileShape));
  847. hash = djb2(hash, this.PathBegin);
  848. hash = djb2(hash, this.PathEnd);
  849. hash = djb2(hash, this.PathScaleX);
  850. hash = djb2(hash, this.PathScaleY);
  851. hash = djb2(hash, this.PathShearX);
  852. hash = djb2(hash, this.PathShearY);
  853. hash = djb2(hash, (byte)this.PathTwist);
  854. hash = djb2(hash, (byte)this.PathTwistBegin);
  855. hash = djb2(hash, (byte)this.PathRadiusOffset);
  856. hash = djb2(hash, (byte)this.PathTaperX);
  857. hash = djb2(hash, (byte)this.PathTaperY);
  858. hash = djb2(hash, this.PathRevolutions);
  859. hash = djb2(hash, (byte)this.PathSkew);
  860. hash = djb2(hash, this.ProfileBegin);
  861. hash = djb2(hash, this.ProfileEnd);
  862. hash = djb2(hash, this.ProfileHollow);
  863. // TODO: Separate scale out from the primitive shape data (after
  864. // scaling is supported at the physics engine level)
  865. byte[] scaleBytes = size.GetBytes();
  866. for (int i = 0; i < scaleBytes.Length; i++)
  867. hash = djb2(hash, scaleBytes[i]);
  868. // Include LOD in hash, accounting for endianness
  869. byte[] lodBytes = new byte[4];
  870. Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
  871. if (!BitConverter.IsLittleEndian)
  872. {
  873. Array.Reverse(lodBytes, 0, 4);
  874. }
  875. for (int i = 0; i < lodBytes.Length; i++)
  876. hash = djb2(hash, lodBytes[i]);
  877. // include sculpt UUID
  878. if (this.SculptEntry)
  879. {
  880. scaleBytes = this.SculptTexture.GetBytes();
  881. for (int i = 0; i < scaleBytes.Length; i++)
  882. hash = djb2(hash, scaleBytes[i]);
  883. }
  884. if(convex)
  885. hash = djb2(hash, 0xa5);
  886. return hash;
  887. }
  888. private ulong djb2(ulong hash, byte c)
  889. {
  890. return ((hash << 5) + hash) + (ulong)c;
  891. }
  892. private ulong djb2(ulong hash, ushort c)
  893. {
  894. hash = ((hash << 5) + hash) + (ulong)((byte)c);
  895. return ((hash << 5) + hash) + (ulong)(c >> 8);
  896. }
  897. public byte[] ExtraParamsToBytes()
  898. {
  899. // m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()");
  900. const byte FlexiEP = 0x10;
  901. const byte LightEP = 0x20;
  902. const byte SculptEP = 0x30;
  903. const byte ProjectionEP = 0x40;
  904. const byte MeshFlagsEP = 0x70;
  905. int TotalBytesLength = 1; // ExtraParamsNum
  906. uint ExtraParamsNum = 0;
  907. if (_flexiEntry)
  908. {
  909. ExtraParamsNum++;
  910. TotalBytesLength += 16 + 2 + 4;// data
  911. }
  912. if (_lightEntry)
  913. {
  914. ExtraParamsNum++;
  915. TotalBytesLength += 16 + 2 + 4; // data
  916. }
  917. if (_sculptEntry)
  918. {
  919. ExtraParamsNum++;
  920. TotalBytesLength += 17 + 2 + 4;// data
  921. }
  922. if (_projectionEntry)
  923. {
  924. ExtraParamsNum++;
  925. TotalBytesLength += 28 + 2 + 4; // data
  926. }
  927. if (_meshFlagsEntry)
  928. {
  929. ExtraParamsNum++;
  930. TotalBytesLength += 4 + 2 + 4; // data
  931. }
  932. byte[] returnBytes = new byte[TotalBytesLength];
  933. returnBytes[0] = (byte)ExtraParamsNum;
  934. if(ExtraParamsNum == 0)
  935. return returnBytes;
  936. int i = 1;
  937. if (_flexiEntry)
  938. {
  939. returnBytes[i] = FlexiEP; // 2 bytes id code
  940. i += 2;
  941. returnBytes[i] = 16; // 4 bytes size
  942. i += 4;
  943. // Softness is packed in the upper bits of tension and drag
  944. returnBytes[i] = (byte)((_flexiSoftness & 2) << 6);
  945. returnBytes[i + 1] = (byte)((_flexiSoftness & 1) << 7);
  946. returnBytes[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F);
  947. returnBytes[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F);
  948. returnBytes[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f);
  949. returnBytes[i++] = (byte)(_flexiWind * 10.01f);
  950. Utils.FloatToBytes(_flexiForceX, returnBytes, i);
  951. Utils.FloatToBytes(_flexiForceY, returnBytes, i + 4);
  952. Utils.FloatToBytes(_flexiForceZ, returnBytes, i + 8);
  953. i += 12;
  954. }
  955. if (_lightEntry)
  956. {
  957. returnBytes[i] = LightEP;
  958. i += 2;
  959. returnBytes[i] = 16;
  960. i += 4;
  961. // Alpha channel in color is intensity
  962. Color4 tmpColor = new Color4(_lightColorR, _lightColorG, _lightColorB, _lightIntensity);
  963. tmpColor.GetBytes().CopyTo(returnBytes, i);
  964. Utils.FloatToBytes(_lightRadius, returnBytes, i + 4);
  965. Utils.FloatToBytes(_lightCutoff, returnBytes, i + 8);
  966. Utils.FloatToBytes(_lightFalloff, returnBytes, i + 12);
  967. i += 16;
  968. }
  969. if (_sculptEntry)
  970. {
  971. returnBytes[i] = SculptEP;
  972. i += 2;
  973. returnBytes[i] = 17;
  974. i += 4;
  975. _sculptTexture.GetBytes().CopyTo(returnBytes, i);
  976. i += 16;
  977. returnBytes[i++] = _sculptType;
  978. }
  979. if (_projectionEntry)
  980. {
  981. returnBytes[i] = ProjectionEP;
  982. i += 2;
  983. returnBytes[i] = 28;
  984. i += 4;
  985. _projectionTextureID.GetBytes().CopyTo(returnBytes, i);
  986. Utils.FloatToBytes(_projectionFOV, returnBytes, i + 16);
  987. Utils.FloatToBytes(_projectionFocus, returnBytes, i + 20);
  988. Utils.FloatToBytes(_projectionAmb, returnBytes, i + 24);
  989. i += 28;
  990. }
  991. if (_meshFlagsEntry)
  992. {
  993. returnBytes[i] = MeshFlagsEP;
  994. i += 2;
  995. returnBytes[i] = 4;
  996. i += 4;
  997. Utils.UIntToBytes(_meshFlags, returnBytes, i);
  998. }
  999. return returnBytes;
  1000. }
  1001. public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data)
  1002. {
  1003. const ushort FlexiEP = 0x10;
  1004. const ushort LightEP = 0x20;
  1005. const ushort SculptEP = 0x30;
  1006. const ushort ProjectionEP = 0x40;
  1007. const ushort MeshFlagsEP = 0x70;
  1008. switch (type)
  1009. {
  1010. case FlexiEP:
  1011. if (!inUse)
  1012. {
  1013. _flexiEntry = false;
  1014. return;
  1015. }
  1016. ReadFlexiData(data, 0);
  1017. break;
  1018. case LightEP:
  1019. if (!inUse)
  1020. {
  1021. _lightEntry = false;
  1022. return;
  1023. }
  1024. ReadLightData(data, 0);
  1025. break;
  1026. case SculptEP:
  1027. if (!inUse)
  1028. {
  1029. _sculptEntry = false;
  1030. return;
  1031. }
  1032. ReadSculptData(data, 0);
  1033. break;
  1034. case ProjectionEP:
  1035. if (!inUse)
  1036. {
  1037. _projectionEntry = false;
  1038. return;
  1039. }
  1040. ReadProjectionData(data, 0);
  1041. break;
  1042. case MeshFlagsEP:
  1043. if (!inUse)
  1044. {
  1045. _meshFlagsEntry = false;
  1046. return;
  1047. }
  1048. ReadMeshFlagsData(data, 0);
  1049. break;
  1050. }
  1051. }
  1052. public void ReadInExtraParamsBytes(byte[] data)
  1053. {
  1054. if (data == null)
  1055. return;
  1056. _flexiEntry = false;
  1057. _lightEntry = false;
  1058. _sculptEntry = false;
  1059. _projectionEntry = false;
  1060. _meshFlagsEntry = false;
  1061. if (data.Length == 1)
  1062. return;
  1063. const byte FlexiEP = 0x10;
  1064. const byte LightEP = 0x20;
  1065. const byte SculptEP = 0x30;
  1066. const byte ProjectionEP = 0x40;
  1067. const byte MeshFlagsEP = 0x70;
  1068. byte extraParamCount = data[0];
  1069. int i = 1;
  1070. for (int k = 0; k < extraParamCount; k++)
  1071. {
  1072. byte epType = data[i];
  1073. i += 6;
  1074. switch (epType)
  1075. {
  1076. case FlexiEP:
  1077. ReadFlexiData(data, i);
  1078. i += 16;
  1079. break;
  1080. case LightEP:
  1081. ReadLightData(data, i);
  1082. i += 16;
  1083. break;
  1084. case SculptEP:
  1085. ReadSculptData(data, i);
  1086. i += 17;
  1087. break;
  1088. case ProjectionEP:
  1089. ReadProjectionData(data, i);
  1090. i += 28;
  1091. break;
  1092. case MeshFlagsEP:
  1093. ReadMeshFlagsData(data, i);
  1094. i += 4;
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. public void ReadSculptData(byte[] data, int pos)
  1100. {
  1101. if (data.Length-pos >= 17)
  1102. {
  1103. _sculptTexture = new UUID(data, pos);
  1104. _sculptType = data[pos + 16];
  1105. _sculptEntry = true;
  1106. }
  1107. else
  1108. {
  1109. _sculptEntry = false;
  1110. _sculptTexture = UUID.Zero;
  1111. _sculptType = 0x00;
  1112. }
  1113. }
  1114. public void ReadFlexiData(byte[] data, int pos)
  1115. {
  1116. if (data.Length-pos >= 16)
  1117. {
  1118. _flexiEntry = true;
  1119. _flexiSoftness = ((data[pos] & 0x80) >> 6) | ((data[pos + 1] & 0x80) >> 7);
  1120. _flexiTension = (float)(data[pos++] & 0x7F) / 10.0f;
  1121. _flexiDrag = (float)(data[pos++] & 0x7F) / 10.0f;
  1122. _flexiGravity = (float)(data[pos++] / 10.0f) - 10.0f;
  1123. _flexiWind = (float)data[pos++] / 10.0f;
  1124. _flexiForceX = Utils.BytesToFloat(data, pos);
  1125. _flexiForceY = Utils.BytesToFloat(data, pos + 4);
  1126. _flexiForceZ = Utils.BytesToFloat(data, pos + 8);
  1127. }
  1128. else
  1129. {
  1130. _flexiEntry = false;
  1131. _flexiSoftness = 0;
  1132. _flexiTension = 0.0f;
  1133. _flexiDrag = 0.0f;
  1134. _flexiGravity = 0.0f;
  1135. _flexiWind = 0.0f;
  1136. _flexiForceX = 0f;
  1137. _flexiForceY = 0f;
  1138. _flexiForceZ = 0f;
  1139. }
  1140. }
  1141. public void ReadLightData(byte[] data, int pos)
  1142. {
  1143. if (data.Length - pos >= 16)
  1144. {
  1145. _lightEntry = true;
  1146. Color4 lColor = new Color4(data, pos, false);
  1147. _lightIntensity = lColor.A;
  1148. _lightColorA = 1f;
  1149. _lightColorR = lColor.R;
  1150. _lightColorG = lColor.G;
  1151. _lightColorB = lColor.B;
  1152. _lightRadius = Utils.BytesToFloat(data, pos + 4);
  1153. _lightCutoff = Utils.BytesToFloat(data, pos + 8);
  1154. _lightFalloff = Utils.BytesToFloat(data, pos + 12);
  1155. }
  1156. else
  1157. {
  1158. _lightEntry = false;
  1159. _lightColorA = 1f;
  1160. _lightColorR = 0f;
  1161. _lightColorG = 0f;
  1162. _lightColorB = 0f;
  1163. _lightRadius = 0f;
  1164. _lightCutoff = 0f;
  1165. _lightFalloff = 0f;
  1166. _lightIntensity = 0f;
  1167. }
  1168. }
  1169. public void ReadProjectionData(byte[] data, int pos)
  1170. {
  1171. if (data.Length - pos >= 28)
  1172. {
  1173. _projectionEntry = true;
  1174. _projectionTextureID = new UUID(data, pos);
  1175. _projectionFOV = Utils.BytesToFloat(data, pos + 16);
  1176. _projectionFocus = Utils.BytesToFloat(data, pos + 20);
  1177. _projectionAmb = Utils.BytesToFloat(data, pos + 24);
  1178. }
  1179. else
  1180. {
  1181. _projectionEntry = false;
  1182. _projectionTextureID = UUID.Zero;
  1183. _projectionFOV = 0f;
  1184. _projectionFocus = 0f;
  1185. _projectionAmb = 0f;
  1186. }
  1187. }
  1188. public void ReadMeshFlagsData(byte[] data, int pos)
  1189. {
  1190. if (data.Length - pos >= 4)
  1191. {
  1192. _meshFlagsEntry = true;
  1193. _meshFlags = Utils.BytesToUInt(data, pos);
  1194. }
  1195. else
  1196. {
  1197. _meshFlagsEntry = true;
  1198. _meshFlags = 0;
  1199. }
  1200. }
  1201. /// <summary>
  1202. /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
  1203. /// </summary>
  1204. /// <returns></returns>
  1205. public Primitive ToOmvPrimitive()
  1206. {
  1207. // position and rotation defaults here since they are not available in PrimitiveBaseShape
  1208. return ToOmvPrimitive(new Vector3(0.0f, 0.0f, 0.0f),
  1209. new Quaternion(0.0f, 0.0f, 0.0f, 1.0f));
  1210. }
  1211. /// <summary>
  1212. /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
  1213. /// </summary>
  1214. /// <param name="position"></param>
  1215. /// <param name="rotation"></param>
  1216. /// <returns></returns>
  1217. public Primitive ToOmvPrimitive(Vector3 position, Quaternion rotation)
  1218. {
  1219. OpenMetaverse.Primitive prim = new OpenMetaverse.Primitive();
  1220. prim.Scale = this.Scale;
  1221. prim.Position = position;
  1222. prim.Rotation = rotation;
  1223. if (this.SculptEntry)
  1224. {
  1225. prim.Sculpt = new Primitive.SculptData();
  1226. prim.Sculpt.Type = (OpenMetaverse.SculptType)this.SculptType;
  1227. prim.Sculpt.SculptTexture = this.SculptTexture;
  1228. }
  1229. prim.PrimData.PathShearX = this.PathShearX < 128 ? (float)this.PathShearX * 0.01f : (float)(this.PathShearX - 256) * 0.01f;
  1230. prim.PrimData.PathShearY = this.PathShearY < 128 ? (float)this.PathShearY * 0.01f : (float)(this.PathShearY - 256) * 0.01f;
  1231. prim.PrimData.PathBegin = (float)this.PathBegin * 2.0e-5f;
  1232. prim.PrimData.PathEnd = 1.0f - (float)this.PathEnd * 2.0e-5f;
  1233. prim.PrimData.PathScaleX = (200 - this.PathScaleX) * 0.01f;
  1234. prim.PrimData.PathScaleY = (200 - this.PathScaleY) * 0.01f;
  1235. prim.PrimData.PathTaperX = this.PathTaperX * 0.01f;
  1236. prim.PrimData.PathTaperY = this.PathTaperY * 0.01f;
  1237. prim.PrimData.PathTwistBegin = this.PathTwistBegin * 0.01f;
  1238. prim.PrimData.PathTwist = this.PathTwist * 0.01f;
  1239. prim.PrimData.ProfileBegin = (float)this.ProfileBegin * 2.0e-5f;
  1240. prim.PrimData.ProfileEnd = 1.0f - (float)this.ProfileEnd * 2.0e-5f;
  1241. prim.PrimData.ProfileHollow = (float)this.ProfileHollow * 2.0e-5f;
  1242. prim.PrimData.profileCurve = this.ProfileCurve;
  1243. prim.PrimData.ProfileHole = (HoleType)this.HollowShape;
  1244. prim.PrimData.PathCurve = (PathCurve)this.PathCurve;
  1245. prim.PrimData.PathRadiusOffset = 0.01f * this.PathRadiusOffset;
  1246. prim.PrimData.PathRevolutions = 1.0f + 0.015f * this.PathRevolutions;
  1247. prim.PrimData.PathSkew = 0.01f * this.PathSkew;
  1248. prim.PrimData.PCode = OpenMetaverse.PCode.Prim;
  1249. prim.PrimData.State = 0;
  1250. if (this.FlexiEntry)
  1251. {
  1252. prim.Flexible = new Primitive.FlexibleData();
  1253. prim.Flexible.Drag = this.FlexiDrag;
  1254. prim.Flexible.Force = new Vector3(this.FlexiForceX, this.FlexiForceY, this.FlexiForceZ);
  1255. prim.Flexible.Gravity = this.FlexiGravity;
  1256. prim.Flexible.Softness = this.FlexiSoftness;
  1257. prim.Flexible.Tension = this.FlexiTension;
  1258. prim.Flexible.Wind = this.FlexiWind;
  1259. }
  1260. if (this.LightEntry)
  1261. {
  1262. prim.Light = new Primitive.LightData();
  1263. prim.Light.Color = new Color4(this.LightColorR, this.LightColorG, this.LightColorB, this.LightColorA);
  1264. prim.Light.Cutoff = this.LightCutoff;
  1265. prim.Light.Falloff = this.LightFalloff;
  1266. prim.Light.Intensity = this.LightIntensity;
  1267. prim.Light.Radius = this.LightRadius;
  1268. }
  1269. prim.Textures = this.Textures;
  1270. prim.Properties = new Primitive.ObjectProperties();
  1271. prim.Properties.Name = "Object";
  1272. prim.Properties.Description = "";
  1273. prim.Properties.CreatorID = UUID.Zero;
  1274. prim.Properties.GroupID = UUID.Zero;
  1275. prim.Properties.OwnerID = UUID.Zero;
  1276. prim.Properties.Permissions = new Permissions();
  1277. prim.Properties.SalePrice = 10;
  1278. prim.Properties.SaleType = new SaleType();
  1279. return prim;
  1280. }
  1281. /// <summary>
  1282. /// Encapsulates a list of media entries.
  1283. /// </summary>
  1284. /// This class is necessary because we want to replace auto-serialization of MediaEntry with something more
  1285. /// OSD like and less vulnerable to change.
  1286. public class MediaList : List<MediaEntry>, IXmlSerializable
  1287. {
  1288. public const string MEDIA_TEXTURE_TYPE = "sl";
  1289. public MediaList() : base() {}
  1290. public MediaList(IEnumerable<MediaEntry> collection) : base(collection) {}
  1291. public MediaList(int capacity) : base(capacity) {}
  1292. public XmlSchema GetSchema()
  1293. {
  1294. return null;
  1295. }
  1296. public string ToXml()
  1297. {
  1298. lock (this)
  1299. {
  1300. using (StringWriter sw = new StringWriter())
  1301. {
  1302. using (XmlTextWriter xtw = new XmlTextWriter(sw))
  1303. {
  1304. xtw.WriteStartElement("OSMedia");
  1305. xtw.WriteAttributeString("type", MEDIA_TEXTURE_TYPE);
  1306. xtw.WriteAttributeString("version", "0.1");
  1307. OSDArray meArray = new OSDArray();
  1308. foreach (MediaEntry me in this)
  1309. {
  1310. OSD osd = (null == me ? new OSD() : me.GetOSD());
  1311. meArray.Add(osd);
  1312. }
  1313. xtw.WriteStartElement("OSData");
  1314. xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray));
  1315. xtw.WriteEndElement();
  1316. xtw.WriteEndElement();
  1317. xtw.Flush();
  1318. return sw.ToString();
  1319. }
  1320. }
  1321. }
  1322. }
  1323. public void WriteXml(XmlWriter writer)
  1324. {
  1325. writer.WriteRaw(ToXml());
  1326. }
  1327. public static MediaList FromXml(string rawXml)
  1328. {
  1329. MediaList ml = new MediaList();
  1330. ml.ReadXml(rawXml);
  1331. if(ml.Count == 0)
  1332. return null;
  1333. return ml;
  1334. }
  1335. public void ReadXml(string rawXml)
  1336. {
  1337. try
  1338. {
  1339. using (StringReader sr = new StringReader(rawXml))
  1340. {
  1341. using (XmlTextReader xtr = new XmlTextReader(sr))
  1342. {
  1343. xtr.MoveToContent();
  1344. string type = xtr.GetAttribute("type");
  1345. //m_log.DebugFormat("[MOAP]: Loaded media texture entry with type {0}", type);
  1346. if (type != MEDIA_TEXTURE_TYPE)
  1347. return;
  1348. xtr.ReadStartElement("OSMedia");
  1349. OSD osdp = OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
  1350. if(osdp == null || !(osdp is OSDArray))
  1351. return;
  1352. OSDArray osdMeArray = osdp as OSDArray;
  1353. if(osdMeArray.Count == 0)
  1354. return;
  1355. foreach (OSD osdMe in osdMeArray)
  1356. {
  1357. MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry());
  1358. Add(me);
  1359. }
  1360. }
  1361. }
  1362. }
  1363. catch
  1364. {
  1365. m_log.Debug("PrimitiveBaseShape] error decoding MOAP xml" );
  1366. }
  1367. }
  1368. public void ReadXml(XmlReader reader)
  1369. {
  1370. if (reader.IsEmptyElement)
  1371. return;
  1372. ReadXml(reader.ReadInnerXml());
  1373. }
  1374. }
  1375. }
  1376. }