v2_v3 updates

beta.r3js.org
Theunis J. Botha 2017-01-31 15:23:38 +01:00
parent 25278cadf5
commit 59650c739e
10 changed files with 102 additions and 69 deletions

View File

@ -65,4 +65,4 @@ console.log("Loading editor library...");
//#endif //#endif
// This gets injected by gulp // This gets injected by gulp
console.log("GameLib compiled at", __DATE__); console.log("GameLib compiled at: " + __DATE__);

View File

@ -76,7 +76,7 @@ GameLib.D3.API.Camera = function(
this.aspect = aspect; this.aspect = aspect;
if (GameLib.Utils.UndefinedOrNull(near)) { if (GameLib.Utils.UndefinedOrNull(near)) {
near = 0.001; near = 0.01;
} }
this.near = near; this.near = near;

View File

@ -187,7 +187,14 @@ GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
if (objectMesh.materials) { if (objectMesh.materials) {
apiMaterials = objectMesh.materials.map( apiMaterials = objectMesh.materials.map(
function (objectMaterial) { function (objectMaterial) {
/**
* From blender we only get Ids to materials (strings)
*/
if (objectMaterial instanceof Object) {
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial); return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
} else {
return objectMaterial
}
} }
) )
} }

View File

@ -14,13 +14,12 @@
GameLib.D3.API.Renderer = function ( GameLib.D3.API.Renderer = function (
id, id,
name, name,
rendererType,
autoClear, autoClear,
localClipping, localClipping,
width, width,
height, height,
parentEntity, preserveDrawingBuffer,
preserveDrawingBuffer parentEntity
) { ) {
GameLib.Component.call( GameLib.Component.call(
@ -41,21 +40,8 @@ GameLib.D3.API.Renderer = function (
} }
this.name = name; this.name = name;
if (GameLib.Utils.UndefinedOrNull(rendererType)) {
rendererType = GameLib.D3.Renderer.RENDER_TYPE_NORMAL;
}
this.rendererType = rendererType;
if (GameLib.Utils.UndefinedOrNull(autoClear)) { if (GameLib.Utils.UndefinedOrNull(autoClear)) {
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
autoClear = true; autoClear = true;
} else if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
autoClear = false;
} else {
console.warn('Unhandled render type : ' + this.rendererType);
throw new Error('Unhandled render type : ' + this.rendererType);
}
} }
this.autoClear = autoClear; this.autoClear = autoClear;
@ -75,15 +61,7 @@ GameLib.D3.API.Renderer = function (
this.height = height; this.height = height;
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) { if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
preserveDrawingBuffer = false; preserveDrawingBuffer = false;
} else if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
preserveDrawingBuffer = true;
} else {
console.warn('Unhandled render type : ' + this.rendererType);
throw new Error('Unhandled render type : ' + this.rendererType);
}
} }
this.preserveDrawingBuffer = preserveDrawingBuffer; this.preserveDrawingBuffer = preserveDrawingBuffer;
}; };
@ -100,12 +78,11 @@ GameLib.D3.API.Renderer.FromObjectComponent = function(objectComponent) {
return new GameLib.D3.API.Renderer( return new GameLib.D3.API.Renderer(
objectComponent.id, objectComponent.id,
objectComponent.name, objectComponent.name,
objectComponent.rendererType,
objectComponent.autoClear, objectComponent.autoClear,
objectComponent.localClipping, objectComponent.localClipping,
objectComponent.width, objectComponent.width,
objectComponent.height, objectComponent.height,
objectComponent.parentEntity, objectComponent.preserveDrawingBuffer,
objectComponent.preserveDrawingBuffer objectComponent.parentEntity
); );
}; };

View File

@ -8,6 +8,8 @@
* @param scale GameLib.API.Vector3 * @param scale GameLib.API.Vector3
* @param parentGameId * @param parentGameId
* @param lights [GameLib.D3.API.Light] * @param lights [GameLib.D3.API.Light]
* @param textures [GameLib.D3.API.Texture]
* @param materials [GameLib.D3.API.Material]
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */

View File

@ -66,8 +66,9 @@ GameLib.D3.Mesh = function (
this.imageFactory this.imageFactory
) )
} else { } else {
console.warn('API material not of instance API.Material'); console.warn('API material not of instance API.Material - should be linked at runtime');
throw new Error('API material not of instance API.Material'); return apiMaterial;
// throw new Error('API material not of instance API.Material');
} }
}.bind(this) }.bind(this)

View File

@ -20,13 +20,12 @@ GameLib.D3.Renderer = function (
this, this,
apiRenderer.id, apiRenderer.id,
apiRenderer.name, apiRenderer.name,
apiRenderer.rendererType,
apiRenderer.autoClear, apiRenderer.autoClear,
apiRenderer.localClipping, apiRenderer.localClipping,
apiRenderer.width, apiRenderer.width,
apiRenderer.height, apiRenderer.height,
apiRenderer.parentEntity, apiRenderer.preserveDrawingBuffer,
apiRenderer.preserveDrawingBuffer apiRenderer.parentEntity
); );
this.instance = this.createInstance(); this.instance = this.createInstance();
@ -35,12 +34,9 @@ GameLib.D3.Renderer = function (
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype); GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);
GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer; GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
GameLib.D3.Renderer.RENDER_TYPE_NORMAL = 0x1;
GameLib.D3.Renderer.RENDER_TYPE_STEREO = 0x2;
/** /**
* Create Renderer Instance * Create Renderer Instance
* @param update * @param updates
* @returns {*} * @returns {*}
*/ */
GameLib.D3.Renderer.prototype.createInstance = function(update) { GameLib.D3.Renderer.prototype.createInstance = function(update) {
@ -75,13 +71,12 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
var apiRenderer = new GameLib.D3.API.Renderer( var apiRenderer = new GameLib.D3.API.Renderer(
this.id, this.id,
this.name, this.name,
this.rendererType,
this.autoClear, this.autoClear,
this.localClipping, this.localClipping,
this.width, this.width,
this.height, this.height,
GameLib.Utils.IdOrNull(this.parentEntity), this.preserveDrawingBuffer,
preserveDrawingBuffer GameLib.Utils.IdOrNull(this.parentEntity)
); );
return apiRenderer; return apiRenderer;
@ -103,3 +98,8 @@ GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
apiRenderer apiRenderer
); );
}; };
GameLib.D3.Renderer.prototype.render = function() {
this.instance.render(this.scene.instance, this.camera.instance);
};

View File

@ -109,8 +109,6 @@ GameLib.D3.Scene = function (
return new GameLib.D3.Texture( return new GameLib.D3.Texture(
this.graphics, this.graphics,
apiTexture, apiTexture,
null,
null,
this.imageFactory this.imageFactory
); );
} else { } else {
@ -138,6 +136,8 @@ GameLib.D3.Scene = function (
}.bind(this) }.bind(this)
); );
this.linkObjects();
this.buildIdToObject(); this.buildIdToObject();
this.instance = this.createInstance(); this.instance = this.createInstance();
@ -146,6 +146,24 @@ GameLib.D3.Scene = function (
GameLib.D3.Scene.prototype = Object.create(GameLib.D3.API.Scene.prototype); GameLib.D3.Scene.prototype = Object.create(GameLib.D3.API.Scene.prototype);
GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene; GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene;
GameLib.D3.Scene.prototype.linkObjects = function() {
this.meshes.map(
function(mesh) {
this.materials = mesh.materials.map(
function(material) {
return this.idToObject[material];
}
);
mesh.materials.map(
function(material) {
material.diffuseMap = this.idToObject[material.diffuseMap];
}
)
}
)
};
/** /**
* Creates an instance scene * Creates an instance scene
* @returns {THREE.Scene} * @returns {THREE.Scene}

View File

@ -2,11 +2,13 @@
* Viewport Runtime * Viewport Runtime
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param apiViewport GameLib.D3.API.Viewport * @param apiViewport GameLib.D3.API.Viewport
* @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
*/ */
GameLib.D3.Viewport = function ( GameLib.D3.Viewport = function (
graphics, graphics,
apiViewport apiViewport,
imageFactory
) { ) {
this.graphics = graphics; this.graphics = graphics;
@ -16,6 +18,11 @@ GameLib.D3.Viewport = function (
apiViewport = {}; apiViewport = {};
} }
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = null;
}
this.imageFactory = imageFactory;
GameLib.D3.API.Viewport.call( GameLib.D3.API.Viewport.call(
this, this,
apiViewport.id, apiViewport.id,
@ -25,6 +32,7 @@ GameLib.D3.Viewport = function (
apiViewport.x, apiViewport.x,
apiViewport.y, apiViewport.y,
apiViewport.composer, apiViewport.composer,
apiViewport.renderer,
apiViewport.scene, apiViewport.scene,
apiViewport.camera, apiViewport.camera,
apiViewport.parentEntity apiViewport.parentEntity
@ -47,7 +55,8 @@ GameLib.D3.Viewport = function (
if (this.scene instanceof GameLib.D3.API.Scene) { if (this.scene instanceof GameLib.D3.API.Scene) {
this.scene = new GameLib.D3.Scene( this.scene = new GameLib.D3.Scene(
this.graphics, this.graphics,
this.scene this.scene,
this.imageFactory
) )
} }
@ -107,7 +116,7 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
this.composer.passes.map( this.composer.passes.map(
function(pass) { function(pass) {
if (pass.camera instanceof GameLib.D3.Camera) { if (pass.camera instanceof GameLib.D3.Camera) {
pass.camera.aspect = (this.width - this.x) / (this.height / this.y); pass.camera.aspect = (this.width - this.x) / (this.height - this.y);
pass.camera.updateInstance(); pass.camera.updateInstance();
} }
}.bind(this) }.bind(this)
@ -115,7 +124,7 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
} }
if (this.camera) { if (this.camera) {
this.camera.aspect = (this.width - this.x) / (this.height / this.y); this.camera.aspect = (this.width - this.x) / (this.height - this.y);
this.camera.updateInstance(); this.camera.updateInstance();
} }

View File

@ -65,6 +65,8 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
array.map( array.map(
function(object) { function(object) {
if (object instanceof Object) {
if (object.buildIdToObject) { if (object.buildIdToObject) {
object.buildIdToObject(); object.buildIdToObject();
var _idToObject = object.idToObject; var _idToObject = object.idToObject;
@ -76,7 +78,17 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
} }
} }
if (object.id) {
idToObject[object.id] = object; idToObject[object.id] = object;
} else {
console.warn('Object with no ID passed: ' + object)
}
} else if (typeof object == 'string') {
console.warn('Linked object found:' + object);
} else {
console.warn('Unhandled type of object: ', object);
}
} }
); );
@ -85,9 +97,7 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) { GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
if (!object) { if (object instanceof Object) {
return idToObject;
}
if (object.buildIdToObject) { if (object.buildIdToObject) {
object.buildIdToObject(); object.buildIdToObject();
@ -100,7 +110,16 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
} }
} }
if (object.id) {
idToObject[object.id] = object; idToObject[object.id] = object;
} else {
console.warn('Object with no ID passed: ' + object)
}
} else if (typeof object == 'string') {
console.warn('Linked object found:' + object);
} else {
console.warn('Unhandled type of object: ', object);
}
return idToObject; return idToObject;
}; };