/[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 86 - (show annotations) (download)
Fri Jul 16 23:35:21 2010 UTC (9 years, 6 months ago) by william
File size: 3070 byte(s)
Add Try/Catch blocks in to all API Calls

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.ExtendedData = IntPtr.Zero;
17 this.Name = "";
18 this.Maps = new List<Map>();
19 this.Texture = new Texture();
20
21 }
22
23 internal static Material ReadFromMemory(IntPtr pointer)
24 {
25 try
26 {
27 if (pointer == IntPtr.Zero) return null;
28 native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
29 Material managed = ReadFromNative(native);
30 managed.NativePointer = pointer;
31 return managed;
32 }
33 catch (Exception ex)
34 {
35 Console.WriteLine(ex.ToString());
36 return default(Material);
37 }
38 }
39
40 internal static Material ReadFromNative(native.Material native)
41 {
42 try
43 {
44 Material managed = new Material();
45 managed.Name = native.Name;
46 IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
47 int length = maps.Length;
48 managed.Maps = new List<Map>(length);
49 foreach (IntPtr ptr in maps)
50 {
51 managed.Maps.Add(new Map());
52 }
53 for (int i = 0; i < length; i++)
54 {
55 managed.Maps[i] = Map.ReadFromMemory(maps[i]);
56 }
57 managed.Texture = Texture.ReadFromMemory(native.Texture);
58 managed.ExtendedData = native.ExtendedData;
59 return managed;
60 }
61 catch (Exception ex)
62 {
63 Console.WriteLine(ex.ToString());
64 return default(Material);
65 }
66 }
67
68 #region INativePointer Members
69 private IntPtr _NativePointer;
70 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
71 #endregion
72
73 #region IMaterial Members
74 private string _Name;
75 private List<Map> _Maps;
76 private Texture _Texture;
77 public string Name { get { return _Name; } set { _Name = value; } }
78 public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
79 public Texture Texture { get { return _Texture; } set { _Texture = value; } }
80 public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
81 #endregion
82
83 #region IExtendedData Members
84 private IntPtr _ExtendedData;
85 public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
86 #endregion
87 }
88 }

  ViewVC Help
Powered by ViewVC 1.1.22