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
|
/**************************************************************************/
/* gltf_texture_sampler.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GLTF_TEXTURE_SAMPLER_H
#define GLTF_TEXTURE_SAMPLER_H
#include "scene/resources/material.h"
class GLTFTextureSampler : public Resource {
GDCLASS(GLTFTextureSampler, Resource);
public:
enum FilterMode {
NEAREST = 9728,
LINEAR = 9729,
NEAREST_MIPMAP_NEAREST = 9984,
LINEAR_MIPMAP_NEAREST = 9985,
NEAREST_MIPMAP_LINEAR = 9986,
LINEAR_MIPMAP_LINEAR = 9987
};
enum WrapMode {
CLAMP_TO_EDGE = 33071,
MIRRORED_REPEAT = 33648,
REPEAT = 10497,
DEFAULT = REPEAT
};
int get_mag_filter() const {
return mag_filter;
}
void set_mag_filter(const int filter_mode) {
mag_filter = (FilterMode)filter_mode;
}
int get_min_filter() const {
return min_filter;
}
void set_min_filter(const int filter_mode) {
min_filter = (FilterMode)filter_mode;
}
int get_wrap_s() const {
return wrap_s;
}
void set_wrap_s(const int wrap_mode) {
wrap_s = (WrapMode)wrap_mode;
}
int get_wrap_t() const {
return wrap_t;
}
void set_wrap_t(const int wrap_mode) {
wrap_s = (WrapMode)wrap_mode;
}
StandardMaterial3D::TextureFilter get_filter_mode() const {
using TextureFilter = StandardMaterial3D::TextureFilter;
switch (min_filter) {
case NEAREST:
return TextureFilter::TEXTURE_FILTER_NEAREST;
case LINEAR:
return TextureFilter::TEXTURE_FILTER_LINEAR;
case NEAREST_MIPMAP_NEAREST:
case NEAREST_MIPMAP_LINEAR:
return TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS;
case LINEAR_MIPMAP_NEAREST:
case LINEAR_MIPMAP_LINEAR:
default:
return TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
}
}
void set_filter_mode(StandardMaterial3D::TextureFilter mode) {
using TextureFilter = StandardMaterial3D::TextureFilter;
switch (mode) {
case TextureFilter::TEXTURE_FILTER_NEAREST:
min_filter = FilterMode::NEAREST;
mag_filter = FilterMode::NEAREST;
break;
case TextureFilter::TEXTURE_FILTER_LINEAR:
min_filter = FilterMode::LINEAR;
mag_filter = FilterMode::LINEAR;
break;
case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS:
case TextureFilter::TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC:
min_filter = FilterMode::NEAREST_MIPMAP_LINEAR;
mag_filter = FilterMode::NEAREST;
break;
case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS:
case TextureFilter::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC:
default:
min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
mag_filter = FilterMode::LINEAR;
break;
}
}
bool get_wrap_mode() const {
// BaseMaterial3D presents wrapping as a boolean property. Either the texture is repeated
// in both dimensions, non-mirrored, or it isn't repeated at all. This will cause oddities
// when people import models having other wrapping mode combinations.
return (wrap_s == WrapMode::REPEAT) && (wrap_t == WrapMode::REPEAT);
}
void set_wrap_mode(bool mat_repeats) {
if (mat_repeats) {
wrap_s = WrapMode::REPEAT;
wrap_t = WrapMode::REPEAT;
} else {
wrap_s = WrapMode::CLAMP_TO_EDGE;
wrap_t = WrapMode::CLAMP_TO_EDGE;
}
}
protected:
static void _bind_methods();
private:
FilterMode mag_filter = FilterMode::LINEAR;
FilterMode min_filter = FilterMode::LINEAR_MIPMAP_LINEAR;
WrapMode wrap_s = WrapMode::REPEAT;
WrapMode wrap_t = WrapMode::REPEAT;
};
VARIANT_ENUM_CAST(GLTFTextureSampler::FilterMode);
VARIANT_ENUM_CAST(GLTFTextureSampler::WrapMode);
#endif // GLTF_TEXTURE_SAMPLER_H
|