store and load cubemaps
parent
453ec6d498
commit
08e92548ef
|
@ -34,7 +34,7 @@ GameLib.Event.TEXTURE_ANIMATED_CHANGE = 0x10;
|
||||||
GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
|
GameLib.Event.ANIMATE_TEXTURE_INSTANCE = 0x11;
|
||||||
GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12;
|
GameLib.Event.REMOVE_PARTICLE_ENGINE = 0x12;
|
||||||
GameLib.Event.GAME_PAUSE = 0x13;
|
GameLib.Event.GAME_PAUSE = 0x13;
|
||||||
GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
|
//GameLib.Event.TEXTURE_INSTANCE_UPDATED = 0x14;
|
||||||
GameLib.Event.PLAY_AUDIO = 0x15;
|
GameLib.Event.PLAY_AUDIO = 0x15;
|
||||||
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
|
GameLib.Event.MATERIAL_INSTANCE_UPDATED = 0x16;
|
||||||
GameLib.Event.PAUSE_AUDIO = 0x17;
|
GameLib.Event.PAUSE_AUDIO = 0x17;
|
||||||
|
@ -61,7 +61,7 @@ GameLib.Event.RENDER = 0x2b;
|
||||||
GameLib.Event.EVENT_LIST = 0x2c;
|
GameLib.Event.EVENT_LIST = 0x2c;
|
||||||
GameLib.Event.COMPILE_SUCCESS = 0x2d;
|
GameLib.Event.COMPILE_SUCCESS = 0x2d;
|
||||||
GameLib.Event.COMPILE_FAILED = 0x2e;
|
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.PARENT_ENTITY_CHANGED = 0x30;
|
||||||
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
|
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
|
||||||
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
|
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
/**
|
/**
|
||||||
* Image
|
* GameLib.API.Image
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
|
* @param parentEntity
|
||||||
|
* @param parentTexture
|
||||||
* @param fileName
|
* @param fileName
|
||||||
* @param extension
|
* @param extension
|
||||||
* @param path
|
* @param path
|
||||||
* @param contentType
|
* @param contentType
|
||||||
* @param size
|
* @param size
|
||||||
* @param parentEntity GameLib.Entity
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Image = function(
|
GameLib.API.Image = function(
|
||||||
|
|
|
@ -24,16 +24,35 @@ GameLib.D3.API.Camera = function(
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Camera (' + this.id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
||||||
throw new Error('No camera type specified - do not call this constructor directly');
|
throw new Error('No camera type specified - do not call this constructor directly');
|
||||||
}
|
}
|
||||||
this.cameraType = cameraType;
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(aspect)) {
|
||||||
//aspect = new GameLib.API.Number(1, 0.001, 0, 5);
|
//aspect = new GameLib.API.Number(1, 0.001, 0, 5);
|
||||||
aspect = 1;
|
aspect = 1;
|
||||||
|
|
|
@ -26,25 +26,22 @@ GameLib.D3.API.Camera.Cube = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
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;
|
this.near = near;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||||
//far = new GameLib.API.Number(2000, 1, 1, 4000);
|
|
||||||
far = 2000;
|
far = 2000;
|
||||||
}
|
}
|
||||||
this.far = far;
|
this.far = far;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
|
if (GameLib.Utils.UndefinedOrNull(cubeResolution)) {
|
||||||
//cubeResolution = new GameLib.API.Number(512, 64, 64, 8192);
|
|
||||||
cubeResolution = 128;
|
cubeResolution = 128;
|
||||||
}
|
}
|
||||||
this.cubeResolution = cubeResolution;
|
this.cubeResolution = cubeResolution;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||||
renderTarget = new GameLib.D3.API.RenderTarget.Cube();
|
renderTarget = null;
|
||||||
}
|
}
|
||||||
this.renderTarget = renderTarget;
|
this.renderTarget = renderTarget;
|
||||||
|
|
||||||
|
|
|
@ -3,24 +3,36 @@
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param renderTargetType
|
* @param renderTargetType
|
||||||
|
* @param parentEntity
|
||||||
|
* @param autoUpdateSize
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
|
* @param scissor
|
||||||
|
* @param scissorTest
|
||||||
|
* @param viewport
|
||||||
|
* @param texture
|
||||||
|
* @param depthBuffer
|
||||||
|
* @param depthTexture
|
||||||
* @param stencilBuffer
|
* @param stencilBuffer
|
||||||
* @param textureParameters
|
* @param textureParameters
|
||||||
* @param texture
|
|
||||||
* @param parentEntity
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.RenderTarget = function (
|
GameLib.D3.API.RenderTarget = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
renderTargetType,
|
renderTargetType,
|
||||||
width,
|
parentEntity,
|
||||||
height,
|
autoUpdateSize,
|
||||||
stencilBuffer,
|
width,
|
||||||
textureParameters,
|
height,
|
||||||
texture,
|
scissor,
|
||||||
parentEntity
|
scissorTest,
|
||||||
|
viewport,
|
||||||
|
texture,
|
||||||
|
depthBuffer,
|
||||||
|
depthTexture,
|
||||||
|
stencilBuffer,
|
||||||
|
textureParameters
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
|
@ -47,6 +59,11 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(autoUpdateSize)) {
|
||||||
|
autoUpdateSize = true;
|
||||||
|
}
|
||||||
|
this.autoUpdateSize = autoUpdateSize;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
width = 512;
|
width = 512;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +74,36 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
}
|
}
|
||||||
this.height = height;
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(stencilBuffer)) {
|
||||||
stencilBuffer = false;
|
stencilBuffer = false;
|
||||||
}
|
}
|
||||||
|
@ -67,34 +114,6 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
}
|
}
|
||||||
this.textureParameters = textureParameters;
|
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);
|
var componentType = GameLib.D3.API.RenderTarget.GetComponentType(this.renderTargetType);
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
GameLib.API.Component.call(
|
||||||
|
|
|
@ -32,12 +32,18 @@ GameLib.D3.API.RenderTarget.Cube = function (
|
||||||
apiRenderTarget.id,
|
apiRenderTarget.id,
|
||||||
apiRenderTarget.name,
|
apiRenderTarget.name,
|
||||||
apiRenderTarget.renderTargetType,
|
apiRenderTarget.renderTargetType,
|
||||||
|
apiRenderTarget.parentEntity,
|
||||||
|
apiRenderTarget.autoUpdateSize,
|
||||||
apiRenderTarget.width,
|
apiRenderTarget.width,
|
||||||
apiRenderTarget.height,
|
apiRenderTarget.height,
|
||||||
apiRenderTarget.stencilBuffer,
|
apiRenderTarget.scissor,
|
||||||
apiRenderTarget.textureParameters,
|
apiRenderTarget.scissorTest,
|
||||||
|
apiRenderTarget.viewport,
|
||||||
apiRenderTarget.texture,
|
apiRenderTarget.texture,
|
||||||
apiRenderTarget.parentEntity
|
apiRenderTarget.depthBuffer,
|
||||||
|
apiRenderTarget.depthTexture,
|
||||||
|
apiRenderTarget.stencilBuffer,
|
||||||
|
apiRenderTarget.textureParameters
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -66,16 +66,32 @@ GameLib.D3.API.Texture = function(
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Texture (' + id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(textureType)) {
|
if (GameLib.Utils.UndefinedOrNull(textureType)) {
|
||||||
textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NONE;
|
textureType = GameLib.D3.API.Texture.TEXTURE_TYPE_NONE;
|
||||||
}
|
}
|
||||||
this.textureType = textureType;
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(parentMaterials)) {
|
||||||
parentMaterials = [];
|
parentMaterials = [];
|
||||||
}
|
}
|
||||||
|
@ -196,9 +212,23 @@ GameLib.D3.API.Texture = function(
|
||||||
}
|
}
|
||||||
this.forward = forward;
|
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;
|
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 :
|
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
|
||||||
componentType = GameLib.Component.TEXTURE_IMAGE;
|
componentType = GameLib.Component.TEXTURE_IMAGE;
|
||||||
break;
|
break;
|
||||||
|
@ -209,16 +239,10 @@ GameLib.D3.API.Texture = function(
|
||||||
componentType = GameLib.Component.TEXTURE_CANVAS;
|
componentType = GameLib.Component.TEXTURE_CANVAS;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
throw new Error('Wrong texture type: ' + this.textureType);
|
throw new Error('unhandled texture type: ' + textureType);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.needsUpdate = false;
|
return componentType;
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
componentType,
|
|
||||||
parentEntity
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Texture.prototype = Object.create(GameLib.API.Component.prototype);
|
GameLib.D3.API.Texture.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
|
|
|
@ -113,6 +113,7 @@ GameLib.D3.Audio.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,24 +38,3 @@ GameLib.D3.BoneWeight.prototype.toApiObject = function() {
|
||||||
|
|
||||||
return apiBoneWeight;
|
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;
|
|
||||||
};
|
|
|
@ -92,7 +92,7 @@ GameLib.D3.Bone.prototype.createInstance = function() {
|
||||||
/**
|
/**
|
||||||
* Updates the instance
|
* Updates the instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Bone.prototype.updateInstance = function() {
|
GameLib.D3.Bone.prototype.updateInstance = function(property) {
|
||||||
this.instance.name = this.name;
|
this.instance.name = this.name;
|
||||||
|
|
||||||
this.instance.position.x = this.position.x;
|
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.x = this.up.x;
|
||||||
this.instance.up.y = this.up.y;
|
this.instance.up.y = this.up.y;
|
||||||
this.instance.up.z = this.up.z;
|
this.instance.up.z = this.up.z;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.broadphaseType === GameLib.D3.Broadphase.BROADPHASE_TYPE_NAIVE) {
|
||||||
if (!(this.instance instanceof CANNON.NaiveBroadphase)) {
|
if (!(this.instance instanceof CANNON.NaiveBroadphase)) {
|
||||||
|
@ -80,6 +80,8 @@ GameLib.D3.Broadphase.prototype.updateInstance = function() {
|
||||||
this.createInstance();
|
this.createInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -173,6 +173,7 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,11 +57,35 @@ GameLib.D3.Camera.Cube.prototype.createInstance = function() {
|
||||||
this.cubeResolution
|
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;
|
if (GameLib.Utils.UndefinedOrNull(this.renderTarget)) {
|
||||||
//
|
|
||||||
// this.renderTarget.texture.instance = this.instance.renderTarget.texture;
|
/**
|
||||||
|
* 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);
|
GameLib.D3.Camera.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
@ -87,12 +111,21 @@ GameLib.D3.Camera.Cube.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'cubeResolution') {
|
if (property === 'cubeResolution') {
|
||||||
this.instance.cubeResolution = this.cubeResolution;
|
this.instance.renderTarget.setSize(
|
||||||
|
this.cubeResolution,
|
||||||
|
this.cubeResolution
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'renderTarget') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +163,20 @@ GameLib.D3.Camera.Cube.prototype.toApiObject = function() {
|
||||||
return apiCubeCamera;
|
return apiCubeCamera;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates GameLib.D3.Camera.Cube from instance
|
||||||
|
*/
|
||||||
GameLib.D3.Camera.Cube.prototype.updateFromInstance = function() {
|
GameLib.D3.Camera.Cube.prototype.updateFromInstance = function() {
|
||||||
|
|
||||||
this.near = this.instance.near;
|
this.near = this.instance.near;
|
||||||
this.far = this.instance.far;
|
this.far = this.instance.far;
|
||||||
this.cubeResolution = this.instance.cubeResolution;
|
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);
|
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
|
||||||
};
|
};
|
|
@ -165,6 +165,7 @@ GameLib.D3.Composer.prototype.updateInstance = function(property) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -108,6 +108,8 @@ GameLib.D3.Effect.prototype.updateInstance = function(property) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -111,6 +111,7 @@ GameLib.D3.Fog.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,6 +64,8 @@ GameLib.D3.Font.prototype.updateInstance = function() {
|
||||||
font : this
|
font : this
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -350,6 +350,8 @@ GameLib.D3.Material.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
this.instance.needsUpdate = true;
|
this.instance.needsUpdate = true;
|
||||||
this.needsUpdate = false;
|
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(
|
Object.keys(this.linkedObjects).map(
|
||||||
function(property) {
|
function(property) {
|
||||||
if (this[property] instanceof GameLib.D3.Texture) {
|
if (this[property] instanceof GameLib.D3.Texture) {
|
||||||
textures.push(this[property]);
|
textures.push(
|
||||||
|
{
|
||||||
|
property: property,
|
||||||
|
texture: this[property]
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
|
@ -244,7 +244,7 @@ GameLib.D3.Material.Basic.prototype.toApiObject = function() {
|
||||||
this.color.toApiObject(),
|
this.color.toApiObject(),
|
||||||
this.combine,
|
this.combine,
|
||||||
GameLib.Utils.IdOrNull(this.envMap),
|
GameLib.Utils.IdOrNull(this.envMap),
|
||||||
GameLib.Utils.IdOrNull(this.envMap),
|
GameLib.Utils.IdOrNull(this.lightMap),
|
||||||
this.lightMapIntensity,
|
this.lightMapIntensity,
|
||||||
GameLib.Utils.IdOrNull(this.diffuseMap),
|
GameLib.Utils.IdOrNull(this.diffuseMap),
|
||||||
this.morphTargets,
|
this.morphTargets,
|
||||||
|
|
|
@ -138,6 +138,7 @@ GameLib.D3.Particle.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ GameLib.D3.Pass.prototype.updateInstance = function(property) {
|
||||||
this.instance.renderToScreen = this.renderToScreen;
|
this.instance.renderToScreen = this.renderToScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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) {
|
if (!this.instance) {
|
||||||
console.log('no world 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.frictionEquationStiffness = this.defaultContactMaterial.frictionEquationStiffness;
|
||||||
this.instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
|
this.instance.defaultContactMaterial.frictionEquationRelaxation = this.defaultContactMaterial.frictionEquationRelaxation;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
// this.instance.chassisBody = this.chassis.instance;
|
||||||
//TODO: add / remove wheels?
|
//TODO: add / remove wheels?
|
||||||
console.log('TODO: update raycast vehicle instance');
|
console.log('TODO: update raycast vehicle instance');
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,24 +23,53 @@ GameLib.D3.RenderTarget = function (
|
||||||
apiRenderTarget.id,
|
apiRenderTarget.id,
|
||||||
apiRenderTarget.name,
|
apiRenderTarget.name,
|
||||||
apiRenderTarget.renderTargetType,
|
apiRenderTarget.renderTargetType,
|
||||||
|
apiRenderTarget.parentEntity,
|
||||||
|
apiRenderTarget.autoUpdateSize,
|
||||||
apiRenderTarget.width,
|
apiRenderTarget.width,
|
||||||
apiRenderTarget.height,
|
apiRenderTarget.height,
|
||||||
|
apiRenderTarget.scissor,
|
||||||
|
apiRenderTarget.scissorTest,
|
||||||
|
apiRenderTarget.viewport,
|
||||||
|
apiRenderTarget.texture,
|
||||||
|
apiRenderTarget.depthBuffer,
|
||||||
|
apiRenderTarget.depthTexture,
|
||||||
apiRenderTarget.stencilBuffer,
|
apiRenderTarget.stencilBuffer,
|
||||||
apiRenderTarget.textureParameters,
|
apiRenderTarget.textureParameters
|
||||||
apiRenderTarget.texture
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (this.texture instanceof GameLib.D3.API.Texture) {
|
this.scissor = new GameLib.Vector4(
|
||||||
// this.texture = new GameLib.D3.Texture(
|
this.graphics,
|
||||||
// this.graphics,
|
this.scissor,
|
||||||
// this.texture
|
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(
|
GameLib.Component.call(
|
||||||
this,
|
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 = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget;
|
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
|
* Creates a Render Target instance
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.RenderTarget.prototype.createInstance = function() {
|
GameLib.D3.RenderTarget.prototype.createInstance = function() {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.texture)) {
|
if (this.autoUpdateSize) {
|
||||||
throw new Error('no texture');
|
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
|
* Only create the instance if it does not already exist - it could be created by a child
|
||||||
* TODO: do this later if it starts failing
|
|
||||||
*/
|
*/
|
||||||
//this.texture.instance = this.instance.texture;
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
//this.texture.updateFromInstance();
|
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);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
@ -87,19 +189,79 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
property === 'width' ||
|
property === 'width' ||
|
||||||
property === 'height'
|
property === 'height' ||
|
||||||
|
property === 'autoUpdateSize'
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
if (this.autoUpdateSize) {
|
||||||
|
GameLib.Utils.UpdateWindowSize(this);
|
||||||
|
}
|
||||||
|
|
||||||
this.instance.setSize(this.width, this.height);
|
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') {
|
if (property === 'stencilBuffer') {
|
||||||
this.instance.stencilBuffer = this.stencilBuffer;
|
this.instance.stencilBuffer = this.stencilBuffer;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'texture') {
|
if (property === 'textureParameters') {
|
||||||
this.instance.texture = this.texture.instance;
|
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.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.renderTargetType,
|
this.renderTargetType,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||||
|
this.autoUpdateSize,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.stencilBuffer,
|
this.scissor.toApiObject(),
|
||||||
this.textureParameters,
|
this.scissorTest,
|
||||||
|
GameLib.Utils.IdOrNull(this.viewport),
|
||||||
GameLib.Utils.IdOrNull(this.texture),
|
GameLib.Utils.IdOrNull(this.texture),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
this.depthBuffer,
|
||||||
|
GameLib.Utils.IdOrNull(this.depthTexture),
|
||||||
|
this.stencilBuffer,
|
||||||
|
this.textureParameters
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiRenderTarget;
|
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;
|
||||||
|
};
|
|
@ -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;
|
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() {
|
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.instance = new THREE.WebGLRenderTargetCube(
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
this.textureParameters
|
this.textureParameters
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
GameLib.D3.RenderTarget.prototype.createInstance.call(this);
|
||||||
* 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);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates instance
|
* updates instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) {
|
GameLib.D3.RenderTarget.Cube.prototype.updateInstance = function(property) {
|
||||||
|
GameLib.D3.RenderTarget.prototype.updateInstance.call(this, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -438,9 +438,7 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
|
||||||
console.warn('todo: viewports change');
|
console.warn('todo: viewports change');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'parentEntity') {
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
console.warn('todo: parentEntity change');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -199,6 +199,8 @@ GameLib.D3.RigidBody.prototype.updateInstance = function() {
|
||||||
this.instance.collisionFilterMask = this.collisionFilterMask;
|
this.instance.collisionFilterMask = this.collisionFilterMask;
|
||||||
this.instance.fixedRotation = this.fixedRotation;
|
this.instance.fixedRotation = this.fixedRotation;
|
||||||
this.instance.kinematic = this.kinematic;
|
this.instance.kinematic = this.kinematic;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.RigidBody.prototype.setFromParentMesh = function() {
|
GameLib.D3.RigidBody.prototype.setFromParentMesh = function() {
|
||||||
|
|
|
@ -286,6 +286,8 @@ GameLib.D3.Scene.prototype.updateInstance = function(property) {
|
||||||
this.removeAxis();
|
this.removeAxis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -101,10 +101,7 @@ GameLib.D3.Shadow.prototype.updateInstance = function(property) {
|
||||||
this.instance.radius = this.radius;
|
this.instance.radius = this.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'parentEntity') {
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
console.warn('todo: implement parentEntity change for light')
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,8 +54,9 @@ GameLib.D3.Shape.prototype.createInstance = function() {
|
||||||
/**
|
/**
|
||||||
* Updates the mesh instance
|
* 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');
|
throw new Error('Do not instantiate this class directly - use a child class instead');
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -171,8 +171,8 @@ GameLib.D3.Skeleton.prototype.createInstance = function(update) {
|
||||||
/**
|
/**
|
||||||
* Updates the instance
|
* Updates the instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Skeleton.prototype.updateInstance = function() {
|
GameLib.D3.Skeleton.prototype.updateInstance = function(property) {
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.solverType === GameLib.D3.API.Solver.GS_SOLVER) {
|
||||||
if (!(this.instance instanceof CANNON.GSSolver)) {
|
if (!(this.instance instanceof CANNON.GSSolver)) {
|
||||||
|
@ -71,6 +71,8 @@ GameLib.D3.Solver.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.instance.iterations = this.iterations;
|
this.instance.iterations = this.iterations;
|
||||||
this.instance.tolerance = this.tolerance;
|
this.instance.tolerance = this.tolerance;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -67,7 +67,7 @@ GameLib.D3.Spline.prototype.createInstance = function() {
|
||||||
/**
|
/**
|
||||||
* Updates the instance
|
* Updates the instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Spline.prototype.updateInstance = function() {
|
GameLib.D3.Spline.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
var vertices = this.vertices.map(
|
var vertices = this.vertices.map(
|
||||||
function (vertex) {
|
function (vertex) {
|
||||||
|
@ -85,6 +85,8 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = new THREE.CatmullRomCurve3(vertices);
|
this.instance = new THREE.CatmullRomCurve3(vertices);
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -94,6 +94,8 @@ GameLib.D3.Text.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,16 +3,23 @@
|
||||||
* created
|
* created
|
||||||
* @param apiTexture
|
* @param apiTexture
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param overrideInstance
|
||||||
* @property textureType
|
* @property textureType
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture = function(
|
GameLib.D3.Texture = function(
|
||||||
graphics,
|
graphics,
|
||||||
apiTexture
|
apiTexture,
|
||||||
|
overrideInstance
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(overrideInstance)) {
|
||||||
|
overrideInstance = null;
|
||||||
|
}
|
||||||
|
this.overrideInstance = overrideInstance;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
|
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
|
||||||
apiTexture = {
|
apiTexture = {
|
||||||
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_NONE
|
textureType : GameLib.D3.API.Texture.TEXTURE_TYPE_NONE
|
||||||
|
@ -72,6 +79,8 @@ GameLib.D3.Texture = function(
|
||||||
var linkedObjects = {};
|
var linkedObjects = {};
|
||||||
|
|
||||||
switch (apiTexture.textureType) {
|
switch (apiTexture.textureType) {
|
||||||
|
case GameLib.D3.API.Texture.TEXTURE_TYPE_NONE :
|
||||||
|
break;
|
||||||
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
|
case GameLib.D3.API.Texture.TEXTURE_TYPE_IMAGE :
|
||||||
linkedObjects.image = GameLib.Image;
|
linkedObjects.image = GameLib.Image;
|
||||||
break;
|
break;
|
||||||
|
@ -94,13 +103,53 @@ GameLib.D3.Texture = function(
|
||||||
GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.Texture.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
|
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
|
* Creates an instance of our texture object
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function() {
|
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
|
* Some settings we copy from the instance
|
||||||
|
@ -116,25 +165,7 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
/**
|
/**
|
||||||
* Others we apply to the instance
|
* Others we apply to the instance
|
||||||
*/
|
*/
|
||||||
this.instance.name = this.name;
|
this.applyToInstance();
|
||||||
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;
|
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
@ -146,7 +177,6 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
console.warn('no texture instance');
|
console.warn('no texture instance');
|
||||||
this.instance.needsUpdate = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,6 +305,8 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
|
||||||
*/
|
*/
|
||||||
this.instance.needsUpdate = true;
|
this.instance.needsUpdate = true;
|
||||||
this.version = this.instance.version;
|
this.version = this.instance.version;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,8 +353,11 @@ GameLib.D3.Texture.prototype.toApiObject = function() {
|
||||||
return apiTexture;
|
return apiTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates GameLib.D3.Texture from instance
|
||||||
|
*/
|
||||||
GameLib.D3.Texture.prototype.updateFromInstance = function() {
|
GameLib.D3.Texture.prototype.updateFromInstance = function() {
|
||||||
this.name = this.instance.name;
|
this.name = this.instance.name;
|
||||||
this.mipmaps = this.instance.mipmaps;
|
this.mipmaps = this.instance.mipmaps;
|
||||||
this.mapping = this.instance.mapping;
|
this.mapping = this.instance.mapping;
|
||||||
this.wrapS = this.instance.wrapS;
|
this.wrapS = this.instance.wrapS;
|
||||||
|
@ -334,11 +369,11 @@ GameLib.D3.Texture.prototype.updateFromInstance = function() {
|
||||||
this.storageType = this.instance.storageType;
|
this.storageType = this.instance.storageType;
|
||||||
this.offset.x = this.instance.offset.x;
|
this.offset.x = this.instance.offset.x;
|
||||||
this.offset.y = this.instance.offset.y;
|
this.offset.y = this.instance.offset.y;
|
||||||
this.repeat.x = this.instance.repeat.x;
|
this.repeat.x = this.instance.repeat.x;
|
||||||
this.repeat.y = this.instance.repeat.y;
|
this.repeat.y = this.instance.repeat.y;
|
||||||
this.rotation = this.instance.rotation;
|
this.rotation = this.instance.rotation;
|
||||||
this.center.x = this.instance.center.x;
|
this.center.x = this.instance.center.x;
|
||||||
this.center.y = this.instance.center.y;
|
this.center.y = this.instance.center.y;
|
||||||
this.matrixAutoUpdate = this.instance.matrixAutoUpdate;
|
this.matrixAutoUpdate = this.instance.matrixAutoUpdate;
|
||||||
this.generateMipMaps = this.instance.generateMipMaps;
|
this.generateMipMaps = this.instance.generateMipMaps;
|
||||||
this.premultiplyAlpha = this.instance.premultiplyAlpha;
|
this.premultiplyAlpha = this.instance.premultiplyAlpha;
|
||||||
|
|
|
@ -107,7 +107,7 @@ GameLib.D3.Texture.Cube.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.publish(
|
this.publish(
|
||||||
GameLib.Event.TEXTURE_IMAGE_UPDATED,
|
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
|
||||||
{
|
{
|
||||||
texture : this
|
texture : this
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
* GameLib.D3.Texture.Image
|
* GameLib.D3.Texture.Image
|
||||||
* @param graphics
|
* @param graphics
|
||||||
* @param apiTextureImage
|
* @param apiTextureImage
|
||||||
|
* @param overrideInstance - if we pass an instance to the constructor, we want to skip the construction of this texture
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.Image = function(
|
GameLib.D3.Texture.Image = function(
|
||||||
graphics,
|
graphics,
|
||||||
apiTextureImage
|
apiTextureImage,
|
||||||
|
overrideInstance
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
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(
|
GameLib.D3.API.Texture.Image.call(
|
||||||
this,
|
this,
|
||||||
apiTextureImage,
|
apiTextureImage,
|
||||||
|
@ -54,9 +61,22 @@ GameLib.D3.Texture.Image.prototype.createInstance = function() {
|
||||||
return;
|
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);
|
GameLib.D3.Texture.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
@ -74,7 +94,7 @@ GameLib.D3.Texture.Image.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.publish(
|
this.publish(
|
||||||
GameLib.Event.TEXTURE_IMAGE_UPDATED,
|
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
|
||||||
{
|
{
|
||||||
texture : this
|
texture : this
|
||||||
}
|
}
|
||||||
|
@ -101,3 +121,18 @@ GameLib.D3.Texture.Image.prototype.toApiObject = function() {
|
||||||
|
|
||||||
return apiTextureImage;
|
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);
|
||||||
|
|
||||||
|
};
|
|
@ -38,14 +38,34 @@ GameLib.D3.Viewport.prototype.constructor = GameLib.D3.Viewport;
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Viewport.prototype.createInstance = function() {
|
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.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;
|
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
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -41,6 +41,8 @@ GameLib.DomElement.prototype.updateInstance = function(property) {
|
||||||
if (property === 'domElementId') {
|
if (property === 'domElementId') {
|
||||||
this.createInstance()
|
this.createInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -241,6 +241,8 @@ GameLib.Entity.prototype.updateInstance = function(property) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,6 +75,8 @@ GameLib.Image.prototype.updateInstance = function(property) {
|
||||||
) {
|
) {
|
||||||
this.createInstance();
|
this.createInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
|
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
|
||||||
|
@ -107,3 +109,14 @@ GameLib.Image.prototype.toApiObject = function() {
|
||||||
|
|
||||||
return apiImage;
|
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';
|
||||||
|
};
|
||||||
|
|
|
@ -39,13 +39,16 @@ GameLib.Mouse.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.Mouse.prototype.updateInstance = function(property) {
|
GameLib.Mouse.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (property === 'x') {
|
if (
|
||||||
|
property === 'x' ||
|
||||||
|
property === 'y'
|
||||||
|
) {
|
||||||
this.instance.x = this.x;
|
this.instance.x = this.x;
|
||||||
|
this.instance.y = this.y;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'y') {
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
this.instance.y = this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,8 @@ GameLib.Plane.prototype.updateInstance = function(property) {
|
||||||
this.instance.constant = this.constant;
|
this.instance.constant = this.constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,6 +53,8 @@ GameLib.Server.prototype.updateInstance = function(property) {
|
||||||
if (property === 'protocols') {
|
if (property === 'protocols') {
|
||||||
console.log('todo: server protocols update');
|
console.log('todo: server protocols update');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,6 +78,7 @@ GameLib.Socket.prototype.updateInstance = function(property) {
|
||||||
if (property === 'server') {
|
if (property === 'server') {
|
||||||
console.log('todo: implement socket server update');
|
console.log('todo: implement socket server update');
|
||||||
}
|
}
|
||||||
|
GameLib.D3.Texture.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1383,7 +1383,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
object,
|
object,
|
||||||
property,
|
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,
|
'cube': GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE,
|
||||||
'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
|
'canvas': GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS
|
||||||
}
|
}
|
||||||
|
@ -1513,6 +1514,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
property === 'volume'
|
property === 'volume'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, 0, 1.0, 0.001));
|
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 (
|
} else if (
|
||||||
property === 'shininess' ||
|
property === 'shininess' ||
|
||||||
property === 'fov'
|
property === 'fov'
|
||||||
|
|
|
@ -29,7 +29,7 @@ GameLib.System.Render = function(
|
||||||
/**
|
/**
|
||||||
* Images
|
* Images
|
||||||
*/
|
*/
|
||||||
this.imageChangedSubscription = null;
|
this.textureUpdatedSubscription = null;
|
||||||
|
|
||||||
this.renderConfigurations = [];
|
this.renderConfigurations = [];
|
||||||
|
|
||||||
|
@ -87,9 +87,9 @@ GameLib.System.Render.prototype.start = function() {
|
||||||
this.windowResize
|
this.windowResize
|
||||||
);
|
);
|
||||||
|
|
||||||
this.imageChangedSubscription = this.subscribe(
|
this.textureUpdatedSubscription = this.subscribe(
|
||||||
GameLib.Event.TEXTURE_IMAGE_UPDATED,
|
GameLib.Event.TEXTURE_INSTANCE_UPDATED,
|
||||||
this.imageChanged
|
this.textureUpdated
|
||||||
);
|
);
|
||||||
|
|
||||||
this.getRenderConfigurationSubscription = this.subscribe(
|
this.getRenderConfigurationSubscription = this.subscribe(
|
||||||
|
@ -189,6 +189,14 @@ GameLib.System.Render.prototype.windowResize = function(data) {
|
||||||
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);
|
var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER);
|
||||||
|
|
||||||
renderers.map(
|
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(
|
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Material).map(
|
||||||
// function(texture) {
|
function(material) {
|
||||||
// if (texture.image ===)
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
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
|
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) {
|
if (configuration.enableComposer) {
|
||||||
composer.render();
|
composer.render();
|
||||||
return;
|
return;
|
||||||
|
@ -559,15 +595,6 @@ GameLib.System.Render.prototype.render = function(data) {
|
||||||
|
|
||||||
function (scene) {
|
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 ||
|
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_TARGET ||
|
||||||
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
|
renderer.renderMode === GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET) {
|
||||||
|
|
||||||
|
@ -632,7 +659,7 @@ GameLib.System.Render.prototype.stop = function() {
|
||||||
/**
|
/**
|
||||||
* Images
|
* Images
|
||||||
*/
|
*/
|
||||||
this.imageChangedSubscription.remove();
|
this.textureUpdatedSubscription.remove();
|
||||||
|
|
||||||
// this.delayedInstanceEncounteredSubscription.remove();
|
// this.delayedInstanceEncounteredSubscription.remove();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue