@babylonjs/serializers 8.23.1 → 8.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +1 -4
- package/glTF/2.0/glTFExporter.js +2 -7
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +1 -10
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +4 -7
- package/glTF/2.0/glTFMaterialExporter.js +111 -71
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/package.json +3 -3
@@ -73,7 +73,7 @@ export class KHR_materials_transmission {
|
|
73
73
|
}
|
74
74
|
if (subSurface.refractionIntensityTexture) {
|
75
75
|
if (subSurface.useGltfStyleTextures) {
|
76
|
-
const transmissionTexture = await this._exporter._materialExporter.exportTextureAsync(subSurface.refractionIntensityTexture
|
76
|
+
const transmissionTexture = await this._exporter._materialExporter.exportTextureAsync(subSurface.refractionIntensityTexture);
|
77
77
|
if (transmissionTexture) {
|
78
78
|
volumeInfo.transmissionTexture = transmissionTexture;
|
79
79
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAE1C,MAAM,IAAI,GAAG,4B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IAAI,CAAC,GAAG,UAAU,CAAC;QACvC,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsTransmission } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRMaterial } from \"core/Materials/PBR/pbrMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Logger } from \"core/Misc/logger\";\r\n\r\nconst NAME = \"KHR_materials_transmission\";\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_transmission implements IGLTFExporterExtensionV2 {\r\n /** Name of this extension */\r\n public readonly name = NAME;\r\n\r\n /** Defines whether this extension is enabled */\r\n public enabled = true;\r\n\r\n /** Defines whether this extension is required */\r\n public required = false;\r\n\r\n private _exporter: GLTFExporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** Dispose */\r\n public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n /**\r\n * After exporting a material, deal with additional textures\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns array of additional textures to export\r\n */\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n\r\n if (babylonMaterial instanceof PBRMaterial) {\r\n if (this._isExtensionEnabled(babylonMaterial)) {\r\n if (babylonMaterial.subSurface.thicknessTexture) {\r\n additionalTextures.push(babylonMaterial.subSurface.thicknessTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return additionalTextures;\r\n }\r\n\r\n private _isExtensionEnabled(mat: PBRMaterial): boolean {\r\n // This extension must not be used on a material that also uses KHR_materials_unlit\r\n if (mat.unlit) {\r\n return false;\r\n }\r\n const subs = mat.subSurface;\r\n return (subs.isRefractionEnabled && subs.refractionIntensity != undefined && subs.refractionIntensity != 0) || this._hasTexturesExtension(mat);\r\n }\r\n\r\n private _hasTexturesExtension(mat: PBRMaterial): boolean {\r\n return mat.subSurface.refractionIntensityTexture != null;\r\n }\r\n\r\n /**\r\n * After exporting a material\r\n * @param context GLTF context of the material\r\n * @param node exported GLTF node\r\n * @param babylonMaterial corresponding babylon material\r\n * @returns true if successful\r\n */\r\n public async postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subSurface = babylonMaterial.subSurface;\r\n const transmissionFactor = subSurface.refractionIntensity === 0 ? undefined : subSurface.refractionIntensity;\r\n\r\n const volumeInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n };\r\n\r\n if (this._hasTexturesExtension(babylonMaterial)) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n if (subSurface.refractionIntensityTexture) {\r\n if (subSurface.useGltfStyleTextures) {\r\n const transmissionTexture = await this._exporter._materialExporter.exportTextureAsync(subSurface.refractionIntensityTexture);\r\n if (transmissionTexture) {\r\n volumeInfo.transmissionTexture = transmissionTexture;\r\n }\r\n } else {\r\n Logger.Warn(`${context}: Exporting a subsurface refraction intensity texture without \\`useGltfStyleTextures\\` is not supported`);\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n\r\n return node;\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n"]}
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import type { IBufferView, IAccessor, INode, IScene, IMesh, IMaterial, ITexture, IImage, ISampler, IAnimation, IMeshPrimitive, IGLTF, ITextureInfo, ISkin, ICamera } from "babylonjs-gltf2interface";
|
2
|
-
import { ImageMimeType } from "babylonjs-gltf2interface";
|
1
|
+
import type { IBufferView, IAccessor, INode, IScene, IMesh, IMaterial, ITexture, IImage, ISampler, IAnimation, IMeshPrimitive, IGLTF, ITextureInfo, ISkin, ICamera, ImageMimeType } from "babylonjs-gltf2interface";
|
3
2
|
import type { Nullable } from "@babylonjs/core/types.js";
|
4
3
|
import type { Node } from "@babylonjs/core/node.js";
|
5
4
|
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
6
|
-
import type { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
7
5
|
import { Material } from "@babylonjs/core/Materials/material.js";
|
8
6
|
import type { Scene } from "@babylonjs/core/scene.js";
|
9
7
|
import type { IGLTFExporterExtensionV2 } from "./glTFExporterExtension.js";
|
@@ -54,7 +52,6 @@ export declare class GLTFExporter {
|
|
54
52
|
private static readonly _ExtensionFactories;
|
55
53
|
private _ApplyExtension;
|
56
54
|
private _ApplyExtensions;
|
57
|
-
_extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Promise<Nullable<BaseTexture>>;
|
58
55
|
_extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
|
59
56
|
_extensionsPostExportMaterialAsync(context: string, material: IMaterial, babylonMaterial: Material): Promise<Nullable<IMaterial>>;
|
60
57
|
_extensionsPostExportMaterialAdditionalTextures(context: string, material: IMaterial, babylonMaterial: Material): BaseTexture[];
|
package/glTF/2.0/glTFExporter.js
CHANGED
@@ -154,11 +154,6 @@ export class GLTFExporter {
|
|
154
154
|
return this._ApplyExtension(node, extensions, 0, actionAsync);
|
155
155
|
}
|
156
156
|
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async
|
157
|
-
_extensionsPreExportTextureAsync(context, babylonTexture, mimeType) {
|
158
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
159
|
-
return this._ApplyExtensions(babylonTexture, (extension, node) => extension.preExportTextureAsync && extension.preExportTextureAsync(context, node, mimeType));
|
160
|
-
}
|
161
|
-
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async
|
162
157
|
_extensionsPostExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded) {
|
163
158
|
return this._ApplyExtensions(node,
|
164
159
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
@@ -1056,10 +1051,10 @@ export class GLTFExporter {
|
|
1056
1051
|
const hasUVs = vertexBuffers && Object.keys(vertexBuffers).some((kind) => kind.startsWith("uv"));
|
1057
1052
|
babylonMaterial = babylonMaterial instanceof MultiMaterial ? babylonMaterial.subMaterials[subMesh.materialIndex] : babylonMaterial;
|
1058
1053
|
if (babylonMaterial instanceof PBRBaseMaterial) {
|
1059
|
-
materialIndex = await this._materialExporter.exportPBRMaterialAsync(babylonMaterial,
|
1054
|
+
materialIndex = await this._materialExporter.exportPBRMaterialAsync(babylonMaterial, hasUVs);
|
1060
1055
|
}
|
1061
1056
|
else if (babylonMaterial instanceof StandardMaterial) {
|
1062
|
-
materialIndex = await this._materialExporter.exportStandardMaterialAsync(babylonMaterial,
|
1057
|
+
materialIndex = await this._materialExporter.exportStandardMaterialAsync(babylonMaterial, hasUVs);
|
1063
1058
|
}
|
1064
1059
|
else {
|
1065
1060
|
Logger.Warn(`Unsupported material '${babylonMaterial.name}' with type ${babylonMaterial.getClassName()}`);
|