Просмотр исходного кода

USDZExporter: Support `mimeType` setting via `Texture.userData`. (#33579)

Michael Herzog 1 месяц назад
Родитель
Сommit
99c7a47d03
1 измененных файлов с 12 добавлено и 3 удалено
  1. 12 3
      examples/jsm/exporters/USDZExporter.js

+ 12 - 3
examples/jsm/exporters/USDZExporter.js

@@ -284,11 +284,14 @@ class USDZExporter {
 				texture.flipY,
 				options.maxTextureSize
 			);
+
+			const mimeType = ( texture.userData.mimeType === 'image/jpeg' ) ? 'image/jpeg' : 'image/png';
+
 			const blob = await new Promise( ( resolve ) =>
-				canvas.toBlob( resolve, 'image/png', 1 )
+				canvas.toBlob( resolve, mimeType )
 			);
 
-			files[ `textures/Texture_${id}.png` ] = new Uint8Array(
+			files[ `textures/Texture_${id}.${getTextureExtension( texture )}` ] = new Uint8Array(
 				await blob.arrayBuffer()
 			);
 
@@ -363,6 +366,12 @@ function getName( object, namesSet ) {
 
 }
 
+function getTextureExtension( texture ) {
+
+	return texture.userData.mimeType === 'image/jpeg' ? 'jpg' : 'png';
+
+}
+
 function imageToCanvas( image, flipY, maxTextureSize ) {
 
 	if (
@@ -839,7 +848,7 @@ function buildMaterial( material, textures, quickLookCompatible = false ) {
 			'Shader'
 		);
 		textureNode.addProperty( 'uniform token info:id = "UsdUVTexture"' );
-		textureNode.addProperty( `asset inputs:file = @textures/Texture_${id}.png@` );
+		textureNode.addProperty( `asset inputs:file = @textures/Texture_${id}.${getTextureExtension( texture )}@` );
 		textureNode.addProperty(
 			`float2 inputs:st.connect = </Materials/Material_${material.id}/Transform2d_${mapType}.outputs:result>`
 		);

粤ICP备19079148号