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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 198 - (hide annotations) (download)
Thu Jul 29 08:12:27 2010 UTC (10 years, 9 months ago) by william
File size: 5663 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 166 using System.Windows.Forms;
11 william 196 using System.ComponentModel;
12 william 83
13     namespace gr2lib.core.coretypes.implementation
14     {
15 william 187 /// <summary>
16     /// Skeleton Class
17     /// </summary>
18 william 196 public class Skeleton : ISkeleton
19     {
20     //private string _ParentResourceName;
21 william 187 /// <summary>
22 william 196 /// Get's the parent resource name
23     /// </summary>
24     protected internal string ParentResourceName { get { return "Skeletons"; } }
25    
26     /// <summary>
27     /// Gets the string representation of this instance
28     /// </summary>
29     /// <returns></returns>
30     public override string ToString()
31     {
32     return this.Name;
33     }
34    
35     /// <summary>
36 william 187 /// default constructor
37     /// </summary>
38 william 196 public Skeleton()
39 william 83 {
40     this.SkeletonName = "Skeleton";
41     this.Bones = new List<Bone>();
42     this.LodType = 0;
43     //this.NativePointer = IntPtr.Zero;
44     //this.ExtendedData = IntPtr.Zero;
45     }
46    
47    
48     internal static Skeleton ReadFromMemory(IntPtr pointer)
49     {
50 william 86 try
51     {
52 william 83 if (pointer == IntPtr.Zero) return null;
53     native.Skeleton native = Helpers.ReadFromMemory<native.Skeleton>(pointer);
54     Skeleton managed = ReadFromNative(native);
55     managed.NativePointer = pointer;
56     return managed;
57 william 86 }
58 william 106 catch (Exception ex)
59 william 86 {
60 william 95 StackTrace st = new StackTrace(true);
61 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
62 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
63 william 102 #endif
64 william 86 return default(Skeleton);
65     }
66 william 83 }
67    
68     internal static Skeleton ReadFromNative(native.Skeleton native)
69     {
70 william 86 try
71     {
72 william 83 Skeleton managed = new Skeleton();
73     managed.SkeletonName = string.IsNullOrEmpty(native.Name) ? "{null}" : native.Name;
74     IntPtr[] bones = Helpers.ReadPtrArrayFromMemory<native.Bone>(native.Bones);
75     int boneLength = bones.Length;
76    
77     foreach (IntPtr ptr in bones)
78     {
79     managed.Bones.Add(new Bone());
80 william 166 Application.DoEvents();
81 william 83 }
82    
83     for (int i = 0; i < boneLength; i++)
84     {
85     managed.Bones[i] = Bone.ReadFromMemory(bones[i]);
86 william 198 managed.Bones[i].Index = i;
87 william 166 Application.DoEvents();
88 william 83 }
89     managed.LodType = native.LodType;
90     managed.ExtendedData = native.ExtendedData;
91     return managed;
92 william 86 }
93 william 106 catch (Exception ex)
94 william 86 {
95 william 95 StackTrace st = new StackTrace(true);
96 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
97 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
98 william 102 #endif
99 william 86 return default(Skeleton);
100     }
101 william 83 }
102    
103     #region ISkeleton Members
104    
105     private string _SkeletonName;
106     private List<Bone> _Bones;
107     private int _LodType;
108    
109 william 187 /// <summary>
110 william 196 /// View Bones using 3d Bone Viwer
111     /// </summary>
112     [RefreshPropertiesAttribute(RefreshProperties.All)]
113     public BoneViewerHelper ViewBones3D { get { return new BoneViewerHelper(this.Bones); } set { this.Bones = value.BoneList; } }
114    
115     /// <summary>
116 william 187 /// get/set name
117     /// </summary>
118 william 83 public string SkeletonName { get { return _SkeletonName; } set { _SkeletonName = value; } }
119 william 187 /// <summary>
120     /// get/set bones
121     /// </summary>
122 william 83 public List<Bone> Bones { get { return _Bones; } set { _Bones = value; } }
123 william 187 /// <summary>
124     /// get/set lodtype
125     /// </summary>
126 william 83 public int LodType { get { return _LodType; } set { _LodType = value; } }
127     #endregion
128    
129     #region INativePointer Members
130     private IntPtr _NativePointer;
131 william 181 /// <summary>
132     /// When used in a derived class, gets the native pointer for this instance
133     /// </summary>
134 william 83 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
135     #endregion
136    
137     #region IExtendedData Members
138     private IntPtr _ExtendedData;
139 william 181 /// <summary>
140     /// When used in a derived class, gets the ExtendedData pointer for this instance
141     /// </summary>
142 william 83 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
143     #endregion
144 william 196
145     #region IResource Members
146     private int _index;
147     [RefreshPropertiesAttribute(RefreshProperties.All)]
148     internal int Index { get { return _index; } set { _index = value; } }
149     #endregion
150     #region IEmbeddedResource Members
151     [RefreshPropertiesAttribute(RefreshProperties.All)]
152     internal string IndexName { get { return new GrannyRigResource("Skeleton", this.Index, this.Name).ResourceBlockIndexFormat; } }
153     [RefreshPropertiesAttribute(RefreshProperties.All)]
154     internal string FullName { get { return new GrannyRigResource("Skeleton", this.Index, this.Name).ResourceBlockFormat; } }
155     [RefreshPropertiesAttribute(RefreshProperties.All)]
156     internal string Name { get { return this.SkeletonName; } set { this.SkeletonName = value; } }
157     #endregion
158 william 83 }
159     }

  ViewVC Help
Powered by ViewVC 1.1.22