PrimitiveBaseShape.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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 OpenSim 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.Reflection;
  29. using System.Xml.Serialization;
  30. using libsecondlife;
  31. using log4net;
  32. namespace OpenSim.Framework
  33. {
  34. public enum ProfileShape : byte
  35. {
  36. Circle = 0,
  37. Square = 1,
  38. IsometricTriangle = 2,
  39. EquilateralTriangle = 3,
  40. RightTriangle = 4,
  41. HalfCircle = 5
  42. }
  43. public enum HollowShape : byte
  44. {
  45. Same = 0,
  46. Circle = 16,
  47. Square = 32,
  48. Triangle = 48
  49. }
  50. public enum PCodeEnum : byte
  51. {
  52. Primitive = 9,
  53. Avatar = 47,
  54. Grass = 95,
  55. NewTree = 111,
  56. ParticleSystem = 143,
  57. Tree = 255
  58. }
  59. public enum Extrusion : byte
  60. {
  61. Straight = 16,
  62. Curve1 = 32,
  63. Curve2 = 48,
  64. Flexible = 128
  65. }
  66. [Serializable]
  67. public class PrimitiveBaseShape
  68. {
  69. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  70. private static readonly LLObject.TextureEntry m_defaultTexture;
  71. private byte[] m_textureEntry;
  72. private ushort _pathBegin;
  73. private byte _pathCurve;
  74. private ushort _pathEnd;
  75. private sbyte _pathRadiusOffset;
  76. private byte _pathRevolutions;
  77. private byte _pathScaleX;
  78. private byte _pathScaleY;
  79. private byte _pathShearX;
  80. private byte _pathShearY;
  81. private sbyte _pathSkew;
  82. private sbyte _pathTaperX;
  83. private sbyte _pathTaperY;
  84. private sbyte _pathTwist;
  85. private sbyte _pathTwistBegin;
  86. private byte _pCode;
  87. private ushort _profileBegin;
  88. private ushort _profileEnd;
  89. private ushort _profileHollow;
  90. private LLVector3 _scale;
  91. private byte _state;
  92. private ProfileShape _profileShape;
  93. private HollowShape _hollowShape;
  94. // Sculpted
  95. [XmlIgnore] private LLUUID _sculptTexture = LLUUID.Zero;
  96. [XmlIgnore] private byte _sculptType = (byte)0;
  97. [XmlIgnore] private byte[] _sculptData = new byte[0];
  98. // Flexi
  99. [XmlIgnore] private int _flexiSoftness = 0;
  100. [XmlIgnore] private float _flexiTension = 0f;
  101. [XmlIgnore] private float _flexiDrag = 0f;
  102. [XmlIgnore] private float _flexiGravity = 0f;
  103. [XmlIgnore] private float _flexiWind = 0f;
  104. [XmlIgnore] private float _flexiForceX = 0f;
  105. [XmlIgnore] private float _flexiForceY = 0f;
  106. [XmlIgnore] private float _flexiForceZ = 0f;
  107. //Bright n sparkly
  108. [XmlIgnore] private float _lightColorR = 0f;
  109. [XmlIgnore] private float _lightColorG = 0f;
  110. [XmlIgnore] private float _lightColorB = 0f;
  111. [XmlIgnore] private float _lightColorA = 1f;
  112. [XmlIgnore] private float _lightRadius = 0f;
  113. [XmlIgnore] private float _lightCutoff = 0f;
  114. [XmlIgnore] private float _lightFalloff = 0f;
  115. [XmlIgnore] private float _lightIntensity = 1f;
  116. [XmlIgnore] private bool _flexiEntry = false;
  117. [XmlIgnore] private bool _lightEntry = false;
  118. [XmlIgnore] private bool _sculptEntry = false;
  119. public byte ProfileCurve
  120. {
  121. get { return (byte)((byte)HollowShape | (byte)ProfileShape); }
  122. set
  123. {
  124. // Handle hollow shape component
  125. byte hollowShapeByte = (byte)(value & 0xf0);
  126. if (!Enum.IsDefined(typeof(HollowShape), hollowShapeByte))
  127. {
  128. m_log.WarnFormat(
  129. "[SHAPE]: Attempt to set a ProfileCurve with a hollow shape value of {0}, which isn't a valid enum. Replacing with default shape.",
  130. hollowShapeByte);
  131. this._hollowShape = HollowShape.Same;
  132. }
  133. else
  134. {
  135. this._hollowShape = (HollowShape)hollowShapeByte;
  136. }
  137. // Handle profile shape component
  138. byte profileShapeByte = (byte)(value & 0xf);
  139. if (!Enum.IsDefined(typeof(ProfileShape), profileShapeByte))
  140. {
  141. m_log.WarnFormat(
  142. "[SHAPE]: Attempt to set a ProfileCurve with a profile shape value of {0}, which isn't a valid enum. Replacing with square.",
  143. profileShapeByte);
  144. this._profileShape = ProfileShape.Square;
  145. }
  146. else
  147. {
  148. this._profileShape = (ProfileShape)profileShapeByte;
  149. }
  150. }
  151. }
  152. static PrimitiveBaseShape()
  153. {
  154. m_defaultTexture =
  155. new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
  156. }
  157. public PrimitiveBaseShape()
  158. {
  159. PCode = (byte) PCodeEnum.Primitive;
  160. ExtraParams = new byte[1];
  161. Textures = m_defaultTexture;
  162. }
  163. [XmlIgnore]
  164. public LLObject.TextureEntry Textures
  165. {
  166. get { return new LLObject.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); }
  167. set { m_textureEntry = value.ToBytes(); }
  168. }
  169. public byte[] TextureEntry
  170. {
  171. get { return m_textureEntry; }
  172. set
  173. {
  174. if (value == null)
  175. m_textureEntry = new byte[1];
  176. else
  177. m_textureEntry = value;
  178. }
  179. }
  180. public static PrimitiveBaseShape Default
  181. {
  182. get
  183. {
  184. PrimitiveBaseShape boxShape = CreateBox();
  185. boxShape.SetScale(0.5f);
  186. return boxShape;
  187. }
  188. }
  189. public static PrimitiveBaseShape Create()
  190. {
  191. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  192. return shape;
  193. }
  194. public static PrimitiveBaseShape CreateBox()
  195. {
  196. PrimitiveBaseShape shape = Create();
  197. shape._pathCurve = (byte) Extrusion.Straight;
  198. shape._profileShape = ProfileShape.Square;
  199. shape._pathScaleX = 100;
  200. shape._pathScaleY = 100;
  201. return shape;
  202. }
  203. public static PrimitiveBaseShape CreateCylinder()
  204. {
  205. PrimitiveBaseShape shape = Create();
  206. shape._pathCurve = (byte) Extrusion.Curve1;
  207. shape._profileShape = ProfileShape.Square;
  208. shape._pathScaleX = 100;
  209. shape._pathScaleY = 100;
  210. return shape;
  211. }
  212. public void SetScale(float side)
  213. {
  214. _scale = new LLVector3(side, side, side);
  215. }
  216. public void SetHeigth(float heigth)
  217. {
  218. _scale.Z = heigth;
  219. }
  220. public void SetRadius(float radius)
  221. {
  222. _scale.X = _scale.Y = radius * 2f;
  223. }
  224. // TODO: void returns need to change of course
  225. public virtual void GetMesh()
  226. {
  227. }
  228. public PrimitiveBaseShape Copy()
  229. {
  230. return (PrimitiveBaseShape) MemberwiseClone();
  231. }
  232. public static PrimitiveBaseShape CreateCylinder(float radius, float heigth)
  233. {
  234. PrimitiveBaseShape shape = CreateCylinder();
  235. shape.SetHeigth(heigth);
  236. shape.SetRadius(radius);
  237. return shape;
  238. }
  239. public void SetPathRange(LLVector3 pathRange)
  240. {
  241. _pathBegin = LLObject.PackBeginCut(pathRange.X);
  242. _pathEnd = LLObject.PackEndCut(pathRange.Y);
  243. }
  244. public void SetSculptData(byte sculptType, LLUUID SculptTextureUUID)
  245. {
  246. _sculptType = sculptType;
  247. _sculptTexture = SculptTextureUUID;
  248. }
  249. public void SetProfileRange(LLVector3 profileRange)
  250. {
  251. _profileBegin = LLObject.PackBeginCut(profileRange.X);
  252. _profileEnd = LLObject.PackEndCut(profileRange.Y);
  253. }
  254. public byte[] ExtraParams
  255. {
  256. get
  257. {
  258. return ExtraParamsToBytes();
  259. }
  260. set
  261. {
  262. ReadInExtraParamsBytes(value);
  263. }
  264. }
  265. public ushort PathBegin {
  266. get {
  267. return _pathBegin;
  268. }
  269. set {
  270. _pathBegin = value;
  271. }
  272. }
  273. public byte PathCurve {
  274. get {
  275. return _pathCurve;
  276. }
  277. set {
  278. _pathCurve = value;
  279. }
  280. }
  281. public ushort PathEnd {
  282. get {
  283. return _pathEnd;
  284. }
  285. set {
  286. _pathEnd = value;
  287. }
  288. }
  289. public sbyte PathRadiusOffset {
  290. get {
  291. return _pathRadiusOffset;
  292. }
  293. set {
  294. _pathRadiusOffset = value;
  295. }
  296. }
  297. public byte PathRevolutions {
  298. get {
  299. return _pathRevolutions;
  300. }
  301. set {
  302. _pathRevolutions = value;
  303. }
  304. }
  305. public byte PathScaleX {
  306. get {
  307. return _pathScaleX;
  308. }
  309. set {
  310. _pathScaleX = value;
  311. }
  312. }
  313. public byte PathScaleY {
  314. get {
  315. return _pathScaleY;
  316. }
  317. set {
  318. _pathScaleY = value;
  319. }
  320. }
  321. public byte PathShearX {
  322. get {
  323. return _pathShearX;
  324. }
  325. set {
  326. _pathShearX = value;
  327. }
  328. }
  329. public byte PathShearY {
  330. get {
  331. return _pathShearY;
  332. }
  333. set {
  334. _pathShearY = value;
  335. }
  336. }
  337. public sbyte PathSkew {
  338. get {
  339. return _pathSkew;
  340. }
  341. set {
  342. _pathSkew = value;
  343. }
  344. }
  345. public sbyte PathTaperX {
  346. get {
  347. return _pathTaperX;
  348. }
  349. set {
  350. _pathTaperX = value;
  351. }
  352. }
  353. public sbyte PathTaperY {
  354. get {
  355. return _pathTaperY;
  356. }
  357. set {
  358. _pathTaperY = value;
  359. }
  360. }
  361. public sbyte PathTwist {
  362. get {
  363. return _pathTwist;
  364. }
  365. set {
  366. _pathTwist = value;
  367. }
  368. }
  369. public sbyte PathTwistBegin {
  370. get {
  371. return _pathTwistBegin;
  372. }
  373. set {
  374. _pathTwistBegin = value;
  375. }
  376. }
  377. public byte PCode {
  378. get {
  379. return _pCode;
  380. }
  381. set {
  382. _pCode = value;
  383. }
  384. }
  385. public ushort ProfileBegin {
  386. get {
  387. return _profileBegin;
  388. }
  389. set {
  390. _profileBegin = value;
  391. }
  392. }
  393. public ushort ProfileEnd {
  394. get {
  395. return _profileEnd;
  396. }
  397. set {
  398. _profileEnd = value;
  399. }
  400. }
  401. public ushort ProfileHollow {
  402. get {
  403. return _profileHollow;
  404. }
  405. set {
  406. _profileHollow = value;
  407. }
  408. }
  409. public LLVector3 Scale {
  410. get {
  411. return _scale;
  412. }
  413. set {
  414. _scale = value;
  415. }
  416. }
  417. public byte State {
  418. get {
  419. return _state;
  420. }
  421. set {
  422. _state = value;
  423. }
  424. }
  425. public ProfileShape ProfileShape {
  426. get {
  427. return _profileShape;
  428. }
  429. set {
  430. _profileShape = value;
  431. }
  432. }
  433. public HollowShape HollowShape {
  434. get {
  435. return _hollowShape;
  436. }
  437. set {
  438. _hollowShape = value;
  439. }
  440. }
  441. public LLUUID SculptTexture {
  442. get {
  443. return _sculptTexture;
  444. }
  445. set {
  446. _sculptTexture = value;
  447. }
  448. }
  449. public byte SculptType {
  450. get {
  451. return _sculptType;
  452. }
  453. set {
  454. _sculptType = value;
  455. }
  456. }
  457. public byte[] SculptData {
  458. get {
  459. return _sculptData;
  460. }
  461. set {
  462. _sculptData = value;
  463. }
  464. }
  465. public int FlexiSoftness {
  466. get {
  467. return _flexiSoftness;
  468. }
  469. set {
  470. _flexiSoftness = value;
  471. }
  472. }
  473. public float FlexiTension {
  474. get {
  475. return _flexiTension;
  476. }
  477. set {
  478. _flexiTension = value;
  479. }
  480. }
  481. public float FlexiDrag {
  482. get {
  483. return _flexiDrag;
  484. }
  485. set {
  486. _flexiDrag = value;
  487. }
  488. }
  489. public float FlexiGravity {
  490. get {
  491. return _flexiGravity;
  492. }
  493. set {
  494. _flexiGravity = value;
  495. }
  496. }
  497. public float FlexiWind {
  498. get {
  499. return _flexiWind;
  500. }
  501. set {
  502. _flexiWind = value;
  503. }
  504. }
  505. public float FlexiForceX {
  506. get {
  507. return _flexiForceX;
  508. }
  509. set {
  510. _flexiForceX = value;
  511. }
  512. }
  513. public float FlexiForceY {
  514. get {
  515. return _flexiForceY;
  516. }
  517. set {
  518. _flexiForceY = value;
  519. }
  520. }
  521. public float FlexiForceZ {
  522. get {
  523. return _flexiForceZ;
  524. }
  525. set {
  526. _flexiForceZ = value;
  527. }
  528. }
  529. public float LightColorR {
  530. get {
  531. return _lightColorR;
  532. }
  533. set {
  534. _lightColorR = value;
  535. }
  536. }
  537. public float LightColorG {
  538. get {
  539. return _lightColorG;
  540. }
  541. set {
  542. _lightColorG = value;
  543. }
  544. }
  545. public float LightColorB {
  546. get {
  547. return _lightColorB;
  548. }
  549. set {
  550. _lightColorB = value;
  551. }
  552. }
  553. public float LightColorA {
  554. get {
  555. return _lightColorA;
  556. }
  557. set {
  558. _lightColorA = value;
  559. }
  560. }
  561. public float LightRadius {
  562. get {
  563. return _lightRadius;
  564. }
  565. set {
  566. _lightRadius = value;
  567. }
  568. }
  569. public float LightCutoff {
  570. get {
  571. return _lightCutoff;
  572. }
  573. set {
  574. _lightCutoff = value;
  575. }
  576. }
  577. public float LightFalloff {
  578. get {
  579. return _lightFalloff;
  580. }
  581. set {
  582. _lightFalloff = value;
  583. }
  584. }
  585. public float LightIntensity {
  586. get {
  587. return _lightIntensity;
  588. }
  589. set {
  590. _lightIntensity = value;
  591. }
  592. }
  593. public bool FlexiEntry {
  594. get {
  595. return _flexiEntry;
  596. }
  597. set {
  598. _flexiEntry = value;
  599. }
  600. }
  601. public bool LightEntry {
  602. get {
  603. return _lightEntry;
  604. }
  605. set {
  606. _lightEntry = value;
  607. }
  608. }
  609. public bool SculptEntry {
  610. get {
  611. return _sculptEntry;
  612. }
  613. set {
  614. _sculptEntry = value;
  615. }
  616. }
  617. public byte[] ExtraParamsToBytes()
  618. {
  619. ushort FlexiEP = 0x10;
  620. ushort LightEP = 0x20;
  621. ushort SculptEP = 0x30;
  622. int i = 0;
  623. uint TotalBytesLength = 1; // ExtraParamsNum
  624. uint ExtraParamsNum = 0;
  625. if (_flexiEntry)
  626. {
  627. ExtraParamsNum++;
  628. TotalBytesLength += 16;// data
  629. TotalBytesLength += 2 + 4; // type
  630. }
  631. if (_lightEntry)
  632. {
  633. ExtraParamsNum++;
  634. TotalBytesLength += 16;// data
  635. TotalBytesLength += 2 + 4; // type
  636. }
  637. if (_sculptEntry)
  638. {
  639. ExtraParamsNum++;
  640. TotalBytesLength += 17;// data
  641. TotalBytesLength += 2 + 4; // type
  642. }
  643. byte[] returnbytes = new byte[TotalBytesLength];
  644. // uint paramlength = ExtraParamsNum;
  645. // Stick in the number of parameters
  646. returnbytes[i++] = (byte)ExtraParamsNum;
  647. if (_flexiEntry)
  648. {
  649. byte[] FlexiData = GetFlexiBytes();
  650. returnbytes[i++] = (byte)(FlexiEP % 256);
  651. returnbytes[i++] = (byte)((FlexiEP >> 8) % 256);
  652. returnbytes[i++] = (byte)(FlexiData.Length % 256);
  653. returnbytes[i++] = (byte)((FlexiData.Length >> 8) % 256);
  654. returnbytes[i++] = (byte)((FlexiData.Length >> 16) % 256);
  655. returnbytes[i++] = (byte)((FlexiData.Length >> 24) % 256);
  656. Array.Copy(FlexiData, 0, returnbytes, i, FlexiData.Length);
  657. i += FlexiData.Length;
  658. }
  659. if (_lightEntry)
  660. {
  661. byte[] LightData = GetLightBytes();
  662. returnbytes[i++] = (byte)(LightEP % 256);
  663. returnbytes[i++] = (byte)((LightEP >> 8) % 256);
  664. returnbytes[i++] = (byte)(LightData.Length % 256);
  665. returnbytes[i++] = (byte)((LightData.Length >> 8) % 256);
  666. returnbytes[i++] = (byte)((LightData.Length >> 16) % 256);
  667. returnbytes[i++] = (byte)((LightData.Length >> 24) % 256);
  668. Array.Copy(LightData, 0, returnbytes, i, LightData.Length);
  669. i += LightData.Length;
  670. }
  671. if (_sculptEntry)
  672. {
  673. byte[] SculptData = GetSculptBytes();
  674. returnbytes[i++] = (byte)(SculptEP % 256);
  675. returnbytes[i++] = (byte)((SculptEP >> 8) % 256);
  676. returnbytes[i++] = (byte)(SculptData.Length % 256);
  677. returnbytes[i++] = (byte)((SculptData.Length >> 8) % 256);
  678. returnbytes[i++] = (byte)((SculptData.Length >> 16) % 256);
  679. returnbytes[i++] = (byte)((SculptData.Length >> 24) % 256);
  680. Array.Copy(SculptData, 0, returnbytes, i, SculptData.Length);
  681. i += SculptData.Length;
  682. }
  683. if (!_flexiEntry && !_lightEntry && !_sculptEntry)
  684. {
  685. byte[] returnbyte = new byte[1];
  686. returnbyte[0] = 0;
  687. return returnbyte;
  688. }
  689. return returnbytes;
  690. //m_log.Info("[EXTRAPARAMS]: Length = " + m_shape.ExtraParams.Length.ToString());
  691. }
  692. public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data)
  693. {
  694. const ushort FlexiEP = 0x10;
  695. const ushort LightEP = 0x20;
  696. const ushort SculptEP = 0x30;
  697. switch (type)
  698. {
  699. case FlexiEP:
  700. if (!inUse)
  701. {
  702. _flexiEntry = false;
  703. return;
  704. }
  705. ReadFlexiData(data, 0);
  706. break;
  707. case LightEP:
  708. if (!inUse)
  709. {
  710. _lightEntry = false;
  711. return;
  712. }
  713. ReadLightData(data, 0);
  714. break;
  715. case SculptEP:
  716. if (!inUse)
  717. {
  718. _sculptEntry = false;
  719. return;
  720. }
  721. ReadSculptData(data, 0);
  722. break;
  723. }
  724. }
  725. public void ReadInExtraParamsBytes(byte[] data)
  726. {
  727. if (data == null)
  728. return;
  729. const ushort FlexiEP = 0x10;
  730. const ushort LightEP = 0x20;
  731. const ushort SculptEP = 0x30;
  732. bool lGotFlexi = false;
  733. bool lGotLight = false;
  734. bool lGotSculpt = false;
  735. int i = 0;
  736. byte extraParamCount = 0;
  737. if (data.Length > 0)
  738. {
  739. extraParamCount = data[i++];
  740. }
  741. for (int k = 0; k < extraParamCount; k++)
  742. {
  743. ushort epType = Helpers.BytesToUInt16(data, i);
  744. i += 2;
  745. // uint paramLength = Helpers.BytesToUIntBig(data, i);
  746. i += 4;
  747. switch (epType)
  748. {
  749. case FlexiEP:
  750. ReadFlexiData(data, i);
  751. i += 16;
  752. lGotFlexi = true;
  753. break;
  754. case LightEP:
  755. ReadLightData(data, i);
  756. i += 16;
  757. lGotLight = true;
  758. break;
  759. case SculptEP:
  760. ReadSculptData(data, i);
  761. i += 17;
  762. lGotSculpt = true;
  763. break;
  764. }
  765. }
  766. if (!lGotFlexi)
  767. _flexiEntry = false;
  768. if (!lGotLight)
  769. _lightEntry = false;
  770. if (!lGotSculpt)
  771. _sculptEntry = false;
  772. }
  773. public void ReadSculptData(byte[] data, int pos)
  774. {
  775. byte[] SculptTextureUUID = new byte[16];
  776. LLUUID SculptUUID = LLUUID.Zero;
  777. byte SculptTypel = data[16+pos];
  778. if (data.Length+pos >= 17)
  779. {
  780. _sculptEntry = true;
  781. SculptTextureUUID = new byte[16];
  782. SculptTypel = data[16 + pos];
  783. Array.Copy(data, pos, SculptTextureUUID,0, 16);
  784. SculptUUID = new LLUUID(SculptTextureUUID, 0);
  785. }
  786. else
  787. {
  788. _sculptEntry = false;
  789. SculptUUID = LLUUID.Zero;
  790. SculptTypel = 0x00;
  791. }
  792. if (_sculptEntry)
  793. {
  794. if (_sculptType != (byte)1 && _sculptType != (byte)2 && _sculptType != (byte)3 && _sculptType != (byte)4)
  795. _sculptType = 4;
  796. }
  797. _sculptTexture = SculptUUID;
  798. _sculptType = SculptTypel;
  799. //m_log.Info("[SCULPT]:" + SculptUUID.ToString());
  800. }
  801. public byte[] GetSculptBytes()
  802. {
  803. byte[] data = new byte[17];
  804. _sculptTexture.GetBytes().CopyTo(data, 0);
  805. data[16] = (byte)_sculptType;
  806. return data;
  807. }
  808. public void ReadFlexiData(byte[] data, int pos)
  809. {
  810. if (data.Length-pos >= 16)
  811. {
  812. _flexiEntry = true;
  813. _flexiSoftness = ((data[pos] & 0x80) >> 6) | ((data[pos + 1] & 0x80) >> 7);
  814. _flexiTension = (float)(data[pos++] & 0x7F) / 10.0f;
  815. _flexiDrag = (float)(data[pos++] & 0x7F) / 10.0f;
  816. _flexiGravity = (float)(data[pos++] / 10.0f) - 10.0f;
  817. _flexiWind = (float)data[pos++] / 10.0f;
  818. LLVector3 lForce = new LLVector3(data, pos);
  819. _flexiForceX = lForce.X;
  820. _flexiForceY = lForce.Y;
  821. _flexiForceZ = lForce.Z;
  822. }
  823. else
  824. {
  825. _flexiEntry = false;
  826. _flexiSoftness = 0;
  827. _flexiTension = 0.0f;
  828. _flexiDrag = 0.0f;
  829. _flexiGravity = 0.0f;
  830. _flexiWind = 0.0f;
  831. _flexiForceX = 0f;
  832. _flexiForceY = 0f;
  833. _flexiForceZ = 0f;
  834. }
  835. }
  836. public byte[] GetFlexiBytes()
  837. {
  838. byte[] data = new byte[16];
  839. int i = 0;
  840. // Softness is packed in the upper bits of tension and drag
  841. data[i] = (byte)((_flexiSoftness & 2) << 6);
  842. data[i + 1] = (byte)((_flexiSoftness & 1) << 7);
  843. data[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F);
  844. data[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F);
  845. data[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f);
  846. data[i++] = (byte)(_flexiWind * 10.01f);
  847. LLVector3 lForce = new LLVector3(_flexiForceX, _flexiForceY, _flexiForceZ);
  848. lForce.GetBytes().CopyTo(data, i);
  849. return data;
  850. }
  851. public void ReadLightData(byte[] data, int pos)
  852. {
  853. if (data.Length - pos >= 16)
  854. {
  855. _lightEntry = true;
  856. LLColor lColor = new LLColor(data, pos, false);
  857. _lightIntensity = lColor.A;
  858. _lightColorA = 1f;
  859. _lightColorR = lColor.R;
  860. _lightColorG = lColor.G;
  861. _lightColorB = lColor.B;
  862. _lightRadius = Helpers.BytesToFloat(data, pos + 4);
  863. _lightCutoff = Helpers.BytesToFloat(data, pos + 8);
  864. _lightFalloff = Helpers.BytesToFloat(data, pos + 12);
  865. }
  866. else
  867. {
  868. _lightEntry = false;
  869. _lightColorA = 1f;
  870. _lightColorR = 0f;
  871. _lightColorG = 0f;
  872. _lightColorB = 0f;
  873. _lightRadius = 0f;
  874. _lightCutoff = 0f;
  875. _lightFalloff = 0f;
  876. _lightIntensity = 0f;
  877. }
  878. }
  879. public byte[] GetLightBytes()
  880. {
  881. byte[] data = new byte[16];
  882. // Alpha channel in color is intensity
  883. LLColor tmpColor = new LLColor(_lightColorR,_lightColorG,_lightColorB,_lightIntensity);
  884. tmpColor.GetBytes().CopyTo(data, 0);
  885. Helpers.FloatToBytes(_lightRadius).CopyTo(data, 4);
  886. Helpers.FloatToBytes(_lightCutoff).CopyTo(data, 8);
  887. Helpers.FloatToBytes(_lightFalloff).CopyTo(data, 12);
  888. return data;
  889. }
  890. }
  891. }