AvatarAppearance.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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 OpenMetaverse;
  33. namespace OpenSim.Framework
  34. {
  35. [Serializable]
  36. public class AvatarAppearance : ISerializable
  37. {
  38. // private static readonly ILog m_log
  39. // = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  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 UUID BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73");
  58. private static UUID BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9");
  59. private static UUID SKIN_ASSET = new UUID("77c41e39-38f9-f75a-024e-585989bbabbb");
  60. private static UUID SKIN_ITEM = new UUID("77c41e39-38f9-f75a-024e-585989bfabc9");
  61. private static UUID SHIRT_ASSET = new UUID("00000000-38f9-1111-024e-222222111110");
  62. private static UUID SHIRT_ITEM = new UUID("77c41e39-38f9-f75a-0000-585989bf0000");
  63. private static UUID PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120");
  64. private static UUID PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111");
  65. public readonly static int VISUALPARAM_COUNT = 218;
  66. protected UUID m_owner;
  67. public virtual UUID Owner
  68. {
  69. get { return m_owner; }
  70. set { m_owner = value; }
  71. }
  72. protected int m_serial = 1;
  73. public virtual int Serial
  74. {
  75. get { return m_serial; }
  76. set { m_serial = value; }
  77. }
  78. protected byte[] m_visualparams;
  79. public virtual byte[] VisualParams
  80. {
  81. get { return m_visualparams; }
  82. set { m_visualparams = value; }
  83. }
  84. protected AvatarWearable[] m_wearables;
  85. public virtual AvatarWearable[] Wearables
  86. {
  87. get { return m_wearables; }
  88. set { m_wearables = value; }
  89. }
  90. public virtual UUID BodyItem {
  91. get { return m_wearables[BODY].ItemID; }
  92. set { m_wearables[BODY].ItemID = value; }
  93. }
  94. public virtual UUID BodyAsset {
  95. get { return m_wearables[BODY].AssetID; }
  96. set { m_wearables[BODY].AssetID = value; }
  97. }
  98. public virtual UUID SkinItem {
  99. get { return m_wearables[SKIN].ItemID; }
  100. set { m_wearables[SKIN].ItemID = value; }
  101. }
  102. public virtual UUID SkinAsset {
  103. get { return m_wearables[SKIN].AssetID; }
  104. set { m_wearables[SKIN].AssetID = value; }
  105. }
  106. public virtual UUID HairItem {
  107. get { return m_wearables[HAIR].ItemID; }
  108. set { m_wearables[HAIR].ItemID = value; }
  109. }
  110. public virtual UUID HairAsset {
  111. get { return m_wearables[HAIR].AssetID; }
  112. set { m_wearables[HAIR].AssetID = value; }
  113. }
  114. public virtual UUID EyesItem {
  115. get { return m_wearables[EYES].ItemID; }
  116. set { m_wearables[EYES].ItemID = value; }
  117. }
  118. public virtual UUID EyesAsset {
  119. get { return m_wearables[EYES].AssetID; }
  120. set { m_wearables[EYES].AssetID = value; }
  121. }
  122. public virtual UUID ShirtItem {
  123. get { return m_wearables[SHIRT].ItemID; }
  124. set { m_wearables[SHIRT].ItemID = value; }
  125. }
  126. public virtual UUID ShirtAsset {
  127. get { return m_wearables[SHIRT].AssetID; }
  128. set { m_wearables[SHIRT].AssetID = value; }
  129. }
  130. public virtual UUID PantsItem {
  131. get { return m_wearables[PANTS].ItemID; }
  132. set { m_wearables[PANTS].ItemID = value; }
  133. }
  134. public virtual UUID PantsAsset {
  135. get { return m_wearables[PANTS].AssetID; }
  136. set { m_wearables[PANTS].AssetID = value; }
  137. }
  138. public virtual UUID ShoesItem {
  139. get { return m_wearables[SHOES].ItemID; }
  140. set { m_wearables[SHOES].ItemID = value; }
  141. }
  142. public virtual UUID ShoesAsset {
  143. get { return m_wearables[SHOES].AssetID; }
  144. set { m_wearables[SHOES].AssetID = value; }
  145. }
  146. public virtual UUID SocksItem {
  147. get { return m_wearables[SOCKS].ItemID; }
  148. set { m_wearables[SOCKS].ItemID = value; }
  149. }
  150. public virtual UUID SocksAsset {
  151. get { return m_wearables[SOCKS].AssetID; }
  152. set { m_wearables[SOCKS].AssetID = value; }
  153. }
  154. public virtual UUID JacketItem {
  155. get { return m_wearables[JACKET].ItemID; }
  156. set { m_wearables[JACKET].ItemID = value; }
  157. }
  158. public virtual UUID JacketAsset {
  159. get { return m_wearables[JACKET].AssetID; }
  160. set { m_wearables[JACKET].AssetID = value; }
  161. }
  162. public virtual UUID GlovesItem {
  163. get { return m_wearables[GLOVES].ItemID; }
  164. set { m_wearables[GLOVES].ItemID = value; }
  165. }
  166. public virtual UUID GlovesAsset {
  167. get { return m_wearables[GLOVES].AssetID; }
  168. set { m_wearables[GLOVES].AssetID = value; }
  169. }
  170. public virtual UUID UnderShirtItem {
  171. get { return m_wearables[UNDERSHIRT].ItemID; }
  172. set { m_wearables[UNDERSHIRT].ItemID = value; }
  173. }
  174. public virtual UUID UnderShirtAsset {
  175. get { return m_wearables[UNDERSHIRT].AssetID; }
  176. set { m_wearables[UNDERSHIRT].AssetID = value; }
  177. }
  178. public virtual UUID UnderPantsItem {
  179. get { return m_wearables[UNDERPANTS].ItemID; }
  180. set { m_wearables[UNDERPANTS].ItemID = value; }
  181. }
  182. public virtual UUID UnderPantsAsset {
  183. get { return m_wearables[UNDERPANTS].AssetID; }
  184. set { m_wearables[UNDERPANTS].AssetID = value; }
  185. }
  186. public virtual UUID SkirtItem {
  187. get { return m_wearables[SKIRT].ItemID; }
  188. set { m_wearables[SKIRT].ItemID = value; }
  189. }
  190. public virtual UUID SkirtAsset {
  191. get { return m_wearables[SKIRT].AssetID; }
  192. set { m_wearables[SKIRT].AssetID = value; }
  193. }
  194. public virtual 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 Primitive.TextureEntry m_texture;
  206. public virtual Primitive.TextureEntry Texture
  207. {
  208. get { return m_texture; }
  209. set { m_texture = value; }
  210. }
  211. protected float m_avatarHeight = 0;
  212. protected float m_hipOffset = 0;
  213. public virtual float AvatarHeight
  214. {
  215. get { return m_avatarHeight; }
  216. set { m_avatarHeight = value; }
  217. }
  218. public virtual float HipOffset
  219. {
  220. get { return m_hipOffset; }
  221. }
  222. public AvatarAppearance()
  223. {
  224. m_wearables = new AvatarWearable[MAX_WEARABLES];
  225. for (int i = 0; i < MAX_WEARABLES; i++)
  226. {
  227. // this makes them all null
  228. m_wearables[i] = new AvatarWearable();
  229. }
  230. m_serial = 0;
  231. m_owner = UUID.Zero;
  232. m_visualparams = new byte[VISUALPARAM_COUNT];
  233. SetDefaultWearables();
  234. m_texture = GetDefaultTexture();
  235. }
  236. public AvatarAppearance(UUID avatarID, AvatarWearable[] wearables, byte[] visualParams)
  237. {
  238. m_owner = avatarID;
  239. m_serial = 1;
  240. m_wearables = wearables;
  241. m_visualparams = visualParams;
  242. m_texture = GetDefaultTexture();
  243. }
  244. /// <summary>
  245. /// Set up appearance textures and avatar parameters, including a height calculation
  246. /// </summary>
  247. /// <param name="texture"></param>
  248. /// <param name="visualParam"></param>
  249. public virtual void SetAppearance(byte[] texture, List<byte> visualParam)
  250. {
  251. Primitive.TextureEntry textureEnt = new Primitive.TextureEntry(texture, 0, texture.Length);
  252. m_texture = textureEnt;
  253. m_visualparams = visualParam.ToArray();
  254. m_avatarHeight = 1.23077f // Shortest possible avatar height
  255. + 0.516945f * (float)m_visualparams[25] / 255.0f // Body height
  256. + 0.072514f * (float)m_visualparams[120] / 255.0f // Head size
  257. + 0.3836f * (float)m_visualparams[125] / 255.0f // Leg length
  258. + 0.08f * (float)m_visualparams[77] / 255.0f // Shoe heel height
  259. + 0.07f * (float)m_visualparams[78] / 255.0f // Shoe platform height
  260. + 0.076f * (float)m_visualparams[148] / 255.0f; // Neck length
  261. m_hipOffset = (0.615385f // Half of avatar
  262. + 0.08f * (float)m_visualparams[77] / 255.0f // Shoe heel height
  263. + 0.07f * (float)m_visualparams[78] / 255.0f // Shoe platform height
  264. + 0.3836f * (float)m_visualparams[125] / 255.0f // Leg length
  265. - m_avatarHeight / 2) * 0.3f - 0.04f;
  266. //System.Console.WriteLine("Height {0} Hip offset {1}", m_avatarHeight, m_hipOffset);
  267. }
  268. public virtual void SetWearable(int wearableId, AvatarWearable wearable)
  269. {
  270. m_wearables[wearableId] = wearable;
  271. }
  272. public static Primitive.TextureEntry GetDefaultTexture()
  273. {
  274. Primitive.TextureEntry textu = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
  275. textu.CreateFace(0).TextureID = new UUID("00000000-0000-1111-9999-000000000012");
  276. textu.CreateFace(1).TextureID = Util.BLANK_TEXTURE_UUID;
  277. textu.CreateFace(2).TextureID = Util.BLANK_TEXTURE_UUID;
  278. textu.CreateFace(3).TextureID = new UUID("6522E74D-1660-4E7F-B601-6F48C1659A77");
  279. textu.CreateFace(4).TextureID = new UUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B");
  280. textu.CreateFace(5).TextureID = new UUID("00000000-0000-1111-9999-000000000010");
  281. textu.CreateFace(6).TextureID = new UUID("00000000-0000-1111-9999-000000000011");
  282. return textu;
  283. }
  284. public override String ToString()
  285. {
  286. String s = "[Wearables] =>";
  287. s += " Body Item: " + BodyItem.ToString() + ";";
  288. s += " Skin Item: " + SkinItem.ToString() + ";";
  289. s += " Shirt Item: " + ShirtItem.ToString() + ";";
  290. s += " Pants Item: " + PantsItem.ToString() + ";";
  291. return s;
  292. }
  293. protected AvatarAppearance(SerializationInfo info, StreamingContext context)
  294. {
  295. if (info == null)
  296. {
  297. throw new ArgumentNullException("info");
  298. }
  299. m_owner = new UUID((Guid)info.GetValue("m_scenePresenceID", typeof(Guid)));
  300. m_serial = (int)info.GetValue("m_wearablesSerial", typeof(int));
  301. m_visualparams = (byte[])info.GetValue("m_visualParams", typeof(byte[]));
  302. m_wearables = (AvatarWearable[])info.GetValue("m_wearables", typeof(AvatarWearable[]));
  303. byte[] m_textureEntry_work = (byte[])info.GetValue("m_textureEntry", typeof(byte[]));
  304. m_texture = new Primitive.TextureEntry(m_textureEntry_work, 0, m_textureEntry_work.Length);
  305. m_avatarHeight = (float)info.GetValue("m_avatarHeight", typeof(float));
  306. //System.Console.WriteLine("AvatarAppearance Deserialize END");
  307. }
  308. // this is used for OGS1
  309. public virtual Hashtable ToHashTable()
  310. {
  311. Hashtable h = new Hashtable();
  312. h["owner"] = Owner.ToString();
  313. h["serial"] = Serial.ToString();
  314. h["visual_params"] = VisualParams;
  315. h["texture"] = Texture.ToBytes();
  316. h["avatar_height"] = AvatarHeight.ToString();
  317. h["body_item"] = BodyItem.ToString();
  318. h["body_asset"] = BodyAsset.ToString();
  319. h["skin_item"] = SkinItem.ToString();
  320. h["skin_asset"] = SkinAsset.ToString();
  321. h["hair_item"] = HairItem.ToString();
  322. h["hair_asset"] = HairAsset.ToString();
  323. h["eyes_item"] = EyesItem.ToString();
  324. h["eyes_asset"] = EyesAsset.ToString();
  325. h["shirt_item"] = ShirtItem.ToString();
  326. h["shirt_asset"] = ShirtAsset.ToString();
  327. h["pants_item"] = PantsItem.ToString();
  328. h["pants_asset"] = PantsAsset.ToString();
  329. h["shoes_item"] = ShoesItem.ToString();
  330. h["shoes_asset"] = ShoesAsset.ToString();
  331. h["socks_item"] = SocksItem.ToString();
  332. h["socks_asset"] = SocksAsset.ToString();
  333. h["jacket_item"] = JacketItem.ToString();
  334. h["jacket_asset"] = JacketAsset.ToString();
  335. h["gloves_item"] = GlovesItem.ToString();
  336. h["gloves_asset"] = GlovesAsset.ToString();
  337. h["undershirt_item"] = UnderShirtItem.ToString();
  338. h["undershirt_asset"] = UnderShirtAsset.ToString();
  339. h["underpants_item"] = UnderPantsItem.ToString();
  340. h["underpants_asset"] = UnderPantsAsset.ToString();
  341. h["skirt_item"] = SkirtItem.ToString();
  342. h["skirt_asset"] = SkirtAsset.ToString();
  343. string attachments = GetAttachmentsString();
  344. if (attachments != String.Empty)
  345. h["attachments"] = attachments;
  346. return h;
  347. }
  348. public AvatarAppearance(Hashtable h)
  349. {
  350. Owner = new UUID((string)h["owner"]);
  351. Serial = Convert.ToInt32((string)h["serial"]);
  352. VisualParams = (byte[])h["visual_params"];
  353. Texture = new Primitive.TextureEntry((byte[])h["texture"], 0, ((byte[])h["texture"]).Length);
  354. AvatarHeight = (float)Convert.ToDouble((string)h["avatar_height"]);
  355. m_wearables = new AvatarWearable[MAX_WEARABLES];
  356. for (int i = 0; i < MAX_WEARABLES; i++)
  357. {
  358. // this makes them all null
  359. m_wearables[i] = new AvatarWearable();
  360. }
  361. BodyItem = new UUID((string)h["body_item"]);
  362. BodyAsset = new UUID((string)h["body_asset"]);
  363. SkinItem = new UUID((string)h["skin_item"]);
  364. SkinAsset = new UUID((string)h["skin_asset"]);
  365. HairItem = new UUID((string)h["hair_item"]);
  366. HairAsset = new UUID((string)h["hair_asset"]);
  367. EyesItem = new UUID((string)h["eyes_item"]);
  368. EyesAsset = new UUID((string)h["eyes_asset"]);
  369. ShirtItem = new UUID((string)h["shirt_item"]);
  370. ShirtAsset = new UUID((string)h["shirt_asset"]);
  371. PantsItem = new UUID((string)h["pants_item"]);
  372. PantsAsset = new UUID((string)h["pants_asset"]);
  373. ShoesItem = new UUID((string)h["shoes_item"]);
  374. ShoesAsset = new UUID((string)h["shoes_asset"]);
  375. SocksItem = new UUID((string)h["socks_item"]);
  376. SocksAsset = new UUID((string)h["socks_asset"]);
  377. JacketItem = new UUID((string)h["jacket_item"]);
  378. JacketAsset = new UUID((string)h["jacket_asset"]);
  379. GlovesItem = new UUID((string)h["gloves_item"]);
  380. GlovesAsset = new UUID((string)h["gloves_asset"]);
  381. UnderShirtItem = new UUID((string)h["undershirt_item"]);
  382. UnderShirtAsset = new UUID((string)h["undershirt_asset"]);
  383. UnderPantsItem = new UUID((string)h["underpants_item"]);
  384. UnderPantsAsset = new UUID((string)h["underpants_asset"]);
  385. SkirtItem = new UUID((string)h["skirt_item"]);
  386. SkirtAsset = new UUID((string)h["skirt_asset"]);
  387. if (h.ContainsKey("attachments"))
  388. {
  389. SetAttachmentsString(h["attachments"].ToString());
  390. }
  391. }
  392. [SecurityPermission(SecurityAction.LinkDemand,
  393. Flags = SecurityPermissionFlag.SerializationFormatter)]
  394. public virtual void GetObjectData(
  395. SerializationInfo info, StreamingContext context)
  396. {
  397. if (info == null)
  398. {
  399. throw new ArgumentNullException("info");
  400. }
  401. info.AddValue("m_scenePresenceID", m_owner.Guid);
  402. info.AddValue("m_wearablesSerial", m_serial);
  403. info.AddValue("m_visualParams", m_visualparams);
  404. info.AddValue("m_wearables", m_wearables);
  405. info.AddValue("m_textureEntry", m_texture.ToBytes());
  406. info.AddValue("m_avatarHeight", m_avatarHeight);
  407. }
  408. private Dictionary<int, UUID[]> m_attachments = new Dictionary<int, UUID[]>();
  409. public void SetAttachments(Hashtable data)
  410. {
  411. m_attachments.Clear();
  412. if (data == null)
  413. return;
  414. foreach (DictionaryEntry e in data)
  415. {
  416. int attachpoint = Convert.ToInt32(e.Key);
  417. if (m_attachments.ContainsKey(attachpoint))
  418. continue;
  419. UUID item;
  420. UUID asset;
  421. Hashtable uuids = (Hashtable) e.Value;
  422. UUID.TryParse(uuids["item"].ToString(), out item);
  423. UUID.TryParse(uuids["asset"].ToString(), out asset);
  424. UUID[] attachment = new UUID[2];
  425. attachment[0] = item;
  426. attachment[1] = asset;
  427. m_attachments[attachpoint] = attachment;
  428. }
  429. }
  430. public Hashtable GetAttachments()
  431. {
  432. if (m_attachments.Count == 0)
  433. return null;
  434. Hashtable ret = new Hashtable();
  435. foreach (KeyValuePair<int, UUID[]> kvp in m_attachments)
  436. {
  437. int attachpoint = kvp.Key;
  438. UUID[] uuids = kvp.Value;
  439. Hashtable data = new Hashtable();
  440. data["item"] = uuids[0].ToString();
  441. data["asset"] = uuids[1].ToString();
  442. ret[attachpoint] = data;
  443. }
  444. return ret;
  445. }
  446. public List<int> GetAttachedPoints()
  447. {
  448. return new List<int>(m_attachments.Keys);
  449. }
  450. public UUID GetAttachedItem(int attachpoint)
  451. {
  452. if (!m_attachments.ContainsKey(attachpoint))
  453. return UUID.Zero;
  454. return m_attachments[attachpoint][0];
  455. }
  456. public UUID GetAttachedAsset(int attachpoint)
  457. {
  458. if (!m_attachments.ContainsKey(attachpoint))
  459. return UUID.Zero;
  460. return m_attachments[attachpoint][1];
  461. }
  462. public void SetAttachment(int attachpoint, UUID item, UUID asset)
  463. {
  464. if (attachpoint == 0)
  465. return;
  466. if (item == UUID.Zero)
  467. {
  468. if (m_attachments.ContainsKey(attachpoint))
  469. m_attachments.Remove(attachpoint);
  470. return;
  471. }
  472. if (!m_attachments.ContainsKey(attachpoint))
  473. m_attachments[attachpoint] = new UUID[2];
  474. m_attachments[attachpoint][0] = item;
  475. m_attachments[attachpoint][1] = asset;
  476. }
  477. public int GetAttachpoint(UUID itemID)
  478. {
  479. foreach (KeyValuePair<int, UUID[]> kvp in m_attachments)
  480. {
  481. if (kvp.Value[0] == itemID)
  482. {
  483. return kvp.Key;
  484. }
  485. }
  486. return 0;
  487. }
  488. public void DetachAttachment(UUID itemID)
  489. {
  490. int attachpoint = GetAttachpoint(itemID);
  491. if (attachpoint > 0)
  492. m_attachments.Remove(attachpoint);
  493. }
  494. string GetAttachmentsString()
  495. {
  496. List<string> strings = new List<string>();
  497. foreach (KeyValuePair<int, UUID[]> e in m_attachments)
  498. {
  499. strings.Add(e.Key.ToString());
  500. strings.Add(e.Value[0].ToString());
  501. strings.Add(e.Value[1].ToString());
  502. }
  503. return String.Join(",", strings.ToArray());
  504. }
  505. void SetAttachmentsString(string data)
  506. {
  507. string[] strings = data.Split(new char[] {','});
  508. int i = 0;
  509. m_attachments.Clear();
  510. while (strings.Length - i > 2)
  511. {
  512. int attachpoint = Int32.Parse(strings[i]);
  513. UUID item = new UUID(strings[i+1]);
  514. UUID asset = new UUID(strings[i+2]);
  515. i += 3;
  516. if (!m_attachments.ContainsKey(attachpoint))
  517. {
  518. m_attachments[attachpoint] = new UUID[2];
  519. m_attachments[attachpoint][0] = item;
  520. m_attachments[attachpoint][1] = asset;
  521. }
  522. }
  523. }
  524. }
  525. }