ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/gr2lib/trunk/gr2lib/core/coretypes/implementation/Material.cs
Revision: 106
Committed: Sat Jul 17 14:52:37 2010 UTC (12 years, 2 months ago) by william
File size: 3360 byte(s)
Log Message:
implement Granny2ExceptionWriter

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using gr2lib.core.helpers;
6 using gr2lib.core.interfaces;
7 using System.Diagnostics;
8 using gr2lib.core.exceptions;
9 namespace gr2lib.core.coretypes.implementation
10 {
11
12
13 public class Material : IMaterial
14 {
15 public Material()
16 {
17 //this.NativePointer = IntPtr.Zero;
18 //this.ExtendedData = IntPtr.Zero;
19 this.Name = "";
20 this.Maps = new List<Map>();
21 this.Texture = new Texture();
22
23 }
24
25 internal static Material ReadFromMemory(IntPtr pointer)
26 {
27 try
28 {
29 if (pointer == IntPtr.Zero) return null;
30 native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
31 Material managed = ReadFromNative(native);
32 managed.NativePointer = pointer;
33 return managed;
34 }
35 catch (Exception ex)
36 {
37 StackTrace st = new StackTrace(true);
38 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
39 Granny2ExceptionWriter.WriteToConsole(ex,st);
40 #endif
41 return default(Material);
42 }
43 }
44
45 internal static Material ReadFromNative(native.Material native)
46 {
47 try
48 {
49 Material managed = new Material();
50 managed.Name = native.Name;
51 IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
52 int length = maps.Length;
53 managed.Maps = new List<Map>(length);
54 foreach (IntPtr ptr in maps)
55 {
56 managed.Maps.Add(new Map());
57 }
58 for (int i = 0; i < length; i++)
59 {
60 managed.Maps[i] = Map.ReadFromMemory(maps[i]);
61 }
62 managed.Texture = Texture.ReadFromMemory(native.Texture);
63 managed.ExtendedData = native.ExtendedData;
64 return managed;
65 }
66 catch (Exception ex)
67 {
68 StackTrace st = new StackTrace(true);
69 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
70 Granny2ExceptionWriter.WriteToConsole(ex,st);
71 #endif
72 return default(Material);
73 }
74 }
75
76 #region INativePointer Members
77 private IntPtr _NativePointer;
78 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
79 #endregion
80
81 #region IMaterial Members
82 private string _Name;
83 private List<Map> _Maps;
84 private Texture _Texture;
85 public string Name { get { return _Name; } set { _Name = value; } }
86 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
87 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
88 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
89 #endregion
90
91 #region IExtendedData Members
92 private IntPtr _ExtendedData;
93 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
94 #endregion
95 }
96 }