runtime vectors and colors complete
parent
48c093a72a
commit
46a00d4fb1
|
@ -0,0 +1,6 @@
|
|||
GameLib.D3.API.Color = function Color(r, g, b, a) {
|
||||
this.r = r || 1;
|
||||
this.g = g || 1;
|
||||
this.b = b || 1;
|
||||
this.a = a || 0;
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
GameLib.D3.API.Vector2 = function Vector2(x, y) {
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
GameLib.D3.API.Vector4 = function Vector4(x, y, z, w) {
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
this.z = z || 0;
|
||||
this.w = w || 1;
|
||||
};
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
||||
* @param id
|
||||
* @param object GameLib.D3.Object
|
||||
* @param name
|
||||
* @param graphics
|
||||
* @param helperType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Helper = function Helper(
|
||||
id,
|
||||
object,
|
||||
helperType,
|
||||
name,
|
||||
graphics
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Tools.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(object)) {
|
||||
throw new Error('Cannot create helpers for unknown objects');
|
||||
}
|
||||
this.object = object;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(helperType)) {
|
||||
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
||||
}
|
||||
this.helperType = helperType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Helper (' + this.helperType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper types
|
||||
* @type {string}
|
||||
*/
|
||||
GameLib.D3.Helper.HELPER_TYPE_EDGES = 'edges';
|
||||
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 'directional-light';
|
||||
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 'spot-light';
|
||||
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 'point-light';
|
||||
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 'wireframe';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a helper instance
|
||||
* @param update
|
||||
*/
|
||||
GameLib.D3.Helper.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
||||
instance = new this.graphics.instance.EdgesHelper(this.object.instance, 0x007700);
|
||||
}
|
||||
|
||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
||||
instance = new this.graphics.instance.DirectionalLightHelper(this.object.instance);
|
||||
}
|
||||
|
||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT) {
|
||||
instance = new this.graphics.instance.PointLightHelper(this.object.instance, 1);
|
||||
}
|
||||
|
||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT) {
|
||||
instance = new this.graphics.instance.SpotLightHelper(this.object.instance);
|
||||
}
|
||||
|
||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
|
||||
instance = new this.graphics.instance.WireframeHelper(this.object.instance, 0x007700);
|
||||
}
|
||||
|
||||
if (!instance) {
|
||||
throw new Error('Unsupported helper type: ' + this.helperType);
|
||||
}
|
||||
|
||||
if (update) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
|
@ -299,18 +299,19 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
|||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
|
||||
instance.rotation.x = this.rotation.x;
|
||||
instance.rotation.y = this.rotation.y;
|
||||
instance.rotation.z = this.rotation.z;
|
||||
|
||||
instance.scale.x = this.scale.x;
|
||||
instance.scale.y = this.scale.y;
|
||||
instance.scale.z = this.scale.z;
|
||||
|
||||
// instance.quaternion.x = this.quaternion.x;
|
||||
// instance.quaternion.y = this.quaternion.y;
|
||||
// instance.quaternion.z = this.quaternion.z;
|
||||
// instance.quaternion.w = this.quaternion.w;
|
||||
// we don't do rotation since it interferes with the quaternion update
|
||||
// instance.rotation.x = this.rotation.x;
|
||||
// instance.rotation.y = this.rotation.y;
|
||||
// instance.rotation.z = this.rotation.z;
|
||||
|
||||
instance.quaternion.x = this.quaternion.x;
|
||||
instance.quaternion.y = this.quaternion.y;
|
||||
instance.quaternion.z = this.quaternion.z;
|
||||
instance.quaternion.w = this.quaternion.w;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Runtime color for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param color GameLib.D3.Color
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Runtime.Color = function RuntimeColor(graphics, parentObject, color, grain) {
|
||||
|
||||
for (var property in color) {
|
||||
if (color.hasOwnProperty(property)) {
|
||||
this[property] = color[property];
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Color, GameLib.D3.Color);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an instance color
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Runtime.Color.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.r = this.r;
|
||||
instance.g = this.g;
|
||||
instance.b = this.b;
|
||||
instance.a = this.a;
|
||||
} else {
|
||||
instance = new this.graphics.instance.Color(this.r, this.g, this.b, this.a);
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance color, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Runtime.Color.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts runtime color to API Color
|
||||
* @returns {GameLib.D3.API.Color}
|
||||
*/
|
||||
GameLib.D3.Runtime.Color.prototype.toApiColor = function() {
|
||||
return new GameLib.D3.API.Color(
|
||||
this.r,
|
||||
this.g,
|
||||
this.b,
|
||||
this.a
|
||||
);
|
||||
};
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* Runtime vector2 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param vector2 GameLib.D3.Vector2
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector2 = function RuntimeVector2(graphics, parentObject, vector2, grain) {
|
||||
|
||||
for (var property in vector2) {
|
||||
if (vector2.hasOwnProperty(property)) {
|
||||
this[property] = vector2[property];
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector2, GameLib.D3.Vector2);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an instance vector2
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector2.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
} else {
|
||||
instance = new this.graphics.instance.Vector2(this.x, this.y);
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector2.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
* @returns {GameLib.D3.API.Vector2}
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector2.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.API.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
};
|
|
@ -68,7 +68,7 @@ GameLib.D3.Runtime.Vector3.prototype.updateInstance = function() {
|
|||
* @returns {GameLib.D3.API.Vector3}
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector3.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.Api.Vector3(
|
||||
return new GameLib.D3.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Runtime vector4 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param vector4 GameLib.D3.Vector4
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector4 = function RuntimeVector4(graphics, parentObject, vector4, grain) {
|
||||
|
||||
for (var property in vector4) {
|
||||
if (vector4.hasOwnProperty(property)) {
|
||||
this[property] = vector4[property];
|
||||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector4, GameLib.D3.Vector4);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an instance vector4
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector4.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
instance.x = this.x;
|
||||
instance.y = this.y;
|
||||
instance.z = this.z;
|
||||
instance.w = this.w;
|
||||
} else {
|
||||
instance = new this.graphics.instance.Vector4(this.x, this.y, this.z, this.w);
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector4.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
if (this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
* @returns {GameLib.D3.API.Vector4}
|
||||
*/
|
||||
GameLib.D3.Runtime.Vector4.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.API.Vector4(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
};
|
|
@ -278,7 +278,7 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
|
||||
var apiTexture = apiMaps[map].texture;
|
||||
|
||||
gameLibTextureMap[map].texture = new GameLib.D3.Texture(
|
||||
var texture = new GameLib.D3.Texture(
|
||||
new GameLib.D3.API.Texture(
|
||||
apiTexture.id,
|
||||
map,
|
||||
|
@ -313,6 +313,20 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
gameLibTextureMap[map].instanceMapId,
|
||||
imageFactory
|
||||
);
|
||||
|
||||
texture.offset = new GameLib.D3.Runtime.Vector2(
|
||||
graphics,
|
||||
texture,
|
||||
texture.offset
|
||||
);
|
||||
|
||||
texture.repeat = new GameLib.D3.Runtime.Vector2(
|
||||
graphics,
|
||||
texture,
|
||||
texture.repeat
|
||||
);
|
||||
|
||||
gameLibTextureMap[map].texture = texture;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -399,18 +413,31 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
gameLibMesh.position
|
||||
);
|
||||
|
||||
gameLibMesh.rotation = new GameLib.D3.Runtime.Vector3(
|
||||
graphics,
|
||||
gameLibMesh,
|
||||
gameLibMesh.rotation
|
||||
);
|
||||
|
||||
gameLibMesh.scale = new GameLib.D3.Runtime.Vector3(
|
||||
graphics,
|
||||
gameLibMesh,
|
||||
gameLibMesh.scale
|
||||
);
|
||||
|
||||
gameLibMesh.up = new GameLib.D3.Runtime.Vector3(
|
||||
graphics,
|
||||
gameLibMesh,
|
||||
gameLibMesh.up
|
||||
);
|
||||
|
||||
// we don't do rotation since it interferes with the quaternion update
|
||||
// gameLibMesh.rotation = new GameLib.D3.Runtime.Vector3(
|
||||
// graphics,
|
||||
// gameLibMesh,
|
||||
// gameLibMesh.rotation
|
||||
// );
|
||||
|
||||
gameLibMesh.quaternion = new GameLib.D3.Runtime.Vector4(
|
||||
graphics,
|
||||
gameLibMesh,
|
||||
gameLibMesh.quaternion
|
||||
);
|
||||
|
||||
gameLibMeshes.push(gameLibMesh);
|
||||
|
||||
meshIdToMesh[gameLibMesh.id] = gameLibMesh;
|
||||
|
|
|
@ -163,6 +163,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
|||
instance.flipY = this.flipY;
|
||||
instance.offset.x = this.offset.x;
|
||||
instance.offset.y = this.offset.y;
|
||||
instance.repeat.x = this.repeat.x;
|
||||
instance.repeat.y = this.repeat.y;
|
||||
instance.mipmaps = this.mipmaps;
|
||||
instance.unpackAlignment = this.unpackAlignment;
|
||||
instance.premultiplyAlpha = this.premultiplyAlpha;
|
||||
|
|
Loading…
Reference in New Issue