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
  • Loading branch information
hybridherbst committed Sep 6, 2023
1 parent fb931eb commit adced29
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 @@ -6,7 +6,7 @@ import {
Group,
Loader,
Mesh,
MeshStandardMaterial,
MeshPhysicalMaterial,
MirroredRepeatWrapping,
RepeatWrapping,
SRGBColorSpace,
Expand Down Expand Up @@ -443,7 +443,7 @@ class USDZLoader extends Loader {

function buildMaterial( data ) {

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

if ( data !== undefined ) {

Expand Down Expand Up @@ -487,6 +487,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 = LinearSRGBColorSpace;

} 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 = LinearSRGBColorSpace;

} 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 ( 'def Shader "diffuseColor_texture"' in data ) {
Expand Down

0 comments on commit adced29

Please sign in to comment.