PrimitiveBaseShape.cs 29 KB

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