Create new Animation using morph targets as a property

Can you repro in the PG? It is complicated to help with it

This should work:

BABYLON.Animation.TransitionTo("influence", 64, casiBody.morphTargetManager.getTarget(8), scene, frameRate, morph, 1134);

Are you sure the 64 isn’t actually supposed to be 1.0 because when I tried using 64 the morph targets influence changed to 64?

That’s correct (I did not pay attention to that part :))

1 Like

I managed to get one lip position to happen but the other lip positions aren’t happening. I want the influence of one morph target to be changed to 1 and then go back to being 0 and then change another morph targets influence to 1 and then back and so on until we’ve reached the end of the jsonParsed array.
If you need a playground I’ve attached it to this message.

1 Like

Sorry I forgot to save the playground I edited this one should show my problem.

I am not sure the issue here is Babylon related but mostly general programming I guess.

You would need something similar to a state machine to chain your various actions depending on some data.

I’m also wondering, is the BABYLON.TransitionTo supposed to change the animation curve that affects the morph targets influence to what’s shown in the picture because using it changed the animation curve to what’s shown in the picture

yup a linear transition over time

I managed to create a state machine with the code shown below but I’m having trouble figuring out how to get the morph targets influence to change once we change the state do you know of any way to do so?
function createMachine(stateMachineDefinition){//we’re also using this machine for thc state = machine.transition and console.logs at the bottom
const machine = {
value: stateMachineDefinition.initialState,//this is where we get the initial state of 1.
//the transition function is what the above comments are going to do
//for transition(currentState, event) we check against the current states transitions
transition(currentState, event){//this transition function is going to accept the current state and an event for switching the that current state to something else in state = machine.transition(state, ‘switch’)
const currentStateDefinition = stateMachineDefinition[currentState]//the currentState is going to be the string on or off and we’re going to grab that state definition from state machine definition
const destinationTransition = currentStateDefinition.transitions[event];//grab the transitions object then grab the switch property from that transition object
if(!destinationTransition){//if there’s no destinationTransition then return
return
}
const destinationState = destinationTransition.target;
const destinationStateDefintion = stateMachineDefinition[destinationState];
destinationTransition.action();
currentStateDefinition.actions.onInfluence1();
destinationStateDefintion.actions.onInfluence0();
console.log(machine.value);
machine.value = destinationState;//this is where machine immediately is in the new state
console.log(machine.value);
return machine.value
}
}
return machine

}

const machine = createMachine({
initialState: ‘1’,
1: {
actions: {
onInfluence1(){
console.log(“influence changed from 1 to 0”);
},
onInfluence0(){
console.log(“influence changed from 0 to 1”);
},
},
transitions: {
switch: {
target: ‘0’,
action(){
console.log(‘transition action for “switch” in influence 1 state’);
},
},
},
},
0: {
actions: {
onInfluence0(){
console.log(“influence changed from 0 to 1”);
},
onInfluence1(){
console.log(“influence changed from 1 to 0”);
},
},
transitions: {
switch: {
target: ‘1’,
action(){
console.log(‘transition action for “switch” in influence 0 state’);
},
},
},
},
})
let state = machine.value;
console.log(current state: ${state});
state = machine.transition(state, “switch”);
console.log(current state: ${state});
state = machine.transition(state, “switch”);
console.log(current state: ${state});

A playground would be better than the code here :slight_smile:

1 Like

I’m trying to show a playground of my problem but I’ve now run into another problem when I try to import a script from an outside source using
var scriptName = “state-machine.js”;
var script = document.createElement(“script”);
script.type = “text/javascript”;
script.src = url + scriptName;
document.head.appendChild(script);
but when I try to it gives me the error shown in the screenshot.


If you need a playground of my problem I’ve attached it below

This sounds more like a javascript issue than a Babylon one and mostly within the organisation of the app isnt it ?

The code to troubleshoot here starts to becoming quite significant and not only in the playground.

To improve the amount of response from the forum I would advise to keep the repro as minimal as possible and heavily focused on only one issue and removing the part which are not mandatory. Troubleshooting your external script in the playground sounds way harder for the community.

1 Like