Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USDZLoader: Load metallic, roughness, emissive, occlusion textures and fix color spaces #26710

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
hybridherbst marked this conversation as resolved.
Show resolved Hide resolved

}

Expand Down