@babylonjs/serializers 7.25.0 → 7.25.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  import { _Exporter } from "../glTFExporter.js";
2
2
  import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
3
+ import { Logger } from "@babylonjs/core/Misc/logger.js";
3
4
  const NAME = "KHR_materials_transmission";
4
5
  /**
5
6
  * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_transmission/README.md)
@@ -59,25 +60,32 @@ export class KHR_materials_transmission {
59
60
  * @param babylonMaterial corresponding babylon material
60
61
  * @returns true if successful
61
62
  */
62
- postExportMaterialAsync(context, node, babylonMaterial) {
63
- return new Promise((resolve) => {
64
- if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
65
- this._wasUsed = true;
66
- const subs = babylonMaterial.subSurface;
67
- const transmissionFactor = subs.refractionIntensity === 0 ? undefined : subs.refractionIntensity;
68
- const transmissionTexture = this._exporter._glTFMaterialExporter._getTextureInfo(subs.refractionIntensityTexture) ?? undefined;
69
- const volumeInfo = {
70
- transmissionFactor: transmissionFactor,
71
- transmissionTexture: transmissionTexture,
72
- hasTextures: () => {
73
- return this._hasTexturesExtension(babylonMaterial);
74
- },
75
- };
76
- node.extensions = node.extensions || {};
77
- node.extensions[NAME] = volumeInfo;
63
+ async postExportMaterialAsync(context, node, babylonMaterial) {
64
+ if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
65
+ this._wasUsed = true;
66
+ const subSurface = babylonMaterial.subSurface;
67
+ const transmissionFactor = subSurface.refractionIntensity === 0 ? undefined : subSurface.refractionIntensity;
68
+ const volumeInfo = {
69
+ transmissionFactor: transmissionFactor,
70
+ hasTextures: () => {
71
+ return this._hasTexturesExtension(babylonMaterial);
72
+ },
73
+ };
74
+ if (subSurface.refractionIntensityTexture) {
75
+ if (subSurface.useGltfStyleTextures) {
76
+ const transmissionTexture = await this._exporter._glTFMaterialExporter._exportTextureInfoAsync(subSurface.refractionIntensityTexture, "image/png" /* ImageMimeType.PNG */);
77
+ if (transmissionTexture) {
78
+ volumeInfo.transmissionTexture = transmissionTexture;
79
+ }
80
+ }
81
+ else {
82
+ Logger.Warn(`${context}: Exporting a subsurface refraction intensity texture without \`useGltfStyleTextures\` is not supported`);
83
+ }
78
84
  }
79
- resolve(node);
80
- });
85
+ node.extensions || (node.extensions = {});
86
+ node.extensions[NAME] = volumeInfo;
87
+ }
88
+ return node;
81
89
  }
82
90
  }
83
91
  _Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));
@@ -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":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAG7D,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,0BAA0B;IAcnC,YAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,cAAc;IACP,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,oCAAoC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QACpG,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAE7C,IAAI,eAAe,YAAY,WAAW,EAAE;YACxC,IAAI,IAAI,CA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AAI,SAAS,CAAC;gBAE/H,MAAM,UAAU,GAA8B;oBAC1C,kBAAkB,EAAE,kBAAkB;oBACtC,mBAAmB,EAAE,mBAAmB;oBACxC,WAAW,EAAE,GAAG,EAAE;wBACd,OAAO,IAAI,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;oBACvD,CAAC;iBACJ,CAAC;gBACF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;gBACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;aACtC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,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 { _Exporter } 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\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: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\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 postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {\r\n this._wasUsed = true;\r\n\r\n const subs = babylonMaterial.subSurface;\r\n const transmissionFactor = subs.refractionIntensity === 0 ? undefined : subs.refractionIntensity;\r\n\r\n const transmissionTexture = this._exporter._glTFMaterialExporter._getTextureInfo(subs.refractionIntensityTexture) ?? undefined;\r\n\r\n const volumeInfo: IKHRMaterialsTransmission = {\r\n transmissionFactor: transmissionFactor,\r\n transmissionTexture: transmissionTexture,\r\n hasTextures: () => {\r\n return this._hasTexturesExtension(babylonMaterial);\r\n },\r\n };\r\n node.extensions = node.extensions || {};\r\n node.extensions[NAME] = volumeInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n"]}
1
+ {"version":3,"file":"KHR_materials_transmission.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_transmission.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAE1C,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,0BAA0B;IAcnC,YAAY,QAAmB;QAb/B,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAIhB,aAAQ,GAAG,KAAK,CAAC;QAGrB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,cAAc;IACP,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACI,oCAAoC,CAAE,OAAe,EAAE,IAAe,EAAE,eAAyB;QACpG,MAAM,kBAAkB,GAAkB,EAAE,CAAC;QAE7C,IAAI,eAAe,YAAY,WAAW,EAAE;YACxC,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,EAAE;gBAC3C,IAAI,eAAe,CAAC,UAAU,CAAC,gBAAgB,EAAE;oBAC7C,kBAAkB,CAAC,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BAAmB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,uBAAuB,CAAC,UAAU,CAAC,0BAA0B,sCAAoB,CAAC;oBACzJ,IAAI,mBAAmB,EAAE;wBACrB,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;qBACxD;iBACJ;qBAAM;oBACH,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,yGAAyG,CAAC,CAAC;iBACpI;aACJ;YAED,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,EAAE,EAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC;SACtC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,SAAS,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 { ImageMimeType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } 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: _Exporter;\r\n\r\n private _wasUsed = false;\r\n\r\n constructor(exporter: _Exporter) {\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 hasTextures: () => {\r\n return this._hasTexturesExtension(babylonMaterial);\r\n },\r\n };\r\n\r\n if (subSurface.refractionIntensityTexture) {\r\n if (subSurface.useGltfStyleTextures) {\r\n const transmissionTexture = await this._exporter._glTFMaterialExporter._exportTextureInfoAsync(subSurface.refractionIntensityTexture, ImageMimeType.PNG);\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\n_Exporter.RegisterExtension(NAME, (exporter) => new KHR_materials_transmission(exporter));\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "7.25.0",
3
+ "version": "7.25.2",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,10 +18,10 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@babylonjs/core": "^7.25.0",
21
+ "@babylonjs/core": "^7.25.2",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@lts/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "^7.25.0"
24
+ "babylonjs-gltf2interface": "^7.25.2"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^7.0.0",