From 5696f32f5da2bb2d516e9730ce08d3bc2275cea0 Mon Sep 17 00:00:00 2001 From: hybridherbst Date: Thu, 7 Sep 2023 10:51:39 +0200 Subject: [PATCH] USDZLoader: Load metallic, roughness, emissive, occlusion textures and fix color spaces (#26710) * USDZLoader: Load metallic, roughness, emissive, occlusion textures and set color spaces * fix incorrect colorspace usage --- examples/jsm/loaders/USDZLoader.js | 51 ++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/USDZLoader.js b/examples/jsm/loaders/USDZLoader.js index 7392e719a4bf68..9060e533203234 100644 --- a/examples/jsm/loaders/USDZLoader.js +++ b/examples/jsm/loaders/USDZLoader.js @@ -4,6 +4,7 @@ import { ClampToEdgeWrapping, FileLoader, Group, + NoColorSpace, Loader, Mesh, MeshStandardMaterial, @@ -513,27 +514,72 @@ class USDZLoader extends Loader { } + if ( 'color3f inputs:emissiveColor.connect' in surface ) { + + const path = surface[ 'color3f inputs:emissiveColor.connect' ]; + const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] ); + + material.emissiveMap = buildTexture( sampler ); + material.emissiveMap.colorSpace = SRGBColorSpace; + material.emissive.set( 0xffffff ); + + } else if ( 'color3f inputs:emissiveColor' in surface ) { + + const color = surface[ 'color3f inputs:emissiveColor' ].replace( /[()]*/g, '' ); + material.emissive.fromArray( JSON.parse( '[' + color + ']' ) ); + + } + if ( 'normal3f inputs:normal.connect' in surface ) { const path = surface[ 'normal3f inputs:normal.connect' ]; const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] ); material.normalMap = buildTexture( sampler ); + material.normalMap.colorSpace = NoColorSpace; } - if ( 'float inputs:roughness' in surface ) { + if ( 'float inputs:roughness.connect' in surface ) { + + const path = surface[ 'float inputs:roughness.connect' ]; + const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] ); + + material.roughness = 1.0; + material.roughnessMap = buildTexture( sampler ); + material.roughnessMap.colorSpace = NoColorSpace; + + } else if ( 'float inputs:roughness' in surface ) { material.roughness = parseFloat( surface[ 'float inputs:roughness' ] ); } - if ( 'float inputs:metallic' in surface ) { + if ( 'float inputs:metallic.connect' in surface ) { + + const path = surface[ 'float inputs:metallic.connect' ]; + const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] ); + + material.metalness = 1.0; + material.metalnessMap = buildTexture( sampler ); + material.metalnessMap.colorSpace = NoColorSpace; + + } else if ( 'float inputs:metallic' in surface ) { material.metalness = parseFloat( surface[ 'float inputs:metallic' ] ); } + if ( 'float inputs:occlusion.connect' in surface ) { + + const path = surface[ 'float inputs:occlusion.connect' ]; + const sampler = findTexture( root, /(\w+).output/.exec( path )[ 1 ] ); + + material.aoMap = buildTexture( sampler ); + material.aoMap.colorSpace = NoColorSpace; + + } + } if ( 'def Shader "diffuseColor_texture"' in data ) { @@ -550,6 +596,7 @@ class USDZLoader extends Loader { const sampler = data[ 'def Shader "normal_texture"' ]; material.normalMap = buildTexture( sampler ); + material.normalMap.colorSpace = NoColorSpace; }