Skip to content

Commit

Permalink
USDZLoader: Load metallic, roughness, emissive, occlusion textures an…
Browse files Browse the repository at this point in the history
…d set color spaces
  • Loading branch information
hybridherbst committed Sep 6, 2023
1 parent fb931eb commit a52dfae
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions examples/jsm/loaders/USDZLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ClampToEdgeWrapping,
FileLoader,
Group,
LinearSRGBColorSpace,
Loader,
Mesh,
MeshStandardMaterial,
Expand Down Expand Up @@ -466,27 +467,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 = LinearSRGBColorSpace;

}

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

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

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

}

}

if ( 'def Shader "diffuseColor_texture"' in data ) {
Expand All @@ -503,6 +549,7 @@ class USDZLoader extends Loader {
const sampler = data[ 'def Shader "normal_texture"' ];

material.normalMap = buildTexture( sampler );
material.normalMap.colorSpace = LinearSRGBColorSpace;

}

Expand Down

0 comments on commit a52dfae

Please sign in to comment.