Skip to content

Commit edb4dec

Browse files
committed
Reworked way to open and init windowed plugins.
1 parent 64592a9 commit edb4dec

File tree

21 files changed

+319
-218
lines changed

21 files changed

+319
-218
lines changed

.gitignore

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,9 @@ build
131131
declaration
132132
electron-packages
133133
dist
134-
vscode-extension/.build
135-
vscode-extension/.declaration
136-
vscode-extension/*.vsix
137134
photoshop-extension/.build
138135
photoshop-extension/.declaration
139-
140-
# Files
141-
babylonjs-editor-extensions.d.ts
142-
babylonjs-editor-extensions-es6.d.ts
143-
css/editor.bundle.css
136+
module/index.d.ts
144137

145138
# Tests
146139
!test/**/

.npmignore

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ npm install
2121
```
2222

2323
## Building
24-
Building Editor)
24+
Building Editor
2525

2626
```bash
2727
npm run build

module/.npmignore

Whitespace-only changes.

module/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "babylonjs-editor",
3+
"version": "3.2.1-beta.4",
4+
"description": "Babylon.js Editor is a Web Application helping artists to work with Babylon.js",
5+
"productName": "Babylon.js Editor",
6+
"typings": "index.d.ts",
7+
"repository": {
8+
"url": "https://github.com/BabylonJS/Editor/"
9+
},
10+
"author": {
11+
"name": "Julien Moreau-Mathis",
12+
"url": "https://medium.com/@Luaacro"
13+
},
14+
"scripts": {},
15+
"readme": "https://github.com/BabylonJS/Editor/blob/master/README.md",
16+
"license": "(Apache-2.0)",
17+
"devDependencies": {},
18+
"dependencies": {}
19+
}

package-lock.json

Lines changed: 178 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,32 @@
3535
"@types/raphael": "2.1.30",
3636
"@types/react": "16.9.19",
3737
"@types/react-dom": "16.9.5",
38+
"dts-bundle": "^0.7.3",
3839
"electron": "8.1.0",
3940
"electron-builder": "22.5.1",
4041
"electron-rebuild": "1.10.1",
4142
"rimraf": "3.0.2"
4243
},
4344
"dependencies": {
44-
"@babylonjs/core": "4.2.0-alpha.15",
45-
"@babylonjs/gui": "4.2.0-alpha.15",
46-
"@babylonjs/loaders": "4.2.0-alpha.15",
47-
"@babylonjs/materials": "4.2.0-alpha.15",
48-
"@babylonjs/post-processes": "4.2.0-alpha.15",
49-
"@babylonjs/procedural-textures": "4.2.0-alpha.15",
45+
"@babylonjs/core": "4.2.0-alpha.16",
46+
"@babylonjs/gui": "4.2.0-alpha.16",
47+
"@babylonjs/loaders": "4.2.0-alpha.16",
48+
"@babylonjs/materials": "4.2.0-alpha.16",
49+
"@babylonjs/post-processes": "4.2.0-alpha.16",
50+
"@babylonjs/procedural-textures": "4.2.0-alpha.16",
5051
"@blueprintjs/core": "3.26.0",
5152
"@blueprintjs/select": "3.12.2",
5253
"adm-zip": "0.4.14",
5354
"antd": "4.2.0",
54-
"babylonjs": "4.2.0-alpha.15",
55-
"babylonjs-gui": "4.2.0-alpha.15",
56-
"babylonjs-inspector": "4.2.0-alpha.15",
57-
"babylonjs-loaders": "4.2.0-alpha.15",
58-
"babylonjs-materials": "4.2.0-alpha.15",
59-
"babylonjs-node-editor": "4.2.0-alpha.15",
60-
"babylonjs-post-process": "4.2.0-alpha.15",
61-
"babylonjs-procedural-textures": "4.2.0-alpha.15",
62-
"babylonjs-serializers": "4.2.0-alpha.15",
55+
"babylonjs": "4.2.0-alpha.16",
56+
"babylonjs-gui": "4.2.0-alpha.16",
57+
"babylonjs-inspector": "4.2.0-alpha.16",
58+
"babylonjs-loaders": "4.2.0-alpha.16",
59+
"babylonjs-materials": "4.2.0-alpha.16",
60+
"babylonjs-node-editor": "4.2.0-alpha.16",
61+
"babylonjs-post-process": "4.2.0-alpha.16",
62+
"babylonjs-procedural-textures": "4.2.0-alpha.16",
63+
"babylonjs-serializers": "4.2.0-alpha.16",
6364
"cannon": "0.6.2",
6465
"ccapture.js": "1.1.0",
6566
"chalk": "4.0.0",

script/dts.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const dts = require("dts-bundle");
2+
3+
dts.bundle({
4+
name: "babylonjs-editor",
5+
main: "./declaration/src/src/renderer/editor/index.d.ts",
6+
out: "../../../../../module/index.d.ts",
7+
});

src/renderer/editor/assets/textures.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class TextureAssets extends AbstractAssets {
125125
const file = FilesStore.GetFileFromBaseName(name);
126126
if (!file) { return; }
127127

128-
await this.editor.addWindowedPlugin("texture-viewer", undefined, { path: file.path });
128+
await this.editor.addWindowedPlugin("texture-viewer", undefined, file.path);
129129
}
130130

131131
/**

src/renderer/editor/components/main-toolbar.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { AbstractMesh, Node, IParticleSystem } from "babylonjs";
1111

1212
import { Editor } from "../editor";
1313

14-
import { IPCTools } from "../tools/ipc";
1514
import { Tools } from "../tools/tools";
1615
import { ExecTools } from "../tools/exec";
1716

@@ -334,10 +333,8 @@ export class MainToolbar extends React.Component<IToolbarProps, IToolbarState> {
334333
* Called on the user wants to show the workspace settings.
335334
*/
336335
private async _handleWorkspaceSettings(): Promise<void> {
337-
const popupId = await this._editor.addWindowedPlugin("workspace-settings");
336+
const popupId = await this._editor.addWindowedPlugin("workspace-settings", undefined, WorkSpace.Path);
338337
if (!popupId) { return; }
339-
340-
IPCTools.SendWindowMessage(popupId, "workspace-path", { path: WorkSpace.Path! });
341338
}
342339

343340
/**

src/renderer/editor/editor.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ export class Editor {
504504
* Adds a new plugin handled by its own window.
505505
* @param name the name of the plugin to load.
506506
* @param windowId the id of the window that is possibly already opened.
507-
* @param initData optional data to send for the initialization of the plugin.
507+
* @param args optional arguments to pass the plugn's .init function.
508508
*/
509-
public async addWindowedPlugin(name: string, windowId?: Undefinable<number>, initData?: Undefinable<any>): Promise<Nullable<number>> {
509+
public async addWindowedPlugin(name: string, windowId?: Undefinable<number>, ...args: any[]): Promise<Nullable<number>> {
510510
// Check if the provided window id exists. If exists, just restore.
511511
if (windowId) {
512512
const index = this._pluginWindows.indexOf(windowId);
@@ -536,13 +536,9 @@ export class Editor {
536536
this._pluginWindows.push(popupId);
537537

538538
await Tools.Wait(100);
539-
await IPCTools.SendWindowMessage(popupId, "pluginName", { name });
539+
await IPCTools.SendWindowMessage(popupId, "pluginName", { name, args });
540540
await Tools.Wait(100);
541541

542-
if (initData !== undefined) {
543-
IPCTools.SendWindowMessage(popupId, "init", initData);
544-
}
545-
546542
return popupId;
547543
}
548544

src/renderer/editor/gui/augmentations/key-mapper.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class KeyMapper extends React.Component<IKeyMapperProps, IKeyMapperState>
7272
export class KeyMapperController extends dat.controllers.Controller {
7373
private _title: HTMLSpanElement;
7474

75+
private _keyMapper: KeyMapper;
76+
private _refHandler = {
77+
getKeyMapper: (ref: KeyMapper) => this._keyMapper = ref,
78+
};
79+
7580
/**
7681
* Constructor.
7782
* @param object the object to modify.
@@ -92,7 +97,7 @@ export class KeyMapperController extends dat.controllers.Controller {
9297
this.domElement.appendChild(div);
9398

9499
// Render mapper
95-
ReactDOM.render(<KeyMapper onChange={(k) => object[property] = k} mappedKey={object[property]} />, div);
100+
ReactDOM.render(<KeyMapper ref={this._refHandler.getKeyMapper} onChange={(k) => object[property] = k} mappedKey={object[property]} />, div);
96101
}
97102

98103
/**
@@ -103,6 +108,14 @@ export class KeyMapperController extends dat.controllers.Controller {
103108
this._title.innerHTML = name;
104109
return this;
105110
}
111+
112+
/**
113+
* Updates the current display of the controller.
114+
*/
115+
public updateDisplay(): KeyMapperController {
116+
this._keyMapper?.setState({ mappedKey: this.object[this.property] });
117+
return this;
118+
}
106119
}
107120

108121
dat.GUI.prototype.addKeyMapper = function(object: any, property: string): KeyMapperController {

src/renderer/editor/gui/augmentations/vector.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class VectorController extends dat.controllers.Controller {
1313
private __onChange: (v: IVector) => void;
1414
private __onFinishChange: (v: IVector) => void;
1515

16+
private _numberControllers: dat.GUIController[] = [];
17+
1618
/**
1719
* Constructor.
1820
* @param title defines the title of the controller.
@@ -68,6 +70,14 @@ export class VectorController extends dat.controllers.Controller {
6870
return this;
6971
}
7072

73+
/**
74+
* Updates the current display of the controller.
75+
*/
76+
public updateDisplay(): VectorController {
77+
this._numberControllers.forEach((c) => c.updateDisplay());
78+
return this;
79+
}
80+
7181
/**
7282
* Adds a new number controller.
7383
*/
@@ -88,6 +98,8 @@ export class VectorController extends dat.controllers.Controller {
8898
c.domElement.style.width = "calc(100% - 25px)";
8999
c.onChange(() => this.__onChange && this.__onChange(this.vector));
90100
c.onFinishChange(() => this.__onFinishChange && this.__onFinishChange(this.vector));
101+
102+
this._numberControllers.push(c);
91103
dummyController.domElement.appendChild(c.domElement);
92104
}
93105
}

src/renderer/windows/index.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
import { ipcRenderer, remote } from "electron";
2+
23
import { IPCResponses, IPCRequests } from "../../shared/ipc";
4+
import { Undefinable } from "../../shared/types";
35

46
import * as React from "react";
57
import * as ReactDOM from "react-dom";
68

9+
export interface IWindowedPluginInitialization {
10+
/**
11+
* Defines the name of the plugin to require.
12+
*/
13+
name: string;
14+
/**
15+
* Defines the option array of arguments to pass the the ".init" function of the plugin.
16+
*/
17+
args?: Undefinable<any[]>;
18+
}
19+
720
export default class WindowedPlugin {
21+
private _ref: any;
22+
private _refHandler = {
23+
getRef: (ref: any) => this._ref = ref,
24+
}
825
/**
926
* Constructor.
1027
*/
11-
constructor() {
28+
public constructor() {
1229
this._init();
1330
}
1431

@@ -22,16 +39,18 @@ export default class WindowedPlugin {
2239
});
2340

2441
// Get plugin name
25-
const pluginName = await new Promise<string>((resolve) => {
26-
ipcRenderer.once(IPCResponses.SendWindowMessage, (_, data) => data.id === "pluginName" && resolve(data.name));
42+
const data = await new Promise<any>((resolve) => {
43+
ipcRenderer.once(IPCResponses.SendWindowMessage, (_, data) => data.id === "pluginName" && resolve(data));
2744
});
2845

2946
// Load plugin!
3047
try {
31-
const plugin = require(`./${pluginName}`);
48+
const plugin = require(`./${data.name}`);
3249
document.title = plugin.title;
3350

34-
ReactDOM.render(<plugin.default />, document.getElementById("BABYLON-EDITOR-PLUGIN"));
51+
ReactDOM.render(<plugin.default ref={this._refHandler.getRef} />, document.getElementById("BABYLON-EDITOR-PLUGIN"), () => {
52+
this._ref?.init?.apply(this._ref, data.args ?? []);
53+
});
3554
ipcRenderer.send(IPCResponses.SendWindowMessage, -1, { id: "pluginName" });
3655
} catch (e) {
3756
/* Catch silently */

src/renderer/windows/material-viewer/index.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { ipcRenderer } from "electron";
2-
3-
import { IPCRequests } from "../../../shared/ipc";
4-
51
import { Engine, Scene, ArcRotateCamera, Vector3, Material, Mesh, Texture, HemisphericLight } from "babylonjs";
62
import "babylonjs-materials";
73

@@ -21,8 +17,6 @@ export default class MeshViewerWindow extends React.Component {
2117
*/
2218
public constructor(props: any) {
2319
super(props);
24-
25-
this._bindEvents();
2620
}
2721

2822
/**
@@ -61,10 +55,11 @@ export default class MeshViewerWindow extends React.Component {
6155
}
6256

6357
/**
64-
* Binds the ipc events.
58+
* Inits the plugin.
59+
* @param data the initialization data containing the material definition etc.
6560
*/
66-
private _bindEvents(): void {
67-
ipcRenderer.on(IPCRequests.SendWindowMessage, (_ , data) => data.id === "init" && this._parseMaterial(data.rootUrl, data.json, data.environmentTexture));
61+
public init(data: { rootUrl: string, json: any, environmentTexture: any }): void {
62+
this._parseMaterial(data.rootUrl, data.json, data.environmentTexture);
6863
}
6964

7065
/**

src/renderer/windows/mesh-viewer/index.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { ipcRenderer } from "electron";
2-
3-
import { IPCRequests } from "../../../shared/ipc";
4-
51
import { Engine, Scene, ArcRotateCamera, Vector3, SceneLoader, PointLight, Mesh, Texture, PBRMaterial, CubeTexture, Color3 } from "babylonjs";
62
import { GridMaterial } from "babylonjs-materials";
73
import "babylonjs-loaders";
@@ -21,8 +17,6 @@ export default class MeshViewerWindow extends React.Component {
2117
*/
2218
public constructor(props: any) {
2319
super(props);
24-
25-
this._bindEvents();
2620
}
2721

2822
/**
@@ -55,10 +49,11 @@ export default class MeshViewerWindow extends React.Component {
5549
}
5650

5751
/**
58-
* Binds the ipc events.
52+
* Inits the plugin.
53+
* @param data the initialization data containing the mesh to load etc.
5954
*/
60-
private _bindEvents(): void {
61-
ipcRenderer.on(IPCRequests.SendWindowMessage, (_ , data) => data.id === "init" && this._loadMesh(data.rootUrl, data.name));
55+
public init(data: { rootUrl: string, name: string }): void {
56+
this._loadMesh(data.rootUrl, data.name);
6257
}
6358

6459
/**

src/renderer/windows/node-material-editor/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export default class NodeMaterialEditorWindow extends React.Component {
3838
return <div id="node-material-editor" style={{ width: "100%", height: "100%" }}></div>;
3939
}
4040

41+
/**
42+
* Inits the plugin.
43+
* @param data the initialization data containing the material definition etc.
44+
*/
45+
public init(data: { json: any, lights: any[], editorData: any }): void {
46+
this._setMaterial(data.json, data.editorData, data.lights);
47+
}
48+
4149
/**
4250
* Binds the ipc events.
4351
*/

0 commit comments

Comments
 (0)