Skip to content

Commit 379b49e

Browse files
authored
USDZExporter: Added texture.channel support (#25996)
* USDZExporteer: Added texture.channel support. * USDZExporter: Support 4 uv sets.
1 parent eeae9a6 commit 379b49e

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

examples/jsm/exporters/USDZExporter.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,7 @@ function buildMesh( geometry ) {
310310
interpolation = "vertex"
311311
)
312312
point3f[] points = [${ buildVector3Array( attributes.position, count )}]
313-
float2[] primvars:st = [${ buildVector2Array( attributes.uv, count )}] (
314-
interpolation = "vertex"
315-
)
313+
${ buildPrimvars( attributes, count ) }
316314
uniform token subdivisionScheme = "none"
317315
}
318316
`;
@@ -405,6 +403,30 @@ function buildVector2Array( attribute, count ) {
405403

406404
}
407405

406+
function buildPrimvars( attributes, count ) {
407+
408+
let string = '';
409+
410+
for ( let i = 0; i < 4; i ++ ) {
411+
412+
const id = ( i > 0 ? i : '' );
413+
const attribute = attributes[ 'uv' + id ];
414+
415+
if ( attribute !== undefined ) {
416+
417+
string += `
418+
float2[] primvars:st${ id } = [${ buildVector2Array( attribute, count )}] (
419+
interpolation = "vertex"
420+
)`;
421+
422+
}
423+
424+
}
425+
426+
return string;
427+
428+
}
429+
408430
// Materials
409431

410432
function buildMaterials( materials, textures ) {
@@ -443,16 +465,22 @@ function buildMaterial( material, textures ) {
443465

444466
textures[ id ] = texture;
445467

468+
const uv = texture.channel > 0 ? 'st' + texture.channel : 'st';
469+
446470
return `
447-
def Shader "Transform2d_${ mapType }" (
448-
sdrMetadata = {
449-
string role = "math"
450-
}
451-
)
471+
def Shader "PrimvarReader_${ mapType }"
472+
{
473+
uniform token info:id = "UsdPrimvarReader_float2"
474+
float2 inputs:fallback = (0.0, 0.0)
475+
token inputs:varname = "${ uv }"
476+
float2 outputs:result
477+
}
478+
479+
def Shader "Transform2d_${ mapType }"
452480
{
453481
uniform token info:id = "UsdTransform2d"
454-
float2 inputs:in.connect = </Materials/Material_${ material.id }/uvReader_st.outputs:result>
455-
float2 inputs:scale = ${ buildVector2( texture.repeat ) }
482+
token inputs:in.connect = </Materials/Material_${ material.id }/PrimvarReader_${ mapType }.outputs:result>
483+
float2 inputs:scale = ${ buildVector2( texture.repeat ) }
456484
float2 inputs:translation = ${ buildVector2( texture.offset ) }
457485
float2 outputs:result
458486
}
@@ -461,7 +489,7 @@ function buildMaterial( material, textures ) {
461489
{
462490
uniform token info:id = "UsdUVTexture"
463491
asset inputs:file = @textures/Texture_${ id }.${ isRGBA ? 'png' : 'jpg' }@
464-
float2 inputs:st.connect = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
492+
float2 inputs:st.connect = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
465493
token inputs:wrapS = "repeat"
466494
token inputs:wrapT = "repeat"
467495
float outputs:r
@@ -588,15 +616,6 @@ ${ inputs.join( '\n' ) }
588616
}
589617
590618
token outputs:surface.connect = </Materials/Material_${ material.id }/PreviewSurface.outputs:surface>
591-
token inputs:frame:stPrimvarName = "st"
592-
593-
def Shader "uvReader_st"
594-
{
595-
uniform token info:id = "UsdPrimvarReader_float2"
596-
token inputs:varname.connect = </Materials/Material_${ material.id }.inputs:frame:stPrimvarName>
597-
float2 inputs:fallback = (0.0, 0.0)
598-
float2 outputs:result
599-
}
600619
601620
${ samplers.join( '\n' ) }
602621

0 commit comments

Comments
 (0)