Skip to content

Commit

Permalink
USDZExporter: Add normalScale support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed May 22, 2024
1 parent 02ed248 commit 8ce5b04
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
${ 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 ] }"
Expand Down Expand Up @@ -596,7 +596,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) {

inputs.push( `${ pad }normal3f inputs:normal.connect = </Materials/Material_${ material.id }/Texture_${ material.normalMap.id }_normal.outputs:rgb>` );

samplers.push( buildTexture( material.normalMap, 'normal' ) );
samplers.push( buildTexture( material.normalMap, 'normal', material.normalScale ) );

}

Expand Down Expand Up @@ -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 })`;
Expand All @@ -691,6 +711,12 @@ function buildVector2( vector ) {

}

function buildNormalScale( normalScale ) {

return `(${ normalScale.x }, ${ normalScale.y }, 1.0, 1.0)`;

}


function buildCamera( camera ) {

Expand Down

0 comments on commit 8ce5b04

Please sign in to comment.