Skip to content

Commit

Permalink
Updated Interop Version to 0.2.3
Browse files Browse the repository at this point in the history
Created an demo page showing the usage of features from 0.2.3.
  • Loading branch information
canhorn committed Jul 23, 2021
1 parent 61baaa9 commit 2958120
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/mesh/builder"

<h1>Mesh Builder!</h1>

<div>
<canvas id="game-window" style="width:100%"></canvas>
</div>
126 changes: 126 additions & 0 deletions Sample/EventHorizon.Blazor.BabylonJS/Pages/MeshBuilderExample.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
namespace EventHorizon.Blazor.BabylonJS.Pages
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BABYLON;
using EventHorizon.Blazor.BabylonJS.Model;
using EventHorizon.Blazor.Interop.Callbacks;

public partial class MeshBuilderExample : IDisposable
{
private Engine _engine;
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
CreateScene();
}
}

public void Dispose()
{
_engine?.dispose();
}

public void CreateScene()
{
var canvas = Canvas.GetElementById(
"game-window"
);
var engine = new Engine(
canvas,
true
);
var scene = new Scene(
engine
);
var light1 = new HemisphericLight(
"HemisphericLight",
new Vector3(1, 1, 0),
scene
);

var columns = 6m;
var rows = 1m;

var faceUV = new Vector4[6];

for (var i = 0; i < 6; i++)
{
faceUV[i] = new Vector4(
i / columns,
0,
(i + 1) / columns,
1m / rows
);
}

var mat = new StandardMaterial(
"mat",
scene
);
var texture = new Texture(
scene,
"https://assets.babylonjs.com/environments/numbers.jpg"
);
mat.diffuseTexture = texture;

var alpha = 1;
var red = new Color4(
1,
0,
0,
alpha
);
var blue = new Color4(
0,
0,
1,
alpha
);
var green = new Color4(
0,
1,
0,
alpha
);

var options = new
{
faceUV,
wrap = true,
width = 1,
height = 2,
depth = 3,
faceColors = new List<Color4> { green, green, green, green, blue, red }
};

var box = MeshBuilder.CreateBox(
"box",
options,
scene
);
box.material = mat;

var camera = new ArcRotateCamera(
"ArcRotateCamera",
(decimal)(Math.PI / 2),
(decimal)(Math.PI / 4),
10,
new Vector3(0, 1, 0),
scene
);
scene.activeCamera = camera;
camera.attachControl(
false
);

engine.runRenderLoop(new ActionCallback(
() => Task.Run(() => scene.render(true, false))
));

_engine = engine;
}
}
}
4 changes: 2 additions & 2 deletions Sample/EventHorizon.Blazor.BabylonJS/Pages/MeshExample.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page "/mesh"
@page "/mesh/gltf"

<h1>Mesh Loaded! Generated Code!</h1>
<h1>glTF Mesh Loaded!</h1>

<div>
<canvas id="game-window" style="width:100%"></canvas>
Expand Down
25 changes: 12 additions & 13 deletions Sample/EventHorizon.Blazor.BabylonJS/Pages/MeshExample.razor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BABYLON;
using EventHorizon.Blazor.BabylonJS.Model;
using EventHorizon.Blazor.Interop.Callbacks;

namespace EventHorizon.Blazor.BabylonJS.Pages
{
using System;
using System.Threading.Tasks;
using BABYLON;
using EventHorizon.Blazor.BabylonJS.Model;
using EventHorizon.Blazor.Interop.Callbacks;

public partial class MeshExample : IDisposable
{
private Engine _engine;
Expand Down Expand Up @@ -54,12 +52,13 @@ public void CreateScene()
),
scene
);

var house = SceneLoader.ImportMesh(
null,
"assets/",
"House.gltf",
scene
);
null,
"assets/",
"House.gltf",
scene
);
var freeCamera = new FreeCamera(
"FreeCamera",
new Vector3(
Expand Down
9 changes: 7 additions & 2 deletions Sample/EventHorizon.Blazor.BabylonJS/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="mesh">
<span class="oi oi-home" aria-hidden="true"></span> Mesh
<NavLink class="nav-link" href="mesh/gltf">
<span class="oi oi-home" aria-hidden="true"></span> Mesh glTF
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="mesh/builder">
<span class="oi oi-home" aria-hidden="true"></span> Mesh Builder
</NavLink>
</li>
<li class="nav-item px-3">
Expand Down
Loading

0 comments on commit 2958120

Please sign in to comment.