Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import custom attributes with GLTFDocumentExtension #97756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions modules/gltf/doc_classes/GLTFDocumentExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
[b]Note:[/b] The [param scene_parent] parameter may be [code]null[/code] if this is the single root node.
</description>
</method>
<method name="_get_attribute_for_mesh_array" qualifiers="virtual">
<return type="String" />
<param index="0" name="state" type="GLTFState" />
<param index="1" name="mesh_index" type="int" />
<param index="2" name="mesh_array" type="int" enum="Mesh.ArrayType" />
<description>
</description>
</method>
<method name="_get_image_file_extension" qualifiers="virtual">
<return type="String" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions modules/gltf/editor/editor_scene_importer_blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
} else {
parameters_map["export_def_bones"] = false;
}
if (p_options.has(SNAME("blender/meshes/export_attributes")) && p_options[SNAME("blender/meshes/export_attributes")]) {
parameters_map["export_attributes"] = true;
} else {
parameters_map["export_attributes"] = false;
}
if (p_options.has(SNAME("blender/nodes/modifiers")) && p_options[SNAME("blender/nodes/modifiers")]) {
parameters_map["export_apply"] = true;
} else {
Expand Down Expand Up @@ -370,6 +375,7 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li
ADD_OPTION_BOOL("blender/meshes/tangents", true);
ADD_OPTION_ENUM("blender/meshes/skins", "None,4 Influences (Compatible),All Influences", BLEND_BONE_INFLUENCES_ALL);
ADD_OPTION_BOOL("blender/meshes/export_bones_deforming_mesh_only", false);
ADD_OPTION_BOOL("blender/meshes/export_attributes", false);
ADD_OPTION_BOOL("blender/materials/unpack_enabled", true);
ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export", BLEND_MATERIAL_EXPORT_EXPORT);
ADD_OPTION_BOOL("blender/animation/limit_playback", true);
Expand Down
9 changes: 9 additions & 0 deletions modules/gltf/extensions/gltf_document_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void GLTFDocumentExtension::_bind_methods() {
// Import process.
GDVIRTUAL_BIND(_import_preflight, "state", "extensions");
GDVIRTUAL_BIND(_get_supported_extensions);
GDVIRTUAL_BIND(_get_attribute_for_mesh_array, "state", "mesh_index", "mesh_array");
GDVIRTUAL_BIND(_parse_node_extensions, "state", "gltf_node", "extensions");
GDVIRTUAL_BIND(_parse_image_data, "state", "image_data", "mime_type", "ret_image");
GDVIRTUAL_BIND(_get_image_file_extension);
Expand Down Expand Up @@ -66,6 +67,14 @@ Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<Str
return err;
}

void GLTFDocumentExtension::get_attribute_for_mesh_array(Ref<GLTFState> p_state, GLTFMeshIndex p_index, Mesh::ArrayType p_mesh_array, String &r_attribute) {
String ret;
GDVIRTUAL_CALL(_get_attribute_for_mesh_array, p_state, p_index, p_mesh_array, ret);
if (!ret.is_empty()) {
r_attribute = ret;
}
}

Vector<String> GLTFDocumentExtension::get_supported_extensions() {
Vector<String> ret;
GDVIRTUAL_CALL(_get_supported_extensions, ret);
Expand Down
2 changes: 2 additions & 0 deletions modules/gltf/extensions/gltf_document_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GLTFDocumentExtension : public Resource {
// Import process.
virtual Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions);
virtual Vector<String> get_supported_extensions();
virtual void get_attribute_for_mesh_array(Ref<GLTFState> p_state, GLTFMeshIndex p_index, Mesh::ArrayType p_mesh_array, String &r_attribute);
virtual Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions);
virtual Error parse_image_data(Ref<GLTFState> p_state, const PackedByteArray &p_image_data, const String &p_mime_type, Ref<Image> r_image);
virtual String get_image_file_extension();
Expand All @@ -71,6 +72,7 @@ class GLTFDocumentExtension : public Resource {
// Import process.
GDVIRTUAL2R(Error, _import_preflight, Ref<GLTFState>, Vector<String>);
GDVIRTUAL0R(Vector<String>, _get_supported_extensions);
GDVIRTUAL3R(String, _get_attribute_for_mesh_array, Ref<GLTFState>, GLTFMeshIndex, Mesh::ArrayType);
GDVIRTUAL3R(Error, _parse_node_extensions, Ref<GLTFState>, Ref<GLTFNode>, Dictionary);
GDVIRTUAL4R(Error, _parse_image_data, Ref<GLTFState>, PackedByteArray, String, Ref<Image>);
GDVIRTUAL0R(String, _get_image_file_extension);
Expand Down
Loading
Loading