aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AvatarAppearance.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs140
1 files changed, 94 insertions, 46 deletions
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index c0bc47e..21e2233 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -47,7 +47,6 @@ namespace OpenSim.Framework
47 public readonly static int TEXTURE_COUNT = 21; 47 public readonly static int TEXTURE_COUNT = 21;
48 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 48 public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
49 49
50 protected UUID m_owner;
51 protected int m_serial = 0; 50 protected int m_serial = 0;
52 protected byte[] m_visualparams; 51 protected byte[] m_visualparams;
53 protected Primitive.TextureEntry m_texture; 52 protected Primitive.TextureEntry m_texture;
@@ -56,12 +55,6 @@ namespace OpenSim.Framework
56 protected float m_avatarHeight = 0; 55 protected float m_avatarHeight = 0;
57 protected float m_hipOffset = 0; 56 protected float m_hipOffset = 0;
58 57
59 public virtual UUID Owner
60 {
61 get { return m_owner; }
62 set { m_owner = value; }
63 }
64
65 public virtual int Serial 58 public virtual int Serial
66 { 59 {
67 get { return m_serial; } 60 get { return m_serial; }
@@ -77,7 +70,11 @@ namespace OpenSim.Framework
77 public virtual Primitive.TextureEntry Texture 70 public virtual Primitive.TextureEntry Texture
78 { 71 {
79 get { return m_texture; } 72 get { return m_texture; }
80 set { m_texture = value; } 73 set
74 {
75// m_log.DebugFormat("[AVATAR APPEARANCE]: Set TextureEntry to {0}", value);
76 m_texture = value;
77 }
81 } 78 }
82 79
83 public virtual AvatarWearable[] Wearables 80 public virtual AvatarWearable[] Wearables
@@ -97,38 +94,31 @@ namespace OpenSim.Framework
97 get { return m_hipOffset; } 94 get { return m_hipOffset; }
98 } 95 }
99 96
100 public AvatarAppearance() : this(UUID.Zero) {} 97 public AvatarAppearance()
101
102 public AvatarAppearance(UUID owner)
103 { 98 {
104// m_log.WarnFormat("[AVATAR APPEARANCE]: create empty appearance for {0}",owner); 99// m_log.WarnFormat("[AVATAR APPEARANCE]: create empty appearance");
105 100
106 m_serial = 0; 101 m_serial = 0;
107 m_owner = owner;
108
109 SetDefaultWearables(); 102 SetDefaultWearables();
110 SetDefaultTexture(); 103 SetDefaultTexture();
111 SetDefaultParams(); 104 SetDefaultParams();
112 SetHeight(); 105 SetHeight();
113
114 m_attachments = new Dictionary<int, List<AvatarAttachment>>(); 106 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
115 } 107 }
116 108
117 public AvatarAppearance(UUID avatarID, OSDMap map) 109 public AvatarAppearance(OSDMap map)
118 { 110 {
119// m_log.WarnFormat("[AVATAR APPEARANCE]: create appearance for {0} from OSDMap",avatarID); 111// m_log.WarnFormat("[AVATAR APPEARANCE]: create appearance from OSDMap");
120 112
121 m_owner = avatarID;
122 Unpack(map); 113 Unpack(map);
123 SetHeight(); 114 SetHeight();
124 } 115 }
125 116
126 public AvatarAppearance(UUID avatarID, AvatarWearable[] wearables, Primitive.TextureEntry textureEntry, byte[] visualParams) 117 public AvatarAppearance(AvatarWearable[] wearables, Primitive.TextureEntry textureEntry, byte[] visualParams)
127 { 118 {
128// m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance for {0}",avatarID); 119// m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance");
129 120
130 m_serial = 0; 121 m_serial = 0;
131 m_owner = avatarID;
132 122
133 if (wearables != null) 123 if (wearables != null)
134 m_wearables = wearables; 124 m_wearables = wearables;
@@ -161,24 +151,21 @@ namespace OpenSim.Framework
161 if (appearance == null) 151 if (appearance == null)
162 { 152 {
163 m_serial = 0; 153 m_serial = 0;
164 m_owner = UUID.Zero;
165
166 SetDefaultWearables(); 154 SetDefaultWearables();
167 SetDefaultTexture(); 155 SetDefaultTexture();
168 SetDefaultParams(); 156 SetDefaultParams();
169 SetHeight(); 157 SetHeight();
170
171 m_attachments = new Dictionary<int, List<AvatarAttachment>>(); 158 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
172 159
173 return; 160 return;
174 } 161 }
175 162
176 m_serial = appearance.Serial; 163 m_serial = appearance.Serial;
177 m_owner = appearance.Owner;
178 164
179 m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES]; 165 m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES];
180 for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) 166 for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
181 m_wearables[i] = new AvatarWearable(); 167 m_wearables[i] = new AvatarWearable();
168
182 if (copyWearables && (appearance.Wearables != null)) 169 if (copyWearables && (appearance.Wearables != null))
183 { 170 {
184 for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) 171 for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
@@ -196,6 +183,9 @@ namespace OpenSim.Framework
196 if (appearance.VisualParams != null) 183 if (appearance.VisualParams != null)
197 m_visualparams = (byte[])appearance.VisualParams.Clone(); 184 m_visualparams = (byte[])appearance.VisualParams.Clone();
198 185
186 m_avatarHeight = appearance.m_avatarHeight;
187 m_hipOffset = appearance.m_hipOffset;
188
199 // Copy the attachment, force append mode since that ensures consistency 189 // Copy the attachment, force append mode since that ensures consistency
200 m_attachments = new Dictionary<int, List<AvatarAttachment>>(); 190 m_attachments = new Dictionary<int, List<AvatarAttachment>>();
201 foreach (AvatarAttachment attachment in appearance.GetAttachments()) 191 foreach (AvatarAttachment attachment in appearance.GetAttachments())
@@ -237,7 +227,6 @@ namespace OpenSim.Framework
237 { 227 {
238 m_serial = 0; 228 m_serial = 0;
239 229
240 SetDefaultParams();
241 SetDefaultTexture(); 230 SetDefaultTexture();
242 231
243 //for (int i = 0; i < BAKE_INDICES.Length; i++) 232 //for (int i = 0; i < BAKE_INDICES.Length; i++)
@@ -409,36 +398,47 @@ namespace OpenSim.Framework
409// DEBUG OFF 398// DEBUG OFF
410 399
411 /// <summary> 400 /// <summary>
412 /// Get a list of the attachments, note that there may be 401 /// Get a list of the attachments.
413 /// duplicate attachpoints
414 /// </summary> 402 /// </summary>
403 /// <remarks>
404 /// There may be duplicate attachpoints
405 /// </remarks>
415 public List<AvatarAttachment> GetAttachments() 406 public List<AvatarAttachment> GetAttachments()
416 { 407 {
408
409
417 lock (m_attachments) 410 lock (m_attachments)
418 { 411 {
419 List<AvatarAttachment> alist = new List<AvatarAttachment>(); 412 List<AvatarAttachment> alist = new List<AvatarAttachment>();
420 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 413 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
421 { 414 {
422 foreach (AvatarAttachment attach in kvp.Value) 415 foreach (AvatarAttachment attach in kvp.Value)
423 alist.Add(new AvatarAttachment(attach)); 416 alist.Add(new AvatarAttachment(attach));
424 } 417 }
425 418 return alist;
426 return alist; 419 } }
427 }
428 }
429 420
430 internal void AppendAttachment(AvatarAttachment attach) 421 internal void AppendAttachment(AvatarAttachment attach)
431 { 422 {
423// m_log.DebugFormat(
424// "[AVATAR APPEARNCE]: Appending itemID={0}, assetID={1} at {2}",
425// attach.ItemID, attach.AssetID, attach.AttachPoint);
426
432 lock (m_attachments) 427 lock (m_attachments)
433 { 428 {
434 if (!m_attachments.ContainsKey(attach.AttachPoint)) 429 if (!m_attachments.ContainsKey(attach.AttachPoint))
435 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 430 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
431
436 m_attachments[attach.AttachPoint].Add(attach); 432 m_attachments[attach.AttachPoint].Add(attach);
437 } 433 }
438 } 434 }
439 435
440 internal void ReplaceAttachment(AvatarAttachment attach) 436 internal void ReplaceAttachment(AvatarAttachment attach)
441 { 437 {
438// m_log.DebugFormat(
439// "[AVATAR APPEARANCE]: Replacing itemID={0}, assetID={1} at {2}",
440// attach.ItemID, attach.AssetID, attach.AttachPoint);
441
442 lock (m_attachments) 442 lock (m_attachments)
443 { 443 {
444 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 444 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
@@ -447,14 +447,26 @@ namespace OpenSim.Framework
447 } 447 }
448 448
449 /// <summary> 449 /// <summary>
450 /// Add an attachment, if the attachpoint has the 450 /// Set an attachment
451 /// </summary>
452 /// <remarks>
453 /// If the attachpoint has the
451 /// 0x80 bit set then we assume this is an append 454 /// 0x80 bit set then we assume this is an append
452 /// operation otherwise we replace whatever is 455 /// operation otherwise we replace whatever is
453 /// currently attached at the attachpoint 456 /// currently attached at the attachpoint
457 /// </remarks>
458 /// <param name="attachpoint"></param>
459 /// <param name="item">If UUID.Zero, then an any attachment at the attachpoint is removed.</param>
460 /// <param name="asset"></param>
461 /// <returns>
454 /// return true if something actually changed 462 /// return true if something actually changed
455 /// </summary> 463 /// </returns>
456 public bool SetAttachment(int attachpoint, UUID item, UUID asset) 464 public bool SetAttachment(int attachpoint, UUID item, UUID asset)
457 { 465 {
466// m_log.DebugFormat(
467// "[AVATAR APPEARANCE]: Setting attachment at {0} with item ID {1}, asset ID {2}",
468// attachpoint, item, asset);
469
458 if (attachpoint == 0) 470 if (attachpoint == 0)
459 return false; 471 return false;
460 472
@@ -467,12 +479,21 @@ namespace OpenSim.Framework
467 m_attachments.Remove(attachpoint); 479 m_attachments.Remove(attachpoint);
468 return true; 480 return true;
469 } 481 }
470 return false;
471 } 482 }
483
484 return false;
472 } 485 }
473 486
474 // check if the item is already attached at this point 487 // When a user logs in, the attachment item ids are pulled from persistence in the Avatars table. However,
475 if (GetAttachpoint(item) == (attachpoint & 0x7F)) 488 // the asset ids are not saved. When the avatar enters a simulator the attachments are set again. If
489 // we simply perform an item check here then the asset ids (which are now present) are never set, and NPC attachments
490 // later fail unless the attachment is detached and reattached.
491 //
492 // Therefore, we will carry on with the set if the existing attachment has no asset id.
493 AvatarAttachment existingAttachment = GetAttachmentForItem(item);
494 if (existingAttachment != null
495 && existingAttachment.AssetID != UUID.Zero
496 && existingAttachment.AttachPoint == (attachpoint & 0x7F))
476 { 497 {
477 // m_log.DebugFormat("[AVATAR APPEARANCE] attempt to attach an already attached item {0}",item); 498 // m_log.DebugFormat("[AVATAR APPEARANCE] attempt to attach an already attached item {0}",item);
478 return false; 499 return false;
@@ -487,11 +508,32 @@ namespace OpenSim.Framework
487 } 508 }
488 else 509 else
489 { 510 {
490 ReplaceAttachment(new AvatarAttachment(attachpoint,item,asset)); 511 ReplaceAttachment(new AvatarAttachment(attachpoint,item, asset));
491 } 512 }
513
492 return true; 514 return true;
493 } 515 }
494 516
517 /// <summary>
518 /// If the item is already attached, return it.
519 /// </summary>
520 /// <param name="itemID"></param>
521 /// <returns>Returns null if this item is not attached.</returns>
522 public AvatarAttachment GetAttachmentForItem(UUID itemID)
523 {
524 lock (m_attachments)
525 {
526 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
527 {
528 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
529 if (index >= 0)
530 return kvp.Value[index];
531 }
532 }
533
534 return null;
535 }
536
495 public int GetAttachpoint(UUID itemID) 537 public int GetAttachpoint(UUID itemID)
496 { 538 {
497 lock (m_attachments) 539 lock (m_attachments)
@@ -502,9 +544,8 @@ namespace OpenSim.Framework
502 if (index >= 0) 544 if (index >= 0)
503 return kvp.Key; 545 return kvp.Key;
504 } 546 }
505
506 return 0;
507 } 547 }
548 return 0;
508 } 549 }
509 550
510 public bool DetachAttachment(UUID itemID) 551 public bool DetachAttachment(UUID itemID)
@@ -518,23 +559,23 @@ namespace OpenSim.Framework
518 { 559 {
519 // Remove it from the list of attachments at that attach point 560 // Remove it from the list of attachments at that attach point
520 m_attachments[kvp.Key].RemoveAt(index); 561 m_attachments[kvp.Key].RemoveAt(index);
521 562
522 // And remove the list if there are no more attachments here 563 // And remove the list if there are no more attachments here
523 if (m_attachments[kvp.Key].Count == 0) 564 if (m_attachments[kvp.Key].Count == 0)
524 m_attachments.Remove(kvp.Key); 565 m_attachments.Remove(kvp.Key);
566
525 return true; 567 return true;
526 } 568 }
527 } 569 }
528 } 570 }
571
529 return false; 572 return false;
530 } 573 }
531 574
532 public void ClearAttachments() 575 public void ClearAttachments()
533 { 576 {
534 lock (m_attachments) 577 lock (m_attachments)
535 {
536 m_attachments.Clear(); 578 m_attachments.Clear();
537 }
538 } 579 }
539 580
540 #region Packing Functions 581 #region Packing Functions
@@ -589,7 +630,7 @@ namespace OpenSim.Framework
589 /// </summary> 630 /// </summary>
590 public void Unpack(OSDMap data) 631 public void Unpack(OSDMap data)
591 { 632 {
592 if ((data != null) && (data["serial"] != null)) 633 if ((data != null) && (data["serial"] != null))
593 m_serial = data["serial"].AsInteger(); 634 m_serial = data["serial"].AsInteger();
594 if ((data != null) && (data["height"] != null)) 635 if ((data != null) && (data["height"] != null))
595 m_avatarHeight = (float)data["height"].AsReal(); 636 m_avatarHeight = (float)data["height"].AsReal();
@@ -647,7 +688,14 @@ namespace OpenSim.Framework
647 { 688 {
648 OSDArray attachs = (OSDArray)(data["attachments"]); 689 OSDArray attachs = (OSDArray)(data["attachments"]);
649 for (int i = 0; i < attachs.Count; i++) 690 for (int i = 0; i < attachs.Count; i++)
650 AppendAttachment(new AvatarAttachment((OSDMap)attachs[i])); 691 {
692 AvatarAttachment att = new AvatarAttachment((OSDMap)attachs[i]);
693 AppendAttachment(att);
694
695// m_log.DebugFormat(
696// "[AVATAR APPEARANCE]: Unpacked attachment itemID {0}, assetID {1}, point {2}",
697// att.ItemID, att.AssetID, att.AttachPoint);
698 }
651 } 699 }
652 } 700 }
653 catch (Exception e) 701 catch (Exception e)