Skip to content

Inspector v2: Add GUI and Frame Graphs to Scene Explorer #16873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dev/inspector-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@dev/addons": "^1.0.0",
"@dev/core": "1.0.0",
"@dev/gui": "^1.0.0",
"@dev/loaders": "1.0.0",
"@dev/materials": "^1.0.0",
"@fluentui/react-components": "^9.62.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/dev/inspector-v2/src/inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { SkeletonPropertiesServiceDefinition } from "./services/panes/properties
import { SpritePropertiesServiceDefinition } from "./services/panes/properties/spritePropertiesService";
import { TransformPropertiesServiceDefinition } from "./services/panes/properties/transformPropertiesService";
import { AnimationGroupExplorerServiceDefinition } from "./services/panes/scene/animationGroupExplorerService";
import { FrameGraphExplorerServiceDefinition } from "./services/panes/scene/frameGraphExplorerService";
import { GuiExplorerServiceDefinition } from "./services/panes/scene/guiExplorerService";
import { MaterialExplorerServiceDefinition } from "./services/panes/scene/materialExplorerService";
import { NodeHierarchyServiceDefinition } from "./services/panes/scene/nodeExplorerService";
import { ParticleSystemExplorerServiceDefinition } from "./services/panes/scene/particleSystemExplorerService";
Expand Down Expand Up @@ -190,6 +192,8 @@ function _ShowInspector(scene: Nullable<Scene>, options: Partial<IInspectorOptio
ParticleSystemExplorerServiceDefinition,
SpriteManagerHierarchyServiceDefinition,
AnimationGroupExplorerServiceDefinition,
GuiExplorerServiceDefinition,
FrameGraphExplorerServiceDefinition,

// Properties pane tab and related services.
PropertiesServiceDefinition,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { ServiceDefinition } from "../../../modularity/serviceDefinition";
import type { ISceneContext } from "../../sceneContext";
import type { ISceneExplorerService } from "./sceneExplorerService";

import { FrameRegular } from "@fluentui/react-icons";

import { FrameGraph } from "core/FrameGraph/frameGraph";
import { Observable } from "core/Misc";
import { InterceptProperty } from "../../../instrumentation/propertyInstrumentation";
import { SceneContextIdentity } from "../../sceneContext";
import { SceneExplorerServiceIdentity } from "./sceneExplorerService";

export const FrameGraphExplorerServiceDefinition: ServiceDefinition<[], [ISceneExplorerService, ISceneContext]> = {
friendlyName: "Frame Graph Hierarchy",
consumes: [SceneExplorerServiceIdentity, SceneContextIdentity],
factory: (sceneExplorerService, sceneContext) => {
const scene = sceneContext.currentScene;
if (!scene) {
return undefined;
}

const sectionRegistration = sceneExplorerService.addSection({
displayName: "Frame Graph",
order: 1000,
predicate: (entity) => entity instanceof FrameGraph,
getRootEntities: () => scene.frameGraphs,
getEntityDisplayInfo: (frameGraph) => {
const onChangeObservable = new Observable<void>();

const nameHookToken = InterceptProperty(frameGraph, "name", {
afterSet: () => {
onChangeObservable.notifyObservers();
},
});

return {
get name() {
return frameGraph.name;
},
onChange: onChangeObservable,
dispose: () => {
nameHookToken.dispose();
onChangeObservable.clear();
},
};
},
entityIcon: () => <FrameRegular />,
getEntityAddedObservables: () => [scene.onNewFrameGraphAddedObservable],
getEntityRemovedObservables: () => [scene.onFrameGraphRemovedObservable],
});

return {
dispose: () => {
sectionRegistration.dispose();
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { AdvancedDynamicTexture } from "gui/index";
import type { ServiceDefinition } from "../../../modularity/serviceDefinition";
import type { ISceneContext } from "../../sceneContext";
import type { ISceneExplorerService } from "./sceneExplorerService";

import { AppGenericRegular } from "@fluentui/react-icons";

import { Observable } from "core/Misc";
import { InterceptProperty } from "../../../instrumentation/propertyInstrumentation";
import { SceneContextIdentity } from "../../sceneContext";
import { SceneExplorerServiceIdentity } from "./sceneExplorerService";

// Don't use instanceof in this case as we don't want to bring in the gui package just to check if the entity is an AdvancedDynamicTexture.
function IsAdvancedDynamicTexture(entity: unknown): entity is AdvancedDynamicTexture {
return (entity as AdvancedDynamicTexture)?.constructor?.name === "AdvancedDynamicTexture";
}

export const GuiExplorerServiceDefinition: ServiceDefinition<[], [ISceneExplorerService, ISceneContext]> = {
friendlyName: "GUI Hierarchy",
consumes: [SceneExplorerServiceIdentity, SceneContextIdentity],
factory: (sceneExplorerService, sceneContext) => {
const scene = sceneContext.currentScene;
if (!scene) {
return undefined;
}

const sectionRegistration = sceneExplorerService.addSection({
displayName: "GUI",
order: 900,
predicate: IsAdvancedDynamicTexture,
getRootEntities: () => scene.textures.filter(IsAdvancedDynamicTexture),
getEntityDisplayInfo: (texture) => {
const onChangeObservable = new Observable<void>();

const nameHookToken = InterceptProperty(texture, "name", {
afterSet: () => {
onChangeObservable.notifyObservers();
},
});

return {
get name() {
return texture.name;
},
onChange: onChangeObservable,
dispose: () => {
nameHookToken.dispose();
onChangeObservable.clear();
},
};
},
entityIcon: () => <AppGenericRegular />,
getEntityAddedObservables: () => [scene.onNewTextureAddedObservable],
getEntityRemovedObservables: () => [scene.onTextureRemovedObservable],
});

return {
dispose: () => {
sectionRegistration.dispose();
},
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type { ServiceDefinition } from "../../../modularity/serviceDefinition";
import type { ISceneContext } from "../../sceneContext";
import type { ISceneExplorerService } from "./sceneExplorerService";

import { ImageRegular } from "@fluentui/react-icons";
import { ImageEditRegular, ImageRegular } from "@fluentui/react-icons";

import { Texture } from "core/Materials/Textures/texture";
import { BaseTexture } from "core/Materials/Textures/baseTexture";
import { DynamicTexture } from "core/Materials/Textures/dynamicTexture";
import { Observable } from "core/Misc";
import { InterceptProperty } from "../../../instrumentation/propertyInstrumentation";
import { SceneContextIdentity } from "../../sceneContext";
Expand All @@ -22,8 +23,8 @@ export const TextureHierarchyServiceDefinition: ServiceDefinition<[], [ISceneExp
const sectionRegistration = sceneExplorerService.addSection({
displayName: "Textures",
order: 400,
predicate: (entity) => entity instanceof Texture,
getRootEntities: () => scene.textures,
predicate: (entity): entity is BaseTexture => entity instanceof BaseTexture && entity.getClassName() !== "AdvancedDynamicTexture",
getRootEntities: () => scene.textures.filter((texture) => texture.getClassName() !== "AdvancedDynamicTexture"),
getEntityDisplayInfo: (texture) => {
const onChangeObservable = new Observable<void>();

Expand All @@ -44,7 +45,7 @@ export const TextureHierarchyServiceDefinition: ServiceDefinition<[], [ISceneExp
},
};
},
entityIcon: () => <ImageRegular />,
entityIcon: ({ entity: texture }) => (texture instanceof DynamicTexture ? <ImageEditRegular /> : <ImageRegular />),
getEntityAddedObservables: () => [scene.onNewTextureAddedObservable],
getEntityRemovedObservables: () => [scene.onTextureRemovedObservable],
});
Expand Down
3 changes: 2 additions & 1 deletion packages/dev/inspector-v2/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ module.exports = (env) => {
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
alias: {
addons: path.resolve("../../dev/addons/dist"),
core: path.resolve("../../dev/core/dist"),
gui: path.resolve("../../dev/gui/dist"),
loaders: path.resolve("../../dev/loaders/dist"),
addons: path.resolve("../../dev/addons/dist"),
materials: path.resolve("../../dev/materials/dist"),
"shared-ui-components": path.resolve("../../dev/sharedUiComponents/src"),
},
Expand Down
3 changes: 3 additions & 0 deletions packages/tools/playground/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = (env) => {
materials: path.resolve("../../dev/materials/dist"),
core: path.resolve("../../dev/core/dist"),
loaders: path.resolve("../../dev/loaders/dist"),
gui: path.resolve("../../dev/gui/dist"),
},
},
externals: [
Expand All @@ -42,6 +43,8 @@ module.exports = (env) => {
return callback(null, "ADDONS");
} else if (/^materials\//.test(request)) {
return callback(null, "BABYLON");
} else if (/^gui\//.test(request)) {
return callback(null, "BABYLON.GUI");
}
}

Expand Down