Godot: There seem to be no way to access Blend Shapes values via code

Created on 16 Jan 2018  路  4Comments  路  Source: godotengine/godot

Godot version:
3.0 Beta 2

Issue description:
Looks like it's impossible to change values of a Blend Shape in a mesh with a script, or at least it's not documented, even though you can change them in the editor.

documentation core

Most helpful comment

After a lot of digging I see it's possible. If you have a mesh instance you need to call "set" on the mesh instance with "blend_shapes/". The capitalization has to match, but the spaces are removed. If you had "Face Smile" (as I did) then doing this should work:

onready var body = $Model/Skeleton/Body
var t = 0.0

func _process(delta):
    t += delta  
    if t > 1:
        t = 0
    body.set("blend_shapes/FaceSmile", t)

All 4 comments

After a lot of digging I see it's possible. If you have a mesh instance you need to call "set" on the mesh instance with "blend_shapes/". The capitalization has to match, but the spaces are removed. If you had "Face Smile" (as I did) then doing this should work:

onready var body = $Model/Skeleton/Body
var t = 0.0

func _process(delta):
    t += delta  
    if t > 1:
        t = 0
    body.set("blend_shapes/FaceSmile", t)

Wouldn't it be better to change this issue to a "bug" or "enchancement", given it is quite unintuitive for users?
I guess it might be better to add a set_blend_amount(blendshape, amount) instead of documenting the workaround.

I'd agree. I spent a long time looking for how to do this and ended up digging through the code before finally stumbling upon a solution. A wrapper for the method wouldn't be unwelcome, especially if it caps the range to 0-1 as is needed by blendshapes.

There is this method in VisualServer.cs

image

/// <summary>
/// <para>Sets the weight for a given blend shape associated with this instance.</para>
/// </summary>
[GodotMethod("instance_set_blend_shape_weight")]
public static void InstanceSetBlendShapeWeight(RID instance, int shape, float weight)
{
     NativeCalls.godot_icall_3_630(method_bind_262, ptr, RID.GetPtr(instance), shape, ref weight);
}
Was this page helpful?
0 / 5 - 0 ratings