Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions modules/fbx/fbx_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ GLTFImageIndex FBXDocument::_parse_image_save_image(Ref<FBXState> p_state, const
return p_state->images.size() - 1;
}

Error FBXDocument::_parse_images(Ref<FBXState> p_state, const String &p_base_path) {
Error FBXDocument::_parse_images(Ref<FBXState> p_state) {
ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);

const ufbx_scene *fbx_scene = p_state->scene.get();
Expand All @@ -1057,8 +1057,8 @@ Error FBXDocument::_parse_images(Ref<FBXState> p_state, const String &p_base_pat
if (path.is_absolute_path()) {
path = path.get_file();
}
if (!p_base_path.is_empty()) {
path = p_base_path.path_join(path);
if (!p_state->base_path.is_empty()) {
path = p_state->base_path.path_join(path);
}
path = path.simplify_path();
Vector<uint8_t> data;
Expand Down Expand Up @@ -2015,7 +2015,7 @@ void FBXDocument::_process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_r
}
}

Error FBXDocument::_parse(Ref<FBXState> p_state, const String &p_path, Ref<FileAccess> p_file) {
Error FBXDocument::_parse(Ref<FBXState> p_state, Ref<FileAccess> p_file) {
p_state->scene.reset();

Error err = ERR_INVALID_DATA;
Expand Down Expand Up @@ -2106,7 +2106,7 @@ Error FBXDocument::_parse(Ref<FBXState> p_state, const String &p_path, Ref<FileA
}
}

err = _parse_fbx_state(p_state, p_path);
err = _parse_fbx_state(p_state);
ERR_FAIL_COND_V(err != OK, err);

return OK;
Expand Down Expand Up @@ -2170,7 +2170,7 @@ Error FBXDocument::append_from_buffer(const PackedByteArray &p_bytes, const Stri
file_access.instantiate();
file_access->open_custom(p_bytes.ptr(), p_bytes.size());
state->base_path = p_base_path.get_base_dir();
err = _parse(state, state->base_path, file_access);
err = _parse(state, file_access);
ERR_FAIL_COND_V(err != OK, err);
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
Expand All @@ -2180,7 +2180,7 @@ Error FBXDocument::append_from_buffer(const PackedByteArray &p_bytes, const Stri
return OK;
}

Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_search_path) {
Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state) {
Error err;

// Abort parsing if the scene is not loaded.
Expand All @@ -2196,7 +2196,7 @@ Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_searc

if (!p_state->discard_meshes_and_materials) {
/* PARSE IMAGES */
err = _parse_images(p_state, p_search_path);
err = _parse_images(p_state);

ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);

Expand Down Expand Up @@ -2260,7 +2260,7 @@ Error FBXDocument::append_from_file(const String &p_path, Ref<GLTFState> p_state
if (p_state == Ref<FBXState>()) {
p_state.instantiate();
}
state->filename = p_path.get_file().get_basename();
state->filename = p_path.get_file();
state->use_named_skin_binds = p_flags & GLTFDocument::ImportFlags::IMPORT_FLAG_USE_NAMED_SKIN_BINDS;
state->discard_meshes_and_materials = p_flags & GLTFDocument::ImportFlags::IMPORT_FLAG_DISCARD_MESHES_AND_MATERIALS;
Error err;
Expand All @@ -2272,7 +2272,7 @@ Error FBXDocument::append_from_file(const String &p_path, Ref<GLTFState> p_state
base_path = p_path.get_base_dir();
}
state->base_path = base_path;
err = _parse(p_state, base_path, file);
err = _parse(p_state, file);
ERR_FAIL_COND_V(err != OK, err);
for (Ref<GLTFDocumentExtension> ext : document_extensions) {
ERR_CONTINUE(ext.is_null());
Expand Down
6 changes: 3 additions & 3 deletions modules/fbx/fbx_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class FBXDocument : public GLTFDocument {
Error _parse_meshes(Ref<FBXState> p_state);
Ref<Image> _parse_image_bytes_into_image(Ref<FBXState> p_state, const Vector<uint8_t> &p_bytes, const String &p_filename, int p_index);
GLTFImageIndex _parse_image_save_image(Ref<FBXState> p_state, const Vector<uint8_t> &p_bytes, const String &p_file_extension, int p_index, Ref<Image> p_image);
Error _parse_images(Ref<FBXState> p_state, const String &p_base_path);
Error _parse_images(Ref<FBXState> p_state);
Error _parse_materials(Ref<FBXState> p_state);
Error _parse_skins(Ref<FBXState> p_state);
Error _parse_animations(Ref<FBXState> p_state);
Expand All @@ -95,11 +95,11 @@ class FBXDocument : public GLTFDocument {
Error _parse_lights(Ref<FBXState> p_state);

public:
Error _parse_fbx_state(Ref<FBXState> p_state, const String &p_search_path);
Error _parse_fbx_state(Ref<FBXState> p_state);
void _process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_root);
void _generate_scene_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
void _generate_skeleton_bone_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
void _import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player,
const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks);
Error _parse(Ref<FBXState> p_state, const String &p_path, Ref<FileAccess> p_file);
Error _parse(Ref<FBXState> p_state, Ref<FileAccess> p_file);
};
12 changes: 12 additions & 0 deletions modules/gltf/doc_classes/GLTFDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
</method>
</methods>
<members>
<member name="binary_format_mode" type="int" setter="set_binary_format_mode" getter="get_binary_format_mode" enum="GLTFDocument.BinaryFormatMode" default="0">
When exporting a binary glTF (.glb), this determines the binary format to use: 32-bit, 64-bit, or automatic selection between the two. This option has no effect when exporting a text glTF (.gltf).
</member>
<member name="fallback_image_format" type="String" setter="set_fallback_image_format" getter="get_fallback_image_format" default="&quot;None&quot;">
The user-friendly name of the fallback image format. This is used when exporting the glTF file, including writing to a file and writing to a byte array.
This property may only be one of "None", "PNG", or "JPEG", and is only used when the [member image_format] is not one of "None", "PNG", or "JPEG". If having multiple extension image formats is desired, that can be done using a [GLTFDocumentExtension] class - this property only covers the use case of providing a base glTF fallback image when using a custom image format.
Expand All @@ -141,6 +144,15 @@
</member>
</members>
<constants>
<constant name="BINARY_FORMAT_MODE_AUTO" value="0" enum="BinaryFormatMode">
Use the binary glTF format with the minimum size for the file being exported. If the file being exported exceeds the limits of the 32-bit format, the 64-bit format will be used. See [constant BINARY_FORMAT_MODE_32_BIT] and [constant BINARY_FORMAT_MODE_64_BIT] for more details.
</constant>
<constant name="BINARY_FORMAT_MODE_32_BIT" value="1" enum="BinaryFormatMode">
Use the binary glTF format with 32-bit file size and chunk sizes as defined in the glTF 2.0 specification. If the file being exported exceeds the limits of the 32-bit format, either a separate buffer will be written, or the export will fail.
</constant>
<constant name="BINARY_FORMAT_MODE_64_BIT" value="2" enum="BinaryFormatMode">
Use the binary glTF format with 64-bit file size and chunk sizes as defined in the glTF 2.1 specification. This format is not compatible with older glTF importers, but allows for larger files to be exported.
</constant>
<constant name="ROOT_NODE_MODE_SINGLE_ROOT" value="0" enum="RootNodeMode">
Treat the Godot scene's root node as the root node of the glTF file, and mark it as the single root node via the [code]GODOT_single_root[/code] glTF extension. This will be parsed the same as [constant ROOT_NODE_MODE_KEEP_ROOT] if the implementation does not support [code]GODOT_single_root[/code].
</constant>
Expand Down
3 changes: 2 additions & 1 deletion modules/gltf/doc_classes/GLTFState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
The folder path associated with this glTF data. This is used to find other files the glTF file references, like images or binary buffers. This will be set during import when appending from a file, and will be set during export when writing to a file.
</member>
<member name="buffers" type="PackedByteArray[]" setter="set_buffers" getter="get_buffers" default="[]">
The buffers of the glTF file's buffers array. Buffer data may be stored in separate files, in data URIs, or in the chunks of a binary glTF .glb file.
</member>
<member name="copyright" type="String" setter="set_copyright" getter="get_copyright" default="&quot;&quot;">
The copyright string in the asset header of the glTF file. This is set during import if present and export if non-empty. See the glTF asset header documentation for more information.
Expand All @@ -304,7 +305,7 @@
<member name="filename" type="String" setter="set_filename" getter="get_filename" default="&quot;&quot;">
The file name associated with this glTF data. If it ends with [code].gltf[/code], this is text-based glTF, otherwise this is binary GLB. This will be set during import when appending from a file, and will be set during export when writing to a file. If writing to a buffer, this will be an empty string.
</member>
<member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()">
<member name="glb_data" type="PackedByteArray" setter="set_glb_data" getter="get_glb_data" default="PackedByteArray()" deprecated="Use [member buffers] instead.">
The binary buffer attached to a .glb file.
</member>
<member name="handle_binary_image_mode" type="int" setter="set_handle_binary_image_mode" getter="get_handle_binary_image_mode" enum="GLTFState.HandleBinaryImageMode" default="1">
Expand Down
4 changes: 2 additions & 2 deletions modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SceneExporterGLTFPlugin::SceneExporterGLTFPlugin() {
_config_dialog->connect(SceneStringName(confirmed), callable_mp(this, &SceneExporterGLTFPlugin::_export_scene_as_gltf));

_export_settings.instantiate();
_export_settings->generate_property_list(_gltf_document);
_export_settings->generate_property_list(_gltf_document, "");
_settings_inspector = memnew(EditorInspector);
_settings_inspector->set_custom_minimum_size(Size2(350, 300) * EDSCALE);
_config_dialog->add_child(_settings_inspector);
Expand All @@ -83,7 +83,7 @@ void SceneExporterGLTFPlugin::_popup_gltf_settings_dialog(const String &p_select
Node *root = EditorNode::get_singleton()->get_tree()->get_edited_scene_root();
ERR_FAIL_NULL(root);
// Generate and refresh the export settings.
_export_settings->generate_property_list(_gltf_document, root);
_export_settings->generate_property_list(_gltf_document, p_selected_path, root);
_settings_inspector->edit(nullptr);
_settings_inspector->edit(_export_settings.ptr());
// Show the config dialog.
Expand Down
32 changes: 30 additions & 2 deletions modules/gltf/editor/editor_scene_exporter_gltf_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ bool EditorSceneExporterGLTFSettings::_set(const StringName &p_name, const Varia
_document->set_fallback_image_quality(p_value);
return true;
}
if (p_name == StringName("binary_format_mode")) {
_document->set_binary_format_mode((GLTFDocument::BinaryFormatMode)(int64_t)p_value);
emit_signal(CoreStringName(property_list_changed));
return true;
}
if (p_name == StringName("encoding_format")) {
_document->set_encoding_format((GLTFDocument::EncodingFormat)(int64_t)p_value);
return true;
}
if (p_name == StringName("root_node_mode")) {
_document->set_root_node_mode((GLTFDocument::RootNodeMode)(int64_t)p_value);
return true;
Expand Down Expand Up @@ -91,6 +100,14 @@ bool EditorSceneExporterGLTFSettings::_get(const StringName &p_name, Variant &r_
r_ret = _document->get_fallback_image_quality();
return true;
}
if (p_name == StringName("binary_format_mode")) {
r_ret = _document->get_binary_format_mode();
return true;
}
if (p_name == StringName("encoding_format")) {
r_ret = _document->get_encoding_format();
return true;
}
if (p_name == StringName("root_node_mode")) {
r_ret = _document->get_root_node_mode();
return true;
Expand Down Expand Up @@ -120,12 +137,16 @@ void EditorSceneExporterGLTFSettings::_get_property_list(List<PropertyInfo> *p_l
const String fallback_format = get("fallback_image_format");
prop.usage = (is_image_format_extension && fallback_format != "None") ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE;
}
// Only offer encoding choices if we are dealing with binary glTF, and either a non-default is selected or the user selected 64-bit mode.
if (prop.name == "encoding_format") {
prop.usage = (_document->get_encoding_format() != 0 || _document->get_binary_format_mode() == GLTFDocument::BinaryFormatMode::BINARY_FORMAT_MODE_64_BIT) ? PROPERTY_USAGE_DEFAULT : PROPERTY_USAGE_STORAGE;
}
p_list->push_back(prop);
}
}

void EditorSceneExporterGLTFSettings::_on_extension_property_list_changed() {
generate_property_list(_document);
generate_property_list(_document, _file_path);
emit_signal(CoreStringName(property_list_changed));
}

Expand Down Expand Up @@ -191,9 +212,10 @@ bool is_any_node_invisible(Node *p_node) {
}

// 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) {
void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p_document, const String &p_file_path, Node *p_root) {
_property_list.clear();
_document = p_document;
_file_path = p_file_path;
String image_format_hint_string = "None,PNG,JPEG";
const Vector<Ref<GLTFDocumentExtension>> all_extensions = GLTFDocument::get_all_gltf_document_extensions();
// If an extension allows saving images in different formats, add to the enum.
Expand All @@ -212,6 +234,12 @@ void EditorSceneExporterGLTFSettings::generate_property_list(Ref<GLTFDocument> p
_property_list.push_back(fallback_image_format_prop);
PropertyInfo fallback_image_quality_prop = PropertyInfo(Variant::FLOAT, "fallback_image_quality", PROPERTY_HINT_RANGE, "0,1,0.01");
_property_list.push_back(fallback_image_quality_prop);
if (!_file_path.ends_with(".gltf")) {
PropertyInfo binary_format_mode_prop = PropertyInfo(Variant::INT, "binary_format_mode", PROPERTY_HINT_ENUM, "Auto,32-bit,64-bit");
_property_list.push_back(binary_format_mode_prop);
PropertyInfo encoding_format_prop = PropertyInfo(Variant::INT, "encoding_format", PROPERTY_HINT_ENUM, "Plain:0,Zstd:1685353306");
_property_list.push_back(encoding_format_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);
// If the scene contains any non-visible nodes, show the visibility mode setting.
Expand Down
3 changes: 2 additions & 1 deletion modules/gltf/editor/editor_scene_exporter_gltf_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EditorSceneExporterGLTFSettings : public RefCounted {
HashMap<String, Ref<GLTFDocumentExtension>> _config_name_to_extension_map;

String _copyright;
String _file_path;
double _bake_fps = 30.0;

protected:
Expand All @@ -52,7 +53,7 @@ class EditorSceneExporterGLTFSettings : public RefCounted {
bool _get_extension_setting(const String &p_name_str, Variant &r_ret) const;

public:
void generate_property_list(Ref<GLTFDocument> p_document, Node *p_root = nullptr);
void generate_property_list(Ref<GLTFDocument> p_document, const String &p_file_path, Node *p_root = nullptr);

String get_copyright() const;
void set_copyright(const String &p_copyright);
Expand Down
Loading