Skip to content

Commit

Permalink
Merge pull request #113 from BabylonJS/feature/prefab-editor
Browse files Browse the repository at this point in the history
Feature/prefab editor
  • Loading branch information
julien-moreau committed Dec 13, 2018
2 parents 05da383 + 7976351 commit 7384343
Show file tree
Hide file tree
Showing 35 changed files with 20,766 additions and 20,751 deletions.
40,495 changes: 19,947 additions & 20,548 deletions assets/typings/babylon.d.ts

Large diffs are not rendered by default.

193 changes: 106 additions & 87 deletions babylonjs-editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ declare module 'babylonjs-editor' {
import CodeProjectEditorFactory from 'babylonjs-editor/editor/project/project-code-editor';
import SceneManager from 'babylonjs-editor/editor/scene/scene-manager';
import SceneFactory from 'babylonjs-editor/editor/scene/scene-factory';
import PrefabAssetComponent from 'babylonjs-editor/editor/prefabs/asset-component';
import { Prefab, PrefabNodeType } from 'babylonjs-editor/editor/prefabs/prefab';
export default Editor;
export { Editor, Tools, UndoRedo, ThemeSwitcher, ThemeType, IStringDictionary, INumberDictionary, IDisposable, EditorPlugin, Layout, Toolbar, List, Grid, GridRow, Picker, Graph, GraphNode, Window, CodeEditor, Form, Edition, Tree, ContextMenuItem, TreeNode, Dialog, ContextMenu, ContextMenuOptions, ResizableLayout, ComponentConfig, ItemConfigType, AbstractEditionTool, ProjectRoot, CodeProjectEditorFactory, SceneManager, SceneFactory };
export { Editor, Tools, UndoRedo, ThemeSwitcher, ThemeType, IStringDictionary, INumberDictionary, IDisposable, EditorPlugin, Layout, Toolbar, List, Grid, GridRow, Picker, Graph, GraphNode, Window, CodeEditor, Form, Edition, Tree, ContextMenuItem, TreeNode, Dialog, ContextMenu, ContextMenuOptions, ResizableLayout, ComponentConfig, ItemConfigType, AbstractEditionTool, ProjectRoot, CodeProjectEditorFactory, SceneManager, SceneFactory, PrefabAssetComponent, Prefab, PrefabNodeType };
}

declare module 'babylonjs-editor/editor/editor' {
Expand Down Expand Up @@ -76,6 +78,7 @@ declare module 'babylonjs-editor/editor/editor' {
projectFileName: string;
_showReloadDialog: boolean;
static LayoutVersion: string;
static EditorVersion: string;
/**
* Constructor
* @param scene: a scene to edit. If undefined, a default scene will be created
Expand Down Expand Up @@ -734,6 +737,10 @@ declare module 'babylonjs-editor/editor/gui/code' {
* Focus the editor
*/
focus(): void;
/**
* Disposes the editor
*/
dispose(): void;
/**
* Builds the code editor
* @param parentId the parent id of the editor
Expand Down Expand Up @@ -850,6 +857,7 @@ declare module 'babylonjs-editor/editor/gui/edition' {
* @param parent the parent folder
* @param name the name of the folder
* @param color the color reference
* @param callback called on the user changes the color
*/
addColor(parent: dat.GUI, name: string, color: Color3 | Color4, callback?: () => void): dat.GUI;
/**
Expand Down Expand Up @@ -1326,6 +1334,7 @@ declare module 'babylonjs-editor/editor/typings/project' {
customMetadatas?: IStringDictionary<any>;
gui: any[];
assets: any;
filesList?: string[];
}
}

Expand Down Expand Up @@ -1511,6 +1520,97 @@ declare module 'babylonjs-editor/editor/scene/scene-factory' {
}
}

declare module 'babylonjs-editor/editor/prefabs/asset-component' {
import { Node, AbstractMesh, PickingInfo, Engine } from 'babylonjs';
import Editor from 'babylonjs-editor/editor/editor';
import { IAssetComponent, AssetElement, AssetContextMenu } from 'babylonjs-editor/extensions/typings/asset';
import { Prefab, PrefabNodeType } from 'babylonjs-editor/editor/prefabs/prefab';
export default class PrefabAssetComponent implements IAssetComponent {
editor: Editor;
id: string;
assetsCaption: string;
size: number;
datas: AssetElement<Prefab>[];
previewCanvas: HTMLCanvasElement;
previewEngine: Engine;
/**
* Constructor
* @param editor the editor reference
*/
constructor(editor: Editor);
/**
* Creates a new prefab
* @param sourceMesh the source mesh for the new prefab asset. Can be a single mesh or a root mesh
*/
createPrefab(sourceNode: Node): Promise<AssetElement<Prefab>>;
/**
* Returns the asset containing the given node instance reference
* @param node the node reference stored into the prefab instances
*/
getAssetFromNode(node: PrefabNodeType): AssetElement<Prefab>;
/**
* On the user adds a new prefab asset
* @param asset the asset to add in the collection
*/
onAddAsset(asset: AssetElement<Prefab>): void;
/**
* On the user removes a prefab from his library
* @param asset the asset to remove
*/
onRemoveAsset(asset: AssetElement<Prefab>): void;
/**
* On the user drops an asset in the scene
* @param targetMesh the mesh under the pointer
* @param asset the asset being dropped
* @param pickInfo the pick info once the user dropped the asset
*/
onDragAndDropAsset(targetMesh: AbstractMesh, asset: AssetElement<Prefab>, pickInfo: PickingInfo): void;
/**
* On the user saves the editor project
*/
onSerializeAssets(): AssetElement<Prefab>[];
/**
* On the user loads the editor project
* @param data the previously saved data
*/
onParseAssets(data: AssetElement<Prefab>[]): void;
/**
* On the assets panel requires the assets stored in this
* asset component
*/
onGetAssets(): Promise<AssetElement<Prefab>[]>;
/**
* On the user wants to show the context menu on the asset
*/
onContextMenu(): AssetContextMenu[];
/**
* Builds the instances of the given asset
* @param data the asset's data
*/
buildInstances(data: AssetElement<Prefab>[]): number;
/**
* Sets all the instances serializable or not
* @param serializable if the instances are serializable
*/
setSerializable(serializable: boolean): void;
}
}

declare module 'babylonjs-editor/editor/prefabs/prefab' {
import { InstancedMesh, SpotLight, PointLight, DirectionalLight, Mesh, ParticleSystem } from 'babylonjs';
import { IStringDictionary } from 'babylonjs-editor/editor/typings/typings';
export type PrefabNodeType = SpotLight | PointLight | DirectionalLight | InstancedMesh | ParticleSystem;
export interface Prefab {
isPrefab: boolean;
nodes: string[];
nodeIds: string[];
instances: IStringDictionary<any[]>;
sourceNodes?: (Mesh | PrefabNodeType)[];
sourceNode?: Mesh | PrefabNodeType;
sourceInstances?: IStringDictionary<PrefabNodeType[]>;
}
}

declare module 'babylonjs-editor/editor/core' {
import { Engine, Scene, Observable } from 'babylonjs';
import { AdvancedDynamicTexture } from 'babylonjs-gui';
Expand Down Expand Up @@ -1877,6 +1977,11 @@ declare module 'babylonjs-editor/editor/components/assets' {
* @param asset the source asset
*/
getAssetPreviewData(asset: AssetElement<any>): AssetPreviewData;
/**
* Adds a new asset to the assets store
* @param component the component used to add an asset
*/
addAsset(component?: IAssetComponent): Promise<AssetElement<any>>;
/**
* Returns the drag end event function
* @param component the source component
Expand Down Expand Up @@ -2108,77 +2213,6 @@ declare module 'babylonjs-editor/extensions/typings/asset' {
}
}

declare module 'babylonjs-editor/editor/prefabs/asset-component' {
import { Node, AbstractMesh, PickingInfo, Engine } from 'babylonjs';
import Editor from 'babylonjs-editor/editor/editor';
import { IAssetComponent, AssetElement, AssetContextMenu } from 'babylonjs-editor/extensions/typings/asset';
import { Prefab } from 'babylonjs-editor/editor/prefabs/prefab';
export default class PrefabAssetComponent implements IAssetComponent {
editor: Editor;
id: string;
assetsCaption: string;
size: number;
datas: AssetElement<Prefab>[];
previewCanvas: HTMLCanvasElement;
previewEngine: Engine;
/**
* Constructor
* @param editor the editor reference
*/
constructor(editor: Editor);
/**
* Creates a new prefab
* @param sourceMesh the source mesh for the new prefab asset. Can be a single mesh or a root mesh
*/
createPrefab(sourceNode: Node): Promise<AssetElement<Prefab>>;
/**
* On the user adds a new prefab asset
* @param asset the asset to add in the collection
*/
onAddAsset(asset: AssetElement<Prefab>): void;
/**
* On the user removes a prefab from his library
* @param asset the asset to remove
*/
onRemoveAsset(asset: AssetElement<Prefab>): void;
/**
* On the user drops an asset in the scene
* @param targetMesh the mesh under the pointer
* @param asset the asset being dropped
* @param pickInfo the pick info once the user dropped the asset
*/
onDragAndDropAsset(targetMesh: AbstractMesh, asset: AssetElement<Prefab>, pickInfo: PickingInfo): void;
/**
* On the user saves the editor project
*/
onSerializeAssets(): AssetElement<Prefab>[];
/**
* On the user loads the editor project
* @param data the previously saved data
*/
onParseAssets(data: AssetElement<Prefab>[]): void;
/**
* On the assets panel requires the assets stored in this
* asset component
*/
onGetAssets(): Promise<AssetElement<Prefab>[]>;
/**
* On the user wants to show the context menu on the asset
*/
onContextMenu(): AssetContextMenu[];
/**
* Builds the instances of the given asset
* @param data the asset's data
*/
buildInstances(data: AssetElement<Prefab>[]): number;
/**
* Sets all the instances serializable or not
* @param serializable if the instances are serializable
*/
setSerializable(serializable: boolean): void;
}
}

declare module 'babylonjs-editor/extensions/extension' {
import { Scene } from 'babylonjs';
import { IExtension } from 'babylonjs-editor/extensions/typings/extension';
Expand Down Expand Up @@ -2209,21 +2243,6 @@ declare module 'babylonjs-editor/extensions/extension' {
}
}

declare module 'babylonjs-editor/editor/prefabs/prefab' {
import { InstancedMesh, SpotLight, PointLight, DirectionalLight, Mesh, ParticleSystem } from 'babylonjs';
import { IStringDictionary } from 'babylonjs-editor/editor/typings/typings';
export type PrefabNodeType = SpotLight | PointLight | DirectionalLight | InstancedMesh | ParticleSystem;
export interface Prefab {
isPrefab: boolean;
nodes: string[];
nodeIds: string[];
instances: IStringDictionary<any[]>;
sourceNodes?: (Mesh | PrefabNodeType)[];
sourceNode?: Mesh | PrefabNodeType;
sourceInstances?: IStringDictionary<PrefabNodeType[]>;
}
}

declare module 'babylonjs-editor/extensions/typings/extension' {
import { Scene } from 'babylonjs';
import { IAssetComponent } from 'babylonjs-editor/extensions/typings/asset';
Expand Down
35 changes: 29 additions & 6 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, BrowserWindow, globalShortcut, Menu, MenuItemConstructorOptions } from 'electron';
import WebServer from './web-server';
import ScenePreview from './preview-scene';
import Settings from './settings/settings';

export default class EditorApp {
// Static members
Expand Down Expand Up @@ -34,6 +35,8 @@ export default class EditorApp {
* Creates a new window
*/
public static CreateWindow (): Promise<void> {
Settings.OpenedFile = process.argv[1];

return new Promise<void>((resolve) => {
this.Window = new BrowserWindow({
width: 800,
Expand Down Expand Up @@ -106,12 +109,32 @@ export default class EditorApp {
}

/**
* Events
* Make single instance
*/
app.on("window-all-closed", async () => {
if (process.platform !== "darwin")
app.quit();
const shouldQuit = app.makeSingleInstance((argv, wd) => {
if (EditorApp.Window) {
if (EditorApp.Window.isMinimized())
EditorApp.Window.restore();

EditorApp.Window.focus();

const filename = argv[1];
if (filename !== Settings.OpenedFile) {
Settings.OpenedFile = filename;
EditorApp.Window.reload();
}
}
});

app.on("ready", () => EditorApp.Create());
app.on("activate", () => EditorApp.Window || EditorApp.Create());
/**
* Events
*/
if (!shouldQuit) {
app.on("window-all-closed", async () => {
if (process.platform !== "darwin")
app.quit();
});

app.on("ready", () => EditorApp.Create());
app.on("activate", () => EditorApp.Window || EditorApp.Create());
}
4 changes: 3 additions & 1 deletion electron/routes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export default class StorageRouter {
const filename = ctx.query.path;

ctx.type = path.extname(filename);
ctx.body = fs.createReadStream(filename);
ctx.body = fs.createReadStream(filename, {
encoding: 'utf-8'
});
});
}

Expand Down
27 changes: 27 additions & 0 deletions electron/routes/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { BrowserWindow } from 'electron';
import * as Koa from 'koa';
import * as KoaRouter from 'koa-router';

import Settings from '../settings/settings';

export default class ToolsRouter {
// Public members
public router: KoaRouter;
Expand All @@ -22,6 +24,9 @@ export default class ToolsRouter {
this.getVersion();
this.getInstallerPath();

this.getOpenedFile();
this.setOpenedFile();

this.application.use(this.router.routes());
}

Expand Down Expand Up @@ -67,4 +72,26 @@ export default class ToolsRouter {
}
});
}

/**
* Returns the opened file path
*/
protected getOpenedFile (): void {
this.router.get('/openedFile', async (ctx, next) => {
ctx.body = Settings.OpenedFile;
})
}

/**
* Sets the opened file path
*/
protected setOpenedFile (): void {
this.router.post('/openedFile', async (ctx, next) => {
Settings.OpenedFile = ctx.body;

ctx.body = {
message: 'success'
};
});
}
}
6 changes: 6 additions & 0 deletions electron/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class Settings {
/**
* The opened file path using the OS file explorer
*/
public static OpenedFile: string = null;
}
2 changes: 1 addition & 1 deletion index-debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"particles-creator": "./build/src/tools/particles-creator/index.js",
"metadatas": "./build/src/tools/metadata/editor.js",
"notes": "./build/src/tools/notes/notes.js",
"prefab-editor": "./build/src/tools/prefabs/editor.js",

"post-processes": "./build/src/extensions/post-process/post-processes.js"
},
Expand Down Expand Up @@ -94,7 +95,6 @@
// Run editor
var editor = window.editor = new e.default();
editor.run();
editor.createDefaultScene();
});
</script>

Expand Down
Loading

0 comments on commit 7384343

Please sign in to comment.