/usr/share/javascript/three/examples/js/BlendCharacter.js is in libjs-three 80+dfsg2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | /**
* @author Michael Guerrero / http://realitymeltdown.com
*/
THREE.BlendCharacter = function () {
this.weightSchedule = [];
this.warpSchedule = [];
this.load = function ( url, onLoad ) {
var scope = this;
var loader = new THREE.ObjectLoader();
loader.load( url, function( loadedObject ) {
// The exporter does not currently allow exporting a skinned mesh by itself
// so we must fish it out of the hierarchy it is embedded in (scene)
loadedObject.traverse( function( object ) {
if ( object instanceof THREE.SkinnedMesh ) {
scope.skinnedMesh = object;
}
} );
THREE.SkinnedMesh.call( scope, scope.skinnedMesh.geometry, scope.skinnedMesh.material );
// If we didn't successfully find the mesh, bail out
if ( scope.skinnedMesh == undefined ) {
console.log( 'unable to find skinned mesh in ' + url );
return;
}
scope.material.skinning = true;
scope.mixer = new THREE.AnimationMixer( scope );
scope.mixer = scope.mixer;
// Create the animations
for ( var i = 0; i < scope.geometry.animations.length; ++ i ) {
scope.mixer.clipAction( scope.geometry.animations[ i ] );
}
// Loading is complete, fire the callback
if ( onLoad !== undefined ) onLoad();
} );
};
this.loadJSON = function ( url, onLoad ) {
var scope = this;
var loader = new THREE.JSONLoader();
loader.load( url, function( geometry, materials ) {
var originalMaterial = materials[ 0 ];
originalMaterial.skinning = true;
THREE.SkinnedMesh.call( scope, geometry, originalMaterial );
var mixer = new THREE.AnimationMixer( scope );
scope.mixer = mixer;
// Create the animations
for ( var i = 0; i < geometry.animations.length; ++ i ) {
mixer.clipAction( geometry.animations[ i ] );
}
// Loading is complete, fire the callback
if ( onLoad !== undefined ) onLoad();
} );
};
this.update = function( dt ) {
this.mixer.update( dt );
};
this.play = function( animName, weight ) {
//console.log("play('%s', %f)", animName, weight);
return this.mixer.clipAction( animName ).
setEffectiveWeight( weight ).play();
};
this.crossfade = function( fromAnimName, toAnimName, duration ) {
this.mixer.stopAllAction();
var fromAction = this.play( fromAnimName, 1 );
var toAction = this.play( toAnimName, 1 );
fromAction.crossFadeTo( toAction, duration, false );
};
this.warp = function( fromAnimName, toAnimName, duration ) {
this.mixer.stopAllAction();
var fromAction = this.play( fromAnimName, 1 );
var toAction = this.play( toAnimName, 1 );
fromAction.crossFadeTo( toAction, duration, true );
};
this.applyWeight = function( animName, weight ) {
this.mixer.clipAction( animName ).setEffectiveWeight( weight );
};
this.getWeight = function( animName ) {
return this.mixer.clipAction( animName ).getEffectiveWeight();
}
this.pauseAll = function() {
this.mixer.timeScale = 0;
};
this.unPauseAll = function() {
this.mixer.timeScale = 1;
};
this.stopAll = function() {
this.mixer.stopAllAction();
};
this.showModel = function( boolean ) {
this.visible = boolean;
}
};
THREE.BlendCharacter.prototype = Object.create( THREE.SkinnedMesh.prototype );
THREE.BlendCharacter.prototype.constructor = THREE.BlendCharacter;
THREE.BlendCharacter.prototype.getForward = function() {
var forward = new THREE.Vector3();
return function() {
// pull the character's forward basis vector out of the matrix
forward.set(
- this.matrix.elements[ 8 ],
- this.matrix.elements[ 9 ],
- this.matrix.elements[ 10 ]
);
return forward;
}
};
|