123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - morph targets - horse</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <link type="text/css" rel="stylesheet" href="main.css">
- <style>
- body {
- background-color: #f0f0f0;
- color: #444;
- }
- a {
- color: #08f;
- }
- </style>
- </head>
- <body>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - morph targets - horse<br/>
- model by <a href="http://mirada.com/">mirada</a> from <a href="http://ro.me">rome</a>
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
- var container, stats;
- var camera, scene, renderer;
- var mesh, mixer;
- init();
- animate();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- //
- camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 10000 );
- camera.position.y = 300;
- camera.target = new THREE.Vector3( 0, 150, 0 );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xf0f0f0 );
- //
- var light = new THREE.DirectionalLight( 0xefefff, 1.5 );
- light.position.set( 1, 1, 1 ).normalize();
- scene.add( light );
- var light = new THREE.DirectionalLight( 0xffefef, 1.5 );
- light.position.set( - 1, - 1, - 1 ).normalize();
- scene.add( light );
- var loader = new GLTFLoader();
- loader.load( "models/gltf/Horse.glb", function ( gltf ) {
- mesh = gltf.scene.children[ 0 ];
- mesh.scale.set( 1.5, 1.5, 1.5 );
- scene.add( mesh );
- mixer = new THREE.AnimationMixer( mesh );
- mixer.clipAction( gltf.animations[ 0 ] ).setDuration( 1 ).play();
- } );
- //
- renderer = new THREE.WebGLRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.outputEncoding = THREE.sRGBEncoding;
- container.appendChild( renderer.domElement );
- //
- stats = new Stats();
- container.appendChild( stats.dom );
- //
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- var radius = 600;
- var theta = 0;
- var prevTime = Date.now();
- function render() {
- theta += 0.1;
- camera.position.x = radius * Math.sin( THREE.MathUtils.degToRad( theta ) );
- camera.position.z = radius * Math.cos( THREE.MathUtils.degToRad( theta ) );
- camera.lookAt( camera.target );
- if ( mixer ) {
- var time = Date.now();
- mixer.update( ( time - prevTime ) * 0.001 );
- prevTime = time;
- }
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|