Skip to content

Commit

Permalink
Import custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
huwpascoe committed Oct 5, 2024
1 parent db66bd3 commit b43538a
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 269 deletions.
6 changes: 6 additions & 0 deletions modules/gltf/doc_classes/GLTFDocumentExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
Runs when parsing the texture JSON from the glTF textures array. This can be used to set the source image index to use as the texture.
</description>
</method>
<method name="_remap_custom_attribute" qualifiers="virtual">
<return type="int" />
<param index="0" name="name" type="String" />
<description>
</description>
</method>
<method name="_save_image_at_path" qualifiers="virtual">
<return type="int" enum="Error" />
<param index="0" name="state" type="GLTFState" />
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 @@ -279,6 +279,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 @@ -373,6 +378,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
7 changes: 7 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(_remap_custom_attribute, "name");
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 @@ -64,6 +65,12 @@ Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<Str
return err;
}

int GLTFDocumentExtension::remap_custom_attribute(const String &p_name) {
int ret = -1;
GDVIRTUAL_CALL(_remap_custom_attribute, p_name, ret);
return 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 int remap_custom_attribute(const String &p_name);
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 @@ -69,6 +70,7 @@ class GLTFDocumentExtension : public Resource {
// Import process.
GDVIRTUAL2R(Error, _import_preflight, Ref<GLTFState>, Vector<String>);
GDVIRTUAL0R(Vector<String>, _get_supported_extensions);
GDVIRTUAL1R(int, _remap_custom_attribute, String);
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

0 comments on commit b43538a

Please sign in to comment.