PrimitiveBaseShape.cs 50 KB

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