123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - helpers</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">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - helpers
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
- import { VertexNormalsHelper } from './jsm/helpers/VertexNormalsHelper.js';
- import { VertexTangentsHelper } from './jsm/helpers/VertexTangentsHelper.js';
- import { BufferGeometryUtils } from './jsm/utils/BufferGeometryUtils.js';
- var scene, renderer;
- var camera, light;
- var vnh;
- var vth;
- init();
- animate();
- function init() {
- renderer = new THREE.WebGLRenderer();
- 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, 1000 );
- camera.position.z = 400;
- scene = new THREE.Scene();
- light = new THREE.PointLight();
- light.position.set( 200, 100, 150 );
- scene.add( light );
- scene.add( new THREE.PointLightHelper( light, 15 ) );
- var gridHelper = new THREE.GridHelper( 400, 40, 0x0000ff, 0x808080 );
- gridHelper.position.y = - 150;
- gridHelper.position.x = - 150;
- scene.add( gridHelper );
- var polarGridHelper = new THREE.PolarGridHelper( 200, 16, 8, 64, 0x0000ff, 0x808080 );
- polarGridHelper.position.y = - 150;
- polarGridHelper.position.x = 200;
- scene.add( polarGridHelper );
- var loader = new GLTFLoader();
- loader.load( 'models/gltf/LeePerrySmith/LeePerrySmith.glb', function ( gltf ) {
- var mesh = gltf.scene.children[ 0 ];
- BufferGeometryUtils.computeTangents( mesh.geometry ); // generates bad data due to degenerate UVs
- var group = new THREE.Group();
- group.scale.multiplyScalar( 50 );
- scene.add( group );
- // To make sure that the matrixWorld is up to date for the boxhelpers
- group.updateMatrixWorld( true );
- group.add( mesh );
- vnh = new VertexNormalsHelper( mesh, 5 );
- scene.add( vnh );
- vth = new VertexTangentsHelper( mesh, 5 );
- scene.add( vth );
- scene.add( new THREE.BoxHelper( mesh ) );
- var wireframe = new THREE.WireframeGeometry( mesh.geometry );
- var line = new THREE.LineSegments( wireframe );
- line.material.depthTest = false;
- line.material.opacity = 0.25;
- line.material.transparent = true;
- line.position.x = 4;
- group.add( line );
- scene.add( new THREE.BoxHelper( line ) );
- var edges = new THREE.EdgesGeometry( mesh.geometry );
- var line = new THREE.LineSegments( edges );
- line.material.depthTest = false;
- line.material.opacity = 0.25;
- line.material.transparent = true;
- line.position.x = - 4;
- group.add( line );
- scene.add( new THREE.BoxHelper( line ) );
- scene.add( new THREE.BoxHelper( group ) );
- scene.add( new THREE.BoxHelper( scene ) );
- } );
- //
- 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 );
- var time = - performance.now() * 0.0003;
- camera.position.x = 400 * Math.cos( time );
- camera.position.z = 400 * Math.sin( time );
- camera.lookAt( scene.position );
- light.position.x = Math.sin( time * 1.7 ) * 300;
- light.position.y = Math.cos( time * 1.5 ) * 400;
- light.position.z = Math.cos( time * 1.3 ) * 300;
- if ( vnh ) vnh.update();
- if ( vth ) vth.update();
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|