Skip to content

Commit

Permalink
Examples: Added webgl_loader_gltf_sheen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Oct 13, 2021
1 parent 63632f2 commit 736ae99
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 201 deletions.
1 change: 0 additions & 1 deletion docs/api/en/materials/MeshPhysicalMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ <h2>Examples</h2>
[example:webgl_materials_variations_physical materials / variations / physical]<br />
[example:webgl_materials_physical_clearcoat materials / physical / clearcoat]<br />
[example:webgl_materials_physical_reflectivity materials / physical / reflectivity]<br />
[example:webgl_materials_physical_sheen materials / physical / sheen]<br />
[example:webgl_materials_physical_transmission materials / physical / transmission]
</p>

Expand Down
1 change: 0 additions & 1 deletion docs/api/zh/materials/MeshPhysicalMaterial.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ <h2>例子</h2>
[example:webgl_materials_variations_physical materials / variations / physical]<br />
[example:webgl_materials_physical_clearcoat materials / physical / clearcoat]<br />
[example:webgl_materials_physical_reflectivity materials / physical / reflectivity]<br />
[example:webgl_materials_physical_sheen materials / physical / sheen]<br />
[example:webgl_materials_physical_transmission materials / physical / transmission]
</p>

Expand Down
2 changes: 1 addition & 1 deletion examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"webgl_loader_gcode",
"webgl_loader_gltf",
"webgl_loader_gltf_compressed",
"webgl_loader_gltf_sheen",
"webgl_loader_gltf_transmission",
"webgl_loader_gltf_variants",
"webgl_loader_ifc",
Expand Down Expand Up @@ -146,7 +147,6 @@
"webgl_materials_normalmap_object_space",
"webgl_materials_physical_clearcoat",
"webgl_materials_physical_reflectivity",
"webgl_materials_physical_sheen",
"webgl_materials_physical_transmission",
"webgl_materials_standard",
"webgl_materials_subsurface_scattering",
Expand Down
71 changes: 71 additions & 0 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class GLTFLoader extends Loader {

} );

this.register( function ( parser ) {

return new GLTFMaterialsSheenExtension( parser );

} );

this.register( function ( parser ) {

return new GLTFMaterialsTransmissionExtension( parser );
Expand Down Expand Up @@ -428,6 +434,7 @@ const EXTENSIONS = {
KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
KHR_MATERIALS_IOR: 'KHR_materials_ior',
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
Expand Down Expand Up @@ -704,6 +711,70 @@ class GLTFMaterialsClearcoatExtension {

}

/**
* Sheen Materials Extension
*
* Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
*/
class GLTFMaterialsSheenExtension {

constructor( parser ) {

this.parser = parser;
this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;

}

getMaterialType( materialIndex ) {

const parser = this.parser;
const materialDef = parser.json.materials[ materialIndex ];

if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;

return MeshPhysicalMaterial;

}

extendMaterialParams( materialIndex, materialParams ) {

const parser = this.parser;
const materialDef = parser.json.materials[ materialIndex ];

if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {

return Promise.resolve();

}

const pending = [];

materialParams.sheenTint = new Color( 0, 0, 0 );
materialParams.sheenRoughness = 0;
materialParams.sheen = 1;

const extension = materialDef.extensions[ this.name ];

if ( extension.sheenColorFactor !== undefined ) {

materialParams.sheenTint.fromArray( extension.sheenColorFactor );

}

if ( extension.sheenRoughnessFactor !== undefined ) {

materialParams.sheenRoughness = extension.sheenRoughnessFactor;

}

// TODO sheenColorTexture and sheenRoughnessTexture

return Promise.all( pending );

}

}

/**
* Transmission Materials Extension
*
Expand Down
Binary file removed examples/models/fbx/cloth.fbx
Binary file not shown.
Binary file added examples/models/gltf/SheenChair.glb
Binary file not shown.
Binary file added examples/screenshots/webgl_loader_gltf_sheen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
113 changes: 113 additions & 0 deletions examples/webgl_loader_gltf_sheen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - glTF 2.0 - transmission</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> - GLTFLoader + <a href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_sheen" target="_blank" rel="noopener">KHR_materials_sheen</a> extension<br />
Sheen Chair from <a href="https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/SheenChair" target="_blank" rel="noopener">glTF-Sample-Models</a>
</div>

<script type="module">

import * as THREE from '../build/three.module.js';

import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
import { RoomEnvironment } from './jsm/environments/RoomEnvironment.js';

import { GUI } from './jsm/libs/dat.gui.module.js';

let camera, scene, renderer, controls;

init();
animate();

function init() {

const container = document.createElement( 'div' );
document.body.appendChild( container );

camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 20 );
camera.position.set( 0, 1, 2 );

scene = new THREE.Scene();

// model

new GLTFLoader()
.setPath( 'models/gltf/' )
.load( 'SheenChair.glb', function ( gltf ) {

scene.add( gltf.scene );

const object = gltf.scene.getObjectByName( 'SheenChair_fabric' );

const gui = new GUI();

gui.add( object.material, 'sheen', 0, 1 );
gui.open();

} );

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1;
renderer.outputEncoding = THREE.sRGBEncoding;
container.appendChild( renderer.domElement );

const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0xbbbbbb );
scene.environment = pmremGenerator.fromScene( environment ).texture;

controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.minDistance = 1;
controls.maxDistance = 10;
controls.target.set( 0, 0.5, 0 );
controls.update();

window.addEventListener( 'resize', onWindowResize );

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );

}

//

function animate() {

requestAnimationFrame( animate );

controls.update(); // required if damping enabled

render();

}

function render() {

renderer.render( scene, camera );

}

</script>

</body>
</html>
Loading

0 comments on commit 736ae99

Please sign in to comment.