123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <html lang="en">
- <head>
- <title>Sheen demo (material property)</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">
- <style>
- body {
- color: #333;
- }
- </style>
- </head>
- <body>
- <div id="info">Sheen demo by <a href="https://github.com/DanielSturk">DanielSturk</a></div>
- <div id="container"></div>
- <script src="js/libs/ammo.js"></script>
- <script type="module">
- import * as THREE from '../build/three.module.js';
- import Stats from './jsm/libs/stats.module.js';
- import { GUI } from './jsm/libs/dat.gui.module.js';
- import { OrbitControls } from './jsm/controls/OrbitControls.js';
- import { FBXLoader } from './jsm/loaders/FBXLoader.js';
- // Graphics variables
- var camera, controls, scene, renderer, mesh, stats;
- var params = {
- sheen: .5,
- hue: 265,
- roughness: .9
- };
- // model
- new FBXLoader().load( 'models/fbx/cloth.fbx', function ( loadedModel ) {
- mesh = loadedModel.children[0];
- init();
- } );
- function init( ) {
- camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.2, 2000 );
- scene = new THREE.Scene();
- scene.background = new THREE.Color( 0xbfd1e5 );
- mesh.material = new THREE.MeshPhysicalMaterial();
- mesh.scale.multiplyScalar( .5 );
- scene.add( mesh );
- camera.position.set( - 12, 7, 4 );
- var container = document.getElementById( 'container' );
- renderer = new THREE.WebGLRenderer();
- renderer.setPixelRatio( window.devicePixelRatio );
- renderer.setSize( window.innerWidth, window.innerHeight );
- renderer.shadowMap.enabled = true;
- container.appendChild( renderer.domElement );
- controls = new OrbitControls( camera, renderer.domElement );
- controls.target.set( 0, 2, 0 );
- controls.update();
- var ambientLight = new THREE.AmbientLight( 0x404040 );
- scene.add( ambientLight );
- var light = new THREE.DirectionalLight( 0xffffff, 1.5 );
- light.position.set( - 7, 30, 15 );
- light.castShadow = true;
- var d = 10;
- light.shadow.camera.left = - d;
- light.shadow.camera.right = d;
- light.shadow.camera.top = d;
- light.shadow.camera.bottom = - d;
- light.shadow.camera.near = 2;
- light.shadow.camera.far = 50;
- light.shadow.mapSize.x = 1024;
- light.shadow.mapSize.y = 1024;
- light.shadow.bias = - 0.003;
- scene.add( light );
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.top = '0px';
- container.appendChild( stats.dom );
- window.addEventListener( 'resize', onWindowResize, false );
- var gui = new GUI();
- gui.add( params, 'sheen', 0, 1 );
- gui.add( params, 'hue', 0, 360 );
- gui.add( params, 'roughness', 0, 1 );
- gui.open();
- animate();
- }
- function onWindowResize() {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize( window.innerWidth, window.innerHeight );
- }
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- mesh.material.sheen = params.sheen;
- mesh.material.color = new THREE.Color().setHSL(params.hue / 360, 1, .5);
- mesh.material.roughness = params.roughness;
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|