Skip to content

Commit 19491dc

Browse files
committed
Import custom attributes
1 parent b9437c3 commit 19491dc

6 files changed

+233
-278
lines changed

modules/gltf/doc_classes/GLTFDocumentExtension.xml

+8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@
9292
[b]Note:[/b] The [param scene_parent] parameter may be [code]null[/code] if this is the single root node.
9393
</description>
9494
</method>
95+
<method name="_get_attribute_for_mesh_array" qualifiers="virtual">
96+
<return type="String" />
97+
<param index="0" name="state" type="GLTFState" />
98+
<param index="1" name="mesh_index" type="int" />
99+
<param index="2" name="mesh_array" type="int" enum="Mesh.ArrayType" />
100+
<description>
101+
</description>
102+
</method>
95103
<method name="_get_image_file_extension" qualifiers="virtual">
96104
<return type="String" />
97105
<description>

modules/gltf/editor/editor_scene_importer_blend.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
283283
} else {
284284
parameters_map["export_def_bones"] = false;
285285
}
286+
if (p_options.has(SNAME("blender/meshes/export_attributes")) && p_options[SNAME("blender/meshes/export_attributes")]) {
287+
parameters_map["export_attributes"] = true;
288+
} else {
289+
parameters_map["export_attributes"] = false;
290+
}
286291
if (p_options.has(SNAME("blender/nodes/modifiers")) && p_options[SNAME("blender/nodes/modifiers")]) {
287292
parameters_map["export_apply"] = true;
288293
} else {
@@ -370,6 +375,7 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li
370375
ADD_OPTION_BOOL("blender/meshes/tangents", true);
371376
ADD_OPTION_ENUM("blender/meshes/skins", "None,4 Influences (Compatible),All Influences", BLEND_BONE_INFLUENCES_ALL);
372377
ADD_OPTION_BOOL("blender/meshes/export_bones_deforming_mesh_only", false);
378+
ADD_OPTION_BOOL("blender/meshes/export_attributes", false);
373379
ADD_OPTION_BOOL("blender/materials/unpack_enabled", true);
374380
ADD_OPTION_ENUM("blender/materials/export_materials", "Placeholder,Export", BLEND_MATERIAL_EXPORT_EXPORT);
375381
ADD_OPTION_BOOL("blender/animation/limit_playback", true);

modules/gltf/extensions/gltf_document_extension.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void GLTFDocumentExtension::_bind_methods() {
3434
// Import process.
3535
GDVIRTUAL_BIND(_import_preflight, "state", "extensions");
3636
GDVIRTUAL_BIND(_get_supported_extensions);
37+
GDVIRTUAL_BIND(_get_attribute_for_mesh_array, "state", "mesh_index", "mesh_array");
3738
GDVIRTUAL_BIND(_parse_node_extensions, "state", "gltf_node", "extensions");
3839
GDVIRTUAL_BIND(_parse_image_data, "state", "image_data", "mime_type", "ret_image");
3940
GDVIRTUAL_BIND(_get_image_file_extension);
@@ -66,6 +67,14 @@ Error GLTFDocumentExtension::import_preflight(Ref<GLTFState> p_state, Vector<Str
6667
return err;
6768
}
6869

70+
void GLTFDocumentExtension::get_attribute_for_mesh_array(Ref<GLTFState> p_state, GLTFMeshIndex p_index, Mesh::ArrayType p_mesh_array, String &r_attribute) {
71+
String ret;
72+
GDVIRTUAL_CALL(_get_attribute_for_mesh_array, p_state, p_index, p_mesh_array, ret);
73+
if (!ret.is_empty()) {
74+
r_attribute = ret;
75+
}
76+
}
77+
6978
Vector<String> GLTFDocumentExtension::get_supported_extensions() {
7079
Vector<String> ret;
7180
GDVIRTUAL_CALL(_get_supported_extensions, ret);

modules/gltf/extensions/gltf_document_extension.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class GLTFDocumentExtension : public Resource {
4545
// Import process.
4646
virtual Error import_preflight(Ref<GLTFState> p_state, Vector<String> p_extensions);
4747
virtual Vector<String> get_supported_extensions();
48+
virtual void get_attribute_for_mesh_array(Ref<GLTFState> p_state, GLTFMeshIndex p_index, Mesh::ArrayType p_mesh_array, String &r_attribute);
4849
virtual Error parse_node_extensions(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &p_extensions);
4950
virtual Error parse_image_data(Ref<GLTFState> p_state, const PackedByteArray &p_image_data, const String &p_mime_type, Ref<Image> r_image);
5051
virtual String get_image_file_extension();
@@ -71,6 +72,7 @@ class GLTFDocumentExtension : public Resource {
7172
// Import process.
7273
GDVIRTUAL2R(Error, _import_preflight, Ref<GLTFState>, Vector<String>);
7374
GDVIRTUAL0R(Vector<String>, _get_supported_extensions);
75+
GDVIRTUAL3R(String, _get_attribute_for_mesh_array, Ref<GLTFState>, GLTFMeshIndex, Mesh::ArrayType);
7476
GDVIRTUAL3R(Error, _parse_node_extensions, Ref<GLTFState>, Ref<GLTFNode>, Dictionary);
7577
GDVIRTUAL4R(Error, _parse_image_data, Ref<GLTFState>, PackedByteArray, String, Ref<Image>);
7678
GDVIRTUAL0R(String, _get_image_file_extension);

0 commit comments

Comments
 (0)