Skip to content

Commit 4e5a7f7

Browse files
authored
Inspector v2: Test app (#16732)
This PR introduces a test app for local development of Inspector v2. It uses webpack, but a newer version than our other tools which is needed for compatibility with the webpack React fast refresh plugin (which is a new local dev only dependency). The simple test app just loads a model, and also enables drag & drop to easily test other models. Inspector is always open, and fast refresh is supported so as you make changes to React components, you immediately see them in the test app, without reloading the page or re-creating the scene. You can run and debug the test app from VSCode by just running the new "Inspector v2 development (Chrome)" launch command. This enables a very tight dev loop. Hopefully in the future we can see what it would take to bring fast refresh to other tools, like Sandbox and Playground, but for now this is a low cost solution to help speed up Inspector v2 development.
1 parent 9e9e8bc commit 4e5a7f7

File tree

10 files changed

+327
-9
lines changed

10 files changed

+327
-9
lines changed

.vscode/launch.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,18 @@
512512
"preLaunchTask": "Viewer Test App (Web)"
513513
},
514514
{
515-
/*
516-
Viewer configurator development - meant for development of the playground
517-
It doesn't set any source code watchers!
518-
*/
519515
"type": "chrome",
520516
"request": "launch",
521517
"name": "Viewer Configurator development (Chrome)",
522518
"url": "http://localhost:3003",
523519
"preLaunchTask": "Viewer Configurator Serve (Dev)"
520+
},
521+
{
522+
"type": "chrome",
523+
"request": "launch",
524+
"name": "Inspector v2 development (Chrome)",
525+
"url": "http://localhost:9001",
526+
"preLaunchTask": "Inspector v2 Test App"
524527
}
525528
],
526529
"inputs": [

.vscode/tasks.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
"label": "Sandbox Serve (Dev)",
310310
"type": "shell",
311311
"command": "npm",
312-
"dependsOn": "CDN Serve and watch (Dev)",
312+
"dependsOn": ["CDN Serve and watch (Dev)", "Watch Inspector v2"],
313313
"runOptions": {
314314
"instanceLimit": 1
315315
},
@@ -566,6 +566,38 @@
566566
"group": "serve"
567567
},
568568
"problemMatcher": ["$ts-webpack-watch", "$tslint-webpack-watch"]
569+
},
570+
{
571+
"label": "Watch Inspector v2",
572+
"type": "shell",
573+
"command": "npm",
574+
"runOptions": {
575+
"instanceLimit": 1
576+
},
577+
"options": {
578+
"cwd": "${workspaceFolder}"
579+
},
580+
"args": ["run", "watch:dev", "-w", "@dev/inspector-v2"],
581+
"isBackground": true,
582+
"problemMatcher": ["$tsc-watch"]
583+
},
584+
{
585+
"label": "Inspector v2 Test App",
586+
"dependsOn": ["Watch all (Dev)"],
587+
"type": "shell",
588+
"command": "npm",
589+
"runOptions": {
590+
"instanceLimit": 1
591+
},
592+
"options": {
593+
"cwd": "${workspaceFolder}"
594+
},
595+
"args": ["run", "serve", "-w", "@dev/inspector-v2"],
596+
"isBackground": true,
597+
"presentation": {
598+
"group": "serve"
599+
},
600+
"problemMatcher": ["$ts-webpack-watch", "$tslint-webpack-watch"]
569601
}
570602
],
571603
"inputs": [

package-lock.json

Lines changed: 122 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dev/inspector-v2/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"test": "jest -c ../../../jest.config.ts",
1212
"clean": "rimraf dist && rimraf *.tsbuildinfo -g",
1313
"compile": "tsc -b tsconfig.build.json",
14+
"serve": "webpack serve --mode development",
1415
"watch": "tsc -b tsconfig.build.json -w",
1516
"watch:dev": "npm run watch"
1617
},
@@ -19,8 +20,14 @@
1920
"@dev/loaders": "1.0.0",
2021
"@fluentui/react-components": "^9.62.0",
2122
"@fluentui/react-icons": "^2.0.271",
23+
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.0",
24+
"html-webpack-plugin": "^5.5.0",
2225
"react": "^18.2.0",
2326
"react-dom": "^18.2.0",
24-
"usehooks-ts": "^3.1.1"
27+
"react-refresh": "^0.17.0",
28+
"react-refresh-typescript": "^2.0.10",
29+
"usehooks-ts": "^3.1.1",
30+
"webpack": "^5.98.0",
31+
"webpack-cli": "^5.1.0"
2532
}
2633
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Inspector v2 Test App</title>
7+
8+
<style>
9+
html,
10+
body,
11+
canvas {
12+
width: 100%;
13+
height: 100%;
14+
padding: 0;
15+
margin: 0;
16+
overflow: hidden;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
<canvas id="canvas"></canvas>
22+
<script type="module" src="bundle.js"></script>
23+
</body>
24+
</html>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// eslint-disable-next-line import/no-internal-modules
2+
import type { ArcRotateCamera, Nullable } from "core/index";
3+
4+
import { Engine } from "core/Engines/engine";
5+
import { LoadAssetContainerAsync } from "core/Loading/sceneLoader";
6+
import { Scene } from "core/scene";
7+
import { registerBuiltInLoaders } from "loaders/dynamic";
8+
9+
import { ShowInspector } from "../../src/inspector";
10+
11+
import "core/Helpers/sceneHelpers";
12+
13+
// Register scene loader plugins.
14+
registerBuiltInLoaders();
15+
16+
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
17+
18+
const engine = new Engine(canvas, true, {
19+
adaptToDeviceRatio: true,
20+
antialias: true,
21+
});
22+
23+
const scene = new Scene(engine);
24+
25+
let camera: Nullable<ArcRotateCamera> = null;
26+
27+
function createCamera() {
28+
camera?.dispose();
29+
scene.createDefaultCameraOrLight(true, true, true);
30+
camera = scene.activeCamera as ArcRotateCamera;
31+
camera.alpha = Math.PI / 2;
32+
}
33+
34+
(async () => {
35+
let assetContainer = await LoadAssetContainerAsync("https://assets.babylonjs.com/meshes/Demos/optimized/acrobaticPlane_variants.glb", scene);
36+
assetContainer.addAllToScene();
37+
createCamera();
38+
39+
engine.runRenderLoop(() => {
40+
scene.render();
41+
});
42+
43+
canvas.addEventListener("dragover", (event) => {
44+
event.preventDefault();
45+
});
46+
47+
let isDropping = false;
48+
canvas.addEventListener("drop", async (event) => {
49+
if (!isDropping) {
50+
const file = event.dataTransfer?.files[0];
51+
if (file) {
52+
event.preventDefault();
53+
isDropping = true;
54+
try {
55+
assetContainer.removeAllFromScene();
56+
assetContainer = await LoadAssetContainerAsync(file, scene);
57+
assetContainer.addAllToScene();
58+
createCamera();
59+
} finally {
60+
isDropping = false;
61+
}
62+
}
63+
}
64+
});
65+
})();
66+
67+
ShowInspector(scene);

packages/dev/inspector-v2/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.build.json",
2+
"extends": ["../../../tsconfig.build.json", "./tsconfig.common.json"],
33

44
"compilerOptions": {
55
"outDir": "./dist",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"strict": true
5+
}
6+
}

packages/dev/inspector-v2/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.json",
2+
"extends": ["../../../tsconfig.json", "./tsconfig.common.json"],
33

44
"compilerOptions": {
55
"strict": true,

0 commit comments

Comments
 (0)