/[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 80 - (hide annotations) (download)
Thu Jul 15 22:18:17 2010 UTC (9 years, 6 months ago) by william
File size: 2515 byte(s)
fix issue with Lists, and add IsTexture to Material class (non-texture materials have a null texture)

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     namespace gr2lib.core.coretypes.implementation
8     {
9    
10    
11     public class Material : IMaterial
12     {
13 william 80 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 william 79 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 william 80 foreach (IntPtr ptr in maps)
39     {
40     managed.Maps.Add(new Map());
41     }
42 william 79 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     private IntPtr _ExtendedData;
61    
62    
63     public string Name { get { return _Name; } set { _Name = value; } }
64     public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
65     public Texture Texture { get { return _Texture; } set { _Texture = value; } }
66     public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
67 william 80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
68 william 79 #endregion
69     }
70     }

  ViewVC Help
Powered by ViewVC 1.1.22