fog component
parent
02a1365712
commit
43b7be5e37
|
@ -278,6 +278,7 @@ GameLib.Component.COMPONENT_SYSTEM_PHYSICS = 0x46;
|
|||
GameLib.Component.COMPONENT_SYSTEM_RENDER = 0x47;
|
||||
GameLib.Component.COMPONENT_SYSTEM_STORAGE = 0x48;
|
||||
GameLib.Component.COMPONENT_SYSTEM_VISUALIZATION = 0x49;
|
||||
GameLib.Component.COMPONENT_FOG = 0x50;
|
||||
|
||||
/**
|
||||
* Returns string name for component number
|
||||
|
@ -360,6 +361,7 @@ GameLib.Component.GetComponentName = function(number) {
|
|||
case 0x47 : return 'GameLib.D3.System.Render';
|
||||
case 0x48 : return 'GameLib.D3.System.Storage';
|
||||
case 0x49 : return 'GameLib.D3.System.Visualization';
|
||||
case 0x50 : return 'GameLib.D3.Fog';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Raw Fog API object - should always correspond with the Fog Schema
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param exponential
|
||||
* @param color
|
||||
* @param near
|
||||
* @param far
|
||||
* @param density
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Fog = function(
|
||||
id,
|
||||
name,
|
||||
exponential,
|
||||
color,
|
||||
near,
|
||||
far,
|
||||
density,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Fog (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(exponential)) {
|
||||
exponential = false;
|
||||
}
|
||||
this.exponential = exponential;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.API.Color(1, 1, 1, 1)
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 1;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
far = 1000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(density)) {
|
||||
density = 0.00025;
|
||||
}
|
||||
this.density = density;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Fog.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.API.Fog.prototype.constructor = GameLib.D3.API.Fog;
|
||||
|
||||
/**
|
||||
* Returns an API scene from an Object scene
|
||||
* @param objectFog
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Fog.FromObject = function(objectFog) {
|
||||
|
||||
return new GameLib.D3.API.Fog(
|
||||
objectFog.id,
|
||||
objectFog.name,
|
||||
objectFog.exponential,
|
||||
objectFog.color,
|
||||
objectFog.near,
|
||||
objectFog.far,
|
||||
objectFog.density,
|
||||
objectFog.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -7,6 +7,7 @@
|
|||
* @param textures [GameLib.D3.API.Texture]
|
||||
* @param materials [GameLib.D3.API.Material]
|
||||
* @param images
|
||||
* @param fog
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -18,6 +19,7 @@ GameLib.D3.API.Scene = function(
|
|||
textures,
|
||||
materials,
|
||||
images,
|
||||
fog,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
|
@ -56,6 +58,11 @@ GameLib.D3.API.Scene = function(
|
|||
}
|
||||
this.images = images;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(fog)) {
|
||||
fog = null;
|
||||
}
|
||||
this.fog = fog;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
|
@ -147,6 +154,7 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
|
|||
apiTextures,
|
||||
apiMaterials,
|
||||
apiImages,
|
||||
objectScene.fog,
|
||||
objectScene.parentEntity
|
||||
);
|
||||
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
* Fog Superset - The apiFog properties get moved into the Fog object itself, and then the instance is
|
||||
* created
|
||||
* @param graphics
|
||||
* @param apiFog GameLib.D3.API.Fog
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Fog = function (
|
||||
graphics,
|
||||
apiFog
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiFog)) {
|
||||
apiFog = {};
|
||||
}
|
||||
|
||||
if (apiFog instanceof GameLib.D3.Fog) {
|
||||
return apiFog;
|
||||
}
|
||||
|
||||
GameLib.D3.API.Fog.call(
|
||||
this,
|
||||
apiFog.id,
|
||||
apiFog.name,
|
||||
apiFog.exponential,
|
||||
apiFog.color,
|
||||
apiFog.near,
|
||||
apiFog.far,
|
||||
apiFog.density,
|
||||
apiFog.parentEntity
|
||||
);
|
||||
|
||||
this.color = new GameLib.Color(
|
||||
this.graphics,
|
||||
this.color,
|
||||
this
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_FOG
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Fog.prototype = Object.create(GameLib.D3.API.Fog.prototype);
|
||||
GameLib.D3.Fog.prototype.constructor = GameLib.D3.Fog;
|
||||
|
||||
/**
|
||||
* Creates an instance scene
|
||||
* @returns {THREE.Fog}
|
||||
*/
|
||||
GameLib.D3.Fog.prototype.createInstance = function() {
|
||||
|
||||
if (this.exponential) {
|
||||
|
||||
this.instance = new THREE.FogExp2(
|
||||
this.color.instance,
|
||||
this.density
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
this.instance = new THREE.Fog(
|
||||
this.color.instance,
|
||||
this.near,
|
||||
this.far
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Fog.prototype.updateInstance = function() {
|
||||
|
||||
if (
|
||||
this.exponential &&
|
||||
!(this.instance instanceof THREE.FogExp2)
|
||||
) {
|
||||
this.createInstance();
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!this.exponential &&
|
||||
!(this.instance instanceof THREE.Fog)
|
||||
) {
|
||||
this.createInstance();
|
||||
return;
|
||||
}
|
||||
|
||||
this.instance.color = this.color.instance;
|
||||
|
||||
if (this.instance instanceof THREE.Fog) {
|
||||
this.instance.near = this.near;
|
||||
this.instance.far = this.far;
|
||||
}
|
||||
|
||||
if (this.instance instanceof THREE.FogExp2) {
|
||||
this.instance.density = this.density;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Fog to a GameLib.D3.API.Fog
|
||||
* @returns {GameLib.D3.API.Fog}
|
||||
*/
|
||||
GameLib.D3.Fog.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.D3.API.Fog(
|
||||
this.id,
|
||||
this.name,
|
||||
this.exponential,
|
||||
this.color.toApiObject(),
|
||||
this.near,
|
||||
this.far,
|
||||
this.density,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a scene Object to a GameLib.D3.Fog object
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectFog Object
|
||||
* @returns {GameLib.D3.Fog}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Fog.FromObject = function(
|
||||
graphics,
|
||||
objectFog
|
||||
) {
|
||||
var apiFog = GameLib.D3.API.Fog.FromObject(objectFog);
|
||||
|
||||
return new GameLib.D3.Fog(
|
||||
graphics,
|
||||
apiFog
|
||||
);
|
||||
};
|
|
@ -29,6 +29,7 @@ GameLib.D3.Scene = function (
|
|||
apiScene.textures,
|
||||
apiScene.materials,
|
||||
apiScene.images,
|
||||
apiScene.fog,
|
||||
apiScene.parentEntity
|
||||
);
|
||||
|
||||
|
@ -123,6 +124,13 @@ GameLib.D3.Scene = function (
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.fog instanceof GameLib.D3.API.Fog) {
|
||||
this.fog = new GameLib.D3.Fog(
|
||||
this.graphics,
|
||||
this.fog
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
|
||||
* @type {Array}
|
||||
|
@ -137,7 +145,8 @@ GameLib.D3.Scene = function (
|
|||
'lights' : [GameLib.D3.Light],
|
||||
'textures' : [GameLib.D3.Texture],
|
||||
'materials' : [GameLib.D3.Material],
|
||||
'images' : [GameLib.D3.Image]
|
||||
'images' : [GameLib.D3.Image],
|
||||
'fog' : GameLib.D3.Fog
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@ -155,6 +164,10 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
|||
|
||||
this.instance.name = this.name;
|
||||
|
||||
if (this.fog && this.fog.instance) {
|
||||
this.instance.fog = this.fog.instance;
|
||||
}
|
||||
|
||||
this.meshes.map(
|
||||
function(mesh) {
|
||||
|
||||
|
@ -196,6 +209,10 @@ GameLib.D3.Scene.prototype.updateInstance = function() {
|
|||
|
||||
this.instance.name = this.name;
|
||||
|
||||
if (this.instance.fog !== this.fog.instance) {
|
||||
this.instance.fog = this.fog.instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing meshes
|
||||
*/
|
||||
|
@ -297,6 +314,7 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
|
|||
apiTextures,
|
||||
apiMaterials,
|
||||
apiImages,
|
||||
GameLib.Utils.IdOrNull(this.fog),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1127,7 +1127,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
property === 'depth' ||
|
||||
property === 'radius'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
|
||||
controllers.push(folder.add(object, property, 0, 1000, 0.1));
|
||||
} else if (
|
||||
property === 'near' ||
|
||||
property === 'distanceGrain' ||
|
||||
|
@ -1147,6 +1147,11 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
property === 'friction'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, 0, 1000, 0.01));
|
||||
} else if (
|
||||
property === 'radiusTop' ||
|
||||
property === 'radiusBottom'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, 0, 100, 0.1));
|
||||
} else if (
|
||||
property === 'mass'
|
||||
) {
|
||||
|
|
|
@ -505,7 +505,7 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
|
|||
};
|
||||
|
||||
GameLib.System.Input.prototype.onMouseDown = function(event) {
|
||||
console.log('mouse down');
|
||||
// console.log('mouse down');
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.MOUSE_DOWN,
|
||||
|
@ -516,7 +516,7 @@ GameLib.System.Input.prototype.onMouseDown = function(event) {
|
|||
};
|
||||
|
||||
GameLib.System.Input.prototype.onMouseMove = function(event) {
|
||||
console.log('mouse move');
|
||||
// console.log('mouse move');
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.MOUSE_MOVE,
|
||||
{
|
||||
|
@ -526,7 +526,7 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
|
|||
};
|
||||
|
||||
GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
||||
console.log('mouse wheel');
|
||||
// console.log('mouse wheel');
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.MOUSE_WHEEL,
|
||||
{
|
||||
|
@ -536,7 +536,7 @@ GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
|||
};
|
||||
|
||||
GameLib.System.Input.prototype.onMouseUp = function(event) {
|
||||
console.log('mouse up');
|
||||
// console.log('mouse up');
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.MOUSE_UP,
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue