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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 william 83 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 william 95 using System.Diagnostics;
8 william 106 using gr2lib.core.exceptions;
9 william 119 using gr2lib.core.ui.helpers;
10 william 196 using System.ComponentModel;
11 william 83
12     namespace gr2lib.core.coretypes.implementation
13     {
14 william 187 /// <summary>
15     /// Bone Class
16     /// </summary>
17 william 196 public class Bone : IBone
18 william 83 {
19 william 198 #region default IComparable Support
20 william 187 /// <summary>
21 william 198 /// 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 william 196 /// 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 william 187 /// default constructor
46     /// </summary>
47 william 196 public Bone()
48 william 83 {
49     this.BoneName = "rootBone";
50     this.ParentIndex = -1;
51     this.Transform = new Transform();
52 william 196 //this.InverseWorldTransform = new Matrix44();
53 william 83 this.LightInfo = new LightInfo();
54     this.CameraInfo = new CameraInfo();
55     this.LodError = 0;
56 william 196
57     this.BonePropertyData = new GrannyBonePropertyData();
58    
59 william 83 }
60    
61     internal static Bone ReadFromMemory(IntPtr pointer)
62     {
63 william 86 try
64     {
65 william 198 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 william 86 }
71 william 106 catch (Exception ex)
72 william 86 {
73 william 95 StackTrace st = new StackTrace(true);
74 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
75 william 198 Granny2ExceptionWriter.WriteToConsole(ex, st);
76 william 102 #endif
77 william 86 return default(Bone);
78     }
79 william 83 }
80    
81     internal static Bone ReadFromNative(native.Bone native)
82     {
83 william 86 try
84     {
85 william 198 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 william 83
96 william 198 // 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 william 86 }
104 william 106 catch (Exception ex)
105 william 86 {
106 william 95 StackTrace st = new StackTrace(true);
107 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
108 william 198 Granny2ExceptionWriter.WriteToConsole(ex, st);
109 william 102 #endif
110 william 86 return default(Bone);
111     }
112 william 83 }
113    
114     #region IBone Members
115    
116     private string _BoneName;
117     private int _ParentIndex;
118     private Transform _Transform;
119 william 196 //private Matrix44 _InverseWorldTransform;
120 william 83 private LightInfo _LightInfo;
121     private CameraInfo _CameraInfo;
122     private int _LodError;
123    
124    
125 william 187 /// <summary>
126     /// Get/set the bone name
127     /// </summary>
128 william 83 public string BoneName { get { return _BoneName; } set { _BoneName = value; } }
129 william 187 /// <summary>
130     /// Get/set the ParentIndex
131     /// </summary>
132 william 83 public int ParentIndex { get { return _ParentIndex; } set { _ParentIndex = value; } }
133 william 187 /// <summary>
134     /// Get/set the Transform
135     /// </summary>
136 william 83 public Transform Transform { get { return _Transform; } set { _Transform = value; } }
137 william 187 /// <summary>
138     /// Get/set the InverseWorldTransform
139     /// </summary>
140 william 196 public Matrix44 InverseWorldTransform { get { return this.Transform.Matrix; } }//set { _InverseWorldTransform = value; } }
141 william 95
142 william 187 /// <summary>
143     /// Get a value indicating if this instance has LightInfo
144     /// </summary>
145 william 83 public bool HasLightInfo { get { if (this.LightInfo == null) { return false; } else { return true; } } }
146 william 187 /// <summary>
147     /// Get a value indicating if this instance has CameraInfo
148     /// </summary>
149 william 83 public bool HasCameraInfo { get { if (this.CameraInfo == null) { return false; } else { return true; } } }
150    
151 william 187 /// <summary>
152     /// Get/set the LightInfo
153     /// </summary>
154 william 83 public LightInfo LightInfo { get { return _LightInfo; } set { _LightInfo = value; } }
155 william 187 /// <summary>
156     /// Get/set the CameraInfo
157     /// </summary>
158 william 83 public CameraInfo CameraInfo { get { return _CameraInfo; } set { _CameraInfo = value; } }
159 william 187 /// <summary>
160     /// Get/set the LodError
161     /// </summary>
162 william 83 public int LodError { get { return _LodError; } set { _LodError = value; } }
163 william 196
164    
165    
166 william 198 private GrannyBonePropertyData _BonePropertyData;
167     /// <summary>
168     /// Extra Bone Property Data, Not Used by Granny2
169     /// </summary>
170 william 196 [RefreshPropertiesAttribute(RefreshProperties.All)]
171     public GrannyBonePropertyData BonePropertyData { get { return _BonePropertyData; } set { _BonePropertyData = value; } }
172 william 83 #endregion
173    
174     #region INativePointer Members
175     private IntPtr _NativePointer;
176 william 181 /// <summary>
177     /// When used in a derived class, gets the native pointer for this instance
178     /// </summary>
179 william 83 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
180     #endregion
181    
182     #region IExtendedData Members
183     private IntPtr _ExtendedData;
184 william 181 /// <summary>
185     /// When used in a derived class, gets the ExtendedData pointer for this instance
186     /// </summary>
187 william 83 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
188     #endregion
189 william 196
190     #region IResource Members
191     private int _index;
192     [RefreshPropertiesAttribute(RefreshProperties.All)]
193 william 198 public int Index { get { return _index; } set { _index = value; } }
194 william 196 #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 william 83 }
204     }

  ViewVC Help
Powered by ViewVC 1.1.22