@onerjs/serializers 8.23.1
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/OBJ/index.d.ts +1 -0
- package/OBJ/index.js +2 -0
- package/OBJ/index.js.map +1 -0
- package/OBJ/objSerializer.d.ts +21 -0
- package/OBJ/objSerializer.js +171 -0
- package/OBJ/objSerializer.js.map +1 -0
- package/USDZ/index.d.ts +1 -0
- package/USDZ/index.js +3 -0
- package/USDZ/index.js.map +1 -0
- package/USDZ/usdzExporter.d.ts +50 -0
- package/USDZ/usdzExporter.js +589 -0
- package/USDZ/usdzExporter.js.map +1 -0
- package/exportUtils.d.ts +12 -0
- package/exportUtils.js +37 -0
- package/exportUtils.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.d.ts +24 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js +61 -0
- package/glTF/2.0/Extensions/EXT_materials_diffuse_roughness.js.map +1 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +109 -0
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +32 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +135 -0
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +39 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +145 -0
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.d.ts +24 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js +62 -0
- package/glTF/2.0/Extensions/KHR_materials_anisotropy.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +24 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +85 -0
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.d.ts +40 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js +118 -0
- package/glTF/2.0/Extensions/KHR_materials_diffuse_transmission.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.d.ts +31 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js +63 -0
- package/glTF/2.0/Extensions/KHR_materials_dispersion.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +27 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +54 -0
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +29 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.js +55 -0
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.d.ts +24 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js +69 -0
- package/glTF/2.0/Extensions/KHR_materials_iridescence.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +24 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +66 -0
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +41 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.js +94 -0
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +41 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +92 -0
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +20 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +46 -0
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +40 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js +96 -0
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +21 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.js +93 -0
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -0
- package/glTF/2.0/Extensions/index.d.ts +17 -0
- package/glTF/2.0/Extensions/index.js +18 -0
- package/glTF/2.0/Extensions/index.js.map +1 -0
- package/glTF/2.0/bufferManager.d.ts +68 -0
- package/glTF/2.0/bufferManager.js +154 -0
- package/glTF/2.0/bufferManager.js.map +1 -0
- package/glTF/2.0/dataWriter.d.ts +20 -0
- package/glTF/2.0/dataWriter.js +83 -0
- package/glTF/2.0/dataWriter.js.map +1 -0
- package/glTF/2.0/glTFAnimation.d.ts +191 -0
- package/glTF/2.0/glTFAnimation.js +786 -0
- package/glTF/2.0/glTFAnimation.js.map +1 -0
- package/glTF/2.0/glTFData.d.ts +21 -0
- package/glTF/2.0/glTFData.js +30 -0
- package/glTF/2.0/glTFData.js.map +1 -0
- package/glTF/2.0/glTFExporter.d.ts +109 -0
- package/glTF/2.0/glTFExporter.js +1166 -0
- package/glTF/2.0/glTFExporter.js.map +1 -0
- package/glTF/2.0/glTFExporterExtension.d.ts +77 -0
- package/glTF/2.0/glTFExporterExtension.js +4 -0
- package/glTF/2.0/glTFExporterExtension.js.map +1 -0
- package/glTF/2.0/glTFMaterialExporter.d.ts +99 -0
- package/glTF/2.0/glTFMaterialExporter.js +778 -0
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -0
- package/glTF/2.0/glTFMorphTargetsUtilities.d.ts +14 -0
- package/glTF/2.0/glTFMorphTargetsUtilities.js +149 -0
- package/glTF/2.0/glTFMorphTargetsUtilities.js.map +1 -0
- package/glTF/2.0/glTFSerializer.d.ts +78 -0
- package/glTF/2.0/glTFSerializer.js +39 -0
- package/glTF/2.0/glTFSerializer.js.map +1 -0
- package/glTF/2.0/glTFUtilities.d.ts +89 -0
- package/glTF/2.0/glTFUtilities.js +349 -0
- package/glTF/2.0/glTFUtilities.js.map +1 -0
- package/glTF/2.0/index.d.ts +4 -0
- package/glTF/2.0/index.js +6 -0
- package/glTF/2.0/index.js.map +1 -0
- package/glTF/glTFFileExporter.d.ts +20 -0
- package/glTF/glTFFileExporter.js +4 -0
- package/glTF/glTFFileExporter.js.map +1 -0
- package/glTF/index.d.ts +2 -0
- package/glTF/index.js +4 -0
- package/glTF/index.js.map +1 -0
- package/index.d.ts +4 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/legacy/legacy-glTF2Serializer.d.ts +2 -0
- package/legacy/legacy-glTF2Serializer.js +45 -0
- package/legacy/legacy-glTF2Serializer.js.map +1 -0
- package/legacy/legacy-objSerializer.d.ts +1 -0
- package/legacy/legacy-objSerializer.js +14 -0
- package/legacy/legacy-objSerializer.js.map +1 -0
- package/legacy/legacy-stlSerializer.d.ts +1 -0
- package/legacy/legacy-stlSerializer.js +14 -0
- package/legacy/legacy-stlSerializer.js.map +1 -0
- package/legacy/legacy-usdzSerializer.d.ts +1 -0
- package/legacy/legacy-usdzSerializer.js +14 -0
- package/legacy/legacy-usdzSerializer.js.map +1 -0
- package/legacy/legacy.d.ts +5 -0
- package/legacy/legacy.js +8 -0
- package/legacy/legacy.js.map +1 -0
- package/license.md +71 -0
- package/package.json +49 -0
- package/readme.md +29 -0
- package/stl/index.d.ts +1 -0
- package/stl/index.js +2 -0
- package/stl/index.js.map +1 -0
- package/stl/stlSerializer.d.ts +20 -0
- package/stl/stlSerializer.js +135 -0
- package/stl/stlSerializer.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_draco_mesh_compression.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_draco_mesh_compression.ts"],"names":[],"mappings":"AAC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AAE;gBAC5D,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAmB,CAAC,CAAC,CAAC,wDAAwD;YACjH,CAAC,CAAC,CAAC;YACH,IAAI,2BAA2B,EAAE,CAAC;gBAC9B,aAAa,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,0BAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\nimport { GLTFExporter } from \"../glTFExporter\";\nimport { MeshPrimitiveMode } from \"babylonjs-gltf2interface\";\nimport type { IAccessor, IBufferView, IKHRDracoMeshCompression, IMeshPrimitive } from \"babylonjs-gltf2interface\";\nimport type { BufferManager } from \"../bufferManager\";\nimport { DracoEncoder } from \"core/Meshes/Compression/dracoEncoder\";\nimport { GetTypedArrayData, GetTypeByteLength } from \"core/Buffers/bufferUtils\";\nimport { GetAccessorElementCount } from \"../glTFUtilities\";\nimport type { DracoAttributeName, IDracoAttributeData, IDracoEncoderOptions } from \"core/Meshes/Compression/dracoEncoder.types\";\nimport { Logger } from \"core/Misc/logger\";\nimport type { Nullable } from \"core/types\";\n\nconst NAME = \"KHR_draco_mesh_compression\";\n\nfunction GetDracoAttributeName(glTFName: string): DracoAttributeName {\n if (glTFName === \"POSITION\") {\n return \"POSITION\";\n } else if (glTFName === \"NORMAL\") {\n return \"NORMAL\";\n } else if (glTFName.startsWith(\"COLOR\")) {\n return \"COLOR\";\n } else if (glTFName.startsWith(\"TEXCOORD\")) {\n return \"TEX_COORD\";\n }\n return \"GENERIC\";\n}\n\n/**\n * [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md)\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport class KHR_draco_mesh_compression implements IGLTFExporterExtensionV2 {\n /** Name of this extension */\n public readonly name = NAME;\n\n /** Defines whether this extension is enabled */\n public enabled;\n\n /** KHR_draco_mesh_compression is required, as uncompressed fallback data is not yet implemented. */\n public required = true;\n\n /** BufferViews used for Draco data, which may be eligible for removal after Draco encoding */\n private _bufferViewsUsed: Set<IBufferView> = new Set();\n\n /** Accessors that were replaced with Draco data, which may be eligible for removal after Draco encoding */\n private _accessorsUsed: Set<IAccessor> = new Set();\n\n /** Promise pool for Draco encoding work */\n private _encodePromises: Promise<void>[] = [];\n\n private _wasUsed = false;\n\n /** @internal */\n public get wasUsed() {\n return this._wasUsed;\n }\n\n /** @internal */\n constructor(exporter: GLTFExporter) {\n this.enabled = exporter.options.meshCompressionMethod === \"Draco\" && DracoEncoder.DefaultAvailable;\n }\n\n /** @internal */\n public dispose() {}\n\n /** @internal */\n public postExportMeshPrimitive(primitive: IMeshPrimitive, bufferManager: BufferManager, accessors: IAccessor[]): void {\n if (!this.enabled) {\n return;\n }\n\n if (primitive.mode !== MeshPrimitiveMode.TRIANGLES && primitive.mode !== MeshPrimitiveMode.TRIANGLE_STRIP) {\n Logger.Warn(\"Cannot compress primitive with mode \" + primitive.mode + \".\");\n return;\n }\n\n // Collect bufferViews and accessors used by this primitive\n const primitiveBufferViews: IBufferView[] = [];\n const primitiveAccessors: IAccessor[] = [];\n\n // Prepare indices for Draco encoding\n let indices: Nullable<Uint32Array | Uint16Array> = null;\n if (primitive.indices !== undefined) {\n const accessor = accessors[primitive.indices];\n const bufferView = bufferManager.getBufferView(accessor);\n // Per exportIndices, indices must be either Uint16Array or Uint32Array\n indices = bufferManager.getData(bufferView).slice() as Uint32Array | Uint16Array;\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Prepare attributes for Draco encoding\n const attributes: IDracoAttributeData[] = [];\n for (const [name, accessorIndex] of Object.entries(primitive.attributes)) {\n const accessor = accessors[accessorIndex];\n const bufferView = bufferManager.getBufferView(accessor);\n\n const size = GetAccessorElementCount(accessor.type);\n const data = GetTypedArrayData(\n bufferManager.getData(bufferView),\n size,\n accessor.componentType,\n accessor.byteOffset || 0,\n bufferView.byteStride || GetTypeByteLength(accessor.componentType) * size,\n accessor.normalized || false,\n accessor.count,\n true\n );\n\n attributes.push({ kind: name, dracoName: GetDracoAttributeName(name), size: GetAccessorElementCount(accessor.type), data: data });\n\n primitiveBufferViews.push(bufferView);\n primitiveAccessors.push(accessor);\n }\n\n // Use sequential encoding to preserve vertex order for cases like morph targets\n const options: IDracoEncoderOptions = {\n method: primitive.targets ? \"MESH_SEQUENTIAL_ENCODING\" : \"MESH_EDGEBREAKER_ENCODING\",\n };\n\n const promise = DracoEncoder.Default._encodeAsync(attributes, indices, options)\n // eslint-disable-next-line github/no-then\n .then((encodedData) => {\n if (!encodedData) {\n Logger.Error(\"Draco encoding failed for primitive.\");\n return;\n }\n\n const dracoInfo: IKHRDracoMeshCompression = {\n bufferView: -1, // bufferView will be set to a real index later, when we write the binary and decide bufferView ordering\n attributes: encodedData.attributeIds,\n };\n const bufferView = bufferManager.createBufferView(encodedData.data);\n bufferManager.setBufferView(dracoInfo, bufferView);\n\n for (const bufferView of primitiveBufferViews) {\n this._bufferViewsUsed.add(bufferView);\n }\n for (const accessor of primitiveAccessors) {\n this._accessorsUsed.add(accessor);\n }\n\n primitive.extensions ||= {};\n primitive.extensions[NAME] = dracoInfo;\n })\n // eslint-disable-next-line github/no-then\n .catch((error) => {\n Logger.Error(\"Draco encoding failed for primitive: \" + error);\n });\n\n this._encodePromises.push(promise);\n\n this._wasUsed = true;\n }\n\n /** @internal */\n public async preGenerateBinaryAsync(bufferManager: BufferManager): Promise<void> {\n if (!this.enabled) {\n return;\n }\n\n await Promise.all(this._encodePromises);\n\n // Cull obsolete bufferViews that were replaced with Draco data\n this._bufferViewsUsed.forEach((bufferView) => {\n const references = bufferManager.getPropertiesWithBufferView(bufferView);\n const onlyUsedByEncodedPrimitives = references.every((object) => {\n return this._accessorsUsed.has(object as IAccessor); // has() can handle any object, but TS doesn't know that\n });\n if (onlyUsedByEncodedPrimitives) {\n bufferManager.removeBufferView(bufferView);\n }\n });\n\n this._bufferViewsUsed.clear();\n this._accessorsUsed.clear();\n }\n}\n\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_draco_mesh_compression(exporter));\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { Node } from "@babylonjs/core/node.js";
|
|
3
|
+
import type { INode } from "babylonjs-gltf2interface";
|
|
4
|
+
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
5
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
6
|
+
/**
|
|
7
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** The name of this extension. */
|
|
11
|
+
readonly name = "KHR_lights_punctual";
|
|
12
|
+
/** Defines whether this extension is enabled. */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
/** Reference to the glTF exporter */
|
|
17
|
+
private _exporter;
|
|
18
|
+
private _lights;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
constructor(exporter: GLTFExporter);
|
|
23
|
+
/** @internal */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
/** @internal */
|
|
26
|
+
get wasUsed(): boolean;
|
|
27
|
+
/** @internal */
|
|
28
|
+
onExporting(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Define this method to modify the default behavior when exporting a node
|
|
31
|
+
* @param context The context when exporting the node
|
|
32
|
+
* @param node glTF node
|
|
33
|
+
* @param babylonNode BabylonJS node
|
|
34
|
+
* @param nodeMap Node mapping of babylon node to glTF node index
|
|
35
|
+
* @param convertToRightHanded Flag to convert the values to right-handed
|
|
36
|
+
* @returns nullable INode promise
|
|
37
|
+
*/
|
|
38
|
+
postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Vector3, Quaternion, TmpVectors } from "@babylonjs/core/Maths/math.vector.js";
|
|
2
|
+
import { Light } from "@babylonjs/core/Lights/light.js";
|
|
3
|
+
import { ShadowLight } from "@babylonjs/core/Lights/shadowLight.js";
|
|
4
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
5
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
6
|
+
import { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from "../glTFUtilities.js";
|
|
7
|
+
const NAME = "KHR_lights_punctual";
|
|
8
|
+
const DEFAULTS = {
|
|
9
|
+
name: "",
|
|
10
|
+
color: [1, 1, 1],
|
|
11
|
+
intensity: 1,
|
|
12
|
+
range: Number.MAX_VALUE,
|
|
13
|
+
};
|
|
14
|
+
const SPOTDEFAULTS = {
|
|
15
|
+
innerConeAngle: 0,
|
|
16
|
+
outerConeAngle: Math.PI / 4.0,
|
|
17
|
+
};
|
|
18
|
+
const LIGHTDIRECTION = Vector3.Backward();
|
|
19
|
+
/**
|
|
20
|
+
* [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
+
export class KHR_lights_punctual {
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
constructor(exporter) {
|
|
28
|
+
/** The name of this extension. */
|
|
29
|
+
this.name = NAME;
|
|
30
|
+
/** Defines whether this extension is enabled. */
|
|
31
|
+
this.enabled = true;
|
|
32
|
+
/** Defines whether this extension is required */
|
|
33
|
+
this.required = false;
|
|
34
|
+
this._exporter = exporter;
|
|
35
|
+
}
|
|
36
|
+
/** @internal */
|
|
37
|
+
dispose() {
|
|
38
|
+
this._lights = null;
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
get wasUsed() {
|
|
42
|
+
return !!this._lights;
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
onExporting() {
|
|
46
|
+
this._exporter._glTF.extensions[NAME] = this._lights;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Define this method to modify the default behavior when exporting a node
|
|
50
|
+
* @param context The context when exporting the node
|
|
51
|
+
* @param node glTF node
|
|
52
|
+
* @param babylonNode BabylonJS node
|
|
53
|
+
* @param nodeMap Node mapping of babylon node to glTF node index
|
|
54
|
+
* @param convertToRightHanded Flag to convert the values to right-handed
|
|
55
|
+
* @returns nullable INode promise
|
|
56
|
+
*/
|
|
57
|
+
async postExportNodeAsync(context, node, babylonNode, nodeMap, convertToRightHanded) {
|
|
58
|
+
return await new Promise((resolve) => {
|
|
59
|
+
if (!(babylonNode instanceof Light)) {
|
|
60
|
+
resolve(node);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const lightType = babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT
|
|
64
|
+
? "point" /* KHRLightsPunctual_LightType.POINT */
|
|
65
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT
|
|
66
|
+
? "directional" /* KHRLightsPunctual_LightType.DIRECTIONAL */
|
|
67
|
+
: babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT
|
|
68
|
+
? "spot" /* KHRLightsPunctual_LightType.SPOT */
|
|
69
|
+
: null;
|
|
70
|
+
if (!lightType || !(babylonNode instanceof ShadowLight)) {
|
|
71
|
+
Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);
|
|
72
|
+
resolve(node);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {
|
|
76
|
+
Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);
|
|
77
|
+
}
|
|
78
|
+
// Set the node's translation and rotation here, since lights are not handled in exportNodeAsync
|
|
79
|
+
if (!babylonNode.position.equalsToFloats(0, 0, 0)) {
|
|
80
|
+
const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);
|
|
81
|
+
if (convertToRightHanded) {
|
|
82
|
+
ConvertToRightHandedPosition(translation);
|
|
83
|
+
}
|
|
84
|
+
node.translation = translation.asArray();
|
|
85
|
+
}
|
|
86
|
+
// Represent the Babylon light's direction as a quaternion
|
|
87
|
+
// relative to glTF lights' forward direction, (0, 0, -1).
|
|
88
|
+
if (lightType !== "point" /* KHRLightsPunctual_LightType.POINT */) {
|
|
89
|
+
const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);
|
|
90
|
+
if (convertToRightHanded) {
|
|
91
|
+
ConvertToRightHandedPosition(direction);
|
|
92
|
+
}
|
|
93
|
+
const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);
|
|
94
|
+
if (!Quaternion.IsIdentity(lightRotationQuaternion)) {
|
|
95
|
+
node.rotation = lightRotationQuaternion.asArray();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const light = {
|
|
99
|
+
type: lightType,
|
|
100
|
+
name: babylonNode.name,
|
|
101
|
+
color: babylonNode.diffuse.asArray(),
|
|
102
|
+
intensity: babylonNode.intensity,
|
|
103
|
+
range: babylonNode.range,
|
|
104
|
+
};
|
|
105
|
+
OmitDefaultValues(light, DEFAULTS);
|
|
106
|
+
// Separately handle the required 'spot' field for spot lights
|
|
107
|
+
if (lightType === "spot" /* KHRLightsPunctual_LightType.SPOT */) {
|
|
108
|
+
const babylonSpotLight = babylonNode;
|
|
109
|
+
light.spot = {
|
|
110
|
+
innerConeAngle: babylonSpotLight.innerAngle / 2.0,
|
|
111
|
+
outerConeAngle: babylonSpotLight.angle / 2.0,
|
|
112
|
+
};
|
|
113
|
+
OmitDefaultValues(light.spot, SPOTDEFAULTS);
|
|
114
|
+
}
|
|
115
|
+
this._lights || (this._lights = {
|
|
116
|
+
lights: [],
|
|
117
|
+
});
|
|
118
|
+
this._lights.lights.push(light);
|
|
119
|
+
const lightReference = {
|
|
120
|
+
light: this._lights.lights.length - 1,
|
|
121
|
+
};
|
|
122
|
+
// Assign the light to its parent node, if possible, to condense the glTF
|
|
123
|
+
// Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export
|
|
124
|
+
const parentBabylonNode = babylonNode.parent;
|
|
125
|
+
if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {
|
|
126
|
+
const parentNodeIndex = nodeMap.get(parentBabylonNode);
|
|
127
|
+
if (parentNodeIndex) {
|
|
128
|
+
// Combine the light's transformation with the parent's
|
|
129
|
+
const parentNode = this._exporter._nodes[parentNodeIndex];
|
|
130
|
+
CollapseChildIntoParent(node, parentNode);
|
|
131
|
+
parentNode.extensions || (parentNode.extensions = {});
|
|
132
|
+
parentNode.extensions[NAME] = lightReference;
|
|
133
|
+
// Do not export the original node
|
|
134
|
+
resolve(null);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
node.extensions || (node.extensions = {});
|
|
139
|
+
node.extensions[NAME] = lightReference;
|
|
140
|
+
resolve(node);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));
|
|
145
|
+
//# sourceMappingURL=KHR_lights_punctual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_lights_punctual.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_lights_punctual.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,6CAA+B;AACzE,OAAO,EAAE,KAAK,EAAE,wCAA0B;AAE1C,OAAO,EAAE,WAAW,EAAE,8CAAgC;AAItD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAC1C,OAAO,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEhI,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,QAAQ,GAA2C;IACrD,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,SAAS,EAAE,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,SAAS;CAC1B,CAAC;AACF,MAAM,YAAY,GAAkD;IAChE,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG;CAChC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;AAE1C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,mBAAmB;IAe5B;;OAEG;IACH,YAAY,QAAsB;QAjBlC,kCAAkC;QAClB,SAAI,GAAG,IAAI,CAAC;QAE5B,iDAAiD;QAC1C,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAWpB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,gBAAgB;IACT,OAAO;QACT,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;IACjC,CAAC;IAED,gB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GAAK,EAAE,EAAC;YACvB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { SpotLight } from \"core/Lights/spotLight\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"core/Maths/math.vector\";\r\nimport { Light } from \"core/Lights/light\";\r\nimport type { Node } from \"core/node\";\r\nimport { ShadowLight } from \"core/Lights/shadowLight\";\r\nimport type { INode, IKHRLightsPunctual_LightReference, IKHRLightsPunctual_Light, IKHRLightsPunctual } from \"babylonjs-gltf2interface\";\r\nimport { KHRLightsPunctual_LightType } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ConvertToRightHandedPosition, OmitDefaultValues, CollapseChildIntoParent, IsChildCollapsible } from \"../glTFUtilities\";\r\n\r\nconst NAME = \"KHR_lights_punctual\";\r\nconst DEFAULTS: Omit<IKHRLightsPunctual_Light, \"type\"> = {\r\n name: \"\",\r\n color: [1, 1, 1],\r\n intensity: 1,\r\n range: Number.MAX_VALUE,\r\n};\r\nconst SPOTDEFAULTS: NonNullable<IKHRLightsPunctual_Light[\"spot\"]> = {\r\n innerConeAngle: 0,\r\n outerConeAngle: Math.PI / 4.0,\r\n};\r\nconst LIGHTDIRECTION = Vector3.Backward();\r\n\r\n/**\r\n * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_lights_punctual implements IGLTFExporterExtensionV2 {\r\n /** The 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 /** Reference to the glTF exporter */\r\n private _exporter: GLTFExporter;\r\n\r\n private _lights: IKHRLightsPunctual;\r\n\r\n /**\r\n * @internal\r\n */\r\n constructor(exporter: GLTFExporter) {\r\n this._exporter = exporter;\r\n }\r\n\r\n /** @internal */\r\n public dispose() {\r\n (this._lights as any) = null;\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return !!this._lights;\r\n }\r\n\r\n /** @internal */\r\n public onExporting(): void {\r\n this._exporter._glTF.extensions![NAME] = this._lights;\r\n }\r\n /**\r\n * Define this method to modify the default behavior when exporting a node\r\n * @param context The context when exporting the node\r\n * @param node glTF node\r\n * @param babylonNode BabylonJS node\r\n * @param nodeMap Node mapping of babylon node to glTF node index\r\n * @param convertToRightHanded Flag to convert the values to right-handed\r\n * @returns nullable INode promise\r\n */\r\n public async postExportNodeAsync(context: string, node: INode, babylonNode: Node, nodeMap: Map<Node, number>, convertToRightHanded: boolean): Promise<Nullable<INode>> {\r\n return await new Promise((resolve) => {\r\n if (!(babylonNode instanceof Light)) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n const lightType =\r\n babylonNode.getTypeID() == Light.LIGHTTYPEID_POINTLIGHT\r\n ? KHRLightsPunctual_LightType.POINT\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_DIRECTIONALLIGHT\r\n ? KHRLightsPunctual_LightType.DIRECTIONAL\r\n : babylonNode.getTypeID() == Light.LIGHTTYPEID_SPOTLIGHT\r\n ? KHRLightsPunctual_LightType.SPOT\r\n : null;\r\n if (!lightType || !(babylonNode instanceof ShadowLight)) {\r\n Logger.Warn(`${context}: Light ${babylonNode.name} is not supported in ${NAME}`);\r\n resolve(node);\r\n return;\r\n }\r\n\r\n if (babylonNode.falloffType !== Light.FALLOFF_GLTF) {\r\n Logger.Warn(`${context}: Light falloff for ${babylonNode.name} does not match the ${NAME} specification!`);\r\n }\r\n\r\n // Set the node's translation and rotation here, since lights are not handled in exportNodeAsync\r\n if (!babylonNode.position.equalsToFloats(0, 0, 0)) {\r\n const translation = TmpVectors.Vector3[0].copyFrom(babylonNode.position);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(translation);\r\n }\r\n node.translation = translation.asArray();\r\n }\r\n\r\n // Represent the Babylon light's direction as a quaternion\r\n // relative to glTF lights' forward direction, (0, 0, -1).\r\n if (lightType !== KHRLightsPunctual_LightType.POINT) {\r\n const direction = babylonNode.direction.normalizeToRef(TmpVectors.Vector3[0]);\r\n if (convertToRightHanded) {\r\n ConvertToRightHandedPosition(direction);\r\n }\r\n\r\n const lightRotationQuaternion = Quaternion.FromUnitVectorsToRef(LIGHTDIRECTION, direction, TmpVectors.Quaternion[0]);\r\n if (!Quaternion.IsIdentity(lightRotationQuaternion)) {\r\n node.rotation = lightRotationQuaternion.asArray();\r\n }\r\n }\r\n\r\n const light: IKHRLightsPunctual_Light = {\r\n type: lightType,\r\n name: babylonNode.name,\r\n color: babylonNode.diffuse.asArray(),\r\n intensity: babylonNode.intensity,\r\n range: babylonNode.range,\r\n };\r\n OmitDefaultValues(light, DEFAULTS);\r\n\r\n // Separately handle the required 'spot' field for spot lights\r\n if (lightType === KHRLightsPunctual_LightType.SPOT) {\r\n const babylonSpotLight = babylonNode as SpotLight;\r\n light.spot = {\r\n innerConeAngle: babylonSpotLight.innerAngle / 2.0,\r\n outerConeAngle: babylonSpotLight.angle / 2.0,\r\n };\r\n OmitDefaultValues(light.spot, SPOTDEFAULTS);\r\n }\r\n\r\n this._lights ||= {\r\n lights: [],\r\n };\r\n this._lights.lights.push(light);\r\n\r\n const lightReference: IKHRLightsPunctual_LightReference = {\r\n light: this._lights.lights.length - 1,\r\n };\r\n\r\n // Assign the light to its parent node, if possible, to condense the glTF\r\n // Why and when: the glTF loader generates a new parent TransformNode for each light node, which we should undo on export\r\n const parentBabylonNode = babylonNode.parent;\r\n\r\n if (parentBabylonNode && IsChildCollapsible(babylonNode, parentBabylonNode)) {\r\n const parentNodeIndex = nodeMap.get(parentBabylonNode);\r\n if (parentNodeIndex) {\r\n // Combine the light's transformation with the parent's\r\n const parentNode = this._exporter._nodes[parentNodeIndex];\r\n CollapseChildIntoParent(node, parentNode);\r\n parentNode.extensions ||= {};\r\n parentNode.extensions[NAME] = lightReference;\r\n\r\n // Do not export the original node\r\n resolve(null);\r\n return;\r\n }\r\n }\r\n\r\n node.extensions ||= {};\r\n node.extensions[NAME] = lightReference;\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_lights_punctual(exporter));\r\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
+
import type { Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
+
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_materials_anisotropy implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
readonly name = "KHR_materials_anisotropy";
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
private _exporter;
|
|
17
|
+
private _wasUsed;
|
|
18
|
+
constructor(exporter: GLTFExporter);
|
|
19
|
+
dispose(): void;
|
|
20
|
+
/** @internal */
|
|
21
|
+
get wasUsed(): boolean;
|
|
22
|
+
postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
23
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
|
+
const NAME = "KHR_materials_anisotropy";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
export class KHR_materials_anisotropy {
|
|
9
|
+
constructor(exporter) {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
this.name = NAME;
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
this.enabled = true;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
this.required = false;
|
|
16
|
+
this._wasUsed = false;
|
|
17
|
+
this._exporter = exporter;
|
|
18
|
+
}
|
|
19
|
+
dispose() { }
|
|
20
|
+
/** @internal */
|
|
21
|
+
get wasUsed() {
|
|
22
|
+
return this._wasUsed;
|
|
23
|
+
}
|
|
24
|
+
postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
|
|
25
|
+
const additionalTextures = [];
|
|
26
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
27
|
+
if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {
|
|
28
|
+
if (babylonMaterial.anisotropy.texture) {
|
|
29
|
+
additionalTextures.push(babylonMaterial.anisotropy.texture);
|
|
30
|
+
}
|
|
31
|
+
return additionalTextures;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
37
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
40
|
+
if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {
|
|
41
|
+
resolve(node);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this._wasUsed = true;
|
|
45
|
+
node.extensions = node.extensions || {};
|
|
46
|
+
const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);
|
|
47
|
+
const anisotropyInfo = {
|
|
48
|
+
anisotropyStrength: babylonMaterial.anisotropy.intensity,
|
|
49
|
+
anisotropyRotation: babylonMaterial.anisotropy.angle,
|
|
50
|
+
anisotropyTexture: anisotropyTextureInfo ?? undefined,
|
|
51
|
+
};
|
|
52
|
+
if (anisotropyInfo.anisotropyTexture !== null) {
|
|
53
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
54
|
+
}
|
|
55
|
+
node.extensions[NAME] = anisotropyInfo;
|
|
56
|
+
}
|
|
57
|
+
resolve(node);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));
|
|
62
|
+
//# sourceMappingURL=KHR_materials_anisotropy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KHR_materials_anisotropy.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_materials_anisotropy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,yDAA2C;AAGrE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AAExC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,wBAAwB;IAcjC,YAAY,QAAsB;QAblC,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,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MAAM,cAAc,GAA4B;oBAC5C,kBAAkB,EAAE,eAAe,CAAC,UAAU,CAAC,SAAS;oBACxD,kBAAkB,EAAE,eAAe,CAAC,UAAU,CAAC,KAAK;oBACpD,iBAAiB,EAAE,qBAAqB,IAAI,SAAS;iBACxD,CAAC;gBAEF,IAAI,cAAc,CAAC,iBAAiB,KAAK,IAAI,EAAE,CAAC;oBAC5C,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC;YAC3C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsAnisotropy } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nconst NAME = \"KHR_materials_anisotropy\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_anisotropy 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 public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.anisotropy.isEnabled && !babylonMaterial.anisotropy.legacy) {\r\n if (babylonMaterial.anisotropy.texture) {\r\n additionalTextures.push(babylonMaterial.anisotropy.texture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.anisotropy.isEnabled || babylonMaterial.anisotropy.legacy) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const anisotropyTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.anisotropy.texture);\r\n\r\n const anisotropyInfo: IKHRMaterialsAnisotropy = {\r\n anisotropyStrength: babylonMaterial.anisotropy.intensity,\r\n anisotropyRotation: babylonMaterial.anisotropy.angle,\r\n anisotropyTexture: anisotropyTextureInfo ?? undefined,\r\n };\r\n\r\n if (anisotropyInfo.anisotropyTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = anisotropyInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_anisotropy(exporter));\r\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
+
import type { Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
+
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare class KHR_materials_clearcoat implements IGLTFExporterExtensionV2 {
|
|
10
|
+
/** Name of this extension */
|
|
11
|
+
readonly name = "KHR_materials_clearcoat";
|
|
12
|
+
/** Defines whether this extension is enabled */
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
/** Defines whether this extension is required */
|
|
15
|
+
required: boolean;
|
|
16
|
+
private _exporter;
|
|
17
|
+
private _wasUsed;
|
|
18
|
+
constructor(exporter: GLTFExporter);
|
|
19
|
+
dispose(): void;
|
|
20
|
+
/** @internal */
|
|
21
|
+
get wasUsed(): boolean;
|
|
22
|
+
postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
23
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRBaseMaterial } from "@babylonjs/core/Materials/PBR/pbrBaseMaterial.js";
|
|
3
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
4
|
+
const NAME = "KHR_materials_clearcoat";
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9
|
+
export class KHR_materials_clearcoat {
|
|
10
|
+
constructor(exporter) {
|
|
11
|
+
/** Name of this extension */
|
|
12
|
+
this.name = NAME;
|
|
13
|
+
/** Defines whether this extension is enabled */
|
|
14
|
+
this.enabled = true;
|
|
15
|
+
/** Defines whether this extension is required */
|
|
16
|
+
this.required = false;
|
|
17
|
+
this._wasUsed = false;
|
|
18
|
+
this._exporter = exporter;
|
|
19
|
+
}
|
|
20
|
+
dispose() { }
|
|
21
|
+
/** @internal */
|
|
22
|
+
get wasUsed() {
|
|
23
|
+
return this._wasUsed;
|
|
24
|
+
}
|
|
25
|
+
postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
|
|
26
|
+
const additionalTextures = [];
|
|
27
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
28
|
+
if (babylonMaterial.clearCoat.isEnabled) {
|
|
29
|
+
if (babylonMaterial.clearCoat.texture) {
|
|
30
|
+
additionalTextures.push(babylonMaterial.clearCoat.texture);
|
|
31
|
+
}
|
|
32
|
+
if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {
|
|
33
|
+
additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);
|
|
34
|
+
}
|
|
35
|
+
if (babylonMaterial.clearCoat.bumpTexture) {
|
|
36
|
+
additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);
|
|
37
|
+
}
|
|
38
|
+
return additionalTextures;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
44
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
if (babylonMaterial instanceof PBRBaseMaterial) {
|
|
47
|
+
if (!babylonMaterial.clearCoat.isEnabled) {
|
|
48
|
+
resolve(node);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this._wasUsed = true;
|
|
52
|
+
node.extensions = node.extensions || {};
|
|
53
|
+
const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);
|
|
54
|
+
let clearCoatTextureRoughnessInfo;
|
|
55
|
+
if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {
|
|
56
|
+
clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);
|
|
60
|
+
}
|
|
61
|
+
if (babylonMaterial.clearCoat.isTintEnabled) {
|
|
62
|
+
Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);
|
|
63
|
+
}
|
|
64
|
+
if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {
|
|
65
|
+
Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);
|
|
66
|
+
}
|
|
67
|
+
const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);
|
|
68
|
+
const clearCoatInfo = {
|
|
69
|
+
clearcoatFactor: babylonMaterial.clearCoat.intensity,
|
|
70
|
+
clearcoatTexture: clearCoatTextureInfo ?? undefined,
|
|
71
|
+
clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,
|
|
72
|
+
clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,
|
|
73
|
+
clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,
|
|
74
|
+
};
|
|
75
|
+
if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {
|
|
76
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
77
|
+
}
|
|
78
|
+
node.extensions[NAME] = clearCoatInfo;
|
|
79
|
+
}
|
|
80
|
+
resolve(node);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));
|
|
85
|
+
//# sourceMappingURL=KHR_materials_clearcoat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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,eAAe,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC;oBACrD,KAAK,CAAC,IAAI,CAAC,4EAA4E,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC;gBACnH,CAAC;gBAED,MAAM,0BAA0B,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,cAAc,CAAC,eAAe,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;gBAE1H,MAAM,aAAa,GAA2B;oBAC1C,eAAe,EAAE,eAAe,CAAC,SAAS,CAAC,SAAS;oBACpD,gBAAgB,EAAE,oBAAoB,IAAI,SAAS;oBACnD,wBAAwB,EAAE,eAAe,CAAC,SAAS,CAAC,SAAS;oBAC7D,yBAAyB,EAAE,6BAA6B,IAAI,SAAS;oBACrE,sBAAsB,EAAE,0BAA0B,IAAI,SAAS;iBAClE,CAAC;gBAEF,IAAI,aAAa,CAAC,gBAAgB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,IAAI,aAAa,CAAC,yBAAyB,KAAK,IAAI,EAAE,CAAC;oBAClJ,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;gBAC7D,CAAC;gBAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;YAC1C,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,YAAY,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC","sourcesContent":["import type { IMaterial, IKHRMaterialsClearcoat } from \"babylonjs-gltf2interface\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { PBRBaseMaterial } from \"core/Materials/PBR/pbrBaseMaterial\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\n\r\nimport { Tools } from \"core/Misc/tools\";\r\n\r\nconst NAME = \"KHR_materials_clearcoat\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_materials_clearcoat 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 public dispose() {}\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[] {\r\n const additionalTextures: BaseTexture[] = [];\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (babylonMaterial.clearCoat.isEnabled) {\r\n if (babylonMaterial.clearCoat.texture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.texture);\r\n }\r\n if (!babylonMaterial.clearCoat.useRoughnessFromMainTexture && babylonMaterial.clearCoat.textureRoughness) {\r\n additionalTextures.push(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n if (babylonMaterial.clearCoat.bumpTexture) {\r\n additionalTextures.push(babylonMaterial.clearCoat.bumpTexture);\r\n }\r\n return additionalTextures;\r\n }\r\n }\r\n\r\n return [];\r\n }\r\n\r\n // eslint-disable-next-line no-restricted-syntax\r\n public postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial> {\r\n return new Promise((resolve) => {\r\n if (babylonMaterial instanceof PBRBaseMaterial) {\r\n if (!babylonMaterial.clearCoat.isEnabled) {\r\n resolve(node);\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n\r\n node.extensions = node.extensions || {};\r\n\r\n const clearCoatTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n let clearCoatTextureRoughnessInfo;\r\n if (babylonMaterial.clearCoat.useRoughnessFromMainTexture) {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.texture);\r\n } else {\r\n clearCoatTextureRoughnessInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.textureRoughness);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.isTintEnabled) {\r\n Tools.Warn(`Clear Color tint is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n if (babylonMaterial.clearCoat.remapF0OnInterfaceChange) {\r\n Tools.Warn(`Clear Color F0 remapping is not supported for glTF export. Ignoring for: ${babylonMaterial.name}`);\r\n }\r\n\r\n const clearCoatNormalTextureInfo = this._exporter._materialExporter.getTextureInfo(babylonMaterial.clearCoat.bumpTexture);\r\n\r\n const clearCoatInfo: IKHRMaterialsClearcoat = {\r\n clearcoatFactor: babylonMaterial.clearCoat.intensity,\r\n clearcoatTexture: clearCoatTextureInfo ?? undefined,\r\n clearcoatRoughnessFactor: babylonMaterial.clearCoat.roughness,\r\n clearcoatRoughnessTexture: clearCoatTextureRoughnessInfo ?? undefined,\r\n clearcoatNormalTexture: clearCoatNormalTextureInfo ?? undefined,\r\n };\r\n\r\n if (clearCoatInfo.clearcoatTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null || clearCoatInfo.clearcoatRoughnessTexture !== null) {\r\n this._exporter._materialNeedsUVsSet.add(babylonMaterial);\r\n }\r\n\r\n node.extensions[NAME] = clearCoatInfo;\r\n }\r\n resolve(node);\r\n });\r\n }\r\n}\r\n\r\nGLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_clearcoat(exporter));\r\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IMaterial } from "babylonjs-gltf2interface";
|
|
2
|
+
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension.js";
|
|
3
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
4
|
+
import type { Material } from "@babylonjs/core/Materials/material.js";
|
|
5
|
+
import type { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
/**
|
|
7
|
+
* [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
|
|
8
|
+
* !!! Experimental Extension Subject to Changes !!!
|
|
9
|
+
*/
|
|
10
|
+
export declare class KHR_materials_diffuse_transmission implements IGLTFExporterExtensionV2 {
|
|
11
|
+
/** Name of this extension */
|
|
12
|
+
readonly name = "KHR_materials_diffuse_transmission";
|
|
13
|
+
/** Defines whether this extension is enabled */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** Defines whether this extension is required */
|
|
16
|
+
required: boolean;
|
|
17
|
+
private _exporter;
|
|
18
|
+
private _wasUsed;
|
|
19
|
+
constructor(exporter: GLTFExporter);
|
|
20
|
+
dispose(): void;
|
|
21
|
+
/** @internal */
|
|
22
|
+
get wasUsed(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* After exporting a material, deal with additional textures
|
|
25
|
+
* @param context GLTF context of the material
|
|
26
|
+
* @param node exported GLTF node
|
|
27
|
+
* @param babylonMaterial corresponding babylon material
|
|
28
|
+
* @returns array of additional textures to export
|
|
29
|
+
*/
|
|
30
|
+
postExportMaterialAdditionalTextures?(context: string, node: IMaterial, babylonMaterial: Material): BaseTexture[];
|
|
31
|
+
private _isExtensionEnabled;
|
|
32
|
+
/**
|
|
33
|
+
* After exporting a material
|
|
34
|
+
* @param context GLTF context of the material
|
|
35
|
+
* @param node exported GLTF node
|
|
36
|
+
* @param babylonMaterial corresponding babylon material
|
|
37
|
+
* @returns promise that resolves with the updated node
|
|
38
|
+
*/
|
|
39
|
+
postExportMaterialAsync?(context: string, node: IMaterial, babylonMaterial: Material): Promise<IMaterial>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { GLTFExporter } from "../glTFExporter.js";
|
|
2
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
3
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
4
|
+
const NAME = "KHR_materials_diffuse_transmission";
|
|
5
|
+
/**
|
|
6
|
+
* Get the appropriate translucency intensity texture for the material.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
function GetTranslucencyIntensityTexture(context, babylonMaterial) {
|
|
10
|
+
const subs = babylonMaterial.subSurface;
|
|
11
|
+
let texture = null;
|
|
12
|
+
// Check if translucency intensity texture is available or can be derived from thickness texture
|
|
13
|
+
if (subs.translucencyIntensityTexture) {
|
|
14
|
+
texture = subs.translucencyIntensityTexture;
|
|
15
|
+
}
|
|
16
|
+
else if (subs.thicknessTexture && subs.useMaskFromThicknessTexture) {
|
|
17
|
+
texture = subs.thicknessTexture;
|
|
18
|
+
}
|
|
19
|
+
if (texture && !subs.useGltfStyleTextures) {
|
|
20
|
+
Logger.Warn(`${context}: Translucency intensity texture is not supported when useGltfStyleTextures = false. Ignoring for: ${babylonMaterial.name}`, 1);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return texture;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* [Proposed Specification](https://github.com/KhronosGroup/glTF/pull/1825)
|
|
27
|
+
* !!! Experimental Extension Subject to Changes !!!
|
|
28
|
+
*/
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
30
|
+
export class KHR_materials_diffuse_transmission {
|
|
31
|
+
constructor(exporter) {
|
|
32
|
+
/** Name of this extension */
|
|
33
|
+
this.name = NAME;
|
|
34
|
+
/** Defines whether this extension is enabled */
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
/** Defines whether this extension is required */
|
|
37
|
+
this.required = false;
|
|
38
|
+
this._wasUsed = false;
|
|
39
|
+
this._exporter = exporter;
|
|
40
|
+
}
|
|
41
|
+
dispose() { }
|
|
42
|
+
/** @internal */
|
|
43
|
+
get wasUsed() {
|
|
44
|
+
return this._wasUsed;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* After exporting a material, deal with additional textures
|
|
48
|
+
* @param context GLTF context of the material
|
|
49
|
+
* @param node exported GLTF node
|
|
50
|
+
* @param babylonMaterial corresponding babylon material
|
|
51
|
+
* @returns array of additional textures to export
|
|
52
|
+
*/
|
|
53
|
+
postExportMaterialAdditionalTextures(context, node, babylonMaterial) {
|
|
54
|
+
const additionalTextures = [];
|
|
55
|
+
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
56
|
+
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
57
|
+
if (translucencyIntensityTexture) {
|
|
58
|
+
additionalTextures.push(translucencyIntensityTexture);
|
|
59
|
+
}
|
|
60
|
+
if (babylonMaterial.subSurface.translucencyColorTexture) {
|
|
61
|
+
additionalTextures.push(babylonMaterial.subSurface.translucencyColorTexture);
|
|
62
|
+
}
|
|
63
|
+
return additionalTextures;
|
|
64
|
+
}
|
|
65
|
+
return additionalTextures;
|
|
66
|
+
}
|
|
67
|
+
_isExtensionEnabled(mat) {
|
|
68
|
+
// This extension must not be used on a material that also uses KHR_materials_unlit
|
|
69
|
+
if (mat.unlit) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const subs = mat.subSurface;
|
|
73
|
+
if (!subs.isTranslucencyEnabled) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return (!mat.unlit &&
|
|
77
|
+
!subs.useAlbedoToTintTranslucency &&
|
|
78
|
+
subs.useGltfStyleTextures &&
|
|
79
|
+
subs.volumeIndexOfRefraction === 1 &&
|
|
80
|
+
subs.minimumThickness === 0 &&
|
|
81
|
+
subs.maximumThickness === 0);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* After exporting a material
|
|
85
|
+
* @param context GLTF context of the material
|
|
86
|
+
* @param node exported GLTF node
|
|
87
|
+
* @param babylonMaterial corresponding babylon material
|
|
88
|
+
* @returns promise that resolves with the updated node
|
|
89
|
+
*/
|
|
90
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
91
|
+
postExportMaterialAsync(context, node, babylonMaterial) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
if (babylonMaterial instanceof PBRMaterial && this._isExtensionEnabled(babylonMaterial)) {
|
|
94
|
+
this._wasUsed = true;
|
|
95
|
+
const subs = babylonMaterial.subSurface;
|
|
96
|
+
const translucencyIntensityTexture = GetTranslucencyIntensityTexture(context, babylonMaterial);
|
|
97
|
+
const diffuseTransmissionFactor = subs.translucencyIntensity == 0 ? undefined : subs.translucencyIntensity;
|
|
98
|
+
const diffuseTransmissionTexture = this._exporter._materialExporter.getTextureInfo(translucencyIntensityTexture) ?? undefined;
|
|
99
|
+
const diffuseTransmissionColorFactor = !subs.translucencyColor || subs.translucencyColor.equalsFloats(1.0, 1.0, 1.0) ? undefined : subs.translucencyColor.asArray();
|
|
100
|
+
const diffuseTransmissionColorTexture = this._exporter._materialExporter.getTextureInfo(subs.translucencyColorTexture) ?? undefined;
|
|
101
|
+
const diffuseTransmissionInfo = {
|
|
102
|
+
diffuseTransmissionFactor,
|
|
103
|
+
diffuseTransmissionTexture,
|
|
104
|
+
diffuseTransmissionColorFactor,
|
|
105
|
+
diffuseTransmissionColorTexture,
|
|
106
|
+
};
|
|
107
|
+
if (diffuseTransmissionTexture || diffuseTransmissionColorTexture) {
|
|
108
|
+
this._exporter._materialNeedsUVsSet.add(babylonMaterial);
|
|
109
|
+
}
|
|
110
|
+
node.extensions = node.extensions || {};
|
|
111
|
+
node.extensions[NAME] = diffuseTransmissionInfo;
|
|
112
|
+
}
|
|
113
|
+
resolve(node);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
GLTFExporter.RegisterExtension(NAME, (exporter) => new KHR_materials_diffuse_transmission(exporter));
|
|
118
|
+
//# sourceMappingURL=KHR_materials_diffuse_transmission.js.map
|