-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created an demo page showing the usage of features from 0.2.3.
- Loading branch information
Showing
8 changed files
with
391 additions
and
89 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Sample/EventHorizon.Blazor.BabylonJS/Pages/MeshBuilderExample.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
Sample/EventHorizon.Blazor.BabylonJS/Pages/MeshBuilderExample.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.