PrimitiveBaseShape.cs 47 KB

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