/[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 82 - (show annotations) (download)
Thu Jul 15 23:36:04 2010 UTC (9 years, 6 months ago) by william
File size: 2573 byte(s)
move ExtenededData to it's own interface and make the classes, that need it, implement it.

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 namespace gr2lib.core.coretypes.implementation
8 {
9
10
11 public class Material : IMaterial
12 {
13 public Material()
14 {
15 this.NativePointer = IntPtr.Zero;
16 this.Name = "";
17 this.Maps = new List<Map>();
18 this.Texture = new Texture();
19 this.ExtendedData = IntPtr.Zero;
20 }
21
22 internal static Material ReadFromMemory(IntPtr pointer)
23 {
24 if (pointer == IntPtr.Zero) return null;
25 native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
26 Material managed = ReadFromNative(native);
27 managed.NativePointer = pointer;
28 return managed;
29 }
30
31 internal static Material ReadFromNative(native.Material native)
32 {
33 Material managed = new Material();
34 managed.Name = native.Name;
35 IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
36 int length = maps.Length;
37 managed.Maps = new List<Map>(length);
38 foreach (IntPtr ptr in maps)
39 {
40 managed.Maps.Add(new Map());
41 }
42 for (int i = 0; i < length; i++)
43 {
44 managed.Maps[i] = Map.ReadFromMemory(maps[i]);
45 }
46 managed.Texture = Texture.ReadFromMemory(native.Texture);
47 managed.ExtendedData = native.ExtendedData;
48 return managed;
49 }
50
51 #region INativePointer Members
52 private IntPtr _NativePointer;
53 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
54 #endregion
55
56 #region IMaterial Members
57 private string _Name;
58 private List<Map> _Maps;
59 private Texture _Texture;
60 public string Name { get { return _Name; } set { _Name = value; } }
61 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
62 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
63 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
64 #endregion
65
66 #region IExtendedData Members
67 private IntPtr _ExtendedData;
68 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
69 #endregion
70 }
71 }

  ViewVC Help
Powered by ViewVC 1.1.22