forked from alvani/Unity-glTF-Exporter
-
Notifications
You must be signed in to change notification settings - Fork 14
/
GlTF_Sampler.cs
131 lines (119 loc) · 2.29 KB
/
GlTF_Sampler.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
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
public class GlTF_Sampler : GlTF_Writer {
public enum MagFilter {
NEAREST = 9728,
LINEAR = 9729
}
public enum MinFilter {
NEAREST = 9728,
LINEAR = 9729,
NEAREST_MIPMAP_NEAREST = 9984,
LINEAR_MIPMAP_NEAREST = 9985,
NEAREST_MIPMAP_LINEAR = 9986,
LINEAR_MIPMAP_LINEAR = 9987
}
public enum Wrap {
CLAMP_TO_EDGE = 33071,
MIRRORED_REPEAT = 33648,
REPEAT = 10497
}
MagFilter magFilter = MagFilter.LINEAR;
MinFilter minFilter = MinFilter.LINEAR;
Wrap wrap = Wrap.REPEAT;
public static string GetNameFromObject(Texture tex)
{
int fm = (int)tex.filterMode;
int w = (int)tex.wrapMode;
var n = "sampler_" + fm + "_" + w;
Texture2D t = tex as Texture2D;
if (t != null)
{
if (t.mipmapCount > 0)
{
n += "_m";
}
}
return n;
}
public GlTF_Sampler (Texture tex)
{
bool hasMipMap = false;
Texture2D t = tex as Texture2D;
if (t != null)
{
if (t.mipmapCount > 0)
{
hasMipMap = true;
}
}
switch (tex.filterMode)
{
case FilterMode.Point:
{
magFilter = MagFilter.NEAREST;
if (hasMipMap)
{
minFilter = MinFilter.NEAREST_MIPMAP_NEAREST;
}
else
{
minFilter = MinFilter.NEAREST;
}
}
break;
case FilterMode.Bilinear:
{
magFilter = MagFilter.LINEAR;
if (hasMipMap)
{
minFilter = MinFilter.LINEAR_MIPMAP_NEAREST;
}
else
{
minFilter = MinFilter.LINEAR;
}
}
break;
case FilterMode.Trilinear:
{
magFilter = MagFilter.LINEAR;
if (hasMipMap)
{
minFilter = MinFilter.LINEAR;
}
else
{
minFilter = MinFilter.LINEAR_MIPMAP_LINEAR;
}
}
break;
}
switch (tex.wrapMode)
{
case TextureWrapMode.Clamp:
{
wrap = Wrap.CLAMP_TO_EDGE;
}
break;
case TextureWrapMode.Repeat:
{
wrap = Wrap.REPEAT;
}
break;
}
}
public override void Write()
{
Indent(); jsonWriter.Write ("{\n");
IndentIn();
Indent(); jsonWriter.Write ("\"magFilter\": " + (int)magFilter + ",\n");
Indent(); jsonWriter.Write ("\"minFilter\": " + (int)minFilter + ",\n");
Indent(); jsonWriter.Write ("\"wrapS\": " + (int)wrap + ",\n");
Indent(); jsonWriter.Write ("\"wrapT\": " + (int)wrap + "\n");
IndentOut();
Indent(); jsonWriter.Write ("}");
}
}
#endif