• 3D
  • How do you get a mesh's vertex positions with blend shapes applied?

I need to retrieve a list of all of the vertices which are transformed by any given blend shape. To do this, I'm applying the blend shapes and keeping track of which vertices changed. However, it seems like global_transform.xform() just returns a vertex position from the base mesh, without taking blend shapes into account. Here's a simplified version of my code in case I'm doing something wrong:

func _ready():
    var MDT = MeshDataTool.new()
    MDT.create_from_surface(mesh, 0)
    var old_verts = []
    var new_verts = []
    for v in MDT.get_vertex_count():
        old_verts.append(global_transform.xform(MDT.get_vertex(v)))
    set_blend_shape("Blend Shape 1", 1) # this function just sets a blend shape's value
    for v in MDT.get_vertex_count():
        new_verts.append(global_transform.xform(MDT.get_vertex(v)))
    for v in old_verts.size():
        if old_verts[v] != new_verts[v]:
            print("!") # this never happens, so old_verts must be identical to new_verts

When using the GLES3 renderer, blend shapes are simulated on the GPU. The CPU can't access this information back, as the GPU does not communicate information back to the CPU (not without a slow process at least). Therefore, it's not feasible to get the transformed vertex information.

In GLES2, blend shapes are simulated on the CPU. This makes it technically possible to retrieve transformed vertex positions, but I'm not sure if there's an API for that.