File: MorphAnimMesh.js

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (78 lines) | stat: -rw-r--r-- 1,437 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
 * @author alteredq / http://alteredqualia.com/
 */

import {
	AnimationClip,
	AnimationMixer,
	Mesh
} from "../../../build/three.module.js";

var MorphAnimMesh = function ( geometry, material ) {

	Mesh.call( this, geometry, material );

	this.type = 'MorphAnimMesh';

	this.mixer = new AnimationMixer( this );
	this.activeAction = null;

};

MorphAnimMesh.prototype = Object.create( Mesh.prototype );
MorphAnimMesh.prototype.constructor = MorphAnimMesh;

MorphAnimMesh.prototype.setDirectionForward = function () {

	this.mixer.timeScale = 1.0;

};

MorphAnimMesh.prototype.setDirectionBackward = function () {

	this.mixer.timeScale = - 1.0;

};

MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {

	if ( this.activeAction ) {

		this.activeAction.stop();
		this.activeAction = null;

	}

	var clip = AnimationClip.findByName( this, label );

	if ( clip ) {

		var action = this.mixer.clipAction( clip );
		action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
		this.activeAction = action.play();

	} else {

		throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );

	}

};

MorphAnimMesh.prototype.updateAnimation = function ( delta ) {

	this.mixer.update( delta );

};

MorphAnimMesh.prototype.copy = function ( source ) {

	Mesh.prototype.copy.call( this, source );

	this.mixer = new AnimationMixer( this );

	return this;

};

export { MorphAnimMesh };