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.Windows.Forms; |
11 |
using System.ComponentModel; |
12 |
|
13 |
namespace gr2lib.core.coretypes.implementation |
14 |
{ |
15 |
/// <summary> |
16 |
/// Skeleton Class |
17 |
/// </summary> |
18 |
public class Skeleton : ISkeleton |
19 |
{ |
20 |
//private string _ParentResourceName; |
21 |
/// <summary> |
22 |
/// 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 |
/// default constructor |
37 |
/// </summary> |
38 |
public Skeleton() |
39 |
{ |
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 |
try |
51 |
{ |
52 |
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 |
} |
58 |
catch (Exception ex) |
59 |
{ |
60 |
StackTrace st = new StackTrace(true); |
61 |
#if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE |
62 |
Granny2ExceptionWriter.WriteToConsole(ex,st); |
63 |
#endif |
64 |
return default(Skeleton); |
65 |
} |
66 |
} |
67 |
|
68 |
internal static Skeleton ReadFromNative(native.Skeleton native) |
69 |
{ |
70 |
try |
71 |
{ |
72 |
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 |
Application.DoEvents(); |
81 |
} |
82 |
|
83 |
for (int i = 0; i < boneLength; i++) |
84 |
{ |
85 |
managed.Bones[i] = Bone.ReadFromMemory(bones[i]); |
86 |
managed.Bones[i].Index = i; |
87 |
Application.DoEvents(); |
88 |
} |
89 |
managed.LodType = native.LodType; |
90 |
managed.ExtendedData = native.ExtendedData; |
91 |
return managed; |
92 |
} |
93 |
catch (Exception ex) |
94 |
{ |
95 |
StackTrace st = new StackTrace(true); |
96 |
#if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE |
97 |
Granny2ExceptionWriter.WriteToConsole(ex,st); |
98 |
#endif |
99 |
return default(Skeleton); |
100 |
} |
101 |
} |
102 |
|
103 |
#region ISkeleton Members |
104 |
|
105 |
private string _SkeletonName; |
106 |
private List<Bone> _Bones; |
107 |
private int _LodType; |
108 |
|
109 |
/// <summary> |
110 |
/// 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 |
/// get/set name |
117 |
/// </summary> |
118 |
public string SkeletonName { get { return _SkeletonName; } set { _SkeletonName = value; } } |
119 |
/// <summary> |
120 |
/// get/set bones |
121 |
/// </summary> |
122 |
public List<Bone> Bones { get { return _Bones; } set { _Bones = value; } } |
123 |
/// <summary> |
124 |
/// get/set lodtype |
125 |
/// </summary> |
126 |
public int LodType { get { return _LodType; } set { _LodType = value; } } |
127 |
#endregion |
128 |
|
129 |
#region INativePointer Members |
130 |
private IntPtr _NativePointer; |
131 |
/// <summary> |
132 |
/// When used in a derived class, gets the native pointer for this instance |
133 |
/// </summary> |
134 |
public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } } |
135 |
#endregion |
136 |
|
137 |
#region IExtendedData Members |
138 |
private IntPtr _ExtendedData; |
139 |
/// <summary> |
140 |
/// When used in a derived class, gets the ExtendedData pointer for this instance |
141 |
/// </summary> |
142 |
public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } } |
143 |
#endregion |
144 |
|
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 |
} |
159 |
} |