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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (show annotations) (download)
Sat Jul 17 13:54:18 2010 UTC (9 years, 2 months ago) by william
File size: 3129 byte(s)
add compiler directive to write exceptions to console or not

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
9 namespace gr2lib.core.coretypes.implementation
10 {
11 public class Skeleton : ISkeleton
12 {
13
14 public Skeleton()
15 {
16 this.SkeletonName = "Skeleton";
17 this.Bones = new List<Bone>();
18 this.LodType = 0;
19 //this.NativePointer = IntPtr.Zero;
20 //this.ExtendedData = IntPtr.Zero;
21 }
22
23
24 internal static Skeleton ReadFromMemory(IntPtr pointer)
25 {
26 try
27 {
28 if (pointer == IntPtr.Zero) return null;
29 native.Skeleton native = Helpers.ReadFromMemory<native.Skeleton>(pointer);
30 Skeleton managed = ReadFromNative(native);
31 managed.NativePointer = pointer;
32 return managed;
33 }
34 catch
35 {
36 StackTrace st = new StackTrace(true);
37 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
38 Console.WriteLine(st.ToString());
39 #endif
40 return default(Skeleton);
41 }
42 }
43
44 internal static Skeleton ReadFromNative(native.Skeleton native)
45 {
46 try
47 {
48 Skeleton managed = new Skeleton();
49 managed.SkeletonName = string.IsNullOrEmpty(native.Name) ? "{null}" : native.Name;
50 IntPtr[] bones = Helpers.ReadPtrArrayFromMemory<native.Bone>(native.Bones);
51 int boneLength = bones.Length;
52
53 foreach (IntPtr ptr in bones)
54 {
55 managed.Bones.Add(new Bone());
56 }
57
58 for (int i = 0; i < boneLength; i++)
59 {
60 managed.Bones[i] = Bone.ReadFromMemory(bones[i]);
61 }
62 managed.LodType = native.LodType;
63 managed.ExtendedData = native.ExtendedData;
64 return managed;
65 }
66 catch
67 {
68 StackTrace st = new StackTrace(true);
69 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
70 Console.WriteLine(st.ToString());
71 #endif
72 return default(Skeleton);
73 }
74 }
75
76 #region ISkeleton Members
77
78 private string _SkeletonName;
79 private List<Bone> _Bones;
80 private int _LodType;
81
82 public string SkeletonName { get { return _SkeletonName; } set { _SkeletonName = value; } }
83 public List<Bone> Bones { get { return _Bones; } set { _Bones = value; } }
84 public int LodType { get { return _LodType; } set { _LodType = value; } }
85 #endregion
86
87 #region INativePointer Members
88 private IntPtr _NativePointer;
89 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
90 #endregion
91
92 #region IExtendedData Members
93 private IntPtr _ExtendedData;
94 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
95 #endregion
96 }
97 }

  ViewVC Help
Powered by ViewVC 1.1.22