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

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

  ViewVC Help
Powered by ViewVC 1.1.22