Where are the get_morph_target(int index) and set_morph_target(int index, float amount) functions?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CrazyM
:warning: Old Version Published before Godot 3 was released.

Going through the MeshInstance and Mesh classes, I found I can retrieve the Mesh from MeshInstance.get_mesh(). Once I have a Mesh reference I can get the morph count, get morph names by index, and get and set their mode (not sure what this does), but I don’t see functions for actually getting or setting morph values by index. For example, if I wanted to get the current shape amount from shape index 3, then set shape index 3 to 0.5. Does anyone know where these functions live?

Thanks,
Michael

:bust_in_silhouette: Reply From: CrazyM

I finally found a usage example on the old site from about a year ago. As a new user, I didn’t know there was an old site. To set a morph, use the [set] method inherited from the [Object] class. Not very intuitive and poorly documented.

–Set the smile morph to 0.5
MeshInstance.set(“morph/smile”, 0.5)

Could you comment further on this? I’m trying to figure out the morph as well and can figure out how to get it to work.

It looks like you’re getting the mesh itself, then using “set(” but this does nothing for me. I can see the morph if I use the morph slider in the Inspector, but I never see it in the running game despite my settings in Inspector - so figuring out how to control this with scripts is high on my list.
Thanks :slight_smile:

Brinux | 2016-11-07 12:22

Here is a simple ping-pong script that you can place on your [MeshInstance] to bounce a morph value from 0-1.

extends MeshInstance

export var shapeName = "shape1"
var i = 0
var increment = true

func _ready():
	set_fixed_process(true)

func _fixed_process(delta):
	if i > 1:
		increment = false
		
	if i < 0:
		increment = true
	
	if increment:
		i = i + 0.01
	else:
		i = i - 0.01
		
	set("morph/" + shapeName, i)

CrazyM | 2016-11-07 22:53