babylonjs-editor-tools 0.0.3 → 0.0.4
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/build/loader.js +11 -1
- package/build/texture.js +37 -74
- package/build/tools/math.js +1 -0
- package/build/tools/scalar.js +12 -0
- package/declaration/loader.d.ts +23 -1
- package/declaration/texture.d.ts +1 -2
- package/declaration/tools/math.d.ts +0 -0
- package/declaration/tools/scalar.d.ts +1 -0
- package/package.json +1 -1
package/build/loader.js
CHANGED
|
@@ -6,7 +6,9 @@ const ssr_1 = require("./rendering/ssr");
|
|
|
6
6
|
const ssao_1 = require("./rendering/ssao");
|
|
7
7
|
const motion_blur_1 = require("./rendering/motion-blur");
|
|
8
8
|
const default_pipeline_1 = require("./rendering/default-pipeline");
|
|
9
|
-
|
|
9
|
+
require("./texture");
|
|
10
|
+
async function loadScene(rootUrl, sceneFilename, scene, scriptsMap, quality = "hight") {
|
|
11
|
+
scene.loadingQuality = quality;
|
|
10
12
|
await sceneLoader_1.SceneLoader.AppendAsync(rootUrl, sceneFilename, scene);
|
|
11
13
|
if (scene.metadata?.rendering) {
|
|
12
14
|
const camera = scene.activeCamera ?? scene.cameras[0];
|
|
@@ -51,6 +53,14 @@ function loadScriptsFor(scene, object, scriptsMap) {
|
|
|
51
53
|
scene.onBeforeRenderObservable.add(() => instance.onUpdate());
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
else {
|
|
57
|
+
if (exports.onStart) {
|
|
58
|
+
scene.onBeforeRenderObservable.addOnce(() => exports.onStart(object));
|
|
59
|
+
}
|
|
60
|
+
if (exports.onUpdate) {
|
|
61
|
+
scene.onBeforeRenderObservable.add(() => exports.onUpdate(object));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
54
64
|
});
|
|
55
65
|
object.metadata.scripts = undefined;
|
|
56
66
|
}
|
package/build/texture.js
CHANGED
|
@@ -1,81 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const decorators_serialization_1 = require("@babylonjs/core/Misc/decorators.serialization");
|
|
4
|
+
const scalar_1 = require("./tools/scalar");
|
|
5
|
+
/**
|
|
6
|
+
* Defines the reference to the original texture parser function.
|
|
7
|
+
*/
|
|
8
|
+
const textureParser = decorators_serialization_1.SerializationHelper._TextureParser;
|
|
9
|
+
decorators_serialization_1.SerializationHelper._TextureParser = (sourceProperty, scene, rootUrl) => {
|
|
10
|
+
if (scene.loadingQuality === "hight" || !sourceProperty.metadata?.baseSize) {
|
|
11
|
+
return textureParser(sourceProperty, scene, rootUrl);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
sceneMap.set(scene, renderLoop);
|
|
28
|
-
engine.runRenderLoop(renderLoop);
|
|
29
|
-
}
|
|
30
|
-
exports.startTextureOptimizer = startTextureOptimizer;
|
|
31
|
-
function handleMesh(camera, mesh) {
|
|
32
|
-
const material = mesh.material;
|
|
33
|
-
const textures = material.getActiveTextures();
|
|
34
|
-
if (!textures.length) {
|
|
35
|
-
return;
|
|
13
|
+
const width = sourceProperty.metadata.baseSize.width;
|
|
14
|
+
const height = sourceProperty.metadata.baseSize.height;
|
|
15
|
+
let suffix = "";
|
|
16
|
+
switch (scene.loadingQuality) {
|
|
17
|
+
case "medium":
|
|
18
|
+
const midWidth = (0, scalar_1.getPowerOfTwoUntil)(width * 0.66);
|
|
19
|
+
const midHeight = (0, scalar_1.getPowerOfTwoUntil)(height * 0.66);
|
|
20
|
+
suffix = `_${midWidth}_${midHeight}`;
|
|
21
|
+
break;
|
|
22
|
+
case "low":
|
|
23
|
+
const lowWidth = (0, scalar_1.getPowerOfTwoUntil)(width * 0.33);
|
|
24
|
+
const lowHeight = (0, scalar_1.getPowerOfTwoUntil)(height * 0.33);
|
|
25
|
+
suffix = `_${lowWidth}_${lowHeight}`;
|
|
26
|
+
break;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
28
|
+
const name = sourceProperty.name;
|
|
29
|
+
if (!name || !suffix) {
|
|
30
|
+
return textureParser(sourceProperty, scene, rootUrl);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const finalUrl = name.split("/");
|
|
33
|
+
const filename = finalUrl.pop();
|
|
34
|
+
if (!filename) {
|
|
35
|
+
return textureParser(sourceProperty, scene, rootUrl);
|
|
43
36
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
url: texture.getInternalTexture()?.url,
|
|
52
|
-
};
|
|
53
|
-
const url = texture.metadata.editor.url;
|
|
54
|
-
if (!url) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
let ratio = texture.metadata.editor.ratio;
|
|
58
|
-
if (isInFrustrum && ratio === 1) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
let split = url.split("/");
|
|
62
|
-
const dirname = split.slice(0, -1).join("/");
|
|
63
|
-
const basename = split[split.length - 1];
|
|
64
|
-
split = basename.split(".");
|
|
65
|
-
ratio *= (isInFrustrum ? 2 : 0.5);
|
|
66
|
-
const width = texture.getBaseSize().width * ratio;
|
|
67
|
-
const height = texture.getBaseSize().height * ratio;
|
|
68
|
-
if (!isInFrustrum && (width <= 8 || height <= 8)) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
if (ratio === 1 && texture.getInternalTexture().url !== url) {
|
|
72
|
-
texture.updateURL(url);
|
|
73
|
-
}
|
|
74
|
-
else if (ratio < 1) {
|
|
75
|
-
const newUrl = `${dirname}/${split[0]}_${width}_${height}.${split[1]}`;
|
|
76
|
-
texture.updateURL(newUrl);
|
|
77
|
-
}
|
|
78
|
-
texture.metadata.editor.ratio = ratio;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
37
|
+
const extension = filename.split(".").pop();
|
|
38
|
+
const baseFilename = filename.replace(`.${extension}`, "");
|
|
39
|
+
const newFilename = `${baseFilename}${suffix}.${extension}`;
|
|
40
|
+
finalUrl.push(newFilename);
|
|
41
|
+
sourceProperty.name = finalUrl.join("/");
|
|
42
|
+
return textureParser(sourceProperty, scene, rootUrl);
|
|
43
|
+
};
|
|
81
44
|
//# sourceMappingURL=texture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPowerOfTwoUntil = void 0;
|
|
4
|
+
function getPowerOfTwoUntil(limit) {
|
|
5
|
+
let size = 1;
|
|
6
|
+
while (size <= limit) {
|
|
7
|
+
size <<= 1;
|
|
8
|
+
}
|
|
9
|
+
return size >> 1;
|
|
10
|
+
}
|
|
11
|
+
exports.getPowerOfTwoUntil = getPowerOfTwoUntil;
|
|
12
|
+
//# sourceMappingURL=scalar.js.map
|
package/declaration/loader.d.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { Scene } from "@babylonjs/core/scene";
|
|
2
|
+
import "./texture";
|
|
3
|
+
/**
|
|
4
|
+
* Defines the possible output type of a script.
|
|
5
|
+
* `default` is a class that will be instantiated with the object as parameter.
|
|
6
|
+
* `onStart` is a function that will be called once before the first render passing the reference to the object the script is attached to.
|
|
7
|
+
* `onUpdate` is a function that will be called every frame passing the reference to the object the script is attached to
|
|
8
|
+
*/
|
|
2
9
|
export type ScriptMap = Record<string, {
|
|
3
10
|
default?: new (object: any) => {
|
|
4
11
|
onStart?(): void;
|
|
5
12
|
onUpdate?(): void;
|
|
6
13
|
};
|
|
14
|
+
onStart?: (object: any) => void;
|
|
15
|
+
onUpdate?: (object: any) => void;
|
|
7
16
|
}>;
|
|
8
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Defines the overall desired quality of the scene.
|
|
19
|
+
* In other words, defines the quality of textures that will be loaded in terms of dimensions.
|
|
20
|
+
* The editor computes automatic "hight (untouched)", "medium (half)", and "low (quarter)" quality levels for textures.
|
|
21
|
+
* Using "medium" or "low" quality levels will reduce the memory usage and improve the performance of the scene
|
|
22
|
+
* especially on mobiles where memory is limited.
|
|
23
|
+
*/
|
|
24
|
+
export type SceneLoaderQualitySelector = "low" | "medium" | "hight";
|
|
25
|
+
declare module "@babylonjs/core/scene" {
|
|
26
|
+
interface Scene {
|
|
27
|
+
loadingQuality: SceneLoaderQualitySelector;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export declare function loadScene(rootUrl: string, sceneFilename: string, scene: Scene, scriptsMap: ScriptMap, quality?: SceneLoaderQualitySelector): Promise<void>;
|
|
9
31
|
export declare function loadScriptsFor(scene: Scene, object: any, scriptsMap: ScriptMap): void;
|
package/declaration/texture.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function startTextureOptimizer(scene: Scene): void;
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPowerOfTwoUntil(limit: number): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babylonjs-editor-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Babylon.js Editor Tools is a set of tools to help you create, edit and manage your Babylon.js scenes made using the Babylon.JS Editor",
|
|
5
5
|
"productName": "Babylon.js Editor Tools",
|
|
6
6
|
"scripts": {
|