where to store components

beta.r3js.org
Theunis J. Botha 2017-02-21 18:55:18 +01:00
parent 8c551eb936
commit 585c8e0d6f
14 changed files with 210 additions and 181 deletions

View File

@ -4,6 +4,7 @@
* @param name
* @param baseUrl
* @param path
* @param imageFactory
* @param games [GameLib.API.D3.Game]
* @param scenes
* @param cameras
@ -23,6 +24,7 @@ GameLib.D3.API.Editor = function(
name,
baseUrl,
path,
imageFactory,
games,
scenes,
cameras,
@ -40,6 +42,7 @@ GameLib.D3.API.Editor = function(
this,
GameLib.Component.COMPONENT_EDITOR,
{
'imageFactory' : GameLib.D3.ImageFactory,
'games' : [GameLib.D3.Game],
'scenes' : [GameLib.D3.Scene],
'cameras' : [GameLib.D3.Camera],
@ -74,6 +77,11 @@ GameLib.D3.API.Editor = function(
}
this.path = path;
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = null;
}
this.imageFactory = imageFactory;
if (GameLib.Utils.UndefinedOrNull(games)) {
games = [];
}
@ -141,6 +149,7 @@ GameLib.D3.API.Editor.prototype.constructor = GameLib.D3.API.Editor;
*/
GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
var apiImageFactory = null;
var apiGames = [];
var apiScenes = [];
var apiCameras = [];
@ -151,6 +160,10 @@ GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
var apiSystems = [];
var apiEntityManager = null;
if (objectEditor.imageFactory) {
apiImageFactory = GameLib.D3.API.ImageFactory.FromObjectImageFactory(objectEditor.imageFactory);
}
if (objectEditor.games) {
apiGames = objectEditor.games.map(
function(objectGame){
@ -224,6 +237,7 @@ GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
objectEditor.name,
objectEditor.baseUrl,
objectEditor.path,
apiImageFactory,
apiGames,
apiScenes,
apiCameras,

View File

@ -3,6 +3,7 @@
* @param id
* @param name
* @param gameType
* @param imageFactory
* @param width
* @param height
* @param baseUrl
@ -14,7 +15,6 @@
* @param systems
* @param viewports
* @param entityManager
* @param mouse
* @param parentEntity
* @constructor
*/
@ -23,9 +23,8 @@ GameLib.D3.API.Game = function(
name,
baseUrl,
path,
imageFactory,
gameType,
width,
height,
cameras,
composers,
viewports,
@ -33,21 +32,20 @@ GameLib.D3.API.Game = function(
renderTargets,
systems,
entityManager,
mouse,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_GAME,
{
'imageFactory' : GameLib.D3.ImageFactory,
'cameras' : [GameLib.D3.Camera],
'composers' : [GameLib.D3.Composer],
'viewports' : [GameLib.D3.Viewport],
'renderers' : [GameLib.D3.Renderer],
'renderTargets' : [GameLib.D3.RenderTarget],
'systems' : [GameLib.System],
'entityManager' : GameLib.EntityManager,
'mouse' : GameLib.Mouse
'entityManager' : GameLib.EntityManager
},
null,
parentEntity
@ -74,21 +72,16 @@ GameLib.D3.API.Game = function(
}
this.path = path;
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = null;
}
this.imageFactory = imageFactory;
if (GameLib.Utils.UndefinedOrNull(gameType)) {
gameType = GameLib.D3.Game.GAME_TYPE_VR_PONG;
}
this.gameType = gameType;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 800;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 600;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(cameras)) {
cameras = [];
}
@ -120,14 +113,10 @@ GameLib.D3.API.Game = function(
this.systems = systems;
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
entityManager = new GameLib.API.EntityManager();
entityManager = null;
}
this.entityManager = entityManager;
if (GameLib.Utils.UndefinedOrNull(mouse)) {
mouse = new GameLib.API.Mouse();
}
this.mouse = mouse;
};
GameLib.D3.API.Game.prototype = Object.create(GameLib.Component.prototype);
@ -140,6 +129,7 @@ GameLib.D3.API.Game.prototype.constructor = GameLib.D3.API.Game;
*/
GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
var apiImageFactory = null;
var apiCameras = [];
var apiComposers = [];
var apiViewports = [];
@ -148,7 +138,10 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
var apiSystems = [];
var apiEntityManager = null;
var apiMouse = null;
if (objectGame.imageFactory) {
apiImageFactory = GameLib.D3.API.ImageFactory.FromObjectImageFactory(objectGame.imageFactory);
}
if (objectGame.cameras) {
apiCameras = objectGame.cameras.map(
@ -202,18 +195,13 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectGame.entityManager);
}
if (objectGame.mouse) {
apiMouse = GameLib.API.Mouse.FromObjectMouse(objectGame.mouse);
}
return new GameLib.D3.API.Game(
objectGame.id,
objectGame.name,
objectGame.baseUrl,
objectGame.path,
apiImageFactory,
objectGame.gameType,
objectGame.width,
objectGame.height,
apiCameras,
apiComposers,
apiViewports,
@ -221,7 +209,6 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
apiRenderTargets,
apiSystems,
apiEntityManager,
apiMouse,
objectGame.parentEntity
);

View File

@ -2,8 +2,8 @@
* This component makes the parentEntity (ex. car) follow the path provided by the spline
* @param id String
* @param name String
* @param domElementId
* @param domContainerId
* @param domElement
* @param domContainer
* @param editor GameLib.D3.API.Editor
* @param camera
* @param widthOffset
@ -17,8 +17,8 @@
GameLib.D3.API.Input.Editor = function (
id,
name,
domElementId,
domContainerId,
domElement,
domContainer,
editor,
camera,
widthOffset,
@ -49,15 +49,15 @@ GameLib.D3.API.Input.Editor = function (
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
domElementId = 'divCanvas';
if (GameLib.Utils.UndefinedOrNull(domElement)) {
domElement = null;
}
this.domElementId = domElementId;
this.domElement = domElement;
if (GameLib.Utils.UndefinedOrNull(domContainerId)) {
domContainerId = 'divContainer';
if (GameLib.Utils.UndefinedOrNull(domContainer)) {
domContainer = null;
}
this.domContainerId = domContainerId;
this.domContainer = domContainer;
if (GameLib.Utils.UndefinedOrNull(editor)) {
editor = null;
@ -108,8 +108,8 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
return new GameLib.D3.API.Input.Editor(
objectComponent.id,
objectComponent.name,
objectComponent.domElementId,
objectComponent.domContainerId,
objectComponent.domElement,
objectComponent.domContainer,
objectComponent.editor,
objectComponent.camera,
objectComponent.widthOffset,

View File

@ -16,6 +16,7 @@
GameLib.D3.API.Scene = function(
id,
name,
imageFactory,
meshes,
position,
quaternion,
@ -30,6 +31,7 @@ GameLib.D3.API.Scene = function(
this,
GameLib.Component.COMPONENT_SCENE,
{
'imageFactory' : GameLib.D3.ImageFactory,
'meshes' : [GameLib.D3.Mesh],
'lights' : [GameLib.D3.Light],
'textures' : [GameLib.D3.Texture],
@ -49,6 +51,12 @@ GameLib.D3.API.Scene = function(
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = null;
console.warn('Constructing an API Scene with no Image Factory')
}
this.imageFactory = imageFactory;
if (GameLib.Utils.UndefinedOrNull(meshes)) {
meshes = [];
}
@ -101,6 +109,7 @@ GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene;
*/
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
var apiImageFactory = null;
var apiMeshes = [];
var apiLights = [];
var apiTextures = [];
@ -110,6 +119,10 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
var apiQuaternion = new GameLib.API.Quaternion();
var apiScale = new GameLib.API.Vector3(1,1,1);
if (objectScene.imageFactory) {
apiImageFactory = GameLib.D3.API.ImageFactory.FromObjectImageFactory(objectScene.imageFactory);
}
if (objectScene.meshes) {
apiMeshes = objectScene.meshes.map(
function(objectMesh) {
@ -157,6 +170,7 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
return new GameLib.D3.API.Scene(
objectScene.id,
objectScene.name,
apiImageFactory,
apiMeshes,
apiPosition,
apiQuaternion,

View File

@ -26,6 +26,34 @@ GameLib.D3.Composer = function (
apiComposer.parentEntity
);
if (this.renderer instanceof GameLib.D3.API.Renderer) {
this.renderer = new GameLib.D3.Renderer(
this.graphics,
this.renderer
)
}
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget) {
this.renderTarget = new GameLib.D3.RenderTarget(
this.graphics,
this.renderTarget
)
}
this.passes = this.passes.map(
function (apiPass) {
if (apiPass instanceof GameLib.D3.API.Pass) {
return GameLib.D3.Pass(
this.graphics,
apiPass
)
} else {
console.warn('apiPass not of type API.Pass');
throw new Error('apiPass not of type API.Pass');
}
}.bind(this)
);
this.buildIdToObject();
this.instance = this.createInstance();

View File

@ -28,6 +28,7 @@ GameLib.D3.Editor = function(
apiEditor.name,
apiEditor.baseUrl,
apiEditor.path,
apiEditor.imageFactory,
apiEditor.games,
apiEditor.scenes,
apiEditor.cameras,
@ -42,10 +43,12 @@ GameLib.D3.Editor = function(
apiEditor.parentEntity
);
this.imageFactory = new GameLib.D3.ImageFactory(
this.graphics,
this.baseUrl + this.path
);
if (this.imageFactory instanceof GameLib.D3.API.ImageFactory) {
this.imageFactory = new GameLib.D3.ImageFactory(
this.graphics,
this.imageFactory
);
}
if (this.games) {
this.games = this.games.map(
@ -53,7 +56,8 @@ GameLib.D3.Editor = function(
if (apiGame instanceof GameLib.D3.API.Game) {
return new GameLib.D3.Game(
this.graphics,
apiGame
apiGame,
this.imageFactory
)
}
else {
@ -111,7 +115,7 @@ GameLib.D3.Editor = function(
this.viewports = this.viewports.map(
function (apiViewport) {
if (apiViewport instanceof GameLib.D3.API.Viewport) {
return GameLib.D3.Viewport(
return new GameLib.D3.Viewport(
this.graphics,
apiViewport
)
@ -125,7 +129,7 @@ GameLib.D3.Editor = function(
this.renderers = this.renderers.map(
function (apiRenderer) {
if (apiRenderer instanceof GameLib.D3.API.Renderer) {
return GameLib.D3.Renderer(
return new GameLib.D3.Renderer(
this.graphics,
apiRenderer
)
@ -139,7 +143,7 @@ GameLib.D3.Editor = function(
this.renderTargets = this.renderTargets.map(
function (apiRenderTarget) {
if (apiRenderTarget instanceof GameLib.D3.API.RenderTarget) {
return GameLib.D3.RenderTarget(
return new GameLib.D3.RenderTarget(
this.graphics,
apiRenderTarget
)
@ -152,8 +156,8 @@ GameLib.D3.Editor = function(
this.systems = this.systems.map(
function (apiSystem) {
if (apiSystem instanceof GameLib.D3.API.System) {
return GameLib.D3.System(
if (apiSystem instanceof GameLib.API.System) {
return new GameLib.System(
this.graphics,
apiSystem
)
@ -193,6 +197,11 @@ GameLib.D3.Editor = function(
this.buildIdToObject();
this.meshMoveMode = false;
this.meshMoveXMode = false;
this.meshMoveYMode = false;
this.meshMoveZMode = false;
this.instance = this.createInstance();
};
@ -227,6 +236,7 @@ GameLib.D3.Editor.prototype.updateInstance = function() {
*/
GameLib.D3.Editor.prototype.toApiEditor = function() {
var apiImageFactory = null;
var apiGames = [];
var apiScenes = [];
var apiCameras = [];
@ -236,7 +246,11 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
var apiRenderTargets = [];
var apiSystems = [];
var apiEntityManager = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
}
if (this.games) {
apiGames = this.games.map(
function(game) {
@ -355,6 +369,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
this.name,
this.baseUrl,
this.path,
apiImageFactory,
apiGames,
apiScenes,
apiCameras,

View File

@ -2,13 +2,11 @@
* Game Runtime
* @param graphics GameLib.D3.Graphics
* @param apiGame GameLib.D3.API.Game
* @param imageFactory GameLib.D3.ImageFactory
* @constructor
*/
GameLib.D3.Game = function (
graphics,
apiGame,
imageFactory
apiGame
) {
this.graphics = graphics;
@ -24,9 +22,8 @@ GameLib.D3.Game = function (
apiGame.name,
apiGame.baseUrl,
apiGame.path,
apiGame.imageFactory,
apiGame.gameType,
apiGame.width,
apiGame.height,
apiGame.cameras,
apiGame.composers,
apiGame.viewports,
@ -34,17 +31,15 @@ GameLib.D3.Game = function (
apiGame.renderTargets,
apiGame.systems,
apiGame.entityManager,
apiGame.mouse,
apiGame.parentEntity
);
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = GameLib.D3.ImageFactory(
if (this.imageFactory instanceof GameLib.D3.API.ImageFactory) {
this.imageFactory = new GameLib.D3.ImageFactory(
this.graphics,
this.baseUrl + this.path
this.imageFactory
);
}
this.imageFactory = imageFactory;
this.cameras = this.cameras.map(
function (apiCamera) {
@ -77,7 +72,7 @@ GameLib.D3.Game = function (
this.viewports = this.viewports.map(
function (apiViewport) {
if (apiViewport instanceof GameLib.D3.API.Viewport) {
return GameLib.D3.Viewport(
return new GameLib.D3.Viewport(
this.graphics,
apiViewport
)
@ -91,7 +86,7 @@ GameLib.D3.Game = function (
this.renderers = this.renderers.map(
function (apiRenderer) {
if (apiRenderer instanceof GameLib.D3.API.Renderer) {
return GameLib.D3.Renderer(
return new GameLib.D3.Renderer(
this.graphics,
apiRenderer
)
@ -105,7 +100,7 @@ GameLib.D3.Game = function (
this.renderTargets = this.renderTargets.map(
function (apiRenderTarget) {
if (apiRenderTarget instanceof GameLib.D3.API.RenderTarget) {
return GameLib.D3.RenderTarget(
return new GameLib.D3.RenderTarget(
this.graphics,
apiRenderTarget
)
@ -118,8 +113,8 @@ GameLib.D3.Game = function (
this.systems = this.systems.map(
function (apiSystem) {
if (apiSystem instanceof GameLib.D3.API.System) {
return GameLib.D3.System(
if (apiSystem instanceof GameLib.API.System) {
return new GameLib.System(
this.graphics,
apiSystem
)
@ -142,16 +137,6 @@ GameLib.D3.Game = function (
}
}
if (this.mouse instanceof GameLib.API.Mouse) {
this.mouse = new GameLib.Mouse(
this.graphics,
this.mouse
);
} else {
console.warn('mouse not of type API.Mouse');
throw new Error('mouse not of type API.Mouse');
}
this.buildIdToObject();
this.entityManager.linkObjects(this.idToObject);
@ -214,6 +199,7 @@ GameLib.D3.Game.prototype.updateInstance = function() {
*/
GameLib.D3.Game.prototype.toApiGame = function() {
var apiImageFactory = null;
var apiCameras = [];
var apiComposers = [];
var apiViewports = [];
@ -221,7 +207,10 @@ GameLib.D3.Game.prototype.toApiGame = function() {
var apiRenderTargets = [];
var apiSystems = [];
var apiEntityManager = null;
var apiMouse = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
}
if (this.cameras) {
apiCameras = this.cameras.map(
@ -310,23 +299,13 @@ GameLib.D3.Game.prototype.toApiGame = function() {
}
}
if (this.mouse) {
if (this.mouse instanceof GameLib.Mouse) {
apiMouse = this.mouse.toApiMouse();
} else {
console.warn('Mouse not an instance of Mouse');
throw new Error('Mouse not an instance of Mouse');
}
}
return new GameLib.D3.API.Game(
this.id,
this.name,
this.baseUrl,
this.path,
apiImageFactory,
this.gameType,
this.width,
this.height,
apiCameras,
apiComposers,
apiViewports,
@ -334,7 +313,6 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiRenderTargets,
apiSystems,
apiEntityManager,
apiMouse,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};

View File

@ -22,8 +22,8 @@ GameLib.D3.Input.Editor = function (
this,
apiInputEditor.id,
apiInputEditor.name,
apiInputEditor.domElementId,
apiInputEditor.domContainerId,
apiInputEditor.domElement,
apiInputEditor.domContainer,
apiInputEditor.editor,
apiInputEditor.camera,
apiInputEditor.widthOffset,
@ -35,13 +35,25 @@ GameLib.D3.Input.Editor = function (
);
if (GameLib.Utils.UndefinedOrNull(dom)) {
console.warn('Cannot create Input without an handle to the DOM');
throw new Error('Cannot create Input without an handle to the DOM');
console.warn('Cannot create window resize event without handle to the DOM');
dom = null;
// throw new Error('Cannot create Input without an handle to the DOM');
}
this.dom = dom;
this.element = null;
this.container = null;
if (this.domElement instanceof GameLib.API.DomElement) {
this.domElement = new GameLib.DomElement(
this.graphics,
this.domElement
)
}
if (this.domContainer instanceof GameLib.API.DomElement) {
this.domContainer = new GameLib.DomElement(
this.graphics,
this.domContainer
)
}
this.meshMoveMode = false;
this.meshMoveXMode = false;
@ -77,18 +89,6 @@ GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
this.element = this.dom.document.getElementById(this.domElementId);
if (!this.element) {
console.warn('Could not locate DOM element with ID: ' + this.domElementId);
throw new Error('Could not locate DOM element with ID: ' + this.domElementId);
}
this.container = this.dom.document.getElementById(this.domContainerId);
if (!this.container) {
console.warn('Could not locate DOM container with ID: ' + this.domContainerId);
throw new Error('Could not locate DOM container with ID: ' + this.domContainerId);
}
var instance = null;
if (update) {
@ -98,39 +98,40 @@ GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
} else {
instance = new THREE.EditorControls(
this.camera.instance,
this.element
this.domElement.instance
)
}
this.element.addEventListener(
this.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
false
);
this.element.addEventListener(
this.domElement.instance.addEventListener(
'contextmenu',
this.contextMenu,
false
);
this.element.addEventListener(
this.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
false
);
this.element.addEventListener(
this.domElement.instance.addEventListener(
'keydown',
this.keyPress,
false
);
this.dom.window.addEventListener(
'resize',
this.resize,
false
);
//TODO : window resize
// this.dom.window.addEventListener(
// 'resize',
// this.resize,
// false
// );
return instance;
};
@ -175,8 +176,8 @@ GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent
GameLib.D3.Input.Editor.prototype.onWindowResize = function() {
this.container.style.height = (this.window.innerHeight - this.containerHeightOffset) + 'px';
this.container.style.width = (this.window.innerWidth - this.containerWidthOffset) + 'px';
this.domContainer.instance.style.height = (this.window.innerHeight - this.containerHeightOffset) + 'px';
this.domContainer.instance.style.width = (this.window.innerWidth - this.containerWidthOffset) + 'px';
var width = this.window.innerWidth - this.widthOffset;
@ -444,31 +445,5 @@ GameLib.D3.Input.Editor.prototype.onContextMenu = function(event){
};
GameLib.D3.Input.Editor.prototype.update = function(deltaTime) {
if (this.pathFollowingComponent) {
this.pathFollowingComponent.mesh.localPosition.x = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.x);
this.pathFollowingComponent.mesh.localPosition.y = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.y);
this.pathFollowingComponent.mesh.localPosition.z = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.z);
if (this.keyLeft) {
this.distance -= this.distanceGrain;
}
if (this.keyRight) {
this.distance += this.distanceGrain;
}
this.pathFollowingComponent.mesh.localPosition.x += (this.distance * this.pathFollowingComponent.rotationMatrix.left.x);
this.pathFollowingComponent.mesh.localPosition.y += (this.distance * this.pathFollowingComponent.rotationMatrix.left.y);
this.pathFollowingComponent.mesh.localPosition.z += (this.distance * this.pathFollowingComponent.rotationMatrix.left.z);
this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
this.wheelRL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
this.wheelRR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
}
return;
};

View File

@ -10,7 +10,6 @@
GameLib.D3.Scene = function (
graphics,
apiScene,
imageFactory,
computeNormals
) {
this.graphics = graphics;
@ -29,6 +28,7 @@ GameLib.D3.Scene = function (
this,
apiScene.id,
apiScene.name,
apiScene.imageFactory,
apiScene.meshes,
apiScene.position,
apiScene.quaternion,
@ -40,11 +40,12 @@ GameLib.D3.Scene = function (
apiScene.parentEntity
);
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
console.warn('Creating a scene without an ImageFactory');
imageFactory = null;
if (this.imageFactory instanceof GameLib.D3.API.ImageFactory) {
this.imageFactory = new GameLib.D3.ImageFactory(
this.graphics,
this.imageFactory
);
}
this.imageFactory = imageFactory;
this.meshes = this.meshes.map(
function(apiMesh) {
@ -202,6 +203,11 @@ GameLib.D3.Scene.prototype.createInstance = function() {
*/
GameLib.D3.Scene.prototype.toApiScene = function() {
var apiImageFactory = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
}
var apiMeshes = this.meshes.map(
function(mesh) {
return mesh.toApiMesh();
@ -229,6 +235,7 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
return new GameLib.D3.API.Scene(
this.id,
this.name,
apiImageFactory,
apiMeshes,
this.position.toApiVector(),
this.quaternion.toApiQuaternion(),
@ -245,7 +252,6 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
* Converts a scene Object to a GameLib.D3.Scene object
* @param graphics GameLib.D3.Graphics
* @param objectScene Object
* @param imageFactory GameLib.D3.ImageFactory
* @param computeNormals boolean to indicate whether or not to recalculate normals
* @returns {GameLib.D3.Scene}
* @constructor
@ -253,7 +259,6 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
GameLib.D3.Scene.FromObjectScene = function(
graphics,
objectScene,
imageFactory,
computeNormals
) {
var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene);
@ -261,7 +266,6 @@ GameLib.D3.Scene.FromObjectScene = function(
return new GameLib.D3.Scene(
graphics,
apiScene,
imageFactory,
computeNormals
);
};
@ -272,20 +276,17 @@ GameLib.D3.Scene.FromObjectScene = function(
* @param objectScene Object (as it comes from the API)
* @param computeNormals
* @param onLoaded
* @param imageFactory GameLib.D3.ImageFactory
* @constructor
*/
GameLib.D3.Scene.LoadScene = function(
graphics,
objectScene,
computeNormals,
onLoaded,
imageFactory
onLoaded
) {
var scene = GameLib.D3.Scene.FromObjectScene(
graphics,
objectScene,
imageFactory,
computeNormals
);
@ -298,14 +299,12 @@ GameLib.D3.Scene.LoadScene = function(
* @param partialSceneObject Object {path: '', name: ''}
* @param apiUrl
* @param onLoaded
* @param imageFactory GameLib.D3.ImageFactory
*/
GameLib.D3.Scene.LoadSceneFromApi = function(
graphics,
partialSceneObject,
apiUrl,
onLoaded,
imageFactory
onLoaded
) {
/**
@ -344,8 +343,7 @@ GameLib.D3.Scene.LoadSceneFromApi = function(
graphics,
objectScene,
true,
onLoaded,
imageFactory
onLoaded
);
}
}

View File

@ -7,8 +7,7 @@
*/
GameLib.D3.Viewport = function (
graphics,
apiViewport,
imageFactory
apiViewport
) {
this.graphics = graphics;
@ -18,11 +17,6 @@ GameLib.D3.Viewport = function (
apiViewport = {};
}
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = null;
}
this.imageFactory = imageFactory;
GameLib.D3.API.Viewport.call(
this,
apiViewport.id,
@ -55,8 +49,7 @@ GameLib.D3.Viewport = function (
if (this.scene instanceof GameLib.D3.API.Scene) {
this.scene = new GameLib.D3.Scene(
this.graphics,
this.scene,
this.imageFactory
this.scene
)
}

View File

@ -29,10 +29,7 @@ GameLib.DomElement.prototype.constructor = GameLib.DomElement;
* @returns {*}
*/
GameLib.DomElement.prototype.createInstance = function(update) {
var instance = document.getElementById(this.domElementId);
return instance;
return document.getElementById(this.domElementId);
};
/**

View File

@ -61,6 +61,10 @@ GameLib.Entity = function (
return new GameLib.D3.Follow(this.graphics, apiComponent);
}
if (apiComponent instanceof GameLib.D3.API.Input.Editor) {
return new GameLib.D3.Input.Editor(this.graphics, apiComponent);
}
if (apiComponent instanceof GameLib.D3.API.Input.Drive) {
return new GameLib.D3.Input.Drive(this.graphics, apiComponent);
}

View File

@ -9,6 +9,10 @@ GameLib.Mouse = function (graphics, apiMouse) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMouse)){
apiMouse = {};
}
GameLib.API.Mouse.call(
this,
apiMouse.id,

View File

@ -27,7 +27,19 @@ GameLib.System = function(
apiSystem.parentEntity
);
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
}
if (this.domElement instanceof GameLib.API.DomElement) {
this.domElement = new GameLib.DomElement(
this.graphics,
this.domElement
);
}
};
GameLib.System.prototype = Object.create(GameLib.API.System.prototype);
@ -179,13 +191,23 @@ GameLib.System.prototype.stop = function() {
*/
GameLib.System.prototype.toApiSystem = function() {
//TODO
var apiDomElement = null;
if (this.domElement instanceof GameLib.DomElement) {
apiDomElement = this.domElement.toApiDomElement();
}
var apiDomStats = null;
if (this.domStats instanceof GameLib.DomElement) {
apiDomStats = this.domStats.toApiDomElement();
}
return new GameLib.API.System(
this.id,
this.name,
this.systemType,
this.domElement.toApiDo,
this.domStats,
GameLib.Utils.IdOrNull(this.entityManager),
apiDomElement,
apiDomStats,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};