animControl = (operation:string, animations:any, from:number, to:number, loop:string, speed:any, callback:any, isPlayAnimCompat:boolean, rev:boolean, view:any) => {
if (!animations)
return;
if (typeof animations == “string”)
animations = [animations];
this.mixer = new THREE.AnimationMixer(this.model.scene);
let animationProcess = (animationName:any) => {
this.animationPlay = this.mixer.clipAction(animationName)
if (! this.animationPlay)
return;
switch (operation) {
case 'PLAY':
if (! this.animationPlay.isRunning()) {
this.animationPlay.reset();
let scene = this.getSceneByAction( this.animationPlay );
let frameRate = this.getSceneAnimFrameRate(scene);
// compatibility reasons: deprecated playAnimation puzzles don't
// change repetitions
if (!isPlayAnimCompat) {
this.animationPlay.repetitions = Infinity;
}
let timeScale = Math.abs(parseFloat('0.05'));
if (rev){
timeScale = -Math.abs(parseFloat('0.05'));
}
this.animationPlay.clampWhenFinished = true;
this.animationPlay.setLoop( THREE.LoopOnce )
let startTime = from/frameRate
this.animationPlay.timeScale = timeScale
if (to !== null) {
this.animationPlay.getClip().duration = to/frameRate;
} else {
this.animationPlay.getClip().resetDuration();
}
this.animationPlay.time = timeScale >= 0 ? startTime : this.animationPlay.getClip().duration;
let val = this.animationPlay.getClip().validate()
if(val){
if(!this.animPause){
this.animationPlay.setEffectiveTimeScale(timeScale).play()
}else{
///
}
}else {
console.log("Not valid clip")
}
}
break;
case 'STOP':
// this.animationPlay = action
this.animationPlay.stop();
// remove callbacks
let callbacks = this.animMixerCallbacks;
for (let j = 0; j < callbacks.length; j++)
if (callbacks[j][0] == this.animationPlay) {
callbacks.splice(j, 1);
j--
}
break;
case 'PAUSE':
this.animationPlay.paused = true;
break;
case 'RESUME':
this.animationPlay.paused = false;
break;
case 'SET_FRAME':
let scene = this.getSceneByAction( this.animationPlay);
let frameRate = this.getSceneAnimFrameRate(scene);
this.animationPlay.time = from ? from/frameRate : 0;
this.animationPlay.play();
this.animationPlay.paused = true;
break;
}
}
for (let i = 0; i < this.model.animations.length; i++) {
let animName = this.model.animations[i];
if (animName)
animationProcess(animName);
}
// this.initAnimationMixer();
this.camera = view ? this.model.cameras.find(o => o.name === view) : this.model.cameras[this.cam];
this.animate()
}
animate = () => {
if(this.animationPlay){
if (this.animationPlay.isRunning()){
requestAnimationFrame(this.animate);
}
if(this.mixer){
this.mixer.update(Math.min(0.05, this.clock.getDelta()))
}
}
this.render()
}
can anyone can help me in this ?.