PrimitiveBaseShape.cs 50 KB

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