Skip to content

Commit b9b07d6

Browse files
committedSep 12, 2024
Merge pull request #94783 from TokageItLab/validate-gltf-anim-name
Add validation to glTF importer for Blendshape and Animation
2 parents 23e51c3 + 0235086 commit b9b07d6

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed
 

‎modules/fbx/fbx_document.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,8 @@ String FBXDocument::_gen_unique_name(HashSet<String> &unique_names, const String
288288
}
289289

290290
String FBXDocument::_sanitize_animation_name(const String &p_name) {
291-
// Animations disallow the normal node invalid characters as well as "," and "["
292-
// (See animation/animation_player.cpp::add_animation)
293-
294-
// TODO: Consider adding invalid_characters or a validate_animation_name to animation_player to mirror Node.
295291
String anim_name = p_name.validate_node_name();
296-
anim_name = anim_name.replace(",", "");
297-
anim_name = anim_name.replace("[", "");
298-
return anim_name;
292+
return AnimationLibrary::validate_library_name(anim_name);
299293
}
300294

301295
String FBXDocument::_gen_unique_animation_name(Ref<FBXState> p_state, const String &p_name) {

‎modules/gltf/gltf_document.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,8 @@ String GLTFDocument::_gen_unique_name(Ref<GLTFState> p_state, const String &p_na
491491
}
492492

493493
String GLTFDocument::_sanitize_animation_name(const String &p_name) {
494-
// Animations disallow the normal node invalid characters as well as "," and "["
495-
// (See animation/animation_player.cpp::add_animation)
496-
497-
// TODO: Consider adding invalid_characters or a validate_animation_name to animation_player to mirror Node.
498494
String anim_name = p_name.validate_node_name();
499-
anim_name = anim_name.replace(",", "");
500-
anim_name = anim_name.replace("[", "");
501-
return anim_name;
495+
return AnimationLibrary::validate_library_name(anim_name);
502496
}
503497

504498
String GLTFDocument::_gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name) {

‎scene/resources/3d/importer_mesh.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "core/math/convex_hull.h"
3535
#include "core/math/random_pcg.h"
3636
#include "core/math/static_raycaster.h"
37+
#include "scene/resources/animation_library.h"
3738
#include "scene/resources/surface_tool.h"
3839

3940
#include <cstdint>
@@ -134,9 +135,18 @@ void ImporterMesh::Surface::_split_normals(Array &r_arrays, const LocalVector<in
134135
}
135136
}
136137

138+
String ImporterMesh::validate_blend_shape_name(const String &p_name) {
139+
String name = p_name;
140+
const char *characters = ":";
141+
for (const char *p = characters; *p; p++) {
142+
name = name.replace(String::chr(*p), "_");
143+
}
144+
return name;
145+
}
146+
137147
void ImporterMesh::add_blend_shape(const String &p_name) {
138148
ERR_FAIL_COND(surfaces.size() > 0);
139-
blend_shapes.push_back(p_name);
149+
blend_shapes.push_back(validate_blend_shape_name(p_name));
140150
}
141151

142152
int ImporterMesh::get_blend_shape_count() const {

‎scene/resources/3d/importer_mesh.h

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class ImporterMesh : public Resource {
9595
int get_blend_shape_count() const;
9696
String get_blend_shape_name(int p_blend_shape) const;
9797

98+
static String validate_blend_shape_name(const String &p_name);
99+
98100
void add_surface(Mesh::PrimitiveType p_primitive, const Array &p_arrays, const TypedArray<Array> &p_blend_shapes = Array(), const Dictionary &p_lods = Dictionary(), const Ref<Material> &p_material = Ref<Material>(), const String &p_name = String(), const uint64_t p_flags = 0);
99101
int get_surface_count() const;
100102

0 commit comments

Comments
 (0)
Please sign in to comment.