How Do I Add a Blend Shape to a Mesh Array?

Godot Version

Godot 4.5

Question

In my project I’m making great use of ArrayMeshes. But now I want to use blendshapes, however, I don’t understand how they are supposed to be used. And I cannot really find examples of them online.

Below is a snippet where I try to morph a square to a triangle using Blend Shapes, you can find the full example here.

func generate():
	var square_mesh := square_array()
	var triangle_mesh := triangle_array()

	var a_mesh := ArrayMesh.new()
	a_mesh.add_blend_shape("Triangle Shape")
	a_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, square_mesh, [triangle_mesh])
	mesh = a_mesh

However, this results in this error:

ERROR: Blend shape format must match the main array format for Vertex, Normal and Tangent arrays.
ERROR: scene/resources/mesh.cpp:1825 - Condition “err != OK” is true.

Why [triangle_mesh] when triangle_mesh is already properly formatted array?

Because it’s expecting an array of MeshArrays, check out the docs.

What happens if you use the already properly formatted array? You get a different error:

ERROR: Unable to convert array index 2 from “Nil” to “Array”.
ERROR: scene/resources/mesh.cpp:1819 - Condition “p_blend_shapes.size() != blend_shapes.size()” is true.

Try adding the tangents array in both.

Tried that too, you can find my attempt here. I’m not too familiar with how tangents work, but it spits out the same error again:

ERROR: Blend shape format must match the main array format for Vertex, Normal and Tangent arrays.
ERROR: scene/resources/mesh.cpp:1825 - Condition “err != OK” is true.

Tangents should be a vector3 array

According to the docs that I am reading, it’s a PackedFloat32Array.

Have you tried with a non-indexed mesh?

Hey now it’s working! Simply removing the indices from the blend shape mesh made it work. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.