forked from KhronosGroup/glTF-Asset-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperty.cs
170 lines (162 loc) · 4.69 KB
/
Property.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using System.Reflection;
namespace AssetGenerator
{
/// <summary>
/// A property is a value that can be set on a glTF model.
/// This class tracks the value of the property and related metadata.
/// </summary>
internal class Property
{
public PropertyName Name;
public string ReadmeColumnName;
public string ReadmeValue;
public Func<object> Value { get; set; }
public Property(PropertyName enumName, string displayValue)
{
Name = enumName;
ReadmeColumnName = enumName.ToReadmeString();
ReadmeValue = displayValue;
}
public override bool Equals(object obj)
{
var otherProperty = obj as Property;
if (Name == otherProperty.Name)
{
return ReadmeValue == otherProperty.ReadmeValue;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}
/// <summary>
/// Pass an object to CloneObject, and it returns a copy of that object that isn't just a reference.
/// </summary>
internal static class DeepCopy
{
public static T CloneObject<T>(T obj)
{
if (obj == null)
{
throw new ArgumentNullException("Object cannot be null");
}
return (T)Process(obj);
}
static object Process(object obj)
{
if (obj == null)
{
return null;
}
Type type = obj.GetType();
if (type.IsValueType || type == typeof(string))
{
return obj;
}
else if (type.IsArray)
{
Type elementType = Type.GetType(type.FullName.Replace("[]", string.Empty));
// Catch for types in System.Numerics.
if (elementType == null)
{
elementType = Type.GetType(type.AssemblyQualifiedName.Replace("[]", string.Empty));
}
var array = obj as Array;
Array copied = Array.CreateInstance(elementType, array.Length);
for (var i = 0; i < array.Length; i++)
{
copied.SetValue(Process(array.GetValue(i)), i);
}
return Convert.ChangeType(copied, obj.GetType());
}
else if (type.IsClass)
{
object toret = Activator.CreateInstance(obj.GetType());
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var field in fields)
{
object fieldValue = field.GetValue(obj);
if (fieldValue == null)
{
continue;
}
field.SetValue(toret, Process(fieldValue));
}
return toret;
}
else
{
throw new ArgumentException("Unknown type");
}
}
}
internal enum PropertyName
{
Mode,
IndicesValues,
IndicesComponentType,
AlphaMode,
AlphaCutoff,
DoubleSided,
VertexUV0,
VertexPosition,
VertexNormal,
VertexTangent,
VertexColor,
NormalTexture,
Normals,
NormalTextureScale,
OcclusionTexture,
OcclusionTextureStrength,
EmissiveTexture,
EmissiveFactor,
ExtensionUsed,
ExtensionRequired,
SpecularGlossinessOnMaterial0,
SpecularGlossinessOnMaterial1,
BaseColorTexture,
BaseColorFactor,
MetallicRoughnessTexture,
MetallicFactor,
RoughnessFactor,
DiffuseTexture,
DiffuseFactor,
SpecularGlossinessTexture,
SpecularFactor,
GlossinessFactor,
Primitive0,
Primitive1,
Material0WithBaseColorFactor,
Material1WithBaseColorFactor,
Primitive0VertexUV0,
Primitive1VertexUV0,
Primitive0VertexUV1,
Primitive1VertexUV1,
Matrix,
Translation,
Rotation,
Scale,
Target,
Interpolation,
WrapT,
WrapS,
MagFilter,
MinFilter,
Version,
MinVersion,
Description,
ModelShouldLoad,
JointsComponentType,
WeightComponentType,
SamplerOutputComponentType,
LeftPrimitiveIndices,
RightPrimitiveIndices,
Difference,
}
}