v2_v3 updates
parent
25278cadf5
commit
59650c739e
|
@ -65,4 +65,4 @@ console.log("Loading editor library...");
|
|||
//#endif
|
||||
|
||||
// This gets injected by gulp
|
||||
console.log("GameLib compiled at", __DATE__);
|
||||
console.log("GameLib compiled at: " + __DATE__);
|
||||
|
|
|
@ -76,7 +76,7 @@ GameLib.D3.API.Camera = function(
|
|||
this.aspect = aspect;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 0.001;
|
||||
near = 0.01;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
|
|
|
@ -187,7 +187,14 @@ GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
|||
if (objectMesh.materials) {
|
||||
apiMaterials = objectMesh.materials.map(
|
||||
function (objectMaterial) {
|
||||
/**
|
||||
* From blender we only get Ids to materials (strings)
|
||||
*/
|
||||
if (objectMaterial instanceof Object) {
|
||||
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
|
||||
} else {
|
||||
return objectMaterial
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,13 +14,12 @@
|
|||
GameLib.D3.API.Renderer = function (
|
||||
id,
|
||||
name,
|
||||
rendererType,
|
||||
autoClear,
|
||||
localClipping,
|
||||
width,
|
||||
height,
|
||||
parentEntity,
|
||||
preserveDrawingBuffer
|
||||
preserveDrawingBuffer,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
GameLib.Component.call(
|
||||
|
@ -41,21 +40,8 @@ GameLib.D3.API.Renderer = function (
|
|||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rendererType)) {
|
||||
rendererType = GameLib.D3.Renderer.RENDER_TYPE_NORMAL;
|
||||
}
|
||||
this.rendererType = rendererType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
||||
|
||||
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||
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;
|
||||
|
||||
|
@ -75,15 +61,7 @@ GameLib.D3.API.Renderer = function (
|
|||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
||||
|
||||
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||
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;
|
||||
};
|
||||
|
@ -100,12 +78,11 @@ GameLib.D3.API.Renderer.FromObjectComponent = function(objectComponent) {
|
|||
return new GameLib.D3.API.Renderer(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.rendererType,
|
||||
objectComponent.autoClear,
|
||||
objectComponent.localClipping,
|
||||
objectComponent.width,
|
||||
objectComponent.height,
|
||||
objectComponent.parentEntity,
|
||||
objectComponent.preserveDrawingBuffer
|
||||
objectComponent.preserveDrawingBuffer,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* @param scale GameLib.API.Vector3
|
||||
* @param parentGameId
|
||||
* @param lights [GameLib.D3.API.Light]
|
||||
* @param textures [GameLib.D3.API.Texture]
|
||||
* @param materials [GameLib.D3.API.Material]
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
|
|
|
@ -66,8 +66,9 @@ GameLib.D3.Mesh = function (
|
|||
this.imageFactory
|
||||
)
|
||||
} else {
|
||||
console.warn('API material not of instance API.Material');
|
||||
throw new Error('API material not of instance API.Material');
|
||||
console.warn('API material not of instance API.Material - should be linked at runtime');
|
||||
return apiMaterial;
|
||||
// throw new Error('API material not of instance API.Material');
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
|
|
|
@ -20,13 +20,12 @@ GameLib.D3.Renderer = function (
|
|||
this,
|
||||
apiRenderer.id,
|
||||
apiRenderer.name,
|
||||
apiRenderer.rendererType,
|
||||
apiRenderer.autoClear,
|
||||
apiRenderer.localClipping,
|
||||
apiRenderer.width,
|
||||
apiRenderer.height,
|
||||
apiRenderer.parentEntity,
|
||||
apiRenderer.preserveDrawingBuffer
|
||||
apiRenderer.preserveDrawingBuffer,
|
||||
apiRenderer.parentEntity
|
||||
);
|
||||
|
||||
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.constructor = GameLib.D3.Renderer;
|
||||
|
||||
GameLib.D3.Renderer.RENDER_TYPE_NORMAL = 0x1;
|
||||
GameLib.D3.Renderer.RENDER_TYPE_STEREO = 0x2;
|
||||
|
||||
/**
|
||||
* Create Renderer Instance
|
||||
* @param update
|
||||
* @param updates
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
||||
|
@ -75,13 +71,12 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
|
|||
var apiRenderer = new GameLib.D3.API.Renderer(
|
||||
this.id,
|
||||
this.name,
|
||||
this.rendererType,
|
||||
this.autoClear,
|
||||
this.localClipping,
|
||||
this.width,
|
||||
this.height,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
preserveDrawingBuffer
|
||||
this.preserveDrawingBuffer,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiRenderer;
|
||||
|
@ -103,3 +98,8 @@ GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
|||
apiRenderer
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Renderer.prototype.render = function() {
|
||||
this.instance.render(this.scene.instance, this.camera.instance);
|
||||
};
|
||||
|
||||
|
|
|
@ -109,8 +109,6 @@ GameLib.D3.Scene = function (
|
|||
return new GameLib.D3.Texture(
|
||||
this.graphics,
|
||||
apiTexture,
|
||||
null,
|
||||
null,
|
||||
this.imageFactory
|
||||
);
|
||||
} else {
|
||||
|
@ -138,6 +136,8 @@ GameLib.D3.Scene = function (
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
this.linkObjects();
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
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.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
|
||||
* @returns {THREE.Scene}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
* Viewport Runtime
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiViewport GameLib.D3.API.Viewport
|
||||
* @param imageFactory GameLib.D3.ImageFactory
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Viewport = function (
|
||||
graphics,
|
||||
apiViewport
|
||||
apiViewport,
|
||||
imageFactory
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
|
@ -16,6 +18,11 @@ GameLib.D3.Viewport = function (
|
|||
apiViewport = {};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||
imageFactory = null;
|
||||
}
|
||||
this.imageFactory = imageFactory;
|
||||
|
||||
GameLib.D3.API.Viewport.call(
|
||||
this,
|
||||
apiViewport.id,
|
||||
|
@ -25,6 +32,7 @@ GameLib.D3.Viewport = function (
|
|||
apiViewport.x,
|
||||
apiViewport.y,
|
||||
apiViewport.composer,
|
||||
apiViewport.renderer,
|
||||
apiViewport.scene,
|
||||
apiViewport.camera,
|
||||
apiViewport.parentEntity
|
||||
|
@ -47,7 +55,8 @@ GameLib.D3.Viewport = function (
|
|||
if (this.scene instanceof GameLib.D3.API.Scene) {
|
||||
this.scene = new GameLib.D3.Scene(
|
||||
this.graphics,
|
||||
this.scene
|
||||
this.scene,
|
||||
this.imageFactory
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -107,7 +116,7 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
|||
this.composer.passes.map(
|
||||
function(pass) {
|
||||
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();
|
||||
}
|
||||
}.bind(this)
|
||||
|
@ -115,7 +124,7 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,8 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
|
|||
array.map(
|
||||
function(object) {
|
||||
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
object.buildIdToObject();
|
||||
var _idToObject = object.idToObject;
|
||||
|
@ -76,7 +78,17 @@ GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
|
|||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
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) {
|
||||
|
||||
if (!object) {
|
||||
return idToObject;
|
||||
}
|
||||
if (object instanceof Object) {
|
||||
|
||||
if (object.buildIdToObject) {
|
||||
object.buildIdToObject();
|
||||
|
@ -100,7 +110,16 @@ GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
|
|||
}
|
||||
}
|
||||
|
||||
if (object.id) {
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue