forked from alvani/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlTF_Material.cs
106 lines (88 loc) · 2.39 KB
/
GlTF_Material.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GlTF_Material : GlTF_Writer {
public class Value : GlTF_Writer {
}
public class ColorValue : Value {
public Color color;
public override void Write()
{
jsonWriter.Write ("\"" + name + "\": [");
jsonWriter.Write (color.r.ToString() + ", " + color.g.ToString() + ", " +color.b.ToString() + ", " + color.a.ToString());
jsonWriter.Write ("]");
}
}
public class VectorValue : Value {
public Vector4 vector;
public override void Write()
{
jsonWriter.Write ("\"" + name + "\": [");
jsonWriter.Write (vector.x.ToString() + ", " + vector.y.ToString() + ", " + vector.z.ToString() + ", " + vector.w.ToString());
jsonWriter.Write ("]");
}
}
public class FloatValue : Value {
public float value;
public override void Write()
{
jsonWriter.Write ("\"" + name + "\": " + value + "");
}
}
public class StringValue : Value {
public string value;
public override void Write()
{
jsonWriter.Write ("\"" + name + "\": \"" + value + "\"");
}
}
public string instanceTechniqueName = "technique1";
public GlTF_ColorOrTexture ambient;// = new GlTF_ColorRGBA ("ambient");
public GlTF_ColorOrTexture diffuse;
public float shininess;
public GlTF_ColorOrTexture specular;// = new GlTF_ColorRGBA ("specular");
public List<Value> values = new List<Value>();
public static string GetNameFromObject(Object o)
{
return "material_" + GlTF_Writer.GetNameFromObject(o, true);
}
public override void Write()
{
Indent(); jsonWriter.Write ("\"" + name + "\": {\n");
IndentIn();
CommaNL();
Indent(); jsonWriter.Write ("\"technique\": \"" + instanceTechniqueName + "\",\n");
Indent(); jsonWriter.Write ("\"values\": {\n");
IndentIn();
foreach (var v in values)
{
CommaNL();
Indent(); v.Write();
}
// if (ambient != null)
// {
// CommaNL();
// ambient.Write ();
// }
// if (diffuse != null)
// {
// CommaNL();
// diffuse.Write ();
// }
// CommaNL();
// Indent(); jsonWriter.Write ("\"shininess\": " + shininess);
// if (specular != null)
// {
// CommaNL();
// specular.Write ();
// }
// jsonWriter.WriteLine();
Indent(); jsonWriter.Write ("\n");
IndentOut();
Indent(); jsonWriter.Write ("}");
CommaNL();
Indent(); jsonWriter.Write ("\"name\": \"" + name + "\"\n");
IndentOut();
Indent(); jsonWriter.Write ("}");
}
}