-
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
Showing
23 changed files
with
201 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,5 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
*.bat |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ export interface IGameRenderer { | |
getCamera(); | ||
|
||
getShadowGenerator(); | ||
getCharacterGallery(); | ||
|
||
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
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,37 @@ | ||
import { IGameRenderer } from '../'; | ||
import { ICharacterGalleryItem, CharacterGalleryItem } from '../model/'; | ||
|
||
export class CharacterGalleryManager { | ||
private _gameRenderer: IGameRenderer; | ||
private _models = { | ||
rabbit: new CharacterGalleryItem( | ||
'assets/models/Rabbit/', | ||
'Rabbit.babylon', | ||
'babylon', | ||
{ | ||
stand: [0, 30], | ||
run: [31, 54] | ||
} | ||
), | ||
dude: new CharacterGalleryItem( | ||
'assets/models/Dude/', | ||
'Dude.babylon', | ||
'babylon', | ||
{ | ||
stand: [0, 30], | ||
run: [31, 54] | ||
} | ||
) | ||
} | ||
constructor(gameRenderer: IGameRenderer) { | ||
this._gameRenderer = gameRenderer; | ||
} | ||
|
||
getModelByName(name: string): ICharacterGalleryItem { | ||
if (this._models[name]) { | ||
return this._models[name]; | ||
} else { | ||
throw new Error(`Cannot find model ${name}!`); | ||
} | ||
} | ||
} |
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 @@ | ||
export * from './CharacterGalleryManager'; |
6 changes: 6 additions & 0 deletions
6
src/app/shared/engine/model/CharacterGalleryItem.interface.ts
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 ICharacterGalleryItem { | ||
modelPath: string; | ||
modelFileName: string; | ||
modelType: string; | ||
animations: any; | ||
} |
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 { ICharacterGalleryItem } from './CharacterGalleryItem.interface'; | ||
|
||
export class CharacterGalleryItem implements ICharacterGalleryItem { | ||
modelPath = ''; | ||
modelFileName = ''; | ||
modelType = 'babylon'; | ||
animations = {}; | ||
|
||
constructor(modelPath: string, modelFileName: string, modelType: string = 'babylon', animations = {}) { | ||
this.modelPath = modelPath; | ||
this.modelFileName = modelFileName; | ||
this.modelType = modelType; | ||
this.animations = animations; | ||
} | ||
} |
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 './CharacterGalleryItem.interface'; | ||
export * from './CharacterGalleryItem'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
export interface IBaseModel { | ||
moveForward(); | ||
moveBackward(); | ||
rotateLeft(angle); | ||
rotateRight(angle); | ||
buildFromUrl(modelName: string, path: string, modelFileName: string, callback?: Function); | ||
buildFromGallery(modelName, callback?: Function); | ||
getModel(); | ||
} |
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,85 @@ | ||
import { Vector3, SceneLoader, MeshBuilder } from 'babylonjs'; | ||
|
||
import { IGameRenderer } from '../'; | ||
import { BaseModel } from './BaseModel'; | ||
|
||
export class Character extends BaseModel { | ||
|
||
protected _model = null; | ||
protected _modelhead = null; | ||
protected _animations = {}; | ||
protected _skeletons = []; | ||
|
||
public animationSpeed = 0.8; | ||
|
||
constructor(gameRenderer: IGameRenderer) { | ||
super(gameRenderer); | ||
this._gameRenderer = gameRenderer; | ||
this._modelhead = MeshBuilder.CreateSphere('', { segments: 16, diameter: 0.01 }, this._gameRenderer.getScene()); | ||
|
||
this._modelhead.position.y = 6; | ||
|
||
|
||
} | ||
|
||
getModel() { | ||
return this._model; | ||
} | ||
|
||
getModelHead() { | ||
return this._modelhead; | ||
} | ||
|
||
public buildFromUrl(modelName: string, path: string, modelFileName: string, callback?: Function) { | ||
const scene = this._gameRenderer.getScene(); | ||
SceneLoader.ImportMesh(modelName, path, modelFileName, scene, | ||
(newMeshes, particleSystems, skeletons) => { | ||
this.importMeshSuccess(newMeshes, particleSystems, skeletons); | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
|
||
public buildFromGallery(modelName, callback?: Function) { | ||
const model = this._gameRenderer.getCharacterGallery().getModelByName(modelName); | ||
console.log(model); | ||
if (model) { | ||
this._animations = model.animations; | ||
const scene = this._gameRenderer.getScene(); | ||
SceneLoader.ImportMesh('', model.modelPath, model.modelFileName, scene, | ||
(newMeshes, particleSystems, skeletons) => { | ||
this.importMeshSuccess(newMeshes, particleSystems, skeletons); | ||
if (callback) { | ||
callback(); | ||
} | ||
}); | ||
} | ||
} | ||
switchToAnimation(animationName) { | ||
if (this._animations[animationName]) { | ||
this._gameRenderer.getScene().beginAnimation( | ||
this._skeletons[0], | ||
this._animations[animationName][0], | ||
this._animations[animationName][1], | ||
true, | ||
this.animationSpeed | ||
); | ||
} | ||
} | ||
|
||
private importMeshSuccess(newMeshes, particleSystems, skeletons) { | ||
try { | ||
if (newMeshes.length > 0) { | ||
const scene = this._gameRenderer.getScene(); | ||
this._skeletons = skeletons; | ||
this._model = newMeshes[0]; | ||
this._model.scaling = new Vector3(0.1, 0.1, 0.1); | ||
this._gameRenderer.getShadowGenerator().getShadowMap().renderList.push(this._model); | ||
// scene.beginAnimation(skeletons[0], 0, 500, true, 0.8); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
} |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.