123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - loaders - Draco loader</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="container"></div>
- <div id="info">
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> -
- <a href="https://github.com/google/draco" target="_blank" rel="noopener">DRACO</a> loader
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import { DRACOLoader } from './jsm/loaders/DRACOLoader.js';
- var camera, scene, renderer;
- var container = document.querySelector( '#container' );
- // Configure and create Draco decoder.
- var dracoLoader = new DRACOLoader();
- dracoLoader.setDecoderPath( 'js/libs/draco/' );
- dracoLoader.setDecoderConfig( { type: 'js' } );
- init();
- animate();
- function init() {
- camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 15 );
- camera.position.set( 3, 0.25, 3 );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0x443333 );
- scene.fog = new THREE.Fog( 0x443333, 1, 4 );
- // Ground
- var plane = new THREE.Mesh(
- new THREE.PlaneBufferGeometry( 8, 8 ),
- new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
- );
- plane.rotation.x = - Math.PI / 2;
- plane.position.y = 0.03;
- plane.receiveShadow = true;
- scene.add( plane );
- // Lights
- var light = new THREE.HemisphereLight( 0x443333, 0x111122 );
- scene.add( light );
- var light = new THREE.SpotLight();
- light.angle = Math.PI / 16;
- light.penumbra = 0.5;
- light.castShadow = true;
- light.position.set( - 1, 1, 1 );
- scene.add( light );
- dracoLoader.load( 'models/draco/bunny.drc', function ( geometry ) {
- geometry.computeVertexNormals();
- var material = new THREE.MeshStandardMaterial( { color: 0x606060 } );
- var mesh = new THREE.Mesh( geometry, material );
- mesh.castShadow = true;
- mesh.receiveShadow = true;
- scene.add( mesh );
- // Release decoder resources.
- dracoLoader.dispose();
- } );
- // renderer
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.outputEncoding = THREE.sRGBEncoding;
- renderer.shadowMap.enabled = true;
- container.appendChild( renderer.domElement );
- window.addEventListener( 'resize', onWindowResize, false );
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- render();
- requestAnimationFrame( animate );
- }
- function render() {
- var timer = Date.now() * 0.0003;
- camera.position.x = Math.sin( timer ) * 0.5;
- camera.position.z = Math.cos( timer ) * 0.5;
- camera.lookAt( 0, 0.1, 0 );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|