Skip to content

Commit

Permalink
Allow GLTF Exporter to export supported mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
christaggart committed Oct 4, 2022
1 parent 2411747 commit 7f8b4d3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/dev/serializers/src/glTF/2.0/glTFExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class _Exporter {

private static _ExtensionNames = new Array<string>();
private static _ExtensionFactories: { [name: string]: (exporter: _Exporter) => IGLTFExporterExtensionV2 } = {};
private _exportMimeType: ImageMimeType;

private _applyExtension<T>(
node: Nullable<T>,
Expand Down Expand Up @@ -358,6 +359,7 @@ export class _Exporter {
this._orderedImageData = [];
this._options = options || {};
this._animationSampleRate = options && options.animationSampleRate ? options.animationSampleRate : 1 / 60;
this._exportMimeType = options && options.mimetype ? options.mimetype : ImageMimeType.PNG;
this._includeCoordinateSystemConversionNodes = options && options.includeCoordinateSystemConversionNodes ? true : false;

this._glTFMaterialExporter = new _GLTFMaterialExporter(this);
Expand Down Expand Up @@ -1973,7 +1975,7 @@ export class _Exporter {
});

const [exportNodes, exportMaterials] = this._getExportNodes(nodes);
return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, ImageMimeType.PNG, true).then(() => {
return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(exportMaterials, this._exportMimeType, true).then(() => {
return this._createNodeMapAndAnimationsAsync(babylonScene, exportNodes, binaryWriter).then((nodeMap) => {
return this._createSkinsAsync(babylonScene, nodeMap, binaryWriter).then((skinMap) => {
this._nodeMap = nodeMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ export class _GLTFMaterialExporter {
}

imageData[textureName] = imageValues;
if (mimeType === ImageMimeType.JPEG || mimeType === ImageMimeType.PNG) {
if (mimeType === ImageMimeType.JPEG || mimeType === ImageMimeType.PNG || mimeType === ImageMimeType.WEBP) {
const glTFImage: IImage = {
name: baseTextureName,
uri: textureName,
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/serializers/src/glTF/2.0/glTFSerializer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ImageMimeType } from "babylonjs-gltf2interface";
import type { Node } from "core/node";
import type { Scene } from "core/scene";
import type { GLTFData } from "./glTFData";
Expand Down Expand Up @@ -40,6 +41,11 @@ export interface IExportOptions {
* Indicates if coordinate system swapping root nodes should be included in export
*/
includeCoordinateSystemConversionNodes?: boolean;

/**
* Indicates the desired export mimetype. Default is png.
*/
mimetype?: ImageMimeType;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/public/glTF2Interface/babylon.glTF2Interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ declare module BABYLON.GLTF2 {
* PNG Mime-type
*/
PNG = "image/png",
/**
* WEBP Mime-type
*/
WEBP = "image/webp",
}

/**
Expand Down

0 comments on commit 7f8b4d3

Please sign in to comment.