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

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 using System.ComponentModel;
10 using gr2lib.core.ui.helpers;
11 namespace gr2lib.core.coretypes.implementation
12 {
13 /// <summary>
14 /// Material class
15 /// </summary>
16 public class Material : IMaterial
17 {
18 //private string _ParentResourceName;
19 /// <summary>
20 /// 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 /// default constructor
35 /// </summary>
36 public Material()
37 {
38 //this.NativePointer = IntPtr.Zero;
39 //this.ExtendedData = IntPtr.Zero;
40 this.Name = "";
41 this.Maps = new List<Map>();
42 this.Texture = new Texture();
43
44 }
45
46 internal static Material ReadFromMemory(IntPtr pointer)
47 {
48 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 catch (Exception ex)
57 {
58 StackTrace st = new StackTrace(true);
59 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
60 Granny2ExceptionWriter.WriteToConsole(ex,st);
61 #endif
62 return default(Material);
63 }
64 }
65
66 internal static Material ReadFromNative(native.Material native)
67 {
68 try
69 {
70 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 }
87 catch (Exception ex)
88 {
89 StackTrace st = new StackTrace(true);
90 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
91 Granny2ExceptionWriter.WriteToConsole(ex,st);
92 #endif
93 return default(Material);
94 }
95 }
96
97 #region INativePointer Members
98 private IntPtr _NativePointer;
99 /// <summary>
100 /// When used in a derived class, gets the native pointer for this instance
101 /// </summary>
102 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
103 #endregion
104
105 #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 #region IMaterial Members
114 private string _Name;
115 private List<Map> _Maps;
116 private Texture _Texture;
117
118 /// <summary>
119 /// get or set the material name
120 /// </summary>
121 public string Name { get { return _Name; } set { _Name = value; } }
122 /// <summary>
123 /// get the maps associated with this instance
124 /// </summary>
125 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
126 /// <summary>
127 /// get the texture associated with this instance
128 /// </summary>
129 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
130 /// <summary>
131 /// Indicates if this instance is a texture or not
132 /// </summary>
133 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
134 #endregion
135
136
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 }
151 }

  ViewVC Help
Powered by ViewVC 1.1.22