فهرست منبع

GLTFExporter: Fix support for RGBA textures. (#21888)

Michael Herzog 4 سال پیش
والد
کامیت
9c2ba55ac6
2فایلهای تغییر یافته به همراه24 افزوده شده و 6 حذف شده
  1. 12 3
      examples/js/exporters/GLTFExporter.js
  2. 12 3
      examples/jsm/exporters/GLTFExporter.js

+ 12 - 3
examples/js/exporters/GLTFExporter.js

@@ -890,11 +890,20 @@
 
 					}
 
-					let data = image.data;
+					const data = new Uint8ClampedArray( image.height * image.width * 4 );
 
-					if ( format === THREE.RGBFormat ) {
+					if ( format === THREE.RGBAFormat ) {
 
-						data = new Uint8ClampedArray( image.height * image.width * 4 );
+						for ( let i = 0; i < data.length; i += 4 ) {
+
+							data[ i + 0 ] = image.data[ i + 0 ];
+							data[ i + 1 ] = image.data[ i + 1 ];
+							data[ i + 2 ] = image.data[ i + 2 ];
+							data[ i + 3 ] = image.data[ i + 3 ];
+
+						}
+
+					} else {
 
 						for ( let i = 0, j = 0; i < data.length; i += 4, j += 3 ) {
 

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

@@ -986,11 +986,20 @@ class GLTFWriter {
 
 				}
 
-				let data = image.data;
+				const data = new Uint8ClampedArray( image.height * image.width * 4 );
 
-				if ( format === RGBFormat ) {
+				if ( format === RGBAFormat ) {
 
-					data = new Uint8ClampedArray( image.height * image.width * 4 );
+					for ( let i = 0; i < data.length; i += 4 ) {
+
+						data[ i + 0 ] = image.data[ i + 0 ];
+						data[ i + 1 ] = image.data[ i + 1 ];
+						data[ i + 2 ] = image.data[ i + 2 ];
+						data[ i + 3 ] = image.data[ i + 3 ];
+
+					}
+
+				} else {
 
 					for ( let i = 0, j = 0; i < data.length; i += 4, j += 3 ) {