aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AvatarSkeleton.cs
diff options
context:
space:
mode:
authorUbitUmarov2012-12-07 13:47:58 +0000
committerUbitUmarov2012-12-07 13:47:58 +0000
commit135e0ea853203cbad5790ac9f0b21d67f8828af8 (patch)
tree7b60c85aa16123a109b3afae4618359abd272dd9 /OpenSim/Framework/AvatarSkeleton.cs
parentavatar collision plane send to viewer is only relative to feet. change (diff)
downloadopensim-SC-135e0ea853203cbad5790ac9f0b21d67f8828af8.zip
opensim-SC-135e0ea853203cbad5790ac9f0b21d67f8828af8.tar.gz
opensim-SC-135e0ea853203cbad5790ac9f0b21d67f8828af8.tar.bz2
opensim-SC-135e0ea853203cbad5790ac9f0b21d67f8828af8.tar.xz
*TEST* add some avatar skeleton information and use it to calculate avatar
height and bounding box. Change LSL acording.
Diffstat (limited to 'OpenSim/Framework/AvatarSkeleton.cs')
-rw-r--r--OpenSim/Framework/AvatarSkeleton.cs281
1 files changed, 281 insertions, 0 deletions
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}