Skip to content

Commit

Permalink
USDZLoader: Switch to MeshPhysicalMaterial and add clearcoat/clearcoa…
Browse files Browse the repository at this point in the history
…tRoughness/ior support

fix incorrect colorspace usage
  • Loading branch information
hybridherbst committed Sep 7, 2023
1 parent 898a633 commit 70c43c5
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions examples/jsm/loaders/USDZLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
NoColorSpace,
Loader,
Mesh,
MeshStandardMaterial,
MeshPhysicalMaterial,
MirroredRepeatWrapping,
RepeatWrapping,
SRGBColorSpace,
Expand Down Expand Up @@ -491,7 +491,7 @@ class USDZLoader extends Loader {

function buildMaterial( data ) {

const material = new MeshStandardMaterial();
const material = new MeshPhysicalMaterial();

if ( data !== undefined ) {

Expand Down Expand Up @@ -570,6 +570,42 @@ class USDZLoader extends Loader {

}

if ( 'float inputs:clearcoat.connect' in surface ) {

const path = surface[ 'float inputs:clearcoat.connect' ];
const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] );

material.clearcoat = 1.0;
material.clearcoatMap = buildTexture( sampler );
material.clearcoatMap.colorSpace = NoColorSpace;

} else if ( 'float inputs:clearcoat' in surface ) {

material.clearcoat = parseFloat( surface[ 'float inputs:clearcoat' ] );

}

if ( 'float inputs:clearcoatRoughness.connect' in surface ) {

const path = surface[ 'float inputs:clearcoatRoughness.connect' ];
const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] );

material.clearcoatRoughness = 1.0;
material.clearcoatRoughnessMap = buildTexture( sampler );
material.clearcoatRoughnessMap.colorSpace = NoColorSpace;

} else if ( 'float inputs:clearcoatRoughness' in surface ) {

material.clearcoatRoughness = parseFloat( surface[ 'float inputs:clearcoatRoughness' ] );

}

if ( 'float inputs:ior' in surface ) {

material.ior = parseFloat( surface[ 'float inputs:ior' ] );

}

if ( 'float inputs:occlusion.connect' in surface ) {

const path = surface[ 'float inputs:occlusion.connect' ];
Expand Down

0 comments on commit 70c43c5

Please sign in to comment.