Skip to content

Commit 91ba691

Browse files
yuripourrejulien-moreau
authored andcommitted
Add model to the menu
1 parent 0d64622 commit 91ba691

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

css/svg/model.svg

Lines changed: 2 additions & 0 deletions
Loading

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export class MainToolbar extends React.Component<IToolbarProps, IToolbarState> {
274274
<MenuItem text="Sphere" icon={<Icon src="circle.svg" />} onClick={() => this._onAddMeshClicked("sphere", parent)} />
275275
<MenuItem text="Cylinder" icon={<Icon src="cylinder.svg" />} onClick={() => this._onAddMeshClicked("cylinder", parent)} />
276276
<MenuItem text="Plane" icon={<Icon src="square-full.svg" />} onClick={() => this._onAddMeshClicked("plane", parent)} />
277+
<MenuItem text="Model" icon={<Icon src="model.svg" />} onClick={() => this._onAddMeshClicked("model", parent)} />
277278
<MenuDivider />
278279
<MenuItem text="Ground" icon={<Icon src="vector-square.svg" />} onClick={() => this._onAddMeshClicked("ground", parent)} />
279280
<MenuItem text="Terrain From Height Map..." icon={<Icon src="terrain.svg" style={{ filter: "none" }} />} onClick={() => this._onAddMeshClicked("heightmap", parent)} />
@@ -482,6 +483,7 @@ export class MainToolbar extends React.Component<IToolbarProps, IToolbarState> {
482483
case "sphere": mesh = SceneFactory.AddSphere(this._editor); break;
483484
case "cylinder": mesh = SceneFactory.AddCynlinder(this._editor); break;
484485
case "plane": mesh = SceneFactory.AddPlane(this._editor); break;
486+
case "model": mesh = await SceneFactory.AddModel(this._editor); break;
485487

486488
case "ground": mesh = SceneFactory.AddGround(this._editor); break;
487489
case "heightmap": mesh = await SceneFactory.AddTerrainFromHeightMap(this._editor); break;

src/renderer/editor/scene/factory.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { extname, join } from "path";
22
import { writeJSON } from "fs-extra";
33
import filenamify from "filenamify";
4+
import "@babylonjs/loaders";
45

56
import {
67
Mesh,
@@ -9,6 +10,7 @@ import {
910
Vector3,
1011
FreeCamera, ArcRotateCamera,
1112
Texture, VertexData, Color3, ReflectionProbe, TargetCamera,
13+
SceneLoader,
1214
} from "babylonjs";
1315
import { SkyMaterial } from "babylonjs-materials";
1416

@@ -79,6 +81,20 @@ export class SceneFactory {
7981
return this._ConfigureNode(Mesh.CreateGround("New Ground", 512, 512, 32, editor.scene!, true) as GroundMesh);
8082
}
8183

84+
/**
85+
* Adds a new ground to the scene.
86+
* @param editor the editor reference.
87+
*/
88+
public static async AddModel(editor: Editor): Promise<Mesh> {
89+
const fileObject = await Tools.ShowNativeOpenFileDialog();
90+
if (!fileObject) {
91+
throw new Error("Can't create model with no file selected");
92+
}
93+
94+
const scene = await SceneLoader.ImportMeshAsync("", "", fileObject, editor.scene!, null, extname(fileObject.name));
95+
return this._ConfigureNode(scene.meshes[0] as Mesh);
96+
}
97+
8298
/**
8399
*
84100
* @param editor the editor reference.

0 commit comments

Comments
 (0)