This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
forked from sketchfab/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GlTF_Technique.cs
141 lines (128 loc) · 3.24 KB
/
GlTF_Technique.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
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GlTF_Technique : GlTF_Writer {
public enum Type {
FLOAT = 5126,
FLOAT_VEC2 = 35664,
FLOAT_VEC3 = 35665,
FLOAT_VEC4 = 35666,
FLOAT_MAT3 = 35675,
FLOAT_MAT4 = 35676,
SAMPLER_2D = 35678
}
public enum Semantic {
UNKNOWN,
POSITION,
NORMAL,
TEXCOORD_0,
TEXCOORD_1,
TEXCOORD_2,
TEXCOORD_3,
MODELVIEW,
PROJECTION,
MODELVIEWINVERSETRANSPOSE
}
public class Parameter {
public string name;
public Type type;
public Semantic semantic = Semantic.UNKNOWN;
}
public class Attribute {
public string name;
public string param;
}
public class Uniform {
public string name;
public string param;
}
public string program;
public List<Attribute> attributes = new List<Attribute>();
public List<Parameter> parameters = new List<Parameter>();
public List<Uniform> uniforms = new List<Uniform>();
public static string GetNameFromObject(Object o)
{
return "technique_" + GlTF_Writer.GetNameFromObject(o);
}
public void AddDefaultUniforms()
{
var tParam = new Parameter();
tParam.name = "modelViewMatrix";
tParam.type = Type.FLOAT_MAT4;
tParam.semantic = Semantic.MODELVIEW;
parameters.Add(tParam);
var uni = new Uniform();
uni.name = "u_modelViewMatrix";
uni.param = tParam.name;
uniforms.Add(uni);
tParam = new Parameter();
tParam.name = "projectionMatrix";
tParam.type = Type.FLOAT_MAT4;
tParam.semantic = Semantic.PROJECTION;
parameters.Add(tParam);
uni = new Uniform();
uni.name = "u_projectionMatrix";
uni.param = tParam.name;
uniforms.Add(uni);
tParam = new Parameter();
tParam.name = "normalMatrix";
tParam.type = Type.FLOAT_MAT3;
tParam.semantic = Semantic.MODELVIEWINVERSETRANSPOSE;
parameters.Add(tParam);
uni = new Uniform();
uni.name = "u_normalMatrix";
uni.param = tParam.name;
uniforms.Add(uni);
}
public override void Write()
{
Indent(); jsonWriter.Write ("\"" + name + "\": {\n");
IndentIn();
Indent(); jsonWriter.Write ("\"program\": \"" + program +"\",\n");
Indent(); jsonWriter.Write ("\"parameters\": {\n");
IndentIn();
foreach (var p in parameters)
{
CommaNL();
Indent(); jsonWriter.Write ("\"" + p.name + "\": {\n");
IndentIn();
Indent(); jsonWriter.Write ("\"type\": " + (int)p.type);
if (p.semantic != Semantic.UNKNOWN)
{
jsonWriter.Write (",\n");
Indent(); jsonWriter.Write ("\"semantic\": \"" + p.semantic + "\"\n");
} else {
jsonWriter.Write ("\n");
}
IndentOut();
Indent(); jsonWriter.Write ("}");
}
jsonWriter.Write ("\n");
IndentOut();
Indent(); jsonWriter.Write ("},\n");
Indent(); jsonWriter.Write ("\"attributes\": {\n");
IndentIn();
foreach (var a in attributes)
{
CommaNL();
Indent(); jsonWriter.Write ("\"" + a.name + "\": \"" + a.param + "\"");
}
jsonWriter.Write ("\n");
IndentOut();
Indent(); jsonWriter.Write ("},\n");
Indent(); jsonWriter.Write ("\"uniforms\": {\n");
IndentIn();
foreach (var u in uniforms)
{
CommaNL();
Indent(); jsonWriter.Write ("\"" + u.name + "\": \"" + u.param + "\"");
}
jsonWriter.Write ("\n");
IndentOut();
Indent(); jsonWriter.Write ("}\n");
IndentOut();
Indent(); jsonWriter.Write ("}");
}
}
#endif