@babylonjs/serializers 5.32.0 → 5.32.2
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_texture_transform.d.ts +2 -9
- package/glTF/2.0/Extensions/KHR_texture_transform.js +5 -54
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/glTFExporter.d.ts +2 -2
- package/glTF/2.0/glTFExporter.js +3 -3
- package/glTF/2.0/glTFExporter.js.map +1 -1
- package/glTF/2.0/glTFExporterExtension.d.ts +1 -1
- package/glTF/2.0/glTFExporterExtension.js.map +1 -1
- package/glTF/2.0/glTFMaterialExporter.d.ts +6 -13
- package/glTF/2.0/glTFMaterialExporter.js +215 -262
- package/glTF/2.0/glTFMaterialExporter.js.map +1 -1
- package/package.json +3 -3
- package/glTF/2.0/shaders/textureTransform.fragment.d.ts +0 -5
- package/glTF/2.0/shaders/textureTransform.fragment.js +0 -13
- package/glTF/2.0/shaders/textureTransform.fragment.js.map +0 -1
@@ -1,12 +1,11 @@
|
|
1
1
|
import type { ITextureInfo } from "babylonjs-gltf2interface";
|
2
2
|
import type { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
3
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
3
4
|
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
4
|
-
import "../shaders/textureTransform.fragment";
|
5
5
|
/**
|
6
6
|
* @internal
|
7
7
|
*/
|
8
8
|
export declare class KHR_texture_transform implements IGLTFExporterExtensionV2 {
|
9
|
-
private _recordedTextures;
|
10
9
|
/** Name of this extension */
|
11
10
|
readonly name = "KHR_texture_transform";
|
12
11
|
/** Defines whether this extension is enabled */
|
@@ -20,11 +19,5 @@ export declare class KHR_texture_transform implements IGLTFExporterExtensionV2 {
|
|
20
19
|
/** @internal */
|
21
20
|
get wasUsed(): boolean;
|
22
21
|
postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
|
23
|
-
preExportTextureAsync(context: string, babylonTexture: Texture): Promise<Texture
|
24
|
-
/**
|
25
|
-
* Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
|
26
|
-
* @param babylonTexture
|
27
|
-
* @param scene
|
28
|
-
*/
|
29
|
-
private _textureTransformTextureAsync;
|
22
|
+
preExportTextureAsync(context: string, babylonTexture: Texture): Promise<Nullable<Texture>>;
|
30
23
|
}
|
@@ -1,15 +1,12 @@
|
|
1
1
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
2
|
-
import { ProceduralTexture } from "@babylonjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
3
2
|
import { _Exporter } from "../glTFExporter.js";
|
4
3
|
const NAME = "KHR_texture_transform";
|
5
|
-
import "../shaders/textureTransform.fragment.js";
|
6
4
|
/**
|
7
5
|
* @internal
|
8
6
|
*/
|
9
7
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
10
8
|
export class KHR_texture_transform {
|
11
9
|
constructor() {
|
12
|
-
this._recordedTextures = [];
|
13
10
|
/** Name of this extension */
|
14
11
|
this.name = NAME;
|
15
12
|
/** Defines whether this extension is enabled */
|
@@ -19,11 +16,7 @@ export class KHR_texture_transform {
|
|
19
16
|
/** Reference to the glTF exporter */
|
20
17
|
this._wasUsed = false;
|
21
18
|
}
|
22
|
-
dispose() {
|
23
|
-
for (const texture of this._recordedTextures) {
|
24
|
-
texture.dispose();
|
25
|
-
}
|
26
|
-
}
|
19
|
+
dispose() { }
|
27
20
|
/** @internal */
|
28
21
|
get wasUsed() {
|
29
22
|
return this._wasUsed;
|
@@ -68,59 +61,17 @@ export class KHR_texture_transform {
|
|
68
61
|
reject(`${context}: "scene" is not defined for Babylon texture ${babylonTexture.name}!`);
|
69
62
|
return;
|
70
63
|
}
|
71
|
-
let bakeTextureTransform = false;
|
72
64
|
/*
|
73
65
|
* The KHR_texture_transform schema only supports rotation around the origin.
|
74
|
-
*
|
75
|
-
* see: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates
|
66
|
+
* See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.
|
76
67
|
*/
|
77
68
|
if ((babylonTexture.uAng !== 0 || babylonTexture.wAng !== 0 || babylonTexture.vAng !== 0) &&
|
78
69
|
(babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {
|
79
|
-
|
80
|
-
|
81
|
-
if (!bakeTextureTransform) {
|
82
|
-
resolve(babylonTexture);
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
return this._textureTransformTextureAsync(babylonTexture, scene)
|
86
|
-
.then((proceduralTexture) => {
|
87
|
-
resolve(proceduralTexture);
|
88
|
-
})
|
89
|
-
.catch((e) => {
|
90
|
-
reject(e);
|
91
|
-
});
|
92
|
-
});
|
93
|
-
}
|
94
|
-
/**
|
95
|
-
* Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture
|
96
|
-
* @param babylonTexture
|
97
|
-
* @param scene
|
98
|
-
*/
|
99
|
-
_textureTransformTextureAsync(babylonTexture, scene) {
|
100
|
-
return new Promise((resolve) => {
|
101
|
-
const proceduralTexture = new ProceduralTexture(`${babylonTexture.name}`, babylonTexture.getSize(), "textureTransform", scene);
|
102
|
-
if (!proceduralTexture) {
|
103
|
-
Tools.Log(`Cannot create procedural texture for ${babylonTexture.name}!`);
|
104
|
-
resolve(babylonTexture);
|
105
|
-
}
|
106
|
-
proceduralTexture.reservedDataStore = {
|
107
|
-
hidden: true,
|
108
|
-
source: babylonTexture,
|
109
|
-
};
|
110
|
-
this._recordedTextures.push(proceduralTexture);
|
111
|
-
proceduralTexture.coordinatesIndex = babylonTexture.coordinatesIndex;
|
112
|
-
proceduralTexture.setTexture("textureSampler", babylonTexture);
|
113
|
-
proceduralTexture.setMatrix("textureTransformMat", babylonTexture.getTextureMatrix());
|
114
|
-
// isReady trigger creation of effect if it doesnt exist yet
|
115
|
-
if (proceduralTexture.isReady()) {
|
116
|
-
proceduralTexture.render();
|
117
|
-
resolve(proceduralTexture);
|
70
|
+
Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin cannot be exported with ${NAME}`);
|
71
|
+
resolve(null);
|
118
72
|
}
|
119
73
|
else {
|
120
|
-
|
121
|
-
proceduralTexture.render();
|
122
|
-
resolve(proceduralTexture);
|
123
|
-
});
|
74
|
+
resolve(babylonTexture);
|
124
75
|
}
|
125
76
|
});
|
126
77
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,iBAAiB,EAAE,4EAA8D;AAI1F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC,OAAO,sCAAsC,CAAC;AAE9C;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAe9B;QAdQ,sBAAiB,GAAwB,EAAE,CAAC;QAEpD,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAExB,qCAAqC;QAC7B,aAAQ,GAAG,KAAK,CAAC;IAEV,CAAC;IAET,OAAO;QACV,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC1C,OAAO,CAAC,OAAO,EAAE,CAAC;SACrB;IACL,CAAC;IAED,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,iBAAiB,CAAE,OAAe,EAAE,WAAyB,EAAE,cAAuB;QACzF,MAAM,eAAe,GACjB,cAAc;YACd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AAG,cAAc,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,OAAO,EAAE,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;YAC/H,IAAI,CAAC,iBAAiB,EAAE;gBACpB,KAAK,CAAC,GAAG,CAAC,wCAAwC,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;gBAC1E,OAAO,CAAC,cAAc,CAAC,CAAC;aAC3B;YAED,iBAAiB,CAAC,iBAAiB,GAAG;gBAClC,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,cAAc;aACzB,CAAC;YAEF,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAE/C,iBAAiB,CAAC,gBAAgB,GAAG,cAAc,CAAC,gBAAgB,CAAC;YACrE,iBAAiB,CAAC,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;YAC/D,iBAAiB,CAAC,SAAS,CAAC,qBAAqB,EAAE,cAAc,CAAC,gBAAgB,EAAE,CAAC,CAAC;YAEtF,4DAA4D;YAC5D,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE;gBAC7B,iBAAiB,CAAC,MAAM,EAAE,CAAC;gBAC3B,OAAO,CAAC,iBAAiB,CAAC,CAAC;aAC9B;iBAAM;gBACH,iBAAiB,CAAC,SAAS,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE;oBACnD,iBAAiB,CAAC,MAAM,EAAE,CAAC;oBAC3B,OAAO,CAAC,iBAAiB,CAAC,CAAC;gBAC/B,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC","sourcesContent":["import type { ITextureInfo, IKHRTextureTransform } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Scene } from \"core/scene\";\r\n\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\nimport \"../shaders/textureTransform.fragment\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_texture_transform implements IGLTFExporterExtensionV2 {\r\n private _recordedTextures: ProceduralTexture[] = [];\r\n\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 /** Reference to the glTF exporter */\r\n private _wasUsed = false;\r\n\r\n constructor() {}\r\n\r\n public dispose() {\r\n for (const texture of this._recordedTextures) {\r\n texture.dispose();\r\n }\r\n }\r\n\r\n /** @internal */\r\n public get wasUsed() {\r\n return this._wasUsed;\r\n }\r\n\r\n public postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void {\r\n const canUseExtension =\r\n babylonTexture &&\r\n ((babylonTexture.uAng === 0 && babylonTexture.wAng === 0 && babylonTexture.vAng === 0) ||\r\n (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0));\r\n\r\n if (canUseExtension) {\r\n const textureTransform: IKHRTextureTransform = {};\r\n let transformIsRequired = false;\r\n\r\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\r\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.wAng !== 0) {\r\n textureTransform.rotation = babylonTexture.wAng;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.coordinatesIndex !== 0) {\r\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (!transformIsRequired) {\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n if (!textureInfo.extensions) {\r\n textureInfo.extensions = {};\r\n }\r\n textureInfo.extensions[NAME] = textureTransform;\r\n }\r\n }\r\n\r\n public preExportTextureAsync(context: string, babylonTexture: Texture): Promise<Texture> {\r\n return new Promise((resolve, reject) => {\r\n const scene = babylonTexture.getScene();\r\n if (!scene) {\r\n reject(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\r\n return;\r\n }\r\n\r\n let bakeTextureTransform = false;\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports rotation around the origin.\r\n * the texture must be baked to preserve appearance.\r\n * see: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates\r\n */\r\n if (\r\n (babylonTexture.uAng !== 0 || babylonTexture.wAng !== 0 || babylonTexture.vAng !== 0) &&\r\n (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)\r\n ) {\r\n bakeTextureTransform = true;\r\n }\r\n\r\n if (!bakeTextureTransform) {\r\n resolve(babylonTexture);\r\n return;\r\n }\r\n\r\n return this._textureTransformTextureAsync(babylonTexture, scene)\r\n .then((proceduralTexture) => {\r\n resolve(proceduralTexture);\r\n })\r\n .catch((e) => {\r\n reject(e);\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Transform the babylon texture by the offset, rotation and scale parameters using a procedural texture\r\n * @param babylonTexture\r\n * @param scene\r\n */\r\n private _textureTransformTextureAsync(babylonTexture: Texture, scene: Scene): Promise<Texture> {\r\n return new Promise((resolve) => {\r\n const proceduralTexture = new ProceduralTexture(`${babylonTexture.name}`, babylonTexture.getSize(), \"textureTransform\", scene);\r\n if (!proceduralTexture) {\r\n Tools.Log(`Cannot create procedural texture for ${babylonTexture.name}!`);\r\n resolve(babylonTexture);\r\n }\r\n\r\n proceduralTexture.reservedDataStore = {\r\n hidden: true,\r\n source: babylonTexture,\r\n };\r\n\r\n this._recordedTextures.push(proceduralTexture);\r\n\r\n proceduralTexture.coordinatesIndex = babylonTexture.coordinatesIndex;\r\n proceduralTexture.setTexture(\"textureSampler\", babylonTexture);\r\n proceduralTexture.setMatrix(\"textureTransformMat\", babylonTexture.getTextureMatrix());\r\n\r\n // isReady trigger creation of effect if it doesnt exist yet\r\n if (proceduralTexture.isReady()) {\r\n proceduralTexture.render();\r\n resolve(proceduralTexture);\r\n } else {\r\n proceduralTexture.getEffect().executeWhenCompiled(() => {\r\n proceduralTexture.render();\r\n resolve(proceduralTexture);\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n"]}
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../../lts/serializers/generated/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAIxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,IAAI,GAAG,uBAAuB,CAAC;AAErC;;GAEG;AACH,gEAAgE;AAChE,MAAM,OAAO,qBAAqB;IAa9B;QAZA,6BAA6B;QACb,SAAI,GAAG,IAAI,CAAC;QAE5B,gDAAgD;QACzC,YAAO,GAAG,IAAI,CAAC;QAEtB,iDAAiD;QAC1C,aAAQ,GAAG,KAAK,CAAC;QAExB,qCAAqC;QAC7B,aAAQ,GAAG,KAAK,CAAC;IAEV,CAAC;IAET,OAAO,KAAI,CAAC;IAEnB,gBAAgB;IAChB,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEM,iBAAiB,CAAE,OAAe,EAAE,WAAyB,EAAE,cAAuB;QACzF,MAAM,eAAe,GACjB,cAAc;YACd,CAAC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C;aAC/B;YACD,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;SACnD;IACL,CAAC;IAEM,qBAAqB,CAAC,OAAe,EAAE,cAAuB;QACjE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,EAAE;gBACR,MAAM,CAAC,GAAG,OAAO,gDAAgD,cAAc,CAAC,IAAI,GAAG,CAAC,CAAC;gBACzF,OAAO;aACV;YAED;;;eAGG;YACH,IACI,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC,CAAC;gBACrF,CAAC,cAAc,CAAC,eAAe,KAAK,CAAC,IAAI,cAAc,CAAC,eAAe,KAAK,CAAC,CAAC,EAChF;gBACE,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,aAAa,cAAc,CAAC,IAAI,qEAAqE,IAAI,EAAE,CAAC,CAAC;gBAClI,OAAO,CAAC,IAAI,CAAC,CAAC;aACjB;iBAAM;gBACH,OAAO,CAAC,cAAc,CAAC,CAAC;aAC3B;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC","sourcesContent":["import type { ITextureInfo, IKHRTextureTransform } from \"babylonjs-gltf2interface\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { _Exporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * @internal\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport class KHR_texture_transform 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 /** Reference to the glTF exporter */\r\n private _wasUsed = false;\r\n\r\n constructor() {}\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 postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void {\r\n const canUseExtension =\r\n babylonTexture &&\r\n ((babylonTexture.uAng === 0 && babylonTexture.wAng === 0 && babylonTexture.vAng === 0) ||\r\n (babylonTexture.uRotationCenter === 0 && babylonTexture.vRotationCenter === 0));\r\n\r\n if (canUseExtension) {\r\n const textureTransform: IKHRTextureTransform = {};\r\n let transformIsRequired = false;\r\n\r\n if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {\r\n textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.wAng !== 0) {\r\n textureTransform.rotation = babylonTexture.wAng;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (babylonTexture.coordinatesIndex !== 0) {\r\n textureTransform.texCoord = babylonTexture.coordinatesIndex;\r\n transformIsRequired = true;\r\n }\r\n\r\n if (!transformIsRequired) {\r\n return;\r\n }\r\n\r\n this._wasUsed = true;\r\n if (!textureInfo.extensions) {\r\n textureInfo.extensions = {};\r\n }\r\n textureInfo.extensions[NAME] = textureTransform;\r\n }\r\n }\r\n\r\n public preExportTextureAsync(context: string, babylonTexture: Texture): Promise<Nullable<Texture>> {\r\n return new Promise((resolve, reject) => {\r\n const scene = babylonTexture.getScene();\r\n if (!scene) {\r\n reject(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}!`);\r\n return;\r\n }\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports rotation around the origin.\r\n * See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.\r\n */\r\n if (\r\n (babylonTexture.uAng !== 0 || babylonTexture.wAng !== 0 || babylonTexture.vAng !== 0) &&\r\n (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)\r\n ) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin cannot be exported with ${NAME}`);\r\n resolve(null);\r\n } else {\r\n resolve(babylonTexture);\r\n }\r\n });\r\n }\r\n}\r\n\r\n_Exporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n"]}
|
@@ -91,12 +91,12 @@ export declare class _Exporter {
|
|
91
91
|
*/
|
92
92
|
_imageData: {
|
93
93
|
[fileName: string]: {
|
94
|
-
data:
|
94
|
+
data: ArrayBuffer;
|
95
95
|
mimeType: ImageMimeType;
|
96
96
|
};
|
97
97
|
};
|
98
98
|
protected _orderedImageData: Array<{
|
99
|
-
data:
|
99
|
+
data: ArrayBuffer;
|
100
100
|
mimeType: ImageMimeType;
|
101
101
|
}>;
|
102
102
|
/**
|
package/glTF/2.0/glTFExporter.js
CHANGED
@@ -784,8 +784,8 @@ export class _Exporter {
|
|
784
784
|
imageData = this._imageData[image.uri];
|
785
785
|
this._orderedImageData.push(imageData);
|
786
786
|
imageName = image.uri.split(".")[0] + " image";
|
787
|
-
bufferView = _GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.
|
788
|
-
byteOffset += imageData.data.
|
787
|
+
bufferView = _GLTFUtilities._CreateBufferView(0, byteOffset, imageData.data.byteLength, undefined, imageName);
|
788
|
+
byteOffset += imageData.data.byteLength;
|
789
789
|
this._bufferViews.push(bufferView);
|
790
790
|
image.bufferView = this._bufferViews.length - 1;
|
791
791
|
image.name = imageName;
|
@@ -937,7 +937,7 @@ export class _Exporter {
|
|
937
937
|
const glbData = [headerBuffer, jsonChunkBuffer, binaryChunkBuffer, binaryBuffer];
|
938
938
|
// binary data
|
939
939
|
for (let i = 0; i < this._orderedImageData.length; ++i) {
|
940
|
-
glbData.push(this._orderedImageData[i].data
|
940
|
+
glbData.push(this._orderedImageData[i].data);
|
941
941
|
}
|
942
942
|
glbData.push(binPaddingBuffer);
|
943
943
|
glbData.push(imagePaddingBuffer);
|