@babylonjs/serializers 7.41.1 → 7.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
|
|
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";
|
4
3
|
import type { IGLTFExporterExtensionV2 } from "../glTFExporterExtension";
|
5
4
|
/**
|
6
5
|
* @internal
|
@@ -19,5 +18,4 @@ export declare class KHR_texture_transform implements IGLTFExporterExtensionV2 {
|
|
19
18
|
/** @internal */
|
20
19
|
get wasUsed(): boolean;
|
21
20
|
postExportTexture?(context: string, textureInfo: ITextureInfo, babylonTexture: Texture): void;
|
22
|
-
preExportTextureAsync(context: string, babylonTexture: Texture): Promise<Nullable<Texture>>;
|
23
21
|
}
|
@@ -3,6 +3,7 @@ import { GLTFExporter } from "../glTFExporter.js";
|
|
3
3
|
const NAME = "KHR_texture_transform";
|
4
4
|
/**
|
5
5
|
* Computes the adjusted offset for a rotation centered about the origin.
|
6
|
+
* This does not work when scaling is involved; investigation is needed.
|
6
7
|
* @internal
|
7
8
|
*/
|
8
9
|
function AdjustOffsetForRotationCenter(babylonTexture) {
|
@@ -34,59 +35,53 @@ export class KHR_texture_transform {
|
|
34
35
|
return this._wasUsed;
|
35
36
|
}
|
36
37
|
postExportTexture(context, textureInfo, babylonTexture) {
|
37
|
-
const
|
38
|
-
if (
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
38
|
+
const scene = babylonTexture.getScene();
|
39
|
+
if (!scene) {
|
40
|
+
Tools.Warn(`${context}: "scene" is not defined for Babylon texture ${babylonTexture.name}! Not exporting with ${NAME}.`);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
/*
|
44
|
+
* The KHR_texture_transform schema only supports w rotation around the origin.
|
45
|
+
* See https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates.
|
46
|
+
*/
|
47
|
+
if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {
|
48
|
+
Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
const textureTransform = {};
|
52
|
+
let transformIsRequired = false;
|
53
|
+
if (babylonTexture.uOffset !== 0 || babylonTexture.vOffset !== 0) {
|
54
|
+
textureTransform.offset = [babylonTexture.uOffset, babylonTexture.vOffset];
|
55
|
+
transformIsRequired = true;
|
56
|
+
}
|
57
|
+
if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
|
58
|
+
textureTransform.scale = [babylonTexture.uScale, babylonTexture.vScale];
|
59
|
+
transformIsRequired = true;
|
60
|
+
}
|
61
|
+
if (babylonTexture.wAng !== 0) {
|
62
|
+
if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {
|
63
|
+
if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {
|
64
|
+
Tools.Warn(`${context}: Texture ${babylonTexture.name} with scaling and a rotation not centered at the origin cannot be exported with ${NAME}`);
|
65
|
+
return;
|
54
66
|
}
|
67
|
+
Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin will be exported with an adjusted texture offset for ${NAME}.`);
|
68
|
+
textureTransform.offset = AdjustOffsetForRotationCenter(babylonTexture);
|
55
69
|
}
|
56
|
-
|
57
|
-
|
58
|
-
transformIsRequired = true;
|
59
|
-
}
|
60
|
-
if (!transformIsRequired) {
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
this._wasUsed = true;
|
64
|
-
if (!textureInfo.extensions) {
|
65
|
-
textureInfo.extensions = {};
|
66
|
-
}
|
67
|
-
textureInfo.extensions[NAME] = textureTransform;
|
70
|
+
textureTransform.rotation = -babylonTexture.wAng;
|
71
|
+
transformIsRequired = true;
|
68
72
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {
|
82
|
-
Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);
|
83
|
-
resolve(null);
|
84
|
-
}
|
85
|
-
if (babylonTexture.wAng !== 0 && (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0)) {
|
86
|
-
Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin will be exported with an adjusted texture offset.`);
|
87
|
-
}
|
88
|
-
resolve(babylonTexture);
|
89
|
-
});
|
73
|
+
if (babylonTexture.coordinatesIndex !== 0) {
|
74
|
+
textureTransform.texCoord = babylonTexture.coordinatesIndex;
|
75
|
+
transformIsRequired = true;
|
76
|
+
}
|
77
|
+
if (!transformIsRequired) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
this._wasUsed = true;
|
81
|
+
if (!textureInfo.extensions) {
|
82
|
+
textureInfo.extensions = {};
|
83
|
+
}
|
84
|
+
textureInfo.extensions[NAME] = textureTransform;
|
90
85
|
}
|
91
86
|
}
|
92
87
|
GLTFExporter.RegisterExtension(NAME, () => new KHR_texture_transform());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,sCAAwB;
|
1
|
+
{"version":3,"file":"KHR_texture_transform.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/glTF/2.0/Extensions/KHR_texture_transform.ts"],"names":[],"mappings":"AACA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I,CAAC,GAAG,OAAO,aAAa,cAAc,CAAC,IAAI,kGAAkG,IAAI,GAAG,CAAC,CAAC;gBAChK,gBAAgB,CAAC,MAAM,GAAG,6BAA6B,CAAC,cAAc,CAAC,CAAC;YAC5E,CAAC;YACD,gBAAgB,CAAC,QAAQ,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC;YACjD,mBAAmB,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,IAAI,cAAc,CAAC,gBAAgB,KAAK,CAAC,EAAE,CAAC;YACxC,gBAAgB,CAAC,QAAQ,GAAG,cAAc,CAAC,gBAAgB,CAAC;YAC5D,mBAAmB,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACvB,OAAO;QACX,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC;YAC1B,WAAW,CAAC,UAAU,GAAG,EAAE,CAAC;QAChC,CAAC;QACD,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC;IACpD,CAAC;CACJ;AAED,YAAY,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 { IGLTFExporterExtensionV2 } from \"../glTFExporterExtension\";\r\nimport { GLTFExporter } from \"../glTFExporter\";\r\n\r\nconst NAME = \"KHR_texture_transform\";\r\n\r\n/**\r\n * Computes the adjusted offset for a rotation centered about the origin.\r\n * This does not work when scaling is involved; investigation is needed.\r\n * @internal\r\n */\r\nfunction AdjustOffsetForRotationCenter(babylonTexture: Texture): [number, number] {\r\n const { uOffset, vOffset, uRotationCenter, vRotationCenter, wAng } = babylonTexture;\r\n const cosAngle = Math.cos(-wAng);\r\n const sinAngle = Math.sin(-wAng);\r\n const deltaU = uRotationCenter * (1 - cosAngle) - vRotationCenter * sinAngle;\r\n const deltaV = vRotationCenter * (1 - cosAngle) + uRotationCenter * sinAngle;\r\n return [uOffset + deltaU, vOffset + deltaV];\r\n}\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 scene = babylonTexture.getScene();\r\n if (!scene) {\r\n Tools.Warn(`${context}: \"scene\" is not defined for Babylon texture ${babylonTexture.name}! Not exporting with ${NAME}.`);\r\n return;\r\n }\r\n\r\n /*\r\n * The KHR_texture_transform schema only supports w 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 (babylonTexture.uAng !== 0 || babylonTexture.vAng !== 0) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation in the u or v axis is not supported in glTF.`);\r\n return;\r\n }\r\n\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 if (babylonTexture.uRotationCenter !== 0 || babylonTexture.vRotationCenter !== 0) {\r\n if (babylonTexture.uScale !== 1 || babylonTexture.vScale !== 1) {\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with scaling and a rotation not centered at the origin cannot be exported with ${NAME}`);\r\n return;\r\n }\r\n Tools.Warn(`${context}: Texture ${babylonTexture.name} with rotation not centered at the origin will be exported with an adjusted texture offset for ${NAME}.`);\r\n textureTransform.offset = AdjustOffsetForRotationCenter(babylonTexture);\r\n }\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\nGLTFExporter.RegisterExtension(NAME, () => new KHR_texture_transform());\r\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babylonjs/serializers",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.43.0",
|
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.
|
21
|
+
"@babylonjs/core": "^7.43.0",
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
23
23
|
"@lts/serializers": "^1.0.0",
|
24
|
-
"babylonjs-gltf2interface": "^7.
|
24
|
+
"babylonjs-gltf2interface": "^7.43.0"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
27
|
"@babylonjs/core": "^7.0.0",
|