store and load cubemaps

beta.r3js.org
-=yb4f310 2018-02-08 13:57:15 +01:00
parent 453ec6d498
commit 08e92548ef
47 changed files with 697 additions and 278 deletions

View File

@ -34,7 +34,7 @@ GameLib.Event.TEXTURE_ANIMATED_CHANGE = 0x10;
GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12;
GameLib.Event.GAME_PAUSE = 0x13;
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
//GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
GameLib.Event.PLAY_AUDIO = 0x15;
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
GameLib.Event.PAUSE_AUDIO = 0x17;
@ -61,7 +61,7 @@ GameLib.Event.RENDER = 0x2b;
GameLib.Event.EVENT_LIST = 0x2c;
GameLib.Event.COMPILE_SUCCESS = 0x2d;
GameLib.Event.COMPILE_FAILED = 0x2e;
GameLib.Event.TEXTURE_IMAGE_UPDATED = 0x2f;
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x2f;
//GameLib.Event.PARENT_ENTITY_CHANGED = 0x30;
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;

View File

@ -1,13 +1,14 @@
/**
* Image
* GameLib.API.Image
* @param id
* @param name
* @param parentEntity
* @param parentTexture
* @param fileName
* @param extension
* @param path
* @param contentType
* @param size
* @param parentEntity GameLib.Entity
* @constructor
*/
GameLib.API.Image = function(

View File

@ -24,16 +24,35 @@ GameLib.D3.API.Camera = function(
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Camera (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
throw new Error('No camera type specified - do not call this constructor directly');
}
this.cameraType = cameraType;
if (GameLib.Utils.UndefinedOrNull(name)) {
switch (this.cameraType) {
case GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC :
name = 'Camera Orthographic';
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE :
name = 'Camera Perspective';
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
name = 'Camera Cube';
break;
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
name = 'Camera Stereo';
break;
default :
console.warn('no nice name for camera');
name = 'Camera';
}
name += ' (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(aspect)) {
//aspect = new GameLib.API.Number(1, 0.001, 0, 5);
aspect = 1;

View File

@ -26,25 +26,22 @@ GameLib.D3.API.Camera.Cube = function(
}
if (GameLib.Utils.UndefinedOrNull(near)) {
//near = new GameLib.API.Number(0.1, 0.001, 0.001, 2000);
near = 0.1;
near = 0.1;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
//far = new GameLib.API.Number(2000, 1, 1, 4000);
far = 2000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
//cubeResolution = new GameLib.API.Number(512, 64, 64, 8192);
cubeResolution = 128;
}
this.cubeResolution = cubeResolution;
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
renderTarget = new GameLib.D3.API.RenderTarget.Cube();
renderTarget = null;
}
this.renderTarget = renderTarget;

View File

@ -3,24 +3,36 @@
* @param id
* @param name
* @param renderTargetType
* @param parentEntity
* @param autoUpdateSize
* @param width
* @param height
* @param scissor
* @param scissorTest
* @param viewport
* @param texture
* @param depthBuffer
* @param depthTexture
* @param stencilBuffer
* @param textureParameters
* @param texture
* @param parentEntity
* @constructor
*/
GameLib.D3.API.RenderTarget = function (
id,
name,
renderTargetType,
width,
height,
stencilBuffer,
textureParameters,
texture,
parentEntity
id,
name,
renderTargetType,
parentEntity,
autoUpdateSize,
width,
height,
scissor,
scissorTest,
viewport,
texture,
depthBuffer,
depthTexture,
stencilBuffer,
textureParameters
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
@ -47,6 +59,11 @@ GameLib.D3.API.RenderTarget = function (
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) {
autoUpdateSize = true;
}
this.autoUpdateSize = autoUpdateSize;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 512;
}
@ -57,6 +74,36 @@ GameLib.D3.API.RenderTarget = function (
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(scissor)) {
scissor = GameLib.API.Vector4(0,0,1,1);
}
this.scissor = scissor;
if (GameLib.Utils.UndefinedOrNull(scissorTest)) {
scissorTest = false;
}
this.scissorTest = scissorTest;
if (GameLib.Utils.UndefinedOrNull(viewport)) {
viewport = new GameLib.D3.API.Viewport(null, 'Viewport RT ' + this.id);
}
this.viewport = viewport;
if (GameLib.Utils.UndefinedOrNull(texture)) {
texture = null;
}
this.texture = texture;
if (GameLib.Utils.UndefinedOrNull(depthBuffer)) {
depthBuffer = true;
}
this.depthBuffer = depthBuffer;
if (GameLib.Utils.UndefinedOrNull(depthTexture)) {
depthTexture = null;
}
this.depthTexture = depthTexture;
if (GameLib.Utils.UndefinedOrNull(stencilBuffer)) {
stencilBuffer = false;
}
@ -67,34 +114,6 @@ GameLib.D3.API.RenderTarget = function (
}
this.textureParameters = textureParameters;
if (GameLib.Utils.UndefinedOrNull(texture)) {
texture = null;
//
// switch (this.renderTargetType) {
// case GameLib.D3.API.RenderTarget.TARGET_TYPE_NORMAL :
//
// texture = new GameLib.D3.API.Texture(
// null,
// 'Texture (Render Target ' + this.id + ')',
// GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE
// );
// break;
//
// case GameLib.D3.API.RenderTarget.TARGET_TYPE_CUBE :
//
// texture = new GameLib.D3.API.Texture(
// null,
// 'Cube Texture (Render Target ' + this.id + ')',
// GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE
// );
// break;
//
// default :
// throw new Error('Unknown render target type: ' + this.renderTargetType);
// }
}
this.texture = texture;
var componentType = GameLib.D3.API.RenderTarget.GetComponentType(this.renderTargetType);
GameLib.API.Component.call(

View File

@ -32,12 +32,18 @@ GameLib.D3.API.RenderTarget.Cube = function (
apiRenderTarget.id,
apiRenderTarget.name,
apiRenderTarget.renderTargetType,
apiRenderTarget.parentEntity,
apiRenderTarget.autoUpdateSize,
apiRenderTarget.width,
apiRenderTarget.height,
apiRenderTarget.stencilBuffer,
apiRenderTarget.textureParameters,
apiRenderTarget.scissor,
apiRenderTarget.scissorTest,
apiRenderTarget.viewport,
apiRenderTarget.texture,
apiRenderTarget.parentEntity
apiRenderTarget.depthBuffer,
apiRenderTarget.depthTexture,
apiRenderTarget.stencilBuffer,
apiRenderTarget.textureParameters
);
};

View File

@ -66,16 +66,32 @@ GameLib.D3.API.Texture = function(
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Texture (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(textureType)) {
textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NONE;
}
this.textureType = textureType;
if (GameLib.Utils.UndefinedOrNull(name)) {
switch (this.textureType) {
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
name = 'Texture Image';
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS :
name = 'Texture Canvas';
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE :
name = 'Texture Cube';
break;
default:
name = 'Texture';
break;
}
name += ' (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(parentMaterials)) {
parentMaterials = [];
}
@ -196,9 +212,23 @@ GameLib.D3.API.Texture = function(
}
this.forward = forward;
this.needsUpdate = false;
GameLib.API.Component.call(
this,
GameLib.D3.API.Texture.GetComponentType(this.textureType),
parentEntity
);
};
GameLib.D3.API.Texture.GetComponentType = function(textureType) {
var componentType = null;
switch (this.textureType) {
switch (textureType) {
case GameLib.D3.API.Texture.TEXTURE_TYPE_NONE :
componentType = GameLib.Component.TEXTURE;
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
componentType = GameLib.Component.TEXTURE_IMAGE;
break;
@ -209,16 +239,10 @@ GameLib.D3.API.Texture = function(
componentType = GameLib.Component.TEXTURE_CANVAS;
break;
default :
throw new Error('Wrong texture type: ' + this.textureType);
throw new Error('unhandled texture type: ' + textureType);
}
this.needsUpdate = false;
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
return componentType;
};
GameLib.D3.API.Texture.prototype = Object.create(GameLib.API.Component.prototype);

View File

@ -113,6 +113,7 @@ GameLib.D3.Audio.prototype.updateInstance = function(property) {
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -38,24 +38,3 @@ GameLib.D3.BoneWeight.prototype.toApiObject = function() {
return apiBoneWeight;
};
/**
* Returns a GameLib.D3.BoneWeight from a boneWeight Object
* @param graphics GameLib.GraphicsRuntime
* @param objectBoneWeight Object
* @returns {GameLib.D3.BoneWeight}
* @constructor
*/
GameLib.D3.BoneWeight.FromObject = function(
graphics,
objectBoneWeight
) {
var apiBoneWeight = GameLib.D3.API.BoneWeight.FromObject(objectBoneWeight);
var boneWeight = new GameLib.D3.BoneWeight(
graphics,
apiBoneWeight
);
return boneWeight;
};

View File

@ -92,7 +92,7 @@ GameLib.D3.Bone.prototype.createInstance = function() {
/**
* Updates the instance
*/
GameLib.D3.Bone.prototype.updateInstance = function() {
GameLib.D3.Bone.prototype.updateInstance = function(property) {
this.instance.name = this.name;
this.instance.position.x = this.position.x;
@ -111,6 +111,8 @@ GameLib.D3.Bone.prototype.updateInstance = function() {
this.instance.up.x = this.up.x;
this.instance.up.y = this.up.y;
this.instance.up.z = this.up.z;
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -61,7 +61,7 @@ GameLib.D3.Broadphase.prototype.createInstance = function() {
/**
*
*/
GameLib.D3.Broadphase.prototype.updateInstance = function() {
GameLib.D3.Broadphase.prototype.updateInstance = function(property) {
if (this.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) {
if (!(this.instance instanceof CANNON.NaiveBroadphase)) {
@ -80,6 +80,8 @@ GameLib.D3.Broadphase.prototype.updateInstance = function() {
this.createInstance();
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -173,6 +173,7 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
return;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -57,11 +57,35 @@ GameLib.D3.Camera.Cube.prototype.createInstance = function() {
this.cubeResolution
);
this.renderTarget.instance = this.instance.renderTarget;
/**
* We have the same situation here - if we have no render target, this camera was constructed dynamically,
* otherwise, it was loaded from the API
*/
this.renderTarget.instance.texture = this.instance.renderTarget.texture;
//
// this.renderTarget.texture.instance = this.instance.renderTarget.texture;
if (GameLib.Utils.UndefinedOrNull(this.renderTarget)) {
/**
* We construct a new target, assign it the instance from the cube camera, and update ourselves from the instance
* @type {GameLib.D3.RenderTarget.Cube}
*/
this.renderTarget = new GameLib.D3.RenderTarget.Cube(this.graphics);
this.renderTarget.instance = this.instance.renderTarget;
this.renderTarget.updateFromInstance();
} else {
/**
* We have a render target loaded from the API
*/
this.renderTarget.instance = this.instance.renderTarget;
this.renderTarget.applyToInstance();
}
this.renderTarget.instance.setSize(
this.cubeResolution,
this.cubeResolution
);
GameLib.D3.Camera.prototype.createInstance.call(this);
};
@ -87,12 +111,21 @@ GameLib.D3.Camera.Cube.prototype.updateInstance = function(property) {
}
if (property === 'cubeResolution') {
this.instance.cubeResolution = this.cubeResolution;
this.instance.renderTarget.setSize(
this.cubeResolution,
this.cubeResolution
);
return;
}
if (property === 'renderTarget') {
this.instance.renderTarget = this.renderTarget.instance;
console.warn('experimental render target change for cube camera');
if (this.renderTarget && this.renderTarget.instance) {
this.instance.renderTarget = this.renderTarget.instance;
}
return;
}
@ -130,12 +163,20 @@ GameLib.D3.Camera.Cube.prototype.toApiObject = function() {
return apiCubeCamera;
};
/**
* Updates GameLib.D3.Camera.Cube from instance
*/
GameLib.D3.Camera.Cube.prototype.updateFromInstance = function() {
this.near = this.instance.near;
this.far = this.instance.far;
this.cubeResolution = this.instance.cubeResolution;
this.near = this.instance.near;
this.far = this.instance.far;
this.cubeResolution = this.instance.cubeResolution;
this.renderTarget.instance = this.instance.renderTarget;
if (this.renderTarget.instance) {
this.renderTarget.updateFromInstance();
}
console.warn('todo: implement renderTarget updateFromInstance');
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -165,6 +165,7 @@ GameLib.D3.Composer.prototype.updateInstance = function(property) {
)
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -108,6 +108,8 @@ GameLib.D3.Effect.prototype.updateInstance = function(property) {
return;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -111,6 +111,7 @@ GameLib.D3.Fog.prototype.updateInstance = function(property) {
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -64,6 +64,8 @@ GameLib.D3.Font.prototype.updateInstance = function() {
font : this
}
);
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -350,6 +350,8 @@ GameLib.D3.Material.prototype.updateInstance = function(property) {
this.instance.needsUpdate = true;
this.needsUpdate = false;
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**
@ -423,7 +425,12 @@ GameLib.D3.Material.prototype.getTextures = function() {
Object.keys(this.linkedObjects).map(
function(property) {
if (this[property] instanceof GameLib.D3.Texture) {
textures.push(this[property]);
textures.push(
{
property: property,
texture: this[property]
}
);
}
}.bind(this)
);

View File

@ -244,7 +244,7 @@ GameLib.D3.Material.Basic.prototype.toApiObject = function() {
this.color.toApiObject(),
this.combine,
GameLib.Utils.IdOrNull(this.envMap),
GameLib.Utils.IdOrNull(this.envMap),
GameLib.Utils.IdOrNull(this.lightMap),
this.lightMapIntensity,
GameLib.Utils.IdOrNull(this.diffuseMap),
this.morphTargets,

View File

@ -138,6 +138,7 @@ GameLib.D3.Particle.prototype.updateInstance = function(property) {
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};

View File

@ -86,6 +86,7 @@ GameLib.D3.Pass.prototype.updateInstance = function(property) {
this.instance.renderToScreen = this.renderToScreen;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -240,7 +240,7 @@ GameLib.D3.PhysicsWorld.prototype.removeRigidBody = function(rigidBody) {
/**
*
*/
GameLib.D3.PhysicsWorld.prototype.updateInstance = function() {
GameLib.D3.PhysicsWorld.prototype.updateInstance = function(property) {
if (!this.instance) {
console.log('no world instance');
@ -259,6 +259,7 @@ GameLib.D3.PhysicsWorld.prototype.updateInstance = function() {
this.instance.defaultContactMaterial.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
this.instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -125,10 +125,11 @@ GameLib.D3.RaycastVehicle.prototype.createInstance = function() {
};
GameLib.D3.RaycastVehicle.prototype.updateInstance = function() {
GameLib.D3.RaycastVehicle.prototype.updateInstance = function(property) {
// this.instance.chassisBody = this.chassis.instance;
//TODO: add / remove wheels?
console.log('TODO: update raycast vehicle instance');
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -23,24 +23,53 @@ GameLib.D3.RenderTarget = function (
apiRenderTarget.id,
apiRenderTarget.name,
apiRenderTarget.renderTargetType,
apiRenderTarget.parentEntity,
apiRenderTarget.autoUpdateSize,
apiRenderTarget.width,
apiRenderTarget.height,
apiRenderTarget.scissor,
apiRenderTarget.scissorTest,
apiRenderTarget.viewport,
apiRenderTarget.texture,
apiRenderTarget.depthBuffer,
apiRenderTarget.depthTexture,
apiRenderTarget.stencilBuffer,
apiRenderTarget.textureParameters,
apiRenderTarget.texture
apiRenderTarget.textureParameters
);
// if (this.texture instanceof GameLib.D3.API.Texture) {
// this.texture = new GameLib.D3.Texture(
// this.graphics,
// this.texture
// )
// }
this.scissor = new GameLib.Vector4(
this.graphics,
this.scissor,
this
);
if (this.viewport instanceof GameLib.D3.API.Viewport) {
this.viewport = new GameLib.D3.Viewport(
this.graphics,
this.viewport
);
}
if (this.texture instanceof GameLib.D3.API.Texture) {
this.texture = new GameLib.D3.Texture(
this.graphics,
this.texture
)
}
if (this.depthTexture instanceof GameLib.D3.API.Texture) {
this.depthTexture = new GameLib.D3.Texture(
this.graphics,
this.depthTexture
)
}
GameLib.Component.call(
this,
{
'texture' : GameLib.D3.Texture
'texture' : GameLib.D3.Texture,
'depthTexture' : GameLib.D3.Texture,
'viewport' : GameLib.D3.Viewport
}
);
};
@ -48,34 +77,107 @@ GameLib.D3.RenderTarget = function (
GameLib.D3.RenderTarget.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget;
GameLib.D3.RenderTarget.prototype.applyToInstance = function() {
this.instance.scissor = this.scissor.instance;
this.instance.scissorTest = this.scissorTest;
this.instance.viewport = this.viewport.instance;
this.instance.depthBuffer = this.depthBuffer;
this.instance.stencilBuffer = this.stencilBuffer;
if (this.instance.texture) {
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
this.texture = new GameLib.D3.Texture(this.graphics);
this.texture.instance = this.instance.texture;
this.texture.updateFromInstance();
} else {
this.texture.instance = this.instance.texture;
this.texture.applyToInstance();
}
this.publish(
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
{
texture : this.texture
}
);
}
if (this.instance.depthTexture) {
if (GameLib.Utils.UndefinedOrNull(this.depthTexture)) {
this.depthTexture = new GameLib.D3.Texture(this.graphics);
this.depthTexture.instance = this.instance.depthTexture;
this.depthTexture.updateFromInstance();
} else {
this.depthTexture.instance = this.instance.depthTexture;
this.depthTexture.applyToInstance();
}
this.publish(
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
{
texture : this.depthTexture
}
);
}
};
/**
* Creates a Render Target instance
* @returns {*}
*/
GameLib.D3.RenderTarget.prototype.createInstance = function() {
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
throw new Error('no texture');
if (this.autoUpdateSize) {
GameLib.Utils.UpdateWindowSize(this);
}
if (GameLib.Utils.UndefinedOrNull(this.texture.instance)) {
throw new Error('no texture instance');
}
this.instance = new THREE.WebGLRenderTarget(
this.width,
this.height,
this.textureParameters
);
/**
* The instance texture is automatically generated - we assign it to our texture and update from instance
* TODO: do this later if it starts failing
* Only create the instance if it does not already exist - it could be created by a child
*/
//this.texture.instance = this.instance.texture;
//this.texture.updateFromInstance();
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.instance = new THREE.WebGLRenderTarget(
this.width,
this.height,
this.textureParameters
);
}
this.instance.texture = this.texture.instance;
/**
* We have two cases - our texure is null, in this case, we create one and update it from instance,
* Or, we loaded it from API, so our texture is up to date, and we should update our instance
*/
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
/**
* We need to generate a new texture and update it from the instance (we provide an overrideInstance)
*/
this.texture = new GameLib.D3.Texture(
this.graphics,
null,
this.instance.texture
);
} else {
/**
* This texture is loaded from the API, we assign the instance to it, and then apply our settings to it
*/
this.texture.instance = this.instance.texture;
this.texture.applyToInstance();
}
if (GameLib.Utils.Defined(this.depthTexture)) {
this.depthTexture.instance = this.instance.depthTexture;
this.depthTexture.applyToInstance();
}
this.applyToInstance();
GameLib.Component.prototype.createInstance.call(this);
};
@ -87,19 +189,79 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function(property) {
if (
property === 'width' ||
property === 'height'
property === 'height' ||
property === 'autoUpdateSize'
) {
if (this.autoUpdateSize) {
GameLib.Utils.UpdateWindowSize(this);
}
this.instance.setSize(this.width, this.height);
}
if (property === 'renderTargetType') {
console.warn('todo : update renderTargetType');
return;
}
if (property === 'parentEntity') {
console.warn('todo : update parentEntity');
return;
}
if (property === 'scissor') {
console.warn('todo : update scissor');
return;
}
if (property === 'scissorTest') {
this.instance.scissorTest = this.scissorTest;
return;
}
if (property === 'viewport') {
if (this.viewport && this.viewport.instance) {
this.instance.viewport = this.viewport.instance;
} else {
this.instance.viewport = null;
}
return;
}
if (property === 'texture') {
console.warn('experimental texture change');
if (this.texture && this.texture.instance) {
this.instance.texture = this.texture.instance;
}
return;
}
if (property === 'depthBuffer') {
this.instance.depthBuffer = this.depthBuffer;
return;
}
if (property === 'depthTexture') {
console.warn('experimental depthTexture change');
if (this.depthTexture && this.depthTexture.instance) {
this.instance.depthTexture = this.depthTexture.instance;
}
return;
}
if (property === 'stencilBuffer') {
this.instance.stencilBuffer = this.stencilBuffer;
return;
}
if (property === 'texture') {
this.instance.texture = this.texture.instance;
if (property === 'textureParameters') {
console.warn('todo: texture parameters change');
return;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**
@ -112,13 +274,62 @@ GameLib.D3.RenderTarget.prototype.toApiObject = function() {
this.id,
this.name,
this.renderTargetType,
GameLib.Utils.IdOrNull(this.parentEntity),
this.autoUpdateSize,
this.width,
this.height,
this.stencilBuffer,
this.textureParameters,
this.scissor.toApiObject(),
this.scissorTest,
GameLib.Utils.IdOrNull(this.viewport),
GameLib.Utils.IdOrNull(this.texture),
GameLib.Utils.IdOrNull(this.parentEntity)
this.depthBuffer,
GameLib.Utils.IdOrNull(this.depthTexture),
this.stencilBuffer,
this.textureParameters
);
return apiRenderTarget;
};
/**
* Updates GameLib.D3.RenderTarget from instance
*/
GameLib.D3.RenderTarget.prototype.updateFromInstance = function() {
this.width = this.instance.width;
this.height = this.instance.height;
this.scissor.x = this.instance.scissor.x;
this.scissor.y = this.instance.scissor.y;
this.scissor.z = this.instance.scissor.z;
this.scissor.w = this.instance.scissor.w;
this.scissorTest = this.instance.scissorTest;
this.viewport.x = this.instance.viewport.x;
this.viewport.y = this.instance.viewport.y;
this.viewport.width = this.instance.viewport.z;
this.viewport.height = this.instance.viewport.w;
if (this.texture.instance) {
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
this.texture = new GameLib.D3.Texture(this.graphics);
}
this.texture.instance = this.instance.texture;
this.texture.updateFromInstance();
}
this.depthBuffer = this.instance.depthBuffer;
if (this.instance.depthTexture) {
if (GameLib.Utils.UndefinedOrNull(this.depthTexture)) {
this.depthTexture = new GameLib.D3.Texture(this.graphics);
}
this.depthTexture.instance = this.instance.depthTexture;
this.depthTexture.updateFromInstance();
}
this.stencilBuffer = this.instance.stencilBuffer;
};

View File

@ -30,7 +30,7 @@ GameLib.D3.RenderTarget.Cube = function (
);
};
GameLib.D3.RenderTarget.Cube.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.RenderTarget.Cube.prototype = Object.create(GameLib.D3.RenderTarget.prototype);
GameLib.D3.RenderTarget.Cube.prototype.constructor = GameLib.D3.RenderTarget.Cube;
/**
@ -39,57 +39,20 @@ GameLib.D3.RenderTarget.Cube.prototype.constructor = GameLib.D3.RenderTarget.Cub
*/
GameLib.D3.RenderTarget.Cube.prototype.createInstance = function() {
if (
GameLib.Utils.UndefinedOrNull(this.texture) ||
GameLib.Utils.UndefinedOrNull(this.texture.instance)
) {
console.warn('render target texture not ready');
return;
}
this.instance = new THREE.WebGLRenderTargetCube(
this.width,
this.height,
this.textureParameters
);
/**
* The instance texture is automatically generated - we assign it to our texture and update from instance
*/
this.texture.instance = this.instance.texture;
this.texture.updateFromInstance();
GameLib.Component.prototype.createInstance.call(this);
GameLib.D3.RenderTarget.prototype.createInstance.call(this);
};
/**
* updates instance
*/
GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) {
if (property === 'texture') {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
}
}
if (
property === 'width' ||
property === 'height'
) {
this.instance.setSize(this.width, this.height);
}
if (property === 'stencilBuffer') {
this.instance.stencilBuffer = this.stencilBuffer;
}
GameLib.D3.RenderTarget.prototype.updateInstance.call(this, property);
};
/**

View File

@ -438,9 +438,7 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
console.warn('todo: viewports change');
}
if (property === 'parentEntity') {
console.warn('todo: parentEntity change');
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -199,6 +199,8 @@ GameLib.D3.RigidBody.prototype.updateInstance = function() {
this.instance.collisionFilterMask = this.collisionFilterMask;
this.instance.fixedRotation = this.fixedRotation;
this.instance.kinematic = this.kinematic;
GameLib.Component.prototype.updateInstance.call(this, property);
};
GameLib.D3.RigidBody.prototype.setFromParentMesh = function() {

View File

@ -286,6 +286,8 @@ GameLib.D3.Scene.prototype.updateInstance = function(property) {
this.removeAxis();
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -101,10 +101,7 @@ GameLib.D3.Shadow.prototype.updateInstance = function(property) {
this.instance.radius = this.radius;
}
if (property === 'parentEntity') {
console.warn('todo: implement parentEntity change for light')
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -54,8 +54,9 @@ GameLib.D3.Shape.prototype.createInstance = function() {
/**
* Updates the mesh instance
*/
GameLib.D3.Shape.prototype.updateInstance = function() {
GameLib.D3.Shape.prototype.updateInstance = function(property) {
throw new Error('Do not instantiate this class directly - use a child class instead');
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -171,8 +171,8 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
/**
* Updates the instance
*/
GameLib.D3.Skeleton.prototype.updateInstance = function() {
GameLib.D3.Skeleton.prototype.updateInstance = function(property) {
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -55,7 +55,7 @@ GameLib.D3.Solver.prototype.createInstance = function() {
/**
*
*/
GameLib.D3.Solver.prototype.updateInstance = function() {
GameLib.D3.Solver.prototype.updateInstance = function(property) {
if (this.solverType === GameLib.D3.API.Solver.GS_SOLVER) {
if (!(this.instance instanceof CANNON.GSSolver)) {
@ -71,6 +71,8 @@ GameLib.D3.Solver.prototype.updateInstance = function() {
this.instance.iterations = this.iterations;
this.instance.tolerance = this.tolerance;
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -67,7 +67,7 @@ GameLib.D3.Spline.prototype.createInstance = function() {
/**
* Updates the instance
*/
GameLib.D3.Spline.prototype.updateInstance = function() {
GameLib.D3.Spline.prototype.updateInstance = function(property) {
var vertices = this.vertices.map(
function (vertex) {
@ -85,6 +85,8 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
);
this.instance = new THREE.CatmullRomCurve3(vertices);
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -94,6 +94,8 @@ GameLib.D3.Text.prototype.updateInstance = function(property) {
}
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -3,16 +3,23 @@
* created
* @param apiTexture
* @param graphics GameLib.GraphicsRuntime
* @param overrideInstance
* @property textureType
* @constructor
*/
GameLib.D3.Texture = function(
graphics,
apiTexture
apiTexture,
overrideInstance
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(overrideInstance)) {
overrideInstance = null;
}
this.overrideInstance = overrideInstance;
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
apiTexture = {
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_NONE
@ -72,6 +79,8 @@ GameLib.D3.Texture = function(
var linkedObjects = {};
switch (apiTexture.textureType) {
case GameLib.D3.API.Texture.TEXTURE_TYPE_NONE :
break;
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
linkedObjects.image = GameLib.Image;
break;
@ -94,13 +103,53 @@ GameLib.D3.Texture = function(
GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
/**
* Apply our settings to the instance (which are OK to be applied)
*/
GameLib.D3.Texture.prototype.applyToInstance = function() {
this.instance.name = this.name;
this.instance.wrapS = this.wrapS;
this.instance.wrapT = this.wrapT;
this.instance.magFilter = this.magFilter;
this.instance.minFilter = this.minFilter;
this.instance.anisotropy = this.anisotropy;
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
this.instance.rotation = this.rotation;
this.instance.center.x = this.center.x;
this.instance.center.y = this.center.y;
this.instance.matrixAutoUpdate = this.matrixAutoUpdate;
this.instance.generateMipMaps = this.generateMipMaps;
this.instance.premultiplyAlpha = this.premultiplyAlpha;
this.instance.flipY = this.flipY;
this.instance.needsUpdate = true;
};
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Texture.prototype.createInstance = function() {
console.log('creating texture instance');
if (this.overrideInstance) {
this.instance = this.overrideInstance;
this.updateFromInstance();
} else {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
/**
* We have no instance - create one
*/
this.instance = new THREE.Texture();
}
}
/**
* Some settings we copy from the instance
@ -116,25 +165,7 @@ GameLib.D3.Texture.prototype.createInstance = function() {
/**
* Others we apply to the instance
*/
this.instance.name = this.name;
this.instance.wrapS = this.wrapS;
this.instance.wrapT = this.wrapT;
this.instance.magFilter = this.magFilter;
this.instance.minFilter = this.minFilter;
this.instance.anisotropy = this.anisotropy;
this.instance.offset.x = this.offset.x;
this.instance.offset.y = this.offset.y;
this.instance.repeat.x = this.repeat.x;
this.instance.repeat.y = this.repeat.y;
this.instance.rotation = this.rotation;
this.instance.center.x = this.center.x;
this.instance.center.y = this.center.y;
this.instance.matrixAutoUpdate = this.matrixAutoUpdate;
this.instance.generateMipMaps = this.generateMipMaps;
this.instance.premultiplyAlpha = this.premultiplyAlpha;
this.instance.flipY = this.flipY;
this.instance.needsUpdate = true;
this.applyToInstance();
GameLib.Component.prototype.createInstance.call(this);
};
@ -146,7 +177,6 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
console.warn('no texture instance');
this.instance.needsUpdate = true;
return;
}
@ -275,6 +305,8 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
*/
this.instance.needsUpdate = true;
this.version = this.instance.version;
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**
@ -321,8 +353,11 @@ GameLib.D3.Texture.prototype.toApiObject = function() {
return apiTexture;
};
/**
* Updates GameLib.D3.Texture from instance
*/
GameLib.D3.Texture.prototype.updateFromInstance = function() {
this.name = this.instance.name;
this.name = this.instance.name;
this.mipmaps = this.instance.mipmaps;
this.mapping = this.instance.mapping;
this.wrapS = this.instance.wrapS;
@ -334,11 +369,11 @@ GameLib.D3.Texture.prototype.updateFromInstance = function() {
this.storageType = this.instance.storageType;
this.offset.x = this.instance.offset.x;
this.offset.y = this.instance.offset.y;
this.repeat.x = this.instance.repeat.x;
this.repeat.y = this.instance.repeat.y;
this.repeat.x = this.instance.repeat.x;
this.repeat.y = this.instance.repeat.y;
this.rotation = this.instance.rotation;
this.center.x = this.instance.center.x;
this.center.y = this.instance.center.y;
this.center.x = this.instance.center.x;
this.center.y = this.instance.center.y;
this.matrixAutoUpdate = this.instance.matrixAutoUpdate;
this.generateMipMaps = this.instance.generateMipMaps;
this.premultiplyAlpha = this.instance.premultiplyAlpha;

View File

@ -107,7 +107,7 @@ GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) {
}
this.publish(
GameLib.Event.TEXTURE_IMAGE_UPDATED,
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
{
texture : this
}

View File

@ -2,11 +2,13 @@
* GameLib.D3.Texture.Image
* @param graphics
* @param apiTextureImage
* @param overrideInstance - if we pass an instance to the constructor, we want to skip the construction of this texture
* @constructor
*/
GameLib.D3.Texture.Image = function(
graphics,
apiTextureImage
apiTextureImage,
overrideInstance
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
@ -17,6 +19,11 @@ GameLib.D3.Texture.Image = function(
};
}
if (GameLib.Utils.UndefinedOrNull(overrideInstance)) {
overrideInstance = null;
}
this.overrideInstance = overrideInstance;
GameLib.D3.API.Texture.Image.call(
this,
apiTextureImage,
@ -54,9 +61,22 @@ GameLib.D3.Texture.Image.prototype.createInstance = function() {
return;
}
this.instance = new THREE.Texture(
this.image.instance
);
/**
* At this point - our image object exists
*/
if (this.overrideInstance) {
this.instance = this.overrideInstance;
this.updateFromInstance();
} else {
this.instance = new THREE.Texture(
this.image.instance
);
}
GameLib.D3.Texture.prototype.createInstance.call(this);
};
@ -74,7 +94,7 @@ GameLib.D3.Texture.Image.prototype.updateInstance = function(property) {
}
this.publish(
GameLib.Event.TEXTURE_IMAGE_UPDATED,
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
{
texture : this
}
@ -101,3 +121,18 @@ GameLib.D3.Texture.Image.prototype.toApiObject = function() {
return apiTextureImage;
};
/**
* Updates GameLib.D3.Texture.Image from instance
*/
GameLib.D3.Texture.Image.prototype.updateFromInstance = function() {
this.image.instance = this.instance.image;
if (this.image.instance) {
this.image.updateFromInstance();
}
GameLib.D3.Texture.prototype.updateFromInstance.call(this);
};

View File

@ -38,14 +38,34 @@ GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
* @returns {boolean}
*/
GameLib.D3.Viewport.prototype.createInstance = function() {
this.instance = true;
this.instance = new THREE.Vector4(
this.x,
this.y,
this.width,
this.height
);
GameLib.Component.prototype.createInstance.call(this);
};
/**
*
*/
GameLib.D3.Viewport.prototype.updateInstance = function() {
GameLib.D3.Viewport.prototype.updateInstance = function(property) {
if (
property === 'x' ||
property === 'y' ||
property === 'width' ||
property === 'height'
) {
this.instance.x = this.x;
this.instance.y = this.y;
this.instance.z = this.width;
this.instance.w = this.height;
}
};
/**
@ -66,20 +86,3 @@ GameLib.D3.Viewport.prototype.toApiObject = function() {
return apiViewport;
};
/**
* GameLib.D3.Viewport from Object Viewport
* @param graphics
* @param objectComponent
* @returns {GameLib.D3.Viewport}
* @constructor
*/
GameLib.D3.Viewport.FromObject = function(graphics, objectComponent) {
var apiViewport = GameLib.D3.API.Viewport.FromObject(objectComponent);
return new GameLib.D3.Viewport(
graphics,
apiViewport
);
};

View File

@ -41,6 +41,8 @@ GameLib.DomElement.prototype.updateInstance = function(property) {
if (property === 'domElementId') {
this.createInstance()
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -241,6 +241,8 @@ GameLib.Entity.prototype.updateInstance = function(property) {
return;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -75,6 +75,8 @@ GameLib.Image.prototype.updateInstance = function(property) {
) {
this.createInstance();
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
@ -107,3 +109,14 @@ GameLib.Image.prototype.toApiObject = function() {
return apiImage;
};
/**
* Updates GameLib.Image from instance
*/
GameLib.Image.prototype.updateFromInstance = function() {
this.fileName = this.instance.fileName || 'no filename';
this.extension = this.instance.extension || 'no extension';
this.path = this.instance.path || 'no path';
this.contentType = this.instance.contentType || 'no content type';
this.size = this.instance.size || 'no size';
};

View File

@ -39,13 +39,16 @@ GameLib.Mouse.prototype.createInstance = function() {
*/
GameLib.Mouse.prototype.updateInstance = function(property) {
if (property === 'x') {
if (
property === 'x' ||
property === 'y'
) {
this.instance.x = this.x;
this.instance.y = this.y;
return;
}
if (property === 'y') {
this.instance.y = this.y;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};

View File

@ -65,6 +65,8 @@ GameLib.Plane.prototype.updateInstance = function(property) {
this.instance.constant = this.constant;
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**

View File

@ -53,6 +53,8 @@ GameLib.Server.prototype.updateInstance = function(property) {
if (property === 'protocols') {
console.log('todo: server protocols update');
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**

View File

@ -78,6 +78,7 @@ GameLib.Socket.prototype.updateInstance = function(property) {
if (property === 'server') {
console.log('todo: implement socket server update');
}
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
};
/**

View File

@ -1383,7 +1383,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
object,
property,
{
'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE,
'normal': GameLib.D3.API.Texture.TEXTURE_TYPE_NONE,
'image': GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE,
'cube': GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE,
'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
}
@ -1513,6 +1514,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
property === 'volume'
) {
controllers.push(folder.add(object, property, 0, 1.0, 0.001));
} else if (
property === 'cubeResolution'
) {
controllers.push(folder.add(object, property, 16, 4096, 16));
} else if (
property === 'shininess' ||
property === 'fov'

View File

@ -29,7 +29,7 @@ GameLib.System.Render = function(
/**
* Images
*/
this.imageChangedSubscription = null;
this.textureUpdatedSubscription = null;
this.renderConfigurations = [];
@ -87,9 +87,9 @@ GameLib.System.Render.prototype.start = function() {
this.windowResize
);
this.imageChangedSubscription = this.subscribe(
GameLib.Event.TEXTURE_IMAGE_UPDATED,
this.imageChanged
this.textureUpdatedSubscription = this.subscribe(
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
this.textureUpdated
);
this.getRenderConfigurationSubscription = this.subscribe(
@ -189,6 +189,14 @@ GameLib.System.Render.prototype.windowResize = function(data) {
data
);
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.RenderTarget).map(
function(renderTarget) {
if (renderTarget.autoUpdateSize) {
renderTarget.updateInstance('autoUpdateSize');
}
}
);
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
renderers.map(
@ -231,27 +239,27 @@ GameLib.System.Render.prototype.windowResize = function(data) {
};
GameLib.System.Render.prototype.imageChanged = function(data) {
GameLib.System.Render.prototype.textureUpdated = function(data) {
// var textures = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Texture).map(
// function(texture) {
// if (texture.image ===)
// }
// );
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Material).map(
function(material) {
var materials = GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Material);
material.getTextures().map(
function (object) {
materials.map(function(material){
if (object.texture === data.texture) {
var textures = material.getTextures();
if (material.loaded) {
material.updateInstance(object.property);
}
}
}
);
if (textures.indexOf(data.texture) !== -1) {
if (material.loaded) {
material.updateInstance('diffuseMap');
}
}
});
);
};
@ -550,6 +558,34 @@ GameLib.System.Render.prototype.render = function(data) {
viewport.height * size.height
);
/**
* Update any cube camera's based on the scene
*/
this.cubeCameras.map(
function(cubeCamera) {
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map(
function(mesh) {
mesh.visible = false;
mesh.updateInstance('visible');
}
);
scenes.map(
function(scene) {
cubeCamera.update(renderer, scene);
}
);
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Mesh.Box).map(
function(mesh) {
mesh.visible = true;
mesh.updateInstance('visible');
}
);
}
);
if (configuration.enableComposer) {
composer.render();
return;
@ -559,15 +595,6 @@ GameLib.System.Render.prototype.render = function(data) {
function (scene) {
/**
* Update any cube camera's based on the scene
*/
this.cubeCameras.map(
function(cubeCamera) {
cubeCamera.update(renderer, scene);
}
);
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET ||
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
@ -632,7 +659,7 @@ GameLib.System.Render.prototype.stop = function() {
/**
* Images
*/
this.imageChangedSubscription.remove();
this.textureUpdatedSubscription.remove();
// this.delayedInstanceEncounteredSubscription.remove();