diff --git a/examples/jsm/loaders/USDZLoader.js b/examples/jsm/loaders/USDZLoader.js index 7e0fefb3ddddf8..36a87a46f95d23 100644 --- a/examples/jsm/loaders/USDZLoader.js +++ b/examples/jsm/loaders/USDZLoader.js @@ -13,6 +13,7 @@ import { SRGBColorSpace, TextureLoader, Object3D, + Vector2 } from 'three'; import * as fflate from '../libs/fflate.module.js'; @@ -489,6 +490,30 @@ class USDZLoader extends Loader { } + function setTextureParams( map, data_value ) { + + // rotation, scale and translation + + if ( data_value[ 'float inputs:rotation' ] ) { + + map.rotation = parseFloat( data_value[ 'float inputs:rotation' ] ); + + } + + if ( data_value[ 'float2 inputs:scale' ] ) { + + map.repeat = new Vector2().fromArray( JSON.parse( '[' + data_value[ 'float2 inputs:scale' ].replace( /[()]*/g, '' ) + ']' ) ); + + } + + if ( data_value[ 'float2 inputs:translation' ] ) { + + map.offset = new Vector2().fromArray( JSON.parse( '[' + data_value[ 'float2 inputs:translation' ].replace( /[()]*/g, '' ) + ']' ) ); + + } + + } + function buildMaterial( data ) { const material = new MeshPhysicalMaterial(); @@ -507,6 +532,12 @@ class USDZLoader extends Loader { material.map = buildTexture( sampler ); material.map.colorSpace = SRGBColorSpace; + if ( 'def Shader "Transform2d_diffuse"' in data ) { + + setTextureParams( material.map, data[ 'def Shader "Transform2d_diffuse"' ] ); + + } + } else if ( 'color3f inputs:diffuseColor' in surface ) { const color = surface[ 'color3f inputs:diffuseColor' ].replace( /[()]*/g, '' ); @@ -523,6 +554,12 @@ class USDZLoader extends Loader { material.emissiveMap.colorSpace = SRGBColorSpace; material.emissive.set( 0xffffff ); + if ( 'def Shader "Transform2d_emissive"' in data ) { + + setTextureParams( material.emissiveMap, data[ 'def Shader "Transform2d_emissive"' ] ); + + } + } else if ( 'color3f inputs:emissiveColor' in surface ) { const color = surface[ 'color3f inputs:emissiveColor' ].replace( /[()]*/g, '' ); @@ -538,6 +575,12 @@ class USDZLoader extends Loader { material.normalMap = buildTexture( sampler ); material.normalMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_normal"' in data ) { + + setTextureParams( material.normalMap, data[ 'def Shader "Transform2d_normal"' ] ); + + } + } if ( 'float inputs:roughness.connect' in surface ) { @@ -549,6 +592,12 @@ class USDZLoader extends Loader { material.roughnessMap = buildTexture( sampler ); material.roughnessMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_roughness"' in data ) { + + setTextureParams( material.roughnessMap, data[ 'def Shader "Transform2d_roughness"' ] ); + + } + } else if ( 'float inputs:roughness' in surface ) { material.roughness = parseFloat( surface[ 'float inputs:roughness' ] ); @@ -564,6 +613,12 @@ class USDZLoader extends Loader { material.metalnessMap = buildTexture( sampler ); material.metalnessMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_metallic"' in data ) { + + setTextureParams( material.metalnessMap, data[ 'def Shader "Transform2d_metallic"' ] ); + + } + } else if ( 'float inputs:metallic' in surface ) { material.metalness = parseFloat( surface[ 'float inputs:metallic' ] ); @@ -579,6 +634,12 @@ class USDZLoader extends Loader { material.clearcoatMap = buildTexture( sampler ); material.clearcoatMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_clearcoat"' in data ) { + + setTextureParams( material.clearcoatMap, data[ 'def Shader "Transform2d_clearcoat"' ] ); + + } + } else if ( 'float inputs:clearcoat' in surface ) { material.clearcoat = parseFloat( surface[ 'float inputs:clearcoat' ] ); @@ -594,6 +655,12 @@ class USDZLoader extends Loader { material.clearcoatRoughnessMap = buildTexture( sampler ); material.clearcoatRoughnessMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_clearcoatRoughness"' in data ) { + + setTextureParams( material.clearcoatRoughnessMap, data[ 'def Shader "Transform2d_clearcoatRoughness"' ] ); + + } + } else if ( 'float inputs:clearcoatRoughness' in surface ) { material.clearcoatRoughness = parseFloat( surface[ 'float inputs:clearcoatRoughness' ] ); @@ -614,6 +681,12 @@ class USDZLoader extends Loader { material.aoMap = buildTexture( sampler ); material.aoMap.colorSpace = NoColorSpace; + if ( 'def Shader "Transform2d_occlusion"' in data ) { + + setTextureParams( material.aoMap, data[ 'def Shader "Transform2d_occlusion"' ] ); + + } + } }