/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Bone.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/coretypes/implementation/Bone.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 198 - (show annotations) (download)
Thu Jul 29 08:12:27 2010 UTC (8 years, 11 months ago) by william
File size: 7858 byte(s)
fix 3d bone viewer, to display bones in correct order

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using gr2lib.core.interfaces;
6 using gr2lib.core.helpers;
7 using System.Diagnostics;
8 using gr2lib.core.exceptions;
9 using gr2lib.core.ui.helpers;
10 using System.ComponentModel;
11
12 namespace gr2lib.core.coretypes.implementation
13 {
14 /// <summary>
15 /// Bone Class
16 /// </summary>
17 public class Bone : IBone
18 {
19 #region default IComparable Support
20 /// <summary>
21 /// IComparable Support
22 /// </summary>
23 /// <param name="obj"></param>
24 /// <returns></returns>
25 public int CompareTo(object obj)
26 {
27 return this.Index.CompareTo((obj as Bone).Index);
28 }
29 #endregion
30 /// <summary>
31 /// Gets the string representation of this instance
32 /// </summary>
33 /// <returns></returns>
34 public override string ToString()
35 {
36 return this.Name;
37 }
38
39 //private string _ParentResourceName;
40 /// <summary>
41 /// Get's the parent resource name
42 /// </summary>
43 protected internal string ParentResourceName { get { return "Bones"; } }
44 /// <summary>
45 /// default constructor
46 /// </summary>
47 public Bone()
48 {
49 this.BoneName = "rootBone";
50 this.ParentIndex = -1;
51 this.Transform = new Transform();
52 //this.InverseWorldTransform = new Matrix44();
53 this.LightInfo = new LightInfo();
54 this.CameraInfo = new CameraInfo();
55 this.LodError = 0;
56
57 this.BonePropertyData = new GrannyBonePropertyData();
58
59 }
60
61 internal static Bone ReadFromMemory(IntPtr pointer)
62 {
63 try
64 {
65 if (pointer == IntPtr.Zero) return null;
66 native.Bone native = Helpers.ReadFromMemory<native.Bone>(pointer);
67 Bone managed = Bone.ReadFromNative(native);
68 managed.NativePointer = pointer;
69 return managed;
70 }
71 catch (Exception ex)
72 {
73 StackTrace st = new StackTrace(true);
74 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
75 Granny2ExceptionWriter.WriteToConsole(ex, st);
76 #endif
77 return default(Bone);
78 }
79 }
80
81 internal static Bone ReadFromNative(native.Bone native)
82 {
83 try
84 {
85 Bone managed = new Bone();
86 managed.BoneName = string.IsNullOrEmpty(native.Name) ? "{null}" : native.Name;
87 managed.ParentIndex = native.ParentIndex;
88 managed.Transform = Transform.ReadFromNative(native.Transform);
89 //managed.InverseWorldTransformNode.Matrix = new Geom.Matrix44(native.InverseWorldTransform);
90 //managed.InverseWorldTransform = managed.Transform.Matrix;
91 managed.LodError = native.LodError;
92 managed.LightInfo = LightInfo.ReadFromMemory(native.LightInfo);
93 managed.CameraInfo = CameraInfo.ReadFromMemory(native.CameraInfo);
94 //managed.ExtendedData = native.ExtendedData;
95
96 // BOne property data
97 managed.BonePropertyData = new GrannyBonePropertyData();
98 managed.BonePropertyData.BoneColor = System.Drawing.Color.LimeGreen;
99 managed.BonePropertyData.BoneJointColor = System.Drawing.Color.White;
100
101
102 return managed;
103 }
104 catch (Exception ex)
105 {
106 StackTrace st = new StackTrace(true);
107 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
108 Granny2ExceptionWriter.WriteToConsole(ex, st);
109 #endif
110 return default(Bone);
111 }
112 }
113
114 #region IBone Members
115
116 private string _BoneName;
117 private int _ParentIndex;
118 private Transform _Transform;
119 //private Matrix44 _InverseWorldTransform;
120 private LightInfo _LightInfo;
121 private CameraInfo _CameraInfo;
122 private int _LodError;
123
124
125 /// <summary>
126 /// Get/set the bone name
127 /// </summary>
128 public string BoneName { get { return _BoneName; } set { _BoneName = value; } }
129 /// <summary>
130 /// Get/set the ParentIndex
131 /// </summary>
132 public int ParentIndex { get { return _ParentIndex; } set { _ParentIndex = value; } }
133 /// <summary>
134 /// Get/set the Transform
135 /// </summary>
136 public Transform Transform { get { return _Transform; } set { _Transform = value; } }
137 /// <summary>
138 /// Get/set the InverseWorldTransform
139 /// </summary>
140 public Matrix44 InverseWorldTransform { get { return this.Transform.Matrix; } }//set { _InverseWorldTransform = value; } }
141
142 /// <summary>
143 /// Get a value indicating if this instance has LightInfo
144 /// </summary>
145 public bool HasLightInfo { get { if (this.LightInfo == null) { return false; } else { return true; } } }
146 /// <summary>
147 /// Get a value indicating if this instance has CameraInfo
148 /// </summary>
149 public bool HasCameraInfo { get { if (this.CameraInfo == null) { return false; } else { return true; } } }
150
151 /// <summary>
152 /// Get/set the LightInfo
153 /// </summary>
154 public LightInfo LightInfo { get { return _LightInfo; } set { _LightInfo = value; } }
155 /// <summary>
156 /// Get/set the CameraInfo
157 /// </summary>
158 public CameraInfo CameraInfo { get { return _CameraInfo; } set { _CameraInfo = value; } }
159 /// <summary>
160 /// Get/set the LodError
161 /// </summary>
162 public int LodError { get { return _LodError; } set { _LodError = value; } }
163
164
165
166 private GrannyBonePropertyData _BonePropertyData;
167 /// <summary>
168 /// Extra Bone Property Data, Not Used by Granny2
169 /// </summary>
170 [RefreshPropertiesAttribute(RefreshProperties.All)]
171 public GrannyBonePropertyData BonePropertyData { get { return _BonePropertyData; } set { _BonePropertyData = value; } }
172 #endregion
173
174 #region INativePointer Members
175 private IntPtr _NativePointer;
176 /// <summary>
177 /// When used in a derived class, gets the native pointer for this instance
178 /// </summary>
179 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
180 #endregion
181
182 #region IExtendedData Members
183 private IntPtr _ExtendedData;
184 /// <summary>
185 /// When used in a derived class, gets the ExtendedData pointer for this instance
186 /// </summary>
187 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
188 #endregion
189
190 #region IResource Members
191 private int _index;
192 [RefreshPropertiesAttribute(RefreshProperties.All)]
193 public int Index { get { return _index; } set { _index = value; } }
194 #endregion
195 #region IEmbeddedResource Members
196 [RefreshPropertiesAttribute(RefreshProperties.All)]
197 internal string IndexName { get { return new GrannyRigResource("Skeleton", this.Index, this.Name).ResourceBlockIndexFormat; } }
198 [RefreshPropertiesAttribute(RefreshProperties.All)]
199 internal string FullName { get { return new GrannyRigResource("Skeleton", this.Index, this.Name).ResourceBlockFormat; } }
200 [RefreshPropertiesAttribute(RefreshProperties.All)]
201 internal string Name { get { return this.BoneName; } set { this.BoneName = value; } }
202 #endregion
203 }
204 }

  ViewVC Help
Powered by ViewVC 1.1.22