Преглед изворни кода

ColladaExporter: Throw exception when processing textures with no image data. (#25100)

Michael Herzog пре 2 година
родитељ
комит
f170533af4
1 измењених фајлова са 24 додато и 12 уклоњено
  1. 24 12
      examples/jsm/exporters/ColladaExporter.js

+ 24 - 12
examples/jsm/exporters/ColladaExporter.js

@@ -124,21 +124,32 @@ class ColladaExporter {
 
 		function imageToData( image, ext ) {
 
-			canvas = canvas || document.createElement( 'canvas' );
-			ctx = ctx || canvas.getContext( '2d' );
+			if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
+				( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
+				( typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas ) ||
+				( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
 
-			canvas.width = image.width;
-			canvas.height = image.height;
+				canvas = canvas || document.createElement( 'canvas' );
+				ctx = ctx || canvas.getContext( '2d' );
 
-			ctx.drawImage( image, 0, 0 );
+				canvas.width = image.width;
+				canvas.height = image.height;
 
-			// Get the base64 encoded data
-			const base64data = canvas
-				.toDataURL( `image/${ ext }`, 1 )
-				.replace( /^data:image\/(png|jpg);base64,/, '' );
+				ctx.drawImage( image, 0, 0 );
 
-			// Convert to a uint8 array
-			return base64ToBuffer( base64data );
+				// Get the base64 encoded data
+				const base64data = canvas
+					.toDataURL( `image/${ ext }`, 1 )
+					.replace( /^data:image\/(png|jpg);base64,/, '' );
+
+				// Convert to a uint8 array
+				return base64ToBuffer( base64data );
+
+			} else {
+
+				throw new Error( 'THREE.ColladaExporter: No valid image data found. Unable to process texture.' );
+
+			}
 
 		}
 
@@ -357,7 +368,8 @@ class ColladaExporter {
 		function processTexture( tex ) {
 
 			let texid = imageMap.get( tex );
-			if ( texid == null ) {
+
+			if ( texid === undefined ) {
 
 				texid = `image-${ libraryImages.length + 1 }`;