Skip to content

Commit

Permalink
USDZExporter: Fixed texture support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed May 27, 2021
1 parent 18226d6 commit a09a704
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,24 @@ function buildMaterial( material ) {
float2 outputs:result
}
def Shader "Texture_${ texture.id }"
def Shader "Texture_${ texture.id }_${ mapType }"
{
uniform token info:id = "UsdUVTexture"
asset inputs:file = @textures/Texture_${ texture.id }.jpg@
float2 inputs:st.connect = </Materials/Material_${ material.id }/Transform2d_${ mapType }.outputs:result>
token inputs:wrapS = "repeat"
token inputs:wrapT = "repeat"
float outputs:r
float outputs:g
float outputs:b
float3 outputs:rgb
}`;

}

if ( material.map !== null ) {

parameters.push( `${ pad }color3f inputs:diffuseColor.connect = </Materials/Material_${ material.id }/Texture_${ material.map.id }.outputs:rgb>` );
parameters.push( `${ pad }color3f inputs:diffuseColor.connect = </Materials/Material_${ material.id }/Texture_${ material.map.id }_diffuse.outputs:rgb>` );

textures.push( buildTexture( material.map, 'diffuse' ) );

Expand All @@ -369,7 +372,7 @@ function buildMaterial( material ) {

if ( material.emissiveMap !== null ) {

parameters.push( `${ pad }color3f inputs:emissiveColor.connect = </Materials/Material_${ material.id }/Texture_${ material.emissiveMap.id }.outputs:rgb>` );
parameters.push( `${ pad }color3f inputs:emissiveColor.connect = </Materials/Material_${ material.id }/Texture_${ material.emissiveMap.id }_emissive.outputs:rgb>` );

textures.push( buildTexture( material.emissiveMap, 'emissive' ) );

Expand All @@ -381,15 +384,15 @@ function buildMaterial( material ) {

if ( material.normalMap !== null ) {

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

textures.push( buildTexture( material.normalMap, 'normal' ) );

}

if ( material.aoMap !== null ) {

parameters.push( `${ pad }float inputs:occlusion.connect = </Materials/Material_${ material.id }/Texture_${ material.aoMap.id }.outputs:r>` );
parameters.push( `${ pad }float inputs:occlusion.connect = </Materials/Material_${ material.id }/Texture_${ material.aoMap.id }_occlusion.outputs:r>` );

textures.push( buildTexture( material.aoMap, 'occlusion' ) );

Expand All @@ -409,7 +412,7 @@ function buildMaterial( material ) {

if ( material.metalnessMap !== null ) {

parameters.push( `${ pad }float inputs:metallic.connect = </Materials/Material_${ material.id }/Texture_${ material.metalnessMap.id }_metalness.outputs:b>` );
parameters.push( `${ pad }float inputs:metallic.connect = </Materials/Material_${ material.id }/Texture_${ material.metalnessMap.id }_metallic.outputs:b>` );

textures.push( buildTexture( material.metalnessMap, 'metallic' ) );

Expand All @@ -422,30 +425,30 @@ function buildMaterial( material ) {
parameters.push( `${ pad }float inputs:opacity = ${ material.opacity }` );

return `
def Material "Material_${ material.id }"
{
def Shader "PreviewSurface"
{
uniform token info:id = "UsdPreviewSurface"
def Material "Material_${ material.id }"
{
def Shader "PreviewSurface"
{
uniform token info:id = "UsdPreviewSurface"
${ parameters.join( '\n' ) }
int inputs:useSpecularWorkflow = 0
token outputs:surface
}
int inputs:useSpecularWorkflow = 0
token outputs:surface
}
token outputs:surface.connect = </Materials/Material_${ material.id }/PreviewSurface.outputs:surface>
token inputs:frame:stPrimvarName = "st"
token outputs:surface.connect = </Materials/Material_${ material.id }/PreviewSurface.outputs:surface>
token inputs:frame:stPrimvarName = "st"
def Shader "uvReader_st"
{
uniform token info:id = "UsdPrimvarReader_float2"
token inputs:varname.connect = </Materials/Material_${ material.id }.inputs:frame:stPrimvarName>
float2 inputs:fallback = (0.0, 0.0)
float2 outputs:result
}
def Shader "uvReader_st"
{
uniform token info:id = "UsdPrimvarReader_float2"
token inputs:varname.connect = </Materials/Material_${ material.id }.inputs:frame:stPrimvarName>
float2 inputs:fallback = (0.0, 0.0)
float2 outputs:result
}
${ textures.join( '\n' ) }
}
}
`;

}
Expand Down

0 comments on commit a09a704

Please sign in to comment.