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

Annotation of /trunk/gr2lib/core/coretypes/implementation/Material.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

1 william 79 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 william 95 using System.Diagnostics;
8 william 79 namespace gr2lib.core.coretypes.implementation
9     {
10    
11 william 86
12 william 79 public class Material : IMaterial
13     {
14 william 80 public Material()
15     {
16 william 83 //this.NativePointer = IntPtr.Zero;
17     //this.ExtendedData = IntPtr.Zero;
18 william 80 this.Name = "";
19     this.Maps = new List<Map>();
20     this.Texture = new Texture();
21 william 86
22 william 80 }
23    
24 william 86 internal static Material ReadFromMemory(IntPtr pointer)
25 william 79 {
26 william 86 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 william 102 catch
35 william 86 {
36 william 95 StackTrace st = new StackTrace(true);
37 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
38     Console.WriteLine(st.ToString());
39     #endif
40 william 86 return default(Material);
41     }
42 william 79 }
43    
44     internal static Material ReadFromNative(native.Material native)
45     {
46 william 86 try
47 william 80 {
48 william 86 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 william 80 }
65 william 102 catch
66 william 79 {
67 william 95 StackTrace st = new StackTrace(true);
68 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
69     Console.WriteLine(st.ToString());
70     #endif
71 william 86 return default(Material);
72 william 79 }
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 william 86 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
87 william 80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
88 william 79 #endregion
89 william 82
90     #region IExtendedData Members
91     private IntPtr _ExtendedData;
92     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
93     #endregion
94 william 79 }
95     }

  ViewVC Help
Powered by ViewVC 1.1.22