|
@@ -0,0 +1,143 @@
|
|
|
+<!DOCTYPE HTML>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js webgl - morph targets - horse</title>
|
|
|
+ <meta charset="utf-8">
|
|
|
+ <style type="text/css">
|
|
|
+ body {
|
|
|
+ font-family: Monospace;
|
|
|
+ background-color: #f0f0f0;
|
|
|
+ margin: 0px;
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+
|
|
|
+ <script type="text/javascript" src="../build/Three.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
|
|
|
+ <script type="text/javascript" src="js/Stats.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+
|
|
|
+ var container, stats;
|
|
|
+ var camera, scene, projector, renderer;
|
|
|
+ var mesh;
|
|
|
+
|
|
|
+ init();
|
|
|
+ animate();
|
|
|
+
|
|
|
+ function init() {
|
|
|
+
|
|
|
+ container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
+
|
|
|
+ var info = document.createElement( 'div' );
|
|
|
+ info.style.position = 'absolute';
|
|
|
+ info.style.top = '10px';
|
|
|
+ info.style.width = '100%';
|
|
|
+ info.style.textAlign = 'center';
|
|
|
+ info.innerHTML = '<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - morph targets - horse. model by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a>';
|
|
|
+ container.appendChild( info );
|
|
|
+
|
|
|
+ camera = new THREE.Camera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
|
|
|
+ camera.position.y = 300;
|
|
|
+ camera.target.position.y = 150;
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+
|
|
|
+ var light = new THREE.DirectionalLight( 0xefefff, 2 );
|
|
|
+ light.position.x = 1;
|
|
|
+ light.position.y = 1;
|
|
|
+ light.position.z = 1;
|
|
|
+ light.position.normalize();
|
|
|
+ scene.addLight( light );
|
|
|
+
|
|
|
+ var light = new THREE.DirectionalLight( 0xffefef, 2 );
|
|
|
+ light.position.x = - 1;
|
|
|
+ light.position.y = - 1;
|
|
|
+ light.position.z = - 1;
|
|
|
+ light.position.normalize();
|
|
|
+ scene.addLight( light );
|
|
|
+
|
|
|
+ var loader = new THREE.JSONLoader( true );
|
|
|
+ loader.load( { model: "models/animated/horse.js", callback: function( geometry ) {
|
|
|
+
|
|
|
+ mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: 0x606060, morphTargets: true } ) );
|
|
|
+ mesh.scale.set( 1.5, 1.5, 1.5 );
|
|
|
+ scene.addObject( mesh );
|
|
|
+
|
|
|
+ } } );
|
|
|
+
|
|
|
+ renderer = new THREE.WebGLRenderer();
|
|
|
+ renderer.sortObjects = false;
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+
|
|
|
+ container.appendChild(renderer.domElement);
|
|
|
+
|
|
|
+ stats = new Stats();
|
|
|
+ stats.domElement.style.position = 'absolute';
|
|
|
+ stats.domElement.style.top = '0px';
|
|
|
+ container.appendChild( stats.domElement );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ function animate() {
|
|
|
+
|
|
|
+ requestAnimationFrame( animate );
|
|
|
+
|
|
|
+ render();
|
|
|
+ stats.update();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var radius = 600;
|
|
|
+ var theta = 0;
|
|
|
+
|
|
|
+ var duration = 1000;
|
|
|
+ var keyframes = 15 /*16*/, interpolation = duration / keyframes;
|
|
|
+ var lastKeyframe = 0, currentKeyframe = 0;
|
|
|
+
|
|
|
+ function render() {
|
|
|
+
|
|
|
+ theta += 0.2;
|
|
|
+ camera.position.x = radius * Math.sin( theta * Math.PI / 360 );
|
|
|
+ camera.position.z = radius * Math.cos( theta * Math.PI / 360 );
|
|
|
+
|
|
|
+ if ( mesh ) {
|
|
|
+
|
|
|
+ // Alternate morph targets
|
|
|
+
|
|
|
+ var time = new Date().getTime() % duration;
|
|
|
+
|
|
|
+ var keyframe = Math.floor( time / interpolation ) + 1;
|
|
|
+
|
|
|
+ if ( keyframe != currentKeyframe ) {
|
|
|
+
|
|
|
+ mesh.morphTargetInfluences[ lastKeyframe ] = 0;
|
|
|
+ mesh.morphTargetInfluences[ currentKeyframe ] = 1;
|
|
|
+ mesh.morphTargetInfluences[ keyframe ] = 0;
|
|
|
+
|
|
|
+ lastKeyframe = currentKeyframe;
|
|
|
+ currentKeyframe = keyframe;
|
|
|
+
|
|
|
+ // console.log( mesh.morphTargetInfluences );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ mesh.morphTargetInfluences[ keyframe ] = ( time % interpolation ) / interpolation;
|
|
|
+ mesh.morphTargetInfluences[ lastKeyframe ] = 1 - mesh.morphTargetInfluences[ keyframe ];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ renderer.render( scene, camera );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+
|
|
|
+ </body>
|
|
|
+</html>
|