summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
authorLyuma <xn.lyuma@gmail.com>2020-10-15 07:53:18 -0700
committerLyuma <xn.lyuma@gmail.com>2020-10-15 07:53:18 -0700
commitd13568a8d1290713bbdab5a32a99e03d762cefc9 (patch)
treeb110452d7103ec95f3e1a93473e359baaea1ee18 /scene/resources
parente273f83be3d34a955bc831e6868d4c50a3a32d15 (diff)
Allow renaming bones and blendshapes.
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/mesh.cpp17
-rw-r--r--scene/resources/mesh.h2
-rw-r--r--scene/resources/primitive_meshes.cpp3
-rw-r--r--scene/resources/primitive_meshes.h1
4 files changed, 23 insertions, 0 deletions
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index e9606e03e6..35b377abbe 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -1172,6 +1172,22 @@ StringName ArrayMesh::get_blend_shape_name(int p_index) const {
return blend_shapes[p_index];
}
+void ArrayMesh::set_blend_shape_name(int p_index, const StringName &p_name) {
+ ERR_FAIL_INDEX(p_index, blend_shapes.size());
+
+ StringName name = p_name;
+ int found = blend_shapes.find(name);
+ if (found != -1 && found != p_index) {
+ int count = 2;
+ do {
+ name = String(p_name) + " " + itos(count);
+ count++;
+ } while (blend_shapes.find(name) != -1);
+ }
+
+ blend_shapes.write[p_index] = name;
+}
+
void ArrayMesh::clear_blend_shapes() {
ERR_FAIL_COND_MSG(surfaces.size(), "Can't set shape key count if surfaces are already created.");
@@ -1508,6 +1524,7 @@ void ArrayMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &ArrayMesh::add_blend_shape);
ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &ArrayMesh::get_blend_shape_count);
ClassDB::bind_method(D_METHOD("get_blend_shape_name", "index"), &ArrayMesh::get_blend_shape_name);
+ ClassDB::bind_method(D_METHOD("set_blend_shape_name", "index", "name"), &ArrayMesh::set_blend_shape_name);
ClassDB::bind_method(D_METHOD("clear_blend_shapes"), &ArrayMesh::clear_blend_shapes);
ClassDB::bind_method(D_METHOD("set_blend_shape_mode", "mode"), &ArrayMesh::set_blend_shape_mode);
ClassDB::bind_method(D_METHOD("get_blend_shape_mode"), &ArrayMesh::get_blend_shape_mode);
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index b0a30a5627..ac8932dbe8 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -125,6 +125,7 @@ public:
virtual Ref<Material> surface_get_material(int p_idx) const = 0;
virtual int get_blend_shape_count() const = 0;
virtual StringName get_blend_shape_name(int p_index) const = 0;
+ virtual void set_blend_shape_name(int p_index, const StringName &p_name) = 0;
Vector<Face3> get_faces() const;
Ref<TriangleMesh> generate_triangle_mesh() const;
@@ -201,6 +202,7 @@ public:
void add_blend_shape(const StringName &p_name);
int get_blend_shape_count() const override;
StringName get_blend_shape_name(int p_index) const override;
+ void set_blend_shape_name(int p_index, const StringName &p_name) override;
void clear_blend_shapes();
void set_blend_shape_mode(BlendShapeMode p_mode);
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index 8d9c5f07b2..1436d06944 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -175,6 +175,9 @@ StringName PrimitiveMesh::get_blend_shape_name(int p_index) const {
return StringName();
}
+void PrimitiveMesh::set_blend_shape_name(int p_index, const StringName &p_name) {
+}
+
AABB PrimitiveMesh::get_aabb() const {
if (pending_request) {
_update();
diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h
index f0ae611b5e..d89db17356 100644
--- a/scene/resources/primitive_meshes.h
+++ b/scene/resources/primitive_meshes.h
@@ -79,6 +79,7 @@ public:
virtual Ref<Material> surface_get_material(int p_idx) const override;
virtual int get_blend_shape_count() const override;
virtual StringName get_blend_shape_name(int p_index) const override;
+ virtual void set_blend_shape_name(int p_index, const StringName &p_name) override;
virtual AABB get_aabb() const override;
virtual RID get_rid() const override;