From 8ce5b04cdb7ef85668af840411c5e2eb7581f7cb Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 22 May 2024 11:59:15 +0200 Subject: [PATCH] USDZExporter: Add `normalScale` support. --- examples/jsm/exporters/USDZExporter.js | 32 +++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/examples/jsm/exporters/USDZExporter.js b/examples/jsm/exporters/USDZExporter.js index 5520d92910d89b..4ba95092072a2d 100644 --- a/examples/jsm/exporters/USDZExporter.js +++ b/examples/jsm/exporters/USDZExporter.js @@ -467,7 +467,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) { const inputs = []; const samplers = []; - function buildTexture( texture, mapType, color ) { + function buildTexture( texture, mapType, scale = null ) { const id = texture.source.id + '_' + texture.flipY; @@ -537,7 +537,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) { uniform token info:id = "UsdUVTexture" asset inputs:file = @textures/Texture_${ id }.png@ float2 inputs:st.connect = - ${ color !== undefined ? 'float4 inputs:scale = ' + buildColor4( color ) : '' } + ${ scale !== null ? 'float4 inputs:scale = ' + buildScale( scale, mapType ) : '' } token inputs:sourceColorSpace = "${ texture.colorSpace === NoColorSpace ? 'raw' : 'sRGB' }" token inputs:wrapS = "${ WRAPPINGS[ texture.wrapS ] }" token inputs:wrapT = "${ WRAPPINGS[ texture.wrapT ] }" @@ -596,7 +596,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) { inputs.push( `${ pad }normal3f inputs:normal.connect = ` ); - samplers.push( buildTexture( material.normalMap, 'normal' ) ); + samplers.push( buildTexture( material.normalMap, 'normal', material.normalScale ) ); } @@ -673,6 +673,26 @@ ${ samplers.join( '\n' ) } } +function buildScale( scale, mapType ) { + + let value; + + switch ( mapType ) { + + case 'diffuse': + value = buildColor4( scale ); + break; + + case 'normal': + value = buildNormalScale( scale ); + break; + + } + + return value; + +} + function buildColor( color ) { return `(${ color.r }, ${ color.g }, ${ color.b })`; @@ -691,6 +711,12 @@ function buildVector2( vector ) { } +function buildNormalScale( normalScale ) { + + return `(${ normalScale.x }, ${ normalScale.y }, 1.0, 1.0)`; + +} + function buildCamera( camera ) {