浏览代码

GLTFExporter: Include correct mimeType, allow embedImages=false opt-out.

Don McCurdy 7 年之前
父节点
当前提交
c270dd8baf
共有 2 个文件被更改,包括 13 次插入7 次删除
  1. 1 0
      docs/examples/exporters/GLTFExporter.html
  2. 12 7
      examples/js/exporters/GLTFExporter.js

+ 1 - 0
docs/examples/exporters/GLTFExporter.html

@@ -79,6 +79,7 @@ exporter.parse( [ scene1, object1, object2, scene2 ], ...)
 			<li>onlyVisible - bool. Export only visible objects. Default is true.</li>
 			<li>truncateDrawRange - bool. Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.</li>
 			<li>binary - bool. Export in binary (.glb) format, returning an ArrayBuffer. Default is false.</li>
+			<li>embedImages - bool. Export with images embedded into the glTF asset. Default is true.</li>
 		</ul>
 		</div>
 		<div>

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

@@ -61,7 +61,8 @@ THREE.GLTFExporter.prototype = {
 		var DEFAULT_OPTIONS = {
 			trs: false,
 			onlyVisible: true,
-			truncateDrawRange: true
+			truncateDrawRange: true,
+			embedImages: true
 		};
 
 		options = Object.assign( {}, DEFAULT_OPTIONS, options );
@@ -86,6 +87,8 @@ THREE.GLTFExporter.prototype = {
 
 		};
 
+		var cachedCanvas;
+
 		/**
 		 * Compare two arrays
 		 */
@@ -368,22 +371,24 @@ THREE.GLTFExporter.prototype = {
 
 			}
 
-			var gltfImage = {};
-
-			var canvas = document.createElement( 'canvas' );
+			var canvas = cachedCanvas = cachedCanvas || document.createElement( 'canvas' );
 			canvas.width = map.image.width;
 			canvas.height = map.image.height;
 			var ctx = canvas.getContext( '2d' );
 			ctx.drawImage( map.image, 0, 0 );
-			var format = map.format === THREE.RGBAFormat ? 'image/png' : 'image/jpg';
+
+			var mimeType = map.format === THREE.RGBAFormat ? 'image/png' : 'image/jpeg';
+			var gltfImage = {mimeType: mimeType};
 
 			if ( options.embedImages ) {
 
-				// @TODO { bufferView, mimeType }
+				// @TODO Embed in { bufferView } if options.binary set.
+
+				gltfImage.uri = canvas.toDataURL( mimeType );
 
 			} else {
 
-				gltfImage.uri = canvas.toDataURL( format );
+				gltfImage.uri = map.image.src;
 
 			}