-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaedc94
commit 395929c
Showing
13 changed files
with
220 additions
and
55 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
html, | ||
body { | ||
overflow: hidden; | ||
width: 100vw; | ||
height: 100vh; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#renderCanvas { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100vw; | ||
height: 100vh; | ||
touch-action: none; | ||
} |
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 |
---|---|---|
@@ -1,3 +1 @@ | ||
<h1> | ||
{{title}} | ||
</h1> | ||
<canvas id="renderCanvas"></canvas> |
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 |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, AfterViewInit } from '@angular/core'; | ||
import { IGameRenderer, GameRenderer } from './shared/engine'; | ||
|
||
import { IBaseModel, Character } from './shared/engine/models'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
title = 'app works!'; | ||
export class AppComponent implements AfterViewInit { | ||
private _game: IGameRenderer | ||
private _currentCharacter: IBaseModel; | ||
ngAfterViewInit() { | ||
this._game = new GameRenderer('renderCanvas'); | ||
this._game.createScene(); | ||
|
||
this._game.animate(); | ||
this.createTestGame(); | ||
} | ||
|
||
createTestGame() { | ||
this._currentCharacter = new Character(this._game, 'currentCharacter', '/assets/Rabbit/', 'Rabbit.babylon'); | ||
} | ||
} |
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,15 @@ | ||
import { | ||
Engine, Scene, FollowCamera, Light, | ||
Vector3, HemisphericLight, MeshBuilder | ||
} from 'babylonjs'; | ||
|
||
export interface IGameRenderer { | ||
createScene(); | ||
getScene(): Scene; | ||
getCamera(); | ||
|
||
getShadowGenerator(); | ||
|
||
animate(); | ||
|
||
} |
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,63 @@ | ||
import { | ||
Engine, Scene, FollowCamera, Light, DirectionalLight, IShadowLight, | ||
Vector3, HemisphericLight, MeshBuilder, ShadowGenerator | ||
} from 'babylonjs'; | ||
|
||
|
||
import { IGameRenderer } from './GameRenderer.interface'; | ||
|
||
|
||
export class GameRenderer implements IGameRenderer { | ||
private _canvas: HTMLCanvasElement; | ||
private _engine: Engine; | ||
private _scene: Scene; | ||
private _camera: FollowCamera; | ||
private _light: IShadowLight; | ||
private _shadowGenerator: ShadowGenerator; | ||
constructor(canvasElement: string) { | ||
this._canvas = <HTMLCanvasElement>document.getElementById(canvasElement); | ||
this._engine = new Engine(this._canvas, true); | ||
} | ||
|
||
public createScene() { | ||
this._scene = new Scene(this._engine); | ||
|
||
this._camera = new FollowCamera('camera1', new Vector3(0, 5, -10), this._scene); | ||
|
||
this._camera.attachControl(this._canvas, true); | ||
|
||
this._light = new DirectionalLight('light1', new Vector3(0, 1, 0), this._scene); | ||
|
||
const sphere = MeshBuilder.CreateSphere('sphere1', { segments: 16, diameter: 2 }, this._scene); | ||
this._camera.lockedTarget = sphere; | ||
this._shadowGenerator = new BABYLON.ShadowGenerator(1024, this._light); | ||
|
||
sphere.position.y = 1; | ||
|
||
const ground = MeshBuilder.CreateGround('ground1', { width: 6, height: 6, subdivisions: 2 }, this._scene); | ||
} | ||
|
||
public getScene(): Scene { | ||
return this._scene; | ||
} | ||
|
||
public getCamera() { | ||
return this._camera; | ||
} | ||
|
||
public getShadowGenerator() { | ||
|
||
} | ||
|
||
public animate() { | ||
// run the render loop | ||
this._engine.runRenderLoop(() => { | ||
this._scene.render(); | ||
}); | ||
|
||
// the canvas/window resize event handler | ||
window.addEventListener('resize', () => { | ||
this._engine.resize(); | ||
}); | ||
} | ||
} |
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,2 @@ | ||
export * from './GameRenderer.interface'; | ||
export * from './GameRenderer'; |
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,6 @@ | ||
export interface IBaseModel { | ||
moveForward(); | ||
moveBackward(); | ||
rotateLeft(angle); | ||
rotateRight(angle); | ||
} |
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,23 @@ | ||
import { IBaseModel } from './BaseModel.interface'; | ||
import { IGameRenderer } from '../'; | ||
|
||
export class BaseModel implements IBaseModel { | ||
private _model = null; | ||
protected _gameRenderer = null; | ||
constructor(gameRenderer: IGameRenderer) { | ||
this._gameRenderer = gameRenderer; | ||
} | ||
|
||
moveForward() { | ||
|
||
} | ||
moveBackward() { | ||
|
||
} | ||
rotateLeft(angle) { | ||
|
||
} | ||
rotateRight(angle) { | ||
|
||
} | ||
} |
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,19 @@ | ||
import { IGameRenderer } from '../'; | ||
import { BaseModel } from './BaseModel'; | ||
|
||
export class Character extends BaseModel { | ||
constructor(gameRenderer: IGameRenderer, modelName: string, path: string, modelFileName: string) { | ||
super(gameRenderer); | ||
this._gameRenderer = gameRenderer; | ||
const scene = gameRenderer.getScene(); | ||
BABYLON.SceneLoader.ImportMesh(modelName, path, modelFileName, scene, | ||
function (newMeshes, particleSystems, skeletons) { | ||
this._model = newMeshes[1]; | ||
|
||
this._model.scaling = new BABYLON.Vector3(0.4, 0.4, 0.4); | ||
gameRenderer.getShadowGenerator().getShadowMap().renderList.push(this._model); | ||
|
||
scene.beginAnimation(skeletons[0], 0, 100, true, 0.8); | ||
}); | ||
} | ||
} |
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,3 @@ | ||
export * from './BaseModel.interface'; | ||
export * from './BaseModel'; | ||
export * from './Character'; |