ecs refactor start
parent
4a880dc2db
commit
05efb8eea0
|
@ -16,7 +16,8 @@
|
|||
"npm": "^4.0.2",
|
||||
"q": "^1.4.1",
|
||||
"three": "^0.81.2",
|
||||
"through2": "^2.0.1"
|
||||
"through2": "^2.0.1",
|
||||
"tiny-ecs": "^2.0.0"
|
||||
},
|
||||
"repository": "https://github.com/ToywheelDev/game-lib.git",
|
||||
"license": "UNLICENSED",
|
||||
|
|
|
@ -20,6 +20,13 @@ if (typeof GameLib.D3.API == 'undefined') {
|
|||
GameLib.D3.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.API Namespace
|
||||
*/
|
||||
if (typeof GameLib.API == 'undefined') {
|
||||
GameLib.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* GameLib.D3.Runtime Namespace
|
||||
* @constructor
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Entity API Object (for storing / loading entities to and from API)
|
||||
* @constructor
|
||||
* @param entities GameLib.API.Entity[]
|
||||
*/
|
||||
GameLib.API.EntityManager = function(
|
||||
entities
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(entities)) {
|
||||
entities = [];
|
||||
}
|
||||
this.entities = entities;
|
||||
};
|
|
@ -2,61 +2,55 @@
|
|||
* Entity API Object (for storing / loading entities to and from API)
|
||||
* @param id
|
||||
* @param name
|
||||
* @param components GameLib.D3.Component[]
|
||||
* @param position
|
||||
* @param quaternion
|
||||
* @param scale
|
||||
* @param parentScene GameLib.D3.Scene
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
* @param components GameLib.Component[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Entity = function(
|
||||
GameLib.API.Entity = function(
|
||||
id,
|
||||
name,
|
||||
components,
|
||||
position,
|
||||
quaternion,
|
||||
scale,
|
||||
parentScene,
|
||||
mesh
|
||||
components
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(components)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(components)) {
|
||||
components = [];
|
||||
}
|
||||
this.components = components;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.D3.API.Vector3(1, 1, 1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentScene)) {
|
||||
parentScene = null;
|
||||
}
|
||||
this.parentScene = parentScene;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adds a components to the entity
|
||||
* @param component GameLib.Component
|
||||
*/
|
||||
GameLib.API.Entity.prototype.addComponent = function(component) {
|
||||
this.components.push(component);
|
||||
this.instance.addComponent(component)
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a component from this entity
|
||||
* @param component GameLib.Component
|
||||
*/
|
||||
GameLib.API.Entity.prototype.removeComponent = function(component) {
|
||||
|
||||
this.instance.removeComponent(component);
|
||||
|
||||
var index = this.components.indexOf(component);
|
||||
|
||||
if (index == -1) {
|
||||
console.log('failed to remove component');
|
||||
return false;
|
||||
}
|
||||
|
||||
this.components.splice(index, 1);
|
||||
return true;
|
||||
};
|
|
@ -1,12 +1,12 @@
|
|||
/**
|
||||
* Api Matrix 4
|
||||
* @param row0 GameLib.D3.API.Quaternion
|
||||
* @param row1 GameLib.D3.API.Quaternion
|
||||
* @param row2 GameLib.D3.API.Quaternion
|
||||
* @param row3 GameLib.D3.API.Quaternion
|
||||
* @param row0 GameLib.API.Quaternion
|
||||
* @param row1 GameLib.API.Quaternion
|
||||
* @param row2 GameLib.API.Quaternion
|
||||
* @param row3 GameLib.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Matrix4 = function ApiMatrix4(
|
||||
GameLib.API.Matrix4 = function ApiMatrix4(
|
||||
row0,
|
||||
row1,
|
||||
row2,
|
||||
|
@ -14,43 +14,43 @@ GameLib.D3.API.Matrix4 = function ApiMatrix4(
|
|||
) {
|
||||
this.rows = [];
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(row0)) {
|
||||
row0 = new GameLib.D3.API.Quaternion(1, 0, 0, 0);
|
||||
if (GameLib.Utils.UndefinedOrNull(row0)) {
|
||||
row0 = new GameLib.API.Quaternion(1, 0, 0, 0);
|
||||
}
|
||||
this.rows[0] = row0;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(row1)) {
|
||||
row1 = new GameLib.D3.API.Quaternion(0, 1, 0, 0);
|
||||
if (GameLib.Utils.UndefinedOrNull(row1)) {
|
||||
row1 = new GameLib.API.Quaternion(0, 1, 0, 0);
|
||||
}
|
||||
this.rows[1] = row1;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(row2)) {
|
||||
row2 = new GameLib.D3.API.Quaternion(0, 0, 1, 0);
|
||||
if (GameLib.Utils.UndefinedOrNull(row2)) {
|
||||
row2 = new GameLib.API.Quaternion(0, 0, 1, 0);
|
||||
}
|
||||
this.rows[2] = row2;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(row3)) {
|
||||
row3 = new GameLib.D3.API.Quaternion(0, 0, 0, 1);
|
||||
if (GameLib.Utils.UndefinedOrNull(row3)) {
|
||||
row3 = new GameLib.API.Quaternion(0, 0, 0, 1);
|
||||
}
|
||||
this.rows[3] = row3;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
||||
this.identity();
|
||||
this.rows[1] = new GameLib.D3.API.Quaternion(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
||||
this.rows[2] = new GameLib.D3.API.Quaternion(0, Math.sin(radians), Math.cos(radians), 0);
|
||||
this.rows[1] = new GameLib.API.Quaternion(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
||||
this.rows[2] = new GameLib.API.Quaternion(0, Math.sin(radians), Math.cos(radians), 0);
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotationMatrixY = function (radians) {
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixY = function (radians) {
|
||||
this.identity();
|
||||
this.rows[0] = new GameLib.D3.API.Quaternion(
|
||||
this.rows[0] = new GameLib.API.Quaternion(
|
||||
Math.cos(radians),
|
||||
0,
|
||||
Math.sin(radians),
|
||||
0
|
||||
);
|
||||
this.rows[2] = new GameLib.D3.API.Quaternion(
|
||||
this.rows[2] = new GameLib.API.Quaternion(
|
||||
-1 * Math.sin(radians),
|
||||
0,
|
||||
Math.cos(radians),
|
||||
|
@ -59,41 +59,41 @@ GameLib.D3.API.Matrix4.prototype.rotationMatrixY = function (radians) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotationMatrixZ = function (radians) {
|
||||
GameLib.API.Matrix4.prototype.rotationMatrixZ = function (radians) {
|
||||
this.identity();
|
||||
this.rows[0] = new GameLib.D3.API.Quaternion(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
|
||||
this.rows[1] = new GameLib.D3.API.Quaternion(Math.sin(radians), Math.cos(radians), 0, 0);
|
||||
this.rows[0] = new GameLib.API.Quaternion(Math.cos(radians), -1 * Math.sin(radians), 0, 0);
|
||||
this.rows[1] = new GameLib.API.Quaternion(Math.sin(radians), Math.cos(radians), 0, 0);
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotateX = function (radians, point) {
|
||||
GameLib.API.Matrix4.prototype.rotateX = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixX(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotateY = function (radians, point) {
|
||||
GameLib.API.Matrix4.prototype.rotateY = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixY(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.rotateZ = function (radians, point) {
|
||||
GameLib.API.Matrix4.prototype.rotateZ = function (radians, point) {
|
||||
this.identity();
|
||||
this.rotationMatrixZ(radians);
|
||||
return this.multiply(point);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.multiply = function (mvp) {
|
||||
if (mvp instanceof GameLib.D3.API.Quaternion) {
|
||||
return new GameLib.D3.API.Quaternion(
|
||||
GameLib.API.Matrix4.prototype.multiply = function (mvp) {
|
||||
if (mvp instanceof GameLib.API.Quaternion) {
|
||||
return new GameLib.API.Quaternion(
|
||||
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w,
|
||||
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z + this.rows[1].w * mvp.w,
|
||||
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z + this.rows[2].w * mvp.w,
|
||||
this.rows[3].x * mvp.x + this.rows[3].y * mvp.y + this.rows[3].z * mvp.z + this.rows[3].w * mvp.w
|
||||
);
|
||||
} else if (mvp instanceof GameLib.D3.API.Vector3) {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
} else if (mvp instanceof GameLib.API.Vector3) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z,
|
||||
this.rows[1].x * mvp.x + this.rows[1].y * mvp.y + this.rows[1].z * mvp.z,
|
||||
this.rows[2].x * mvp.x + this.rows[2].y * mvp.y + this.rows[2].z * mvp.z
|
||||
|
@ -101,18 +101,18 @@ GameLib.D3.API.Matrix4.prototype.multiply = function (mvp) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.identity = function () {
|
||||
GameLib.API.Matrix4.prototype.identity = function () {
|
||||
this.rows = [
|
||||
new GameLib.D3.API.Quaternion(1, 0, 0, 0),
|
||||
new GameLib.D3.API.Quaternion(0, 1, 0, 0),
|
||||
new GameLib.D3.API.Quaternion(0, 0, 1, 0),
|
||||
new GameLib.D3.API.Quaternion(0, 0, 0, 1)
|
||||
new GameLib.API.Quaternion(1, 0, 0, 0),
|
||||
new GameLib.API.Quaternion(0, 1, 0, 0),
|
||||
new GameLib.API.Quaternion(0, 0, 1, 0),
|
||||
new GameLib.API.Quaternion(0, 0, 0, 1)
|
||||
];
|
||||
};
|
||||
|
||||
GameLib.D3.API.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||
GameLib.API.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||
|
||||
var pv = new GameLib.D3.API.Vector3(position.x, position.y, position.z);
|
||||
var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
|
||||
|
||||
var z = pv.subtract(target).normalize();
|
||||
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
* Raw Mesh API object - should always correspond with the Mesh Schema
|
||||
* @param id
|
||||
* @param meshType
|
||||
* @param name
|
||||
* @param vertices GameLib.D3.Vertex[]
|
||||
* @param faces GameLib.D3.TriangleFace[]
|
||||
* @param faceVertexUvs
|
||||
* @param materials GameLib.D3.API.Material[]
|
||||
* @param parentMeshId
|
||||
* @param parentSceneId
|
||||
* @param skeleton
|
||||
* @param skinIndices
|
||||
* @param skinWeights
|
||||
* @param position GameLib.D3.API.Vector3
|
||||
* @param quaternion GameLib.D3.API.Quaternion
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param up
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Mesh = function(
|
||||
id,
|
||||
meshType,
|
||||
name,
|
||||
vertices,
|
||||
faces,
|
||||
faceVertexUvs,
|
||||
materials,
|
||||
parentMeshId,
|
||||
parentSceneId,
|
||||
skeleton,
|
||||
skinIndices,
|
||||
skinWeights,
|
||||
position,
|
||||
quaternion,
|
||||
scale,
|
||||
up
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(meshType)) {
|
||||
meshType = GameLib.D3.Mesh.TYPE_NORMAL;
|
||||
}
|
||||
this.meshType = meshType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Mesh (' + meshType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(vertices)) {
|
||||
throw new Error('Cannot create a mesh with no vertices');
|
||||
}
|
||||
this.vertices = vertices;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(faces)) {
|
||||
throw new Error('Cannot create a mesh with no faces');
|
||||
}
|
||||
this.faces = faces;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentMeshId)) {
|
||||
parentMeshId = null;
|
||||
}
|
||||
this.parentMeshId = parentMeshId;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentSceneId)) {
|
||||
parentSceneId = null;
|
||||
}
|
||||
this.parentSceneId = parentSceneId;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skeleton)) {
|
||||
skeleton = null;
|
||||
}
|
||||
this.skeleton = skeleton;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(faceVertexUvs)) {
|
||||
faceVertexUvs = [];
|
||||
}
|
||||
this.faceVertexUvs = faceVertexUvs;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinIndices)) {
|
||||
skinIndices = [];
|
||||
}
|
||||
this.skinIndices = skinIndices;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinWeights)) {
|
||||
skinWeights = [];
|
||||
}
|
||||
this.skinWeights = skinWeights;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(materials)) {
|
||||
materials = [];
|
||||
}
|
||||
this.materials = materials;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.API.Vector3(0,0,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.D3.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.D3.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
this.localRotation = new GameLib.D3.API.Vector3(0,0,0);
|
||||
this.localScale = new GameLib.D3.API.Vector3(1,1,1);
|
||||
this.localPosition = new GameLib.D3.API.Vector3(0,0,0);
|
||||
|
||||
};
|
|
@ -1,45 +1,45 @@
|
|||
GameLib.D3.API.Quaternion = function (x, y, z, w, axis, angle) {
|
||||
GameLib.API.Quaternion = function (x, y, z, w, axis, angle) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(x)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(y)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(z)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(w)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(w)) {
|
||||
w = 1;
|
||||
}
|
||||
this.w = w;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(axis)) {
|
||||
axis = new GameLib.D3.API.Vector3();
|
||||
if (GameLib.Utils.UndefinedOrNull(axis)) {
|
||||
axis = new GameLib.API.Vector3();
|
||||
}
|
||||
this.axis = axis;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(angle)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||
angle = 0;
|
||||
}
|
||||
this.angle = angle;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.translate = function (v) {
|
||||
GameLib.API.Quaternion.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.copy = function () {
|
||||
return new GameLib.D3.API.Quaternion(
|
||||
GameLib.API.Quaternion.prototype.copy = function () {
|
||||
return new GameLib.API.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
|
@ -50,7 +50,7 @@ GameLib.D3.API.Quaternion.prototype.copy = function () {
|
|||
/**
|
||||
* Note, this normalize function leaves 'w' component untouched
|
||||
*/
|
||||
GameLib.D3.API.Quaternion.prototype.normalize = function () {
|
||||
GameLib.API.Quaternion.prototype.normalize = function () {
|
||||
|
||||
var EPSILON = 0.000001;
|
||||
|
||||
|
@ -67,13 +67,13 @@ GameLib.D3.API.Quaternion.prototype.normalize = function () {
|
|||
this.z *= invLength;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.multiply = function (q) {
|
||||
GameLib.API.Quaternion.prototype.multiply = function (q) {
|
||||
|
||||
var x, y, z, w;
|
||||
var a = q;
|
||||
var b = this;
|
||||
|
||||
if (q instanceof GameLib.D3.API.Matrix4) {
|
||||
if (q instanceof GameLib.API.Matrix4) {
|
||||
|
||||
x = a.rows[0].x * b.x + a.rows[0].y * b.y + a.rows[0].z * b.z + a.rows[0].w * b.w;
|
||||
y = a.rows[1].x * b.x + a.rows[1].y * b.y + a.rows[1].z * b.z + a.rows[1].w * b.w;
|
||||
|
@ -87,7 +87,7 @@ GameLib.D3.API.Quaternion.prototype.multiply = function (q) {
|
|||
|
||||
return this;
|
||||
|
||||
} else if (q instanceof GameLib.D3.API.Quaternion) {
|
||||
} else if (q instanceof GameLib.API.Quaternion) {
|
||||
|
||||
x = ((a.x * b.x) - (a.y * b.y) - (a.z * b.z) - (a.w * a.w));
|
||||
y = ((a.x * b.y) + (a.y * b.x) - (a.z * b.w) + (a.w * a.z));
|
||||
|
@ -107,7 +107,7 @@ GameLib.D3.API.Quaternion.prototype.multiply = function (q) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.setFromAngle = function (angle) {
|
||||
GameLib.API.Quaternion.prototype.setFromAngle = function (angle) {
|
||||
|
||||
this.instance.setFromAxisAngle(this.axis.instance, angle);
|
||||
|
||||
|
@ -119,15 +119,15 @@ GameLib.D3.API.Quaternion.prototype.setFromAngle = function (angle) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.subtract = function (v) {
|
||||
GameLib.API.Quaternion.prototype.subtract = function (v) {
|
||||
|
||||
if (v instanceof GameLib.D3.API.Vector3) {
|
||||
if (v instanceof GameLib.API.Vector3) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
}
|
||||
|
||||
if (v instanceof GameLib.D3.API.Quaternion) {
|
||||
if (v instanceof GameLib.API.Quaternion) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
|
@ -137,7 +137,7 @@ GameLib.D3.API.Quaternion.prototype.subtract = function (v) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.magnitude = function () {
|
||||
GameLib.API.Quaternion.prototype.magnitude = function () {
|
||||
return Math.sqrt(
|
||||
(this.x * this.x) +
|
||||
(this.y * this.y) +
|
||||
|
@ -146,7 +146,7 @@ GameLib.D3.API.Quaternion.prototype.magnitude = function () {
|
|||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.prototype.normalize = function () {
|
||||
GameLib.API.Quaternion.prototype.normalize = function () {
|
||||
|
||||
var magnitude = this.magnitude();
|
||||
|
||||
|
@ -164,9 +164,9 @@ GameLib.D3.API.Quaternion.prototype.normalize = function () {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param matrix4 GameLib.D3.Matrix4
|
||||
* @param matrix4 GameLib.Matrix4
|
||||
*/
|
||||
GameLib.D3.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) {
|
||||
GameLib.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) {
|
||||
|
||||
this.instance.setFromRotationMatrix(matrix4.instance);
|
||||
|
||||
|
@ -178,11 +178,11 @@ GameLib.D3.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param quaternion GameLib.D3.Quaternion
|
||||
* @param quaternion GameLib.Quaternion
|
||||
* @param t
|
||||
* @returns {GameLib.D3.Quaternion}
|
||||
* @returns {GameLib.Quaternion}
|
||||
*/
|
||||
GameLib.D3.API.Quaternion.prototype.slerp = function (quaternion, t) {
|
||||
GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) {
|
||||
|
||||
this.updateInstance();
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
GameLib.D3.API.Quaternion.Points = function () {
|
||||
GameLib.API.Quaternion.Points = function () {
|
||||
this.vectors = [];
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.add = function (vector) {
|
||||
GameLib.API.Quaternion.Points.prototype.add = function (vector) {
|
||||
|
||||
if (vector instanceof GameLib.D3.API.Vector3) {
|
||||
vector = new GameLib.D3.API.Quaternion(
|
||||
if (vector instanceof GameLib.API.Vector3) {
|
||||
vector = new GameLib.API.Quaternion(
|
||||
vector.x,
|
||||
vector.y,
|
||||
vector.z,
|
||||
|
@ -13,7 +13,7 @@ GameLib.D3.API.Quaternion.Points.prototype.add = function (vector) {
|
|||
)
|
||||
}
|
||||
|
||||
if (!vector instanceof GameLib.D3.API.Quaternion) {
|
||||
if (!vector instanceof GameLib.API.Quaternion) {
|
||||
console.warn("Vector needs to be of type Quaternion");
|
||||
throw new Error("Vector needs to be of type Quaternion");
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ GameLib.D3.API.Quaternion.Points.prototype.add = function (vector) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.copy = function () {
|
||||
GameLib.API.Quaternion.Points.prototype.copy = function () {
|
||||
|
||||
var vectors = [];
|
||||
|
||||
|
@ -34,13 +34,13 @@ GameLib.D3.API.Quaternion.Points.prototype.copy = function () {
|
|||
return vectors;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) {
|
||||
GameLib.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixY = new GameLib.D3.API.Matrix4().rotationMatrixY(grain);
|
||||
var rotationMatrixY = new GameLib.API.Matrix4().rotationMatrixY(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
|
@ -69,7 +69,7 @@ GameLib.D3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain)
|
|||
|
||||
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.API.Matrix4().rotationMatrixY(totalRadians);
|
||||
var maxRotationMatrix = new GameLib.API.Matrix4().rotationMatrixY(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
|
@ -79,13 +79,13 @@ GameLib.D3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain)
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) {
|
||||
GameLib.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixX = new GameLib.D3.API.Matrix4().rotationMatrixX(grain);
|
||||
var rotationMatrixX = new GameLib.API.Matrix4().rotationMatrixX(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
|
@ -113,7 +113,7 @@ GameLib.D3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain)
|
|||
|
||||
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.API.Matrix4().rotationMatrixX(totalRadians);
|
||||
var maxRotationMatrix = new GameLib.API.Matrix4().rotationMatrixX(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
|
@ -124,17 +124,17 @@ GameLib.D3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain)
|
|||
};
|
||||
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.lookAt = function (at, up) {
|
||||
GameLib.API.Quaternion.Points.prototype.lookAt = function (at, up) {
|
||||
|
||||
var polyCenter = this.average();
|
||||
|
||||
console.log("poly center : " + JSON.stringify(polyCenter));
|
||||
|
||||
var lookAtMatrix = new GameLib.D3.API.Matrix4().lookAt(polyCenter, at, up);
|
||||
var lookAtMatrix = new GameLib.API.Matrix4().lookAt(polyCenter, at, up);
|
||||
|
||||
lookAtMatrix.rows[0] = new GameLib.D3.API.Quaternion(1, 0, 0, 0);
|
||||
lookAtMatrix.rows[1] = new GameLib.D3.API.Quaternion(0, 0, 1, 0);
|
||||
lookAtMatrix.rows[2] = new GameLib.D3.API.Quaternion(0, 1, 0, 0);
|
||||
lookAtMatrix.rows[0] = new GameLib.API.Quaternion(1, 0, 0, 0);
|
||||
lookAtMatrix.rows[1] = new GameLib.API.Quaternion(0, 0, 1, 0);
|
||||
lookAtMatrix.rows[2] = new GameLib.API.Quaternion(0, 1, 0, 0);
|
||||
|
||||
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
|
||||
|
||||
|
@ -145,7 +145,7 @@ GameLib.D3.API.Quaternion.Points.prototype.lookAt = function (at, up) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.distances = function () {
|
||||
GameLib.API.Quaternion.Points.prototype.distances = function () {
|
||||
|
||||
var minX = this.vectors[0].x;
|
||||
var minY = this.vectors[0].y;
|
||||
|
@ -177,14 +177,14 @@ GameLib.D3.API.Quaternion.Points.prototype.distances = function () {
|
|||
}
|
||||
}
|
||||
|
||||
return new GameLib.D3.API.Vector3(
|
||||
return new GameLib.API.Vector3(
|
||||
Math.abs(maxX - minX),
|
||||
Math.abs(maxY - minY),
|
||||
Math.abs(maxY - minZ)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.average = function () {
|
||||
GameLib.API.Quaternion.Points.prototype.average = function () {
|
||||
var averageX = 0;
|
||||
var averageY = 0;
|
||||
var averageZ = 0;
|
||||
|
@ -195,14 +195,14 @@ GameLib.D3.API.Quaternion.Points.prototype.average = function () {
|
|||
averageZ += this.vectors[i].z;
|
||||
}
|
||||
|
||||
return new GameLib.D3.API.Vector3(
|
||||
return new GameLib.API.Vector3(
|
||||
averageX / this.vectors.length,
|
||||
averageY / this.vectors.length,
|
||||
averageZ / this.vectors.length
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.negate = function () {
|
||||
GameLib.API.Quaternion.Points.prototype.negate = function () {
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
this.vectors[i].x *= -1;
|
||||
|
@ -214,7 +214,7 @@ GameLib.D3.API.Quaternion.Points.prototype.negate = function () {
|
|||
};
|
||||
|
||||
|
||||
GameLib.D3.API.Quaternion.Points.prototype.toOrigin = function () {
|
||||
GameLib.API.Quaternion.Points.prototype.toOrigin = function () {
|
||||
|
||||
var distanceFromOrigin = this.average().negate();
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
GameLib.D3.API.Vector2 = function ApiVector2(x, y) {
|
||||
GameLib.API.Vector2 = function ApiVector2(x, y) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(x)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(y)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector2.prototype.copy = function () {
|
||||
return new GameLib.D3.API.Vector2(
|
||||
GameLib.API.Vector2.prototype.copy = function () {
|
||||
return new GameLib.API.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
|
|
|
@ -1,112 +1,112 @@
|
|||
GameLib.D3.API.Vector3 = function (x, y, z) {
|
||||
GameLib.API.Vector3 = function (x, y, z) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(x)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(y)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(z)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.negate = function() {
|
||||
GameLib.API.Vector3.prototype.negate = function() {
|
||||
this.x = -this.x;
|
||||
this.y = -this.y;
|
||||
this.z = -this.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.subtract = function (v) {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.subtract = function (v) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x - v.x,
|
||||
this.y - v.y,
|
||||
this.z - v.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.sub = function (v) {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.sub = function (v) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x - v.x,
|
||||
this.y - v.y,
|
||||
this.z - v.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.cross = function (v) {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.cross = function (v) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.y * v.z - this.z * v.y,
|
||||
this.z * v.x - this.x * v.z,
|
||||
this.x * v.y - this.y * v.x
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.clockwise = function (u, v, w, viewPoint) {
|
||||
var normal = GameLib.D3.API.Vector3.normal(u, v, w);
|
||||
GameLib.API.Vector3.clockwise = function (u, v, w, viewPoint) {
|
||||
var normal = GameLib.API.Vector3.normal(u, v, w);
|
||||
var uv = u.copy();
|
||||
var winding = normal.dot(uv.subtract(viewPoint));
|
||||
return (winding > 0);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.normal = function (u, v, w) {
|
||||
GameLib.API.Vector3.normal = function (u, v, w) {
|
||||
var vv = v.copy();
|
||||
var wv = w.copy();
|
||||
return vv.subtract(u).cross(wv.subtract(u));
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.lookAt = function (at, up) {
|
||||
var lookAtMatrix = GameLib.D3.API.Matrix4.lookAt(this, at, up);
|
||||
GameLib.API.Vector3.prototype.lookAt = function (at, up) {
|
||||
var lookAtMatrix = GameLib.API.Matrix4.lookAt(this, at, up);
|
||||
return this.multiply(lookAtMatrix);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.translate = function (v) {
|
||||
GameLib.API.Vector3.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.add = function (v) {
|
||||
GameLib.API.Vector3.prototype.add = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.squared = function () {
|
||||
GameLib.API.Vector3.prototype.squared = function () {
|
||||
return this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.copy = function () {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.copy = function () {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.set = function (x, y, z) {
|
||||
GameLib.API.Vector3.prototype.set = function (x, y, z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x + ( v.x - this.x ) * alpha,
|
||||
this.y + ( v.y - this.y ) * alpha,
|
||||
this.z + ( v.z - this.z ) * alpha
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.distanceTo = function(v) {
|
||||
GameLib.API.Vector3.prototype.distanceTo = function(v) {
|
||||
var dx = this.x - v.x,
|
||||
dy = this.y - v.y,
|
||||
dz = this.z - v.z;
|
||||
|
@ -116,7 +116,7 @@ GameLib.D3.API.Vector3.prototype.distanceTo = function(v) {
|
|||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
GameLib.D3.API.Vector3.AngleDirection = function(forward, directionToCheck, up) {
|
||||
GameLib.API.Vector3.AngleDirection = function(forward, directionToCheck, up) {
|
||||
var perp = forward.cross(directionToCheck);
|
||||
var dir = perp.dot(up);
|
||||
|
||||
|
@ -131,18 +131,18 @@ GameLib.D3.API.Vector3.AngleDirection = function(forward, directionToCheck, up)
|
|||
|
||||
/**
|
||||
* Multiplies this vector with a scalar, vector or matrix. If you want a copy, copy() it first
|
||||
* @param object {Number | GameLib.D3.API.Vector3 | GameLib.D3.API.Vector4 | GameLib.D3.API.Matrix3 | GameLib.D3.API.Matrix4}
|
||||
* @param object {Number | GameLib.API.Vector3 | GameLib.API.Vector4 | GameLib.API.Matrix3 | GameLib.API.Matrix4}
|
||||
* @param cross boolean true if you want the cross product, otherwise returns the scalar (dot or inner) product
|
||||
* @returns {GameLib.D3.API.Vector3 | Number}
|
||||
* @returns {GameLib.API.Vector3 | Number}
|
||||
*/
|
||||
GameLib.D3.API.Vector3.prototype.multiply = function (object, cross) {
|
||||
GameLib.API.Vector3.prototype.multiply = function (object, cross) {
|
||||
|
||||
var x, y, z;
|
||||
|
||||
var a = object;
|
||||
var b = this;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(cross)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(cross)) {
|
||||
cross = false;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ GameLib.D3.API.Vector3.prototype.multiply = function (object, cross) {
|
|||
|
||||
}
|
||||
|
||||
if (object instanceof GameLib.D3.API.Vector3) {
|
||||
if (object instanceof GameLib.API.Vector3) {
|
||||
|
||||
if (cross) {
|
||||
|
||||
|
@ -184,11 +184,11 @@ GameLib.D3.API.Vector3.prototype.multiply = function (object, cross) {
|
|||
};
|
||||
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.dot = function (v) {
|
||||
GameLib.API.Vector3.prototype.dot = function (v) {
|
||||
return (this.x * v.x) + (this.y * v.y) + (this.z * v.z);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.normalize = function () {
|
||||
GameLib.API.Vector3.prototype.normalize = function () {
|
||||
var EPSILON = 0.000001;
|
||||
var v2 = this.squared();
|
||||
|
||||
|
@ -197,22 +197,22 @@ GameLib.D3.API.Vector3.prototype.normalize = function () {
|
|||
}
|
||||
|
||||
var invLength = 1.0 / Math.sqrt(v2);
|
||||
return new GameLib.D3.API.Vector3(
|
||||
return new GameLib.API.Vector3(
|
||||
this.x * invLength,
|
||||
this.y * invLength,
|
||||
this.z * invLength
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.clone = function () {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.API.Vector3.prototype.clone = function () {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.applyQuaternion = function(q) {
|
||||
GameLib.API.Vector3.prototype.applyQuaternion = function(q) {
|
||||
var x = this.x, y = this.y, z = this.z;
|
||||
var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
|
||||
|
||||
|
@ -232,7 +232,7 @@ GameLib.D3.API.Vector3.prototype.applyQuaternion = function(q) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.clamp = function(min, max) {
|
||||
GameLib.API.Vector3.prototype.clamp = function(min, max) {
|
||||
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.z = Math.max( min.z, Math.min( max.z, this.z ) );
|
||||
|
@ -240,15 +240,15 @@ GameLib.D3.API.Vector3.prototype.clamp = function(min, max) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.length = function() {
|
||||
GameLib.API.Vector3.prototype.length = function() {
|
||||
return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.reflect = function(normal) {
|
||||
GameLib.API.Vector3.prototype.reflect = function(normal) {
|
||||
return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) );
|
||||
};
|
||||
|
||||
GameLib.D3.API.Vector3.prototype.angleTo = function (v) {
|
||||
GameLib.API.Vector3.prototype.angleTo = function (v) {
|
||||
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
|
||||
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
|
||||
};
|
|
@ -1,21 +1,21 @@
|
|||
GameLib.D3.API.Vector4 = function (x, y, z, w) {
|
||||
GameLib.API.Vector4 = function (x, y, z, w) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(x)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||
x = 0;
|
||||
}
|
||||
this.x = x;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(y)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(y)) {
|
||||
y = 0;
|
||||
}
|
||||
this.y = y;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(z)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(z)) {
|
||||
z = 0;
|
||||
}
|
||||
this.z = z;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(w)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(w)) {
|
||||
w = 1;
|
||||
}
|
||||
this.w = w;
|
||||
|
|
|
@ -2,44 +2,44 @@
|
|||
* Common properties of all Components
|
||||
* @param id
|
||||
* @param name
|
||||
* @param componentType GameLib.D3.Component.COMPONENT_*
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param componentType GameLib.Component.COMPONENT_*
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @param linkedProperties GameLib.D3.LinkedProperty[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Component = function Component(
|
||||
GameLib.Component = function Component(
|
||||
id,
|
||||
name,
|
||||
componentType,
|
||||
parentEntity,
|
||||
linkedProperties
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(componentType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(componentType)) {
|
||||
throw new Error('No Component Type - You should extend from this class not instantiate directly');
|
||||
}
|
||||
this.componentType = componentType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(linkedProperties)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(linkedProperties)) {
|
||||
linkedProperties = [];
|
||||
}
|
||||
this.linkedProperties = linkedProperties;
|
||||
|
||||
this.linkedProperties.push(
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
new GameLib.Component.LinkedProperty(
|
||||
'parentEntity',
|
||||
GameLib.D3.Entity
|
||||
GameLib.Entity
|
||||
)
|
||||
)
|
||||
};
|
||||
|
@ -51,7 +51,7 @@ GameLib.D3.Component = function Component(
|
|||
* @param objectType GameLib.D3.Object
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Component.LinkedProperty = function(
|
||||
GameLib.Component.LinkedProperty = function(
|
||||
propertyName,
|
||||
objectType
|
||||
) {
|
||||
|
@ -59,32 +59,32 @@ GameLib.D3.Component.LinkedProperty = function(
|
|||
this.objectType = objectType;
|
||||
};
|
||||
|
||||
GameLib.D3.Component.COMPONENT_INTERFACE = 0x1;
|
||||
GameLib.D3.Component.COMPONENT_CAMERA = 0x2;
|
||||
GameLib.D3.Component.COMPONENT_COLOR_FLASH = 0x3;
|
||||
GameLib.D3.Component.COMPONENT_COLOR_LERP = 0x4;
|
||||
GameLib.D3.Component.COMPONENT_FLY_CONTROLS = 0x5;
|
||||
GameLib.D3.Component.COMPONENT_FOLLOW = 0x6;
|
||||
GameLib.D3.Component.COMPONENT_LOOK_AT = 0x7;
|
||||
GameLib.D3.Component.COMPONENT_MESH = 0x8;
|
||||
GameLib.D3.Component.COMPONENT_MESH_PERMUTATION = 0x9;
|
||||
GameLib.D3.Component.COMPONENT_PATH_AI = 0xA;
|
||||
GameLib.D3.Component.COMPONENT_PATH_FOLLOWING = 0xB;
|
||||
GameLib.D3.Component.COMPONENT_PATH_CONTROLS = 0xC;
|
||||
GameLib.D3.Component.COMPONENT_RAYCAST_VEHICLE_CONTROLS = 0xD;
|
||||
GameLib.D3.Component.COMPONENT_TRIGGER_BOX_BOX = 0xE;
|
||||
GameLib.D3.Component.COMPONENT_TRIGGER_BOX_SPHERE = 0xF;
|
||||
GameLib.D3.Component.COMPONENT_TRIGGER_SPHERE_SPHERE = 0x10;
|
||||
GameLib.D3.Component.COMPONENT_VEHICLE_AI_OBJECT_AVOIDENCE = 0x11;
|
||||
GameLib.D3.Component.COMPONENT_VEHICLE_AI_PATH_STEERING = 0x12;
|
||||
GameLib.Component.COMPONENT_INTERFACE = 0x1;
|
||||
GameLib.Component.COMPONENT_CAMERA = 0x2;
|
||||
GameLib.Component.COMPONENT_COLOR_FLASH = 0x3;
|
||||
GameLib.Component.COMPONENT_COLOR_LERP = 0x4;
|
||||
GameLib.Component.COMPONENT_FLY_CONTROLS = 0x5;
|
||||
GameLib.Component.COMPONENT_FOLLOW = 0x6;
|
||||
GameLib.Component.COMPONENT_LOOK_AT = 0x7;
|
||||
GameLib.Component.COMPONENT_MESH = 0x8;
|
||||
GameLib.Component.COMPONENT_MESH_PERMUTATION = 0x9;
|
||||
GameLib.Component.COMPONENT_PATH_AI = 0xA;
|
||||
GameLib.Component.COMPONENT_PATH_FOLLOWING = 0xB;
|
||||
GameLib.Component.COMPONENT_PATH_CONTROLS = 0xC;
|
||||
GameLib.Component.COMPONENT_RAYCAST_VEHICLE_CONTROLS = 0xD;
|
||||
GameLib.Component.COMPONENT_TRIGGER_BOX_BOX = 0xE;
|
||||
GameLib.Component.COMPONENT_TRIGGER_BOX_SPHERE = 0xF;
|
||||
GameLib.Component.COMPONENT_TRIGGER_SPHERE_SPHERE = 0x10;
|
||||
GameLib.Component.COMPONENT_VEHICLE_AI_OBJECT_AVOIDENCE = 0x11;
|
||||
GameLib.Component.COMPONENT_VEHICLE_AI_PATH_STEERING = 0x12;
|
||||
|
||||
GameLib.D3.Component.prototype.toApiComponent = function() {
|
||||
GameLib.Component.prototype.toApiComponent = function() {
|
||||
|
||||
var apiComponent = new GameLib.D3.API.Component(
|
||||
var apiComponent = new GameLib.API.Component(
|
||||
this.id,
|
||||
this.name,
|
||||
this.componentType,
|
||||
GameLib.D3.Utils.IdOrNull(this.parentEntity)
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
var isObjectProperty;
|
||||
|
@ -107,17 +107,17 @@ GameLib.D3.Component.prototype.toApiComponent = function() {
|
|||
}
|
||||
|
||||
if (isObjectProperty) {
|
||||
apiComponent[property] = GameLib.D3.Utils.IdOrNull(this[property]);
|
||||
apiComponent[property] = GameLib.Utils.IdOrNull(this[property]);
|
||||
} else if (
|
||||
this[property] instanceof GameLib.D3.Vector2 ||
|
||||
this[property] instanceof GameLib.D3.Vector3
|
||||
this[property] instanceof GameLib.Vector2 ||
|
||||
this[property] instanceof GameLib.Vector3
|
||||
) {
|
||||
apiComponent[property] = this[property].toApiVector();
|
||||
} else if (this[property] instanceof GameLib.D3.Quaternion) {
|
||||
} else if (this[property] instanceof GameLib.Quaternion) {
|
||||
apiComponent[property] = this[property].toApiQuaternion();
|
||||
} else if (
|
||||
this[property] instanceof GameLib.D3.Matrix3 ||
|
||||
this[property] instanceof GameLib.D3.Matrix4
|
||||
this[property] instanceof GameLib.Matrix3 ||
|
||||
this[property] instanceof GameLib.Matrix4
|
||||
) {
|
||||
apiComponent[property] = this[property].toApiMatrix();
|
||||
} else {
|
||||
|
@ -135,37 +135,37 @@ GameLib.D3.Component.prototype.toApiComponent = function() {
|
|||
};
|
||||
|
||||
/**
|
||||
* Converts and Object component into a proper GameLib.D3.Component
|
||||
* Converts and Object component into a proper GameLib.Component
|
||||
* @param graphics
|
||||
* @param objectComponent
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Component.FromObjectComponent = function(graphics, objectComponent) {
|
||||
GameLib.Component.FromObjectComponent = function(graphics, objectComponent) {
|
||||
|
||||
var component = null;
|
||||
|
||||
switch (objectComponent.componentType) {
|
||||
|
||||
case GameLib.D3.Component.COMPONENT_CAMERA :
|
||||
component = new GameLib.D3.ComponentCamera();
|
||||
case GameLib.Component.COMPONENT_CAMERA :
|
||||
component = new GameLib.ComponentCamera();
|
||||
break;
|
||||
|
||||
case GameLib.D3.Component.COMPONENT_FOLLOW :
|
||||
component = new GameLib.D3.ComponentFollow(null, null, graphics);
|
||||
case GameLib.Component.COMPONENT_FOLLOW :
|
||||
component = new GameLib.ComponentFollow(null, null, graphics);
|
||||
break;
|
||||
|
||||
case GameLib.D3.Component.COMPONENT_LOOK_AT :
|
||||
component = new GameLib.D3.ComponentLookAt(null, null, graphics);
|
||||
case GameLib.Component.COMPONENT_LOOK_AT :
|
||||
component = new GameLib.ComponentLookAt(null, null, graphics);
|
||||
break;
|
||||
|
||||
case GameLib.D3.Component.COMPONENT_PATH_FOLLOWING :
|
||||
component = new GameLib.D3.ComponentPathFollowing(null, null, graphics);
|
||||
case GameLib.Component.COMPONENT_PATH_FOLLOWING :
|
||||
component = new GameLib.ComponentPathFollowing(null, null, graphics);
|
||||
break;
|
||||
case GameLib.D3.Component.COMPONENT_MESH :
|
||||
component = new GameLib.D3.ComponentMesh(null, null, graphics);
|
||||
case GameLib.Component.COMPONENT_MESH :
|
||||
component = new GameLib.ComponentMesh(null, null, graphics);
|
||||
break;
|
||||
case GameLib.D3.Component.COMPONENT_MESH_PERMUTATION :
|
||||
component = new GameLib.D3.ComponentMeshPermutation(null, null, graphics);
|
||||
case GameLib.Component.COMPONENT_MESH_PERMUTATION :
|
||||
component = new GameLib.ComponentMeshPermutation(null, null, graphics);
|
||||
break;
|
||||
default:
|
||||
console.warn('This type of component is not yet read from the database:' + objectComponent.componentType);
|
||||
|
@ -177,36 +177,36 @@ GameLib.D3.Component.FromObjectComponent = function(graphics, objectComponent) {
|
|||
component.hasOwnProperty(property) &&
|
||||
objectComponent.hasOwnProperty(property)
|
||||
) {
|
||||
if (component[property] instanceof GameLib.D3.Vector2) {
|
||||
component[property] = new GameLib.D3.Vector2(
|
||||
if (component[property] instanceof GameLib.Vector2) {
|
||||
component[property] = new GameLib.Vector2(
|
||||
graphics,
|
||||
component,
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
objectComponent[property].x,
|
||||
objectComponent[property].y
|
||||
)
|
||||
)
|
||||
} else if (component[property] instanceof GameLib.D3.Vector3) {
|
||||
component[property] = new GameLib.D3.Vector3(
|
||||
} else if (component[property] instanceof GameLib.Vector3) {
|
||||
component[property] = new GameLib.Vector3(
|
||||
graphics,
|
||||
component,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectComponent[property].x,
|
||||
objectComponent[property].y,
|
||||
objectComponent[property].z
|
||||
)
|
||||
)
|
||||
} else if (component[property] instanceof GameLib.D3.Quaternion) {
|
||||
} else if (component[property] instanceof GameLib.Quaternion) {
|
||||
|
||||
component[property] = new GameLib.D3.Quaternion(
|
||||
component[property] = new GameLib.Quaternion(
|
||||
graphics,
|
||||
component,
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectComponent[property].x,
|
||||
objectComponent[property].y,
|
||||
objectComponent[property].z,
|
||||
objectComponent[property].w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectComponent[property].axis.x,
|
||||
objectComponent[property].axis.y,
|
||||
objectComponent[property].axis.z
|
||||
|
@ -228,31 +228,31 @@ GameLib.D3.Component.FromObjectComponent = function(graphics, objectComponent) {
|
|||
)
|
||||
)
|
||||
|
||||
} else if (component[property] instanceof GameLib.D3.Matrix4) {
|
||||
} else if (component[property] instanceof GameLib.Matrix4) {
|
||||
|
||||
component[property] = new GameLib.D3.Matrix4(
|
||||
component[property] = new GameLib.Matrix4(
|
||||
graphics,
|
||||
component,
|
||||
new GameLib.D3.API.Matrix4(
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Matrix4(
|
||||
new GameLib.API.Quaternion(
|
||||
objectComponent[property].rows[0].x,
|
||||
objectComponent[property].rows[0].y,
|
||||
objectComponent[property].rows[0].z,
|
||||
objectComponent[property].rows[0].w
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectComponent[property].rows[1].x,
|
||||
objectComponent[property].rows[1].y,
|
||||
objectComponent[property].rows[1].z,
|
||||
objectComponent[property].rows[1].w
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectComponent[property].rows[2].x,
|
||||
objectComponent[property].rows[2].y,
|
||||
objectComponent[property].rows[2].z,
|
||||
objectComponent[property].rows[2].w
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectComponent[property].rows[3].x,
|
||||
objectComponent[property].rows[3].y,
|
||||
objectComponent[property].rows[3].z,
|
||||
|
@ -278,7 +278,7 @@ GameLib.D3.Component.FromObjectComponent = function(graphics, objectComponent) {
|
|||
* @callback
|
||||
* @default null
|
||||
*/
|
||||
GameLib.D3.Component.prototype.onUpdate = null;
|
||||
GameLib.Component.prototype.onUpdate = null;
|
||||
|
||||
/**
|
||||
* Gets executed from every entity during each game loop - after onUpdate has been called
|
||||
|
@ -287,30 +287,30 @@ GameLib.D3.Component.prototype.onUpdate = null;
|
|||
* @override
|
||||
* @callback
|
||||
*/
|
||||
GameLib.D3.Component.prototype.onLateUpdate = null;
|
||||
GameLib.Component.prototype.onLateUpdate = null;
|
||||
|
||||
|
||||
/**
|
||||
* Gets executed when component is added to an Entity
|
||||
* @param entity GameLib.D3.Entity
|
||||
* @param entity GameLib.Entity
|
||||
* @override
|
||||
* @callback
|
||||
*/
|
||||
GameLib.D3.Component.prototype.onAdd = function(entity) {};
|
||||
GameLib.Component.prototype.onAdd = function(entity) {};
|
||||
|
||||
/**
|
||||
* Gets executed when a component is removed from an Entity
|
||||
* @param entity GameLib.D3.Entity
|
||||
* @param entity GameLib.Entity
|
||||
* @override
|
||||
* @callback
|
||||
*/
|
||||
GameLib.D3.Component.prototype.onRemove = function(entity) {};
|
||||
GameLib.Component.prototype.onRemove = function(entity) {};
|
||||
|
||||
/**
|
||||
* links object ids to actual objects
|
||||
* @param idToObject Object linking object components to objects
|
||||
*/
|
||||
GameLib.D3.Component.prototype.linkObjects = function(idToObject) {
|
||||
GameLib.Component.prototype.linkObjects = function(idToObject) {
|
||||
|
||||
this.linkedProperties.forEach(
|
||||
function (linkedProperty) {
|
||||
|
@ -326,6 +326,6 @@ GameLib.D3.Component.prototype.linkObjects = function(idToObject) {
|
|||
* Clones this component
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Component.prototype.clone = function() {
|
||||
GameLib.Component.prototype.clone = function() {
|
||||
return _.cloneDeep(this);
|
||||
};
|
||||
|
|
|
@ -3,38 +3,38 @@
|
|||
* is.
|
||||
* @param id
|
||||
* @param name String
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @param camera GameLib.D3.Camera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentCamera = function ComponentCamera(
|
||||
GameLib.ComponentCamera = function ComponentCamera(
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
camera
|
||||
) {
|
||||
GameLib.D3.Component.call(
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_CAMERA,
|
||||
GameLib.Component.COMPONENT_CAMERA,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
new GameLib.Component.LinkedProperty(
|
||||
'camera',
|
||||
GameLib.D3.Camera
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(camera)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentCamera.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentCamera.prototype.constructor = GameLib.D3.ComponentCamera;
|
||||
GameLib.ComponentCamera.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.ComponentCamera.prototype.constructor = GameLib.ComponentCamera;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ GameLib.D3.ComponentCamera.prototype.constructor = GameLib.D3.ComponentCamera;
|
|||
* @override
|
||||
* @callback
|
||||
*/
|
||||
GameLib.D3.ComponentCamera.prototype.onLateUpdate = function() {
|
||||
GameLib.ComponentCamera.prototype.onLateUpdate = function() {
|
||||
|
||||
if (this.camera) {
|
||||
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
* @param name
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentColorFlash = function ComponentColorFlash(
|
||||
GameLib.ComponentColorFlash = function ComponentColorFlash(
|
||||
id,
|
||||
name
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -18,18 +18,18 @@ GameLib.D3.ComponentColorFlash = function ComponentColorFlash(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentColorFlash, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentColorFlash, GameLib.Component);
|
||||
};
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentColorFlash.prototype.onUpdate = function(
|
||||
GameLib.ComponentColorFlash.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
this.parentEntity.mesh.material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentColorFlash.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentColorFlash.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
GameLib.D3.ComponentColorLerp = function(
|
||||
GameLib.ComponentColorLerp = function(
|
||||
id,
|
||||
name,
|
||||
startColor,
|
||||
endColor,
|
||||
lerpSpeed
|
||||
) {
|
||||
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||
this.id = id|| GameLib.Utils.RandomId();
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
|
@ -14,17 +14,17 @@ GameLib.D3.ComponentColorLerp = function(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentColorLerp, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentColorLerp, GameLib.Component);
|
||||
|
||||
this.startColor = startColor || new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
this.endColor = endColor || new GameLib.D3.API.Vector3(1, 1, 1);
|
||||
this.startColor = startColor || new GameLib.API.Vector3(0, 0, 0);
|
||||
this.endColor = endColor || new GameLib.API.Vector3(1, 1, 1);
|
||||
this.lerpSpeed = lerpSpeed || 1.0;
|
||||
|
||||
this.lerpTarget = this.endColor;
|
||||
};
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentColorLerp.prototype.onUpdate = function(
|
||||
GameLib.ComponentColorLerp.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -54,7 +54,7 @@ GameLib.D3.ComponentColorLerp.prototype.onUpdate = function(
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentColorLerp.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentColorLerp.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
*
|
||||
* @param id {String}
|
||||
* @param name {String}
|
||||
* @param parent {GameLib.D3.Entity}
|
||||
* @param parent {GameLib.Entity}
|
||||
* @param centerToOrigin {Boolean}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentEntityParent = function ComponentEntityParent(
|
||||
GameLib.ComponentEntityParent = function ComponentEntityParent(
|
||||
id,
|
||||
name,
|
||||
parent,
|
||||
centerToOrigin
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -22,9 +22,9 @@ GameLib.D3.ComponentEntityParent = function ComponentEntityParent(
|
|||
|
||||
this.parentEntity = null;
|
||||
this.centerToOrigin = centerToOrigin;
|
||||
this.originPosition = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
this.originPosition = new GameLib.API.Vector3(0, 0, 0);
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityParent, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentEntityParent, GameLib.Component);
|
||||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
@ -35,7 +35,7 @@ if(typeof THREE !== "undefined") {
|
|||
}
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
|
||||
GameLib.ComponentEntityParent.prototype.onLateUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -89,7 +89,7 @@ GameLib.D3.ComponentEntityParent.prototype.onLateUpdate = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentEntityParent.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentEntityParent.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -100,7 +100,7 @@ GameLib.D3.ComponentEntityParent.prototype.onSetParentEntity = function(
|
|||
|
||||
if(this.centerToOrigin) {
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(this.parent.origin)) {
|
||||
if(GameLib.Utils.UndefinedOrNull(this.parent.origin)) {
|
||||
this.parent.origin = this.parent.mesh.geometry.center();
|
||||
parentEntity.position.x = this.parent.position.x - this.parent.origin.x;
|
||||
parentEntity.position.y = this.parent.position.y - this.parent.origin.y;
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
* @param scaleOffset
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
|
||||
GameLib.ComponentEntityPermutation = function ComponentEntityPermutation(
|
||||
id,
|
||||
name,
|
||||
positionOffset,
|
||||
quaternionOffset,
|
||||
scaleOffset
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -23,21 +23,21 @@ GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
|
|||
|
||||
this.parentEntity = null;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
} this.positionOffset = positionOffset;
|
||||
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.D3.API.Quaternion(0, 0, 0, 1);
|
||||
if(GameLib.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.API.Quaternion(0, 0, 0, 1);
|
||||
} this.quaternionOffset = quaternionOffset;
|
||||
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.D3.API.Vector3(1, 1, 1);
|
||||
if(GameLib.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.API.Vector3(1, 1, 1);
|
||||
} this.scaleOffset = scaleOffset;
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentEntityPermutation, GameLib.Component);
|
||||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
@ -52,7 +52,7 @@ if(typeof THREE != "undefined") {
|
|||
}
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentEntityPermutation.prototype.onUpdate = function(
|
||||
GameLib.ComponentEntityPermutation.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
* @param name
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentFlyControls = function ComponentFlyControls(
|
||||
GameLib.ComponentFlyControls = function ComponentFlyControls(
|
||||
id,
|
||||
name
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -18,7 +18,7 @@ GameLib.D3.ComponentFlyControls = function ComponentFlyControls(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentFlyControls, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentFlyControls, GameLib.Component);
|
||||
|
||||
// Component fields
|
||||
this.pitch = 0;
|
||||
|
@ -35,7 +35,7 @@ GameLib.D3.ComponentFlyControls = function ComponentFlyControls(
|
|||
};
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentFlyControls.prototype.onUpdate = function(
|
||||
GameLib.ComponentFlyControls.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -107,7 +107,7 @@ GameLib.D3.ComponentFlyControls.prototype.onUpdate = function(
|
|||
* @param parentScene
|
||||
* @param parentEntity
|
||||
*/
|
||||
GameLib.D3.ComponentFlyControls.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentFlyControls.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -1,181 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param targetEntity GameLib.D3.Entity
|
||||
* @param targetOffset GameLib.D3.API.Vector3
|
||||
* @param minDistance
|
||||
* @param moveSpeed
|
||||
* @param parentEntity
|
||||
* @param target GameLib.D3.API.Vector3
|
||||
* @param targetToParent GameLib.D3.API.Vector3
|
||||
* @param rotatedTargetOffset GameLib.D3.API.Vector3
|
||||
* @param rotated GameLib.D3.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentFollow = function ComponentFollow(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
parentEntity,
|
||||
targetEntity,
|
||||
targetOffset,
|
||||
minDistance,
|
||||
moveSpeed,
|
||||
target,
|
||||
targetToParent,
|
||||
rotatedTargetOffset,
|
||||
rotated
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_FOLLOW,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
'targetEntity',
|
||||
GameLib.D3.Entity
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(targetEntity)) {
|
||||
targetEntity = null;
|
||||
}
|
||||
this.targetEntity = targetEntity;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
targetOffset = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
targetOffset
|
||||
);
|
||||
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(moveSpeed)) {
|
||||
moveSpeed = 12.5;
|
||||
}
|
||||
this.moveSpeed = moveSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minDistance)) {
|
||||
minDistance = 0;
|
||||
}
|
||||
this.minDistance = minDistance;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(target)) {
|
||||
target = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
target = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
target
|
||||
);
|
||||
this.target = target;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(targetToParent)) {
|
||||
targetToParent = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
targetToParent = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
targetToParent
|
||||
);
|
||||
|
||||
this.targetToParent = targetToParent;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(rotatedTargetOffset)) {
|
||||
rotatedTargetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
rotatedTargetOffset = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
rotatedTargetOffset
|
||||
);
|
||||
this.rotatedTargetOffset = rotatedTargetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotated)) {
|
||||
rotated = new GameLib.D3.API.Quaternion();
|
||||
}
|
||||
rotated = new GameLib.D3.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
rotated
|
||||
);
|
||||
this.rotated = rotated;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentFollow.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentFollow.prototype.constructor = GameLib.D3.ComponentFollow;
|
||||
|
||||
/**
|
||||
* onUpdate callback
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.ComponentFollow.prototype.onUpdate = function(
|
||||
deltaTime
|
||||
) {
|
||||
|
||||
if (this.parentEntity && this.targetEntity) {
|
||||
|
||||
this.rotated.x = this.targetEntity.quaternion.x;
|
||||
this.rotated.y = this.targetEntity.quaternion.y;
|
||||
this.rotated.z = this.targetEntity.quaternion.z;
|
||||
this.rotated.w = this.targetEntity.quaternion.w;
|
||||
|
||||
this.rotated.updateInstance();
|
||||
|
||||
this.rotatedTargetOffset.x = this.targetOffset.x;
|
||||
this.rotatedTargetOffset.y = this.targetOffset.y;
|
||||
this.rotatedTargetOffset.z = this.targetOffset.z;
|
||||
|
||||
this.rotatedTargetOffset.applyQuaternion(this.rotated);
|
||||
|
||||
this.rotatedTargetOffset.updateInstance();
|
||||
|
||||
this.target.x = this.targetEntity.position.x + this.rotatedTargetOffset.x;
|
||||
this.target.y = this.targetEntity.position.y + this.rotatedTargetOffset.y;
|
||||
this.target.z = this.targetEntity.position.z + this.rotatedTargetOffset.z;
|
||||
|
||||
this.target.updateInstance();
|
||||
|
||||
this.targetToParent.x = this.parentEntity.position.x - this.targetEntity.position.x;
|
||||
this.targetToParent.y = this.parentEntity.position.y - this.targetEntity.position.y;
|
||||
this.targetToParent.z = this.parentEntity.position.z - this.targetEntity.position.z;
|
||||
|
||||
this.targetToParent.normalize();
|
||||
|
||||
this.targetToParent.x *= this.minDistance;
|
||||
this.targetToParent.y *= this.minDistance;
|
||||
this.targetToParent.z *= this.minDistance;
|
||||
|
||||
this.targetToParent.updateInstance();
|
||||
|
||||
this.target.x = this.target.x + this.targetToParent.x;
|
||||
this.target.y = this.target.y + this.targetToParent.y;
|
||||
this.target.z = this.target.z + this.targetToParent.z;
|
||||
|
||||
this.target.updateInstance();
|
||||
|
||||
var t = deltaTime * this.moveSpeed;
|
||||
|
||||
//t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
var lerp = this.parentEntity.position.lerp(this.target, t);
|
||||
|
||||
this.parentEntity.position.x = lerp.x;
|
||||
this.parentEntity.position.y = lerp.y;
|
||||
this.parentEntity.position.z = lerp.z;
|
||||
|
||||
this.parentEntity.position.updateInstance();
|
||||
}
|
||||
};
|
|
@ -1,132 +0,0 @@
|
|||
/**
|
||||
* Looks from parentEntity to targetEntity (default up is 0,1,0)
|
||||
* @param id
|
||||
* @param name
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param targetEntity GameLib.D3.Entity
|
||||
* @param targetOffset GameLib.D3.API.Vector3
|
||||
* @param rotationSpeed
|
||||
* @param lookAtMatrix GameLib.D3.API.Matrix4
|
||||
* @param up GameLib.D3.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentLookAt = function ComponentLookAt(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
parentEntity,
|
||||
targetEntity,
|
||||
targetOffset,
|
||||
rotationSpeed,
|
||||
lookAtMatrix,
|
||||
up
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_LOOK_AT,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
'targetEntity',
|
||||
GameLib.D3.Entity
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(targetEntity)) {
|
||||
targetEntity = null;
|
||||
}
|
||||
this.targetEntity = targetEntity;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
targetOffset = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
targetOffset
|
||||
);
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
rotationSpeed = 22.0;
|
||||
}
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lookAtMatrix)) {
|
||||
lookAtMatrix = new GameLib.D3.API.Matrix4();
|
||||
}
|
||||
lookAtMatrix = new GameLib.D3.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
lookAtMatrix
|
||||
);
|
||||
this.lookAtMatrix = lookAtMatrix;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.D3.API.Vector3(0, 1, 0);
|
||||
}
|
||||
up = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
up
|
||||
);
|
||||
this.up = up;
|
||||
|
||||
this.targetPosition = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, 0, 0)
|
||||
);
|
||||
|
||||
this.currentRotation = new GameLib.D3.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Quaternion()
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentLookAt.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentLookAt.prototype.constructor = GameLib.D3.ComponentLookAt;
|
||||
|
||||
/**
|
||||
* onUpdate
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.ComponentLookAt.prototype.onUpdate = function(deltaTime) {
|
||||
|
||||
if (this.targetEntity && this.parentEntity) {
|
||||
|
||||
this.targetPosition.x = this.targetEntity.position.x + this.targetOffset.x;
|
||||
this.targetPosition.y = this.targetEntity.position.y + this.targetOffset.y;
|
||||
this.targetPosition.z = this.targetEntity.position.z + this.targetOffset.z;
|
||||
|
||||
this.targetPosition.updateInstance();
|
||||
|
||||
this.lookAtMatrix.lookAt(
|
||||
this.parentEntity.position,
|
||||
this.targetPosition,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.currentRotation.setFromRotationMatrix(this.lookAtMatrix);
|
||||
|
||||
var t = deltaTime * this.rotationSpeed;
|
||||
t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
this.currentRotation.slerp(this.currentRotation, t);
|
||||
|
||||
this.parentEntity.quaternion.x = this.currentRotation.x;
|
||||
this.parentEntity.quaternion.y = this.currentRotation.y;
|
||||
this.parentEntity.quaternion.z = this.currentRotation.z;
|
||||
this.parentEntity.quaternion.w = this.currentRotation.w;
|
||||
|
||||
this.parentEntity.quaternion.updateInstance();
|
||||
}
|
||||
};
|
|
@ -3,14 +3,14 @@
|
|||
* @param id
|
||||
* @param name
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
* @param positionOffset GameLib.D3.Vector3
|
||||
* @param quaternionOffset GameLib.D3.Quaternion
|
||||
* @param scaleOffset GameLib.D3.Vector3
|
||||
* @param positionOffset GameLib.Vector3
|
||||
* @param quaternionOffset GameLib.Quaternion
|
||||
* @param scaleOffset GameLib.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
||||
GameLib.ComponentMeshPermutation = function ComponentMeshPermutation(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
|
@ -23,21 +23,21 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.Component.call(
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_MESH_PERMUTATION,
|
||||
GameLib.Component.COMPONENT_MESH_PERMUTATION,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
new GameLib.Component.LinkedProperty(
|
||||
'mesh',
|
||||
GameLib.D3.Camera
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mesh)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
|
@ -45,11 +45,11 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
|||
/**
|
||||
* Position
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.D3.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, 0, 0)
|
||||
new GameLib.API.Vector3(0, 0, 0)
|
||||
);
|
||||
}
|
||||
this.positionOffset = positionOffset;
|
||||
|
@ -57,11 +57,11 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
|||
/**
|
||||
* Rotation
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.D3.Quaternion(
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Quaternion(0, 0, 0, 1)
|
||||
new GameLib.API.Quaternion(0, 0, 0, 1)
|
||||
);
|
||||
}
|
||||
this.quaternionOffset = quaternionOffset;
|
||||
|
@ -69,11 +69,11 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
|||
/**
|
||||
* Scale
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.D3.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(1, 1, 1)
|
||||
new GameLib.API.Vector3(1, 1, 1)
|
||||
);
|
||||
}
|
||||
this.scaleOffset = scaleOffset;
|
||||
|
@ -81,35 +81,35 @@ GameLib.D3.ComponentMeshPermutation = function ComponentMeshPermutation(
|
|||
/**
|
||||
* Runtime members
|
||||
*/
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Quaternion()
|
||||
new GameLib.API.Quaternion()
|
||||
);
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3()
|
||||
new GameLib.API.Vector3()
|
||||
);
|
||||
|
||||
this.scale = new GameLib.D3.Vector3(
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3()
|
||||
new GameLib.API.Vector3()
|
||||
);
|
||||
|
||||
this.customCode = "";
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentMeshPermutation.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentMeshPermutation.prototype.constructor = GameLib.D3.ComponentMeshPermutation;
|
||||
GameLib.ComponentMeshPermutation.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.ComponentMeshPermutation.prototype.constructor = GameLib.ComponentMeshPermutation;
|
||||
|
||||
/**
|
||||
* onLateUpdate
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.ComponentMeshPermutation.prototype.onUpdate = function(deltaTime) {
|
||||
GameLib.ComponentMeshPermutation.prototype.onUpdate = function(deltaTime) {
|
||||
|
||||
if (this.parentEntity && this.mesh) {
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
* @param id
|
||||
* @param name String
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @param mesh GameLib.D3.Camera
|
||||
* @param positionOffset
|
||||
* @param scaleOffset
|
||||
* @param quaternionOffset
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentMesh = function ComponentMesh(
|
||||
GameLib.ComponentMesh = function ComponentMesh(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
|
@ -24,21 +24,21 @@ GameLib.D3.ComponentMesh = function ComponentMesh(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.Component.call(
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_MESH,
|
||||
GameLib.Component.COMPONENT_MESH,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
new GameLib.Component.LinkedProperty(
|
||||
'mesh',
|
||||
GameLib.D3.Camera
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mesh)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
|
@ -46,11 +46,11 @@ GameLib.D3.ComponentMesh = function ComponentMesh(
|
|||
/**
|
||||
* Position
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.D3.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(positionOffset)) {
|
||||
positionOffset = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, 0, 0)
|
||||
new GameLib.API.Vector3(0, 0, 0)
|
||||
);
|
||||
}
|
||||
this.positionOffset = positionOffset;
|
||||
|
@ -58,11 +58,11 @@ GameLib.D3.ComponentMesh = function ComponentMesh(
|
|||
/**
|
||||
* Rotation
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.D3.Quaternion(
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternionOffset)) {
|
||||
quaternionOffset = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Quaternion(1, 0, 0, 0)
|
||||
new GameLib.API.Quaternion(1, 0, 0, 0)
|
||||
);
|
||||
}
|
||||
this.quaternionOffset = quaternionOffset;
|
||||
|
@ -70,19 +70,19 @@ GameLib.D3.ComponentMesh = function ComponentMesh(
|
|||
/**
|
||||
* Scale
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.D3.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(scaleOffset)) {
|
||||
scaleOffset = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, 0, 0)
|
||||
new GameLib.API.Vector3(0, 0, 0)
|
||||
);
|
||||
}
|
||||
this.scaleOffset = scaleOffset;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentMesh.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentMesh.prototype.constructor = GameLib.D3.ComponentMesh;
|
||||
GameLib.ComponentMesh.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.ComponentMesh.prototype.constructor = GameLib.ComponentMesh;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -90,14 +90,14 @@ GameLib.D3.ComponentMesh.prototype.constructor = GameLib.D3.ComponentMesh;
|
|||
* @override
|
||||
* @callback
|
||||
*/
|
||||
GameLib.D3.ComponentMesh.prototype.onUpdate = function() {
|
||||
GameLib.ComponentMesh.prototype.onUpdate = function() {
|
||||
|
||||
if (this.mesh) {
|
||||
|
||||
this.mesh.position = this.parentEntity.position.copy().add(this.positionOffset);
|
||||
this.mesh.scale = this.parentEntity.scale.copy().add(this.scaleOffset);
|
||||
this.mesh.quaternion = this.parentEntity.quaternion.copy().multiply(this.quaternionOffset).normalize();
|
||||
// this.mesh.position = this.parentEntity.position.copy().add(this.positionOffset);
|
||||
// this.mesh.scale = this.parentEntity.scale.copy().add(this.scaleOffset);
|
||||
// this.mesh.quaternion = this.parentEntity.quaternion.copy().multiply(this.quaternionOffset).normalize();
|
||||
|
||||
this.mesh.updateInstance();
|
||||
// this.mesh.updateInstance();
|
||||
}
|
||||
};
|
|
@ -2,19 +2,19 @@
|
|||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param axis {GameLib.D3.API.Vector3}
|
||||
* @param axis {GameLib.API.Vector3}
|
||||
* @param getOffsetFunc {function}
|
||||
* @param userData {Object}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
|
||||
GameLib.ComponentOffsettor = function ComponentOffsettor(
|
||||
id,
|
||||
name,
|
||||
axis,
|
||||
getOffsetFunc,
|
||||
userData
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -22,19 +22,19 @@ GameLib.D3.ComponentOffsettor = function ComponentOffsettor(
|
|||
this.name = name;
|
||||
this.parentEntity = null;
|
||||
|
||||
this.axis = axis || new GameLib.D3.API.Vector3();
|
||||
this.axis = axis || new GameLib.API.Vector3();
|
||||
this.offset = 1;
|
||||
var component = this;
|
||||
this.getOffsetFunc = getOffsetFunc || function(entity, component, userData){ return component.offset; };
|
||||
this.userData = userData;
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentOffsettor, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentOffsettor, GameLib.Component);
|
||||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentOffsettor.prototype.onLateUpdate = function(
|
||||
GameLib.ComponentOffsettor.prototype.onLateUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
* @param sensorLength
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentPathAI = function ComponentPathAI(
|
||||
GameLib.ComponentPathAI = function ComponentPathAI(
|
||||
id,
|
||||
name,
|
||||
sensorLength
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -20,7 +20,7 @@ GameLib.D3.ComponentPathAI = function ComponentPathAI(
|
|||
this.parentEntity = null;
|
||||
this.sensorLength = sensorLength || 5;
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentPathAI, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentPathAI, GameLib.Component);
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
||||
|
@ -40,7 +40,7 @@ var componentPathAI_Raycast = function(from, to, settings, world) {
|
|||
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
|
||||
GameLib.ComponentPathAI.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -172,12 +172,12 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentPathAI.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentPathAI.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
this.parentEntity = parentEntity;
|
||||
this.pathFollowingComponent = parentEntity.getComponent(GameLib.D3.ComponentPathFollowing);
|
||||
this.pathFollowingComponent = parentEntity.getComponent(GameLib.ComponentPathFollowing);
|
||||
if(!this.pathFollowingComponent) {
|
||||
console.error("ComponentPathAI. NO PATH FOLLOWING COMPONENT");
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
* @param name
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentPathControls = function ComponentPathControls(
|
||||
GameLib.ComponentPathControls = function ComponentPathControls(
|
||||
id,
|
||||
name
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -25,13 +25,13 @@ GameLib.D3.ComponentPathControls = function ComponentPathControls(
|
|||
this.keyBackPressed = false;
|
||||
this.keyBreakPressed = false;
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentPathControls, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentPathControls, GameLib.Component);
|
||||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentPathControls.prototype.onUpdate = function(
|
||||
GameLib.ComponentPathControls.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -67,12 +67,12 @@ GameLib.D3.ComponentPathControls.prototype.onUpdate = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentPathControls.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentPathControls.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
this.pathFollowingComponent = parentEntity.getComponent(GameLib.D3.ComponentPathFollowing);
|
||||
this.pathFollowingComponent = parentEntity.getComponent(GameLib.ComponentPathFollowing);
|
||||
if(!this.pathFollowingComponent) {
|
||||
console.error("ComponentPathControls. NO PATH FOLLOWING COMPONENT");
|
||||
}
|
||||
|
|
|
@ -1,315 +0,0 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param spline GameLib.D3.Spline
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
* @param accelleration Number
|
||||
* @param maxSpeed Number
|
||||
* @param baseOffset GameLib.D3.Vector
|
||||
* @param maxOffset GameLib.D3.Vector
|
||||
* @param steeringSpeed Number
|
||||
* @param targetOffset GameLib.D3.Vector3
|
||||
* @param currentOffset GameLib.D3.Vector3
|
||||
* @param currentPathValue Number
|
||||
* @param currentSpeed Number
|
||||
* @param direction Number
|
||||
* @param mx GameLib.D3.Utils.MovingAverage
|
||||
* @param my GameLib.D3.Utils.MovingAverage
|
||||
* @param mz GameLib.D3.Utils.MovingAverage
|
||||
* @param raycaster GameLib.D3.Raycaster
|
||||
* @param currentPosition GameLib.D3.Vector3
|
||||
* @param futurePosition GameLib.D3.Vector3
|
||||
* @param up GameLib.D3.Vector3
|
||||
* @param rotationMatrix GameLib.D3.Matrix4
|
||||
* @param rotationVector GameLib.D3.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentPathFollowing = function ComponentPathFollowing(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
parentEntity,
|
||||
spline,
|
||||
mesh,
|
||||
accelleration,
|
||||
maxSpeed,
|
||||
baseOffset,
|
||||
maxOffset,
|
||||
steeringSpeed,
|
||||
targetOffset,
|
||||
currentOffset,
|
||||
currentPathValue,
|
||||
currentSpeed,
|
||||
direction,
|
||||
mx,
|
||||
my,
|
||||
mz,
|
||||
raycaster,
|
||||
currentPosition,
|
||||
futurePosition,
|
||||
up,
|
||||
rotationMatrix,
|
||||
rotationVector
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.Component.call(
|
||||
this,
|
||||
id,
|
||||
name,
|
||||
GameLib.D3.Component.COMPONENT_PATH_FOLLOWING,
|
||||
parentEntity,
|
||||
[
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
'spline',
|
||||
GameLib.D3.Spline
|
||||
),
|
||||
new GameLib.D3.Component.LinkedProperty(
|
||||
'mesh',
|
||||
GameLib.D3.Mesh
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(spline)) {
|
||||
spline = null;
|
||||
}
|
||||
this.spline = spline;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxSpeed)) {
|
||||
maxSpeed = 0.03;
|
||||
}
|
||||
this.maxSpeed = maxSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(accelleration)) {
|
||||
accelleration = 0.1;
|
||||
}
|
||||
this.accelleration = accelleration;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(baseOffset)) {
|
||||
baseOffset = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
baseOffset = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
baseOffset
|
||||
);
|
||||
this.baseOffset = baseOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxOffset)) {
|
||||
maxOffset = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
maxOffset = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
maxOffset
|
||||
);
|
||||
this.maxOffset = maxOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(steeringSpeed)) {
|
||||
steeringSpeed = 1.0;
|
||||
}
|
||||
this.steeringSpeed = steeringSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
targetOffset = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
targetOffset
|
||||
);
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentOffset)) {
|
||||
currentOffset = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
currentOffset = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
currentOffset
|
||||
);
|
||||
this.currentOffset = currentOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentPathValue)) {
|
||||
currentPathValue = 0;
|
||||
}
|
||||
this.currentPathValue = currentPathValue;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentSpeed)) {
|
||||
currentSpeed = 0;
|
||||
}
|
||||
this.currentSpeed = currentSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(direction)) {
|
||||
direction = 1;
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mx)) {
|
||||
mx = new GameLib.D3.Utils.MovingAverage(10);
|
||||
}
|
||||
this.mx = mx;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(my)) {
|
||||
my = new GameLib.D3.Utils.MovingAverage(10);
|
||||
}
|
||||
this.my = my;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mz)) {
|
||||
mz = new GameLib.D3.Utils.MovingAverage(10);
|
||||
}
|
||||
this.mz = mz;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(raycaster)) {
|
||||
raycaster = new GameLib.D3.Raycaster(
|
||||
graphics,
|
||||
new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3()
|
||||
),
|
||||
new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, -1, 0)
|
||||
)
|
||||
);
|
||||
}
|
||||
this.raycaster = raycaster;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
currentPosition = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
currentPosition
|
||||
);
|
||||
this.currentPosition = currentPosition;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(futurePosition)) {
|
||||
futurePosition = new GameLib.D3.API.Vector3();
|
||||
}
|
||||
futurePosition = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
futurePosition
|
||||
);
|
||||
this.futurePosition = futurePosition;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.D3.API.Vector3(0, 1, 0);
|
||||
}
|
||||
up = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
up
|
||||
);
|
||||
this.up = up;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotationMatrix)) {
|
||||
rotationMatrix = new GameLib.D3.Matrix4(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Matrix4()
|
||||
);
|
||||
}
|
||||
this.rotationMatrix = rotationMatrix;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotationVector)) {
|
||||
rotationVector = new GameLib.D3.API.Quaternion();
|
||||
}
|
||||
rotationVector = new GameLib.D3.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
rotationVector
|
||||
);
|
||||
this.rotationVector = rotationVector;
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentPathFollowing.prototype = Object.create(GameLib.D3.Component.prototype);
|
||||
GameLib.D3.ComponentPathFollowing.prototype.constructor = GameLib.D3.ComponentPathFollowing;
|
||||
|
||||
|
||||
/**
|
||||
* @param deltaTime
|
||||
* @callback
|
||||
* @override
|
||||
*/
|
||||
GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
||||
deltaTime
|
||||
) {
|
||||
|
||||
if (this.spline && this.mesh) {
|
||||
|
||||
this.currentSpeed += this.accelleration * deltaTime * this.direction;
|
||||
if(this.currentSpeed > this.maxSpeed) {
|
||||
this.currentSpeed = this.maxSpeed;
|
||||
}
|
||||
this.grain = (this.currentSpeed / 100.0);
|
||||
|
||||
this.currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.currentPathValue += this.grain;
|
||||
|
||||
if (this.currentPathValue >= 1) {
|
||||
this.currentPathValue = this.currentPathValue - 1;
|
||||
}
|
||||
|
||||
if (this.currentPathValue < 0) {
|
||||
this.currentPathValue = 0.0;
|
||||
}
|
||||
|
||||
this.futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.raycaster.setPosition(
|
||||
this.futurePosition
|
||||
);
|
||||
|
||||
var normal = this.raycaster.getFaceNormal(this.mesh);
|
||||
|
||||
if (normal) {
|
||||
this.up.x = this.mx(normal.x);
|
||||
this.up.y = this.my(normal.y);
|
||||
this.up.z = this.mz(normal.z);
|
||||
|
||||
this.up.updateInstance();
|
||||
}
|
||||
|
||||
this.rotationMatrix.lookAt(
|
||||
this.currentPosition,
|
||||
this.futurePosition,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.rotationVector.setFromRotationMatrix(this.rotationMatrix);
|
||||
|
||||
/**
|
||||
* Update Position
|
||||
*/
|
||||
this.parentEntity.position.x = this.futurePosition.x;// + transformedOffset.x;
|
||||
this.parentEntity.position.y = this.futurePosition.y;// + transformedOffset.y;
|
||||
this.parentEntity.position.z = this.futurePosition.z;// + transformedOffset.z;
|
||||
|
||||
/**
|
||||
* Update Rotation
|
||||
*/
|
||||
this.parentEntity.quaternion.x = this.rotationVector.x;
|
||||
this.parentEntity.quaternion.y = this.rotationVector.y;
|
||||
this.parentEntity.quaternion.z = this.rotationVector.z;
|
||||
this.parentEntity.quaternion.w = this.rotationVector.w;
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
GameLib.D3.ComponentRaycastVehicleControls = function ComponentRaycastVehicleControls(
|
||||
GameLib.ComponentRaycastVehicleControls = function ComponentRaycastVehicleControls(
|
||||
id,
|
||||
name,
|
||||
frontLWheelIndex,
|
||||
|
@ -8,7 +8,7 @@ GameLib.D3.ComponentRaycastVehicleControls = function ComponentRaycastVehicleCon
|
|||
maxForce,
|
||||
steering
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -38,11 +38,11 @@ GameLib.D3.ComponentRaycastVehicleControls = function ComponentRaycastVehicleCon
|
|||
this.keyBreakPressed = false;
|
||||
|
||||
// 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.ComponentRaycastVehicleControls, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentRaycastVehicleControls, GameLib.Component);
|
||||
};
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentRaycastVehicleControls.prototype.onUpdate = function(
|
||||
GameLib.ComponentRaycastVehicleControls.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -112,7 +112,7 @@ GameLib.D3.ComponentRaycastVehicleControls.prototype.onUpdate = function(
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentRaycastVehicleControls.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentRaycastVehicleControls.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param axis {GameLib.D3.API.Vector3}
|
||||
* @param axis {GameLib.API.Vector3}
|
||||
* @param getRotationFunc {Function}
|
||||
* @param userData {Object}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentRotator = function ComponentRotator(
|
||||
GameLib.ComponentRotator = function ComponentRotator(
|
||||
id,
|
||||
name,
|
||||
axis,
|
||||
getRotationFunc,
|
||||
userData
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -24,17 +24,17 @@ GameLib.D3.ComponentRotator = function ComponentRotator(
|
|||
|
||||
this.rotation = 0;
|
||||
var component = this;
|
||||
this.axis = axis || new GameLib.D3.API.Vector3();
|
||||
this.axis = axis || new GameLib.API.Vector3();
|
||||
this.getRotationFunc = getRotationFunc || function(entity, component, userData){ return component.rotation; };
|
||||
this.userData = userData;
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentRotator, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentRotator, GameLib.Component);
|
||||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentRotator.prototype.onLateUpdate = function(
|
||||
GameLib.ComponentRotator.prototype.onLateUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// this component operates on it's parent entity's bounding box.
|
||||
// so, you can't use this component with a null-mesh.
|
||||
//
|
||||
GameLib.D3.ComponentTriggerBoxBox = function ComponentTriggerBoxBox(
|
||||
GameLib.ComponentTriggerBoxBox = function ComponentTriggerBoxBox(
|
||||
id,
|
||||
name,
|
||||
entitiesToCheck,
|
||||
|
@ -13,7 +13,7 @@ GameLib.D3.ComponentTriggerBoxBox = function ComponentTriggerBoxBox(
|
|||
) {
|
||||
console.log('triggerbox box!');
|
||||
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -23,7 +23,7 @@ GameLib.D3.ComponentTriggerBoxBox = function ComponentTriggerBoxBox(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentTriggerBoxBox, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentTriggerBoxBox, GameLib.Component);
|
||||
|
||||
this.entitiesToCheck = entitiesToCheck || [];
|
||||
this.onInside = onInside || null;
|
||||
|
@ -44,7 +44,7 @@ if(typeof THREE != "undefined") {
|
|||
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentTriggerBoxBox.prototype.onUpdate = function(
|
||||
GameLib.ComponentTriggerBoxBox.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -94,7 +94,7 @@ GameLib.D3.ComponentTriggerBoxBox.prototype.onUpdate = function(
|
|||
//#endif
|
||||
|
||||
|
||||
GameLib.D3.ComponentTriggerBoxBox.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentTriggerBoxBox.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// this component operates on it's parent entity's bounding box.
|
||||
// so, you can't use this component with a null-mesh.
|
||||
//
|
||||
GameLib.D3.ComponentTriggerBoxSphere = function ComponentTriggerBoxSphere(
|
||||
GameLib.ComponentTriggerBoxSphere = function ComponentTriggerBoxSphere(
|
||||
id,
|
||||
name,
|
||||
entitiesToCheck,
|
||||
|
@ -11,7 +11,7 @@ GameLib.D3.ComponentTriggerBoxSphere = function ComponentTriggerBoxSphere(
|
|||
onLeave,
|
||||
onSetParent
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -21,7 +21,7 @@ GameLib.D3.ComponentTriggerBoxSphere = function ComponentTriggerBoxSphere(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentTriggerBoxSphere, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentTriggerBoxSphere, GameLib.Component);
|
||||
|
||||
this.entitiesToCheck = entitiesToCheck || [];
|
||||
this.onInside = onInside || null;
|
||||
|
@ -40,7 +40,7 @@ if(typeof THREE != "undefined") {
|
|||
}
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentTriggerBoxSphere.prototype.onUpdate = function(
|
||||
GameLib.ComponentTriggerBoxSphere.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -118,7 +118,7 @@ GameLib.D3.ComponentTriggerBoxSphere.prototype.onUpdate = function(
|
|||
|
||||
//#endif
|
||||
|
||||
GameLib.D3.ComponentTriggerBoxSphere.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentTriggerBoxSphere.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* @param onSetParent
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentTriggerSphereSphere = function ComponentTriggerSphereSphere(
|
||||
GameLib.ComponentTriggerSphereSphere = function ComponentTriggerSphereSphere(
|
||||
id,
|
||||
name,
|
||||
sphereRadius,
|
||||
|
@ -21,7 +21,7 @@ GameLib.D3.ComponentTriggerSphereSphere = function ComponentTriggerSphereSphere(
|
|||
onLeave,
|
||||
onSetParent
|
||||
) {
|
||||
this.id = id || GameLib.D3.Utils.RandomId();
|
||||
this.id = id || GameLib.Utils.RandomId();
|
||||
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
|
@ -32,7 +32,7 @@ GameLib.D3.ComponentTriggerSphereSphere = function ComponentTriggerSphereSphere(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentTriggerSphereSphere, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentTriggerSphereSphere, GameLib.Component);
|
||||
|
||||
this.entitiesToCheck = entitiesToCheck || [];
|
||||
this.sphereRadius = sphereRadius || 1.0;
|
||||
|
@ -54,7 +54,7 @@ if(typeof THREE != "undefined") {
|
|||
}
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
GameLib.D3.ComponentTriggerSphereSphere.prototype.onUpdate = function(
|
||||
GameLib.ComponentTriggerSphereSphere.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -129,7 +129,7 @@ GameLib.D3.ComponentTriggerSphereSphere.prototype.onUpdate = function(
|
|||
|
||||
//#endif
|
||||
|
||||
GameLib.D3.ComponentTriggerSphereSphere.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentTriggerSphereSphere.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
|
|
@ -5,19 +5,19 @@
|
|||
* @param world GameLib.D3.World
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentVehicleAIObjectAvoidance = function(
|
||||
GameLib.ComponentVehicleAIObjectAvoidance = function(
|
||||
id,
|
||||
name,
|
||||
world
|
||||
) {
|
||||
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||
this.id = id|| GameLib.Utils.RandomId();
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
this.parentEntity = null;
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.ComponentVehicleAIObjectAvoidance, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentVehicleAIObjectAvoidance, GameLib.Component);
|
||||
|
||||
this.raycastVehicleComponent = null;
|
||||
this.physicsWorld = world || null;
|
||||
|
@ -35,7 +35,7 @@ GameLib.D3.ComponentVehicleAIObjectAvoidance = function(
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////// Methods to override ///////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
GameLib.D3.ComponentVehicleAIObjectAvoidance.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentVehicleAIObjectAvoidance.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -262,7 +262,7 @@ GameLib.D3.ComponentVehicleAIObjectAvoidance.prototype.onSetParentEntity = funct
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.ComponentVehicleAIObjectAvoidance.prototype.onUpdate = function(
|
||||
GameLib.ComponentVehicleAIObjectAvoidance.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -548,10 +548,10 @@ GameLib.D3.ComponentVehicleAIObjectAvoidance.prototype.onUpdate = function(
|
|||
var cos = avgMoveVector.dot(forward);
|
||||
|
||||
var angleRadians = Math.acos(cos);
|
||||
var steerAngleModifier = GameLib.D3.API.Vector3.AngleDirection(
|
||||
var steerAngleModifier = GameLib.API.Vector3.AngleDirection(
|
||||
forward,
|
||||
avgMoveVector,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
0,
|
||||
1,
|
||||
0
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
*
|
||||
* @param id
|
||||
* @param name
|
||||
* @param targetEntity GameLib.D3.Entity
|
||||
* @param targetEntity GameLib.Entity
|
||||
* @param steeringSpeed
|
||||
* @param maxSteerAngle
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.ComponentVehicleAIPathSteering = function(
|
||||
GameLib.ComponentVehicleAIPathSteering = function(
|
||||
id,
|
||||
name,
|
||||
targetEntity,
|
||||
steeringSpeed,
|
||||
maxSteerAngle
|
||||
) {
|
||||
this.id = id|| GameLib.D3.Utils.RandomId();
|
||||
this.id = id|| GameLib.Utils.RandomId();
|
||||
if (typeof name == 'undefined') {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ GameLib.D3.ComponentVehicleAIPathSteering = function(
|
|||
this.parentEntity = null;
|
||||
|
||||
// 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.ComponentVehicleAIPathSteering, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.ComponentVehicleAIPathSteering, GameLib.Component);
|
||||
|
||||
//
|
||||
this.targetEntity = targetEntity;
|
||||
|
@ -37,7 +37,7 @@ GameLib.D3.ComponentVehicleAIPathSteering = function(
|
|||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
|
||||
GameLib.D3.ComponentVehicleAIPathSteering.prototype.onSetParentEntity = function(
|
||||
GameLib.ComponentVehicleAIPathSteering.prototype.onSetParentEntity = function(
|
||||
parentScene,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -50,7 +50,7 @@ GameLib.D3.ComponentVehicleAIPathSteering.prototype.onSetParentEntity = function
|
|||
};
|
||||
|
||||
//#ifdef RUNTIME__
|
||||
GameLib.D3.ComponentVehicleAIPathSteering.prototype.onUpdate = function(
|
||||
GameLib.ComponentVehicleAIPathSteering.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
|
@ -111,10 +111,10 @@ GameLib.D3.ComponentVehicleAIPathSteering.prototype.onUpdate = function(
|
|||
|
||||
var cos = v1v2cpy.dot(forwardcpy);
|
||||
var angleRadians = Math.acos(cos);
|
||||
var steerAngleModifier = GameLib.D3.API.Vector3.AngleDirection(
|
||||
var steerAngleModifier = GameLib.API.Vector3.AngleDirection(
|
||||
forwardcpy,
|
||||
v1v2cpy,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
0,
|
||||
1,
|
||||
0
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @param quaternion
|
||||
* @param position
|
||||
* @param rotation
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param up
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -39,27 +39,27 @@ GameLib.D3.API.Bone = function Bone(
|
|||
this.parentBoneId = parentBoneId;
|
||||
|
||||
if (typeof quaternion == 'undefined') {
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (typeof position == 'undefined') {
|
||||
position = new GameLib.D3.API.Vector3(0,0,0);
|
||||
position = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (typeof rotation == 'undefined') {
|
||||
rotation = new GameLib.D3.API.Vector3(0,0,0);
|
||||
rotation = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (typeof scale == 'undefined') {
|
||||
scale = new GameLib.D3.API.Vector3(1,1,1);
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (typeof up == 'undefined') {
|
||||
up = new GameLib.D3.API.Vector3(0,1,0);
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
};
|
|
@ -7,15 +7,15 @@
|
|||
* @param aspect
|
||||
* @param near
|
||||
* @param far
|
||||
* @param position GameLib.D3.API.Vector3
|
||||
* @param lookAt GameLib.D3.API.Vector3
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param lookAt GameLib.API.Vector3
|
||||
* @param minX
|
||||
* @param maxX
|
||||
* @param minY
|
||||
* @param maxY
|
||||
* @param minZ
|
||||
* @param maxZ
|
||||
* @param quaternion GameLib.D3.Quaternion
|
||||
* @param quaternion GameLib.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Camera = function(
|
||||
|
@ -36,43 +36,43 @@ GameLib.D3.API.Camera = function(
|
|||
maxZ,
|
||||
quaternion
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(cameraType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
||||
cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE;
|
||||
}
|
||||
this.cameraType = cameraType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Camera (' + cameraType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(fov)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(fov)) {
|
||||
fov = 75;
|
||||
}
|
||||
this.fov = fov;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(aspect)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(aspect)) {
|
||||
aspect = window.innerWidth / window.innerHeight;
|
||||
}
|
||||
this.aspect = aspect;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(near)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
near = 0.001;
|
||||
}
|
||||
this.near = near;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(far)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(far)) {
|
||||
far = 1000;
|
||||
}
|
||||
this.far = far;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.API.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3(
|
||||
15,
|
||||
15,
|
||||
15
|
||||
|
@ -80,13 +80,13 @@ GameLib.D3.API.Camera = function(
|
|||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lookAt)) {
|
||||
lookAt = new GameLib.D3.API.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
|
||||
lookAt = new GameLib.API.Vector3(
|
||||
0,
|
||||
0,
|
||||
0
|
||||
|
@ -94,32 +94,32 @@ GameLib.D3.API.Camera = function(
|
|||
}
|
||||
this.lookAt = lookAt;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minX)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(minX)) {
|
||||
minX = -100;
|
||||
}
|
||||
this.minX = minX;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxX)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(maxX)) {
|
||||
maxX = 100;
|
||||
}
|
||||
this.maxX = maxX;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minY)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(minY)) {
|
||||
minY = -100;
|
||||
}
|
||||
this.minY = minY;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxY)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(maxY)) {
|
||||
maxY = 100;
|
||||
}
|
||||
this.maxY = maxY;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minZ)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(minZ)) {
|
||||
minZ = -100;
|
||||
}
|
||||
this.minZ = minZ;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxZ)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(maxZ)) {
|
||||
maxZ = 100;
|
||||
}
|
||||
this.maxZ = maxZ;
|
|
@ -1,21 +1,21 @@
|
|||
GameLib.D3.API.Color = function ApiColor(r, g, b, a) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(r)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(r)) {
|
||||
r = 1;
|
||||
}
|
||||
this.r = r;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(g)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(g)) {
|
||||
g = 1;
|
||||
}
|
||||
this.g = g;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(b)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(b)) {
|
||||
b = 1;
|
||||
}
|
||||
this.b = b;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(a)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(a)) {
|
||||
a = 0;
|
||||
}
|
||||
this.a = a;
|
|
@ -4,8 +4,8 @@
|
|||
* @param name
|
||||
* @param componentType
|
||||
* @param camera GameLib.D3.Camera
|
||||
* @param parentEntity GameLib.D3.Entity
|
||||
* @param targetEntity GameLib.D3.Entity
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @param targetEntity GameLib.Entity
|
||||
* @param targetOffset
|
||||
* @param minDistance
|
||||
* @param moveSpeed
|
||||
|
@ -30,7 +30,7 @@
|
|||
* @param currentPosition
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Component = function(
|
||||
GameLib.API.Component = function(
|
||||
// General
|
||||
id,
|
||||
name,
|
||||
|
@ -73,30 +73,30 @@ GameLib.D3.API.Component = function(
|
|||
/**
|
||||
* General
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'component-unnamed';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(componentType)) {
|
||||
componentType = GameLib.D3.Component.COMPONENT_INTERFACE;
|
||||
if (GameLib.Utils.UndefinedOrNull(componentType)) {
|
||||
componentType = GameLib.Component.COMPONENT_INTERFACE;
|
||||
}
|
||||
this.componentType = componentType;
|
||||
|
||||
/**
|
||||
* Camera Component
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(camera)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
@ -104,124 +104,124 @@ GameLib.D3.API.Component = function(
|
|||
/**
|
||||
* Follow Component
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(targetEntity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(targetEntity)) {
|
||||
targetEntity = null;
|
||||
}
|
||||
this.targetEntity = targetEntity;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(moveSpeed)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(moveSpeed)) {
|
||||
moveSpeed = 12.5;
|
||||
}
|
||||
this.moveSpeed = moveSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minDistance)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
||||
minDistance = 0;
|
||||
}
|
||||
this.minDistance = minDistance;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(target)) {
|
||||
target = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(target)) {
|
||||
target = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.target = target;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(targetToParent)) {
|
||||
targetToParent = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(targetToParent)) {
|
||||
targetToParent = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetToParent = targetToParent;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(rotatedTargetOffset)) {
|
||||
rotatedTargetOffset = new GameLib.D3.API.Vector3(0, 0, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(rotatedTargetOffset)) {
|
||||
rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.rotatedTargetOffset = rotatedTargetOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotated)) {
|
||||
rotated = new GameLib.D3.API.Quaternion();
|
||||
if (GameLib.Utils.UndefinedOrNull(rotated)) {
|
||||
rotated = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.rotated = rotated;
|
||||
|
||||
/**
|
||||
* LookAt Component
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
rotationSpeed = 22.0;
|
||||
}
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lookAtMatrix)) {
|
||||
lookAtMatrix = new GameLib.D3.API.Matrix4();
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAtMatrix)) {
|
||||
lookAtMatrix = new GameLib.API.Matrix4();
|
||||
}
|
||||
this.lookAtMatrix = lookAtMatrix;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.D3.API.Vector3(0, 1, 0);
|
||||
if(GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0, 1, 0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
/**
|
||||
* Path Following Component
|
||||
*/
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(spline)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(spline)) {
|
||||
spline = null;
|
||||
}
|
||||
this.spline = spline;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mesh)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(accelleration)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(accelleration)) {
|
||||
accelleration = 0.1;
|
||||
}
|
||||
this.accelleration = accelleration;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxSpeed)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(maxSpeed)) {
|
||||
maxSpeed = 0.03;
|
||||
}
|
||||
this.maxSpeed = maxSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(baseOffset)) {
|
||||
baseOffset = new GameLib.D3.API.Vector3();
|
||||
if (GameLib.Utils.UndefinedOrNull(baseOffset)) {
|
||||
baseOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.baseOffset = baseOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maxOffset)) {
|
||||
maxOffset = new GameLib.D3.API.Vector3(10, 10, 10);
|
||||
if (GameLib.Utils.UndefinedOrNull(maxOffset)) {
|
||||
maxOffset = new GameLib.API.Vector3(10, 10, 10);
|
||||
}
|
||||
this.maxOffset = maxOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(steeringSpeed)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(steeringSpeed)) {
|
||||
steeringSpeed = 1.0;
|
||||
}
|
||||
this.steeringSpeed = steeringSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentOffset)) {
|
||||
currentOffset = new GameLib.D3.API.Vector3();
|
||||
if (GameLib.Utils.UndefinedOrNull(currentOffset)) {
|
||||
currentOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.currentOffset = currentOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentPathValue)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(currentPathValue)) {
|
||||
currentPathValue = 0;
|
||||
}
|
||||
this.currentPathValue = currentPathValue;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentSpeed)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(currentSpeed)) {
|
||||
currentSpeed = 0;
|
||||
}
|
||||
this.currentSpeed = currentSpeed;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(direction)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
||||
direction = 1;
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new GameLib.D3.API.Vector3();
|
||||
if (GameLib.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new GameLib.API.Vector3();
|
||||
}
|
||||
this.currentPosition = currentPosition;
|
||||
};
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Follow Component
|
||||
* @param id
|
||||
* @param name
|
||||
* @param targetPosition GameLib.API.Vector3
|
||||
* @param targetOffset GameLib.API.Vector3
|
||||
* @param minDistance
|
||||
* @param moveSpeed
|
||||
* @param target GameLib.API.Vector3
|
||||
* @param targetToParent GameLib.API.Vector3
|
||||
* @param rotatedTargetOffset GameLib.API.Vector3
|
||||
* @param rotated GameLib.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Follow = function (
|
||||
id,
|
||||
name,
|
||||
targetPosition,
|
||||
targetOffset,
|
||||
minDistance,
|
||||
moveSpeed,
|
||||
target,
|
||||
targetToParent,
|
||||
rotatedTargetOffset,
|
||||
rotated
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(targetPosition)) {
|
||||
targetPosition = null;
|
||||
}
|
||||
this.targetPosition = targetPosition;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
||||
minDistance = 0;
|
||||
}
|
||||
this.minDistance = minDistance;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(moveSpeed)) {
|
||||
moveSpeed = 12.5;
|
||||
}
|
||||
this.moveSpeed = moveSpeed;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(target)) {
|
||||
target = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.target = target;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(targetToParent)) {
|
||||
targetToParent = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetToParent = targetToParent;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(rotatedTargetOffset)) {
|
||||
rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.rotatedTargetOffset = rotatedTargetOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotated)) {
|
||||
rotated = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.rotated = rotated;
|
||||
};
|
|
@ -34,53 +34,53 @@ GameLib.D3.API.Light = function(
|
|||
angle,
|
||||
penumbra
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lightType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lightType)) {
|
||||
lightType = GameLib.D3.Light.LIGHT_TYPE_AMBIENT;
|
||||
}
|
||||
this.lightType = lightType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Light (' + lightType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.D3.API.Color(1,1,1,1);
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(intensity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(intensity)) {
|
||||
intensity = 1;
|
||||
}
|
||||
this.intensity = intensity;
|
||||
|
||||
if (typeof position == 'undefined') {
|
||||
position = new GameLib.D3.API.Vector3(0,10,0);
|
||||
position = new GameLib.API.Vector3(0,10,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (typeof targetPosition == 'undefined') {
|
||||
targetPosition = new GameLib.D3.API.Vector3(0,0,0);
|
||||
targetPosition = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.targetPosition = targetPosition;
|
||||
|
||||
if (typeof quaternion == 'undefined'){
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (typeof rotation == 'undefined'){
|
||||
rotation = new GameLib.D3.API.Vector3(0,0,0);
|
||||
rotation = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (typeof scale == 'undefined'){
|
||||
scale = new GameLib.D3.API.Vector3(1,1,1);
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
||||
* @param id
|
||||
* @param name
|
||||
* @param currentPosition GameLib.API.Vector3
|
||||
* @param targetPosition GameLib.API.Vector3
|
||||
* @param targetPositionOffset GameLib.API.Vector3
|
||||
* @param rotationSpeed Number
|
||||
* @param lookAtMatrix GameLib.API.Matrix4
|
||||
* @param up GameLib.API.Vector3
|
||||
* @param currentRotation GameLib.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.LookAt = function (
|
||||
id,
|
||||
name,
|
||||
currentPosition,
|
||||
targetPosition,
|
||||
targetPositionOffset,
|
||||
rotationSpeed,
|
||||
lookAtMatrix,
|
||||
up,
|
||||
currentRotation
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new GameLib.API.Vector3(0, 10, 10);
|
||||
}
|
||||
this.currentPosition = currentPosition;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(targetPosition)) {
|
||||
targetPosition = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetPosition = targetPosition;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(targetPositionOffset)) {
|
||||
targetPositionOffset = new GameLib.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetPositionOffset = targetPositionOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
rotationSpeed = 22.0;
|
||||
}
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAtMatrix)) {
|
||||
lookAtMatrix = new GameLib.API.Matrix4();
|
||||
}
|
||||
this.lookAtMatrix = lookAtMatrix;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0, 1, 0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(currentRotation)) {
|
||||
currentRotation = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.currentRotation = currentRotation;
|
||||
};
|
|
@ -118,287 +118,287 @@ GameLib.D3.API.Material = function(
|
|||
spriteRotation,
|
||||
envMapIntensity
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(materialType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(materialType)) {
|
||||
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
|
||||
}
|
||||
this.materialType = materialType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Material (' + materialType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(opacity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(opacity)) {
|
||||
opacity = 1.0;
|
||||
}
|
||||
this.opacity = opacity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(side)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(side)) {
|
||||
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
|
||||
}
|
||||
this.side = side;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(transparent)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(transparent)) {
|
||||
transparent = false;
|
||||
}
|
||||
this.transparent = transparent;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maps)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(maps)) {
|
||||
maps = GameLib.D3.API.TextureMapTemplate();
|
||||
}
|
||||
this.maps = maps;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(specular)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(specular)) {
|
||||
specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06);
|
||||
}
|
||||
this.specular = specular;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lightMapIntensity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lightMapIntensity)) {
|
||||
lightMapIntensity = 1;
|
||||
}
|
||||
this.lightMapIntensity = lightMapIntensity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(aoMapIntensity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(aoMapIntensity)) {
|
||||
aoMapIntensity = 1;
|
||||
}
|
||||
this.aoMapIntensity = aoMapIntensity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.D3.API.Color(1, 1, 1, 1)
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(emissive)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(emissive)) {
|
||||
emissive = new GameLib.D3.API.Color(0, 0, 0, 0);
|
||||
}
|
||||
this.emissive = emissive;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(emissiveIntensity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(emissiveIntensity)) {
|
||||
emissiveIntensity = 1;
|
||||
}
|
||||
this.emissiveIntensity = emissiveIntensity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(combine)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(combine)) {
|
||||
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
|
||||
}
|
||||
this.combine = combine;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(shininess)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(shininess)) {
|
||||
shininess = 30;
|
||||
}
|
||||
this.shininess = shininess;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(reflectivity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(reflectivity)) {
|
||||
reflectivity = 1;
|
||||
}
|
||||
this.reflectivity = reflectivity;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(refractionRatio)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(refractionRatio)) {
|
||||
refractionRatio = 0.98;
|
||||
}
|
||||
this.refractionRatio = refractionRatio;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(fog)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(fog)) {
|
||||
fog = true;
|
||||
}
|
||||
this.fog = fog;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframe)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wireframe)) {
|
||||
wireframe = false;
|
||||
}
|
||||
this.wireframe = wireframe;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineWidth)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wireframeLineWidth)) {
|
||||
wireframeLineWidth = 1;
|
||||
}
|
||||
this.wireframeLineWidth = wireframeLineWidth;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineCap)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wireframeLineCap)) {
|
||||
wireframeLineCap = 'round';
|
||||
}
|
||||
this.wireframeLineCap = wireframeLineCap;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineJoin)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wireframeLineJoin)) {
|
||||
wireframeLineJoin = 'round';
|
||||
}
|
||||
this.wireframeLineJoin = wireframeLineJoin;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(vertexColors)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(vertexColors)) {
|
||||
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||||
}
|
||||
this.vertexColors = vertexColors;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinning)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(skinning)) {
|
||||
skinning = false;
|
||||
}
|
||||
this.skinning = skinning;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(morphTargets)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(morphTargets)) {
|
||||
morphTargets = false;
|
||||
}
|
||||
this.morphTargets = morphTargets;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(morphNormals)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(morphNormals)) {
|
||||
morphNormals = false;
|
||||
}
|
||||
this.morphNormals = morphNormals;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(overdraw)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(overdraw)) {
|
||||
overdraw = 0;
|
||||
}
|
||||
this.overdraw = overdraw;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineWidth)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lineWidth)) {
|
||||
lineWidth = 1;
|
||||
}
|
||||
this.lineWidth = lineWidth;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineCap)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lineCap)) {
|
||||
lineCap = 'round';
|
||||
}
|
||||
this.lineCap = lineCap;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineJoin)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lineJoin)) {
|
||||
lineJoin = 'round';
|
||||
}
|
||||
this.lineJoin = lineJoin;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(dashSize)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(dashSize)) {
|
||||
dashSize = 3;
|
||||
}
|
||||
this.dashSize = dashSize;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(gapWidth)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(gapWidth)) {
|
||||
gapWidth = 1;
|
||||
}
|
||||
this.gapWidth = gapWidth;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blending)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(blending)) {
|
||||
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
|
||||
}
|
||||
this.blending = blending;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendSrc)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(blendSrc)) {
|
||||
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
|
||||
}
|
||||
this.blendSrc = blendSrc;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendDst)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(blendDst)) {
|
||||
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
||||
}
|
||||
this.blendDst = blendDst;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendEquation)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(blendEquation)) {
|
||||
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
|
||||
}
|
||||
this.blendEquation = blendEquation;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthTest)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(depthTest)) {
|
||||
depthTest = true;
|
||||
}
|
||||
this.depthTest = depthTest;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthFunc)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(depthFunc)) {
|
||||
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
|
||||
}
|
||||
this.depthFunc = depthFunc;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthWrite)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(depthWrite)) {
|
||||
depthWrite = true;
|
||||
}
|
||||
this.depthWrite = depthWrite;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffset)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(polygonOffset)) {
|
||||
polygonOffset = false;
|
||||
}
|
||||
this.polygonOffset = polygonOffset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetFactor)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(polygonOffsetFactor)) {
|
||||
polygonOffsetFactor = 1;
|
||||
}
|
||||
this.polygonOffsetFactor = polygonOffsetFactor;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetUnits)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(polygonOffsetUnits)) {
|
||||
polygonOffsetUnits = 1;
|
||||
}
|
||||
this.polygonOffsetUnits = polygonOffsetUnits;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(alphaTest)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(alphaTest)) {
|
||||
alphaTest = 0;
|
||||
}
|
||||
this.alphaTest = alphaTest;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||
clippingPlanes = [];
|
||||
}
|
||||
this.clippingPlanes = clippingPlanes;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(clipShadows)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(clipShadows)) {
|
||||
clipShadows = false;
|
||||
}
|
||||
this.clipShadows = clipShadows;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(visible)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
||||
visible = true;
|
||||
}
|
||||
this.visible = visible;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(shading)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(shading)) {
|
||||
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
||||
}
|
||||
this.shading = shading;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(bumpScale)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
|
||||
bumpScale = 1;
|
||||
}
|
||||
this.bumpScale = bumpScale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(normalScale)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(normalScale)) {
|
||||
normalScale = 1;
|
||||
}
|
||||
this.normalScale = normalScale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(displacementScale)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(displacementScale)) {
|
||||
displacementScale = 1;
|
||||
}
|
||||
this.displacementScale = displacementScale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(displacementBias)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(displacementBias)) {
|
||||
displacementBias = 0;
|
||||
}
|
||||
this.displacementBias = displacementBias;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(roughness)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(roughness)) {
|
||||
roughness = 0.5;
|
||||
}
|
||||
this.roughness = roughness;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(metalness)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(metalness)) {
|
||||
metalness = 0.5;
|
||||
}
|
||||
this.metalness = metalness;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(pointSize)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(pointSize)) {
|
||||
pointSize = 1;
|
||||
}
|
||||
this.pointSize = pointSize;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(pointSizeAttenuation)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(pointSizeAttenuation)) {
|
||||
pointSizeAttenuation = true;
|
||||
}
|
||||
this.pointSizeAttenuation = pointSizeAttenuation;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(spriteRotation)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(spriteRotation)) {
|
||||
spriteRotation = 0;
|
||||
}
|
||||
this.spriteRotation = spriteRotation;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(envMapIntensity)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(envMapIntensity)) {
|
||||
envMapIntensity = 1.0;
|
||||
}
|
||||
this.envMapIntensity = envMapIntensity;
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
* Raw Mesh API object - should always correspond with the Mesh Schema
|
||||
* @param id
|
||||
* @param meshType
|
||||
* @param name
|
||||
* @param vertices GameLib.D3.Vertex[]
|
||||
* @param faces GameLib.D3.TriangleFace[]
|
||||
* @param faceVertexUvs
|
||||
* @param materials GameLib.D3.API.Material[]
|
||||
* @param parentMeshId
|
||||
* @param parentSceneId
|
||||
* @param skeleton
|
||||
* @param skinIndices
|
||||
* @param skinWeights
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param quaternion GameLib.API.Quaternion
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param localPosition GameLib.API.Vector3
|
||||
* @param localRotation GameLib.API.Vector3
|
||||
* @param localScale GameLib.API.Vector3
|
||||
* @param up
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Mesh = function(
|
||||
id,
|
||||
meshType,
|
||||
name,
|
||||
vertices,
|
||||
faces,
|
||||
faceVertexUvs,
|
||||
materials,
|
||||
parentMeshId,
|
||||
parentSceneId,
|
||||
skeleton,
|
||||
skinIndices,
|
||||
skinWeights,
|
||||
position,
|
||||
quaternion,
|
||||
scale,
|
||||
localPosition,
|
||||
localRotation,
|
||||
localScale,
|
||||
up
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(meshType)) {
|
||||
meshType = GameLib.D3.Mesh.TYPE_NORMAL;
|
||||
}
|
||||
this.meshType = meshType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Mesh (' + meshType + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
||||
throw new Error('Cannot create a mesh with no vertices');
|
||||
}
|
||||
this.vertices = vertices;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
||||
throw new Error('Cannot create a mesh with no faces');
|
||||
}
|
||||
this.faces = faces;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentMeshId)) {
|
||||
parentMeshId = null;
|
||||
}
|
||||
this.parentMeshId = parentMeshId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentSceneId)) {
|
||||
parentSceneId = null;
|
||||
}
|
||||
this.parentSceneId = parentSceneId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(skeleton)) {
|
||||
skeleton = null;
|
||||
}
|
||||
this.skeleton = skeleton;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(faceVertexUvs)) {
|
||||
faceVertexUvs = [];
|
||||
}
|
||||
this.faceVertexUvs = faceVertexUvs;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(skinIndices)) {
|
||||
skinIndices = [];
|
||||
}
|
||||
this.skinIndices = skinIndices;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(skinWeights)) {
|
||||
skinWeights = [];
|
||||
}
|
||||
this.skinWeights = skinWeights;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||
materials = [];
|
||||
}
|
||||
this.materials = materials;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(localPosition)) {
|
||||
localPosition = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.localPosition = localPosition;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(localRotation)) {
|
||||
localRotation = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.localRotation = localRotation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(localScale)) {
|
||||
localScale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.localScale = localScale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
};
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param spline GameLib.D3.API.Spline
|
||||
* @param raytraceMesh GameLib.D3.API.Mesh
|
||||
* @param accelleration Number
|
||||
* @param maxSpeed Number
|
||||
* @param baseOffset GameLib.API.Vector
|
||||
* @param maxOffset GameLib.API.Vector
|
||||
* @param steeringSpeed Number
|
||||
* @param targetOffset GameLib.API.Vector3
|
||||
* @param currentOffset GameLib.API.Vector3
|
||||
* @param currentPathValue Number
|
||||
* @param currentSpeed Number
|
||||
* @param direction Number
|
||||
* @param mx GameLib.Utils.MovingAverage
|
||||
* @param my GameLib.Utils.MovingAverage
|
||||
* @param mz GameLib.Utils.MovingAverage
|
||||
* @param raycaster GameLib.D3.Raycaster
|
||||
* @param currentPosition GameLib.API.Vector3
|
||||
* @param futurePosition GameLib.API.Vector3
|
||||
* @param up GameLib.API.Vector3
|
||||
* @param rotationMatrix GameLib.API.Matrix4
|
||||
* @param rotationVector GameLib.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.PathFollowing = function (
|
||||
id,
|
||||
name,
|
||||
spline,
|
||||
raytraceMesh,
|
||||
accelleration,
|
||||
maxSpeed,
|
||||
baseOffset,
|
||||
maxOffset,
|
||||
steeringSpeed,
|
||||
targetOffset,
|
||||
currentOffset,
|
||||
currentPathValue,
|
||||
currentSpeed,
|
||||
direction,
|
||||
mx,
|
||||
my,
|
||||
mz,
|
||||
raycaster,
|
||||
currentPosition,
|
||||
futurePosition,
|
||||
up,
|
||||
rotationMatrix,
|
||||
rotationVector
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(spline)) {
|
||||
spline = null;
|
||||
}
|
||||
this.spline = spline;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(raytraceMesh)) {
|
||||
raytraceMesh = null;
|
||||
}
|
||||
this.raytraceMesh = raytraceMesh;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxSpeed)) {
|
||||
maxSpeed = 0.03;
|
||||
}
|
||||
this.maxSpeed = maxSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(accelleration)) {
|
||||
accelleration = 0.1;
|
||||
}
|
||||
this.accelleration = accelleration;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(baseOffset)) {
|
||||
baseOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.baseOffset = baseOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(maxOffset)) {
|
||||
maxOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.maxOffset = maxOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(steeringSpeed)) {
|
||||
steeringSpeed = 1.0;
|
||||
}
|
||||
this.steeringSpeed = steeringSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(currentOffset)) {
|
||||
currentOffset = new GameLib.API.Vector3();
|
||||
}
|
||||
this.currentOffset = currentOffset;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(currentPathValue)) {
|
||||
currentPathValue = 0;
|
||||
}
|
||||
this.currentPathValue = currentPathValue;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(currentSpeed)) {
|
||||
currentSpeed = 0;
|
||||
}
|
||||
this.currentSpeed = currentSpeed;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
||||
direction = 1;
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mx)) {
|
||||
mx = new GameLib.Utils.MovingAverage(10);
|
||||
}
|
||||
this.mx = mx;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(my)) {
|
||||
my = new GameLib.Utils.MovingAverage(10);
|
||||
}
|
||||
this.my = my;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(mz)) {
|
||||
mz = new GameLib.Utils.MovingAverage(10);
|
||||
}
|
||||
this.mz = mz;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
||||
raycaster = new GameLib.D3.API.Raycaster();
|
||||
}
|
||||
this.raycaster = raycaster;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new GameLib.API.Vector3();
|
||||
}
|
||||
this.currentPosition = currentPosition;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(futurePosition)) {
|
||||
futurePosition = new GameLib.API.Vector3();
|
||||
}
|
||||
this.futurePosition = futurePosition;
|
||||
|
||||
if(GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0, 1, 0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationMatrix)) {
|
||||
rotationMatrix = new GameLib.API.Matrix4();
|
||||
}
|
||||
this.rotationMatrix = rotationMatrix;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotationVector)) {
|
||||
rotationVector = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.rotationVector = rotationVector;
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Raycaster for GameLib.D3
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param direction GameLib.API.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Raycaster = function(
|
||||
position,
|
||||
direction
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
||||
direction = new GameLib.API.Vector3(0, -1, 0);
|
||||
}
|
||||
this.direction = direction;
|
||||
};
|
|
@ -4,15 +4,15 @@
|
|||
* @param path String
|
||||
* @param name String
|
||||
* @param meshes GameLib.D3.API.Mesh []
|
||||
* @param quaternion GameLib.D3.API.Quaternion
|
||||
* @param position GameLib.D3.API.Vector3
|
||||
* @param rotation GameLib.D3.API.Vector3
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param quaternion GameLib.API.Quaternion
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param rotation GameLib.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param parentSceneId
|
||||
* @param lights GameLib.D3.API.Light[]
|
||||
* @param worlds GameLib.D3.API.World[]
|
||||
* @param entities GameLib.D3.API.Entity[]
|
||||
* @param components GameLib.D3.API.Component[]
|
||||
* @param entities GameLib.API.Entity[]
|
||||
* @param components GameLib.API.Component[]
|
||||
* @param shapes GameLib.D3.API.Shape[]
|
||||
* @param cameras
|
||||
* @param activeCameraIndex
|
||||
|
@ -37,82 +37,82 @@ GameLib.D3.API.Scene = function(
|
|||
activeCameraIndex,
|
||||
splines
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(path)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(path)) {
|
||||
path = null;
|
||||
}
|
||||
this.path = path;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'unnamed';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(meshes)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(meshes)) {
|
||||
meshes = [];
|
||||
}
|
||||
this.meshes = meshes;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.D3.API.Quaternion();
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.API.Vector3();
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.D3.API.Vector3(1,1,1);
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentSceneId)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(parentSceneId)) {
|
||||
parentSceneId = null;
|
||||
}
|
||||
this.parentSceneId = parentSceneId;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lights)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
||||
lights = [];
|
||||
}
|
||||
this.lights = lights;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(worlds)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(worlds)) {
|
||||
worlds = [];
|
||||
}
|
||||
this.worlds = worlds;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(entities)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(entities)) {
|
||||
entities = [];
|
||||
}
|
||||
this.entities = entities;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(components)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(components)) {
|
||||
components = [];
|
||||
}
|
||||
this.components = components;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(shapes)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(shapes)) {
|
||||
shapes = [];
|
||||
}
|
||||
this.shapes = shapes;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(cameras)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(cameras)) {
|
||||
cameras = [];
|
||||
}
|
||||
this.cameras = cameras;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(activeCameraIndex)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(activeCameraIndex)) {
|
||||
activeCameraIndex = 0;
|
||||
}
|
||||
this.activeCameraIndex = activeCameraIndex;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(splines)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(splines)) {
|
||||
splines = [];
|
||||
}
|
||||
this.splines = splines;
|
|
@ -2,7 +2,7 @@
|
|||
* API Spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param vertices GameLib.D3.API.Vector3[]
|
||||
* @param vertices GameLib.API.Vector3[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Spline = function(
|
||||
|
@ -10,17 +10,17 @@ GameLib.D3.API.Spline = function(
|
|||
name,
|
||||
vertices
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'spline-unnamed';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(vertices)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
||||
vertices = [];
|
||||
}
|
||||
this.vertices = vertices;
|
|
@ -46,107 +46,107 @@ GameLib.D3.API.Texture = function(
|
|||
premultiplyAlpha,
|
||||
encoding
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(typeId)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(typeId)) {
|
||||
typeId = GameLib.D3.Texture.TEXTURE_TYPE_DIFFUSE;
|
||||
}
|
||||
this.typeId = typeId;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Texture (' + typeId + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(imagePath)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(imagePath)) {
|
||||
imagePath = null;
|
||||
}
|
||||
this.imagePath = imagePath;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wrapS)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wrapS)) {
|
||||
wrapS = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING;
|
||||
}
|
||||
this.wrapS = wrapS;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wrapT)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(wrapT)) {
|
||||
wrapT = GameLib.D3.Texture.TYPE_REPEAT_WRAPPING;
|
||||
}
|
||||
this.wrapT = wrapT;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(repeat)) {
|
||||
repeat = new GameLib.D3.API.Vector2(1, 1);
|
||||
if (GameLib.Utils.UndefinedOrNull(repeat)) {
|
||||
repeat = new GameLib.API.Vector2(1, 1);
|
||||
}
|
||||
this.repeat = repeat;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(data)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(data)) {
|
||||
data = null;
|
||||
}
|
||||
this.data = data;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(format)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(format)) {
|
||||
format = GameLib.D3.Texture.TYPE_RGBA_FORMAT;
|
||||
}
|
||||
this.format = format;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mapping)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mapping)) {
|
||||
mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
||||
}
|
||||
this.mapping = mapping;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(magFilter)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(magFilter)) {
|
||||
magFilter = GameLib.D3.Texture.TYPE_LINEAR_FILTER;
|
||||
}
|
||||
this.magFilter = magFilter;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(minFilter)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(minFilter)) {
|
||||
minFilter = GameLib.D3.Texture.TYPE_LINEAR_MIPMAP_LINEAR_FILTER;
|
||||
}
|
||||
this.minFilter = minFilter;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(textureType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(textureType)) {
|
||||
textureType = GameLib.D3.Texture.TYPE_UNSIGNED_BYTE;
|
||||
}
|
||||
this.textureType = textureType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(anisotropy)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(anisotropy)) {
|
||||
anisotropy = 1;
|
||||
}
|
||||
this.anisotropy = anisotropy;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(offset)) {
|
||||
offset = new GameLib.D3.API.Vector2(0, 0);
|
||||
if (GameLib.Utils.UndefinedOrNull(offset)) {
|
||||
offset = new GameLib.API.Vector2(0, 0);
|
||||
}
|
||||
this.offset = offset;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(generateMipmaps)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(generateMipmaps)) {
|
||||
generateMipmaps = true;
|
||||
}
|
||||
this.generateMipmaps = generateMipmaps;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(flipY)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(flipY)) {
|
||||
flipY = true;
|
||||
}
|
||||
this.flipY = flipY;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(mipmaps)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(mipmaps)) {
|
||||
mipmaps = [];
|
||||
}
|
||||
this.mipmaps = mipmaps;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(unpackAlignment)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(unpackAlignment)) {
|
||||
unpackAlignment = 4;
|
||||
}
|
||||
this.unpackAlignment = unpackAlignment;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(premultiplyAlpha)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(premultiplyAlpha)) {
|
||||
premultiplyAlpha = false;
|
||||
}
|
||||
this.premultiplyAlpha = premultiplyAlpha;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(encoding)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(encoding)) {
|
||||
encoding = GameLib.D3.Texture.TYPE_LINEAR_ENCODING;
|
||||
}
|
||||
this.encoding = encoding;
|
|
@ -18,19 +18,19 @@ GameLib.D3.Camera = function Camera(
|
|||
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
);
|
||||
|
||||
this.lookAt = new GameLib.D3.Vector3(
|
||||
this.lookAt = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.lookAt
|
||||
|
@ -163,12 +163,12 @@ GameLib.D3.Camera.FromObjectCamera = function(graphics, objectCamera) {
|
|||
objectCamera.aspect,
|
||||
objectCamera.near,
|
||||
objectCamera.far,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectCamera.position.x,
|
||||
objectCamera.position.y,
|
||||
objectCamera.position.z
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectCamera.lookAt.x,
|
||||
objectCamera.lookAt.y,
|
||||
objectCamera.lookAt.z
|
||||
|
@ -179,12 +179,12 @@ GameLib.D3.Camera.FromObjectCamera = function(graphics, objectCamera) {
|
|||
objectCamera.maxY,
|
||||
objectCamera.minZ,
|
||||
objectCamera.maxZ,
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectCamera.quaternion.x,
|
||||
objectCamera.quaternion.y,
|
||||
objectCamera.quaternion.z,
|
||||
objectCamera.quaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectCamera.quaternion.axis.x,
|
||||
objectCamera.quaternion.axis.y,
|
||||
objectCamera.quaternion.axis.z
|
|
@ -14,7 +14,7 @@ GameLib.D3.Color = function RuntimeColor(graphics, parentObject, apiColor, grain
|
|||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Color, GameLib.D3.API.Color);
|
||||
GameLib.Utils.Extend(GameLib.D3.Color, GameLib.D3.API.Color);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
|
@ -22,7 +22,7 @@ GameLib.D3.Color = function RuntimeColor(graphics, parentObject, apiColor, grain
|
|||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Fly Controls
|
||||
* @param camera
|
||||
* @param THREE
|
||||
* @param canvas
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.FlyControls = function(
|
||||
camera,
|
||||
THREE,
|
||||
canvas
|
||||
) {
|
||||
this.flySpeed = 100;
|
||||
|
||||
this.canvas = canvas;
|
||||
|
||||
this.THREE = THREE;
|
||||
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
this.canRotate = false;
|
||||
|
||||
this.moveForward = false;
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
this.moveUp = false;
|
||||
this.moveDown = false;
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Runtime Follow Component
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiFollow
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Follow = function RuntimeFollow(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiFollow
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.API.Follow.call(
|
||||
this,
|
||||
apiFollow.id,
|
||||
apiFollow.name,
|
||||
apiFollow.targetPosition,
|
||||
apiFollow.targetOffset,
|
||||
apiFollow.minDistance,
|
||||
apiFollow.moveSpeed,
|
||||
apiFollow.target,
|
||||
apiFollow.targetToParent,
|
||||
apiFollow.rotatedTargetOffset,
|
||||
apiFollow.rotated
|
||||
);
|
||||
|
||||
this.targetPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetPosition
|
||||
);
|
||||
|
||||
this.targetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetOffset
|
||||
);
|
||||
|
||||
this.target = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.target
|
||||
);
|
||||
|
||||
this.targetToParent = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetToParent
|
||||
);
|
||||
|
||||
this.rotatedTargetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotatedTargetOffset
|
||||
);
|
||||
|
||||
this.rotated = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotated
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);
|
||||
GameLib.D3.Follow.prototype.constructor = GameLib.D3.Follow;
|
|
@ -14,22 +14,22 @@ GameLib.D3.Helper = function Helper(
|
|||
name,
|
||||
graphics
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(object)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||
throw new Error('Cannot create helpers for unknown objects');
|
||||
}
|
||||
this.object = object;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(helperType)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
||||
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
||||
}
|
||||
this.helperType = helperType;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Helper (' + this.helperType + ')';
|
||||
}
|
||||
this.name = name;
|
|
@ -76,8 +76,8 @@ GameLib.D3.Image = function(
|
|||
contentType,
|
||||
textureLink
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.D3.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
|
@ -24,25 +24,25 @@ GameLib.D3.Light = function Light(
|
|||
0.01
|
||||
);
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
);
|
||||
|
||||
this.targetPosition = new GameLib.D3.Vector3(
|
||||
this.targetPosition = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.targetPosition
|
||||
);
|
||||
|
||||
this.scale = new GameLib.D3.Vector3(
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
|
@ -200,34 +200,34 @@ GameLib.D3.Light.FromObjectLight = function(graphics, apiLight) {
|
|||
apiLight.color.a
|
||||
),
|
||||
apiLight.intensity,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiLight.position.x,
|
||||
apiLight.position.y,
|
||||
apiLight.position.z
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiLight.targetPosition.x,
|
||||
apiLight.targetPosition.y,
|
||||
apiLight.targetPosition.z
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
apiLight.quaternion.x,
|
||||
apiLight.quaternion.y,
|
||||
apiLight.quaternion.z,
|
||||
apiLight.quaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiLight.quaternion.axis.x,
|
||||
apiLight.quaternion.axis.y,
|
||||
apiLight.quaternion.axis.z
|
||||
),
|
||||
apiLight.quaternion.angle
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiLight.rotation.x,
|
||||
apiLight.rotation.y,
|
||||
apiLight.rotation.z
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiLight.scale.x,
|
||||
apiLight.scale.y,
|
||||
apiLight.scale.z
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Entities with LookAt component looks to targetPosition (default up is 0,1,0)
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiLookAt GameLib.D3.API.LookAt
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.LookAt = function RuntimeLookAt(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiLookAt
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
GameLib.D3.API.LookAt.call(
|
||||
this,
|
||||
apiLookAt.id,
|
||||
apiLookAt.name,
|
||||
apiLookAt.currentPosition,
|
||||
apiLookAt.targetPosition,
|
||||
apiLookAt.targetPositionOffset,
|
||||
apiLookAt.rotationSpeed,
|
||||
apiLookAt.lookAtMatrix,
|
||||
apiLookAt.up,
|
||||
apiLookAt.currentRotation
|
||||
);
|
||||
|
||||
this.currentPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentPosition
|
||||
);
|
||||
|
||||
this.targetPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetPosition
|
||||
);
|
||||
|
||||
this.targetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetOffset
|
||||
);
|
||||
|
||||
this.lookAtMatrix = new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.lookAtMatrix
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.currentRotation = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentRotation
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
||||
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
|
|
@ -13,7 +13,6 @@ GameLib.D3.Mesh = function RuntimeMesh(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
GameLib.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
|
@ -31,49 +30,52 @@ GameLib.D3.Mesh = function RuntimeMesh(
|
|||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.scale,
|
||||
apiMesh.localPosition,
|
||||
apiMesh.localRotation,
|
||||
apiMesh.localScale,
|
||||
apiMesh.up
|
||||
);
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position,
|
||||
0.001
|
||||
);
|
||||
|
||||
this.scale = new GameLib.D3.Vector3(
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale,
|
||||
0.001
|
||||
);
|
||||
|
||||
this.up = new GameLib.D3.Vector3(
|
||||
this.up = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.up,
|
||||
0.001
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
);
|
||||
|
||||
this.localRotation = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.localRotation
|
||||
);
|
||||
|
||||
this.localPosition = new GameLib.D3.Vector3(
|
||||
this.localPosition = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.localPosition
|
||||
);
|
||||
|
||||
this.localScale = new GameLib.D3.Vector3(
|
||||
this.localRotation = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.localRotation
|
||||
);
|
||||
|
||||
this.localScale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.localScale
|
||||
|
@ -341,13 +343,13 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
|||
|
||||
instance.gameLibObject = this;
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
instance.position.x = this.position.x + this.localPosition.x;
|
||||
instance.position.y = this.position.y + this.localPosition.y;
|
||||
instance.position.z = this.position.z + this.localPosition.z;
|
||||
|
||||
instance.scale.x = this.scale.x;
|
||||
instance.scale.y = this.scale.y;
|
||||
instance.scale.z = this.scale.z;
|
||||
instance.scale.x = this.scale.x * this.localScale.x;
|
||||
instance.scale.y = this.scale.y * this.localScale.y;
|
||||
instance.scale.z = this.scale.z * this.localScale.z;
|
||||
|
||||
instance.up.x = this.up.x;
|
||||
instance.up.y = this.up.y;
|
||||
|
@ -402,6 +404,9 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
|
|||
this.position.toApiVector(),
|
||||
this.quaternion.toApiQuaternion(),
|
||||
this.scale.toApiVector(),
|
||||
this.localPosition.toApiVector(),
|
||||
this.localRotation.toApiVector(),
|
||||
this.localScale.toApiVector(),
|
||||
this.up.toApiVector()
|
||||
);
|
||||
};
|
||||
|
@ -423,7 +428,7 @@ GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals,
|
|||
objectMesh.vertices.map(
|
||||
function (objectVertex) {
|
||||
return new GameLib.D3.Vertex(
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectVertex.position.x,
|
||||
objectVertex.position.y,
|
||||
objectVertex.position.z
|
||||
|
@ -455,29 +460,44 @@ GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals,
|
|||
objectMesh.skeleton,
|
||||
objectMesh.skinIndices,
|
||||
objectMesh.skinWeights,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.position.x,
|
||||
objectMesh.position.y,
|
||||
objectMesh.position.z
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectMesh.quaternion.x,
|
||||
objectMesh.quaternion.y,
|
||||
objectMesh.quaternion.z,
|
||||
objectMesh.quaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.quaternion.axis.x,
|
||||
objectMesh.quaternion.axis.y,
|
||||
objectMesh.quaternion.axis.z
|
||||
),
|
||||
objectMesh.quaternion.angle
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.scale.x,
|
||||
objectMesh.scale.y,
|
||||
objectMesh.scale.z
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.localPosition.x,
|
||||
objectMesh.localPosition.y,
|
||||
objectMesh.localPosition.z
|
||||
),
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.localRotation.x,
|
||||
objectMesh.localRotation.y,
|
||||
objectMesh.localRotation.z
|
||||
),
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.localScale.x,
|
||||
objectMesh.localScale.y,
|
||||
objectMesh.localScale.z
|
||||
),
|
||||
new GameLib.API.Vector3(
|
||||
objectMesh.up.x,
|
||||
objectMesh.up.y,
|
||||
objectMesh.up.z
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiPathFollowing GameLib.D3.API.PathFollowing
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiPathFollowing
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
GameLib.D3.API.PathFollowing.call(
|
||||
this,
|
||||
apiPathFollowing.id,
|
||||
apiPathFollowing.name,
|
||||
apiPathFollowing.spline,
|
||||
apiPathFollowing.raytraceMesh,
|
||||
apiPathFollowing.accelleration,
|
||||
apiPathFollowing.maxSpeed,
|
||||
apiPathFollowing.baseOffset,
|
||||
apiPathFollowing.maxOffset,
|
||||
apiPathFollowing.steeringSpeed,
|
||||
apiPathFollowing.targetOffset,
|
||||
apiPathFollowing.currentOffset,
|
||||
apiPathFollowing.currentPathValue,
|
||||
apiPathFollowing.currentSpeed,
|
||||
apiPathFollowing.direction,
|
||||
apiPathFollowing.mx,
|
||||
apiPathFollowing.my,
|
||||
apiPathFollowing.mz,
|
||||
apiPathFollowing.raycaster,
|
||||
apiPathFollowing.currentPosition,
|
||||
apiPathFollowing.futurePosition,
|
||||
apiPathFollowing.up,
|
||||
apiPathFollowing.rotationMatrix,
|
||||
apiPathFollowing.rotationVector
|
||||
);
|
||||
|
||||
this.baseOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.baseOffset
|
||||
);
|
||||
|
||||
this.maxOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.maxOffset
|
||||
);
|
||||
|
||||
this.targetOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.targetOffset
|
||||
);
|
||||
|
||||
this.currentOffset = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentOffset
|
||||
);
|
||||
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
this.graphics,
|
||||
this,
|
||||
this.raycaster
|
||||
);
|
||||
|
||||
this.currentPosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.currentPosition
|
||||
);
|
||||
|
||||
this.futurePosition = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.futurePosition
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.rotationMatrix = new GameLib.Matrix4(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotationMatrix
|
||||
);
|
||||
|
||||
this.rotationVector = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rotationVector
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
||||
GameLib.D3.PathFollowing.prototype.constructor = GameLib.D3.PathFollowing;
|
|
@ -2,7 +2,7 @@
|
|||
* Contains a Poly vertex data structure
|
||||
* @param localIndex
|
||||
* @param mvertIndex
|
||||
* @param uv GameLib.D3.API.Vector2
|
||||
* @param uv GameLib.API.Vector2
|
||||
* @param materialIndex
|
||||
* @param edgeIndex
|
||||
* @constructor
|
|
@ -14,7 +14,7 @@ GameLib.D3.RaycastVehicle = function(
|
|||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.id = GameLib.D3.Utils.RandomId();
|
||||
this.id = GameLib.Utils.RandomId();
|
||||
|
||||
this.chassisBody = chassisBody;
|
||||
|
||||
|
@ -23,14 +23,14 @@ GameLib.D3.RaycastVehicle = function(
|
|||
}
|
||||
this.wheels = wheels;
|
||||
|
||||
if(GameLib.D3.Utils.UndefinedOrNull(wheelBodies)) {
|
||||
if(GameLib.Utils.UndefinedOrNull(wheelBodies)) {
|
||||
wheelBodies = [];
|
||||
}
|
||||
this.wheelBodies = wheelBodies;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.RaycastVehicle, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.D3.RaycastVehicle, GameLib.Component);
|
||||
};
|
||||
|
||||
/**
|
|
@ -30,7 +30,7 @@ GameLib.D3.RaycastWheel = function(
|
|||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.id = GameLib.D3.Utils.RandomId();
|
||||
this.id = GameLib.Utils.RandomId();
|
||||
|
||||
if(typeof chassisConnectionPointLocal == 'undefined' || chassisConnectionPointLocal == null) {
|
||||
chassisConnectionPointLocal = new this.engine.instance.Vec3();
|
|
@ -1,40 +1,48 @@
|
|||
/**
|
||||
* Raycaster for GameLib.D3
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param position GameLib.D3.Vector3
|
||||
* @param direction GameLib.D3.Vector3
|
||||
* @param parentObject
|
||||
* @param apiRaycaster
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Raycaster = function(
|
||||
graphics,
|
||||
position,
|
||||
direction
|
||||
parentObject,
|
||||
apiRaycaster
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3()
|
||||
);
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.position = position;
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(direction)) {
|
||||
direction = new GameLib.D3.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(0, -1, 0)
|
||||
);
|
||||
}
|
||||
this.direction = direction;
|
||||
GameLib.D3.API.Raycaster.call(
|
||||
this,
|
||||
apiRaycaster.position,
|
||||
apiRaycaster.direction
|
||||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.position
|
||||
);
|
||||
|
||||
this.direction = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.direction
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.D3.Raycaster.prototype = Object.create(GameLib.D3.API.Raycaster.prototype);
|
||||
GameLib.D3.Raycaster.prototype.constructor = GameLib.D3.Raycaster;
|
||||
|
||||
/**
|
||||
* Creates or updates a raycaster instance
|
||||
* @param update
|
||||
|
@ -59,8 +67,8 @@ GameLib.D3.Raycaster.prototype.createInstance = function(update) {
|
|||
|
||||
/**
|
||||
* Sets the direction and position of this raycaster
|
||||
* @param position GameLib.D3.Vector3
|
||||
* @param direction GameLib.D3.Vector3
|
||||
* @param position GameLib.Vector3
|
||||
* @param direction GameLib.Vector3
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.set = function(
|
||||
position,
|
||||
|
@ -77,7 +85,7 @@ GameLib.D3.Raycaster.prototype.set = function(
|
|||
|
||||
/**
|
||||
* Sets the direction of this raycaster
|
||||
* @param direction GameLib.D3.Vector3
|
||||
* @param direction GameLib.Vector3
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.setDirection = function(
|
||||
direction
|
||||
|
@ -91,7 +99,7 @@ GameLib.D3.Raycaster.prototype.setDirection = function(
|
|||
|
||||
/**
|
||||
* Sets the position of this raycaster
|
||||
* @param position GameLib.D3.Vector3
|
||||
* @param position GameLib.Vector3
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.setPosition = function(
|
||||
position
|
||||
|
@ -106,7 +114,7 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
|
|||
/**
|
||||
* Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh
|
||||
* @param mesh GameLib.D3.Mesh
|
||||
* @returns {null | GameLib.D3.Vector3}
|
||||
* @returns {null | GameLib.Vector3}
|
||||
*/
|
||||
GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) {
|
||||
|
||||
|
@ -117,10 +125,10 @@ GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) {
|
|||
);
|
||||
|
||||
if (intersect && intersect.length > 0) {
|
||||
normal = new GameLib.D3.Vector3(
|
||||
normal = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
intersect[0].face.normal.x,
|
||||
intersect[0].face.normal.y,
|
||||
intersect[0].face.normal.z
|
|
@ -10,7 +10,7 @@ GameLib.D3.RigidBodyVehicle = function(
|
|||
chassisBody,
|
||||
wheels
|
||||
) {
|
||||
this.id = GameLib.D3.Utils.RandomId();
|
||||
this.id = GameLib.Utils.RandomId();
|
||||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
|
@ -39,11 +39,11 @@ GameLib.D3.RigidBody = function(
|
|||
shape,
|
||||
kinematic
|
||||
) {
|
||||
this.id = GameLib.D3.Utils.RandomId();
|
||||
this.position = position || new GameLib.D3.API.Vector3();
|
||||
this.velocity = velocity || new GameLib.D3.API.Vector3();
|
||||
this.angularVelocity = angularVelocity || new GameLib.D3.API.Vector3();
|
||||
this.quaternion = quaternion || new GameLib.D3.API.Quaternion(0, 0, 0, 1);
|
||||
this.id = GameLib.Utils.RandomId();
|
||||
this.position = position || new GameLib.API.Vector3();
|
||||
this.velocity = velocity || new GameLib.API.Vector3();
|
||||
this.angularVelocity = angularVelocity || new GameLib.API.Vector3();
|
||||
this.quaternion = quaternion || new GameLib.API.Quaternion(0, 0, 0, 1);
|
||||
this.mass = typeof mass == "undefined" ? 0 : mass;
|
||||
this.friction = typeof friction == "undefined" ? 5 : friction;
|
||||
this.linearDamping = typeof linearDamping == "undefined" ? 0.01 : linearDamping;
|
||||
|
@ -62,7 +62,7 @@ GameLib.D3.RigidBody = function(
|
|||
this.instance = this.createInstance();
|
||||
|
||||
// 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.RigidBody, GameLib.D3.Component);
|
||||
GameLib.Utils.Extend(GameLib.D3.RigidBody, GameLib.Component);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -118,8 +118,8 @@ GameLib.D3.RigidBody.prototype.toApiRigidBody = function() {
|
|||
/**
|
||||
* Adds a shape to this rigid body
|
||||
* @param shape GameLib.D3.Shape
|
||||
* @param offset GameLib.D3.API.Vector3
|
||||
* @param orientation GameLib.D3.API.Quaternion
|
||||
* @param offset GameLib.API.Vector3
|
||||
* @param orientation GameLib.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RigidBody.prototype.addShape = function(
|
||||
|
@ -128,11 +128,11 @@ GameLib.D3.RigidBody.prototype.addShape = function(
|
|||
orientation
|
||||
) {
|
||||
if (!offset || typeof offset == 'undefined') {
|
||||
offset = new GameLib.D3.API.Vector3(0,0,0);
|
||||
offset = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
|
||||
if (!orientation || typeof orientation == 'undefined') {
|
||||
orientation = new GameLib.D3.API.Quaternion(0,0,0,1);
|
||||
orientation = new GameLib.API.Quaternion(0,0,0,1);
|
||||
}
|
||||
|
||||
this.instance.addShape(
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* Rigid Wheel superset
|
||||
* @param body GameLib.D3.RigidBody
|
||||
* @param position GameLib.D3.API.Vector3
|
||||
* @param axis GameLib.D3.API.Vector3
|
||||
* @param direction GameLib.D3.API.Vector3
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param axis GameLib.API.Vector3
|
||||
* @param direction GameLib.API.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.RigidWheel = function(
|
||||
|
@ -12,7 +12,7 @@ GameLib.D3.RigidWheel = function(
|
|||
axis,
|
||||
direction
|
||||
) {
|
||||
this.id = GameLib.D3.Utils.RandomId();
|
||||
this.id = GameLib.Utils.RandomId();
|
||||
this.body = body;
|
||||
this.position = position;
|
||||
this.axis = axis;
|
|
@ -25,19 +25,19 @@ GameLib.D3.Scene = function Scene(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.position
|
||||
);
|
||||
|
||||
this.scale = new GameLib.D3.Vector3(
|
||||
this.scale = new GameLib.Vector3(
|
||||
graphics,
|
||||
this,
|
||||
this.scale
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
|
@ -209,24 +209,24 @@ GameLib.D3.Scene.FromObjectScene = function(
|
|||
)
|
||||
}
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectScene.quaternion.x,
|
||||
objectScene.quaternion.y,
|
||||
objectScene.quaternion.z,
|
||||
objectScene.quaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectScene.quaternion.axis.x,
|
||||
objectScene.quaternion.axis.y,
|
||||
objectScene.quaternion.axis.z
|
||||
),
|
||||
objectScene.quaternion.angle
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectScene.position.x,
|
||||
objectScene.position.y,
|
||||
objectScene.position.z
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
objectScene.scale.x,
|
||||
objectScene.scale.y,
|
||||
objectScene.scale.z
|
||||
|
@ -250,7 +250,7 @@ GameLib.D3.Scene.FromObjectScene = function(
|
|||
),
|
||||
objectScene.entities.map(
|
||||
function (objectEntity) {
|
||||
return GameLib.D3.Entity.FromObjectEntity(
|
||||
return GameLib.Entity.FromObjectEntity(
|
||||
graphics,
|
||||
objectEntity
|
||||
);
|
||||
|
@ -258,7 +258,7 @@ GameLib.D3.Scene.FromObjectScene = function(
|
|||
),
|
||||
objectScene.components.map(
|
||||
function (objectComponent) {
|
||||
return GameLib.D3.Component.FromObjectComponent(
|
||||
return GameLib.Component.FromObjectComponent(
|
||||
graphics,
|
||||
objectComponent
|
||||
);
|
||||
|
@ -385,61 +385,3 @@ GameLib.D3.Scene.LoadSceneFromApi = function(
|
|||
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the scene
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.Scene.prototype.update = function(
|
||||
deltaTime
|
||||
) {
|
||||
this.entities.forEach(
|
||||
function (entity) {
|
||||
if (_.isFunction(entity.update)) {
|
||||
/**
|
||||
* Normal update
|
||||
*/
|
||||
entity.update(deltaTime, false);
|
||||
|
||||
//TODO: calculate new delta time?
|
||||
|
||||
/**
|
||||
* Late update
|
||||
*/
|
||||
entity.update(deltaTime, true);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* renders the scene
|
||||
* @param deltaTime
|
||||
* @param renderer
|
||||
*/
|
||||
GameLib.D3.Scene.prototype.render = function(
|
||||
deltaTime,
|
||||
renderer
|
||||
) {
|
||||
renderer.render(this.instance, this.cameras[this.activeCameraIndex].instance);
|
||||
};
|
||||
|
||||
/**
|
||||
* After we created a scene and idToObject has been created, we should execute this function to map
|
||||
* the scene objects to the components and entities
|
||||
*/
|
||||
GameLib.D3.Scene.prototype.linkObjects = function() {
|
||||
|
||||
this.components.map(
|
||||
function(component) {
|
||||
component.linkObjects(this.idToObject);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.entities.map(
|
||||
function(entity) {
|
||||
entity.linkObjects(this.idToObject);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
};
|
|
@ -2,11 +2,11 @@
|
|||
* Physics Shape Superset
|
||||
* @param engine GameLib.D3.Engine
|
||||
* @param shapeType
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param vertices Number[]
|
||||
* @param indices Number[]
|
||||
* @param radius Number
|
||||
* @param halfExtensions GameLib.D3.API.Vector3
|
||||
* @param halfExtensions GameLib.API.Vector3
|
||||
* @param radiusTop Number
|
||||
* @param radiusBottom Number
|
||||
* @param height Number
|
||||
|
@ -37,7 +37,7 @@ GameLib.D3.Shape = function(
|
|||
this.shapeType = shapeType;
|
||||
|
||||
if (typeof scale == 'undefined') {
|
||||
scale = new GameLib.D3.API.Vector3(1, 1, 1)
|
||||
scale = new GameLib.API.Vector3(1, 1, 1)
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
|
@ -57,7 +57,7 @@ GameLib.D3.Shape = function(
|
|||
this.radius = radius;
|
||||
|
||||
if (typeof halfExtensions == 'undefined') {
|
||||
halfExtensions = new GameLib.D3.API.Vector3(1,1,1);
|
||||
halfExtensions = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.halfExtensions = halfExtensions;
|
||||
|
|
@ -26,7 +26,7 @@ GameLib.D3.Skeleton = function Skeleton(
|
|||
|
||||
/**
|
||||
* An array of Matrix4s that represent the inverse of the matrixWorld of the individual bones.
|
||||
* @type GameLib.D3.Matrix4[]
|
||||
* @type GameLib.Matrix4[]
|
||||
*/
|
||||
if (typeof boneInverses == 'undefined') {
|
||||
boneInverses = [];
|
|
@ -54,10 +54,10 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Spline.prototype.getPointAt = function(proper) {
|
||||
var point = this.instance.getPointAt(proper);
|
||||
return new GameLib.D3.Vector3(
|
||||
return new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
new GameLib.D3.API.Vector3(point.x, point.y, point.z),
|
||||
new GameLib.API.Vector3(point.x, point.y, point.z),
|
||||
0.1
|
||||
);
|
||||
};
|
|
@ -9,12 +9,12 @@ GameLib.D3.TextureMap = function TextureMap(
|
|||
texture,
|
||||
instanceMapId
|
||||
) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(texture)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(texture)) {
|
||||
texture = null;
|
||||
}
|
||||
this.texture = texture;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(instanceMapId)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(instanceMapId)) {
|
||||
instanceMapId = null;
|
||||
}
|
||||
this.instanceMapId = instanceMapId;
|
|
@ -24,13 +24,13 @@ GameLib.D3.Texture = function Texture(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.offset = new GameLib.D3.Vector2(
|
||||
this.offset = new GameLib.Vector2(
|
||||
graphics,
|
||||
this,
|
||||
this.offset
|
||||
);
|
||||
|
||||
this.repeat = new GameLib.D3.Vector2(
|
||||
this.repeat = new GameLib.Vector2(
|
||||
graphics,
|
||||
this,
|
||||
this.repeat
|
||||
|
@ -265,7 +265,7 @@ GameLib.D3.Texture.FromObjectTexture = function(
|
|||
objectTexture.imagePath,
|
||||
objectTexture.wrapS,
|
||||
objectTexture.wrapT,
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
objectTexture.repeat.x,
|
||||
objectTexture.repeat.y
|
||||
),
|
||||
|
@ -276,7 +276,7 @@ GameLib.D3.Texture.FromObjectTexture = function(
|
|||
objectTexture.minFilter,
|
||||
objectTexture.textureType,
|
||||
objectTexture.anisotropy,
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
objectTexture.offset.x,
|
||||
objectTexture.offset.y
|
||||
),
|
|
@ -49,15 +49,15 @@ GameLib.D3.TriangleFace = function TriangleFace(
|
|||
|
||||
if (!vertexNormals) {
|
||||
vertexNormals = [
|
||||
new GameLib.D3.API.Vector3(),
|
||||
new GameLib.D3.API.Vector3(),
|
||||
new GameLib.D3.API.Vector3()
|
||||
new GameLib.API.Vector3(),
|
||||
new GameLib.API.Vector3(),
|
||||
new GameLib.API.Vector3()
|
||||
]
|
||||
}
|
||||
this.vertexNormals = vertexNormals;
|
||||
|
||||
if (!normal) {
|
||||
normal = new GameLib.D3.API.Vector3(0);
|
||||
normal = new GameLib.API.Vector3(0);
|
||||
}
|
||||
|
||||
this.normal = normal;
|
|
@ -24,7 +24,7 @@ GameLib.D3.World = function(
|
|||
this.name = name;
|
||||
|
||||
if (typeof gravity == 'undefined') {
|
||||
gravity = new GameLib.D3.API.Vector3(0, -9.81, 0);
|
||||
gravity = new GameLib.API.Vector3(0, -9.81, 0);
|
||||
}
|
||||
this.gravity = gravity;
|
||||
|
||||
|
@ -174,7 +174,7 @@ GameLib.D3.World.prototype.GetIndexedVertices = function(
|
|||
/**
|
||||
* @param triangleMeshShape GameLib.D3.Shape
|
||||
* @param normalLength Number
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param opacity Number
|
||||
* @param wireframeColor HexCode
|
||||
* @param graphics THREE
|
||||
|
@ -281,7 +281,7 @@ GameLib.D3.World.prototype.generateWireframeViewTriangleMesh = function(
|
|||
/**
|
||||
* @param convexPolyMeshShape GameLib.D3.Shape
|
||||
* @param normalLength Number
|
||||
* @param scale GameLib.D3.API.Vector3
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param opacity Number
|
||||
* @param wireframeColor HexCode
|
||||
* @param graphics THREE
|
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
* GameLib.EntityManager
|
||||
* @param entities GameLib.D3.Entity[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.EntityManager = function(entities) {
|
||||
|
||||
GameLib.API.EntityManager.call(
|
||||
this,
|
||||
entities
|
||||
);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.EntityManager.prototype = Object.create(GameLib.API.EntityManager.prototype);
|
||||
GameLib.EntityManager.prototype.constructor = GameLib.EntityManager;
|
||||
|
||||
/**
|
||||
* Creates an Entity Manager instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.EntityManager.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (typeof 'require' != 'undefined') {
|
||||
instance = require('tiny-ecs').EntityManager;
|
||||
} else {
|
||||
instance = EntityManager.EntityManager;
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an GameLib.Entity
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.EntityManager.prototype.createEntity = function() {
|
||||
|
||||
var entity = new GameLib.Entity(this);
|
||||
|
||||
this.entities.push(entity);
|
||||
|
||||
return entity;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes an entity
|
||||
* @param entity GameLib.D3.Entity
|
||||
* @returns bool true if successful
|
||||
*/
|
||||
GameLib.EntityManager.prototype.removeEntity = function(entity) {
|
||||
|
||||
entity.instance.remove();
|
||||
|
||||
var index = this.entities.indexOf(entity);
|
||||
|
||||
if (index == -1) {
|
||||
console.log('failed to remove entity : ', entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.entities.splice(index, 1);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a component to an entity
|
||||
* @param entity GameLib.D3.Entity
|
||||
* @param component Object.constructor
|
||||
*/
|
||||
GameLib.EntityManager.prototype.entityAddComponent = function(entity, component) {
|
||||
this.instance.entityAddComponent(entity.instance, component);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all the objects with the following components
|
||||
* @param components GameLib.Component[]
|
||||
*/
|
||||
GameLib.EntityManager.prototype.queryComponents = function(components) {
|
||||
return this.instance.queryComponents(components);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.Entity to GameLib.API.Entity
|
||||
* @returns {GameLib.API.Entity}
|
||||
*/
|
||||
GameLib.EntityManager.prototype.toApiEntity = function() {
|
||||
|
||||
//TODO: refactor / fix
|
||||
// var apiEntity = new GameLib.API.Entity(
|
||||
// this.id,
|
||||
// this.name,
|
||||
// GameLib.Utils.IdArrayOrEmptyArray(this.components),
|
||||
// this.position.toApiVector(),
|
||||
// this.quaternion.toApiQuaternion(),
|
||||
// this.scale.toApiVector(),
|
||||
// GameLib.Utils.IdOrNull(this.parentScene),
|
||||
// GameLib.Utils.IdOrNull(this.mesh)
|
||||
// );
|
||||
//
|
||||
// return apiEntity;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectEntity Object
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntity) {
|
||||
|
||||
//TODO: refactor /fix
|
||||
// var apiEntity = new GameLib.API.Entity(
|
||||
// objectEntity.id,
|
||||
// objectEntity.name,
|
||||
// objectEntity.components,
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.position.x,
|
||||
// objectEntity.position.y,
|
||||
// objectEntity.position.z
|
||||
// ),
|
||||
// new GameLib.API.Quaternion(
|
||||
// objectEntity.quaternion.x,
|
||||
// objectEntity.quaternion.y,
|
||||
// objectEntity.quaternion.z,
|
||||
// objectEntity.quaternion.w,
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.quaternion.axis.x,
|
||||
// objectEntity.quaternion.axis.y,
|
||||
// objectEntity.quaternion.axis.z
|
||||
// )
|
||||
// ),
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.scale.x,
|
||||
// objectEntity.scale.y,
|
||||
// objectEntity.scale.z
|
||||
// ),
|
||||
// objectEntity.parentScene,
|
||||
// objectEntity.mesh
|
||||
// );
|
||||
//
|
||||
// return new GameLib.Entity(
|
||||
// graphics,
|
||||
// apiEntity
|
||||
// );
|
||||
};
|
||||
|
||||
/**
|
||||
* Links object Ids to actual objects
|
||||
* @param idToObject
|
||||
*/
|
||||
GameLib.EntityManager.prototype.linkObjects = function(idToObject) {
|
||||
|
||||
// TODO: fix
|
||||
// this.components.forEach(
|
||||
// function(currentValue, index, array) {
|
||||
//
|
||||
// if (!idToObject[currentValue]) {
|
||||
// //throw new Error('Unable to locate component with ID: ' + currentValue);
|
||||
// console.log('Unable to locate component with ID: ' + currentValue + ' - it must have been deleted before');
|
||||
// array.splice(index, 1);
|
||||
// } else {
|
||||
// array[index] = idToObject[currentValue];
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }.bind(this)
|
||||
// );
|
||||
|
||||
};
|
|
@ -1,82 +1,69 @@
|
|||
/**
|
||||
* Entity Runtime
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiEntity GameLib.D3.API.Entity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Entity = function Entity(
|
||||
graphics,
|
||||
GameLib.Entity = function RuntimeEntity(
|
||||
entityManager,
|
||||
parentObject,
|
||||
apiEntity
|
||||
) {
|
||||
for (var property in apiEntity) {
|
||||
if (apiEntity.hasOwnProperty(property)) {
|
||||
this[property] = apiEntity[property];
|
||||
}
|
||||
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
|
||||
throw new Error('You cannot create entities without an entity manager')
|
||||
}
|
||||
this.entityManager = entityManager;
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
this.position = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
GameLib.API.Entity.call(
|
||||
this,
|
||||
this.position
|
||||
apiEntity.id,
|
||||
apiEntity.name,
|
||||
apiEntity.components
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.D3.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.quaternion
|
||||
);
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
this.scale = new GameLib.D3.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.scale
|
||||
);
|
||||
GameLib.Entity.prototype = Object.create(GameLib.API.Entity.prototype);
|
||||
GameLib.Entity.prototype.constructor = GameLib.Entity;
|
||||
|
||||
/**
|
||||
* Creates an entity instance
|
||||
*/
|
||||
GameLib.Entity.prototype.createInstance = function() {
|
||||
var instance = this.entityManager.createEntity();
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the Entity and it's components
|
||||
* @param deltaTime Number
|
||||
* @param late boolean to indicate whether or not this is a late update
|
||||
* Updates an entity instance
|
||||
*/
|
||||
GameLib.D3.Entity.prototype.update = function(
|
||||
deltaTime,
|
||||
late
|
||||
) {
|
||||
|
||||
this.components.forEach(
|
||||
function (component) {
|
||||
if (!late && component.onUpdate) {
|
||||
component.onUpdate(deltaTime, this);
|
||||
}
|
||||
|
||||
if (late && component.onLateUpdate) {
|
||||
component.onLateUpdate(deltaTime, this);
|
||||
}
|
||||
}
|
||||
);
|
||||
GameLib.Entity.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Entity to GameLib.D3.API.Entity
|
||||
* @returns {GameLib.D3.API.Entity}
|
||||
* Converts a GameLib.Entity to GameLib.API.Entity
|
||||
* @returns {GameLib.API.Entity}
|
||||
*/
|
||||
GameLib.D3.Entity.prototype.toApiEntity = function() {
|
||||
GameLib.Entity.prototype.toApiEntity = function() {
|
||||
|
||||
var apiEntity = new GameLib.D3.API.Entity(
|
||||
this.id,
|
||||
this.name,
|
||||
GameLib.D3.Utils.IdArrayOrEmptyArray(this.components),
|
||||
this.position.toApiVector(),
|
||||
this.quaternion.toApiQuaternion(),
|
||||
this.scale.toApiVector(),
|
||||
GameLib.D3.Utils.IdOrNull(this.parentScene),
|
||||
GameLib.D3.Utils.IdOrNull(this.mesh)
|
||||
);
|
||||
|
||||
return apiEntity;
|
||||
//TODO: refactor / fix
|
||||
// var apiEntity = new GameLib.API.Entity(
|
||||
// this.id,
|
||||
// this.name,
|
||||
// GameLib.Utils.IdArrayOrEmptyArray(this.components),
|
||||
// this.position.toApiVector(),
|
||||
// this.quaternion.toApiQuaternion(),
|
||||
// this.scale.toApiVector(),
|
||||
// GameLib.Utils.IdOrNull(this.parentScene),
|
||||
// GameLib.Utils.IdOrNull(this.mesh)
|
||||
// );
|
||||
//
|
||||
// return apiEntity;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -85,111 +72,40 @@ GameLib.D3.Entity.prototype.toApiEntity = function() {
|
|||
* @param objectEntity Object
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Entity.FromObjectEntity = function(graphics, objectEntity) {
|
||||
GameLib.Entity.FromObjectEntity = function(graphics, objectEntity) {
|
||||
|
||||
var apiEntity = new GameLib.D3.API.Entity(
|
||||
objectEntity.id,
|
||||
objectEntity.name,
|
||||
objectEntity.components,
|
||||
new GameLib.D3.API.Vector3(
|
||||
objectEntity.position.x,
|
||||
objectEntity.position.y,
|
||||
objectEntity.position.z
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
objectEntity.quaternion.x,
|
||||
objectEntity.quaternion.y,
|
||||
objectEntity.quaternion.z,
|
||||
objectEntity.quaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
objectEntity.quaternion.axis.x,
|
||||
objectEntity.quaternion.axis.y,
|
||||
objectEntity.quaternion.axis.z
|
||||
)
|
||||
),
|
||||
new GameLib.D3.API.Vector3(
|
||||
objectEntity.scale.x,
|
||||
objectEntity.scale.y,
|
||||
objectEntity.scale.z
|
||||
),
|
||||
objectEntity.parentScene,
|
||||
objectEntity.mesh
|
||||
);
|
||||
|
||||
return new GameLib.D3.Entity(
|
||||
graphics,
|
||||
apiEntity
|
||||
);
|
||||
//TODO: refactor /fix
|
||||
// var apiEntity = new GameLib.API.Entity(
|
||||
// objectEntity.id,
|
||||
// objectEntity.name,
|
||||
// objectEntity.components,
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.position.x,
|
||||
// objectEntity.position.y,
|
||||
// objectEntity.position.z
|
||||
// ),
|
||||
// new GameLib.API.Quaternion(
|
||||
// objectEntity.quaternion.x,
|
||||
// objectEntity.quaternion.y,
|
||||
// objectEntity.quaternion.z,
|
||||
// objectEntity.quaternion.w,
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.quaternion.axis.x,
|
||||
// objectEntity.quaternion.axis.y,
|
||||
// objectEntity.quaternion.axis.z
|
||||
// )
|
||||
// ),
|
||||
// new GameLib.API.Vector3(
|
||||
// objectEntity.scale.x,
|
||||
// objectEntity.scale.y,
|
||||
// objectEntity.scale.z
|
||||
// ),
|
||||
// objectEntity.parentScene,
|
||||
// objectEntity.mesh
|
||||
// );
|
||||
//
|
||||
// return new GameLib.Entity(
|
||||
// graphics,
|
||||
// apiEntity
|
||||
// );
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets called when the entity was registered with it's parent scene
|
||||
* @param parentScene GameLib.D3.Scene
|
||||
*/
|
||||
GameLib.D3.Entity.prototype.register = function(
|
||||
parentScene
|
||||
) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a components to the entity and registers it with the entity's parent scene
|
||||
* @param component GameLib.D3.Component
|
||||
*/
|
||||
GameLib.D3.Entity.prototype.addComponent = function(
|
||||
component
|
||||
) {
|
||||
this.components.push(component);
|
||||
|
||||
if (_.isFunction(component.onAdd)) {
|
||||
component.onAdd(this);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Entity.prototype.removeComponent = function(component) {
|
||||
|
||||
var index = this.components.indexOf(component);
|
||||
this.components.splice(index, 1);
|
||||
|
||||
if (_.isFunction(component.onRemove)) {
|
||||
component.onRemove(this);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Links object Ids to actual objects
|
||||
* @param idToObject
|
||||
*/
|
||||
GameLib.D3.Entity.prototype.linkObjects = function(idToObject) {
|
||||
|
||||
this.components.forEach(
|
||||
function(currentValue, index, array) {
|
||||
|
||||
if (!idToObject[currentValue]) {
|
||||
throw new Error('Unable to locate component with ID: ' + currentValue);
|
||||
}
|
||||
|
||||
array[index] = idToObject[currentValue];
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.parentScene) {
|
||||
|
||||
if (!idToObject[this.parentScene]) {
|
||||
throw new Error('Unable to locate scene with ID: ' + this.parentScene);
|
||||
}
|
||||
|
||||
this.parentScene = idToObject[this.parentScene];
|
||||
|
||||
}
|
||||
|
||||
if (this.mesh) {
|
||||
|
||||
if (!idToObject[this.mesh]) {
|
||||
throw new Error('Unable to locate mesh with ID: ' + this.mesh);
|
||||
}
|
||||
|
||||
this.mesh = idToObject[this.mesh];
|
||||
}
|
||||
|
||||
};
|
|
@ -1,237 +0,0 @@
|
|||
/**
|
||||
* Fly Controls
|
||||
* @param camera
|
||||
* @param THREE
|
||||
* @param canvas
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.FlyControls = function(
|
||||
camera,
|
||||
THREE,
|
||||
canvas
|
||||
) {
|
||||
this.flySpeed = 100;
|
||||
|
||||
this.canvas = canvas;
|
||||
|
||||
this.THREE = THREE;
|
||||
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
this.canRotate = false;
|
||||
|
||||
this.moveForward = false;
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
this.moveUp = false;
|
||||
this.moveDown = false;
|
||||
|
||||
this.mouseUpCallback = this.onMouseUp.bind(this);
|
||||
this.mouseDownCallback = this.onMouseDown.bind(this);
|
||||
this.mouseMoveCallback = this.onMouseMove.bind(this);
|
||||
this.mouseWheelCallback = this.onMouseWheel.bind(this);
|
||||
this.keyDownCallback = this.onKeyDown.bind(this);
|
||||
this.keyUpCallback = this.onKeyUp.bind(this);
|
||||
|
||||
this.camera = camera;
|
||||
|
||||
this.canvas.addEventListener('keydown', this.keyDownCallback, false);
|
||||
this.canvas.addEventListener('keyup', this.keyUpCallback, false);
|
||||
this.canvas.addEventListener('mousedown', this.mouseDownCallback, false);
|
||||
this.canvas.addEventListener('mouseup', this.mouseUpCallback, false);
|
||||
this.canvas.addEventListener('mousewheel', this.mouseWheelCallback, false);
|
||||
|
||||
this.havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
||||
this.element = document.body;
|
||||
|
||||
if (this.havePointerLock) {
|
||||
this.element.requestPointerLock = this.element.requestPointerLock || this.element.mozRequestPointerLock || this.element.webkitRequestPointerLock;
|
||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Go forward / backward on mouse wheel
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onMouseWheel = function(event) {
|
||||
this.moveForward = true;
|
||||
this.applyTranslation(event.wheelDelta * 0.001);
|
||||
event.preventDefault();
|
||||
this.moveForward = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start rotating the camera on mouse middle button down
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onMouseDown = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = true;
|
||||
this.canvas.addEventListener('mousemove', this.mouseMoveCallback, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop rotating on middle mouse button down
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onMouseUp = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = false;
|
||||
this.canvas.removeEventListener('mousemove', this.mouseMoveCallback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current yaw and pitch to camera
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.applyRotation = function() {
|
||||
this.camera.rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current position to camera
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.applyTranslation = function(deltaTime) {
|
||||
var direction = new this.THREE.Vector3(0, 0, -1);
|
||||
var rotation = new this.THREE.Euler(0, 0, 0, "YXZ");
|
||||
rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
|
||||
direction = direction.applyEuler(rotation);
|
||||
|
||||
var forward = direction.normalize();
|
||||
var right = forward.cross(new this.THREE.Vector3(0, 1, 0));
|
||||
|
||||
if(this.moveForward) {
|
||||
|
||||
this.camera.position.x += forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += forward.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveBackward) {
|
||||
|
||||
this.camera.position.x -= forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= forward.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveLeft) {
|
||||
|
||||
this.camera.position.x -= right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= right.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveRight) {
|
||||
|
||||
this.camera.position.x += right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += right.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveUp) {
|
||||
|
||||
this.camera.position.y += (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveDown) {
|
||||
|
||||
this.camera.position.y -= (deltaTime * this.flySpeed);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This update function should be called from the animation function in order to apply the 'frame rate independent'
|
||||
* movement to the camera
|
||||
* @param deltaTime
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.update = function(deltaTime) {
|
||||
this.applyRotation();
|
||||
this.applyTranslation(deltaTime);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate on mouse move
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onMouseMove = function ( event ) {
|
||||
if (this.canRotate) {
|
||||
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||
|
||||
this.yaw -= movementX * 0.002;
|
||||
this.pitch -= movementY * 0.002;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onKeyDown = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 87: // w
|
||||
this.moveForward = true;
|
||||
break;
|
||||
|
||||
case 65: // a
|
||||
this.moveLeft = true;
|
||||
break;
|
||||
|
||||
case 83: // s
|
||||
this.moveBackward = true;
|
||||
break;
|
||||
|
||||
case 68: // d
|
||||
this.moveRight = true;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = true;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*/
|
||||
GameLib.D3.FlyControls.prototype.onKeyUp = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: // up
|
||||
case 87: // w
|
||||
this.moveForward = false;
|
||||
break;
|
||||
|
||||
case 37: // left
|
||||
case 65: // a
|
||||
this.moveLeft = false;
|
||||
break;
|
||||
|
||||
case 40: // down
|
||||
case 83: // s
|
||||
this.moveBackward = false;
|
||||
break;
|
||||
|
||||
case 39: // right
|
||||
case 68: // d
|
||||
this.moveRight = false;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = false;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = false;
|
||||
break;
|
||||
}
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Matrix 3 Maths
|
||||
* @param row0 GameLib.D3.API.Vector3
|
||||
* @param row1 GameLib.D3.API.Vector3
|
||||
* @param row2 GameLib.D3.API.Vector3
|
||||
* @param row0 GameLib.API.Vector3
|
||||
* @param row1 GameLib.API.Vector3
|
||||
* @param row2 GameLib.API.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Matrix3 = function(
|
||||
GameLib.Matrix3 = function(
|
||||
row0,
|
||||
row1,
|
||||
row2
|
||||
|
@ -28,10 +28,10 @@ GameLib.D3.Matrix3 = function(
|
|||
/**
|
||||
* Set matrix to identity
|
||||
*/
|
||||
GameLib.D3.Matrix3.prototype.identity = function () {
|
||||
GameLib.Matrix3.prototype.identity = function () {
|
||||
this.rows = [
|
||||
new GameLib.D3.API.Vector3(1, 0, 0),
|
||||
new GameLib.D3.API.Vector3(0, 1, 0),
|
||||
new GameLib.D3.API.Vector3(0, 0, 1)
|
||||
new GameLib.API.Vector3(1, 0, 0),
|
||||
new GameLib.API.Vector3(0, 1, 0),
|
||||
new GameLib.API.Vector3(0, 0, 1)
|
||||
];
|
||||
};
|
|
@ -6,7 +6,7 @@
|
|||
* @param grain
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Matrix4 = function(
|
||||
GameLib.Matrix4 = function(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiMatrix4,
|
||||
|
@ -19,7 +19,7 @@ GameLib.D3.Matrix4 = function(
|
|||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Matrix4, GameLib.D3.API.Matrix4);
|
||||
GameLib.Utils.Extend(GameLib.Matrix4, GameLib.API.Matrix4);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
|
@ -27,33 +27,33 @@ GameLib.D3.Matrix4 = function(
|
|||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
this.rows[0] = new GameLib.D3.Quaternion(
|
||||
this.rows[0] = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[0],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[1] = new GameLib.D3.Quaternion(
|
||||
this.rows[1] = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[1],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[2] = new GameLib.D3.Quaternion(
|
||||
this.rows[2] = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[2],
|
||||
grain
|
||||
);
|
||||
|
||||
this.rows[3] = new GameLib.D3.Quaternion(
|
||||
this.rows[3] = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this,
|
||||
this.rows[3],
|
||||
|
@ -67,7 +67,7 @@ GameLib.D3.Matrix4 = function(
|
|||
* Creates a matrix 4 instance (currently from graphics lib)
|
||||
* @param update
|
||||
*/
|
||||
GameLib.D3.Matrix4.prototype.createInstance = function(update) {
|
||||
GameLib.Matrix4.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
|
@ -104,7 +104,7 @@ GameLib.D3.Matrix4.prototype.createInstance = function(update) {
|
|||
/**
|
||||
* Updates this instance
|
||||
*/
|
||||
GameLib.D3.Matrix4.prototype.updateInstance = function() {
|
||||
GameLib.Matrix4.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
|
@ -115,7 +115,7 @@ GameLib.D3.Matrix4.prototype.updateInstance = function() {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||
|
||||
this.instance.lookAt(position.instance, target.instance, up.instance);
|
||||
|
||||
|
@ -142,11 +142,11 @@ GameLib.D3.Matrix4.prototype.lookAt = function (position, target, up) {
|
|||
};
|
||||
|
||||
/**
|
||||
* GameLib.D3.Matrix4 to GameLib.D3.API.Matrix4
|
||||
* GameLib.Matrix4 to GameLib.API.Matrix4
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Matrix4.prototype.toApiMatrix = function () {
|
||||
return new GameLib.D3.API.Matrix4(
|
||||
GameLib.Matrix4.prototype.toApiMatrix = function () {
|
||||
return new GameLib.API.Matrix4(
|
||||
this.rows[0].toApiQuaternion(),
|
||||
this.rows[1].toApiQuaternion(),
|
||||
this.rows[2].toApiQuaternion(),
|
||||
|
@ -155,34 +155,34 @@ GameLib.D3.Matrix4.prototype.toApiMatrix = function () {
|
|||
};
|
||||
|
||||
/**
|
||||
* Creates a GameLib.D3.Matrix4 from an Object matrix
|
||||
* Creates a GameLib.Matrix4 from an Object matrix
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectMatrix Object
|
||||
* @param parentObject
|
||||
* @returns {GameLib.D3.Matrix4}
|
||||
* @returns {GameLib.Matrix4}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject) {
|
||||
var apiMatrix = new GameLib.D3.API.Matrix4(
|
||||
new GameLib.D3.API.Quaternion(
|
||||
GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject) {
|
||||
var apiMatrix = new GameLib.API.Matrix4(
|
||||
new GameLib.API.Quaternion(
|
||||
objectMatrix[0],
|
||||
objectMatrix[1],
|
||||
objectMatrix[2],
|
||||
objectMatrix[3]
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectMatrix[4],
|
||||
objectMatrix[5],
|
||||
objectMatrix[6],
|
||||
objectMatrix[7]
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectMatrix[8],
|
||||
objectMatrix[9],
|
||||
objectMatrix[10],
|
||||
objectMatrix[11]
|
||||
),
|
||||
new GameLib.D3.API.Quaternion(
|
||||
new GameLib.API.Quaternion(
|
||||
objectMatrix[12],
|
||||
objectMatrix[13],
|
||||
objectMatrix[14],
|
||||
|
@ -190,7 +190,7 @@ GameLib.D3.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObj
|
|||
)
|
||||
);
|
||||
|
||||
return new GameLib.D3.Matrix4(
|
||||
return new GameLib.Matrix4(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiMatrix
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* Runtime quaternion for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiQuaternion GameLib.D3.API.Quaternion
|
||||
* @param apiQuaternion GameLib.API.Quaternion
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Quaternion = function RuntimeQuaternion(
|
||||
GameLib.Quaternion = function RuntimeQuaternion(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiQuaternion,
|
||||
|
@ -15,13 +15,13 @@ GameLib.D3.Quaternion = function RuntimeQuaternion(
|
|||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
GameLib.D3.API.Quaternion.call(
|
||||
GameLib.API.Quaternion.call(
|
||||
this,
|
||||
apiQuaternion.x,
|
||||
apiQuaternion.y,
|
||||
apiQuaternion.z,
|
||||
apiQuaternion.w,
|
||||
new GameLib.D3.API.Vector3(
|
||||
new GameLib.API.Vector3(
|
||||
apiQuaternion.axis.x,
|
||||
apiQuaternion.axis.y,
|
||||
apiQuaternion.axis.z
|
||||
|
@ -29,19 +29,19 @@ GameLib.D3.Quaternion = function RuntimeQuaternion(
|
|||
apiQuaternion.angle
|
||||
);
|
||||
|
||||
this.axis = new GameLib.D3.Vector3(
|
||||
this.axis = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this,
|
||||
this.axis,
|
||||
0.001
|
||||
);
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentObject)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
@ -49,15 +49,15 @@ GameLib.D3.Quaternion = function RuntimeQuaternion(
|
|||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.D3.Quaternion.prototype = Object.create(GameLib.D3.API.Quaternion.prototype);
|
||||
GameLib.D3.Quaternion.prototype.constructor = GameLib.D3.Quaternion;
|
||||
GameLib.Quaternion.prototype = Object.create(GameLib.API.Quaternion.prototype);
|
||||
GameLib.Quaternion.prototype.constructor = GameLib.Quaternion;
|
||||
|
||||
/**
|
||||
* Creates an instance quaternion
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Quaternion.prototype.createInstance = function(update) {
|
||||
GameLib.Quaternion.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
|
@ -77,7 +77,7 @@ GameLib.D3.Quaternion.prototype.createInstance = function(update) {
|
|||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Quaternion.prototype.updateInstance = function() {
|
||||
GameLib.Quaternion.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
|
@ -90,8 +90,8 @@ GameLib.D3.Quaternion.prototype.updateInstance = function() {
|
|||
* Converts runtime quaternion to API quaternion
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Quaternion.prototype.toApiQuaternion = function() {
|
||||
return new GameLib.D3.API.Quaternion(
|
||||
GameLib.Quaternion.prototype.toApiQuaternion = function() {
|
||||
return new GameLib.API.Quaternion(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @param entityManager GameLib.EntityManager
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System = function(
|
||||
entityManager
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
|
||||
entityManager = null;
|
||||
}
|
||||
this.entityManager = entityManager;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @callback
|
||||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.update = function() {};
|
|
@ -0,0 +1,180 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System.Animation = function(
|
||||
entityManager
|
||||
) {
|
||||
GameLib.System.call(
|
||||
this,
|
||||
entityManager
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.System.Animation.prototype = Object.create(GameLib.System.prototype);
|
||||
GameLib.System.Animation.prototype.constructor = GameLib.System.Animation;
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.update = function() {
|
||||
|
||||
var objects = this.entityManager.queryComponents([GameLib.D3.Mesh, GameLib.D3.Animation]);
|
||||
|
||||
objects.forEach(function(object) {
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO: PathFollowingComponent Stuff
|
||||
*
|
||||
*
|
||||
* if (this.spline && this.raytraceMesh) {
|
||||
|
||||
this.currentSpeed += this.accelleration * deltaTime * this.direction;
|
||||
if(this.currentSpeed > this.maxSpeed) {
|
||||
this.currentSpeed = this.maxSpeed;
|
||||
}
|
||||
this.grain = (this.currentSpeed / 100.0);
|
||||
|
||||
this.currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.currentPathValue += this.grain;
|
||||
|
||||
if (this.currentPathValue >= 1) {
|
||||
this.currentPathValue = this.currentPathValue - 1;
|
||||
}
|
||||
|
||||
if (this.currentPathValue < 0) {
|
||||
this.currentPathValue = 0.0;
|
||||
}
|
||||
|
||||
this.futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.raycaster.setPosition(
|
||||
this.futurePosition
|
||||
);
|
||||
|
||||
var normal = this.raycaster.getFaceNormal(this.raytraceMesh);
|
||||
|
||||
if (normal) {
|
||||
this.up.x = this.mx(normal.x);
|
||||
this.up.y = this.my(normal.y);
|
||||
this.up.z = this.mz(normal.z);
|
||||
|
||||
this.up.updateInstance();
|
||||
}
|
||||
|
||||
this.rotationMatrix.lookAt(
|
||||
this.currentPosition,
|
||||
this.futurePosition,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.rotationVector.setFromRotationMatrix(this.rotationMatrix);
|
||||
|
||||
/**
|
||||
* Update Position
|
||||
*
|
||||
this.parentEntity.position.x = this.futurePosition.x;// + transformedOffset.x;
|
||||
this.parentEntity.position.y = this.futurePosition.y;// + transformedOffset.y;
|
||||
this.parentEntity.position.z = this.futurePosition.z;// + transformedOffset.z;
|
||||
|
||||
/**
|
||||
* Update Rotation
|
||||
*
|
||||
this.parentEntity.quaternion.x = this.rotationVector.x;
|
||||
this.parentEntity.quaternion.y = this.rotationVector.y;
|
||||
this.parentEntity.quaternion.z = this.rotationVector.z;
|
||||
this.parentEntity.quaternion.w = this.rotationVector.w;
|
||||
|
||||
}
|
||||
|
||||
TODO: lookat component code
|
||||
|
||||
|
||||
if (this.targetEntity && this.parentEntity) {
|
||||
|
||||
this.targetPosition.x = this.targetEntity.position.x + this.targetOffset.x;
|
||||
this.targetPosition.y = this.targetEntity.position.y + this.targetOffset.y;
|
||||
this.targetPosition.z = this.targetEntity.position.z + this.targetOffset.z;
|
||||
|
||||
this.targetPosition.updateInstance();
|
||||
|
||||
this.lookAtMatrix.lookAt(
|
||||
this.parentEntity.position,
|
||||
this.targetPosition,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.currentRotation.setFromRotationMatrix(this.lookAtMatrix);
|
||||
|
||||
var t = deltaTime * this.rotationSpeed;
|
||||
t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
this.currentRotation.slerp(this.currentRotation, t);
|
||||
|
||||
this.parentEntity.quaternion.x = this.currentRotation.x;
|
||||
this.parentEntity.quaternion.y = this.currentRotation.y;
|
||||
this.parentEntity.quaternion.z = this.currentRotation.z;
|
||||
this.parentEntity.quaternion.w = this.currentRotation.w;
|
||||
|
||||
this.parentEntity.quaternion.updateInstance();
|
||||
}
|
||||
|
||||
TODO: entity follow component stuff
|
||||
if (this.parentEntity && this.targetEntity) {
|
||||
|
||||
this.rotated.x = this.targetEntity.quaternion.x;
|
||||
this.rotated.y = this.targetEntity.quaternion.y;
|
||||
this.rotated.z = this.targetEntity.quaternion.z;
|
||||
this.rotated.w = this.targetEntity.quaternion.w;
|
||||
|
||||
this.rotated.updateInstance();
|
||||
|
||||
this.rotatedTargetOffset.x = this.targetOffset.x;
|
||||
this.rotatedTargetOffset.y = this.targetOffset.y;
|
||||
this.rotatedTargetOffset.z = this.targetOffset.z;
|
||||
|
||||
this.rotatedTargetOffset.applyQuaternion(this.rotated);
|
||||
|
||||
this.rotatedTargetOffset.updateInstance();
|
||||
|
||||
this.target.x = this.targetEntity.position.x + this.rotatedTargetOffset.x;
|
||||
this.target.y = this.targetEntity.position.y + this.rotatedTargetOffset.y;
|
||||
this.target.z = this.targetEntity.position.z + this.rotatedTargetOffset.z;
|
||||
|
||||
this.target.updateInstance();
|
||||
|
||||
this.targetToParent.x = this.parentEntity.position.x - this.targetEntity.position.x;
|
||||
this.targetToParent.y = this.parentEntity.position.y - this.targetEntity.position.y;
|
||||
this.targetToParent.z = this.parentEntity.position.z - this.targetEntity.position.z;
|
||||
|
||||
this.targetToParent.normalize();
|
||||
|
||||
this.targetToParent.x *= this.minDistance;
|
||||
this.targetToParent.y *= this.minDistance;
|
||||
this.targetToParent.z *= this.minDistance;
|
||||
|
||||
this.targetToParent.updateInstance();
|
||||
|
||||
this.target.x = this.target.x + this.targetToParent.x;
|
||||
this.target.y = this.target.y + this.targetToParent.y;
|
||||
this.target.z = this.target.z + this.targetToParent.z;
|
||||
|
||||
this.target.updateInstance();
|
||||
|
||||
var t = deltaTime * this.moveSpeed;
|
||||
|
||||
//t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
var lerp = this.parentEntity.position.lerp(this.target, t);
|
||||
|
||||
this.parentEntity.position.x = lerp.x;
|
||||
this.parentEntity.position.y = lerp.y;
|
||||
this.parentEntity.position.z = lerp.z;
|
||||
|
||||
this.parentEntity.position.updateInstance();
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
|
@ -0,0 +1,242 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System.Input = function(
|
||||
entityManager
|
||||
) {
|
||||
GameLib.System.call(
|
||||
this,
|
||||
entityManager
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
|
||||
GameLib.System.Input.prototype.constructor = GameLib.System.Input;
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.update = function() {
|
||||
|
||||
var objects = this.entityManager.queryComponents([GameLib.D3.FlyControls, GameLib.D3.Input]);
|
||||
|
||||
objects.forEach(function(object) {
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO : flycontrols stuff
|
||||
* this.mouseUpCallback = this.onMouseUp.bind(this);
|
||||
this.mouseDownCallback = this.onMouseDown.bind(this);
|
||||
this.mouseMoveCallback = this.onMouseMove.bind(this);
|
||||
this.mouseWheelCallback = this.onMouseWheel.bind(this);
|
||||
this.keyDownCallback = this.onKeyDown.bind(this);
|
||||
this.keyUpCallback = this.onKeyUp.bind(this);
|
||||
|
||||
this.camera = camera;
|
||||
|
||||
this.canvas.addEventListener('keydown', this.keyDownCallback, false);
|
||||
this.canvas.addEventListener('keyup', this.keyUpCallback, false);
|
||||
this.canvas.addEventListener('mousedown', this.mouseDownCallback, false);
|
||||
this.canvas.addEventListener('mouseup', this.mouseUpCallback, false);
|
||||
this.canvas.addEventListener('mousewheel', this.mouseWheelCallback, false);
|
||||
|
||||
this.havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
||||
this.element = document.body;
|
||||
|
||||
if (this.havePointerLock) {
|
||||
this.element.requestPointerLock = this.element.requestPointerLock || this.element.mozRequestPointerLock || this.element.webkitRequestPointerLock;
|
||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Go forward / backward on mouse wheel
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onMouseWheel = function(event) {
|
||||
this.moveForward = true;
|
||||
this.applyTranslation(event.wheelDelta * 0.001);
|
||||
event.preventDefault();
|
||||
this.moveForward = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start rotating the camera on mouse middle button down
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onMouseDown = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = true;
|
||||
this.canvas.addEventListener('mousemove', this.mouseMoveCallback, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop rotating on middle mouse button down
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onMouseUp = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = false;
|
||||
this.canvas.removeEventListener('mousemove', this.mouseMoveCallback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current yaw and pitch to camera
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.applyRotation = function() {
|
||||
this.camera.rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current position to camera
|
||||
* @param deltaTime
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.applyTranslation = function(deltaTime) {
|
||||
var direction = new this.THREE.Vector3(0, 0, -1);
|
||||
var rotation = new this.THREE.Euler(0, 0, 0, "YXZ");
|
||||
rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
|
||||
direction = direction.applyEuler(rotation);
|
||||
|
||||
var forward = direction.normalize();
|
||||
var right = forward.cross(new this.THREE.Vector3(0, 1, 0));
|
||||
|
||||
if(this.moveForward) {
|
||||
|
||||
this.camera.position.x += forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += forward.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveBackward) {
|
||||
|
||||
this.camera.position.x -= forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= forward.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveLeft) {
|
||||
|
||||
this.camera.position.x -= right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= right.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveRight) {
|
||||
|
||||
this.camera.position.x += right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += right.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveUp) {
|
||||
|
||||
this.camera.position.y += (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveDown) {
|
||||
|
||||
this.camera.position.y -= (deltaTime * this.flySpeed);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This update function should be called from the animation function in order to apply the 'frame rate independent'
|
||||
* movement to the camera
|
||||
* @param deltaTime
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.update = function(deltaTime) {
|
||||
this.applyRotation();
|
||||
this.applyTranslation(deltaTime);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate on mouse move
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onMouseMove = function ( event ) {
|
||||
if (this.canRotate) {
|
||||
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||
|
||||
this.yaw -= movementX * 0.002;
|
||||
this.pitch -= movementY * 0.002;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onKeyDown = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 87: // w
|
||||
this.moveForward = true;
|
||||
break;
|
||||
|
||||
case 65: // a
|
||||
this.moveLeft = true;
|
||||
break;
|
||||
|
||||
case 83: // s
|
||||
this.moveBackward = true;
|
||||
break;
|
||||
|
||||
case 68: // d
|
||||
this.moveRight = true;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = true;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*
|
||||
GameLib.D3.FlyControls.prototype.onKeyUp = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: // up
|
||||
case 87: // w
|
||||
this.moveForward = false;
|
||||
break;
|
||||
|
||||
case 37: // left
|
||||
case 65: // a
|
||||
this.moveLeft = false;
|
||||
break;
|
||||
|
||||
case 40: // down
|
||||
case 83: // s
|
||||
this.moveBackward = false;
|
||||
break;
|
||||
|
||||
case 39: // right
|
||||
case 68: // d
|
||||
this.moveRight = false;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = false;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = false;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System.Render = function(
|
||||
entityManager
|
||||
) {
|
||||
GameLib.System.call(
|
||||
this,
|
||||
entityManager
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
|
||||
GameLib.System.Render.prototype.constructor = GameLib.System.Render;
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
GameLib.System.prototype.update = function() {
|
||||
|
||||
var objects = this.entityManager.queryComponents([GameLib.D3.Camera]);
|
||||
|
||||
objects.forEach(function(object) {
|
||||
|
||||
//TODO camera component stuff
|
||||
object.quaternion.x = this.parentEntity.quaternion.x;
|
||||
object.quaternion.y = this.parentEntity.quaternion.y;
|
||||
object.quaternion.z = this.parentEntity.quaternion.z;
|
||||
object.quaternion.w = this.parentEntity.quaternion.w;
|
||||
|
||||
object.position.x = this.parentEntity.position.x;
|
||||
object.position.y = this.parentEntity.position.y;
|
||||
object.position.z = this.parentEntity.position.z;
|
||||
|
||||
object.updateInstance();
|
||||
|
||||
//TODO scene component stuff
|
||||
renderer.render(this.instance, this.cameras[this.activeCameraIndex].instance);
|
||||
});
|
||||
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
GameLib.D3.Utils = function() {};
|
||||
GameLib.D3.Utils.Extend = function(
|
||||
GameLib.Utils = function() {};
|
||||
GameLib.Utils.Extend = function(
|
||||
child, // child class
|
||||
parent // parent class
|
||||
) {
|
||||
|
@ -10,7 +10,7 @@ GameLib.D3.Utils.Extend = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Utils.UndefinedOrNull = function (
|
||||
GameLib.Utils.UndefinedOrNull = function (
|
||||
variable
|
||||
) {
|
||||
return typeof variable == 'undefined' || variable == null;
|
||||
|
@ -22,11 +22,11 @@ GameLib.D3.Utils.UndefinedOrNull = function (
|
|||
* @returns {null}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Utils.IdOrNull = function (object) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(object)) {
|
||||
GameLib.Utils.IdOrNull = function (object) {
|
||||
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||
return null;
|
||||
} else {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(object.id)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(object.id)) {
|
||||
console.warn('saving an object reference with no ID : ', object);
|
||||
return null;
|
||||
}
|
||||
|
@ -40,14 +40,14 @@ GameLib.D3.Utils.IdOrNull = function (object) {
|
|||
* @returns []
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Utils.IdArrayOrEmptyArray = function (array) {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(array)) {
|
||||
GameLib.Utils.IdArrayOrEmptyArray = function (array) {
|
||||
if (GameLib.Utils.UndefinedOrNull(array)) {
|
||||
return [];
|
||||
} else {
|
||||
|
||||
return array.map(function(item) {
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(item.id)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(item.id)) {
|
||||
throw new Error('No ID found while trying to store IDs to array');
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ GameLib.D3.Utils.IdArrayOrEmptyArray = function (array) {
|
|||
* @param id
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Utils.Link = function(propertyString, idToObject, parentObject, id) {
|
||||
GameLib.Utils.Link = function(propertyString, idToObject, parentObject, id) {
|
||||
|
||||
if (!GameLib.D3.Utils.UndefinedOrNull(parentObject[propertyString])) {
|
||||
if (!GameLib.Utils.UndefinedOrNull(parentObject[propertyString])) {
|
||||
|
||||
if (!idToObject.hasOwnProperty(id)) {
|
||||
console.warn('Linking failed for object:' + parentObject.name);
|
||||
|
@ -76,7 +76,7 @@ GameLib.D3.Utils.Link = function(propertyString, idToObject, parentObject, id) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Utils.Raycast = function (
|
||||
GameLib.Utils.Raycast = function (
|
||||
from,
|
||||
to,
|
||||
options,
|
||||
|
@ -90,11 +90,11 @@ GameLib.D3.Utils.Raycast = function (
|
|||
* @returns {string}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Utils.RandomId = function() {
|
||||
GameLib.Utils.RandomId = function() {
|
||||
return Math.random().toString(36).substr(2, 10);
|
||||
};
|
||||
|
||||
GameLib.D3.Utils.InvertWindingOrder = function(triangles) {
|
||||
GameLib.Utils.InvertWindingOrder = function(triangles) {
|
||||
|
||||
for (var i = 0; i < triangles.length; i++) {
|
||||
var v1 = triangles[i].v1;
|
||||
|
@ -112,12 +112,12 @@ GameLib.D3.Utils.InvertWindingOrder = function(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) {
|
||||
GameLib.Utils.ResetWindingOrder = function(faces, vertices) {
|
||||
|
||||
var vertexList = new GameLib.D3.API.Vector3.Points();
|
||||
var vertexList = new GameLib.API.Vector3.Points();
|
||||
|
||||
for (var v = 0; v < vertices.length; v++) {
|
||||
vertexList.add(new GameLib.D3.API.Vector3(
|
||||
vertexList.add(new GameLib.API.Vector3(
|
||||
vertices[v].position.x,
|
||||
vertices[v].position.y,
|
||||
vertices[v].position.z
|
||||
|
@ -153,7 +153,7 @@ GameLib.D3.Utils.ResetWindingOrder = function(faces, vertices) {
|
|||
|
||||
for (var i = 0; i < triangles.length; i++) {
|
||||
if (
|
||||
GameLib.D3.API.Vector3.clockwise(
|
||||
GameLib.API.Vector3.clockwise(
|
||||
vertices[triangles[i].v0].position,
|
||||
vertices[triangles[i].v1].position,
|
||||
vertices[triangles[i].v2].position,
|
||||
|
@ -194,10 +194,10 @@ GameLib.D3.Utils.ResetWindingOrder = function(faces, vertices) {
|
|||
* 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
|
||||
* @param orientationEdge GameLib.API.Vector2
|
||||
* @returns {Array}
|
||||
*/
|
||||
GameLib.D3.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
||||
GameLib.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
||||
|
||||
/**
|
||||
* Checks if a TriangleFace belonging to a TriangleEdge has already been processed
|
||||
|
@ -218,7 +218,7 @@ GameLib.D3.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
|||
|
||||
/**
|
||||
* Returns a neighbouring triangle on a specific edge - preserving the edge orientation
|
||||
* @param edge GameLib.D3.API.Vector2
|
||||
* @param edge GameLib.API.Vector2
|
||||
* @param faces GameLib.D3.TriangleFace[]
|
||||
* @param currentTriangle
|
||||
* @returns {*}
|
||||
|
@ -304,15 +304,15 @@ GameLib.D3.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
|||
processed.push(triangleEdge);
|
||||
|
||||
var edges = [
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
triangleEdge.triangle.v0,
|
||||
triangleEdge.triangle.v1
|
||||
),
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
triangleEdge.triangle.v1,
|
||||
triangleEdge.triangle.v2
|
||||
),
|
||||
new GameLib.D3.API.Vector2(
|
||||
new GameLib.API.Vector2(
|
||||
triangleEdge.triangle.v2,
|
||||
triangleEdge.triangle.v0
|
||||
)
|
||||
|
@ -355,7 +355,7 @@ GameLib.D3.Utils.FixWindingOrder = function(faces, orientationEdge) {
|
|||
* @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) {
|
||||
GameLib.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);
|
||||
|
@ -363,10 +363,10 @@ GameLib.D3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
|
|||
|
||||
var vertices = [];
|
||||
|
||||
var points = new GameLib.D3.API.Quaternion.Points();
|
||||
var points = new GameLib.API.Quaternion.Points();
|
||||
|
||||
for (var i = 0; i < verticesFlat.length; i += 3) {
|
||||
points.add(new GameLib.D3.API.Vector3(
|
||||
points.add(new GameLib.API.Vector3(
|
||||
verticesFlat[i],
|
||||
verticesFlat[i + 1],
|
||||
verticesFlat[i + 2]
|
||||
|
@ -391,7 +391,7 @@ GameLib.D3.Utils.FixPolyZPlane = function(verticesFlat, grain) {
|
|||
return vertices;
|
||||
};
|
||||
|
||||
GameLib.D3.Utils.MovingAverage = function(period) {
|
||||
GameLib.Utils.MovingAverage = function(period) {
|
||||
var nums = [];
|
||||
return function(num) {
|
||||
nums.push(num);
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* Runtime vector2 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiVector2 GameLib.D3.API.Vector2
|
||||
* @param apiVector2 GameLib.API.Vector2
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2, grain) {
|
||||
GameLib.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2, grain) {
|
||||
|
||||
for (var property in apiVector2) {
|
||||
if (apiVector2.hasOwnProperty(property)) {
|
||||
|
@ -14,7 +14,7 @@ GameLib.D3.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2,
|
|||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Vector2, GameLib.D3.API.Vector2);
|
||||
GameLib.Utils.Extend(GameLib.Vector2, GameLib.API.Vector2);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
|
@ -22,7 +22,7 @@ GameLib.D3.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2,
|
|||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
@ -35,7 +35,7 @@ GameLib.D3.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2,
|
|||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Vector2.prototype.createInstance = function(update) {
|
||||
GameLib.Vector2.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
|
@ -53,7 +53,7 @@ GameLib.D3.Vector2.prototype.createInstance = function(update) {
|
|||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Vector2.prototype.updateInstance = function() {
|
||||
GameLib.Vector2.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
|
@ -64,110 +64,110 @@ GameLib.D3.Vector2.prototype.updateInstance = function() {
|
|||
|
||||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
* @returns {GameLib.D3.API.Vector2}
|
||||
* @returns {GameLib.API.Vector2}
|
||||
*/
|
||||
GameLib.D3.Vector2.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.API.Vector2(
|
||||
GameLib.Vector2.prototype.toApiVector = function() {
|
||||
return new GameLib.API.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.copy = function (v) {
|
||||
if (!GameLib.D3.Utils.UndefinedOrNull(v)) {
|
||||
GameLib.Vector2.prototype.copy = function (v) {
|
||||
if (!GameLib.Utils.UndefinedOrNull(v)) {
|
||||
this.x = v.x;
|
||||
this.y = v.y;
|
||||
return this;
|
||||
} else {
|
||||
return new GameLib.D3.Vector2(
|
||||
return new GameLib.Vector2(
|
||||
this.x,
|
||||
this.y
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.equals = function(v) {
|
||||
GameLib.Vector2.prototype.equals = function(v) {
|
||||
return (((this.x == v.x) &&
|
||||
(this.y == v.y)) ||
|
||||
((this.y == v.x) &&
|
||||
(this.x == v.y)));
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.add = function(v) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.add = function(v) {
|
||||
return new GameLib.Vector2(
|
||||
this.x + v.x,
|
||||
this.y + v.y
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.subtract = function(v) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.subtract = function(v) {
|
||||
return new GameLib.Vector2(
|
||||
this.x - v.x,
|
||||
this.y - v.y
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.multiply = function(v) {
|
||||
if (v instanceof GameLib.D3.Vector2) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.multiply = function(v) {
|
||||
if (v instanceof GameLib.Vector2) {
|
||||
return new GameLib.Vector2(
|
||||
this.x * v.x,
|
||||
this.y * v.y
|
||||
);
|
||||
} else if (isNumber(v)) {
|
||||
return new GameLib.D3.Vector2(
|
||||
return new GameLib.Vector2(
|
||||
this.x * v,
|
||||
this.y * v
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.divide = function(v) {
|
||||
if (v instanceof GameLib.D3.Vector2) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.divide = function(v) {
|
||||
if (v instanceof GameLib.Vector2) {
|
||||
return new GameLib.Vector2(
|
||||
this.x * (1.0 / v.x),
|
||||
this.y * (1.0 / v.y)
|
||||
);
|
||||
} else if (isNumber(v)) {
|
||||
var invS = 1.0 / v;
|
||||
return new GameLib.D3.Vector2(
|
||||
return new GameLib.Vector2(
|
||||
this.x * invS,
|
||||
this.y * invS
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.set = function(x, y) {
|
||||
GameLib.Vector2.prototype.set = function(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.clamp = function(min, max) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.clamp = function(min, max) {
|
||||
return new GameLib.Vector2(
|
||||
Math.max(min.x, Math.min(max.x, this.x)),
|
||||
Math.max(min.y, Math.min(max.y, this.y))
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.length = function() {
|
||||
GameLib.Vector2.prototype.length = function() {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.dot = function(v) {
|
||||
GameLib.Vector2.prototype.dot = function(v) {
|
||||
return this.x * v.x + this.y * v.y;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.normalize = function() {
|
||||
GameLib.Vector2.prototype.normalize = function() {
|
||||
return this.multiply(1.0 / this.length());
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.angle = function() {
|
||||
GameLib.Vector2.prototype.angle = function() {
|
||||
var angle = Math.atan2(this.y, this.x);
|
||||
if ( angle < 0 ) angle += 2 * Math.PI;
|
||||
return angle;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector2.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.D3.Vector2(
|
||||
GameLib.Vector2.prototype.lerp = function ( v, alpha ) {
|
||||
return new GameLib.Vector2(
|
||||
this.x + ( v.x - this.x ) * alpha,
|
||||
this.y + ( v.y - this.y ) * alpha
|
||||
);
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
* Runtime apiVector3 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiVector3 GameLib.D3.API.Vector3
|
||||
* @param apiVector3 GameLib.API.Vector3
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3, grain) {
|
||||
GameLib.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3, grain) {
|
||||
|
||||
for (var property in apiVector3) {
|
||||
if (apiVector3.hasOwnProperty(property)) {
|
||||
|
@ -14,7 +14,7 @@ GameLib.D3.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3,
|
|||
}
|
||||
}
|
||||
|
||||
GameLib.D3.Utils.Extend(GameLib.D3.Vector3, GameLib.D3.API.Vector3);
|
||||
GameLib.Utils.Extend(GameLib.Vector3, GameLib.API.Vector3);
|
||||
|
||||
this.graphics = graphics;
|
||||
|
||||
|
@ -22,7 +22,7 @@ GameLib.D3.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3,
|
|||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
@ -35,7 +35,7 @@ GameLib.D3.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3,
|
|||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Vector3.prototype.createInstance = function(update) {
|
||||
GameLib.Vector3.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
|
@ -54,7 +54,7 @@ GameLib.D3.Vector3.prototype.createInstance = function(update) {
|
|||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Vector3.prototype.updateInstance = function() {
|
||||
GameLib.Vector3.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
|
@ -66,8 +66,8 @@ GameLib.D3.Vector3.prototype.updateInstance = function() {
|
|||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
*/
|
||||
GameLib.D3.Vector3.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.API.Vector3(
|
||||
GameLib.Vector3.prototype.toApiVector = function() {
|
||||
return new GameLib.API.Vector3(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
* Runtime apiVector4 for updating instance objects
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param parentObject GameLib.D3.*
|
||||
* @param apiVector4 GameLib.D3.API.Vector4
|
||||
* @param apiVector4 GameLib.API.Vector4
|
||||
* @param grain Number
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4, grain) {
|
||||
GameLib.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4, grain) {
|
||||
|
||||
GameLib.D3.API.Vector4.call(
|
||||
GameLib.API.Vector4.call(
|
||||
this,
|
||||
apiVector4.x,
|
||||
apiVector4.y,
|
||||
|
@ -22,7 +22,7 @@ GameLib.D3.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4,
|
|||
|
||||
this.parentObject = parentObject;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(grain)) {
|
||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.001;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
@ -30,15 +30,15 @@ GameLib.D3.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4,
|
|||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype = Object.create(GameLib.D3.API.Vector4.prototype);
|
||||
GameLib.D3.Vector4.prototype.constructor = GameLib.D3.Vector4;
|
||||
GameLib.Vector4.prototype = Object.create(GameLib.API.Vector4.prototype);
|
||||
GameLib.Vector4.prototype.constructor = GameLib.Vector4;
|
||||
|
||||
/**
|
||||
* Creates an instance vector3
|
||||
* @param update
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Vector4.prototype.createInstance = function(update) {
|
||||
GameLib.Vector4.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
|
@ -58,7 +58,7 @@ GameLib.D3.Vector4.prototype.createInstance = function(update) {
|
|||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
GameLib.D3.Vector4.prototype.updateInstance = function() {
|
||||
GameLib.Vector4.prototype.updateInstance = function() {
|
||||
|
||||
this.createInstance(true);
|
||||
|
||||
|
@ -70,8 +70,8 @@ GameLib.D3.Vector4.prototype.updateInstance = function() {
|
|||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
*/
|
||||
GameLib.D3.Vector4.prototype.toApiVector = function() {
|
||||
return new GameLib.D3.API.Vector4(
|
||||
GameLib.Vector4.prototype.toApiVector = function() {
|
||||
return new GameLib.API.Vector4(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
|
|
Loading…
Reference in New Issue