PrimitiveBaseShape.cs 28 KB

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