123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - materials - modified</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> wegbl - modified material.
- <a href="http://graphics.cs.williams.edu/data/meshes.xml#14" target="_blank" rel="noopener">Lee Perry-Smith</a> head.
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
- var camera, scene, renderer, stats;
- var materialShader;
- init();
- animate();
- function init() {
- camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 1, 10000 );
- camera.position.z = 1500;
- scene = new THREE.Scene();
- var material = new THREE.MeshNormalMaterial();
- material.onBeforeCompile = function ( shader ) {
- shader.uniforms.time = { value: 0 };
- shader.vertexShader = 'uniform float time;\n' + shader.vertexShader;
- shader.vertexShader = shader.vertexShader.replace(
- '#include <begin_vertex>',
- [
- 'float theta = sin( time + position.y ) / 2.0;',
- 'float c = cos( theta );',
- 'float s = sin( theta );',
- 'mat3 m = mat3( c, 0, s, 0, 1, 0, -s, 0, c );',
- 'vec3 transformed = vec3( position ) * m;',
- 'vNormal = vNormal * m;'
- ].join( '\n' )
- );
- materialShader = shader;
- };
- var loader = new GLTFLoader();
- loader.load( 'models/gltf/LeePerrySmith/LeePerrySmith.glb', function ( gltf ) {
- var mesh = new THREE.Mesh( gltf.scene.children[ 0 ].geometry, material );
- mesh.position.y = - 50;
- mesh.scale.setScalar( 100 );
- scene.add( mesh );
- } );
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- document.body.appendChild( renderer.domElement );
- var controls = new OrbitControls( camera, renderer.domElement );
- //
- stats = new Stats();
- document.body.appendChild( stats.dom );
- // EVENTS
- window.addEventListener( 'resize', onWindowResize, false );
- }
- //
- function onWindowResize() {
- var width = window.innerWidth;
- var height = window.innerHeight;
- camera.aspect = width / height;
- camera.updateProjectionMatrix();
- renderer.setSize( width, height );
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- if ( materialShader ) {
- materialShader.uniforms.time.value = performance.now() / 1000;
- }
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|