| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - transform controls</title>
- <meta charset="utf-8">
- <style>
- body {
- margin: 0px;
- background-color: #000000;
- color: #fff;
- font-family:Monospace;
- text-align: center;
- font-size: 15px;
- line-height: 30px;
- overflow: hidden;
- }
- #info {
- position: absolute;
- top: 0px; width: 100%;
- padding: 15px;
- z-index:100;
- }
- </style>
- </head>
- <body>
- <div id="info">
- "W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size<br />
- Press "w/E/R" twice to toggle world/local space
- </div>
- <script src="../build/three.min.js"></script>
- <script src="js/controls/TransformControls.js"></script>
- <script>
- var camera, scene, renderer;
- var grid, box;
- init();
- animate();
- function init() {
- renderer = new THREE.WebGLRenderer();
- renderer.sortObjects = false;
- 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, 1000, 1000 );
- camera.lookAt( new THREE.Vector3( 0, 700, 0 ) );
- scene = new THREE.Scene();
- var texture = THREE.ImageUtils.loadTexture( 'textures/crate.gif' );
- texture.anisotropy = renderer.getMaxAnisotropy();
- grid = new THREE.Mesh(
- new THREE.PlaneGeometry( 1000, 1000, 10, 10 ),
- new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe:true } )
- );
- grid.rotation.x = Math.PI/2;
- scene.add(grid);
- box = [];
- box[0] = new THREE.Mesh(
- new THREE.CubeGeometry( 200, 200, 200 ),
- new THREE.MeshBasicMaterial( { map: texture } )
- );
- box[0].position.set( 0, 100, 0 );
- scene.add( box[0] );
- box[1] = box[0].clone();
- box[1].position.set( 0, 350, 0 );
- box[0].add( box[1] );
- box[2] = box[1].clone();
- box[2].position.set( 0, 350, 0 );
- box[1].add( box[2] );
- box[3] = box[2].clone();
- box[3].position.set( 0, 350, 0 );
- box[2].add( box[3] );
- for ( var i = 0; i < box.length; i++ ){
- var translateLocal = new THREE.TransformControls( camera, renderer.domElement );
- scene.add( translateLocal.gizmo );
- translateLocal.attatch( box[i] );
- }
- 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 );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|