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, 4 months ago) by william
File size: 3360 byte(s)
Log Message:
implement Granny2ExceptionWriter

File Contents

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