PrimitiveBaseShape.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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 MeshEP = 0x60;
  905. const byte MeshFlagsEP = 0x70;
  906. int TotalBytesLength = 1; // ExtraParamsNum
  907. uint ExtraParamsNum = 0;
  908. if (_flexiEntry)
  909. {
  910. ExtraParamsNum++;
  911. TotalBytesLength += 16 + 2 + 4;// data
  912. }
  913. if (_lightEntry)
  914. {
  915. ExtraParamsNum++;
  916. TotalBytesLength += 16 + 2 + 4; // data
  917. }
  918. if (_sculptEntry)
  919. {
  920. ExtraParamsNum++;
  921. TotalBytesLength += 17 + 2 + 4;// data
  922. }
  923. if (_projectionEntry)
  924. {
  925. ExtraParamsNum++;
  926. TotalBytesLength += 28 + 2 + 4; // data
  927. }
  928. if (_meshFlagsEntry)
  929. {
  930. ExtraParamsNum++;
  931. TotalBytesLength += 4 + 2 + 4; // data
  932. }
  933. byte[] returnBytes = new byte[TotalBytesLength];
  934. returnBytes[0] = (byte)ExtraParamsNum;
  935. if(ExtraParamsNum == 0)
  936. return returnBytes;
  937. int i = 1;
  938. if (_flexiEntry)
  939. {
  940. returnBytes[i] = FlexiEP; // 2 bytes id code
  941. i += 2;
  942. returnBytes[i] = 16; // 4 bytes size
  943. i += 4;
  944. // Softness is packed in the upper bits of tension and drag
  945. returnBytes[i] = (byte)((_flexiSoftness & 2) << 6);
  946. returnBytes[i + 1] = (byte)((_flexiSoftness & 1) << 7);
  947. returnBytes[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F);
  948. returnBytes[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F);
  949. returnBytes[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f);
  950. returnBytes[i++] = (byte)(_flexiWind * 10.01f);
  951. Utils.FloatToBytes(_flexiForceX, returnBytes, i);
  952. Utils.FloatToBytes(_flexiForceY, returnBytes, i + 4);
  953. Utils.FloatToBytes(_flexiForceZ, returnBytes, i + 8);
  954. i += 12;
  955. }
  956. if (_lightEntry)
  957. {
  958. returnBytes[i] = LightEP;
  959. i += 2;
  960. returnBytes[i] = 16;
  961. i += 4;
  962. // Alpha channel in color is intensity
  963. Color4 tmpColor = new Color4(_lightColorR, _lightColorG, _lightColorB, _lightIntensity);
  964. tmpColor.GetBytes().CopyTo(returnBytes, i);
  965. Utils.FloatToBytes(_lightRadius, returnBytes, i + 4);
  966. Utils.FloatToBytes(_lightCutoff, returnBytes, i + 8);
  967. Utils.FloatToBytes(_lightFalloff, returnBytes, i + 12);
  968. i += 16;
  969. }
  970. if (_sculptEntry)
  971. {
  972. //if(_sculptType == 5)
  973. // returnBytes[i] = MeshEP;
  974. //else
  975. returnBytes[i] = SculptEP;
  976. i += 2;
  977. returnBytes[i] = 17;
  978. i += 4;
  979. _sculptTexture.GetBytes().CopyTo(returnBytes, i);
  980. i += 16;
  981. returnBytes[i++] = _sculptType;
  982. }
  983. if (_projectionEntry)
  984. {
  985. returnBytes[i] = ProjectionEP;
  986. i += 2;
  987. returnBytes[i] = 28;
  988. i += 4;
  989. _projectionTextureID.GetBytes().CopyTo(returnBytes, i);
  990. Utils.FloatToBytes(_projectionFOV, returnBytes, i + 16);
  991. Utils.FloatToBytes(_projectionFocus, returnBytes, i + 20);
  992. Utils.FloatToBytes(_projectionAmb, returnBytes, i + 24);
  993. i += 28;
  994. }
  995. if (_meshFlagsEntry)
  996. {
  997. returnBytes[i] = MeshFlagsEP;
  998. i += 2;
  999. returnBytes[i] = 4;
  1000. i += 4;
  1001. Utils.UIntToBytes(_meshFlags, returnBytes, i);
  1002. }
  1003. return returnBytes;
  1004. }
  1005. public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data)
  1006. {
  1007. const ushort FlexiEP = 0x10;
  1008. const ushort LightEP = 0x20;
  1009. const ushort SculptEP = 0x30;
  1010. const ushort ProjectionEP = 0x40;
  1011. const ushort MeshEP = 0x60;
  1012. const ushort MeshFlagsEP = 0x70;
  1013. switch (type)
  1014. {
  1015. case FlexiEP:
  1016. if (!inUse)
  1017. {
  1018. _flexiEntry = false;
  1019. return;
  1020. }
  1021. ReadFlexiData(data, 0);
  1022. break;
  1023. case LightEP:
  1024. if (!inUse)
  1025. {
  1026. _lightEntry = false;
  1027. return;
  1028. }
  1029. ReadLightData(data, 0);
  1030. break;
  1031. case MeshEP:
  1032. case SculptEP:
  1033. if (!inUse)
  1034. {
  1035. _sculptEntry = false;
  1036. return;
  1037. }
  1038. ReadSculptData(data, 0);
  1039. break;
  1040. case ProjectionEP:
  1041. if (!inUse)
  1042. {
  1043. _projectionEntry = false;
  1044. return;
  1045. }
  1046. ReadProjectionData(data, 0);
  1047. break;
  1048. case MeshFlagsEP:
  1049. if (!inUse)
  1050. {
  1051. _meshFlagsEntry = false;
  1052. return;
  1053. }
  1054. ReadMeshFlagsData(data, 0);
  1055. break;
  1056. }
  1057. }
  1058. public void ReadInExtraParamsBytes(byte[] data)
  1059. {
  1060. if (data == null)
  1061. return;
  1062. _flexiEntry = false;
  1063. _lightEntry = false;
  1064. _sculptEntry = false;
  1065. _projectionEntry = false;
  1066. _meshFlagsEntry = false;
  1067. if (data.Length == 1)
  1068. return;
  1069. const byte FlexiEP = 0x10;
  1070. const byte LightEP = 0x20;
  1071. const byte SculptEP = 0x30;
  1072. const byte ProjectionEP = 0x40;
  1073. const byte MeshEP = 0x60;
  1074. const byte MeshFlagsEP = 0x70;
  1075. byte extraParamCount = data[0];
  1076. int i = 1;
  1077. for (int k = 0; k < extraParamCount; k++)
  1078. {
  1079. byte epType = data[i];
  1080. i += 6;
  1081. switch (epType)
  1082. {
  1083. case FlexiEP:
  1084. ReadFlexiData(data, i);
  1085. i += 16;
  1086. break;
  1087. case LightEP:
  1088. ReadLightData(data, i);
  1089. i += 16;
  1090. break;
  1091. case MeshEP:
  1092. case SculptEP:
  1093. ReadSculptData(data, i);
  1094. i += 17;
  1095. break;
  1096. case ProjectionEP:
  1097. ReadProjectionData(data, i);
  1098. i += 28;
  1099. break;
  1100. case MeshFlagsEP:
  1101. ReadMeshFlagsData(data, i);
  1102. i += 4;
  1103. break;
  1104. }
  1105. }
  1106. }
  1107. public void ReadSculptData(byte[] data, int pos)
  1108. {
  1109. if (data.Length-pos >= 17)
  1110. {
  1111. _sculptTexture = new UUID(data, pos);
  1112. _sculptType = data[pos + 16];
  1113. _sculptEntry = true;
  1114. }
  1115. else
  1116. {
  1117. _sculptEntry = false;
  1118. _sculptTexture = UUID.Zero;
  1119. _sculptType = 0x00;
  1120. }
  1121. }
  1122. public void ReadFlexiData(byte[] data, int pos)
  1123. {
  1124. if (data.Length-pos >= 16)
  1125. {
  1126. _flexiEntry = true;
  1127. _flexiSoftness = ((data[pos] & 0x80) >> 6) | ((data[pos + 1] & 0x80) >> 7);
  1128. _flexiTension = (float)(data[pos++] & 0x7F) / 10.0f;
  1129. _flexiDrag = (float)(data[pos++] & 0x7F) / 10.0f;
  1130. _flexiGravity = (float)(data[pos++] / 10.0f) - 10.0f;
  1131. _flexiWind = (float)data[pos++] / 10.0f;
  1132. _flexiForceX = Utils.BytesToFloat(data, pos);
  1133. _flexiForceY = Utils.BytesToFloat(data, pos + 4);
  1134. _flexiForceZ = Utils.BytesToFloat(data, pos + 8);
  1135. }
  1136. else
  1137. {
  1138. _flexiEntry = false;
  1139. _flexiSoftness = 0;
  1140. _flexiTension = 0.0f;
  1141. _flexiDrag = 0.0f;
  1142. _flexiGravity = 0.0f;
  1143. _flexiWind = 0.0f;
  1144. _flexiForceX = 0f;
  1145. _flexiForceY = 0f;
  1146. _flexiForceZ = 0f;
  1147. }
  1148. }
  1149. public void ReadLightData(byte[] data, int pos)
  1150. {
  1151. if (data.Length - pos >= 16)
  1152. {
  1153. _lightEntry = true;
  1154. Color4 lColor = new Color4(data, pos, false);
  1155. _lightIntensity = lColor.A;
  1156. _lightColorA = 1f;
  1157. _lightColorR = lColor.R;
  1158. _lightColorG = lColor.G;
  1159. _lightColorB = lColor.B;
  1160. _lightRadius = Utils.BytesToFloat(data, pos + 4);
  1161. _lightCutoff = Utils.BytesToFloat(data, pos + 8);
  1162. _lightFalloff = Utils.BytesToFloat(data, pos + 12);
  1163. }
  1164. else
  1165. {
  1166. _lightEntry = false;
  1167. _lightColorA = 1f;
  1168. _lightColorR = 0f;
  1169. _lightColorG = 0f;
  1170. _lightColorB = 0f;
  1171. _lightRadius = 0f;
  1172. _lightCutoff = 0f;
  1173. _lightFalloff = 0f;
  1174. _lightIntensity = 0f;
  1175. }
  1176. }
  1177. public void ReadProjectionData(byte[] data, int pos)
  1178. {
  1179. if (data.Length - pos >= 28)
  1180. {
  1181. _projectionEntry = true;
  1182. _projectionTextureID = new UUID(data, pos);
  1183. _projectionFOV = Utils.BytesToFloat(data, pos + 16);
  1184. _projectionFocus = Utils.BytesToFloat(data, pos + 20);
  1185. _projectionAmb = Utils.BytesToFloat(data, pos + 24);
  1186. }
  1187. else
  1188. {
  1189. _projectionEntry = false;
  1190. _projectionTextureID = UUID.Zero;
  1191. _projectionFOV = 0f;
  1192. _projectionFocus = 0f;
  1193. _projectionAmb = 0f;
  1194. }
  1195. }
  1196. public void ReadMeshFlagsData(byte[] data, int pos)
  1197. {
  1198. if (data.Length - pos >= 4)
  1199. {
  1200. _meshFlagsEntry = true;
  1201. _meshFlags = Utils.BytesToUInt(data, pos);
  1202. }
  1203. else
  1204. {
  1205. _meshFlagsEntry = true;
  1206. _meshFlags = 0;
  1207. }
  1208. }
  1209. /// <summary>
  1210. /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
  1211. /// </summary>
  1212. /// <returns></returns>
  1213. public Primitive ToOmvPrimitive()
  1214. {
  1215. // position and rotation defaults here since they are not available in PrimitiveBaseShape
  1216. return ToOmvPrimitive(new Vector3(0.0f, 0.0f, 0.0f),
  1217. new Quaternion(0.0f, 0.0f, 0.0f, 1.0f));
  1218. }
  1219. /// <summary>
  1220. /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
  1221. /// </summary>
  1222. /// <param name="position"></param>
  1223. /// <param name="rotation"></param>
  1224. /// <returns></returns>
  1225. public Primitive ToOmvPrimitive(Vector3 position, Quaternion rotation)
  1226. {
  1227. OpenMetaverse.Primitive prim = new OpenMetaverse.Primitive();
  1228. prim.Scale = this.Scale;
  1229. prim.Position = position;
  1230. prim.Rotation = rotation;
  1231. if (this.SculptEntry)
  1232. {
  1233. prim.Sculpt = new Primitive.SculptData();
  1234. prim.Sculpt.Type = (OpenMetaverse.SculptType)this.SculptType;
  1235. prim.Sculpt.SculptTexture = this.SculptTexture;
  1236. }
  1237. prim.PrimData.PathShearX = this.PathShearX < 128 ? (float)this.PathShearX * 0.01f : (float)(this.PathShearX - 256) * 0.01f;
  1238. prim.PrimData.PathShearY = this.PathShearY < 128 ? (float)this.PathShearY * 0.01f : (float)(this.PathShearY - 256) * 0.01f;
  1239. prim.PrimData.PathBegin = (float)this.PathBegin * 2.0e-5f;
  1240. prim.PrimData.PathEnd = 1.0f - (float)this.PathEnd * 2.0e-5f;
  1241. prim.PrimData.PathScaleX = (200 - this.PathScaleX) * 0.01f;
  1242. prim.PrimData.PathScaleY = (200 - this.PathScaleY) * 0.01f;
  1243. prim.PrimData.PathTaperX = this.PathTaperX * 0.01f;
  1244. prim.PrimData.PathTaperY = this.PathTaperY * 0.01f;
  1245. prim.PrimData.PathTwistBegin = this.PathTwistBegin * 0.01f;
  1246. prim.PrimData.PathTwist = this.PathTwist * 0.01f;
  1247. prim.PrimData.ProfileBegin = (float)this.ProfileBegin * 2.0e-5f;
  1248. prim.PrimData.ProfileEnd = 1.0f - (float)this.ProfileEnd * 2.0e-5f;
  1249. prim.PrimData.ProfileHollow = (float)this.ProfileHollow * 2.0e-5f;
  1250. prim.PrimData.profileCurve = this.ProfileCurve;
  1251. prim.PrimData.ProfileHole = (HoleType)this.HollowShape;
  1252. prim.PrimData.PathCurve = (PathCurve)this.PathCurve;
  1253. prim.PrimData.PathRadiusOffset = 0.01f * this.PathRadiusOffset;
  1254. prim.PrimData.PathRevolutions = 1.0f + 0.015f * this.PathRevolutions;
  1255. prim.PrimData.PathSkew = 0.01f * this.PathSkew;
  1256. prim.PrimData.PCode = OpenMetaverse.PCode.Prim;
  1257. prim.PrimData.State = 0;
  1258. if (this.FlexiEntry)
  1259. {
  1260. prim.Flexible = new Primitive.FlexibleData();
  1261. prim.Flexible.Drag = this.FlexiDrag;
  1262. prim.Flexible.Force = new Vector3(this.FlexiForceX, this.FlexiForceY, this.FlexiForceZ);
  1263. prim.Flexible.Gravity = this.FlexiGravity;
  1264. prim.Flexible.Softness = this.FlexiSoftness;
  1265. prim.Flexible.Tension = this.FlexiTension;
  1266. prim.Flexible.Wind = this.FlexiWind;
  1267. }
  1268. if (this.LightEntry)
  1269. {
  1270. prim.Light = new Primitive.LightData();
  1271. prim.Light.Color = new Color4(this.LightColorR, this.LightColorG, this.LightColorB, this.LightColorA);
  1272. prim.Light.Cutoff = this.LightCutoff;
  1273. prim.Light.Falloff = this.LightFalloff;
  1274. prim.Light.Intensity = this.LightIntensity;
  1275. prim.Light.Radius = this.LightRadius;
  1276. }
  1277. prim.Textures = this.Textures;
  1278. prim.Properties = new Primitive.ObjectProperties();
  1279. prim.Properties.Name = "Object";
  1280. prim.Properties.Description = "";
  1281. prim.Properties.CreatorID = UUID.Zero;
  1282. prim.Properties.GroupID = UUID.Zero;
  1283. prim.Properties.OwnerID = UUID.Zero;
  1284. prim.Properties.Permissions = new Permissions();
  1285. prim.Properties.SalePrice = 10;
  1286. prim.Properties.SaleType = new SaleType();
  1287. return prim;
  1288. }
  1289. /// <summary>
  1290. /// Encapsulates a list of media entries.
  1291. /// </summary>
  1292. /// This class is necessary because we want to replace auto-serialization of MediaEntry with something more
  1293. /// OSD like and less vulnerable to change.
  1294. public class MediaList : List<MediaEntry>, IXmlSerializable
  1295. {
  1296. public const string MEDIA_TEXTURE_TYPE = "sl";
  1297. public MediaList() : base() {}
  1298. public MediaList(IEnumerable<MediaEntry> collection) : base(collection) {}
  1299. public MediaList(int capacity) : base(capacity) {}
  1300. public XmlSchema GetSchema()
  1301. {
  1302. return null;
  1303. }
  1304. public string ToXml()
  1305. {
  1306. lock (this)
  1307. {
  1308. using (StringWriter sw = new StringWriter())
  1309. {
  1310. using (XmlTextWriter xtw = new XmlTextWriter(sw))
  1311. {
  1312. xtw.WriteStartElement("OSMedia");
  1313. xtw.WriteAttributeString("type", MEDIA_TEXTURE_TYPE);
  1314. xtw.WriteAttributeString("version", "0.1");
  1315. OSDArray meArray = new OSDArray();
  1316. foreach (MediaEntry me in this)
  1317. {
  1318. OSD osd = (null == me ? new OSD() : me.GetOSD());
  1319. meArray.Add(osd);
  1320. }
  1321. xtw.WriteStartElement("OSData");
  1322. xtw.WriteRaw(OSDParser.SerializeLLSDXmlString(meArray));
  1323. xtw.WriteEndElement();
  1324. xtw.WriteEndElement();
  1325. xtw.Flush();
  1326. return sw.ToString();
  1327. }
  1328. }
  1329. }
  1330. }
  1331. public void WriteXml(XmlWriter writer)
  1332. {
  1333. writer.WriteRaw(ToXml());
  1334. }
  1335. public static MediaList FromXml(string rawXml)
  1336. {
  1337. MediaList ml = new MediaList();
  1338. ml.ReadXml(rawXml);
  1339. if(ml.Count == 0)
  1340. return null;
  1341. return ml;
  1342. }
  1343. public void ReadXml(string rawXml)
  1344. {
  1345. try
  1346. {
  1347. using (StringReader sr = new StringReader(rawXml))
  1348. {
  1349. using (XmlTextReader xtr = new XmlTextReader(sr))
  1350. {
  1351. xtr.MoveToContent();
  1352. string type = xtr.GetAttribute("type");
  1353. //m_log.DebugFormat("[MOAP]: Loaded media texture entry with type {0}", type);
  1354. if (type != MEDIA_TEXTURE_TYPE)
  1355. return;
  1356. xtr.ReadStartElement("OSMedia");
  1357. OSD osdp = OSDParser.DeserializeLLSDXml(xtr.ReadInnerXml());
  1358. if(osdp == null || !(osdp is OSDArray))
  1359. return;
  1360. OSDArray osdMeArray = osdp as OSDArray;
  1361. if(osdMeArray.Count == 0)
  1362. return;
  1363. foreach (OSD osdMe in osdMeArray)
  1364. {
  1365. MediaEntry me = (osdMe is OSDMap ? MediaEntry.FromOSD(osdMe) : new MediaEntry());
  1366. Add(me);
  1367. }
  1368. }
  1369. }
  1370. }
  1371. catch
  1372. {
  1373. m_log.Debug("PrimitiveBaseShape] error decoding MOAP xml" );
  1374. }
  1375. }
  1376. public void ReadXml(XmlReader reader)
  1377. {
  1378. if (reader.IsEmptyElement)
  1379. return;
  1380. ReadXml(reader.ReadInnerXml());
  1381. }
  1382. }
  1383. }
  1384. }