From 70c43c59afb16972799da94ffd19b06b95cb9a47 Mon Sep 17 00:00:00 2001 From: hybridherbst Date: Thu, 7 Sep 2023 00:41:09 +0200 Subject: [PATCH] USDZLoader: Switch to MeshPhysicalMaterial and add clearcoat/clearcoatRoughness/ior support fix incorrect colorspace usage --- examples/jsm/loaders/USDZLoader.js | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/USDZLoader.js b/examples/jsm/loaders/USDZLoader.js index 9060e533203234..e95e6e8e73a6f1 100644 --- a/examples/jsm/loaders/USDZLoader.js +++ b/examples/jsm/loaders/USDZLoader.js @@ -7,7 +7,7 @@ import { NoColorSpace, Loader, Mesh, - MeshStandardMaterial, + MeshPhysicalMaterial, MirroredRepeatWrapping, RepeatWrapping, SRGBColorSpace, @@ -491,7 +491,7 @@ class USDZLoader extends Loader { function buildMaterial( data ) { - const material = new MeshStandardMaterial(); + const material = new MeshPhysicalMaterial(); if ( data !== undefined ) { @@ -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' ];