/[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 187 - (show annotations) (download)
Sat Jul 24 04:16:43 2010 UTC (9 years, 3 months ago) by william
File size: 4178 byte(s)
continue to add xml documentation

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 /// <summary>
12 /// Material class
13 /// </summary>
14 public class Material : IMaterial
15 {
16 /// <summary>
17 /// default constructor
18 /// </summary>
19 public Material()
20 {
21 //this.NativePointer = IntPtr.Zero;
22 //this.ExtendedData = IntPtr.Zero;
23 this.Name = "";
24 this.Maps = new List<Map>();
25 this.Texture = new Texture();
26
27 }
28
29 internal static Material ReadFromMemory(IntPtr pointer)
30 {
31 try
32 {
33 if (pointer == IntPtr.Zero) return null;
34 native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
35 Material managed = ReadFromNative(native);
36 managed.NativePointer = pointer;
37 return managed;
38 }
39 catch (Exception ex)
40 {
41 StackTrace st = new StackTrace(true);
42 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
43 Granny2ExceptionWriter.WriteToConsole(ex,st);
44 #endif
45 return default(Material);
46 }
47 }
48
49 internal static Material ReadFromNative(native.Material native)
50 {
51 try
52 {
53 Material managed = new Material();
54 managed.Name = native.Name;
55 IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
56 int length = maps.Length;
57 managed.Maps = new List<Map>(length);
58 foreach (IntPtr ptr in maps)
59 {
60 managed.Maps.Add(new Map());
61 }
62 for (int i = 0; i < length; i++)
63 {
64 managed.Maps[i] = Map.ReadFromMemory(maps[i]);
65 }
66 managed.Texture = Texture.ReadFromMemory(native.Texture);
67 managed.ExtendedData = native.ExtendedData;
68 return managed;
69 }
70 catch (Exception ex)
71 {
72 StackTrace st = new StackTrace(true);
73 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
74 Granny2ExceptionWriter.WriteToConsole(ex,st);
75 #endif
76 return default(Material);
77 }
78 }
79
80 #region INativePointer Members
81 private IntPtr _NativePointer;
82 /// <summary>
83 /// When used in a derived class, gets the native pointer for this instance
84 /// </summary>
85 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
86 #endregion
87
88 #region IExtendedData Members
89 private IntPtr _ExtendedData;
90 /// <summary>
91 /// When used in a derived class, gets the ExtendedData pointer for this instance
92 /// </summary>
93 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
94 #endregion
95
96 #region IMaterial Members
97 private string _Name;
98 private List<Map> _Maps;
99 private Texture _Texture;
100
101 /// <summary>
102 /// get or set the material name
103 /// </summary>
104 public string Name { get { return _Name; } set { _Name = value; } }
105 /// <summary>
106 /// get the maps associated with this instance
107 /// </summary>
108 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
109 /// <summary>
110 /// get the texture associated with this instance
111 /// </summary>
112 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
113 /// <summary>
114 /// Indicates if this instance is a texture or not
115 /// </summary>
116 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
117 #endregion
118
119 }
120 }

  ViewVC Help
Powered by ViewVC 1.1.22