/[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 196 - (hide annotations) (download)
Thu Jul 29 07:47:26 2010 UTC (9 years, 5 months ago) by william
File size: 5551 byte(s)
bulk commit

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 196 using System.ComponentModel;
10     using gr2lib.core.ui.helpers;
11 william 79 namespace gr2lib.core.coretypes.implementation
12     {
13 william 187 /// <summary>
14     /// Material class
15     /// </summary>
16 william 79 public class Material : IMaterial
17     {
18 william 196 //private string _ParentResourceName;
19 william 187 /// <summary>
20 william 196 /// Get's the parent resource name
21     /// </summary>
22     protected internal string ParentResourceName { get { return "Materials"; } }
23    
24     /// <summary>
25     /// Gets the string representation of this instance
26     /// </summary>
27     /// <returns></returns>
28     public override string ToString()
29     {
30     return this.Name;
31     }
32    
33     /// <summary>
34 william 187 /// default constructor
35     /// </summary>
36 william 80 public Material()
37     {
38 william 83 //this.NativePointer = IntPtr.Zero;
39     //this.ExtendedData = IntPtr.Zero;
40 william 80 this.Name = "";
41     this.Maps = new List<Map>();
42     this.Texture = new Texture();
43 william 86
44 william 80 }
45    
46 william 86 internal static Material ReadFromMemory(IntPtr pointer)
47 william 79 {
48 william 86 try
49     {
50     if (pointer == IntPtr.Zero) return null;
51     native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
52     Material managed = ReadFromNative(native);
53     managed.NativePointer = pointer;
54     return managed;
55     }
56 william 106 catch (Exception ex)
57 william 86 {
58 william 95 StackTrace st = new StackTrace(true);
59 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
60 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
61 william 102 #endif
62 william 86 return default(Material);
63     }
64 william 79 }
65    
66     internal static Material ReadFromNative(native.Material native)
67     {
68 william 86 try
69 william 80 {
70 william 86 Material managed = new Material();
71     managed.Name = native.Name;
72     IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
73     int length = maps.Length;
74     managed.Maps = new List<Map>(length);
75     foreach (IntPtr ptr in maps)
76     {
77     managed.Maps.Add(new Map());
78     }
79     for (int i = 0; i < length; i++)
80     {
81     managed.Maps[i] = Map.ReadFromMemory(maps[i]);
82     }
83     managed.Texture = Texture.ReadFromMemory(native.Texture);
84     managed.ExtendedData = native.ExtendedData;
85     return managed;
86 william 80 }
87 william 106 catch (Exception ex)
88 william 79 {
89 william 95 StackTrace st = new StackTrace(true);
90 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
91 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
92 william 102 #endif
93 william 86 return default(Material);
94 william 79 }
95     }
96    
97     #region INativePointer Members
98     private IntPtr _NativePointer;
99 william 181 /// <summary>
100     /// When used in a derived class, gets the native pointer for this instance
101     /// </summary>
102 william 79 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
103     #endregion
104    
105 william 181 #region IExtendedData Members
106     private IntPtr _ExtendedData;
107     /// <summary>
108     /// When used in a derived class, gets the ExtendedData pointer for this instance
109     /// </summary>
110     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
111     #endregion
112    
113 william 79 #region IMaterial Members
114     private string _Name;
115     private List<Map> _Maps;
116     private Texture _Texture;
117 william 187
118     /// <summary>
119     /// get or set the material name
120     /// </summary>
121 william 79 public string Name { get { return _Name; } set { _Name = value; } }
122 william 187 /// <summary>
123     /// get the maps associated with this instance
124     /// </summary>
125 william 79 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
126 william 187 /// <summary>
127     /// get the texture associated with this instance
128     /// </summary>
129 william 86 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
130 william 187 /// <summary>
131     /// Indicates if this instance is a texture or not
132     /// </summary>
133 william 80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
134 william 79 #endregion
135 william 82
136 william 196
137     #region IResource Members
138     private int _index;
139     [RefreshPropertiesAttribute(RefreshProperties.All)]
140     internal int Index { get { return _index; } set { _index = value; } }
141     #endregion
142     #region IEmbeddedResource Members
143     [RefreshPropertiesAttribute(RefreshProperties.All)]
144     internal string IndexName { get { return new GrannyRigResource("Material", this.Index, this.Name).ResourceBlockIndexFormat; } }
145     [RefreshPropertiesAttribute(RefreshProperties.All)]
146     internal string FullName { get { return new GrannyRigResource("Material", this.Index, this.Name).ResourceBlockFormat; } }
147     //[RefreshPropertiesAttribute(RefreshProperties.All)]
148     //internal string Name { get { return this.FromFileName; } set { this.FromFileName = value; } }
149     #endregion
150 william 79 }
151     }

  ViewVC Help
Powered by ViewVC 1.1.22