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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/**************************************************************************/
/* editor_scene_exporter_gltf_settings.cpp */
/**************************************************************************/
/* This file is part of: */
/* REDOT ENGINE */
/* https://redotengine.org */
/**************************************************************************/
/* Copyright (c) 2024-present Redot Engine contributors */
/* (see REDOT_AUTHORS.md) */
/* 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. */
/**************************************************************************/
#include "editor_scene_exporter_gltf_settings.h"
const uint32_t PROP_EDITOR_SCRIPT_VAR = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE;
bool EditorSceneExporterGLTFSettings::_set(const StringName &p_name, const Variant &p_value) {
String name_str = String(p_name);
if (name_str.contains("/")) {
return _set_extension_setting(name_str, p_value);
}
if (p_name == StringName("image_format")) {
_document->set_image_format(p_value);
emit_signal(CoreStringName(property_list_changed));
return true;
}
if (p_name == StringName("lossy_quality")) {
_document->set_lossy_quality(p_value);
return true;
}
if (p_name == StringName("root_node_mode")) {
_document->set_root_node_mode((GLTFDocument::RootNodeMode)(int64_t)p_value);
return true;
}
return false;
}
bool EditorSceneExporterGLTFSettings::_get(const StringName &p_name, Variant &r_ret) const {
String name_str = String(p_name);
if (name_str.contains("/")) {
return _get_extension_setting(name_str, r_ret);
}
if (p_name == StringName("image_format")) {
r_ret = _document->get_image_format();
return true;
}
if (p_name == StringName("lossy_quality")) {
r_ret = _document->get_lossy_quality();
return true;
}
if (p_name == StringName("root_node_mode")) {
r_ret = _document->get_root_node_mode();
return true;
}
return false;
}
void EditorSceneExporterGLTFSettings::_get_property_list(List<PropertyInfo> *p_list) const {
for (PropertyInfo prop : _property_list) {
if (prop.name == "lossy_quality") {
String image_format = get("image_format");
bool is_image_format_lossy = image_format == "JPEG" || image_format.containsn("Lossy");
prop.usage = is_image_format_lossy ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE;
}
p_list->push_back(prop);
}
}
void EditorSceneExporterGLTFSettings::_on_extension_property_list_changed() {
generate_property_list(_document);
emit_signal(CoreStringName(property_list_changed));
}
bool EditorSceneExporterGLTFSettings::_set_extension_setting(const String &p_name_str, const Variant &p_value) {
PackedStringArray split = String(p_name_str).split("/", true, 1);
if (!_config_name_to_extension_map.has(split[0])) {
return false;
}
Ref<GLTFDocumentExtension> extension = _config_name_to_extension_map[split[0]];
bool valid;
extension->set(split[1], p_value, &valid);
return valid;
}
bool EditorSceneExporterGLTFSettings::_get_extension_setting(const String &p_name_str, Variant &r_ret) const {
PackedStringArray split = String(p_name_str).split("/", true, 1);
if (!_config_name_to_extension_map.has(split[0])) {
return false;
}
Ref<GLTFDocumentExtension> extension = _config_name_to_extension_map[split[0]];
bool valid;
r_ret = extension->get(split[1], &valid);
return valid;
}
String get_friendly_config_prefix(Ref<GLTFDocumentExtension> p_extension) {
String config_prefix = p_extension->get_name();
if (!config_prefix.is_empty()) {
return config_prefix;
}
const String class_name = p_extension->get_class_name();
config_prefix = class_name.trim_prefix("GLTFDocumentExtension").capitalize();
if (!config_prefix.is_empty()) {
return config_prefix;
}
PackedStringArray supported_extensions = p_extension->get_supported_extensions();
if (supported_extensions.size() > 0) {
return supported_extensions[0];
}
return "Unknown GLTFDocumentExtension";
}
// Run this before popping up the export settings, because the extensions may have changed.
void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p_document, Node *p_root) {
_property_list.clear();
_document = p_document;
String image_format_hint_string = "None,PNG,JPEG";
// Add properties from all document extensions.
for (Ref<GLTFDocumentExtension> &extension : GLTFDocument::get_all_gltf_document_extensions()) {
const Callable on_prop_changed = callable_mp(this, &EditorSceneExporterGLTFSettings::_on_extension_property_list_changed);
if (!extension->is_connected(CoreStringName(property_list_changed), on_prop_changed)) {
extension->connect(CoreStringName(property_list_changed), on_prop_changed);
}
const String config_prefix = get_friendly_config_prefix(extension);
_config_name_to_extension_map[config_prefix] = extension;
// If the extension allows saving in different image formats, add to the enum.
PackedStringArray saveable_image_formats = extension->get_saveable_image_formats();
for (int i = 0; i < saveable_image_formats.size(); i++) {
image_format_hint_string += "," + saveable_image_formats[i];
}
// Look through the extension's properties and find the relevant ones.
List<PropertyInfo> ext_prop_list;
extension->get_property_list(&ext_prop_list);
for (const PropertyInfo &prop : ext_prop_list) {
// We only want properties that will show up in the exporter
// settings list. Exclude Resource's properties, as they are
// not relevant to the exporter. Include any user-defined script
// variables exposed to the editor (PROP_EDITOR_SCRIPT_VAR).
if ((prop.usage & PROP_EDITOR_SCRIPT_VAR) == PROP_EDITOR_SCRIPT_VAR) {
PropertyInfo ext_prop = prop;
ext_prop.name = config_prefix + "/" + prop.name;
_property_list.push_back(ext_prop);
}
}
}
// Add top-level properties (in addition to what _bind_methods registers).
PropertyInfo image_format_prop = PropertyInfo(Variant::STRING, "image_format", PROPERTY_HINT_ENUM, image_format_hint_string);
_property_list.push_back(image_format_prop);
PropertyInfo lossy_quality_prop = PropertyInfo(Variant::FLOAT, "lossy_quality", PROPERTY_HINT_RANGE, "0,1,0.01");
_property_list.push_back(lossy_quality_prop);
PropertyInfo root_node_mode_prop = PropertyInfo(Variant::INT, "root_node_mode", PROPERTY_HINT_ENUM, "Single Root,Keep Root,Multi Root");
_property_list.push_back(root_node_mode_prop);
}
String EditorSceneExporterGLTFSettings::get_copyright() const {
return _copyright;
}
void EditorSceneExporterGLTFSettings::set_copyright(const String &p_copyright) {
_copyright = p_copyright;
}
void EditorSceneExporterGLTFSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_copyright"), &EditorSceneExporterGLTFSettings::get_copyright);
ClassDB::bind_method(D_METHOD("set_copyright", "copyright"), &EditorSceneExporterGLTFSettings::set_copyright);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "copyright", PROPERTY_HINT_PLACEHOLDER_TEXT, "Example: 2014 Godette"), "set_copyright", "get_copyright");
ClassDB::bind_method(D_METHOD("get_bake_fps"), &EditorSceneExporterGLTFSettings::get_bake_fps);
ClassDB::bind_method(D_METHOD("set_bake_fps", "bake_fps"), &EditorSceneExporterGLTFSettings::set_bake_fps);
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_fps"), "set_bake_fps", "get_bake_fps");
}
double EditorSceneExporterGLTFSettings::get_bake_fps() const {
return _bake_fps;
}
void EditorSceneExporterGLTFSettings::set_bake_fps(const double p_bake_fps) {
_bake_fps = p_bake_fps;
}
|