PrimitiveBaseShape.cs 46 KB

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