@configura/babylon-view 2.2.0 → 2.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/material/texture.js +40 -2
- package/package.json +7 -6
package/dist/material/texture.js
CHANGED
|
@@ -13,6 +13,7 @@ import { GMaterial3DTexture, } from "@configura/web-core/dist/cm/core3D/GMateria
|
|
|
13
13
|
import { Bump3D, GMaterialClassic } from "@configura/web-core/dist/cm/core3D/GMaterialClassic.js";
|
|
14
14
|
import { GMaterialPBR, MIPS_TEXTURE_LEVEL, } from "@configura/web-core/dist/cm/core3D/GMaterialPBR.js";
|
|
15
15
|
import { CMMIPS_MIMETYPE, extractCmMips, getFileExtension, loadImage, LogObservable, } from "@configura/web-utilities";
|
|
16
|
+
import exifr from "exifr";
|
|
16
17
|
function getImageMimeType(fileExtension) {
|
|
17
18
|
switch (fileExtension.toLowerCase()) {
|
|
18
19
|
case "jpg":
|
|
@@ -118,12 +119,49 @@ function loadCachedImage(logger, resourceUrl, renderEnvironment) {
|
|
|
118
119
|
return textureImageWithMeta.image;
|
|
119
120
|
});
|
|
120
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* This is needed because textures are drawn inconsistently when applied in Model Lab
|
|
124
|
+
* or Catalogue Creator. This ensures consistency with Catalogue Creator (if texture loaded
|
|
125
|
+
* is an image of jpg/png format)
|
|
126
|
+
*/
|
|
127
|
+
function calculateUvScaling(url) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const img = yield loadImage(url);
|
|
130
|
+
if (img === undefined) {
|
|
131
|
+
return { uScale: 1, vScale: 1 };
|
|
132
|
+
}
|
|
133
|
+
const fileExtensionMatch = url.match(/\.(jpg|jpeg|png)$/);
|
|
134
|
+
const fileExtension = fileExtensionMatch ? fileExtensionMatch[1] : "unknown";
|
|
135
|
+
if (fileExtension !== "jpg" && fileExtension !== "jpeg" && fileExtension !== "png") {
|
|
136
|
+
return { uScale: 1, vScale: 1 };
|
|
137
|
+
}
|
|
138
|
+
const metadata = yield exifr.parse(img, {
|
|
139
|
+
jfif: fileExtension === "jpg" || fileExtension === "jpeg",
|
|
140
|
+
ihdr: fileExtension === "png",
|
|
141
|
+
});
|
|
142
|
+
const imageWidth = img.naturalWidth;
|
|
143
|
+
const imageHeight = img.naturalHeight;
|
|
144
|
+
if (!metadata.XResolution || !metadata.YResolution) {
|
|
145
|
+
return { uScale: 1, vScale: 1 };
|
|
146
|
+
}
|
|
147
|
+
const xResolution = metadata.XResolution;
|
|
148
|
+
const yResolution = metadata.YResolution;
|
|
149
|
+
const textureXDimension = imageWidth * (25.4 / xResolution);
|
|
150
|
+
const textureYDimension = imageHeight * (25.4 / yResolution);
|
|
151
|
+
const xScale = 1000 / textureXDimension;
|
|
152
|
+
const yScale = 1000 / textureYDimension;
|
|
153
|
+
return { uScale: xScale, vScale: yScale };
|
|
154
|
+
});
|
|
155
|
+
}
|
|
121
156
|
export function loadTextureFromURL(url, renderEnvironment) {
|
|
122
157
|
const task = renderEnvironment.assetsManager.addTextureTask("(loadTextureFromURL)", url);
|
|
123
158
|
return new Promise((resolve, reject) => {
|
|
124
|
-
task.runTask(renderEnvironment.scene, () => {
|
|
159
|
+
task.runTask(renderEnvironment.scene, () => __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const { uScale, vScale } = yield calculateUvScaling(task.url);
|
|
161
|
+
task.texture.uScale = uScale;
|
|
162
|
+
task.texture.vScale = vScale;
|
|
125
163
|
resolve(task.texture);
|
|
126
|
-
}, reject);
|
|
164
|
+
}), reject);
|
|
127
165
|
});
|
|
128
166
|
}
|
|
129
167
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configura/babylon-view",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-alpha.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
"@babylonjs/loaders": "5.52.0",
|
|
23
23
|
"@babylonjs/materials": "5.52.0",
|
|
24
24
|
"@babylonjs/serializers": "5.52.0",
|
|
25
|
-
"@configura/web-core": "2.
|
|
26
|
-
"@configura/web-utilities": "2.
|
|
27
|
-
"babylonjs-gltf2interface": "5.22.0"
|
|
25
|
+
"@configura/web-core": "2.3.0-alpha.0",
|
|
26
|
+
"@configura/web-utilities": "2.3.0-alpha.0",
|
|
27
|
+
"babylonjs-gltf2interface": "5.22.0",
|
|
28
|
+
"exifr": "^7.1.3"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@configura/web-api": "2.
|
|
31
|
+
"@configura/web-api": "2.3.0-alpha.0",
|
|
31
32
|
"@types/react": "17.0.9",
|
|
32
33
|
"@types/react-dom": "17.0.6",
|
|
33
34
|
"del-cli": "^3.0.0",
|
|
@@ -36,5 +37,5 @@
|
|
|
36
37
|
"publishConfig": {
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "45b11d8e97c4f0c6e75cb3bb785005d238ffd046"
|
|
40
41
|
}
|