Skip to content

Commit

Permalink
USDZExporter: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed May 21, 2021
1 parent d66b8ae commit ad868b3
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions examples/jsm/exporters/USDZExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ function buildMaterial( material ) {
const textures = [];
let texture;

function prepareTextureTransform(texture, mapType) {
function prepareTextureTransform( texture, mapType ) {

return `
def Shader "Transform2D_${ mapType }" (
sdrMetadata = {
Expand All @@ -349,17 +350,16 @@ function buildMaterial( material ) {
float2 outputs:result
}
`;
}


}

if ( material.map !== null ) {

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

texture = material.map;
texturesTransforms.push(prepareTextureTransform(texture, "diffuse"));
textures.push(`
texturesTransforms.push( prepareTextureTransform( texture, 'diffuse' ) );
textures.push( `
def Shader "Texture_${ texture.id }"
{
Expand All @@ -370,8 +370,8 @@ function buildMaterial( material ) {
token inputs:wrapT = "repeat"
float3 outputs:rgb
}
`);
` );

} else {

Expand All @@ -384,8 +384,8 @@ function buildMaterial( material ) {
parameters.push( `${ pad }color3f inputs:emissiveColor.connect = </Materials/Material_${ material.id }/Texture_${ material.emissiveMap.id }.outputs:rgb>` );

texture = material.emissiveMap;
texturesTransforms.push(prepareTextureTransform(texture, "emissive"));
textures.push(`
texturesTransforms.push( prepareTextureTransform( texture, 'emissive' ) );
textures.push( `
def Shader "Texture_${ texture.id }"
{
Expand All @@ -399,8 +399,8 @@ function buildMaterial( material ) {
float outputs:b
float3 outputs:rgb
}
`);
` );

} else if ( material.emissive.getHex() > 0 ) {

Expand All @@ -413,8 +413,8 @@ function buildMaterial( material ) {
parameters.push( `${ pad }normal3f inputs:normal.connect = </Materials/Material_${ material.id }/Texture_${ material.normalMap.id }.outputs:rgb>` );

texture = material.normalMap;
texturesTransforms.push(prepareTextureTransform(texture, "normal"));
textures.push(`
texturesTransforms.push( prepareTextureTransform( texture, 'normal' ) );
textures.push( `
def Shader "Texture_${ texture.id }"
{
Expand All @@ -428,8 +428,8 @@ function buildMaterial( material ) {
float outputs:b
float3 outputs:rgb
}
`);
` );

}

Expand All @@ -438,7 +438,7 @@ function buildMaterial( material ) {
parameters.push( `${ pad }float inputs:occlusion.connect = </Materials/Material_${ material.id }/Texture_${ material.aoMap.id }.outputs:r>` );

texture = material.aoMap;
textures.push(`
textures.push( `
def Shader "Texture_${ texture.id }"
{
Expand All @@ -452,17 +452,18 @@ function buildMaterial( material ) {
float outputs:b
float3 outputs:rgb
}
`);
` );

}

if ( material.roughnessMap !== null ) {

parameters.push( `${ pad }float inputs:roughness.connect = </Materials/Material_${ material.id }/Texture_${ material.roughnessMap.id }_roughness.outputs:g>` );

texture = material.roughnessMap;
texturesTransforms.push(prepareTextureTransform(texture, "roughness"));
textures.push(`
texturesTransforms.push( prepareTextureTransform( texture, 'roughness' ) );
textures.push( `
def Shader "Texture_${ texture.id }_roughness"
{
Expand All @@ -476,8 +477,8 @@ function buildMaterial( material ) {
float outputs:b
float3 outputs:rgb
}
`);
` );

} else {

Expand All @@ -490,8 +491,8 @@ function buildMaterial( material ) {
parameters.push( `${ pad }float inputs:metallic.connect = </Materials/Material_${ material.id }/Texture_${ material.metalnessMap.id }_metalness.outputs:b>` );

texture = material.metalnessMap;
texturesTransforms.push(prepareTextureTransform(texture, "metallic"));
textures.push(`
texturesTransforms.push( prepareTextureTransform( texture, 'metallic' ) );
textures.push( `
def Shader "Texture_${ texture.id }_metalness"
{
Expand All @@ -505,8 +506,8 @@ function buildMaterial( material ) {
float outputs:b
float3 outputs:rgb
}
`);
` );

} else {

Expand All @@ -519,7 +520,7 @@ function buildMaterial( material ) {
return `
def Material "Material_${ material.id }"
{
def Shader "PreviewSurface"
{
uniform token info:id = "UsdPreviewSurface"
Expand All @@ -531,15 +532,15 @@ ${ parameters.join( '\n' ) }
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
}
${ texturesTransforms.join( '\n' ) }
${ textures.join( '\n' ) }
}
Expand Down

0 comments on commit ad868b3

Please sign in to comment.