Skip to content

Commit b7f8a6c

Browse files
committed
feat: add support of automatic shadows quality in babylonjs-editor-tools
1 parent a2c2cbe commit b7f8a6c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

tools/src/loading/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { _applyScriptsForObject, _preloadScriptsAssets } from "./script";
1515

1616
import "./sound";
1717
import "./texture";
18+
import "./shadows";
1819

1920
/**
2021
* Defines the possible output type of a script.

tools/src/loading/shadows.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Scene } from "@babylonjs/core/scene";
2+
import { AssetContainer } from "@babylonjs/core/assetContainer";
3+
import { SceneComponentConstants } from "@babylonjs/core/sceneComponent";
4+
import { GetParser, AddParser } from "@babylonjs/core/Loading/Plugins/babylonFileParser.function";
5+
6+
import { getPowerOfTwoUntil } from "../tools/scalar";
7+
8+
const shadowsGeneratorParser = GetParser(SceneComponentConstants.NAME_SHADOWGENERATOR);
9+
10+
AddParser(SceneComponentConstants.NAME_SHADOWGENERATOR, (parsedData: any, scene: Scene, container: AssetContainer, rootUrl: string) => {
11+
if (scene.loadingQuality !== "high") {
12+
parsedData.shadowGenerators?.forEach((shadowGenerator: any) => {
13+
switch (scene.loadingQuality) {
14+
case "medium":
15+
shadowGenerator.mapSize = shadowGenerator.mapSize * 0.5;
16+
break;
17+
18+
case "low":
19+
shadowGenerator.mapSize = shadowGenerator.mapSize * 0.25;
20+
break;
21+
}
22+
23+
shadowGenerator.mapSize = Math.max(128, getPowerOfTwoUntil(shadowGenerator.mapSize));
24+
});
25+
}
26+
27+
shadowsGeneratorParser?.(parsedData, scene, container, rootUrl);
28+
});

0 commit comments

Comments
 (0)