|
@@ -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,15 +371,23 @@ THREE.GLTFExporter.prototype = {
|
|
|
|
|
|
}
|
|
|
|
|
|
- var gltfImage = {};
|
|
|
+ var mimeType = map.format === THREE.RGBAFormat ? 'image/png' : 'image/jpeg';
|
|
|
+ var gltfImage = {mimeType: mimeType};
|
|
|
|
|
|
if ( options.embedImages ) {
|
|
|
|
|
|
- // @TODO { bufferView, mimeType }
|
|
|
+ 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 );
|
|
|
+
|
|
|
+ // @TODO Embed in { bufferView } if options.binary set.
|
|
|
+
|
|
|
+ gltfImage.uri = canvas.toDataURL( mimeType );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- // @TODO base64 based on options
|
|
|
gltfImage.uri = map.image.src;
|
|
|
|
|
|
}
|