huge refactorings - vector fixes
parent
90622a80d9
commit
b543c586e4
|
@ -35,7 +35,7 @@ GameLib.D3.API.Camera = function(
|
||||||
maxZ
|
maxZ
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
GameLib.D3.API.Color = function Color(r, g, b, a) {
|
GameLib.D3.API.Color = function Color(r, g, b, a) {
|
||||||
this.r = r || 1;
|
|
||||||
this.g = g || 1;
|
if (GameLib.D3.Utils.UndefinedOrNull(r)) {
|
||||||
this.b = b || 1;
|
r = 1;
|
||||||
this.a = a || 0;
|
}
|
||||||
|
this.r = r;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(g)) {
|
||||||
|
g = 1;
|
||||||
|
}
|
||||||
|
this.g = g;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(b)) {
|
||||||
|
b = 1;
|
||||||
|
}
|
||||||
|
this.b = b;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(a)) {
|
||||||
|
a = 0;
|
||||||
|
}
|
||||||
|
this.a = a;
|
||||||
|
|
||||||
};
|
};
|
|
@ -79,7 +79,7 @@ GameLib.D3.API.ComponentInterface = function(
|
||||||
maxSteerAngle
|
maxSteerAngle
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ GameLib.D3.API.Entity = function Entity(
|
||||||
mesh
|
mesh
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
@ -88,17 +88,17 @@ GameLib.D3.Entity = function Entity(
|
||||||
this.mesh = null;
|
this.mesh = null;
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(position)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||||
position = new GameLib.D3.Vector3(0, 0, 0);
|
position = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||||
}
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||||
quaternion = new GameLib.D3.Vector4(0, 0, 0, 1);
|
quaternion = new GameLib.D3.API.Vector4(0, 0, 0, 1);
|
||||||
}
|
}
|
||||||
this.quaternion = quaternion;
|
this.quaternion = quaternion;
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||||
scale = new GameLib.D3.Vector3(1, 1, 1);
|
scale = new GameLib.D3.API.Vector3(1, 1, 1);
|
||||||
}
|
}
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
};
|
};
|
|
@ -35,7 +35,7 @@ GameLib.D3.API.Light = function(
|
||||||
penumbra
|
penumbra
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ GameLib.D3.API.Material = function(
|
||||||
envMapIntensity
|
envMapIntensity
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ GameLib.D3.API.Mesh = function(
|
||||||
up
|
up
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* @param shapes GameLib.D3.API.Shape[]
|
* @param shapes GameLib.D3.API.Shape[]
|
||||||
* @param cameras
|
* @param cameras
|
||||||
* @param activeCameraIndex
|
* @param activeCameraIndex
|
||||||
|
* @param splines GameLib.D3.API.Spline[]
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Scene = function(
|
GameLib.D3.API.Scene = function(
|
||||||
|
@ -38,7 +39,7 @@ GameLib.D3.API.Scene = function(
|
||||||
splines
|
splines
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.API.Spline = function(
|
||||||
vertices
|
vertices
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ GameLib.D3.API.Texture = function(
|
||||||
encoding
|
encoding
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
GameLib.D3.API.Vector2 = function Vector2(x, y) {
|
GameLib.D3.API.Vector2 = function Vector2(x, y) {
|
||||||
this.x = x || 0;
|
this.x = x || 0;
|
||||||
this.y = y || 0;
|
this.y = y || 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Vector2.prototype.copy = function () {
|
||||||
|
return new GameLib.D3.API.Vector2(
|
||||||
|
this.x,
|
||||||
|
this.y
|
||||||
|
);
|
||||||
};
|
};
|
|
@ -18,13 +18,13 @@ GameLib.D3.Camera = function Camera(
|
||||||
|
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
this.position = new GameLib.D3.Runtime.Vector3(
|
this.position = new GameLib.D3.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.position
|
this.position
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lookAt = new GameLib.D3.Runtime.Vector3(
|
this.lookAt = new GameLib.D3.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.lookAt
|
this.lookAt
|
||||||
|
@ -55,9 +55,7 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
instance = this.instance;
|
instance = this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance ||
|
if (!instance) {
|
||||||
(instance && this.cameraType != instance.cameraType)
|
|
||||||
) {
|
|
||||||
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
||||||
instance = new this.graphics.instance.PerspectiveCamera(
|
instance = new this.graphics.instance.PerspectiveCamera(
|
||||||
this.fov,
|
this.fov,
|
||||||
|
@ -77,7 +75,7 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update && this.cameraType == instance.cameraType) {
|
if (update) {
|
||||||
instance.minX = this.minX;
|
instance.minX = this.minX;
|
||||||
instance.maxX = this.maxX;
|
instance.maxX = this.maxX;
|
||||||
instance.minY = this.minY;
|
instance.minY = this.minY;
|
||||||
|
@ -90,21 +88,9 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
instance.far = this.far;
|
instance.far = this.far;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
instance.position.copy(this.position.instance);
|
||||||
instance.cameraType = this.cameraType;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.lookAt(this.lookAt.instance);
|
||||||
instance.position.y = this.position.y;
|
|
||||||
instance.position.z = this.position.z;
|
|
||||||
|
|
||||||
instance.lookAt(
|
|
||||||
new this.graphics.instance.Vector3(
|
|
||||||
this.lookAt.x,
|
|
||||||
this.lookAt.y,
|
|
||||||
this.lookAt.z
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
instance.updateProjectionMatrix();
|
instance.updateProjectionMatrix();
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Color = function RuntimeColor(graphics, parentObject, color, grain) {
|
GameLib.D3.Color = function RuntimeColor(graphics, parentObject, color, grain) {
|
||||||
|
|
||||||
for (var property in color) {
|
for (var property in color) {
|
||||||
if (color.hasOwnProperty(property)) {
|
if (color.hasOwnProperty(property)) {
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Color = function RuntimeColor(graphics, parentObject, color,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Color, GameLib.D3.API.Color);
|
GameLib.D3.Utils.Extend(GameLib.D3.Color, GameLib.D3.API.Color);
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ GameLib.D3.Runtime.Color = function RuntimeColor(graphics, parentObject, color,
|
||||||
* @param update
|
* @param update
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Color.prototype.createInstance = function(update) {
|
GameLib.D3.Color.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ GameLib.D3.Runtime.Color.prototype.createInstance = function(update) {
|
||||||
/**
|
/**
|
||||||
* Updates the instance color, calls updateInstance on the parent object
|
* Updates the instance color, calls updateInstance on the parent object
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Color.prototype.updateInstance = function() {
|
GameLib.D3.Color.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ GameLib.D3.Runtime.Color.prototype.updateInstance = function() {
|
||||||
* Converts runtime color to API Color
|
* Converts runtime color to API Color
|
||||||
* @returns {GameLib.D3.API.Color}
|
* @returns {GameLib.D3.API.Color}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Color.prototype.toApiColor = function() {
|
GameLib.D3.Color.prototype.toApiColor = function() {
|
||||||
return new GameLib.D3.API.Color(
|
return new GameLib.D3.API.Color(
|
||||||
this.r,
|
this.r,
|
||||||
this.g,
|
this.g,
|
||||||
|
@ -80,7 +80,7 @@ GameLib.D3.Runtime.Color.prototype.toApiColor = function() {
|
||||||
* Converts the current color to HTML hex format (ex. #ffffff)
|
* Converts the current color to HTML hex format (ex. #ffffff)
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Color.prototype.toHex = function() {
|
GameLib.D3.Color.prototype.toHex = function() {
|
||||||
|
|
||||||
if (this.r < 0) {
|
if (this.r < 0) {
|
||||||
this.r = 0;
|
this.r = 0;
|
||||||
|
@ -123,4 +123,18 @@ GameLib.D3.Runtime.Color.prototype.toHex = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return '#' + rf + gf + bf;
|
return '#' + rf + gf + bf;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets this object color to what the hex value is
|
||||||
|
* @param hex
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Color.prototype.fromHex = function(hex) {
|
||||||
|
|
||||||
|
var matches = hex.match(new RegExp('#+(..)(..)(..)'));
|
||||||
|
|
||||||
|
this.r = parseInt(matches[1], 16) / 255.0;
|
||||||
|
this.g = parseInt(matches[2], 16) / 255.0;
|
||||||
|
this.b = parseInt(matches[3], 16) / 255.0;
|
||||||
};
|
};
|
|
@ -11,7 +11,7 @@ GameLib.D3.ComponentCamera = function ComponentCamera(
|
||||||
name,
|
name,
|
||||||
camera
|
camera
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentColorFlash = function ComponentColorFlash(
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -5,7 +5,7 @@ GameLib.D3.ComponentColorLerp = function(
|
||||||
endColor,
|
endColor,
|
||||||
lerpSpeed
|
lerpSpeed
|
||||||
) {
|
) {
|
||||||
this.id = id|| GameLib.D3.Tools.RandomId();
|
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent(
|
||||||
parent,
|
parent,
|
||||||
centerToOrigin
|
centerToOrigin
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
|
||||||
quaternionOffset,
|
quaternionOffset,
|
||||||
scaleOffset
|
scaleOffset
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
@ -24,17 +24,17 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
||||||
positionOffset = new GameLib.D3.Vector3(0, 0, 0);
|
positionOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||||
} this.positionOffset = positionOffset;
|
} this.positionOffset = positionOffset;
|
||||||
|
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||||
quaternionOffset = new GameLib.D3.Vector4(0, 0, 0, 1);
|
quaternionOffset = new GameLib.D3.API.Vector4(0, 0, 0, 1);
|
||||||
} this.quaternionOffset = quaternionOffset;
|
} this.quaternionOffset = quaternionOffset;
|
||||||
|
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
||||||
scaleOffset = new GameLib.D3.Vector3(1, 1, 1);
|
scaleOffset = new GameLib.D3.API.Vector3(1, 1, 1);
|
||||||
} this.scaleOffset = scaleOffset;
|
} this.scaleOffset = scaleOffset;
|
||||||
|
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface);
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface);
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentFlyControls = function ComponentFlyControls(
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -16,7 +16,7 @@ GameLib.D3.ComponentFollow = function ComponentFollow(
|
||||||
minDistance,
|
minDistance,
|
||||||
moveSpeed
|
moveSpeed
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentInterface = function ComponentInterface(
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentLookAt = function ComponentLookAt(
|
||||||
targetOffset,
|
targetOffset,
|
||||||
rotationSpeed
|
rotationSpeed
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
||||||
quaternionOffset,
|
quaternionOffset,
|
||||||
scaleOffset
|
scaleOffset
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
@ -23,9 +23,9 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
||||||
|
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
|
||||||
this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0);
|
this.positionOffset = positionOffset || new GameLib.D3.API.Vector3(0, 0, 0);
|
||||||
this.quaternionOffset = quaternionOffset || new GameLib.D3.Vector4(0, 0, 0, 1);
|
this.quaternionOffset = quaternionOffset || new GameLib.D3.API.Vector4(0, 0, 0, 1);
|
||||||
this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(1, 1, 1);
|
this.scaleOffset = scaleOffset || new GameLib.D3.API.Vector3(1, 1, 1);
|
||||||
|
|
||||||
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
|
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface);
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param axis {GameLib.D3.Vector3}
|
* @param axis {GameLib.D3.API.Vector3}
|
||||||
* @param getOffsetFunc {function}
|
* @param getOffsetFunc {function}
|
||||||
* @param userData {Object}
|
* @param userData {Object}
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
|
||||||
getOffsetFunc,
|
getOffsetFunc,
|
||||||
userData
|
userData
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
@ -22,7 +22,7 @@ GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
|
||||||
this.axis = axis || new GameLib.D3.Vector3();
|
this.axis = axis || new GameLib.D3.API.Vector3();
|
||||||
this.offset = 1;
|
this.offset = 1;
|
||||||
var component = this;
|
var component = this;
|
||||||
this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return component.offset; };
|
this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return component.offset; };
|
||||||
|
|
|
@ -10,7 +10,7 @@ GameLib.D3.ComponentPathAI = function ComponentPathAI(
|
||||||
name,
|
name,
|
||||||
sensorLength
|
sensorLength
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentPathControls = function ComponentPathControls(
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -22,7 +22,7 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
|
||||||
maxOffset,
|
maxOffset,
|
||||||
steeringSpeed
|
steeringSpeed
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
@ -37,16 +37,16 @@ GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
|
||||||
this.maxSpeed = maxSpeed || 10.0;
|
this.maxSpeed = maxSpeed || 10.0;
|
||||||
this.accel = accel || 2.0;
|
this.accel = accel || 2.0;
|
||||||
|
|
||||||
this.baseOffset = baseOffset || new GameLib.D3.Vector3();
|
this.baseOffset = baseOffset || new GameLib.D3.API.Vector3();
|
||||||
this.maxOffset = maxOffset || new GameLib.D3.Vector3(10, 10, 10);
|
this.maxOffset = maxOffset || new GameLib.D3.API.Vector3(10, 10, 10);
|
||||||
this.steeringSpeed = steeringSpeed || 1.0;
|
this.steeringSpeed = steeringSpeed || 1.0;
|
||||||
|
|
||||||
|
|
||||||
// runtime code
|
// runtime code
|
||||||
|
|
||||||
//#ifdef RUNTIME__
|
//#ifdef RUNTIME__
|
||||||
this.offset = new GameLib.D3.Vector3(); // this one is our destination offset
|
this.offset = new GameLib.D3.API.Vector3(); // this one is our destination offset
|
||||||
this.currentOffset = new GameLib.D3.Vector3();
|
this.currentOffset = new GameLib.D3.API.Vector3();
|
||||||
this.currentPathValue = 0.0;
|
this.currentPathValue = 0.0;
|
||||||
this.currentSpeed = 0.0;
|
this.currentSpeed = 0.0;
|
||||||
this.direction = 0;
|
this.direction = 0;
|
||||||
|
|
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentRaycastVehicleControls = function ComponentRaycastVehicleCon
|
||||||
maxForce,
|
maxForce,
|
||||||
steering
|
steering
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param name
|
* @param name
|
||||||
* @param axis {GameLib.D3.Vector3}
|
* @param axis {GameLib.D3.API.Vector3}
|
||||||
* @param getRotationFunc {Function}
|
* @param getRotationFunc {Function}
|
||||||
* @param userData {Object}
|
* @param userData {Object}
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentRotator = function ComponentRotator(
|
||||||
getRotationFunc,
|
getRotationFunc,
|
||||||
userData
|
userData
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
@ -24,7 +24,7 @@ GameLib.D3.ComponentRotator = function ComponentRotator(
|
||||||
|
|
||||||
this.rotation = 0;
|
this.rotation = 0;
|
||||||
var component = this;
|
var component = this;
|
||||||
this.axis = axis || new GameLib.D3.Vector3();
|
this.axis = axis || new GameLib.D3.API.Vector3();
|
||||||
this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return component.rotation; };
|
this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return component.rotation; };
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ GameLib.D3.ComponentTriggerBoxBox = function ComponentTriggerBoxBox(
|
||||||
) {
|
) {
|
||||||
console.log('triggerbox box!');
|
console.log('triggerbox box!');
|
||||||
|
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -11,7 +11,7 @@ GameLib.D3.ComponentTriggerBoxSphere = function ComponentTriggerBoxSphere(
|
||||||
onLeave,
|
onLeave,
|
||||||
onSetParent
|
onSetParent
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -21,7 +21,7 @@ GameLib.D3.ComponentTriggerSphereSphere = function ComponentTriggerSphereSphere(
|
||||||
onLeave,
|
onLeave,
|
||||||
onSetParent
|
onSetParent
|
||||||
) {
|
) {
|
||||||
this.id = id || GameLib.D3.Tools.RandomId();
|
this.id = id || GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
|
|
|
@ -10,7 +10,7 @@ GameLib.D3.ComponentVehicleAIObjectAvoidance = function(
|
||||||
name,
|
name,
|
||||||
world
|
world
|
||||||
) {
|
) {
|
||||||
this.id = id|| GameLib.D3.Tools.RandomId();
|
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ GameLib.D3.ComponentVehicleAIPathSteering = function(
|
||||||
steeringSpeed,
|
steeringSpeed,
|
||||||
maxSteerAngle
|
maxSteerAngle
|
||||||
) {
|
) {
|
||||||
this.id = id|| GameLib.D3.Tools.RandomId();
|
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||||
if (typeof name == 'undefined') {
|
if (typeof name == 'undefined') {
|
||||||
name = this.constructor.name;
|
name = this.constructor.name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ GameLib.D3.Helper = function Helper(
|
||||||
graphics
|
graphics
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ GameLib.D3.Image = function(
|
||||||
contentType
|
contentType
|
||||||
) {
|
) {
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.D3.Tools.RandomId();
|
id = GameLib.D3.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
|
|
@ -14,40 +14,40 @@ GameLib.D3.Light = function Light(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.color = new GameLib.D3.Runtime.Color(
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.color = new GameLib.D3.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.color,
|
this.color,
|
||||||
0.01
|
0.01
|
||||||
);
|
);
|
||||||
|
|
||||||
this.position = new GameLib.D3.Runtime.Vector3(
|
this.position = new GameLib.D3.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.position
|
this.position
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetPosition = new GameLib.D3.Runtime.Vector3(
|
this.targetPosition = new GameLib.D3.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.targetPosition
|
this.targetPosition
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.D3.Runtime.Vector3(
|
this.scale = new GameLib.D3.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.scale
|
this.scale
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.D3.Runtime.Vector4(
|
this.quaternion = new GameLib.D3.Vector4(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.quaternion
|
this.quaternion
|
||||||
);
|
);
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,33 +76,21 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
||||||
instance = new this.graphics.instance.AmbientLight(
|
instance = new this.graphics.instance.AmbientLight(
|
||||||
new this.graphics.instance.Color(
|
this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
instance = new this.graphics.instance.DirectionalLight(
|
instance = new this.graphics.instance.DirectionalLight(
|
||||||
new this.graphics.instance.Color(
|
this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
instance = new this.graphics.instance.PointLight(
|
instance = new this.graphics.instance.PointLight(
|
||||||
new this.graphics.instance.Color(
|
this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
instance.distance = this.distance;
|
instance.distance = this.distance;
|
||||||
|
@ -111,11 +99,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
||||||
instance = new this.graphics.instance.SpotLight(
|
instance = new this.graphics.instance.SpotLight(
|
||||||
new this.graphics.instance.Color(
|
this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
instance.distance = this.distance;
|
instance.distance = this.distance;
|
||||||
|
@ -134,24 +118,15 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.position.copy(this.position.instance);
|
||||||
instance.position.y = this.position.y;
|
|
||||||
instance.position.z = this.position.z;
|
|
||||||
|
|
||||||
instance.scale.x = this.scale.x;
|
instance.scale.copy(this.scale.instance);
|
||||||
instance.scale.y = this.scale.y;
|
|
||||||
instance.scale.z = this.scale.z;
|
|
||||||
|
|
||||||
if (instance.target) {
|
if (instance.target) {
|
||||||
instance.target.x = this.targetPosition.x;
|
instance.target.position.copy(this.targetPosition.instance);
|
||||||
instance.target.y = this.targetPosition.y;
|
|
||||||
instance.target.z = this.targetPosition.z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.quaternion.x = this.quaternion.x;
|
instance.quaternion.copy(this.quaternion.instance);
|
||||||
instance.quaternion.y = this.quaternion.y;
|
|
||||||
instance.quaternion.z = this.quaternion.z;
|
|
||||||
instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
instance.intensity = this.intensity;
|
instance.intensity = this.intensity;
|
||||||
|
|
||||||
|
|
|
@ -16,27 +16,27 @@ GameLib.D3.Material = function Material(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.specular = new GameLib.D3.Runtime.Color(
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.specular = new GameLib.D3.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.specular
|
this.specular
|
||||||
);
|
);
|
||||||
|
|
||||||
this.color = new GameLib.D3.Runtime.Color(
|
this.color = new GameLib.D3.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.color
|
this.color
|
||||||
);
|
);
|
||||||
|
|
||||||
this.emissive = new GameLib.D3.Runtime.Color(
|
this.emissive = new GameLib.D3.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.emissive
|
this.emissive
|
||||||
);
|
);
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
this.needsUpdate = false;
|
this.needsUpdate = false;
|
||||||
|
@ -150,10 +150,7 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
instance = this.instance;
|
instance = this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!instance) {
|
||||||
(!instance) ||
|
|
||||||
(instance && instance.type != this.materialType)
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||||
|
|
||||||
|
@ -177,20 +174,12 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
overdraw: this.overdraw,
|
overdraw: this.overdraw,
|
||||||
visible: this.visible,
|
visible: this.visible,
|
||||||
side: this.side,
|
side: this.side,
|
||||||
color: new this.graphics.instance.Color(
|
color: this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
roughness: this.roughness,
|
roughness: this.roughness,
|
||||||
metalness: this.metalness,
|
metalness: this.metalness,
|
||||||
lightMapIntensity: this.lightMapIntensity,
|
lightMapIntensity: this.lightMapIntensity,
|
||||||
aoMapIntensity: this.aoMapIntensity,
|
aoMapIntensity: this.aoMapIntensity,
|
||||||
emissive: new this.graphics.instance.Color(
|
emissive: this.emissive.instance,
|
||||||
this.emissive.r,
|
|
||||||
this.emissive.g,
|
|
||||||
this.emissive.b
|
|
||||||
),
|
|
||||||
emissiveIntensity: this.emissiveIntensity,
|
emissiveIntensity: this.emissiveIntensity,
|
||||||
bumpScale: this.bumpScale,
|
bumpScale: this.bumpScale,
|
||||||
normalScale: this.normalScale,
|
normalScale: this.normalScale,
|
||||||
|
@ -230,24 +219,12 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
overdraw: this.overdraw,
|
overdraw: this.overdraw,
|
||||||
visible: this.visible,
|
visible: this.visible,
|
||||||
side: this.side,
|
side: this.side,
|
||||||
color: new this.graphics.instance.Color(
|
color: this.color.instance,
|
||||||
this.color.r,
|
specular: this.specular.instance,
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
specular: new this.graphics.instance.Color(
|
|
||||||
this.specular.r,
|
|
||||||
this.specular.g,
|
|
||||||
this.specular.b
|
|
||||||
),
|
|
||||||
shininess: this.shininess,
|
shininess: this.shininess,
|
||||||
lightMapIntensity: this.lightMapIntensity,
|
lightMapIntensity: this.lightMapIntensity,
|
||||||
aoMapIntensity: this.aoMapIntensity,
|
aoMapIntensity: this.aoMapIntensity,
|
||||||
emissive: new this.graphics.instance.Color(
|
emissive: this.emissive.instance,
|
||||||
this.emissive.r,
|
|
||||||
this.emissive.g,
|
|
||||||
this.emissive.b
|
|
||||||
),
|
|
||||||
emissiveIntensity: this.emissiveIntensity,
|
emissiveIntensity: this.emissiveIntensity,
|
||||||
bumpScale: this.bumpScale,
|
bumpScale: this.bumpScale,
|
||||||
normalScale: this.normalScale,
|
normalScale: this.normalScale,
|
||||||
|
@ -287,11 +264,7 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
overdraw: this.overdraw,
|
overdraw: this.overdraw,
|
||||||
visible: this.visible,
|
visible: this.visible,
|
||||||
side: this.side,
|
side: this.side,
|
||||||
color: new this.graphics.instance.Color(
|
color: this.color.instance,
|
||||||
this.color.r,
|
|
||||||
this.color.g,
|
|
||||||
this.color.b
|
|
||||||
),
|
|
||||||
size: this.pointSize,
|
size: this.pointSize,
|
||||||
sizeAttenuation: this.pointSizeAttenuation,
|
sizeAttenuation: this.pointSizeAttenuation,
|
||||||
vertexColors: GameLib.D3.Material.TYPE_NO_COLORS,
|
vertexColors: GameLib.D3.Material.TYPE_NO_COLORS,
|
||||||
|
@ -319,7 +292,11 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
this.hasOwnProperty(property) &&
|
this.hasOwnProperty(property) &&
|
||||||
instance.hasOwnProperty(property)
|
instance.hasOwnProperty(property)
|
||||||
) {
|
) {
|
||||||
instance[property] = this[property];
|
if (instance[property] instanceof THREE.Color) {
|
||||||
|
instance[property].copy(this[property])
|
||||||
|
} else {
|
||||||
|
instance[property] = this[property];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,25 +20,39 @@ GameLib.D3.Mesh = function Mesh(
|
||||||
|
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.position = new GameLib.D3.Vector3(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.position
|
||||||
|
);
|
||||||
|
|
||||||
|
this.scale = new GameLib.D3.Vector3(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.scale
|
||||||
|
);
|
||||||
|
|
||||||
|
this.up = new GameLib.D3.Vector3(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.up
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We don't do a Runtime rotation since it interferes with the quaternion update
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.quaternion = new GameLib.D3.Vector4(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.quaternion
|
||||||
|
);
|
||||||
|
|
||||||
this.computeNormals = computeNormals;
|
this.computeNormals = computeNormals;
|
||||||
|
|
||||||
this.instance = this.createInstance(false);
|
this.instance = this.createInstance(false);
|
||||||
|
|
||||||
this.needsUpdate = false;
|
this.needsUpdate = false;
|
||||||
|
|
||||||
this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
|
|
||||||
|
|
||||||
delete this.offsetRotation.updateInstance;
|
|
||||||
|
|
||||||
// this.lookAtPoint = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
|
|
||||||
//
|
|
||||||
// delete this.offsetRotation.updateInstance;
|
|
||||||
//
|
|
||||||
// this.offsetRotation = new GameLib.D3.Runtime.Vector3(graphics, this, new GameLib.D3.API.Vector3(0,0,0));
|
|
||||||
//
|
|
||||||
// delete this.offsetRotation.updateInstance;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,23 +309,16 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
instance.gameLibObject = this;
|
instance.gameLibObject = this;
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.position.copy(this.position.instance);
|
||||||
instance.position.y = this.position.y;
|
|
||||||
instance.position.z = this.position.z;
|
|
||||||
|
|
||||||
instance.scale.x = this.scale.x;
|
instance.scale.copy(this.scale.instance);
|
||||||
instance.scale.y = this.scale.y;
|
|
||||||
instance.scale.z = this.scale.z;
|
|
||||||
|
|
||||||
// we don't do rotation since it interferes with the quaternion update
|
instance.up.copy(this.up.instance);
|
||||||
// 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;
|
* We don't do rotation - its dealt with by quaternion
|
||||||
instance.quaternion.z = this.quaternion.z;
|
*/
|
||||||
instance.quaternion.w = this.quaternion.w;
|
instance.quaternion.copy(this.quaternion.instance);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -320,303 +327,6 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.prototype.invertWindingOrder = function(triangles) {
|
|
||||||
|
|
||||||
for (var i = 0; i < triangles.length; i++) {
|
|
||||||
var v1 = triangles[i].v1;
|
|
||||||
triangles[i].v1 = triangles[i].v2;
|
|
||||||
triangles[i].v2 = v1;
|
|
||||||
|
|
||||||
var backupUV = triangles[i].triangle.v1uv;
|
|
||||||
triangles[i].triangle.v1uv = triangles[i].triangle.v2uv;
|
|
||||||
triangles[i].triangle.v2uv = backupUV;
|
|
||||||
}
|
|
||||||
|
|
||||||
return triangles;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function resets a the winding order of a mesh from a reference point V (the average center of the mesh)
|
|
||||||
*/
|
|
||||||
GameLib.D3.prototype.resetWindingOrder = function(faces, vertices) {
|
|
||||||
|
|
||||||
var vertexList = new GameLib.D3.API.Vector3.Points();
|
|
||||||
|
|
||||||
for (var v = 0; v < vertices.length; v++) {
|
|
||||||
vertexList.add(new GameLib.D3.API.Vector3(
|
|
||||||
vertices[v].position.x,
|
|
||||||
vertices[v].position.y,
|
|
||||||
vertices[v].position.z
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
var V = vertexList.average();
|
|
||||||
|
|
||||||
var triangles = [];
|
|
||||||
|
|
||||||
for (var s = 0; s < faces.length; s += 3) {
|
|
||||||
|
|
||||||
var v0 = faces[s];
|
|
||||||
var v1 = faces[s+1];
|
|
||||||
var v2 = faces[s+2];
|
|
||||||
|
|
||||||
triangles.push(
|
|
||||||
{
|
|
||||||
v0 : v0,
|
|
||||||
v1 : v1,
|
|
||||||
v2 : v2,
|
|
||||||
edges : [
|
|
||||||
{v0: v0, v1: v1},
|
|
||||||
{v0: v1, v1: v2},
|
|
||||||
{v0: v2, v1: v0}
|
|
||||||
],
|
|
||||||
winding : 0,
|
|
||||||
edgeIndex : -1,
|
|
||||||
processed : false
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < triangles.length; i++) {
|
|
||||||
if (
|
|
||||||
GameLib.D3.API.Vector3.clockwise(
|
|
||||||
vertices[triangles[i].v0].position,
|
|
||||||
vertices[triangles[i].v1].position,
|
|
||||||
vertices[triangles[i].v2].position,
|
|
||||||
V
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
console.log('clockwise');
|
|
||||||
var bv1 = triangles[i].v1;
|
|
||||||
triangles[i].v1 = triangles[i].v2;
|
|
||||||
triangles[i].v2 = bv1;
|
|
||||||
} else {
|
|
||||||
console.log('not clockwise');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return triangles;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function resets the winding order for triangles in faces, given an initial triangle and orientation edge
|
|
||||||
* used pseudocode from
|
|
||||||
* http://stackoverflow.com/questions/17036970/how-to-correct-winding-of-triangles-to-counter-clockwise-direction-of-a-3d-mesh
|
|
||||||
* We need to use a graph traversal algorithm,
|
|
||||||
* lets assume we have method that returns neighbor of triangle on given edge
|
|
||||||
*
|
|
||||||
* neighbor_on_egde( next_tria, edge )
|
|
||||||
*
|
|
||||||
* to_process = set of pairs triangle and orientation edge, initial state is one good oriented triangle with any edge on it
|
|
||||||
* processed = set of processed triangles; initial empty
|
|
||||||
*
|
|
||||||
* while to_process is not empty:
|
|
||||||
* next_tria, orientation_edge = to_process.pop()
|
|
||||||
* add next_tria in processed
|
|
||||||
* if next_tria is not opposite oriented than orientation_edge:
|
|
||||||
* change next_tria (ABC) orientation (B<->C)
|
|
||||||
* for each edge (AB) in next_tria:
|
|
||||||
* neighbor_tria = neighbor_on_egde( next_tria, edge )
|
|
||||||
* if neighbor_tria exists and neighbor_tria not in processed:
|
|
||||||
* to_process add (neighbor_tria, edge opposite oriented (BA))
|
|
||||||
* @param faces GameLib.D3.TriangleFace[]
|
|
||||||
* @param orientationEdge GameLib.D3.API.Vector2
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
GameLib.D3.fixWindingOrder = function(faces, orientationEdge) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a TriangleFace belonging to a TriangleEdge has already been processed
|
|
||||||
* @param processed TriangleEdge[]
|
|
||||||
* @param triangle TriangleFace
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function inProcessed(processed, triangle) {
|
|
||||||
|
|
||||||
for (var i = 0; i < processed.length; i++) {
|
|
||||||
if (processed[i].triangle.equals(triangle)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a neighbouring triangle on a specific edge - preserving the edge orientation
|
|
||||||
* @param edge GameLib.D3.API.Vector2
|
|
||||||
* @param faces GameLib.D3.TriangleFace[]
|
|
||||||
* @param currentTriangle
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
function neighbourOnEdge(edge, faces, currentTriangle) {
|
|
||||||
|
|
||||||
for (var i = 0; i < faces.length; i++) {
|
|
||||||
if (
|
|
||||||
(faces[i].v0 == edge.x && faces[i].v1 == edge.y) ||
|
|
||||||
(faces[i].v1 == edge.x && faces[i].v2 == edge.y) ||
|
|
||||||
(faces[i].v2 == edge.x && faces[i].v0 == edge.y) ||
|
|
||||||
(faces[i].v0 == edge.y && faces[i].v1 == edge.x) ||
|
|
||||||
(faces[i].v1 == edge.y && faces[i].v2 == edge.x) ||
|
|
||||||
(faces[i].v2 == edge.y && faces[i].v0 == edge.x)
|
|
||||||
) {
|
|
||||||
|
|
||||||
var triangle = new GameLib.D3.TriangleFace(
|
|
||||||
faces[i].v0,
|
|
||||||
faces[i].v1,
|
|
||||||
faces[i].v2,
|
|
||||||
faces[i].materialIndex,
|
|
||||||
faces[i].v0uv,
|
|
||||||
faces[i].v1uv,
|
|
||||||
faces[i].v2uv
|
|
||||||
);
|
|
||||||
|
|
||||||
if (triangle.equals(currentTriangle)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GameLib.D3.TriangleEdge(
|
|
||||||
triangle,
|
|
||||||
edge
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var toProcess = [
|
|
||||||
new GameLib.D3.TriangleEdge(
|
|
||||||
new GameLib.D3.TriangleFace(
|
|
||||||
faces[0].v0,
|
|
||||||
faces[0].v1,
|
|
||||||
faces[0].v2,
|
|
||||||
faces[0].materialIndex,
|
|
||||||
faces[0].v0uv,
|
|
||||||
faces[0].v1uv,
|
|
||||||
faces[0].v2uv
|
|
||||||
),
|
|
||||||
orientationEdge
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
var processed = [];
|
|
||||||
|
|
||||||
while (toProcess.length > 0) {
|
|
||||||
|
|
||||||
var triangleEdge = toProcess.pop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If edge is the same orientation (i.e. the edge order is the same as the given triangle edge) it needs to be reversed
|
|
||||||
* to have the same winding order)
|
|
||||||
*/
|
|
||||||
if (
|
|
||||||
(triangleEdge.triangle.v0 == triangleEdge.edge.x &&
|
|
||||||
triangleEdge.triangle.v1 == triangleEdge.edge.y) ||
|
|
||||||
(triangleEdge.triangle.v1 == triangleEdge.edge.x &&
|
|
||||||
triangleEdge.triangle.v2 == triangleEdge.edge.y) ||
|
|
||||||
(triangleEdge.triangle.v2 == triangleEdge.edge.x &&
|
|
||||||
triangleEdge.triangle.v0 == triangleEdge.edge.y)
|
|
||||||
) {
|
|
||||||
var backupV = triangleEdge.triangle.v1;
|
|
||||||
triangleEdge.triangle.v1 = triangleEdge.triangle.v2;
|
|
||||||
triangleEdge.triangle.v2 = backupV;
|
|
||||||
|
|
||||||
var backupUV = triangleEdge.triangle.v1uv;
|
|
||||||
triangleEdge.triangle.v1uv = triangleEdge.triangle.v2uv;
|
|
||||||
triangleEdge.triangle.v2uv = backupUV;
|
|
||||||
}
|
|
||||||
|
|
||||||
processed.push(triangleEdge);
|
|
||||||
|
|
||||||
var edges = [
|
|
||||||
new GameLib.D3.API.Vector2(
|
|
||||||
triangleEdge.triangle.v0,
|
|
||||||
triangleEdge.triangle.v1
|
|
||||||
),
|
|
||||||
new GameLib.D3.API.Vector2(
|
|
||||||
triangleEdge.triangle.v1,
|
|
||||||
triangleEdge.triangle.v2
|
|
||||||
),
|
|
||||||
new GameLib.D3.API.Vector2(
|
|
||||||
triangleEdge.triangle.v2,
|
|
||||||
triangleEdge.triangle.v0
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var j = 0; j < edges.length; j++) {
|
|
||||||
var neighbour = neighbourOnEdge(edges[j], faces, triangleEdge.triangle);
|
|
||||||
if (neighbour && !inProcessed(processed, neighbour.triangle)) {
|
|
||||||
toProcess.push(neighbour);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In processed - we will have some duplicates - only add the unique ones
|
|
||||||
* @type {Array}
|
|
||||||
*/
|
|
||||||
var triangles = [];
|
|
||||||
for (var i = 0; i < processed.length; i++) {
|
|
||||||
var found = false;
|
|
||||||
for (var k = 0; k < triangles.length; k++) {
|
|
||||||
if (triangles[k].equals(processed[i].triangle)){
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
triangles.push(processed[i].triangle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return triangles;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a work-around function to fix polys which don't triangulate because
|
|
||||||
* they could lie on Z-plane (XZ or YZ)) - we translate the poly to the origin, systematically rotate the poly around
|
|
||||||
* Z then Y axis
|
|
||||||
* @param verticesFlat []
|
|
||||||
* @param grain is the amount to systematically rotate the poly by - a finer grain means a more accurate maximum XY
|
|
||||||
* @return []
|
|
||||||
*/
|
|
||||||
GameLib.D3.fixPolyZPlane = function(verticesFlat, grain) {
|
|
||||||
|
|
||||||
if ((verticesFlat.length % 3) != 0 && !(verticesFlat.length > 9)) {
|
|
||||||
console.log("The vertices are not in the right length : " + verticesFlat.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
var vertices = [];
|
|
||||||
|
|
||||||
var points = new GameLib.D3.API.Vector4.Points();
|
|
||||||
|
|
||||||
for (var i = 0; i < verticesFlat.length; i += 3) {
|
|
||||||
points.add(new GameLib.D3.API.Vector3(
|
|
||||||
verticesFlat[i],
|
|
||||||
verticesFlat[i + 1],
|
|
||||||
verticesFlat[i + 2]
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
points.toOrigin();
|
|
||||||
|
|
||||||
points.maximizeXDistance(grain);
|
|
||||||
|
|
||||||
points.maximizeYDistance(grain);
|
|
||||||
|
|
||||||
for (i = 0; i < points.vectors.length; i++) {
|
|
||||||
vertices.push(
|
|
||||||
[
|
|
||||||
points.vectors[i].x,
|
|
||||||
points.vectors[i].y
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return vertices;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.clone = function() {
|
GameLib.D3.Mesh.prototype.clone = function() {
|
||||||
return _.cloneDeep(this);
|
return _.cloneDeep(this);
|
||||||
};
|
};
|
|
@ -14,7 +14,7 @@ GameLib.D3.RaycastVehicle = function(
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.engine.isNotCannonThrow();
|
this.engine.isNotCannonThrow();
|
||||||
|
|
||||||
this.id = GameLib.D3.Tools.RandomId();
|
this.id = GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
this.chassisBody = chassisBody;
|
this.chassisBody = chassisBody;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ GameLib.D3.RaycastWheel = function(
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.engine.isNotCannonThrow();
|
this.engine.isNotCannonThrow();
|
||||||
|
|
||||||
this.id = GameLib.D3.Tools.RandomId();
|
this.id = GameLib.D3.Utils.RandomId();
|
||||||
|
|
||||||
if(typeof chassisConnectionPointLocal == 'undefined' || chassisConnectionPointLocal == null) {
|
if(typeof chassisConnectionPointLocal == 'undefined' || chassisConnectionPointLocal == null) {
|
||||||
chassisConnectionPointLocal = new this.engine.instance.Vec3();
|
chassisConnectionPointLocal = new this.engine.instance.Vec3();
|
||||||
|
|
|
@ -10,7 +10,7 @@ GameLib.D3.RigidBodyVehicle = function(
|
||||||
chassisBody,
|
chassisBody,
|
||||||
wheels
|
wheels
|
||||||
) {
|
) {
|
||||||
this.id = GameLib.D3.Tools.RandomId();
|
this.id = GameLib.D3.Utils.RandomId();
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.engine.isNotCannonThrow();
|
this.engine.isNotCannonThrow();
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ GameLib.D3.RigidBody = function(
|
||||||
shape,
|
shape,
|
||||||
kinematic
|
kinematic
|
||||||
) {
|
) {
|
||||||
this.id = GameLib.D3.Tools.RandomId();
|
this.id = GameLib.D3.Utils.RandomId();
|
||||||
this.position = position || new GameLib.D3.API.Vector3();
|
this.position = position || new GameLib.D3.API.Vector3();
|
||||||
this.velocity = velocity || new GameLib.D3.API.Vector3();
|
this.velocity = velocity || new GameLib.D3.API.Vector3();
|
||||||
this.angularVelocity = angularVelocity || new GameLib.D3.API.Vector3();
|
this.angularVelocity = angularVelocity || new GameLib.D3.API.Vector3();
|
||||||
|
|
|
@ -12,7 +12,7 @@ GameLib.D3.RigidWheel = function(
|
||||||
axis,
|
axis,
|
||||||
direction
|
direction
|
||||||
) {
|
) {
|
||||||
this.id = GameLib.D3.Tools.RandomId();
|
this.id = GameLib.D3.Utils.RandomId();
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.axis = axis;
|
this.axis = axis;
|
||||||
|
|
|
@ -27,6 +27,28 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.position = new GameLib.D3.Vector3(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.position
|
||||||
|
);
|
||||||
|
|
||||||
|
this.scale = new GameLib.D3.Vector3(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.scale
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We don't do a Runtime rotation since it interferes with the quaternion update
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.quaternion = new GameLib.D3.Vector4(
|
||||||
|
graphics,
|
||||||
|
this,
|
||||||
|
this.quaternion
|
||||||
|
);
|
||||||
|
|
||||||
if (GameLib.D3.Utils.UndefinedOrNull(meshIdToMesh)) {
|
if (GameLib.D3.Utils.UndefinedOrNull(meshIdToMesh)) {
|
||||||
meshIdToMesh = {};
|
meshIdToMesh = {};
|
||||||
}
|
}
|
||||||
|
@ -56,22 +78,11 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.position = this.position.instance;
|
||||||
instance.position.y = this.position.y;
|
|
||||||
instance.position.z = this.position.z;
|
|
||||||
|
|
||||||
instance.rotation.x = this.rotation.x;
|
instance.scale = this.scale.instance;
|
||||||
instance.rotation.y = this.rotation.y;
|
|
||||||
instance.rotation.z = this.rotation.z;
|
|
||||||
|
|
||||||
instance.scale.x = this.scale.x;
|
instance.quaternion = this.quaternion.instance;
|
||||||
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;
|
|
||||||
|
|
||||||
for (var im = 0; im < this.meshes.length; im++) {
|
for (var im = 0; im < this.meshes.length; im++) {
|
||||||
instance.add(this.meshes[im].instance);
|
instance.add(this.meshes[im].instance);
|
||||||
|
@ -396,37 +407,6 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
gameLibMesh.position = new GameLib.D3.Runtime.Vector3(
|
|
||||||
graphics,
|
|
||||||
gameLibMesh,
|
|
||||||
gameLibMesh.position
|
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
gameLibMeshes.push(gameLibMesh);
|
||||||
|
|
||||||
meshIdToMesh[gameLibMesh.id] = gameLibMesh;
|
meshIdToMesh[gameLibMesh.id] = gameLibMesh;
|
||||||
|
|
|
@ -21,21 +21,21 @@ GameLib.D3.Texture = function Texture(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.offset = new GameLib.D3.Runtime.Vector2(
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.offset = new GameLib.D3.Vector2(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.offset
|
this.offset
|
||||||
);
|
);
|
||||||
|
|
||||||
this.repeat = new GameLib.D3.Runtime.Vector2(
|
this.repeat = new GameLib.D3.Vector2(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.repeat
|
this.repeat
|
||||||
);
|
);
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
this.parentMaterial = parentMaterial;
|
this.parentMaterial = parentMaterial;
|
||||||
|
|
||||||
this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
|
this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
|
||||||
|
@ -173,10 +173,8 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
instance.flipY = this.flipY;
|
instance.flipY = this.flipY;
|
||||||
instance.encoding = this.encoding;
|
instance.encoding = this.encoding;
|
||||||
instance.flipY = this.flipY;
|
instance.flipY = this.flipY;
|
||||||
instance.offset.x = this.offset.x;
|
instance.offset.copy(this.offset.instance);
|
||||||
instance.offset.y = this.offset.y;
|
instance.repeat.copy(this.repeat.instance);
|
||||||
instance.repeat.x = this.repeat.x;
|
|
||||||
instance.repeat.y = this.repeat.y;
|
|
||||||
instance.mipmaps = this.mipmaps;
|
instance.mipmaps = this.mipmaps;
|
||||||
instance.unpackAlignment = this.unpackAlignment;
|
instance.unpackAlignment = this.unpackAlignment;
|
||||||
instance.premultiplyAlpha = this.premultiplyAlpha;
|
instance.premultiplyAlpha = this.premultiplyAlpha;
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
GameLib.D3.Tools = function(){};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a random ID
|
|
||||||
* @returns {string}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.Tools.RandomId = function() {
|
|
||||||
return Math.random().toString(36).substr(2, 10);
|
|
||||||
};
|
|
|
@ -23,4 +23,310 @@ GameLib.D3.Utils.Raycast = function (
|
||||||
world
|
world
|
||||||
) {
|
) {
|
||||||
console.log("not implemented yet");
|
console.log("not implemented yet");
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a random ID
|
||||||
|
* @returns {string}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Utils.RandomId = function() {
|
||||||
|
return Math.random().toString(36).substr(2, 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Utils.InvertWindingOrder = function(triangles) {
|
||||||
|
|
||||||
|
for (var i = 0; i < triangles.length; i++) {
|
||||||
|
var v1 = triangles[i].v1;
|
||||||
|
triangles[i].v1 = triangles[i].v2;
|
||||||
|
triangles[i].v2 = v1;
|
||||||
|
|
||||||
|
var backupUV = triangles[i].triangle.v1uv;
|
||||||
|
triangles[i].triangle.v1uv = triangles[i].triangle.v2uv;
|
||||||
|
triangles[i].triangle.v2uv = backupUV;
|
||||||
|
}
|
||||||
|
|
||||||
|
return triangles;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function resets a the winding order of a mesh from a reference point V (the average center of the mesh)
|
||||||
|
*/
|
||||||
|
GameLib.D3.Utils.ResetWindingOrder = function(faces, vertices) {
|
||||||
|
|
||||||
|
var vertexList = new GameLib.D3.API.Vector3.Points();
|
||||||
|
|
||||||
|
for (var v = 0; v < vertices.length; v++) {
|
||||||
|
vertexList.add(new GameLib.D3.API.Vector3(
|
||||||
|
vertices[v].position.x,
|
||||||
|
vertices[v].position.y,
|
||||||
|
vertices[v].position.z
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
var V = vertexList.average();
|
||||||
|
|
||||||
|
var triangles = [];
|
||||||
|
|
||||||
|
for (var s = 0; s < faces.length; s += 3) {
|
||||||
|
|
||||||
|
var v0 = faces[s];
|
||||||
|
var v1 = faces[s+1];
|
||||||
|
var v2 = faces[s+2];
|
||||||
|
|
||||||
|
triangles.push(
|
||||||
|
{
|
||||||
|
v0 : v0,
|
||||||
|
v1 : v1,
|
||||||
|
v2 : v2,
|
||||||
|
edges : [
|
||||||
|
{v0: v0, v1: v1},
|
||||||
|
{v0: v1, v1: v2},
|
||||||
|
{v0: v2, v1: v0}
|
||||||
|
],
|
||||||
|
winding : 0,
|
||||||
|
edgeIndex : -1,
|
||||||
|
processed : false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < triangles.length; i++) {
|
||||||
|
if (
|
||||||
|
GameLib.D3.API.Vector3.clockwise(
|
||||||
|
vertices[triangles[i].v0].position,
|
||||||
|
vertices[triangles[i].v1].position,
|
||||||
|
vertices[triangles[i].v2].position,
|
||||||
|
V
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
console.log('clockwise');
|
||||||
|
var bv1 = triangles[i].v1;
|
||||||
|
triangles[i].v1 = triangles[i].v2;
|
||||||
|
triangles[i].v2 = bv1;
|
||||||
|
} else {
|
||||||
|
console.log('not clockwise');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return triangles;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function resets the winding order for triangles in faces, given an initial triangle and orientation edge
|
||||||
|
* used pseudocode from
|
||||||
|
* http://stackoverflow.com/questions/17036970/how-to-correct-winding-of-triangles-to-counter-clockwise-direction-of-a-3d-mesh
|
||||||
|
* We need to use a graph traversal algorithm,
|
||||||
|
* lets assume we have method that returns neighbor of triangle on given edge
|
||||||
|
*
|
||||||
|
* neighbor_on_egde( next_tria, edge )
|
||||||
|
*
|
||||||
|
* to_process = set of pairs triangle and orientation edge, initial state is one good oriented triangle with any edge on it
|
||||||
|
* processed = set of processed triangles; initial empty
|
||||||
|
*
|
||||||
|
* while to_process is not empty:
|
||||||
|
* next_tria, orientation_edge = to_process.pop()
|
||||||
|
* add next_tria in processed
|
||||||
|
* if next_tria is not opposite oriented than orientation_edge:
|
||||||
|
* change next_tria (ABC) orientation (B<->C)
|
||||||
|
* for each edge (AB) in next_tria:
|
||||||
|
* neighbor_tria = neighbor_on_egde( next_tria, edge )
|
||||||
|
* if neighbor_tria exists and neighbor_tria not in processed:
|
||||||
|
* to_process add (neighbor_tria, edge opposite oriented (BA))
|
||||||
|
* @param faces GameLib.D3.TriangleFace[]
|
||||||
|
* @param orientationEdge GameLib.D3.API.Vector2
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a TriangleFace belonging to a TriangleEdge has already been processed
|
||||||
|
* @param processed TriangleEdge[]
|
||||||
|
* @param triangle TriangleFace
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function inProcessed(processed, triangle) {
|
||||||
|
|
||||||
|
for (var i = 0; i < processed.length; i++) {
|
||||||
|
if (processed[i].triangle.equals(triangle)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a neighbouring triangle on a specific edge - preserving the edge orientation
|
||||||
|
* @param edge GameLib.D3.API.Vector2
|
||||||
|
* @param faces GameLib.D3.TriangleFace[]
|
||||||
|
* @param currentTriangle
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function neighbourOnEdge(edge, faces, currentTriangle) {
|
||||||
|
|
||||||
|
for (var i = 0; i < faces.length; i++) {
|
||||||
|
if (
|
||||||
|
(faces[i].v0 == edge.x && faces[i].v1 == edge.y) ||
|
||||||
|
(faces[i].v1 == edge.x && faces[i].v2 == edge.y) ||
|
||||||
|
(faces[i].v2 == edge.x && faces[i].v0 == edge.y) ||
|
||||||
|
(faces[i].v0 == edge.y && faces[i].v1 == edge.x) ||
|
||||||
|
(faces[i].v1 == edge.y && faces[i].v2 == edge.x) ||
|
||||||
|
(faces[i].v2 == edge.y && faces[i].v0 == edge.x)
|
||||||
|
) {
|
||||||
|
|
||||||
|
var triangle = new GameLib.D3.TriangleFace(
|
||||||
|
faces[i].v0,
|
||||||
|
faces[i].v1,
|
||||||
|
faces[i].v2,
|
||||||
|
faces[i].materialIndex,
|
||||||
|
faces[i].v0uv,
|
||||||
|
faces[i].v1uv,
|
||||||
|
faces[i].v2uv
|
||||||
|
);
|
||||||
|
|
||||||
|
if (triangle.equals(currentTriangle)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.TriangleEdge(
|
||||||
|
triangle,
|
||||||
|
edge
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var toProcess = [
|
||||||
|
new GameLib.D3.TriangleEdge(
|
||||||
|
new GameLib.D3.TriangleFace(
|
||||||
|
faces[0].v0,
|
||||||
|
faces[0].v1,
|
||||||
|
faces[0].v2,
|
||||||
|
faces[0].materialIndex,
|
||||||
|
faces[0].v0uv,
|
||||||
|
faces[0].v1uv,
|
||||||
|
faces[0].v2uv
|
||||||
|
),
|
||||||
|
orientationEdge
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
var processed = [];
|
||||||
|
|
||||||
|
while (toProcess.length > 0) {
|
||||||
|
|
||||||
|
var triangleEdge = toProcess.pop();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If edge is the same orientation (i.e. the edge order is the same as the given triangle edge) it needs to be reversed
|
||||||
|
* to have the same winding order)
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
(triangleEdge.triangle.v0 == triangleEdge.edge.x &&
|
||||||
|
triangleEdge.triangle.v1 == triangleEdge.edge.y) ||
|
||||||
|
(triangleEdge.triangle.v1 == triangleEdge.edge.x &&
|
||||||
|
triangleEdge.triangle.v2 == triangleEdge.edge.y) ||
|
||||||
|
(triangleEdge.triangle.v2 == triangleEdge.edge.x &&
|
||||||
|
triangleEdge.triangle.v0 == triangleEdge.edge.y)
|
||||||
|
) {
|
||||||
|
var backupV = triangleEdge.triangle.v1;
|
||||||
|
triangleEdge.triangle.v1 = triangleEdge.triangle.v2;
|
||||||
|
triangleEdge.triangle.v2 = backupV;
|
||||||
|
|
||||||
|
var backupUV = triangleEdge.triangle.v1uv;
|
||||||
|
triangleEdge.triangle.v1uv = triangleEdge.triangle.v2uv;
|
||||||
|
triangleEdge.triangle.v2uv = backupUV;
|
||||||
|
}
|
||||||
|
|
||||||
|
processed.push(triangleEdge);
|
||||||
|
|
||||||
|
var edges = [
|
||||||
|
new GameLib.D3.API.Vector2(
|
||||||
|
triangleEdge.triangle.v0,
|
||||||
|
triangleEdge.triangle.v1
|
||||||
|
),
|
||||||
|
new GameLib.D3.API.Vector2(
|
||||||
|
triangleEdge.triangle.v1,
|
||||||
|
triangleEdge.triangle.v2
|
||||||
|
),
|
||||||
|
new GameLib.D3.API.Vector2(
|
||||||
|
triangleEdge.triangle.v2,
|
||||||
|
triangleEdge.triangle.v0
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var j = 0; j < edges.length; j++) {
|
||||||
|
var neighbour = neighbourOnEdge(edges[j], faces, triangleEdge.triangle);
|
||||||
|
if (neighbour && !inProcessed(processed, neighbour.triangle)) {
|
||||||
|
toProcess.push(neighbour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In processed - we will have some duplicates - only add the unique ones
|
||||||
|
* @type {Array}
|
||||||
|
*/
|
||||||
|
var triangles = [];
|
||||||
|
for (var i = 0; i < processed.length; i++) {
|
||||||
|
var found = false;
|
||||||
|
for (var k = 0; k < triangles.length; k++) {
|
||||||
|
if (triangles[k].equals(processed[i].triangle)){
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
triangles.push(processed[i].triangle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return triangles;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a work-around function to fix polys which don't triangulate because
|
||||||
|
* they could lie on Z-plane (XZ or YZ)) - we translate the poly to the origin, systematically rotate the poly around
|
||||||
|
* Z then Y axis
|
||||||
|
* @param verticesFlat []
|
||||||
|
* @param grain is the amount to systematically rotate the poly by - a finer grain means a more accurate maximum XY
|
||||||
|
* @return []
|
||||||
|
*/
|
||||||
|
GameLib.D3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
|
||||||
|
|
||||||
|
if ((verticesFlat.length % 3) != 0 && !(verticesFlat.length > 9)) {
|
||||||
|
console.log("The vertices are not in the right length : " + verticesFlat.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
var vertices = [];
|
||||||
|
|
||||||
|
var points = new GameLib.D3.API.Vector4.Points();
|
||||||
|
|
||||||
|
for (var i = 0; i < verticesFlat.length; i += 3) {
|
||||||
|
points.add(new GameLib.D3.API.Vector3(
|
||||||
|
verticesFlat[i],
|
||||||
|
verticesFlat[i + 1],
|
||||||
|
verticesFlat[i + 2]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
points.toOrigin();
|
||||||
|
|
||||||
|
points.maximizeXDistance(grain);
|
||||||
|
|
||||||
|
points.maximizeYDistance(grain);
|
||||||
|
|
||||||
|
for (i = 0; i < points.vectors.length; i++) {
|
||||||
|
vertices.push(
|
||||||
|
[
|
||||||
|
points.vectors[i].x,
|
||||||
|
points.vectors[i].y
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vertices;
|
||||||
};
|
};
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector2 = function RuntimeVector2(graphics, parentObject, vector2, grain) {
|
GameLib.D3.Vector2 = function RuntimeVector2(graphics, parentObject, vector2, grain) {
|
||||||
|
|
||||||
for (var property in vector2) {
|
for (var property in vector2) {
|
||||||
if (vector2.hasOwnProperty(property)) {
|
if (vector2.hasOwnProperty(property)) {
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector2 = function RuntimeVector2(graphics, parentObject, vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector2, GameLib.D3.API.Vector2);
|
GameLib.D3.Utils.Extend(GameLib.D3.Vector2, GameLib.D3.API.Vector2);
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ GameLib.D3.Runtime.Vector2 = function RuntimeVector2(graphics, parentObject, vec
|
||||||
* @param update
|
* @param update
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector2.prototype.createInstance = function(update) {
|
GameLib.D3.Vector2.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ GameLib.D3.Runtime.Vector2.prototype.createInstance = function(update) {
|
||||||
/**
|
/**
|
||||||
* Updates the instance vector, calls updateInstance on the parent object
|
* Updates the instance vector, calls updateInstance on the parent object
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector2.prototype.updateInstance = function() {
|
GameLib.D3.Vector2.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
|
@ -66,113 +66,108 @@ GameLib.D3.Runtime.Vector2.prototype.updateInstance = function() {
|
||||||
* Converts runtime vector to API Vector
|
* Converts runtime vector to API Vector
|
||||||
* @returns {GameLib.D3.API.Vector2}
|
* @returns {GameLib.D3.API.Vector2}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector2.prototype.toApiVector = function() {
|
GameLib.D3.Vector2.prototype.toApiVector = function() {
|
||||||
return new GameLib.D3.API.Vector2(
|
return new GameLib.D3.API.Vector2(
|
||||||
this.x,
|
this.x,
|
||||||
this.y
|
this.y
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2 = function Vector2(x, y) {
|
GameLib.D3.Vector2.prototype.copy = function (v) {
|
||||||
this.x = x || 0;
|
|
||||||
this.y = y || 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.copy = function (v) {
|
|
||||||
if (!GameLib.D3.Utils.UndefinedOrNull(v)) {
|
if (!GameLib.D3.Utils.UndefinedOrNull(v)) {
|
||||||
this.x = v.x;
|
this.x = v.x;
|
||||||
this.y = v.y;
|
this.y = v.y;
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x,
|
this.x,
|
||||||
this.y
|
this.y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.equals = function(v) {
|
GameLib.D3.Vector2.prototype.equals = function(v) {
|
||||||
return (((this.x == v.x) &&
|
return (((this.x == v.x) &&
|
||||||
(this.y == v.y)) ||
|
(this.y == v.y)) ||
|
||||||
((this.y == v.x) &&
|
((this.y == v.x) &&
|
||||||
(this.x == v.y)));
|
(this.x == v.y)));
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.add = function(v) {
|
GameLib.D3.Vector2.prototype.add = function(v) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x + v.x,
|
this.x + v.x,
|
||||||
this.y + v.y
|
this.y + v.y
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.subtract = function(v) {
|
GameLib.D3.Vector2.prototype.subtract = function(v) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x - v.x,
|
this.x - v.x,
|
||||||
this.y - v.y
|
this.y - v.y
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.multiply = function(v) {
|
GameLib.D3.Vector2.prototype.multiply = function(v) {
|
||||||
if (v instanceof GameLib.D3.Runtime.Vector2) {
|
if (v instanceof GameLib.D3.Vector2) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x * v.x,
|
this.x * v.x,
|
||||||
this.y * v.y
|
this.y * v.y
|
||||||
);
|
);
|
||||||
} else if (isNumber(v)) {
|
} else if (isNumber(v)) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x * v,
|
this.x * v,
|
||||||
this.y * v
|
this.y * v
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.divide = function(v) {
|
GameLib.D3.Vector2.prototype.divide = function(v) {
|
||||||
if (v instanceof GameLib.D3.Runtime.Vector2) {
|
if (v instanceof GameLib.D3.Vector2) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x * (1.0 / v.x),
|
this.x * (1.0 / v.x),
|
||||||
this.y * (1.0 / v.y)
|
this.y * (1.0 / v.y)
|
||||||
);
|
);
|
||||||
} else if (isNumber(v)) {
|
} else if (isNumber(v)) {
|
||||||
var invS = 1.0 / v;
|
var invS = 1.0 / v;
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x * invS,
|
this.x * invS,
|
||||||
this.y * invS
|
this.y * invS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.set = function(x, y) {
|
GameLib.D3.Vector2.prototype.set = function(x, y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.clamp = function(min, max) {
|
GameLib.D3.Vector2.prototype.clamp = function(min, max) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
Math.max(min.x, Math.min(max.x, this.x)),
|
Math.max(min.x, Math.min(max.x, this.x)),
|
||||||
Math.max(min.y, Math.min(max.y, this.y))
|
Math.max(min.y, Math.min(max.y, this.y))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.length = function() {
|
GameLib.D3.Vector2.prototype.length = function() {
|
||||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.dot = function(v) {
|
GameLib.D3.Vector2.prototype.dot = function(v) {
|
||||||
return this.x * v.x + this.y * v.y;
|
return this.x * v.x + this.y * v.y;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.normalize = function() {
|
GameLib.D3.Vector2.prototype.normalize = function() {
|
||||||
return this.multiply(1.0 / this.length());
|
return this.multiply(1.0 / this.length());
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.angle = function() {
|
GameLib.D3.Vector2.prototype.angle = function() {
|
||||||
var angle = Math.atan2(this.y, this.x);
|
var angle = Math.atan2(this.y, this.x);
|
||||||
if ( angle < 0 ) angle += 2 * Math.PI;
|
if ( angle < 0 ) angle += 2 * Math.PI;
|
||||||
return angle;
|
return angle;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector2.prototype.lerp = function ( v, alpha ) {
|
GameLib.D3.Vector2.prototype.lerp = function ( v, alpha ) {
|
||||||
return new GameLib.D3.Runtime.Vector2(
|
return new GameLib.D3.Vector2(
|
||||||
this.x + ( v.x - this.x ) * alpha,
|
this.x + ( v.x - this.x ) * alpha,
|
||||||
this.y + ( v.y - this.y ) * alpha
|
this.y + ( v.y - this.y ) * alpha
|
||||||
);
|
);
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector3 = function RuntimeVector3(graphics, parentObject, vector3, grain) {
|
GameLib.D3.Vector3 = function RuntimeVector3(graphics, parentObject, vector3, grain) {
|
||||||
|
|
||||||
for (var property in vector3) {
|
for (var property in vector3) {
|
||||||
if (vector3.hasOwnProperty(property)) {
|
if (vector3.hasOwnProperty(property)) {
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector3 = function RuntimeVector3(graphics, parentObject, vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector3, GameLib.D3.API.Vector3);
|
GameLib.D3.Utils.Extend(GameLib.D3.Vector3, GameLib.D3.API.Vector3);
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ GameLib.D3.Runtime.Vector3 = function RuntimeVector3(graphics, parentObject, vec
|
||||||
* @param update
|
* @param update
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector3.prototype.createInstance = function(update) {
|
GameLib.D3.Vector3.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ GameLib.D3.Runtime.Vector3.prototype.createInstance = function(update) {
|
||||||
/**
|
/**
|
||||||
* Updates the instance vector, calls updateInstance on the parent object
|
* Updates the instance vector, calls updateInstance on the parent object
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector3.prototype.updateInstance = function() {
|
GameLib.D3.Vector3.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ GameLib.D3.Runtime.Vector3.prototype.updateInstance = function() {
|
||||||
* Converts runtime vector to API Vector
|
* Converts runtime vector to API Vector
|
||||||
* @returns {GameLib.D3.API.Vector3}
|
* @returns {GameLib.D3.API.Vector3}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector3.prototype.toApiVector = function() {
|
GameLib.D3.Vector3.prototype.toApiVector = function() {
|
||||||
return new GameLib.D3.API.Vector3(
|
return new GameLib.D3.API.Vector3(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
|
@ -75,24 +75,24 @@ GameLib.D3.Runtime.Vector3.prototype.toApiVector = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.subtract = function (v) {
|
GameLib.D3.Vector3.prototype.subtract = function (v) {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x - v.x,
|
this.x - v.x,
|
||||||
this.y - v.y,
|
this.y - v.y,
|
||||||
this.z - v.z
|
this.z - v.z
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.sub = function (v) {
|
GameLib.D3.Vector3.prototype.sub = function (v) {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x - v.x,
|
this.x - v.x,
|
||||||
this.y - v.y,
|
this.y - v.y,
|
||||||
this.z - v.z
|
this.z - v.z
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.cross = function (v) {
|
GameLib.D3.Vector3.prototype.cross = function (v) {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.y * v.z - this.z * v.y,
|
this.y * v.z - this.z * v.y,
|
||||||
this.z * v.x - this.x * v.z,
|
this.z * v.x - this.x * v.z,
|
||||||
this.x * v.y - this.y * v.x
|
this.x * v.y - this.y * v.x
|
||||||
|
@ -100,66 +100,66 @@ GameLib.D3.Runtime.Vector3.prototype.cross = function (v) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.clockwise = function (u, v, w, viewPoint) {
|
GameLib.D3.Vector3.clockwise = function (u, v, w, viewPoint) {
|
||||||
var normal = GameLib.D3.Runtime.Vector3.normal(u, v, w);
|
var normal = GameLib.D3.Vector3.normal(u, v, w);
|
||||||
var uv = u.copy();
|
var uv = u.copy();
|
||||||
var winding = normal.dot(uv.subtract(viewPoint));
|
var winding = normal.dot(uv.subtract(viewPoint));
|
||||||
return (winding > 0);
|
return (winding > 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.normal = function (u, v, w) {
|
GameLib.D3.Vector3.normal = function (u, v, w) {
|
||||||
var vv = v.copy();
|
var vv = v.copy();
|
||||||
var wv = w.copy();
|
var wv = w.copy();
|
||||||
return vv.subtract(u).cross(wv.subtract(u));
|
return vv.subtract(u).cross(wv.subtract(u));
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.lookAt = function (at, up) {
|
GameLib.D3.Vector3.prototype.lookAt = function (at, up) {
|
||||||
var lookAtMatrix = GameLib.D3.Matrix4.lookAt(this, at, up);
|
var lookAtMatrix = GameLib.D3.Matrix4.lookAt(this, at, up);
|
||||||
return this.multiply(lookAtMatrix);
|
return this.multiply(lookAtMatrix);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.translate = function (v) {
|
GameLib.D3.Vector3.prototype.translate = function (v) {
|
||||||
this.x += v.x;
|
this.x += v.x;
|
||||||
this.y += v.y;
|
this.y += v.y;
|
||||||
this.z += v.z;
|
this.z += v.z;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.add = function (v) {
|
GameLib.D3.Vector3.prototype.add = function (v) {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x + v.x,
|
this.x + v.x,
|
||||||
this.y + v.y,
|
this.y + v.y,
|
||||||
this.z + v.z
|
this.z + v.z
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.squared = function () {
|
GameLib.D3.Vector3.prototype.squared = function () {
|
||||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.copy = function () {
|
GameLib.D3.Vector3.prototype.copy = function () {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
this.z
|
this.z
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.set = function (x, y, z) {
|
GameLib.D3.Vector3.prototype.set = function (x, y, z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.lerp = function ( v, alpha ) {
|
GameLib.D3.Vector3.prototype.lerp = function ( v, alpha ) {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x + ( v.x - this.x ) * alpha,
|
this.x + ( v.x - this.x ) * alpha,
|
||||||
this.y + ( v.y - this.y ) * alpha,
|
this.y + ( v.y - this.y ) * alpha,
|
||||||
this.z + ( v.z - this.z ) * alpha
|
this.z + ( v.z - this.z ) * alpha
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.distanceTo = function(v) {
|
GameLib.D3.Vector3.prototype.distanceTo = function(v) {
|
||||||
var dx = this.x - v.x,
|
var dx = this.x - v.x,
|
||||||
dy = this.y - v.y,
|
dy = this.y - v.y,
|
||||||
dz = this.z - v.z;
|
dz = this.z - v.z;
|
||||||
|
@ -169,7 +169,7 @@ GameLib.D3.Runtime.Vector3.prototype.distanceTo = function(v) {
|
||||||
/**
|
/**
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector3.AngleDirection = function(forward, directionToCheck, up) {
|
GameLib.D3.Vector3.AngleDirection = function(forward, directionToCheck, up) {
|
||||||
var perp = forward.cross(directionToCheck);
|
var perp = forward.cross(directionToCheck);
|
||||||
var dir = perp.dot(up);
|
var dir = perp.dot(up);
|
||||||
|
|
||||||
|
@ -183,10 +183,10 @@ GameLib.D3.Runtime.Vector3.AngleDirection = function(forward, directionToCheck,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
|
GameLib.D3.Vector3.prototype.multiply = function (s) {
|
||||||
if (s instanceof GameLib.D3.Runtime.Vector3) {
|
if (s instanceof GameLib.D3.Vector3) {
|
||||||
|
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x * s.x,
|
this.x * s.x,
|
||||||
this.y * s.y,
|
this.y * s.y,
|
||||||
this.z * s.z
|
this.z * s.z
|
||||||
|
@ -198,7 +198,7 @@ GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
|
||||||
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w;
|
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w;
|
||||||
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w;
|
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w;
|
||||||
|
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z
|
z
|
||||||
|
@ -210,7 +210,7 @@ GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
|
||||||
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z;
|
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z;
|
||||||
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z;
|
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z;
|
||||||
|
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z
|
z
|
||||||
|
@ -218,7 +218,7 @@ GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
|
||||||
|
|
||||||
} else if(!isNaN(parseFloat(s)) && isFinite(s)) {
|
} else if(!isNaN(parseFloat(s)) && isFinite(s)) {
|
||||||
|
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x * s,
|
this.x * s,
|
||||||
this.y * s,
|
this.y * s,
|
||||||
this.z * s
|
this.z * s
|
||||||
|
@ -233,11 +233,11 @@ GameLib.D3.Runtime.Vector3.prototype.multiply = function (s) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.dot = function (v) {
|
GameLib.D3.Vector3.prototype.dot = function (v) {
|
||||||
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
|
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.normalize = function () {
|
GameLib.D3.Vector3.prototype.normalize = function () {
|
||||||
var EPSILON = 0.000001;
|
var EPSILON = 0.000001;
|
||||||
var v2 = this.squared();
|
var v2 = this.squared();
|
||||||
|
|
||||||
|
@ -246,22 +246,22 @@ GameLib.D3.Runtime.Vector3.prototype.normalize = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
var invLength = 1.0 / Math.sqrt(v2);
|
var invLength = 1.0 / Math.sqrt(v2);
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x * invLength,
|
this.x * invLength,
|
||||||
this.y * invLength,
|
this.y * invLength,
|
||||||
this.z * invLength
|
this.z * invLength
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.clone = function () {
|
GameLib.D3.Vector3.prototype.clone = function () {
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
this.z
|
this.z
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.applyQuaternion = function(q) {
|
GameLib.D3.Vector3.prototype.applyQuaternion = function(q) {
|
||||||
var x = this.x, y = this.y, z = this.z;
|
var x = this.x, y = this.y, z = this.z;
|
||||||
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
||||||
|
|
||||||
|
@ -274,14 +274,14 @@ GameLib.D3.Runtime.Vector3.prototype.applyQuaternion = function(q) {
|
||||||
|
|
||||||
// calculate result * inverse quat
|
// calculate result * inverse quat
|
||||||
|
|
||||||
return new GameLib.D3.Runtime.Vector3(
|
return new GameLib.D3.Vector3(
|
||||||
ix * qw + iw * - qx + iy * - qz - iz * - qy,
|
ix * qw + iw * - qx + iy * - qz - iz * - qy,
|
||||||
iy * qw + iw * - qy + iz * - qx - ix * - qz,
|
iy * qw + iw * - qy + iz * - qx - ix * - qz,
|
||||||
iz * qw + iw * - qz + ix * - qy - iy * - qx
|
iz * qw + iw * - qz + ix * - qy - iy * - qx
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.clamp = function(min, max) {
|
GameLib.D3.Vector3.prototype.clamp = function(min, max) {
|
||||||
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
this.x = Math.max( min.x, Math.min( max.x, this.x ) );
|
||||||
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
this.y = Math.max( min.y, Math.min( max.y, this.y ) );
|
||||||
this.z = Math.max( min.z, Math.min( max.z, this.z ) );
|
this.z = Math.max( min.z, Math.min( max.z, this.z ) );
|
||||||
|
@ -289,22 +289,22 @@ GameLib.D3.Runtime.Vector3.prototype.clamp = function(min, max) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.negate = function() {
|
GameLib.D3.Vector3.prototype.negate = function() {
|
||||||
this.x = -this.x;
|
this.x = -this.x;
|
||||||
this.y = -this.y;
|
this.y = -this.y;
|
||||||
this.z = -this.z;
|
this.z = -this.z;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.length = function() {
|
GameLib.D3.Vector3.prototype.length = function() {
|
||||||
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
|
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.reflect = function(normal) {
|
GameLib.D3.Vector3.prototype.reflect = function(normal) {
|
||||||
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
|
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector3.prototype.angleTo = function (v) {
|
GameLib.D3.Vector3.prototype.angleTo = function (v) {
|
||||||
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
|
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
|
||||||
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
|
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
|
||||||
};
|
};
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector4 = function RuntimeVector4(graphics, parentObject, vector4, grain) {
|
GameLib.D3.Vector4 = function RuntimeVector4(graphics, parentObject, vector4, grain) {
|
||||||
|
|
||||||
for (var property in vector4) {
|
for (var property in vector4) {
|
||||||
if (vector4.hasOwnProperty(property)) {
|
if (vector4.hasOwnProperty(property)) {
|
||||||
|
@ -14,7 +14,7 @@ GameLib.D3.Runtime.Vector4 = function RuntimeVector4(graphics, parentObject, vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Utils.Extend(GameLib.D3.Runtime.Vector4, GameLib.D3.API.Vector4);
|
GameLib.D3.Utils.Extend(GameLib.D3.Vector4, GameLib.D3.API.Vector4);
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ GameLib.D3.Runtime.Vector4 = function RuntimeVector4(graphics, parentObject, vec
|
||||||
* @param update
|
* @param update
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector4.prototype.createInstance = function(update) {
|
GameLib.D3.Vector4.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ GameLib.D3.Runtime.Vector4.prototype.createInstance = function(update) {
|
||||||
/**
|
/**
|
||||||
* Updates the instance vector, calls updateInstance on the parent object
|
* Updates the instance vector, calls updateInstance on the parent object
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector4.prototype.updateInstance = function() {
|
GameLib.D3.Vector4.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ GameLib.D3.Runtime.Vector4.prototype.updateInstance = function() {
|
||||||
* Converts runtime vector to API Vector
|
* Converts runtime vector to API Vector
|
||||||
* @returns {GameLib.D3.API.Vector4}
|
* @returns {GameLib.D3.API.Vector4}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Runtime.Vector4.prototype.toApiVector = function() {
|
GameLib.D3.Vector4.prototype.toApiVector = function() {
|
||||||
return new GameLib.D3.API.Vector4(
|
return new GameLib.D3.API.Vector4(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
|
@ -77,39 +77,15 @@ GameLib.D3.Runtime.Vector4.prototype.toApiVector = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4 = function Vector4(x, y, z, w) {
|
GameLib.D3.Vector4.prototype.translate = function (v) {
|
||||||
|
|
||||||
this.x = 0;
|
|
||||||
this.y = 0;
|
|
||||||
this.z = 0;
|
|
||||||
this.w = 1;
|
|
||||||
|
|
||||||
if (x) {
|
|
||||||
this.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z) {
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w) {
|
|
||||||
this.w = w;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.prototype.translate = function (v) {
|
|
||||||
this.x += v.x;
|
this.x += v.x;
|
||||||
this.y += v.y;
|
this.y += v.y;
|
||||||
this.z += v.z;
|
this.z += v.z;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.prototype.copy = function () {
|
GameLib.D3.Vector4.prototype.copy = function () {
|
||||||
return new GameLib.D3.Runtime.Vector4(
|
return new GameLib.D3.Vector4(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
this.z,
|
this.z,
|
||||||
|
@ -117,8 +93,8 @@ GameLib.D3.Runtime.Vector4.prototype.copy = function () {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.prototype.multiply = function (s) {
|
GameLib.D3.Vector4.prototype.multiply = function (s) {
|
||||||
if (s instanceof GameLib.D3.API.Vector3) {
|
if (s instanceof GameLib.D3.Vector3) {
|
||||||
this.x *= s.x;
|
this.x *= s.x;
|
||||||
this.y *= s.y;
|
this.y *= s.y;
|
||||||
this.z *= s.z;
|
this.z *= s.z;
|
||||||
|
@ -138,7 +114,7 @@ GameLib.D3.Runtime.Vector4.prototype.multiply = function (s) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.prototype.normalize = function () {
|
GameLib.D3.Vector4.prototype.normalize = function () {
|
||||||
|
|
||||||
// note - leave w untouched
|
// note - leave w untouched
|
||||||
var EPSILON = 0.000001;
|
var EPSILON = 0.000001;
|
||||||
|
@ -158,7 +134,7 @@ GameLib.D3.Runtime.Vector4.prototype.normalize = function () {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.prototype.subtract = function (v) {
|
GameLib.D3.Vector4.prototype.subtract = function (v) {
|
||||||
|
|
||||||
if (v instanceof GameLib.D3.API.Vector3) {
|
if (v instanceof GameLib.D3.API.Vector3) {
|
||||||
this.x -= v.x;
|
this.x -= v.x;
|
||||||
|
@ -166,7 +142,7 @@ GameLib.D3.Runtime.Vector4.prototype.subtract = function (v) {
|
||||||
this.z -= v.z;
|
this.z -= v.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v instanceof GameLib.D3.Runtime.Vector4) {
|
if (v instanceof GameLib.D3.Vector4) {
|
||||||
this.x -= v.x;
|
this.x -= v.x;
|
||||||
this.y -= v.y;
|
this.y -= v.y;
|
||||||
this.z -= v.z;
|
this.z -= v.z;
|
||||||
|
@ -176,14 +152,14 @@ GameLib.D3.Runtime.Vector4.prototype.subtract = function (v) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points = function () {
|
GameLib.D3.Vector4.Points = function () {
|
||||||
this.vectors = [];
|
this.vectors = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.add = function (vector) {
|
GameLib.D3.Vector4.Points.prototype.add = function (vector) {
|
||||||
|
|
||||||
if (vector instanceof GameLib.D3.API.Vector3) {
|
if (vector instanceof GameLib.D3.API.Vector3) {
|
||||||
vector = new GameLib.D3.Runtime.Vector4(
|
vector = new GameLib.D3.Vector4(
|
||||||
vector.x,
|
vector.x,
|
||||||
vector.y,
|
vector.y,
|
||||||
vector.z,
|
vector.z,
|
||||||
|
@ -191,7 +167,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.add = function (vector) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vector instanceof GameLib.D3.Runtime.Vector4) {
|
if (!vector instanceof GameLib.D3.Vector4) {
|
||||||
console.warn("Vector needs to be of type Vector4");
|
console.warn("Vector needs to be of type Vector4");
|
||||||
throw new Error("Vector needs to be of type Vector4");
|
throw new Error("Vector needs to be of type Vector4");
|
||||||
}
|
}
|
||||||
|
@ -201,7 +177,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.add = function (vector) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.copy = function () {
|
GameLib.D3.Vector4.Points.prototype.copy = function () {
|
||||||
|
|
||||||
var vectors = [];
|
var vectors = [];
|
||||||
|
|
||||||
|
@ -212,7 +188,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.copy = function () {
|
||||||
return vectors;
|
return vectors;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.maximizeXDistance = function (grain) {
|
GameLib.D3.Vector4.Points.prototype.maximizeXDistance = function (grain) {
|
||||||
|
|
||||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||||
|
|
||||||
|
@ -257,7 +233,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.maximizeXDistance = function (grain)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.maximizeYDistance = function (grain) {
|
GameLib.D3.Vector4.Points.prototype.maximizeYDistance = function (grain) {
|
||||||
|
|
||||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||||
|
|
||||||
|
@ -302,7 +278,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.maximizeYDistance = function (grain)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.lookAt = function (at, up) {
|
GameLib.D3.Vector4.Points.prototype.lookAt = function (at, up) {
|
||||||
|
|
||||||
var polyCenter = this.average();
|
var polyCenter = this.average();
|
||||||
|
|
||||||
|
@ -310,9 +286,9 @@ GameLib.D3.Runtime.Vector4.Points.prototype.lookAt = function (at, up) {
|
||||||
|
|
||||||
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
|
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
|
||||||
|
|
||||||
lookAtMatrix.rows[0] = new GameLib.D3.Runtime.Vector4(1, 0, 0, 0);
|
lookAtMatrix.rows[0] = new GameLib.D3.Vector4(1, 0, 0, 0);
|
||||||
lookAtMatrix.rows[1] = new GameLib.D3.Runtime.Vector4(0, 0, 1, 0);
|
lookAtMatrix.rows[1] = new GameLib.D3.Vector4(0, 0, 1, 0);
|
||||||
lookAtMatrix.rows[2] = new GameLib.D3.Runtime.Vector4(0, 1, 0, 0);
|
lookAtMatrix.rows[2] = new GameLib.D3.Vector4(0, 1, 0, 0);
|
||||||
|
|
||||||
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
|
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
|
||||||
|
|
||||||
|
@ -323,7 +299,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.lookAt = function (at, up) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.distances = function () {
|
GameLib.D3.Vector4.Points.prototype.distances = function () {
|
||||||
|
|
||||||
var minX = this.vectors[0].x;
|
var minX = this.vectors[0].x;
|
||||||
var minY = this.vectors[0].y;
|
var minY = this.vectors[0].y;
|
||||||
|
@ -362,7 +338,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.distances = function () {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.average = function () {
|
GameLib.D3.Vector4.Points.prototype.average = function () {
|
||||||
var averageX = 0;
|
var averageX = 0;
|
||||||
var averageY = 0;
|
var averageY = 0;
|
||||||
var averageZ = 0;
|
var averageZ = 0;
|
||||||
|
@ -380,7 +356,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.average = function () {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.negate = function () {
|
GameLib.D3.Vector4.Points.prototype.negate = function () {
|
||||||
|
|
||||||
for (var i = 0; i < this.vectors.length; i++) {
|
for (var i = 0; i < this.vectors.length; i++) {
|
||||||
this.vectors[i].x *= -1;
|
this.vectors[i].x *= -1;
|
||||||
|
@ -392,7 +368,7 @@ GameLib.D3.Runtime.Vector4.Points.prototype.negate = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Runtime.Vector4.Points.prototype.toOrigin = function () {
|
GameLib.D3.Vector4.Points.prototype.toOrigin = function () {
|
||||||
|
|
||||||
var distanceFromOrigin = this.average().negate();
|
var distanceFromOrigin = this.average().negate();
|
||||||
|
|
94
src/index.js
94
src/index.js
|
@ -1,94 +0,0 @@
|
||||||
if (typeof GameLib === 'undefined') {
|
|
||||||
function GameLib() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof GameLib.D3 === 'undefined') {
|
|
||||||
GameLib.D3 = function() {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof require != 'undefined') {
|
|
||||||
GameLib.D3.API.Bone = require('./game-lib-bone.js');
|
|
||||||
GameLib.D3.API.BoneWeight = require('./game-lib-bone-weight');
|
|
||||||
GameLib.D3.Broadphase = require('./game-lib-broadphase');
|
|
||||||
GameLib.D3.API.Color = require('./game-lib-color');
|
|
||||||
GameLib.D3.FlyControls = require('./game-lib-fly-controls');
|
|
||||||
GameLib.D3.Engine = require('./game-lib-engine');
|
|
||||||
GameLib.D3.Game = require('./game-lib-game');
|
|
||||||
GameLib.D3.Heightmap = require('./game-lib-heightmap');
|
|
||||||
GameLib.D3.Image = require('./game-lib-image');
|
|
||||||
GameLib.D3.Light = require('./game-lib-light');
|
|
||||||
GameLib.D3.Material = require('./game-lib-material');
|
|
||||||
GameLib.D3.Matrix3 = require('./game-lib-matrix-3');
|
|
||||||
GameLib.D3.Matrix4 = require('./game-lib-matrix-4');
|
|
||||||
GameLib.D3.Mesh = require('./game-lib-mesh');
|
|
||||||
GameLib.D3.Physics = require('./game-lib-physics');
|
|
||||||
GameLib.D3.PolyVertex = require('./game-lib-poly-vertex');
|
|
||||||
GameLib.D3.RaycastVehicle = require('./game-lib-raycast-vehicle');
|
|
||||||
GameLib.D3.RigidBody = require('./game-lib-rigid-body');
|
|
||||||
GameLib.D3.RigidBodyVehicle = require('./game-lib-rigid-body-vehicle');
|
|
||||||
GameLib.D3.Scene = require('./game-lib-scene');
|
|
||||||
GameLib.D3.Shape = require('./game-lib-shape');
|
|
||||||
GameLib.D3.Skeleton = require('./game-lib-skeleton');
|
|
||||||
GameLib.D3.SkyBox = require('./game-lib-sky-box');
|
|
||||||
GameLib.D3.Solver = require('./game-lib-solver');
|
|
||||||
GameLib.D3.Texture = require('./game-lib-texture');
|
|
||||||
GameLib.D3.TriangleEdge = require('./game-lib-triangle-edge');
|
|
||||||
GameLib.D3.TriangleFace = require('./game-lib-triangle-face');
|
|
||||||
GameLib.D3.API.Vector2 = require('./game-lib-vector-2');
|
|
||||||
GameLib.D3.API.Vector3 = require('./game-lib-vector-3');
|
|
||||||
GameLib.D3.API.Vector4 = require('./game-lib-vector-4');
|
|
||||||
GameLib.D3.API.Vector4.Points = require('./game-lib-vector-4-points');
|
|
||||||
GameLib.D3.Vertex = require('./game-lib-vertex');
|
|
||||||
GameLib.D3.World = require('./game-lib-world');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof module != 'undefined') {
|
|
||||||
module.exports = GameLib;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (typeof module != 'undefined') {
|
|
||||||
module.exports = GameLib;
|
|
||||||
}
|
|
Loading…
Reference in New Issue