AvatarAppearance.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.Runtime.Serialization;
  29. using System.Security.Permissions;
  30. using libsecondlife;
  31. using libsecondlife.Packets;
  32. using OpenSim.Framework;
  33. namespace OpenSim.Region.Environment.Scenes
  34. {
  35. [Serializable]
  36. public class AvatarAppearance : ISerializable
  37. {
  38. protected LLUUID m_scenePresenceID;
  39. public LLUUID ScenePresenceID
  40. {
  41. get { return m_scenePresenceID; }
  42. set { m_scenePresenceID = value; }
  43. }
  44. protected int m_wearablesSerial = 1;
  45. public int WearablesSerial
  46. {
  47. get { return m_wearablesSerial; }
  48. set { m_wearablesSerial = value; }
  49. }
  50. protected byte[] m_visualParams;
  51. public byte[] VisualParams
  52. {
  53. get { return m_visualParams; }
  54. set { m_visualParams = value; }
  55. }
  56. protected AvatarWearable[] m_wearables;
  57. public AvatarWearable[] Wearables
  58. {
  59. get { return m_wearables; }
  60. set { m_wearables = value; }
  61. }
  62. protected LLObject.TextureEntry m_textureEntry;
  63. public LLObject.TextureEntry TextureEntry
  64. {
  65. get { return m_textureEntry; }
  66. set { m_textureEntry = value; }
  67. }
  68. protected float m_avatarHeight = 0;
  69. public float AvatarHeight
  70. {
  71. get { return m_avatarHeight; }
  72. set { m_avatarHeight = value; }
  73. }
  74. public AvatarAppearance()
  75. {
  76. }
  77. public AvatarAppearance(LLUUID avatarID, AvatarWearable[] wearables, byte[] visualParams)
  78. {
  79. m_scenePresenceID = avatarID;
  80. m_wearablesSerial = 1;
  81. m_wearables = wearables;
  82. m_visualParams = visualParams;
  83. m_textureEntry = GetDefaultTextureEntry();
  84. }
  85. /// <summary>
  86. ///
  87. /// </summary>
  88. /// <param name="texture"></param>
  89. /// <param name="visualParam"></param>
  90. public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
  91. {
  92. LLObject.TextureEntry textureEnt = new LLObject.TextureEntry(texture, 0, texture.Length);
  93. m_textureEntry = textureEnt;
  94. for (int i = 0; i < visualParam.Length; i++)
  95. {
  96. m_visualParams[i] = visualParam[i].ParamValue;
  97. }
  98. // Teravus : Nifty AV Height Getting Maaaaagical formula. Oh how we love turning 0-255 into meters.
  99. // (float)m_visualParams[25] = Height
  100. // (float)m_visualParams[125] = LegLength
  101. m_avatarHeight = (1.50856f + (((float) m_visualParams[25]/255.0f)*(2.525506f - 1.50856f)))
  102. + (((float) m_visualParams[125]/255.0f)/1.5f);
  103. }
  104. /// <summary>
  105. ///
  106. /// </summary>
  107. /// <param name="avatar"></param>
  108. public void SendAppearanceToOtherAgent(ScenePresence avatar)
  109. {
  110. avatar.ControllingClient.SendAppearance(m_scenePresenceID, m_visualParams,
  111. m_textureEntry.ToBytes());
  112. }
  113. public void SetWearable(IClientAPI client, int wearableId, AvatarWearable wearable)
  114. {
  115. m_wearables[wearableId] = wearable;
  116. SendOwnWearables(client);
  117. }
  118. public void SendOwnWearables(IClientAPI ourClient)
  119. {
  120. ourClient.SendWearables(m_wearables, m_wearablesSerial++);
  121. }
  122. public static LLObject.TextureEntry GetDefaultTextureEntry()
  123. {
  124. LLObject.TextureEntry textu = new LLObject.TextureEntry(new LLUUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
  125. textu.CreateFace(0).TextureID = new LLUUID("00000000-0000-1111-9999-000000000012");
  126. textu.CreateFace(1).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  127. textu.CreateFace(2).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  128. textu.CreateFace(3).TextureID = new LLUUID("6522E74D-1660-4E7F-B601-6F48C1659A77");
  129. textu.CreateFace(4).TextureID = new LLUUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B");
  130. textu.CreateFace(5).TextureID = new LLUUID("00000000-0000-1111-9999-000000000010");
  131. textu.CreateFace(6).TextureID = new LLUUID("00000000-0000-1111-9999-000000000011");
  132. return textu;
  133. }
  134. protected AvatarAppearance(SerializationInfo info, StreamingContext context)
  135. {
  136. //System.Console.WriteLine("AvatarAppearance Deserialize BGN");
  137. if (info == null)
  138. {
  139. throw new ArgumentNullException("info");
  140. }
  141. m_scenePresenceID = new LLUUID((Guid)info.GetValue("m_scenePresenceID", typeof(Guid)));
  142. m_wearablesSerial = (int)info.GetValue("m_wearablesSerial", typeof(int));
  143. m_visualParams = (byte[])info.GetValue("m_visualParams", typeof(byte[]));
  144. m_wearables = (AvatarWearable[])info.GetValue("m_wearables", typeof(AvatarWearable[]));
  145. byte[] m_textureEntry_work = (byte[])info.GetValue("m_textureEntry", typeof(byte[]));
  146. m_textureEntry = new LLObject.TextureEntry(m_textureEntry_work, 0, m_textureEntry_work.Length);
  147. m_avatarHeight = (float)info.GetValue("m_avatarHeight", typeof(float));
  148. //System.Console.WriteLine("AvatarAppearance Deserialize END");
  149. }
  150. [SecurityPermission(SecurityAction.LinkDemand,
  151. Flags = SecurityPermissionFlag.SerializationFormatter)]
  152. public virtual void GetObjectData(
  153. SerializationInfo info, StreamingContext context)
  154. {
  155. if (info == null)
  156. {
  157. throw new ArgumentNullException("info");
  158. }
  159. info.AddValue("m_scenePresenceID", m_scenePresenceID.UUID);
  160. info.AddValue("m_wearablesSerial", m_wearablesSerial);
  161. info.AddValue("m_visualParams", m_visualParams);
  162. info.AddValue("m_wearables", m_wearables);
  163. info.AddValue("m_textureEntry", m_textureEntry.ToBytes());
  164. info.AddValue("m_avatarHeight", m_avatarHeight);
  165. }
  166. }
  167. }