AvatarAppearance.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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.Collections;
  29. using System.Collections.Generic;
  30. using System.Runtime.Serialization;
  31. using System.Security.Permissions;
  32. using libsecondlife;
  33. using libsecondlife.Packets;
  34. using OpenSim.Framework;
  35. namespace OpenSim.Framework
  36. {
  37. [Serializable]
  38. public class AvatarAppearance : ISerializable
  39. {
  40. // these are guessed at by the list here -
  41. // http://wiki.secondlife.com/wiki/Avatar_Appearance. We'll
  42. // correct them over time for when were are wrong.
  43. public readonly static int BODY = 0;
  44. public readonly static int SKIN = 1;
  45. public readonly static int HAIR = 2;
  46. public readonly static int EYES = 3;
  47. public readonly static int SHIRT = 4;
  48. public readonly static int PANTS = 5;
  49. public readonly static int SHOES = 6;
  50. public readonly static int SOCKS = 7;
  51. public readonly static int JACKET = 8;
  52. public readonly static int GLOVES = 9;
  53. public readonly static int UNDERSHIRT = 10;
  54. public readonly static int UNDERPANTS = 11;
  55. public readonly static int SKIRT = 12;
  56. private readonly static int MAX_WEARABLES = 13;
  57. private static LLUUID BODY_ASSET = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
  58. private static LLUUID BODY_ITEM = new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9");
  59. private static LLUUID SKIN_ASSET = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb");
  60. private static LLUUID SKIN_ITEM = new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9");
  61. private static LLUUID SHIRT_ASSET = new LLUUID("00000000-38f9-1111-024e-222222111110");
  62. private static LLUUID SHIRT_ITEM = new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000");
  63. private static LLUUID PANTS_ASSET = new LLUUID("00000000-38f9-1111-024e-222222111120");
  64. private static LLUUID PANTS_ITEM = new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111");
  65. public readonly static int VISUALPARAM_COUNT = 218;
  66. protected LLUUID m_owner;
  67. public LLUUID Owner
  68. {
  69. get { return m_owner; }
  70. set { m_owner = value; }
  71. }
  72. protected int m_serial = 1;
  73. public int Serial
  74. {
  75. get { return m_serial; }
  76. set { m_serial = value; }
  77. }
  78. protected byte[] m_visualparams;
  79. public byte[] VisualParams
  80. {
  81. get { return m_visualparams; }
  82. set { m_visualparams = value; }
  83. }
  84. protected AvatarWearable[] m_wearables;
  85. public AvatarWearable[] Wearables
  86. {
  87. get { return m_wearables; }
  88. set { m_wearables = value; }
  89. }
  90. public LLUUID BodyItem {
  91. get { return m_wearables[BODY].ItemID; }
  92. set { m_wearables[BODY].ItemID = value; }
  93. }
  94. public LLUUID BodyAsset {
  95. get { return m_wearables[BODY].AssetID; }
  96. set { m_wearables[BODY].AssetID = value; }
  97. }
  98. public LLUUID SkinItem {
  99. get { return m_wearables[SKIN].ItemID; }
  100. set { m_wearables[SKIN].ItemID = value; }
  101. }
  102. public LLUUID SkinAsset {
  103. get { return m_wearables[SKIN].AssetID; }
  104. set { m_wearables[SKIN].AssetID = value; }
  105. }
  106. public LLUUID HairItem {
  107. get { return m_wearables[HAIR].ItemID; }
  108. set { m_wearables[HAIR].ItemID = value; }
  109. }
  110. public LLUUID HairAsset {
  111. get { return m_wearables[HAIR].AssetID; }
  112. set { m_wearables[HAIR].AssetID = value; }
  113. }
  114. public LLUUID EyesItem {
  115. get { return m_wearables[EYES].ItemID; }
  116. set { m_wearables[EYES].ItemID = value; }
  117. }
  118. public LLUUID EyesAsset {
  119. get { return m_wearables[EYES].AssetID; }
  120. set { m_wearables[EYES].AssetID = value; }
  121. }
  122. public LLUUID ShirtItem {
  123. get { return m_wearables[SHIRT].ItemID; }
  124. set { m_wearables[SHIRT].ItemID = value; }
  125. }
  126. public LLUUID ShirtAsset {
  127. get { return m_wearables[SHIRT].AssetID; }
  128. set { m_wearables[SHIRT].AssetID = value; }
  129. }
  130. public LLUUID PantsItem {
  131. get { return m_wearables[PANTS].ItemID; }
  132. set { m_wearables[PANTS].ItemID = value; }
  133. }
  134. public LLUUID PantsAsset {
  135. get { return m_wearables[PANTS].AssetID; }
  136. set { m_wearables[PANTS].AssetID = value; }
  137. }
  138. public LLUUID ShoesItem {
  139. get { return m_wearables[SHOES].ItemID; }
  140. set { m_wearables[SHOES].ItemID = value; }
  141. }
  142. public LLUUID ShoesAsset {
  143. get { return m_wearables[SHOES].AssetID; }
  144. set { m_wearables[SHOES].AssetID = value; }
  145. }
  146. public LLUUID SocksItem {
  147. get { return m_wearables[SOCKS].ItemID; }
  148. set { m_wearables[SOCKS].ItemID = value; }
  149. }
  150. public LLUUID SocksAsset {
  151. get { return m_wearables[SOCKS].AssetID; }
  152. set { m_wearables[SOCKS].AssetID = value; }
  153. }
  154. public LLUUID JacketItem {
  155. get { return m_wearables[JACKET].ItemID; }
  156. set { m_wearables[JACKET].ItemID = value; }
  157. }
  158. public LLUUID JacketAsset {
  159. get { return m_wearables[JACKET].AssetID; }
  160. set { m_wearables[JACKET].AssetID = value; }
  161. }
  162. public LLUUID GlovesItem {
  163. get { return m_wearables[GLOVES].ItemID; }
  164. set { m_wearables[GLOVES].ItemID = value; }
  165. }
  166. public LLUUID GlovesAsset {
  167. get { return m_wearables[GLOVES].AssetID; }
  168. set { m_wearables[GLOVES].AssetID = value; }
  169. }
  170. public LLUUID UnderShirtItem {
  171. get { return m_wearables[UNDERSHIRT].ItemID; }
  172. set { m_wearables[UNDERSHIRT].ItemID = value; }
  173. }
  174. public LLUUID UnderShirtAsset {
  175. get { return m_wearables[UNDERSHIRT].AssetID; }
  176. set { m_wearables[UNDERSHIRT].AssetID = value; }
  177. }
  178. public LLUUID UnderPantsItem {
  179. get { return m_wearables[UNDERPANTS].ItemID; }
  180. set { m_wearables[UNDERPANTS].ItemID = value; }
  181. }
  182. public LLUUID UnderPantsAsset {
  183. get { return m_wearables[UNDERPANTS].AssetID; }
  184. set { m_wearables[UNDERPANTS].AssetID = value; }
  185. }
  186. public LLUUID SkirtItem {
  187. get { return m_wearables[SKIRT].ItemID; }
  188. set { m_wearables[SKIRT].ItemID = value; }
  189. }
  190. public LLUUID SkirtAsset {
  191. get { return m_wearables[SKIRT].AssetID; }
  192. set { m_wearables[SKIRT].AssetID = value; }
  193. }
  194. public void SetDefaultWearables()
  195. {
  196. m_wearables[BODY].AssetID = BODY_ASSET;
  197. m_wearables[BODY].ItemID = BODY_ITEM;
  198. m_wearables[SKIN].AssetID = SKIN_ASSET;
  199. m_wearables[SKIN].ItemID = SKIN_ITEM;
  200. m_wearables[SHIRT].AssetID = SHIRT_ASSET;
  201. m_wearables[SHIRT].ItemID = SHIRT_ITEM;
  202. m_wearables[PANTS].AssetID = PANTS_ASSET;
  203. m_wearables[PANTS].ItemID = PANTS_ITEM;
  204. }
  205. protected LLObject.TextureEntry m_texture;
  206. public LLObject.TextureEntry Texture
  207. {
  208. get { return m_texture; }
  209. set { m_texture = value; }
  210. }
  211. protected float m_avatarHeight = 0;
  212. public float AvatarHeight
  213. {
  214. get { return m_avatarHeight; }
  215. set { m_avatarHeight = value; }
  216. }
  217. public AvatarAppearance()
  218. {
  219. m_wearables = new AvatarWearable[MAX_WEARABLES];
  220. for (int i = 0; i < MAX_WEARABLES; i++)
  221. {
  222. // this makes them all null
  223. m_wearables[i] = new AvatarWearable();
  224. }
  225. m_serial = 0;
  226. m_owner = LLUUID.Zero;
  227. m_visualparams = new byte[VISUALPARAM_COUNT];
  228. SetDefaultWearables();
  229. m_texture = GetDefaultTexture();
  230. }
  231. public AvatarAppearance(LLUUID avatarID, AvatarWearable[] wearables, byte[] visualParams)
  232. {
  233. m_owner = avatarID;
  234. m_serial = 1;
  235. m_wearables = wearables;
  236. m_visualparams = visualParams;
  237. m_texture = GetDefaultTexture();
  238. }
  239. /// <summary>
  240. ///
  241. /// </summary>
  242. /// <param name="texture"></param>
  243. /// <param name="visualParam"></param>
  244. public void SetAppearance(byte[] texture, List<byte> visualParam)
  245. {
  246. LLObject.TextureEntry textureEnt = new LLObject.TextureEntry(texture, 0, texture.Length);
  247. m_texture = textureEnt;
  248. m_visualparams = visualParam.ToArray();
  249. // Teravus : Nifty AV Height Getting Maaaaagical formula. Oh how we love turning 0-255 into meters.
  250. // (float)m_visualParams[25] = Height
  251. // (float)m_visualParams[125] = LegLength
  252. m_avatarHeight = (1.50856f + (((float) m_visualparams[25]/255.0f)*(2.525506f - 1.50856f)))
  253. + (((float) m_visualparams[125]/255.0f)/1.5f);
  254. }
  255. public void SetWearable(int wearableId, AvatarWearable wearable)
  256. {
  257. m_wearables[wearableId] = wearable;
  258. }
  259. public static LLObject.TextureEntry GetDefaultTexture()
  260. {
  261. LLObject.TextureEntry textu = new LLObject.TextureEntry(new LLUUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
  262. textu.CreateFace(0).TextureID = new LLUUID("00000000-0000-1111-9999-000000000012");
  263. textu.CreateFace(1).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  264. textu.CreateFace(2).TextureID = new LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
  265. textu.CreateFace(3).TextureID = new LLUUID("6522E74D-1660-4E7F-B601-6F48C1659A77");
  266. textu.CreateFace(4).TextureID = new LLUUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B");
  267. textu.CreateFace(5).TextureID = new LLUUID("00000000-0000-1111-9999-000000000010");
  268. textu.CreateFace(6).TextureID = new LLUUID("00000000-0000-1111-9999-000000000011");
  269. return textu;
  270. }
  271. public override String ToString()
  272. {
  273. String s = "[Wearables] =>";
  274. s += "Body Item: " + BodyItem.ToString() + ";";
  275. s += "Skin Item: " + SkinItem.ToString() + ";";
  276. s += "Shirt Item: " + ShirtItem.ToString() + ";";
  277. s += "Pants Item: " + PantsItem.ToString() + ";";
  278. return s;
  279. }
  280. protected AvatarAppearance(SerializationInfo info, StreamingContext context)
  281. {
  282. //System.Console.WriteLine("AvatarAppearance Deserialize BGN");
  283. if (info == null)
  284. {
  285. throw new ArgumentNullException("info");
  286. }
  287. m_owner = new LLUUID((Guid)info.GetValue("m_scenePresenceID", typeof(Guid)));
  288. m_serial = (int)info.GetValue("m_wearablesSerial", typeof(int));
  289. m_visualparams = (byte[])info.GetValue("m_visualParams", typeof(byte[]));
  290. m_wearables = (AvatarWearable[])info.GetValue("m_wearables", typeof(AvatarWearable[]));
  291. byte[] m_textureEntry_work = (byte[])info.GetValue("m_textureEntry", typeof(byte[]));
  292. m_texture = new LLObject.TextureEntry(m_textureEntry_work, 0, m_textureEntry_work.Length);
  293. m_avatarHeight = (float)info.GetValue("m_avatarHeight", typeof(float));
  294. //System.Console.WriteLine("AvatarAppearance Deserialize END");
  295. }
  296. // this is used for OGS1
  297. public Hashtable ToHashTable()
  298. {
  299. Hashtable h = new Hashtable();
  300. h["owner"] = Owner.ToString();
  301. h["serial"] = Serial.ToString();
  302. h["visual_params"] = VisualParams;
  303. h["texture"] = Texture.ToBytes();
  304. h["avatar_height"] = AvatarHeight.ToString();
  305. h["body_item"] = BodyItem.ToString();
  306. h["body_asset"] = BodyAsset.ToString();
  307. h["skin_item"] = SkinItem.ToString();
  308. h["skin_asset"] = SkinAsset.ToString();
  309. h["hair_item"] = HairItem.ToString();
  310. h["hair_asset"] = HairAsset.ToString();
  311. h["eyes_item"] = EyesItem.ToString();
  312. h["eyes_asset"] = EyesAsset.ToString();
  313. h["shirt_item"] = ShirtItem.ToString();
  314. h["shirt_asset"] = ShirtAsset.ToString();
  315. h["pants_item"] = PantsItem.ToString();
  316. h["pants_asset"] = PantsAsset.ToString();
  317. h["shoes_item"] = ShoesItem.ToString();
  318. h["shoes_asset"] = ShoesAsset.ToString();
  319. h["socks_item"] = SocksItem.ToString();
  320. h["socks_asset"] = SocksAsset.ToString();
  321. h["jacket_item"] = JacketItem.ToString();
  322. h["jacket_asset"] = JacketAsset.ToString();
  323. h["gloves_item"] = GlovesItem.ToString();
  324. h["gloves_asset"] = GlovesAsset.ToString();
  325. h["undershirt_item"] = UnderShirtItem.ToString();
  326. h["undershirt_asset"] = UnderShirtAsset.ToString();
  327. h["underpants_item"] = UnderPantsItem.ToString();
  328. h["underpants_asset"] = UnderPantsAsset.ToString();
  329. h["skirt_item"] = SkirtItem.ToString();
  330. h["skirt_asset"] = SkirtAsset.ToString();
  331. return h;
  332. }
  333. public AvatarAppearance(Hashtable h)
  334. {
  335. Owner = new LLUUID((string)h["owner"]);
  336. Serial = Convert.ToInt32((string)h["serial"]);
  337. VisualParams = (byte[])h["visual_params"];
  338. Texture = new LLObject.TextureEntry((byte[])h["texture"], 0, ((byte[])h["texture"]).Length);
  339. AvatarHeight = (float)Convert.ToDouble((string)h["avatar_height"]);
  340. m_wearables = new AvatarWearable[MAX_WEARABLES];
  341. for (int i = 0; i < MAX_WEARABLES; i++)
  342. {
  343. // this makes them all null
  344. m_wearables[i] = new AvatarWearable();
  345. }
  346. BodyItem = new LLUUID((string)h["body_item"]);
  347. BodyAsset = new LLUUID((string)h["body_asset"]);
  348. SkinItem = new LLUUID((string)h["skin_item"]);
  349. SkinAsset = new LLUUID((string)h["skin_asset"]);
  350. HairItem = new LLUUID((string)h["hair_item"]);
  351. HairAsset = new LLUUID((string)h["hair_asset"]);
  352. EyesItem = new LLUUID((string)h["eyes_item"]);
  353. EyesAsset = new LLUUID((string)h["eyes_asset"]);
  354. ShirtItem = new LLUUID((string)h["shirt_item"]);
  355. ShirtAsset = new LLUUID((string)h["shirt_asset"]);
  356. PantsItem = new LLUUID((string)h["pants_item"]);
  357. PantsAsset = new LLUUID((string)h["pants_asset"]);
  358. ShoesItem = new LLUUID((string)h["shoes_item"]);
  359. ShoesAsset = new LLUUID((string)h["shoes_asset"]);
  360. SocksItem = new LLUUID((string)h["socks_item"]);
  361. SocksAsset = new LLUUID((string)h["socks_asset"]);
  362. JacketItem = new LLUUID((string)h["jacket_item"]);
  363. JacketAsset = new LLUUID((string)h["jacket_asset"]);
  364. GlovesItem = new LLUUID((string)h["gloves_item"]);
  365. GlovesAsset = new LLUUID((string)h["gloves_asset"]);
  366. UnderShirtItem = new LLUUID((string)h["undershirt_item"]);
  367. UnderShirtAsset = new LLUUID((string)h["undershirt_asset"]);
  368. UnderPantsItem = new LLUUID((string)h["underpants_item"]);
  369. UnderPantsAsset = new LLUUID((string)h["underpants_asset"]);
  370. SkirtItem = new LLUUID((string)h["skirt_item"]);
  371. SkirtAsset = new LLUUID((string)h["skirt_asset"]);
  372. }
  373. [SecurityPermission(SecurityAction.LinkDemand,
  374. Flags = SecurityPermissionFlag.SerializationFormatter)]
  375. public virtual void GetObjectData(
  376. SerializationInfo info, StreamingContext context)
  377. {
  378. if (info == null)
  379. {
  380. throw new ArgumentNullException("info");
  381. }
  382. info.AddValue("m_scenePresenceID", m_owner.UUID);
  383. info.AddValue("m_wearablesSerial", m_serial);
  384. info.AddValue("m_visualParams", m_visualparams);
  385. info.AddValue("m_wearables", m_wearables);
  386. info.AddValue("m_textureEntry", m_texture.ToBytes());
  387. info.AddValue("m_avatarHeight", m_avatarHeight);
  388. }
  389. }
  390. }