123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - animation authoring</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">
- </head>
- <body>
- <div id="info">
- "W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size<br />
- Press "Q" to toggle world/local space, hold down "Ctrl" to snap to grid
- </div>
- <script src="js/libs/timeliner_gui.min.js"></script>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { TransformControls } from './jsm/controls/TransformControls.js';
- import { TimelinerController } from './jsm/animation/TimelinerController.js';
- var camera, scene, renderer, control;
- init();
- render();
- function init() {
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- //
- camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 3000 );
- camera.position.set( 1000, 500, 1000 );
- camera.lookAt( 0, 200, 0 );
- scene = new THREE.Scene();
- scene.add( new THREE.GridHelper( 1000, 10 ) );
- var light = new THREE.DirectionalLight( 0xffffff, 2 );
- light.position.set( 1, 1, 1 );
- scene.add( light );
- var texture = new THREE.TextureLoader().load( 'textures/crate.gif', render );
- texture.mapping = THREE.UVMapping;
- texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
- var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
- var material = new THREE.MeshLambertMaterial( { map: texture } );
- control = new TransformControls( camera, renderer.domElement );
- control.addEventListener( 'change', render );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.name = "MyBox";
- scene.add( mesh );
- control.attach( mesh );
- scene.add( control );
- window.addEventListener( 'resize', onWindowResize, false );
- window.addEventListener( 'keydown', function ( event ) {
- switch ( event.keyCode ) {
- case 81: // Q
- control.setSpace( control.space === "local" ? "world" : "local" );
- break;
- case 17: // Ctrl
- control.setTranslationSnap( 100 );
- control.setRotationSnap( THREE.MathUtils.degToRad( 15 ) );
- break;
- case 87: // W
- control.setMode( "translate" );
- break;
- case 69: // E
- control.setMode( "rotate" );
- break;
- case 82: // R
- control.setMode( "scale" );
- break;
- case 187:
- case 107: // +, =, num+
- control.setSize( control.size + 0.1 );
- break;
- case 189:
- case 109: // -, _, num-
- control.setSize( Math.max( control.size - 0.1, 0.1 ) );
- break;
- }
- } );
- window.addEventListener( 'keyup', function ( event ) {
- switch ( event.keyCode ) {
- case 17: // Ctrl
- control.setTranslationSnap( null );
- control.setRotationSnap( null );
- break;
- }
- } );
- var trackInfo = [
- {
- type: THREE.VectorKeyframeTrack,
- propertyPath: 'MyBox.position',
- initialValue: [ 0, 0, 0 ],
- interpolation: THREE.InterpolateSmooth
- },
- {
- type: THREE.QuaternionKeyframeTrack,
- propertyPath: 'MyBox.quaternion',
- initialValue: [ 0, 0, 0, 1 ],
- interpolation: THREE.InterpolateLinear
- }
- ];
- new Timeliner( new TimelinerController( scene, trackInfo, render ) );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- render();
- }
- function render() {
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|