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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations) (download)
Sat Jul 17 05:53:44 2010 UTC (10 years ago) by william
File size: 7950 byte(s)
Add:
#define HAVE_GRN_REFERENCE
when defined enables GRN_REFERENCE class, else disables it (the code does not work)

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6 using gr2lib.core.header;
7
8 namespace gr2lib.core.coretypes.implementation
9 {
10
11 public class grnfileinfo : Igrnfileinfo
12 {
13 private string fromFileName;
14 private ArtToolInfo _ArtToolInfo;
15 private ExporterInfo _ExporterInfo;
16 private List<Texture> _Textures;
17 private List<Material> _Materials;
18 private List<Skeleton> _Skeletons;
19
20
21 //VertexDatas
22 //TriTopologies
23 //Meshes
24 //Models
25 //TrackGroups
26 //Animations
27 //ExtendedData
28
29
30
31 private string filePath;
32 private string fileName;
33
34 public grnfileinfo()
35 {
36 this.filePath = "";
37 this.fileName = FileNameFromPath(this.filePath);
38 }
39 public grnfileinfo(string path)
40 {
41 this.filePath = path;
42 this.fileName = FileNameFromPath(this.filePath);
43 }
44
45 private static string FileNameFromPath(string path)
46 {
47 int lastSlash = path.LastIndexOf('\\');
48 if (lastSlash > 0) return path.Substring(lastSlash + 1);
49 lastSlash = path.LastIndexOf('/');
50 if (lastSlash > 0) return path.Substring(lastSlash + 1);
51 return path;
52 }
53
54 internal static grnfileinfo ReadFromMemory(IntPtr pointer)
55 {
56 try
57 {
58 if (pointer == IntPtr.Zero) return null;
59 native.grnfileinfo native = Helpers.ReadFromMemory<native.grnfileinfo>(pointer);
60 grnfileinfo managed = new grnfileinfo();
61 managed.NativePointer = pointer;
62
63 if (native.ArtToolInfo != IntPtr.Zero)
64 {
65 managed.ArtToolInfo = ArtToolInfo.ReadFromMemory(native.ArtToolInfo);
66 }
67 //else
68 //{
69 // managed.ArtToolInfo = new ArtToolInfo();
70 //}
71 if (native.ExporterInfo != IntPtr.Zero)
72 {
73 managed.ExporterInfo = ExporterInfo.ReadFromMemory(native.ExporterInfo);
74 }
75 //else
76 //{
77 // managed.ExporterInfo = new ExporterInfo();
78 //}
79
80 managed.fromFileName = string.IsNullOrEmpty(native.FromFileName) ? "{null}" : native.FromFileName;
81 managed.ExtendedData = native.ExtendedData;
82
83 int length = 0;
84 if (native.Textures.Pointer != IntPtr.Zero)
85 {
86
87 IntPtr[] textures = Helpers.ReadArrayFromMemory(native.Textures);
88 length = textures.Length;
89 managed.Textures = new List<Texture>(length);
90 foreach (IntPtr ptr in textures)
91 {
92 Texture _tmp = new Texture();
93 _tmp.NativePointer = ptr;
94 managed.Textures.Add(_tmp);
95 }
96 for (int i = 0; i < length; i++)
97 {
98 managed.Textures[i] = Texture.ReadFromMemory(textures[i]);
99 }
100 }
101 else
102 {
103 managed.Textures = new List<Texture>();
104 }
105
106 if (native.Materials.Pointer != IntPtr.Zero)
107 {
108 IntPtr[] materials = Helpers.ReadArrayFromMemory(native.Materials);
109 length = materials.Length;
110 managed.Materials = new List<Material>(length);
111 foreach (IntPtr ptr in materials)
112 {
113 managed.Materials.Add(new Material());
114 }
115 for (int i = 0; i < length; i++)
116 {
117 managed.Materials[i] = Material.ReadFromMemory(materials[i]);
118 }
119 }
120 else
121 {
122 managed.Materials = new List<Material>();
123 }
124
125 if (native.Skeletons.Pointer != IntPtr.Zero)
126 {
127 IntPtr[] skeletons = Helpers.ReadArrayFromMemory(native.Skeletons);
128 length = skeletons.Length;
129 managed.Skeletons = new List<Skeleton>(length);
130 foreach (IntPtr ptr in skeletons)
131 {
132 managed.Skeletons.Add(new Skeleton());
133 }
134 for (int i = 0; i < length; i++)
135 {
136 managed.Skeletons[i] = (Skeleton.ReadFromMemory(skeletons[i]));
137 }
138 }
139 else
140 {
141 managed.Skeletons = new List<Skeleton>();
142 }
143
144 return managed;
145 }
146 catch (Exception ex)
147 {
148 Console.WriteLine(ex.ToString());
149 return default(grnfileinfo);
150 }
151 }
152 //public static grnfileinfo GetFileInfo(granny_file grn_file)
153 //{
154 // //IntPtr file = coreapi.GrannyReadEntireFile(fileName);
155 // grnfileinfo info = null;
156
157 // try
158 // {
159
160 // //int GrannyFileTypeTag = coreapi.GrannyGetFileTypeTag(pointer);
161 // //Console.WriteLine("Granny File Type Tag: 0x{0}", GrannyFileTypeTag.ToString("X8"));
162
163 // //IntPtr pinfo = coreapi.GetFileInfo(grn_file.NativePointer);
164
165 // //coreapi.FreeFile(grn_file.NativePointer);
166
167 // return info;
168 // }
169 // catch (Exception ex)
170 // {
171 // Console.WriteLine(ex.ToString());
172 // return default(grnfileinfo);
173 // }
174 //}
175
176
177 #region Igrnfileinfo Members
178
179
180 public bool HaveArtToolInfo { get { if (this.ArtToolInfo == null) return false; return true; } }
181 public bool HaveExporterInfo { get { if (this.ExporterInfo == null) return false; return true; } }
182 public bool HaveFromFileName { get { if (this.FromFileName == null || this.FromFileName == "") return false; return true; } }
183 public bool HaveTextures { get { if (this.Textures == null || this.Textures.Count <= 0) return false; return true; } }
184 public bool HaveMaterials { get { if (this.Materials == null || this.Materials.Count <= 0) return false; return true; } }
185 public bool HaveSkeletons { get { if (this.Skeletons == null || this.Skeletons.Count <= 0) return false; return true; } }
186
187 public ArtToolInfo ArtToolInfo { get { return _ArtToolInfo; } set { _ArtToolInfo = value; } }
188 public ExporterInfo ExporterInfo { get { return _ExporterInfo; } set { _ExporterInfo = value; } }
189 public string FromFileName { get { return fromFileName; } set { fromFileName = value; } }
190 public List<Texture> Textures { get { return _Textures; } set { _Textures = value; } }
191 public List<Material> Materials { get { return _Materials; } set { _Materials = value; } }
192 public List<Skeleton> Skeletons { get { return _Skeletons; } set { _Skeletons = value; } }
193 #endregion
194
195 #region INativePointer Members
196 private IntPtr _NativePointer;
197 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
198 #endregion
199
200 #region IExtendedData Members
201 private IntPtr _ExtendedData;
202 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
203 #endregion
204 }
205 }

  ViewVC Help
Powered by ViewVC 1.1.22