提交 c43140f0 编写于 作者: M Mr.doob

Tab indentations.

上级 b90267dd
......@@ -204,15 +204,15 @@ THREE.BlendCharacter = function () {
this.unPauseAll = function() {
for ( var a in this.animations ) {
for ( var a in this.animations ) {
if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) {
if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) {
this.animations[ a ].pause();
this.animations[ a ].pause();
}
}
}
}
};
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - animation - skinning</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #000;
font-family:Monospace;
font-size:13px;
text-align:center;
<head>
<title>three.js webgl - animation - skinning</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #000;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #fff;
margin: 0px;
overflow: hidden;
}
background-color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
position: absolute;
top: 0px; width: 100%;
padding: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - Skeletal Animation Blending
<br><br> Adjust blend weights to affect the animations that are currently playing.
<br> Cross fades (and warping) blend between 2 animations and end with a single animation.
</div>
#info {
position: absolute;
top: 0px; width: 100%;
padding: 5px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - Skeletal Animation Blending
<br><br> Adjust blend weights to affect the animations that are currently playing.
<br> Cross fades (and warping) blend between 2 animations and end with a single animation.
</div>
<script src="../build/Three.js"></script>
<script src="../build/Three.js"></script>
<script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="js/Controls/OrbitControls.js"></script>
<script src="js/BlendCharacter.js"></script>
<script src="js/BlendCharacterGui.js"></script>
<script src="js/libs/dat.gui.min.js"></script>
<script src="js/Detector.js"></script>
<script src="js/libs/stats.min.js"></script>
<script src="js/Controls/OrbitControls.js"></script>
<script src="js/BlendCharacter.js"></script>
<script src="js/BlendCharacterGui.js"></script>
<script src="js/libs/dat.gui.min.js"></script>
<script>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var container, stats;
var blendMesh, camera, scene, renderer, controls;
var blendMesh, camera, scene, renderer, controls;
var clock = new THREE.Clock();
var gui = null;
var clock = new THREE.Clock();
var gui = null;
var isFrameStepping = false;
var timeToStep = 0;
var isFrameStepping = false;
var timeToStep = 0;
init();
init();
function init() {
function init() {
container = document.getElementById( 'container' );
container = document.getElementById( 'container' );
scene = new THREE.Scene();
scene.add ( new THREE.AmbientLight( 0xaaaaaa ) );
scene = new THREE.Scene();
scene.add ( new THREE.AmbientLight( 0xaaaaaa ) );
var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
light.position = new THREE.Vector3( 0, 0, 1000.0 );
scene.add( light );
var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
light.position = new THREE.Vector3( 0, 0, 1000.0 );
scene.add( light );
renderer = new THREE.WebGLRenderer( { antialias: true, alpha: false } );
renderer.setClearColor( '#777777', 1 );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = true;
renderer = new THREE.WebGLRenderer( { antialias: true, alpha: false } );
renderer.setClearColor( '#777777', 1 );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.autoClear = true;
container.appendChild( renderer.domElement );
container.appendChild( renderer.domElement );
//
//
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
//
//
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener( 'resize', onWindowResize, false );
// listen for messages from the gui
window.addEventListener( 'start-animation', onStartAnimation );
window.addEventListener( 'stop-animation', onStopAnimation );
window.addEventListener( 'pause-animation', onPauseAnimation );
window.addEventListener( 'step-animation', onStepAnimation );
window.addEventListener( 'weight-animation', onWeightAnimation );
window.addEventListener( 'crossfade', onCrossfade );
window.addEventListener( 'warp', onWarp );
window.addEventListener( 'toggle-lock-camera', onLockCameraToggle );
window.addEventListener( 'toggle-show-bones', onShowBonesToggle );
// listen for messages from the gui
window.addEventListener( 'start-animation', onStartAnimation );
window.addEventListener( 'stop-animation', onStopAnimation );
window.addEventListener( 'pause-animation', onPauseAnimation );
window.addEventListener( 'step-animation', onStepAnimation );
window.addEventListener( 'weight-animation', onWeightAnimation );
window.addEventListener( 'crossfade', onCrossfade );
window.addEventListener( 'warp', onWarp );
window.addEventListener( 'toggle-lock-camera', onLockCameraToggle );
window.addEventListener( 'toggle-show-bones', onShowBonesToggle );
blendMesh = new THREE.BlendCharacter();
blendMesh.load( "models/skinned/marine/marine_anims.js", start );
blendMesh = new THREE.BlendCharacter();
blendMesh.load( "models/skinned/marine/marine_anims.js", start );
}
}
function onWindowResize() {
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setSize( window.innerWidth, window.innerHeight );
}
}
function onStartAnimation( event ) {
function onStartAnimation( event ) {
var data = event.detail;
var data = event.detail;
blendMesh.stopAll();
blendMesh.stopAll();
// the blend mesh will combine 1 or more animations
for ( var i = 0; i < data.anims.length; ++i ) {
// the blend mesh will combine 1 or more animations
for ( var i = 0; i < data.anims.length; ++i ) {
blendMesh.play(data.anims[i], data.weights[i]);
blendMesh.play(data.anims[i], data.weights[i]);
}
}
isFrameStepping = false;
isFrameStepping = false;
}
}
function onStopAnimation( event ) {
function onStopAnimation( event ) {
blendMesh.stopAll();
isFrameStepping = false;
blendMesh.stopAll();
isFrameStepping = false;
}
}
function onPauseAnimation( event ) {
function onPauseAnimation( event ) {
( isFrameStepping ) ? blendMesh.unPauseAll(): blendMesh.pauseAll();
( isFrameStepping ) ? blendMesh.unPauseAll(): blendMesh.pauseAll();
isFrameStepping = false;
isFrameStepping = false;
}
}
function onStepAnimation( event ) {
function onStepAnimation( event ) {
blendMesh.unPauseAll();
isFrameStepping = true;
timeToStep = event.detail.stepSize;
}
blendMesh.unPauseAll();
isFrameStepping = true;
timeToStep = event.detail.stepSize;
}
function onWeightAnimation(event) {
function onWeightAnimation(event) {
var data = event.detail;
for ( var i = 0; i < data.anims.length; ++i ) {
var data = event.detail;
for ( var i = 0; i < data.anims.length; ++i ) {
blendMesh.applyWeight(data.anims[i], data.weights[i]);
blendMesh.applyWeight(data.anims[i], data.weights[i]);
}
}
}
}
function onCrossfade(event) {
function onCrossfade(event) {
var data = event.detail;
var data = event.detail;
blendMesh.stopAll();
blendMesh.crossfade( data.from, data.to, data.time );
blendMesh.stopAll();
blendMesh.crossfade( data.from, data.to, data.time );
isFrameStepping = false;
isFrameStepping = false;
}
}
function onWarp( event ) {
function onWarp( event ) {
var data = event.detail;
var data = event.detail;
blendMesh.stopAll();
blendMesh.warp( data.from, data.to, data.time );
blendMesh.stopAll();
blendMesh.warp( data.from, data.to, data.time );
isFrameStepping = false;
isFrameStepping = false;
}
}
function onLockCameraToggle( event ) {
function onLockCameraToggle( event ) {
var shouldLock = event.detail.shouldLock;
controls.enabled = !shouldLock;
var shouldLock = event.detail.shouldLock;
controls.enabled = !shouldLock;
}
}
function onShowBonesToggle( event ) {
function onShowBonesToggle( event ) {
var shouldShow = event.detail.shouldShow;
blendMesh.toggleShowBones( shouldShow );
var shouldShow = event.detail.shouldShow;
blendMesh.toggleShowBones( shouldShow );
}
}
function start() {
function start() {
blendMesh.rotation.y = Math.PI * -135 / 180;
scene.add( blendMesh );
blendMesh.rotation.y = Math.PI * -135 / 180;
scene.add( blendMesh );
var aspect = window.innerWidth / window.innerHeight;
var radius = blendMesh.geometry.boundingSphere.radius;
var aspect = window.innerWidth / window.innerHeight;
var radius = blendMesh.geometry.boundingSphere.radius;
camera = new THREE.PerspectiveCamera( 45, aspect, 1, 10000 );
camera.position.set( 0.0, radius, radius * 3.5 );
camera = new THREE.PerspectiveCamera( 45, aspect, 1, 10000 );
camera.position.set( 0.0, radius, radius * 3.5 );
controls = new THREE.OrbitControls( camera );
controls.target = new THREE.Vector3( 0, radius, 0 );
controls.update();
controls = new THREE.OrbitControls( camera );
controls.target = new THREE.Vector3( 0, radius, 0 );
controls.update();
// Set default weights
// Set default weights
blendMesh.animations[ 'idle' ].weight = 1 / 3;
blendMesh.animations[ 'walk' ].weight = 1 / 3;
blendMesh.animations[ 'run' ].weight = 1 / 3;
blendMesh.animations[ 'idle' ].weight = 1 / 3;
blendMesh.animations[ 'walk' ].weight = 1 / 3;
blendMesh.animations[ 'run' ].weight = 1 / 3;
gui = new BlendCharacterGui(blendMesh.animations);
gui = new BlendCharacterGui(blendMesh.animations);
animate();
}
animate();
}
function animate() {
function animate() {
requestAnimationFrame( animate, renderer.domElement );
requestAnimationFrame( animate, renderer.domElement );
// step forward in time based on whether we're stepping and scale
// step forward in time based on whether we're stepping and scale
var scale = gui.getTimeScale();
var delta = clock.getDelta();
var stepSize = (!isFrameStepping) ? delta * scale: timeToStep;
var scale = gui.getTimeScale();
var delta = clock.getDelta();
var stepSize = (!isFrameStepping) ? delta * scale: timeToStep;
// modify blend weights
// modify blend weights
blendMesh.update( stepSize );
gui.update();
blendMesh.update( stepSize );
gui.update();
THREE.AnimationHandler.update( stepSize );
THREE.AnimationHandler.update( stepSize );
renderer.render( scene, camera );
stats.update();
renderer.render( scene, camera );
stats.update();
// if we are stepping, consume time
// ( will equal step size next time a single step is desired )
// if we are stepping, consume time
// ( will equal step size next time a single step is desired )
timeToStep = 0;
timeToStep = 0;
}
}
</script>
</script>
</body>
</body>
</html>
......@@ -137,7 +137,7 @@ THREE.KeyFrameAnimation.prototype.stop = function() {
// reset JIT matrix and remove cache
for ( var h = 0; h < this.data.hierarchy.length; h++ ) {
var obj = this.hierarchy[ h ];
var node = this.data.hierarchy[ h ];
......
......@@ -5,48 +5,48 @@
THREE.SkeletonHelper = function ( skeleton, jointBoxSize, scaleRatio ) {
THREE.Object3D.call( this );
THREE.Object3D.call( this );
this.scaleRatio = ( scaleRatio !== undefined ) ? scaleRatio : 1;
this.skeleton = skeleton;
this.scaleRatio = ( scaleRatio !== undefined ) ? scaleRatio : 1;
this.skeleton = skeleton;
if ( jointBoxSize === undefined ) jointBoxSize = 1;
var boxSize = jointBoxSize * this.scaleRatio;
if ( jointBoxSize === undefined ) jointBoxSize = 1;
var boxSize = jointBoxSize * this.scaleRatio;
for ( var i = 0; i < skeleton.bones.length; ++i ) {
for ( var i = 0; i < skeleton.bones.length; ++i ) {
var bone = skeleton.bones[ i ];
var boxGeometry = new THREE.BoxGeometry( boxSize, boxSize, boxSize );
var boxMaterial = new THREE.MeshBasicMaterial();
var bone = skeleton.bones[ i ];
var boxGeometry = new THREE.BoxGeometry( boxSize, boxSize, boxSize );
var boxMaterial = new THREE.MeshBasicMaterial();
bone.helper = {};
bone.helper.box = new THREE.Mesh( boxGeometry, boxMaterial );
bone.helper.axes = new THREE.AxisHelper( jointBoxSize * 3 );
bone.helper = {};
bone.helper.box = new THREE.Mesh( boxGeometry, boxMaterial );
bone.helper.axes = new THREE.AxisHelper( jointBoxSize * 3 );
this.add( bone.helper.box );
this.add( bone.helper.axes );
this.add( bone.helper.box );
this.add( bone.helper.axes );
if ( bone.parent instanceof THREE.Bone ) {
if ( bone.parent instanceof THREE.Bone ) {
var lineMaterial = new THREE.LineBasicMaterial();
var lineGeometry = new THREE.Geometry();
var lineMaterial = new THREE.LineBasicMaterial();
var lineGeometry = new THREE.Geometry();
lineMaterial.vertexColors = true;
lineMaterial.vertexColors = true;
lineGeometry.vertices.push( new THREE.Vector3() );
lineGeometry.vertices.push( new THREE.Vector3() );
lineGeometry.colors.push( new THREE.Color( 1, 1, 0 ) );
lineGeometry.colors.push( new THREE.Color( 0, 0, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3() );
lineGeometry.vertices.push( new THREE.Vector3() );
lineGeometry.colors.push( new THREE.Color( 1, 1, 0 ) );
lineGeometry.colors.push( new THREE.Color( 0, 0, 0 ) );
bone.helper.line = new THREE.Line( lineGeometry, lineMaterial );
this.add( bone.helper.line);
bone.helper.line = new THREE.Line( lineGeometry, lineMaterial );
this.add( bone.helper.line);
}
}
}
}
this.update();
this.update();
};
......@@ -54,50 +54,50 @@ THREE.SkeletonHelper.prototype = Object.create( THREE.Object3D.prototype );
THREE.SkeletonHelper.prototype.update = function () {
for ( var i = 0; i < this.skeleton.bones.length; ++i ) {
for ( var i = 0; i < this.skeleton.bones.length; ++i ) {
var bone = this.skeleton.bones[ i ];
var bone = this.skeleton.bones[ i ];
if ( this.visible && bone.parent instanceof THREE.Bone ) {
if ( this.visible && bone.parent instanceof THREE.Bone ) {
bone.skinMatrix.decompose( bone.helper.box.position, bone.helper.box.quaternion, bone.helper.box.scale );
bone.helper.box.position.multiplyScalar( this.scaleRatio );
bone.skinMatrix.decompose( bone.helper.box.position, bone.helper.box.quaternion, bone.helper.box.scale );
bone.helper.box.position.multiplyScalar( this.scaleRatio );
bone.helper.axes.quaternion = bone.helper.box.quaternion;
bone.helper.axes.position = bone.helper.box.position;
bone.helper.axes.scale = bone.helper.box.scale;
bone.helper.axes.quaternion = bone.helper.box.quaternion;
bone.helper.axes.position = bone.helper.box.position;
bone.helper.axes.scale = bone.helper.box.scale;
bone.helper.line.geometry.vertices[0].setFromMatrixPosition( bone.skinMatrix );
bone.helper.line.geometry.vertices[0].multiplyScalar( this.scaleRatio );
bone.helper.line.geometry.vertices[0].setFromMatrixPosition( bone.skinMatrix );
bone.helper.line.geometry.vertices[0].multiplyScalar( this.scaleRatio );
bone.helper.line.geometry.vertices[1].setFromMatrixPosition( bone.parent.skinMatrix );
bone.helper.line.geometry.vertices[1].multiplyScalar( this.scaleRatio );
bone.helper.line.geometry.vertices[1].setFromMatrixPosition( bone.parent.skinMatrix );
bone.helper.line.geometry.vertices[1].multiplyScalar( this.scaleRatio );
bone.helper.line.geometry.verticesNeedUpdate = true;
bone.helper.line.geometry.verticesNeedUpdate = true;
}
}
}
}
};
THREE.SkeletonHelper.prototype.setVisible = function ( shouldBeVisible ) {
for ( var i = 0; i < this.skeleton.bones.length; ++i ) {
for ( var i = 0; i < this.skeleton.bones.length; ++i ) {
var bone = this.skeleton.bones[ i ];
if ( bone.helper ) {
var bone = this.skeleton.bones[ i ];
if ( bone.helper ) {
bone.helper.box.visible = shouldBeVisible;
bone.helper.axes.visible = shouldBeVisible;
bone.helper.box.visible = shouldBeVisible;
bone.helper.axes.visible = shouldBeVisible;
if ( bone.parent instanceof THREE.Bone ) {
if ( bone.parent instanceof THREE.Bone ) {
bone.helper.line.visible = shouldBeVisible;
bone.helper.line.visible = shouldBeVisible;
}
}
}
}
}
}
}
......@@ -6,96 +6,96 @@
THREE.Skeleton = function ( boneList, useVertexTexture ) {
this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
// init bones
// init bones
this.bones = [];
this.boneMatrices = [];
this.bones = [];
this.boneMatrices = [];
var bone, gbone, p, q, s;
var bone, gbone, p, q, s;
if ( boneList !== undefined ) {
if ( boneList !== undefined ) {
for ( var b = 0; b < boneList.length; ++b ) {
for ( var b = 0; b < boneList.length; ++b ) {
gbone = boneList[ b ];
gbone = boneList[ b ];
p = gbone.pos;
q = gbone.rotq;
s = gbone.scl;
p = gbone.pos;
q = gbone.rotq;
s = gbone.scl;
bone = this.addBone();
bone = this.addBone();
bone.name = gbone.name;
bone.position.set( p[0], p[1], p[2] );
bone.quaternion.set( q[0], q[1], q[2], q[3] );
bone.name = gbone.name;
bone.position.set( p[0], p[1], p[2] );
bone.quaternion.set( q[0], q[1], q[2], q[3] );
if ( s !== undefined ) {
if ( s !== undefined ) {
bone.scale.set( s[0], s[1], s[2] );
bone.scale.set( s[0], s[1], s[2] );
} else {
} else {
bone.scale.set( 1, 1, 1 );
bone.scale.set( 1, 1, 1 );
}
}
}
}
for ( var b = 0; b < boneList.length; ++b ) {
for ( var b = 0; b < boneList.length; ++b ) {
gbone = boneList[ b ];
gbone = boneList[ b ];
if ( gbone.parent !== -1 ) {
if ( gbone.parent !== -1 ) {
this.bones[ gbone.parent ].add( this.bones[ b ] );
this.bones[ gbone.parent ].add( this.bones[ b ] );
}
}
}
}
//
//
var nBones = this.bones.length;
var nBones = this.bones.length;
if ( this.useVertexTexture ) {
if ( this.useVertexTexture ) {
// layout (1 matrix = 4 pixels)
// RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
// with 8x8 pixel texture max 16 bones (8 * 8 / 4)
// 16x16 pixel texture max 64 bones (16 * 16 / 4)
// 32x32 pixel texture max 256 bones (32 * 32 / 4)
// 64x64 pixel texture max 1024 bones (64 * 64 / 4)
// layout (1 matrix = 4 pixels)
// RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
// with 8x8 pixel texture max 16 bones (8 * 8 / 4)
// 16x16 pixel texture max 64 bones (16 * 16 / 4)
// 32x32 pixel texture max 256 bones (32 * 32 / 4)
// 64x64 pixel texture max 1024 bones (64 * 64 / 4)
var size;
var size;
if ( nBones > 256 )
size = 64;
else if ( nBones > 64 )
size = 32;
else if ( nBones > 16 )
size = 16;
else
size = 8;
if ( nBones > 256 )
size = 64;
else if ( nBones > 64 )
size = 32;
else if ( nBones > 16 )
size = 16;
else
size = 8;
this.boneTextureWidth = size;
this.boneTextureHeight = size;
this.boneTextureWidth = size;
this.boneTextureHeight = size;
this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
this.boneTexture.minFilter = THREE.NearestFilter;
this.boneTexture.magFilter = THREE.NearestFilter;
this.boneTexture.generateMipmaps = false;
this.boneTexture.flipY = false;
this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
this.boneTexture.minFilter = THREE.NearestFilter;
this.boneTexture.magFilter = THREE.NearestFilter;
this.boneTexture.generateMipmaps = false;
this.boneTexture.flipY = false;
} else {
} else {
this.boneMatrices = new Float32Array( 16 * nBones );
this.boneMatrices = new Float32Array( 16 * nBones );
}
}
}
}
};
......@@ -105,31 +105,31 @@ THREE.Skeleton.prototype = Object.create( THREE.Mesh.prototype );
THREE.Skeleton.prototype.addBone = function( bone ) {
if ( bone === undefined ) {
if ( bone === undefined ) {
bone = new THREE.Bone( this );
bone = new THREE.Bone( this );
}
}
this.bones.push( bone );
this.bones.push( bone );
return bone;
return bone;
};
THREE.Skeleton.prototype.calculateInverses = function( bone ) {
this.boneInverses = [];
this.boneInverses = [];
for ( var b = 0, bl = this.bones.length; b < bl; ++b ) {
for ( var b = 0, bl = this.bones.length; b < bl; ++b ) {
var inverse = new THREE.Matrix4();
var inverse = new THREE.Matrix4();
inverse.getInverse( this.bones[ b ].skinMatrix );
inverse.getInverse( this.bones[ b ].skinMatrix );
this.boneInverses.push( inverse );
this.boneInverses.push( inverse );
}
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册