123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>three.js webgl - materials - standard</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> - webgl physically based material<br/>
- <a href="http://www.polycount.com/forum/showthread.php?t=130641" target="_blank" rel="noopener">Cerberus(FFVII Gun) model</a> by Andrew Maximov.
- </div>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { TrackballControls } from './jsm/controls/TrackballControls.js';
- import { OBJLoader } from './jsm/loaders/OBJLoader.js';
- import { RGBELoader } from './jsm/loaders/RGBELoader.js';
- var statsEnabled = true;
- var container, stats;
- var camera, scene, renderer, controls;
- init();
- animate();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- renderer = new THREE.WebGLRenderer( { antialias: true } );
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- renderer.outputEncoding = THREE.sRGBEncoding;
- renderer.toneMapping = THREE.ReinhardToneMapping;
- renderer.toneMappingExposure = 3;
- //
- scene = new THREE.Scene();
- camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.01, 1000 );
- camera.position.z = 2;
- controls = new TrackballControls( camera, renderer.domElement );
- //
- scene.add( new THREE.HemisphereLight( 0x443333, 0x222233, 4 ) );
- //
- var material = new THREE.MeshStandardMaterial();
- new OBJLoader()
- .setPath( 'models/obj/cerberus/' )
- .load( 'Cerberus.obj', function ( group ) {
- var loader = new THREE.TextureLoader()
- .setPath( 'models/obj/cerberus/' );
- material.roughness = 1; // attenuates roughnessMap
- material.metalness = 1; // attenuates metalnessMap
- var diffuseMap = loader.load( 'Cerberus_A.jpg' );
- diffuseMap.encoding = THREE.sRGBEncoding;
- material.map = diffuseMap;
- // roughness is in G channel, metalness is in B channel
- material.metalnessMap = material.roughnessMap = loader.load( 'Cerberus_RM.jpg' );
- material.normalMap = loader.load( 'Cerberus_N.jpg' );
- material.map.wrapS = THREE.RepeatWrapping;
- material.roughnessMap.wrapS = THREE.RepeatWrapping;
- material.metalnessMap.wrapS = THREE.RepeatWrapping;
- material.normalMap.wrapS = THREE.RepeatWrapping;
- group.traverse( function ( child ) {
- if ( child.isMesh ) {
- child.material = material;
- }
- } );
- group.position.x = - 0.45;
- group.rotation.y = - Math.PI / 2;
- scene.add( group );
- } );
- new RGBELoader()
- .setDataType( THREE.UnsignedByteType )
- .setPath( 'textures/equirectangular/' )
- .load( 'venice_sunset_1k.hdr', function ( hdrEquirect ) {
- var hdrCubeRenderTarget = pmremGenerator.fromEquirectangular( hdrEquirect );
- hdrEquirect.dispose();
- pmremGenerator.dispose();
- scene.background = hdrCubeRenderTarget.texture;
- scene.environment = hdrCubeRenderTarget.texture;
- } );
- var pmremGenerator = new THREE.PMREMGenerator( renderer );
- pmremGenerator.compileEquirectangularShader();
- //
- if ( statsEnabled ) {
- stats = new Stats();
- container.appendChild( stats.dom );
- }
- window.addEventListener( 'resize', onWindowResize, false );
- }
- //
- function onWindowResize() {
- renderer.setSize( window.innerWidth, window.innerHeight );
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- controls.update();
- renderer.render( scene, camera );
- if ( statsEnabled ) stats.update();
- }
- </script>
- </body>
- </html>
|