aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs30
-rw-r--r--OpenSim/Framework/AvatarSkeleton.cs281
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs29
3 files changed, 336 insertions, 4 deletions
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 1638541..ad783c8 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -55,6 +55,13 @@ namespace OpenSim.Framework
55 protected AvatarWearable[] m_wearables; 55 protected AvatarWearable[] m_wearables;
56 protected Dictionary<int, List<AvatarAttachment>> m_attachments; 56 protected Dictionary<int, List<AvatarAttachment>> m_attachments;
57 protected float m_avatarHeight = 0; 57 protected float m_avatarHeight = 0;
58 protected Vector3 m_avatarSize = new Vector3(0.45f, 0.6f, 1.9f);
59 protected Vector3 m_avatarBoxSize = new Vector3(0.45f, 0.6f, 1.9f);
60 protected float m_avatarFeetOffset = 0;
61 protected float m_avatarAnimOffset = 0;
62
63
64 private AvatarSkeleton skeleton = new AvatarSkeleton();
58 65
59 public virtual int Serial 66 public virtual int Serial
60 { 67 {
@@ -68,6 +75,21 @@ namespace OpenSim.Framework
68 set { m_visualparams = value; } 75 set { m_visualparams = value; }
69 } 76 }
70 77
78 public virtual Vector3 AvatarSize
79 {
80 get { return m_avatarSize; }
81 }
82
83 public virtual Vector3 AvatarBoxSize
84 {
85 get { return m_avatarBoxSize; }
86 }
87
88 public virtual float AvatarFeetOffset
89 {
90 get { return m_avatarFeetOffset + m_avatarAnimOffset; }
91 }
92
71 public virtual Primitive.TextureEntry Texture 93 public virtual Primitive.TextureEntry Texture
72 { 94 {
73 get { return m_texture; } 95 get { return m_texture; }
@@ -363,6 +385,7 @@ namespace OpenSim.Framework
363 /// </summary> 385 /// </summary>
364 public virtual void SetHeight() 386 public virtual void SetHeight()
365 { 387 {
388/*
366 // Start with shortest possible female avatar height 389 // Start with shortest possible female avatar height
367 m_avatarHeight = 1.14597f; 390 m_avatarHeight = 1.14597f;
368 // Add offset for male avatars 391 // Add offset for male avatars
@@ -375,6 +398,13 @@ namespace OpenSim.Framework
375 + 0.07f * (float)m_visualparams[(int)VPElement.SHOES_PLATFORM_HEIGHT] / 255.0f 398 + 0.07f * (float)m_visualparams[(int)VPElement.SHOES_PLATFORM_HEIGHT] / 255.0f
376 + 0.08f * (float)m_visualparams[(int)VPElement.SHOES_HEEL_HEIGHT] / 255.0f 399 + 0.08f * (float)m_visualparams[(int)VPElement.SHOES_HEEL_HEIGHT] / 255.0f
377 + 0.076f * (float)m_visualparams[(int)VPElement.SHAPE_NECK_LENGTH] / 255.0f; 400 + 0.076f * (float)m_visualparams[(int)VPElement.SHAPE_NECK_LENGTH] / 255.0f;
401*/
402
403 skeleton.ApplyVisualParameters(m_visualparams);
404 m_avatarSize = skeleton.StandSize;
405 m_avatarBoxSize = skeleton.StandBoxSize;
406 m_avatarFeetOffset = skeleton.FeetOffset;
407 m_avatarHeight = m_avatarSize.Z;
378 } 408 }
379 409
380 public virtual void SetWearable(int wearableId, AvatarWearable wearable) 410 public virtual void SetWearable(int wearableId, AvatarWearable wearable)
diff --git a/OpenSim/Framework/AvatarSkeleton.cs b/OpenSim/Framework/AvatarSkeleton.cs
new file mode 100644
index 0000000..269099b
--- /dev/null
+++ b/OpenSim/Framework/AvatarSkeleton.cs
@@ -0,0 +1,281 @@
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 OpenSimulator 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// Ubit 2012
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32using OpenMetaverse.StructuredData;
33using log4net;
34using VPElement = OpenSim.Framework.AvatarAppearance.VPElement;
35
36
37
38namespace OpenSim.Framework
39{
40 /// <summary>
41 /// Contains the Avatar's Skeleton
42 /// </summary>
43 public class AvatarSkeleton
44 {
45 const int NBONES = 26;
46 const float BOXAJUST = 0.2f;
47
48 public enum Bones : int
49 {
50 EyeLeft,
51 Eyeright,
52 Skull,
53 Head,
54 Neck,
55 CollarRight,
56 CollarLeft,
57 Shoulderright,
58 ShoulderLeft,
59 ElbowRight,
60 ElbowLeft,
61 WristRight,
62 WristLeft,
63 Chest,
64 Torso,
65 Pelvis,
66 Hipright,
67 HipLeft,
68 KneeRight,
69 KneeLeft,
70 AnkleRight,
71 AnkleLeft,
72 FootRight,
73 FootLeft,
74 ToeRight,
75 ToeLeft
76 }
77
78 public struct bone
79 {
80 public Vector3 Offset;
81 public Vector3 Scale;
82 public bone(float x, float y, float z)
83 {
84 Offset = new Vector3(x, y, z);
85 Scale = new Vector3(1f, 1f, 1f);
86 }
87
88 public void addScale(float x, float y, float z, float factor)
89 {
90 Scale.X += x * factor;
91 Scale.Y += y * factor;
92 Scale.Y += z * factor;
93 }
94
95 public void addOffset(float x, float y, float z, float factor)
96 {
97 Offset.X += x * factor;
98 Offset.Y += y * factor;
99 Offset.Y += z * factor;
100 }
101 }
102
103 private bone[] DefaultBones = new bone[]
104 {
105 new bone(0.098f, 0.036f, 0.079f), // EyeLeft
106 new bone(0.098f, -0.036f, 0.079f), // Eyeright
107 new bone(0.0f, 0.0f, 0.079f), // Skull
108 new bone(0.0f, 0.0f, 0.076f), // Head
109 new bone(-0.1f, 0.0f, 0.251f), // Neck
110 new bone(-0.021f, -0.085f, 0.165f), // CollarRight
111 new bone(-0.021f, 0.085f, 0.165f), // CollarLeft
112 new bone(0.0f, -0.79f, 0.0f), // Shoulderright
113 new bone(0.0f, 0.79f, 0.0f), // ShoulderLeft
114 new bone(0.0f, -0.248f, 0.0f), // ElbowRight
115 new bone(0.0f, 0.248f, 0.0f), // ElbowLeft
116 new bone(0.0f, -0.205f, 0.0f), // WristRight
117 new bone(0.0f, 0.205f, 0.0f), // WristLeft
118 new bone(-0.015f, 0.000f, 0.205f), // Chest
119 new bone(0.0f, 0.0f, 0.084f), // Torso
120 new bone(0.0f, 0.0f, 1.067f), // Pelvis
121 new bone(0.034f, -0.129f, -0.041f), // Hipright
122 new bone(0.034f, 0.127f, -0.041f), // HipLeft
123 new bone(-0.001f, 0.049f, -0.491f), // KneeRight
124 new bone(-0.001f, -0.046f, -0.491f), // KneeLeft
125 new bone(-0.029f, 0.0f, -0.468f), // AnkleRight
126 new bone(-0.029f, 0.001f, -0.468f), // AnkleLeft
127 new bone(0.112f, 0.0f, -0.061f), // FootRight
128 new bone(0.112f, 0.0f, -0.061f), // FootLeft
129 new bone(0.109f, 0.0f, 0.0f), // ToeRight
130 new bone(0.109f, 0.0f, 0.0f) // ToeLeft
131 };
132
133 private bone[] m_bones = null;
134 private byte[] m_visualParams = null;
135
136 const float bytescale = 1.0f / 255.0f;
137
138 private float convertVP(AvatarAppearance.VPElement vp)
139 {
140 return (float)m_visualParams[(int)vp] * bytescale;
141 }
142
143 private Vector3 m_standSize;
144 private float m_feetOffset = 0f;
145
146 public Vector3 StandSize
147 {
148 get
149 {
150 if (m_bones == null || m_visualParams == null)
151 return new Vector3(0.45f, 0.6f, 1.9f);
152 else
153 return m_standSize;
154 }
155 }
156
157 public Vector3 StandBoxSize
158 {
159 get
160 {
161 if (m_bones == null || m_visualParams == null)
162 return new Vector3(0.45f, 0.6f, 1.9f + BOXAJUST);
163 else
164 {
165 Vector3 r = m_standSize;
166 r.Z += BOXAJUST;
167 return r;
168 }
169 }
170 }
171
172 public float FeetOffset
173 {
174 get
175 {
176 if (m_bones == null || m_visualParams == null)
177 return 0.0f;
178 else
179 {
180 return m_feetOffset;
181 }
182 }
183 }
184
185 /// <summary>
186 /// Set avatar height by a calculation based on their visual parameters.
187 /// </summary>
188
189 public void ApplyVisualParameters(byte[] vPs)
190 {
191 m_visualParams = vPs;
192
193 if (m_bones == null)
194 {
195 m_bones = new bone[NBONES];
196 for (int i = 0; i < NBONES; i++)
197 m_bones[i] = DefaultBones[i];
198 }
199
200 float bone_skull = m_bones[(int)Bones.Skull].Offset.Z;
201 float bone_head = m_bones[(int)Bones.Head].Offset.Z;
202 float bone_neck = m_bones[(int)Bones.Neck].Offset.Z;
203 float bone_chest = m_bones[(int)Bones.Chest].Offset.Z;
204 float bone_torso = m_bones[(int)Bones.Torso].Offset.Z;
205 float bone_hip = m_bones[(int)Bones.Hipright].Offset.Z;
206 float bone_knee = m_bones[(int)Bones.KneeRight].Offset.Z;
207 float bone_ank = m_bones[(int)Bones.AnkleRight].Offset.Z;
208 float bone_foot = m_bones[(int)Bones.FootRight].Offset.Z;
209
210 float sbone_skull = m_bones[(int)Bones.Skull].Scale.Z;
211 float sbone_head = m_bones[(int)Bones.Head].Scale.Z;
212 float sbone_neck = m_bones[(int)Bones.Neck].Scale.Z;
213 float sbone_chest = m_bones[(int)Bones.Chest].Scale.Z;
214 float sbone_torso = m_bones[(int)Bones.Torso].Scale.Z;
215 float sbone_pelvis = m_bones[(int)Bones.Pelvis].Scale.Z;
216 float sbone_hip = m_bones[(int)Bones.Hipright].Scale.Z;
217 float sbone_knee = m_bones[(int)Bones.KneeRight].Scale.Z;
218 float sbone_ank = m_bones[(int)Bones.AnkleRight].Scale.Z;
219 float sbone_foot = m_bones[(int)Bones.FootRight].Scale.Z;
220
221 float v_male = (m_visualParams[(int)VPElement.SHAPE_MALE] == 0) ? 0.0f : 1.0f;
222 sbone_neck += v_male * 0.2f;
223 sbone_chest += v_male * 0.05f;
224 sbone_torso += v_male * 0.05f;
225 sbone_knee += v_male * 0.1f;
226
227 float v_height = convertVP(VPElement.SHAPE_HEIGHT) * 4.3f - 2.3f;
228 sbone_neck += v_height * 0.02f;
229 sbone_chest += v_height * 0.05f;
230 sbone_torso += v_height * 0.05f;
231 sbone_hip += v_height * 0.1f;
232 sbone_knee += v_height * 0.1f;
233
234 float v_hip_len = convertVP(VPElement.SHAPE_HIP_LENGTH) * 2f - 1f;
235 sbone_pelvis += v_hip_len * 0.3f;
236
237 float v_torso_len = convertVP(VPElement.SHAPE_TORSO_LENGTH) * 2f - 1f;
238 sbone_torso += v_torso_len * 0.3f;
239 sbone_pelvis += v_torso_len * 0.1f;
240 sbone_hip += v_torso_len * -0.1f;
241 sbone_knee += v_torso_len * -0.05f;
242
243 float v_head_size = convertVP(VPElement.SHAPE_HEAD_SIZE) * 0.35f - 0.25f;
244 bone_skull += v_head_size * 0.1f;
245 sbone_skull += v_head_size;
246 sbone_head += v_head_size;
247
248 float v_shoes_heel = convertVP(VPElement.SHOES_HEEL_HEIGHT);
249 bone_foot += v_shoes_heel * -0.08f;
250
251 float v_shoes_plat = convertVP(VPElement.SHOES_PLATFORM_HEIGHT);
252 bone_foot += v_shoes_plat * -0.07f;
253
254 float v_leg_lenght = convertVP(VPElement.SHAPE_LEG_LENGTH) * 2f - 1f;
255 sbone_hip += v_leg_lenght * 0.2f;
256 sbone_knee += v_leg_lenght * 0.2f;
257
258 float v_neck_len = convertVP(VPElement.SHAPE_NECK_LENGTH) * 2f - 1f;
259 sbone_neck += v_neck_len * 0.5f;
260
261 float hipmess = bone_hip * sbone_pelvis;
262
263 float pelvisToFoot = hipmess -
264 bone_knee * sbone_hip -
265 bone_ank * sbone_knee -
266 bone_foot * sbone_ank;
267
268
269 float size = 1.4142f * bone_skull * sbone_head +
270 bone_head * sbone_neck +
271 bone_neck * sbone_chest +
272 bone_chest * sbone_torso +
273 bone_torso * sbone_pelvis;
274
275 size += pelvisToFoot;
276
277 m_standSize = new Vector3(0.45f, 0.6f, size);
278 m_feetOffset = 0.5f * size - pelvisToFoot;
279 }
280 }
281}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 6b63d94..7593395 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -3013,7 +3013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3013 } 3013 }
3014 3014
3015 bool result = money.ObjectGiveMoney( 3015 bool result = money.ObjectGiveMoney(
3016 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, UUID.Zero); 3016 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
3017 3017
3018 if (result) 3018 if (result)
3019 return 1; 3019 return 1;
@@ -6384,7 +6384,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6384 } 6384 }
6385 else 6385 else
6386 { 6386 {
6387 agentSize = new LSL_Vector(0.45, 0.6, avatar.Appearance.AvatarHeight); 6387// agentSize = new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight);
6388 Vector3 s = avatar.Appearance.AvatarSize;
6389 agentSize = new LSL_Vector(s.X, s.Y, s.Z);
6388 } 6390 }
6389 return agentSize; 6391 return agentSize;
6390 } 6392 }
@@ -8591,8 +8593,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8591 // and standing avatar since server 1.36 8593 // and standing avatar since server 1.36
8592 LSL_Vector lower; 8594 LSL_Vector lower;
8593 LSL_Vector upper; 8595 LSL_Vector upper;
8596
8597 Vector3 box = presence.Appearance.AvatarBoxSize * 0.5f;
8598
8594 if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID 8599 if (presence.Animator.Animations.ImplicitDefaultAnimation.AnimID
8595 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) 8600 == DefaultAvatarAnimations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
8601/*
8596 { 8602 {
8597 // This is for ground sitting avatars 8603 // This is for ground sitting avatars
8598 float height = presence.Appearance.AvatarHeight / 2.66666667f; 8604 float height = presence.Appearance.AvatarHeight / 2.66666667f;
@@ -8610,6 +8616,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8610 // Adjust to the documented error offsets (see LSL Wiki) 8616 // Adjust to the documented error offsets (see LSL Wiki)
8611 lower += new LSL_Vector(0.05f, 0.05f, 0.05f); 8617 lower += new LSL_Vector(0.05f, 0.05f, 0.05f);
8612 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f); 8618 upper -= new LSL_Vector(0.05f, 0.05f, 0.05f);
8619*/
8620 {
8621 // This is for ground sitting avatars TODO!
8622 lower = new LSL_Vector(-box.X - 0.1125, -box.Y, box.Z * -1.0f);
8623 upper = new LSL_Vector(box.X + 0.1125, box.Y, box.Z * -1.0f);
8624 }
8625 else
8626 {
8627 // This is for standing/flying avatars
8628 lower = new LSL_Vector(-box.X, -box.Y, -box.Z);
8629 upper = new LSL_Vector(box.X, box.Y, box.Z);
8630 }
8613 8631
8614 if (lower.x > upper.x) 8632 if (lower.x > upper.x)
8615 lower.x = upper.x; 8633 lower.x = upper.x;
@@ -12529,7 +12547,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12529 } 12547 }
12530 12548
12531 bool result = money.ObjectGiveMoney( 12549 bool result = money.ObjectGiveMoney(
12532 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn); 12550 m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount);
12533 12551
12534 if (result) 12552 if (result)
12535 { 12553 {
@@ -12931,7 +12949,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12931 12949
12932 case (int)ScriptBaseClass.PRIM_SIZE: 12950 case (int)ScriptBaseClass.PRIM_SIZE:
12933 // as in llGetAgentSize above 12951 // as in llGetAgentSize above
12934 res.Add(new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight)); 12952// res.Add(new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight));
12953 Vector3 s = avatar.Appearance.AvatarSize;
12954 res.Add(new LSL_Vector(s.X, s.Y, s.Z));
12955
12935 break; 12956 break;
12936 12957
12937 case (int)ScriptBaseClass.PRIM_ROTATION: 12958 case (int)ScriptBaseClass.PRIM_ROTATION: