1
0

AvatarAppearance.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. */
  28. using libsecondlife;
  29. using libsecondlife.Packets;
  30. using OpenSim.Framework;
  31. namespace OpenSim.Region.Environment.Scenes
  32. {
  33. public class AvatarAppearance
  34. {
  35. protected LLUUID m_scenePresenceID;
  36. public LLUUID ScenePresenceID
  37. {
  38. get { return m_scenePresenceID; }
  39. set { m_scenePresenceID = value; }
  40. }
  41. protected int m_wearablesSerial = 1;
  42. public int WearablesSerial
  43. {
  44. get { return m_wearablesSerial; }
  45. set { m_wearablesSerial = value; }
  46. }
  47. protected byte[] m_visualParams;
  48. public byte[] VisualParams
  49. {
  50. get { return m_visualParams; }
  51. set { m_visualParams = value; }
  52. }
  53. protected AvatarWearable[] m_wearables;
  54. public AvatarWearable[] Wearables
  55. {
  56. get { return m_wearables; }
  57. set { m_wearables = value; }
  58. }
  59. protected LLObject.TextureEntry m_textureEntry;
  60. public LLObject.TextureEntry TextureEntry
  61. {
  62. get { return m_textureEntry; }
  63. set { m_textureEntry = value; }
  64. }
  65. protected float m_avatarHeight = 0;
  66. public float AvatarHeight
  67. {
  68. get { return m_avatarHeight; }
  69. set { m_avatarHeight = value; }
  70. }
  71. public AvatarAppearance()
  72. {
  73. }
  74. public AvatarAppearance(LLUUID avatarID, AvatarWearable[] wearables, byte[] visualParams)
  75. {
  76. m_scenePresenceID = avatarID;
  77. m_wearablesSerial = 1;
  78. m_wearables = wearables;
  79. m_visualParams = visualParams;
  80. m_textureEntry = GetDefaultTextureEntry();
  81. }
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. /// <param name="texture"></param>
  86. /// <param name="visualParam"></param>
  87. public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
  88. {
  89. LLObject.TextureEntry textureEnt = new LLObject.TextureEntry(texture, 0, texture.Length);
  90. m_textureEntry = textureEnt;
  91. for (int i = 0; i < visualParam.Length; i++)
  92. {
  93. m_visualParams[i] = visualParam[i].ParamValue;
  94. }
  95. // Teravus : Nifty AV Height Getting Maaaaagical formula. Oh how we love turning 0-255 into meters.
  96. // (float)m_visualParams[25] = Height
  97. // (float)m_visualParams[125] = LegLength
  98. m_avatarHeight = (1.50856f + (((float) m_visualParams[25]/255.0f)*(2.525506f - 1.50856f)))
  99. + (((float) m_visualParams[125]/255.0f)/1.5f);
  100. }
  101. /// <summary>
  102. ///
  103. /// </summary>
  104. /// <param name="avatar"></param>
  105. public void SendAppearanceToOtherAgent(ScenePresence avatar)
  106. {
  107. avatar.ControllingClient.SendAppearance(m_scenePresenceID, m_visualParams,
  108. m_textureEntry.ToBytes());
  109. }
  110. public void SetWearable(IClientAPI client, int wearableId, AvatarWearable wearable)
  111. {
  112. m_wearables[wearableId] = wearable;
  113. SendOwnWearables(client);
  114. }
  115. public void SendOwnWearables(IClientAPI ourClient)
  116. {
  117. ourClient.SendWearables(m_wearables, m_wearablesSerial++);
  118. }
  119. public static LLObject.TextureEntry GetDefaultTextureEntry()
  120. {
  121. LLObject.TextureEntry textu = new LLObject.TextureEntry(new LLUUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
  122. textu.CreateFace(0).TextureID = new LLUUID("00000000-0000-1111-9999-000000000012");
  123. textu.CreateFace(1).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  124. textu.CreateFace(2).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  125. textu.CreateFace(3).TextureID = new LLUUID("6522E74D-1660-4E7F-B601-6F48C1659A77");
  126. textu.CreateFace(4).TextureID = new LLUUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B");
  127. textu.CreateFace(5).TextureID = new LLUUID("00000000-0000-1111-9999-000000000010");
  128. textu.CreateFace(6).TextureID = new LLUUID("00000000-0000-1111-9999-000000000011");
  129. return textu;
  130. }
  131. }
  132. }