start writing tests
parent
48c44abf93
commit
d9c4cee85f
File diff suppressed because one or more lines are too long
|
@ -1328,10 +1328,11 @@ GameLib.D3.Material.TYPE_SPRITE = "SpriteMaterial";
|
|||
GameLib.D3.Material.TYPE_MULTI_MATERIAL= "MultiMaterial";
|
||||
|
||||
/**
|
||||
* Creates a this.THREE.Material from a GameLib.D3.Material
|
||||
* Creates a THREE.Material from a GameLib.D3.Material
|
||||
* @param blenderMaterial GameLib.D3.Material
|
||||
* @param THREE THREE.js
|
||||
*/
|
||||
GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
||||
GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial, THREE) {
|
||||
|
||||
var defer = this.Q.defer();
|
||||
|
||||
|
@ -1341,7 +1342,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
|
||||
if (blenderMaterial.materialType == GameLib.D3.Material.TYPE_MESH_STANDARD) {
|
||||
|
||||
threeMaterial = new this.THREE.MeshStandardMaterial({
|
||||
threeMaterial = new THREE.MeshStandardMaterial({
|
||||
name: blenderMaterial.name,
|
||||
opacity: blenderMaterial.opacity,
|
||||
transparent: blenderMaterial.transparent,
|
||||
|
@ -1361,7 +1362,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
overdraw: blenderMaterial.overdraw,
|
||||
visible: blenderMaterial.visible,
|
||||
side: blenderMaterial.side,
|
||||
color: new this.THREE.Color(
|
||||
color: new THREE.Color(
|
||||
blenderMaterial.color.r,
|
||||
blenderMaterial.color.g,
|
||||
blenderMaterial.color.b
|
||||
|
@ -1370,7 +1371,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
metalness: blenderMaterial.metalness,
|
||||
lightMapIntensity: blenderMaterial.lightMapIntensity,
|
||||
aoMapIntensity: blenderMaterial.aoMapIntensity,
|
||||
emissive: new this.THREE.Color(
|
||||
emissive: new THREE.Color(
|
||||
blenderMaterial.emissive.r,
|
||||
blenderMaterial.emissive.g,
|
||||
blenderMaterial.emissive.b
|
||||
|
@ -1407,7 +1408,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
);
|
||||
} else if (blenderMaterial.materialType == GameLib.D3.Material.TYPE_MESH_PHONG) {
|
||||
|
||||
threeMaterial = new this.THREE.MeshPhongMaterial({
|
||||
threeMaterial = new THREE.MeshPhongMaterial({
|
||||
name: blenderMaterial.name,
|
||||
opacity: blenderMaterial.opacity,
|
||||
transparent: blenderMaterial.transparent,
|
||||
|
@ -1427,12 +1428,12 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
overdraw: blenderMaterial.overdraw,
|
||||
visible: blenderMaterial.visible,
|
||||
side: blenderMaterial.side,
|
||||
color: new this.THREE.Color(
|
||||
color: new THREE.Color(
|
||||
blenderMaterial.color.r,
|
||||
blenderMaterial.color.g,
|
||||
blenderMaterial.color.b
|
||||
),
|
||||
specular: new this.THREE.Color(
|
||||
specular: new THREE.Color(
|
||||
blenderMaterial.specular.r,
|
||||
blenderMaterial.specular.g,
|
||||
blenderMaterial.specular.b
|
||||
|
@ -1440,7 +1441,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
shininess: blenderMaterial.shininess,
|
||||
lightMapIntensity: blenderMaterial.lightMapIntensity,
|
||||
aoMapIntensity: blenderMaterial.aoMapIntensity,
|
||||
emissive: new this.THREE.Color(
|
||||
emissive: new THREE.Color(
|
||||
blenderMaterial.emissive.r,
|
||||
blenderMaterial.emissive.g,
|
||||
blenderMaterial.emissive.b
|
||||
|
@ -2321,22 +2322,35 @@ GameLib.D3.PolyVertex.prototype.clone = function() {
|
|||
* TODO: body + wheels[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RaycastVehicle = function(
|
||||
GameLib.D3.RaycastVehicle = function(
|
||||
) {
|
||||
this.vehicleObject = null;
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelInfos;
|
||||
};
|
||||
|
||||
/**
|
||||
* Physics Rigid Body Vehicle Superset
|
||||
* TODO: body + wheels[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RigidVehicle = function(
|
||||
GameLib.D3.RigidVehicle = function(
|
||||
) {
|
||||
this.vehicleObject = null;
|
||||
};
|
||||
|
||||
GameLib.D3.RigidVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelBodies;
|
||||
};
|
||||
|
||||
/**
|
||||
* RigidBody Superset
|
||||
* @param mass
|
||||
|
@ -2357,7 +2371,7 @@ GameLib.D3.Physics.RigidVehicle = function(
|
|||
* @returns {GameLib.D3.Physics.RigidBody}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RigidBody = function(
|
||||
GameLib.D3.RigidBody = function(
|
||||
mass,
|
||||
friction,
|
||||
position,
|
||||
|
@ -2398,7 +2412,7 @@ GameLib.D3.Physics.RigidBody = function(
|
|||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Physics.World.RigidBody.prototype.createRigidBodyInstance = function() {
|
||||
GameLib.D3.RigidBody.prototype.createRigidBodyInstance = function() {
|
||||
|
||||
var rigidBody = null;
|
||||
|
||||
|
@ -3217,7 +3231,6 @@ GameLib.D3.Physics.GS_SOLVER = 0x2;
|
|||
/**
|
||||
* Texture Superset
|
||||
* @param id
|
||||
* @param path
|
||||
* @param name
|
||||
* @param image
|
||||
* @param wrapS
|
||||
|
@ -3887,6 +3900,105 @@ GameLib.D3.Vector3.prototype.normalize = function () {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4 = function(x, y, z, w) {
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
this.w = 0;
|
||||
|
||||
if (x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
if (y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
if (z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
if (w) {
|
||||
this.w = w;
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.copy = function () {
|
||||
return new GameLib.D3.Vector4(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.multiply = function (s) {
|
||||
if (s instanceof GameLib.D3.Vector3) {
|
||||
this.x *= s.x;
|
||||
this.y *= s.y;
|
||||
this.z *= s.z;
|
||||
} else if (s instanceof GameLib.D3.Matrix4) {
|
||||
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w * this.w;
|
||||
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w * this.w;
|
||||
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w * this.w;
|
||||
var w = s.rows[3].x * this.x + s.rows[3].y * this.y + s.rows[3].z * this.z + s.rows[3].w * this.w;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
} else {
|
||||
console.log("functionality not implemented - please do this");
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.prototype.normalize = function () {
|
||||
|
||||
// note - leave w untouched
|
||||
var EPSILON = 0.000001;
|
||||
|
||||
var v2 = this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
|
||||
if (v2 < EPSILON) {
|
||||
return this; //do nothing for zero vector
|
||||
}
|
||||
|
||||
var invLength = 1 / Math.sqrt(v2);
|
||||
|
||||
this.x *= invLength;
|
||||
this.y *= invLength;
|
||||
this.z *= invLength;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.subtract = function (v) {
|
||||
|
||||
if (v instanceof GameLib.D3.Vector3) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
}
|
||||
|
||||
if (v instanceof GameLib.D3.Vector4) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
this.w -= v.w;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points = function () {
|
||||
this.vectors = [];
|
||||
};
|
||||
|
@ -4111,105 +4223,6 @@ GameLib.D3.Vector4.Points.prototype.toOrigin = function () {
|
|||
this.vectors[i].translate(distanceFromOrigin);
|
||||
}
|
||||
};
|
||||
GameLib.D3.Vector4 = function(x, y, z, w) {
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.z = 0;
|
||||
this.w = 0;
|
||||
|
||||
if (x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
if (y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
if (z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
if (w) {
|
||||
this.w = w;
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.translate = function (v) {
|
||||
this.x += v.x;
|
||||
this.y += v.y;
|
||||
this.z += v.z;
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.copy = function () {
|
||||
return new GameLib.D3.Vector4(
|
||||
this.x,
|
||||
this.y,
|
||||
this.z,
|
||||
this.w
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.multiply = function (s) {
|
||||
if (s instanceof GameLib.D3.Vector3) {
|
||||
this.x *= s.x;
|
||||
this.y *= s.y;
|
||||
this.z *= s.z;
|
||||
} else if (s instanceof GameLib.D3.Matrix4) {
|
||||
var x = s.rows[0].x * this.x + s.rows[0].y * this.y + s.rows[0].z * this.z + s.rows[0].w * this.w;
|
||||
var y = s.rows[1].x * this.x + s.rows[1].y * this.y + s.rows[1].z * this.z + s.rows[1].w * this.w;
|
||||
var z = s.rows[2].x * this.x + s.rows[2].y * this.y + s.rows[2].z * this.z + s.rows[2].w * this.w;
|
||||
var w = s.rows[3].x * this.x + s.rows[3].y * this.y + s.rows[3].z * this.z + s.rows[3].w * this.w;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
} else {
|
||||
console.log("functionality not implemented - please do this");
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.prototype.normalize = function () {
|
||||
|
||||
// note - leave w untouched
|
||||
var EPSILON = 0.000001;
|
||||
|
||||
var v2 = this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
|
||||
if (v2 < EPSILON) {
|
||||
return this; //do nothing for zero vector
|
||||
}
|
||||
|
||||
var invLength = 1 / Math.sqrt(v2);
|
||||
|
||||
this.x *= invLength;
|
||||
this.y *= invLength;
|
||||
this.z *= invLength;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.prototype.subtract = function (v) {
|
||||
|
||||
if (v instanceof GameLib.D3.Vector3) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
}
|
||||
|
||||
if (v instanceof GameLib.D3.Vector4) {
|
||||
this.x -= v.x;
|
||||
this.y -= v.y;
|
||||
this.z -= v.z;
|
||||
this.w -= v.w;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The normal gets assigned when the face calculates its normal
|
||||
|
@ -4331,7 +4344,7 @@ GameLib.D3.World.prototype.createWorldInstance = function() {
|
|||
return customWorld;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddShape = function(
|
||||
GameLib.D3.World.prototype.AddShape = function(
|
||||
shape, // d3.physics.shape
|
||||
rigidBody,
|
||||
offset, // vec3
|
||||
|
@ -4359,11 +4372,11 @@ GameLib.D3.Physics.World.prototype.AddShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.Wheel = function() {
|
||||
GameLib.D3.World.prototype.Wheel = function() {
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function(
|
||||
GameLib.D3.World.prototype.CreateRigidVehicle = function(
|
||||
chassisBody // Physics.RigidBody
|
||||
) {
|
||||
var rigidVehicle = new GameLib.D3.Physics.RigidVehicle();
|
||||
|
@ -4377,7 +4390,7 @@ GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateRaycastVehicle = function(
|
||||
GameLib.D3.World.prototype.CreateRaycastVehicle = function(
|
||||
chassisBody // Physics.RigidBody
|
||||
) {
|
||||
var raycastVehicle = new GameLib.D3.Physics.RaycastVehicle();
|
||||
|
@ -4391,7 +4404,7 @@ GameLib.D3.Physics.World.prototype.CreateRaycastVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle = function(
|
||||
GameLib.D3.World.prototype.AddWheelToRigidVehicle = function(
|
||||
vehicle,
|
||||
rigidBody,
|
||||
position,
|
||||
|
@ -4408,7 +4421,7 @@ GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle = function (
|
||||
GameLib.D3.World.prototype.AddWheelToRaycastVehicle = function (
|
||||
vehicle, // physics.raycastvehicle
|
||||
options // cannon options
|
||||
) {
|
||||
|
@ -4419,22 +4432,9 @@ GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle = function (
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.RigidVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelBodies;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.RaycastVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelInfos;
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateTriMeshShape = function(
|
||||
GameLib.D3.World.prototype.CreateTriMeshShape = function(
|
||||
vertices, // flat list of floats
|
||||
indices // flat list of floats
|
||||
) {
|
||||
|
@ -4443,7 +4443,7 @@ GameLib.D3.Physics.World.prototype.CreateTriMeshShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateSphereShape = function (
|
||||
GameLib.D3.World.prototype.CreateSphereShape = function (
|
||||
radius
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -4451,7 +4451,7 @@ GameLib.D3.Physics.World.prototype.CreateSphereShape = function (
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateBoxShape = function(
|
||||
GameLib.D3.World.prototype.CreateBoxShape = function(
|
||||
halfExtensions // vec3
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -4459,7 +4459,7 @@ GameLib.D3.Physics.World.prototype.CreateBoxShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateCylinderShape = function(
|
||||
GameLib.D3.World.prototype.CreateCylinderShape = function(
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
|
@ -4470,7 +4470,7 @@ GameLib.D3.Physics.World.prototype.CreateCylinderShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddRigidBody = function(
|
||||
GameLib.D3.World.prototype.AddRigidBody = function(
|
||||
rigidBody // Physics.RigidBody
|
||||
) {
|
||||
if(this.physics.engineType === GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -4478,7 +4478,7 @@ GameLib.D3.Physics.World.prototype.AddRigidBody = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddVehicle = function(
|
||||
GameLib.D3.World.prototype.AddVehicle = function(
|
||||
vehicle // note: physics.vehicle
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -4486,7 +4486,7 @@ GameLib.D3.Physics.World.prototype.AddVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.Step = function(
|
||||
GameLib.D3.World.prototype.Step = function(
|
||||
timeStep
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -4512,7 +4512,7 @@ GameLib.D3.Physics.World.prototype.Step = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GetIndexedVertices = function(
|
||||
GameLib.D3.World.prototype.GetIndexedVertices = function(
|
||||
triangleMeshShape
|
||||
) {
|
||||
|
||||
|
@ -4530,7 +4530,7 @@ GameLib.D3.Physics.World.prototype.GetIndexedVertices = function(
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GenerateWireframeViewMesh = function(
|
||||
GameLib.D3.World.prototype.GenerateWireframeViewMesh = function(
|
||||
triangleMeshShape,
|
||||
normalLength,
|
||||
scale,
|
||||
|
@ -4589,7 +4589,7 @@ GameLib.D3.Physics.World.prototype.GenerateWireframeViewMesh = function(
|
|||
return wireframeTHREEMesh;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GenerateTriangleCollisionMesh = function(
|
||||
GameLib.D3.World.prototype.GenerateTriangleCollisionMesh = function(
|
||||
threeMesh,
|
||||
mass, // default = 0
|
||||
friction, // default = 10
|
||||
|
|
36
gulpfile.js
36
gulpfile.js
|
@ -2,6 +2,9 @@ var gulp = require('gulp');
|
|||
var concat = require('gulp-concat');
|
||||
var sort = require('gulp-sort');
|
||||
var minify = require('gulp-minify');
|
||||
var plumber = require('gulp-plumber');
|
||||
var istanbul = require('gulp-istanbul');
|
||||
var mocha = require('gulp-mocha');
|
||||
|
||||
gulp.task(
|
||||
'build',
|
||||
|
@ -19,6 +22,39 @@ gulp.task(
|
|||
}
|
||||
);
|
||||
|
||||
gulp.task('test-prepare', function(){
|
||||
return gulp.src(['./build/game-lib.js'])
|
||||
.pipe(plumber())
|
||||
.pipe(istanbul())
|
||||
.pipe(istanbul.hookRequire())
|
||||
.on('end', function(){
|
||||
console.log('prepared the game lib for code coverage');
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task(
|
||||
'test',
|
||||
['build', 'test-prepare'],
|
||||
function() {
|
||||
gulp.src('./test/test.*.js')
|
||||
.pipe(sort())
|
||||
.pipe(plumber())
|
||||
.pipe(mocha({reporter: 'spec'}))
|
||||
.pipe(istanbul.writeReports())
|
||||
.pipe(istanbul.enforceThresholds({thresholds:{global:90}}))
|
||||
.on('error',
|
||||
function(error) {
|
||||
console.log('plugin error occurred' + error);
|
||||
}
|
||||
)
|
||||
.on('end',
|
||||
function() {
|
||||
console.log('test task ended')
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
gulp.task(
|
||||
'default',
|
||||
['build'],
|
||||
|
|
10
package.json
10
package.json
|
@ -9,5 +9,13 @@
|
|||
"gulp-sort": "^2.0.0"
|
||||
},
|
||||
"repository": "https://github.com/ToywheelDev/game-lib.git",
|
||||
"license": "UNLICENSED"
|
||||
"license": "UNLICENSED",
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"gulp-istanbul": "^1.1.1",
|
||||
"gulp-mocha": "^3.0.1",
|
||||
"gulp-plumber": "^1.1.0",
|
||||
"sinon": "^1.17.6",
|
||||
"sinon-chai": "^2.8.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -507,10 +507,11 @@ GameLib.D3.Material.TYPE_SPRITE = "SpriteMaterial";
|
|||
GameLib.D3.Material.TYPE_MULTI_MATERIAL= "MultiMaterial";
|
||||
|
||||
/**
|
||||
* Creates a this.THREE.Material from a GameLib.D3.Material
|
||||
* Creates a THREE.Material from a GameLib.D3.Material
|
||||
* @param blenderMaterial GameLib.D3.Material
|
||||
* @param THREE THREE.js
|
||||
*/
|
||||
GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
||||
GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial, THREE) {
|
||||
|
||||
var defer = this.Q.defer();
|
||||
|
||||
|
@ -520,7 +521,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
|
||||
if (blenderMaterial.materialType == GameLib.D3.Material.TYPE_MESH_STANDARD) {
|
||||
|
||||
threeMaterial = new this.THREE.MeshStandardMaterial({
|
||||
threeMaterial = new THREE.MeshStandardMaterial({
|
||||
name: blenderMaterial.name,
|
||||
opacity: blenderMaterial.opacity,
|
||||
transparent: blenderMaterial.transparent,
|
||||
|
@ -540,7 +541,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
overdraw: blenderMaterial.overdraw,
|
||||
visible: blenderMaterial.visible,
|
||||
side: blenderMaterial.side,
|
||||
color: new this.THREE.Color(
|
||||
color: new THREE.Color(
|
||||
blenderMaterial.color.r,
|
||||
blenderMaterial.color.g,
|
||||
blenderMaterial.color.b
|
||||
|
@ -549,7 +550,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
metalness: blenderMaterial.metalness,
|
||||
lightMapIntensity: blenderMaterial.lightMapIntensity,
|
||||
aoMapIntensity: blenderMaterial.aoMapIntensity,
|
||||
emissive: new this.THREE.Color(
|
||||
emissive: new THREE.Color(
|
||||
blenderMaterial.emissive.r,
|
||||
blenderMaterial.emissive.g,
|
||||
blenderMaterial.emissive.b
|
||||
|
@ -586,7 +587,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
);
|
||||
} else if (blenderMaterial.materialType == GameLib.D3.Material.TYPE_MESH_PHONG) {
|
||||
|
||||
threeMaterial = new this.THREE.MeshPhongMaterial({
|
||||
threeMaterial = new THREE.MeshPhongMaterial({
|
||||
name: blenderMaterial.name,
|
||||
opacity: blenderMaterial.opacity,
|
||||
transparent: blenderMaterial.transparent,
|
||||
|
@ -606,12 +607,12 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
overdraw: blenderMaterial.overdraw,
|
||||
visible: blenderMaterial.visible,
|
||||
side: blenderMaterial.side,
|
||||
color: new this.THREE.Color(
|
||||
color: new THREE.Color(
|
||||
blenderMaterial.color.r,
|
||||
blenderMaterial.color.g,
|
||||
blenderMaterial.color.b
|
||||
),
|
||||
specular: new this.THREE.Color(
|
||||
specular: new THREE.Color(
|
||||
blenderMaterial.specular.r,
|
||||
blenderMaterial.specular.g,
|
||||
blenderMaterial.specular.b
|
||||
|
@ -619,7 +620,7 @@ GameLib.D3.prototype.createThreeMaterial = function(blenderMaterial) {
|
|||
shininess: blenderMaterial.shininess,
|
||||
lightMapIntensity: blenderMaterial.lightMapIntensity,
|
||||
aoMapIntensity: blenderMaterial.aoMapIntensity,
|
||||
emissive: new this.THREE.Color(
|
||||
emissive: new THREE.Color(
|
||||
blenderMaterial.emissive.r,
|
||||
blenderMaterial.emissive.g,
|
||||
blenderMaterial.emissive.b
|
||||
|
|
|
@ -3,8 +3,14 @@
|
|||
* TODO: body + wheels[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RaycastVehicle = function(
|
||||
GameLib.D3.RaycastVehicle = function(
|
||||
) {
|
||||
this.vehicleObject = null;
|
||||
};
|
||||
|
||||
GameLib.D3.RaycastVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelInfos;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,14 @@
|
|||
* TODO: body + wheels[]
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RigidVehicle = function(
|
||||
GameLib.D3.RigidVehicle = function(
|
||||
) {
|
||||
this.vehicleObject = null;
|
||||
};
|
||||
|
||||
GameLib.D3.RigidVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelBodies;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* @returns {GameLib.D3.Physics.RigidBody}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Physics.RigidBody = function(
|
||||
GameLib.D3.RigidBody = function(
|
||||
mass,
|
||||
friction,
|
||||
position,
|
||||
|
@ -59,7 +59,7 @@ GameLib.D3.Physics.RigidBody = function(
|
|||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Physics.World.RigidBody.prototype.createRigidBodyInstance = function() {
|
||||
GameLib.D3.RigidBody.prototype.createRigidBodyInstance = function() {
|
||||
|
||||
var rigidBody = null;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/**
|
||||
* Texture Superset
|
||||
* @param id
|
||||
* @param path
|
||||
* @param name
|
||||
* @param image
|
||||
* @param wrapS
|
||||
|
|
|
@ -1,224 +0,0 @@
|
|||
GameLib.D3.Vector4.Points = function () {
|
||||
this.vectors = [];
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.add = function (vector) {
|
||||
|
||||
if (vector instanceof GameLib.D3.Vector3) {
|
||||
vector = new GameLib.D3.Vector4(
|
||||
vector.x,
|
||||
vector.y,
|
||||
vector.z,
|
||||
1
|
||||
)
|
||||
}
|
||||
|
||||
if (!vector instanceof GameLib.D3.Vector4) {
|
||||
console.warn("Vector needs to be of type Vector4");
|
||||
throw new Error("Vector needs to be of type Vector4");
|
||||
}
|
||||
|
||||
this.vectors.push(vector);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.copy = function () {
|
||||
|
||||
var vectors = [];
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
vectors.push(this.vectors[i].copy());
|
||||
}
|
||||
|
||||
return vectors;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.maximizeXDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixY = new GameLib.D3.Matrix4().rotationMatrixY(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
var backupVectors = this.copy();
|
||||
|
||||
var maxXDistance = 0;
|
||||
|
||||
for (var i = 0; i < Math.PI * 2; i += grain) {
|
||||
|
||||
multiplier++;
|
||||
|
||||
for (var j = 0; j < this.vectors.length; j++) {
|
||||
this.vectors[j] = rotationMatrixY.multiply(this.vectors[j]);
|
||||
}
|
||||
|
||||
var distances = this.distances();
|
||||
|
||||
if (distances.x > maxXDistance) {
|
||||
|
||||
maxXDistance = distances.x;
|
||||
totalRadians = multiplier * grain;
|
||||
}
|
||||
}
|
||||
|
||||
this.vectors = backupVectors;
|
||||
|
||||
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixY(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
}
|
||||
|
||||
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.maximizeYDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixX = new GameLib.D3.Matrix4().rotationMatrixX(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
var backupVectors = this.copy();
|
||||
|
||||
var maxYDistance = 0;
|
||||
|
||||
for (var i = 0; i < Math.PI * 2; i += grain) {
|
||||
|
||||
multiplier++;
|
||||
|
||||
for (var j = 0; j < this.vectors.length; j++) {
|
||||
this.vectors[j] = rotationMatrixX.multiply(this.vectors[j]);
|
||||
}
|
||||
|
||||
var distances = this.distances();
|
||||
|
||||
if (distances.y > maxYDistance) {
|
||||
maxYDistance = distances.y;
|
||||
totalRadians = multiplier * grain;
|
||||
}
|
||||
}
|
||||
|
||||
this.vectors = backupVectors;
|
||||
|
||||
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixX(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
}
|
||||
|
||||
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.lookAt = function (at, up) {
|
||||
|
||||
var polyCenter = this.average();
|
||||
|
||||
console.log("poly center : " + JSON.stringify(polyCenter));
|
||||
|
||||
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
|
||||
|
||||
lookAtMatrix.rows[0] = new GameLib.D3.Vector4(1, 0, 0, 0);
|
||||
lookAtMatrix.rows[1] = new GameLib.D3.Vector4(0, 0, 1, 0);
|
||||
lookAtMatrix.rows[2] = new GameLib.D3.Vector4(0, 1, 0, 0);
|
||||
|
||||
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
console.log("vector " + i + " (before): " + JSON.stringify(this.vectors[i]));
|
||||
this.vectors[i] = lookAtMatrix.multiply(this.vectors[i]);
|
||||
console.log("vector " + i + " (after) : " + JSON.stringify(this.vectors[i]));
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.distances = function () {
|
||||
|
||||
var minX = this.vectors[0].x;
|
||||
var minY = this.vectors[0].y;
|
||||
var minZ = this.vectors[0].z;
|
||||
|
||||
var maxX = this.vectors[0].x;
|
||||
var maxY = this.vectors[0].y;
|
||||
var maxZ = this.vectors[0].z;
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
if (this.vectors[i].x < minX) {
|
||||
minX = this.vectors[i].x;
|
||||
}
|
||||
if (this.vectors[i].y < minY) {
|
||||
minY = this.vectors[i].y;
|
||||
}
|
||||
if (this.vectors[i].z < minZ) {
|
||||
minZ = this.vectors[i].z;
|
||||
}
|
||||
|
||||
if (this.vectors[i].x > maxX) {
|
||||
maxX = this.vectors[i].x;
|
||||
}
|
||||
if (this.vectors[i].y > maxY) {
|
||||
maxY = this.vectors[i].y;
|
||||
}
|
||||
if (this.vectors[i].z > maxZ) {
|
||||
maxZ = this.vectors[i].z;
|
||||
}
|
||||
}
|
||||
|
||||
return new GameLib.D3.Vector3(
|
||||
Math.abs(maxX - minX),
|
||||
Math.abs(maxY - minY),
|
||||
Math.abs(maxY - minZ)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.average = function () {
|
||||
var averageX = 0;
|
||||
var averageY = 0;
|
||||
var averageZ = 0;
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
averageX += this.vectors[i].x;
|
||||
averageY += this.vectors[i].y;
|
||||
averageZ += this.vectors[i].z;
|
||||
}
|
||||
|
||||
return new GameLib.D3.Vector3(
|
||||
averageX / this.vectors.length,
|
||||
averageY / this.vectors.length,
|
||||
averageZ / this.vectors.length
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.negative = function () {
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
this.vectors[i].x *= -1;
|
||||
this.vectors[i].y *= -1;
|
||||
this.vectors[i].z *= -1;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.toOrigin = function () {
|
||||
|
||||
var distanceFromOrigin = this.average().negative();
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
this.vectors[i].translate(distanceFromOrigin);
|
||||
}
|
||||
};
|
|
@ -97,3 +97,227 @@ GameLib.D3.Vector4.prototype.subtract = function (v) {
|
|||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points = function () {
|
||||
this.vectors = [];
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.add = function (vector) {
|
||||
|
||||
if (vector instanceof GameLib.D3.Vector3) {
|
||||
vector = new GameLib.D3.Vector4(
|
||||
vector.x,
|
||||
vector.y,
|
||||
vector.z,
|
||||
1
|
||||
)
|
||||
}
|
||||
|
||||
if (!vector instanceof GameLib.D3.Vector4) {
|
||||
console.warn("Vector needs to be of type Vector4");
|
||||
throw new Error("Vector needs to be of type Vector4");
|
||||
}
|
||||
|
||||
this.vectors.push(vector);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.copy = function () {
|
||||
|
||||
var vectors = [];
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
vectors.push(this.vectors[i].copy());
|
||||
}
|
||||
|
||||
return vectors;
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.maximizeXDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixY = new GameLib.D3.Matrix4().rotationMatrixY(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
var backupVectors = this.copy();
|
||||
|
||||
var maxXDistance = 0;
|
||||
|
||||
for (var i = 0; i < Math.PI * 2; i += grain) {
|
||||
|
||||
multiplier++;
|
||||
|
||||
for (var j = 0; j < this.vectors.length; j++) {
|
||||
this.vectors[j] = rotationMatrixY.multiply(this.vectors[j]);
|
||||
}
|
||||
|
||||
var distances = this.distances();
|
||||
|
||||
if (distances.x > maxXDistance) {
|
||||
|
||||
maxXDistance = distances.x;
|
||||
totalRadians = multiplier * grain;
|
||||
}
|
||||
}
|
||||
|
||||
this.vectors = backupVectors;
|
||||
|
||||
// console.log("distance: " + maxXDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixY(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
}
|
||||
|
||||
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.maximizeYDistance = function (grain) {
|
||||
|
||||
// console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
var rotationMatrixX = new GameLib.D3.Matrix4().rotationMatrixX(grain);
|
||||
|
||||
var totalRadians = 0;
|
||||
|
||||
var backupVectors = this.copy();
|
||||
|
||||
var maxYDistance = 0;
|
||||
|
||||
for (var i = 0; i < Math.PI * 2; i += grain) {
|
||||
|
||||
multiplier++;
|
||||
|
||||
for (var j = 0; j < this.vectors.length; j++) {
|
||||
this.vectors[j] = rotationMatrixX.multiply(this.vectors[j]);
|
||||
}
|
||||
|
||||
var distances = this.distances();
|
||||
|
||||
if (distances.y > maxYDistance) {
|
||||
maxYDistance = distances.y;
|
||||
totalRadians = multiplier * grain;
|
||||
}
|
||||
}
|
||||
|
||||
this.vectors = backupVectors;
|
||||
|
||||
// console.log("distance: " + maxYDistance + " radians : " + totalRadians);
|
||||
|
||||
var maxRotationMatrix = new GameLib.D3.Matrix4().rotationMatrixX(totalRadians);
|
||||
|
||||
for (var k = 0; k < this.vectors.length; k++) {
|
||||
this.vectors[k] = maxRotationMatrix.multiply(this.vectors[k]);
|
||||
}
|
||||
|
||||
// console.log("vectors (after): " + JSON.stringify(this.vectors, null, 2));
|
||||
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.lookAt = function (at, up) {
|
||||
|
||||
var polyCenter = this.average();
|
||||
|
||||
console.log("poly center : " + JSON.stringify(polyCenter));
|
||||
|
||||
var lookAtMatrix = new GameLib.D3.Matrix4().lookAt(polyCenter, at, up);
|
||||
|
||||
lookAtMatrix.rows[0] = new GameLib.D3.Vector4(1, 0, 0, 0);
|
||||
lookAtMatrix.rows[1] = new GameLib.D3.Vector4(0, 0, 1, 0);
|
||||
lookAtMatrix.rows[2] = new GameLib.D3.Vector4(0, 1, 0, 0);
|
||||
|
||||
console.log("look at matrix : " + JSON.stringify(lookAtMatrix, null, 2));
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
console.log("vector " + i + " (before): " + JSON.stringify(this.vectors[i]));
|
||||
this.vectors[i] = lookAtMatrix.multiply(this.vectors[i]);
|
||||
console.log("vector " + i + " (after) : " + JSON.stringify(this.vectors[i]));
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.distances = function () {
|
||||
|
||||
var minX = this.vectors[0].x;
|
||||
var minY = this.vectors[0].y;
|
||||
var minZ = this.vectors[0].z;
|
||||
|
||||
var maxX = this.vectors[0].x;
|
||||
var maxY = this.vectors[0].y;
|
||||
var maxZ = this.vectors[0].z;
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
if (this.vectors[i].x < minX) {
|
||||
minX = this.vectors[i].x;
|
||||
}
|
||||
if (this.vectors[i].y < minY) {
|
||||
minY = this.vectors[i].y;
|
||||
}
|
||||
if (this.vectors[i].z < minZ) {
|
||||
minZ = this.vectors[i].z;
|
||||
}
|
||||
|
||||
if (this.vectors[i].x > maxX) {
|
||||
maxX = this.vectors[i].x;
|
||||
}
|
||||
if (this.vectors[i].y > maxY) {
|
||||
maxY = this.vectors[i].y;
|
||||
}
|
||||
if (this.vectors[i].z > maxZ) {
|
||||
maxZ = this.vectors[i].z;
|
||||
}
|
||||
}
|
||||
|
||||
return new GameLib.D3.Vector3(
|
||||
Math.abs(maxX - minX),
|
||||
Math.abs(maxY - minY),
|
||||
Math.abs(maxY - minZ)
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.average = function () {
|
||||
var averageX = 0;
|
||||
var averageY = 0;
|
||||
var averageZ = 0;
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
averageX += this.vectors[i].x;
|
||||
averageY += this.vectors[i].y;
|
||||
averageZ += this.vectors[i].z;
|
||||
}
|
||||
|
||||
return new GameLib.D3.Vector3(
|
||||
averageX / this.vectors.length,
|
||||
averageY / this.vectors.length,
|
||||
averageZ / this.vectors.length
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.negative = function () {
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
this.vectors[i].x *= -1;
|
||||
this.vectors[i].y *= -1;
|
||||
this.vectors[i].z *= -1;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Vector4.Points.prototype.toOrigin = function () {
|
||||
|
||||
var distanceFromOrigin = this.average().negative();
|
||||
|
||||
for (var i = 0; i < this.vectors.length; i++) {
|
||||
this.vectors[i].translate(distanceFromOrigin);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -105,7 +105,7 @@ GameLib.D3.World.prototype.createWorldInstance = function() {
|
|||
return customWorld;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddShape = function(
|
||||
GameLib.D3.World.prototype.AddShape = function(
|
||||
shape, // d3.physics.shape
|
||||
rigidBody,
|
||||
offset, // vec3
|
||||
|
@ -133,11 +133,11 @@ GameLib.D3.Physics.World.prototype.AddShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.Wheel = function() {
|
||||
GameLib.D3.World.prototype.Wheel = function() {
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function(
|
||||
GameLib.D3.World.prototype.CreateRigidVehicle = function(
|
||||
chassisBody // Physics.RigidBody
|
||||
) {
|
||||
var rigidVehicle = new GameLib.D3.Physics.RigidVehicle();
|
||||
|
@ -151,7 +151,7 @@ GameLib.D3.Physics.World.prototype.CreateRigidVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateRaycastVehicle = function(
|
||||
GameLib.D3.World.prototype.CreateRaycastVehicle = function(
|
||||
chassisBody // Physics.RigidBody
|
||||
) {
|
||||
var raycastVehicle = new GameLib.D3.Physics.RaycastVehicle();
|
||||
|
@ -165,7 +165,7 @@ GameLib.D3.Physics.World.prototype.CreateRaycastVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle = function(
|
||||
GameLib.D3.World.prototype.AddWheelToRigidVehicle = function(
|
||||
vehicle,
|
||||
rigidBody,
|
||||
position,
|
||||
|
@ -182,7 +182,7 @@ GameLib.D3.Physics.World.prototype.AddWheelToRigidVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle = function (
|
||||
GameLib.D3.World.prototype.AddWheelToRaycastVehicle = function (
|
||||
vehicle, // physics.raycastvehicle
|
||||
options // cannon options
|
||||
) {
|
||||
|
@ -193,22 +193,9 @@ GameLib.D3.Physics.World.prototype.AddWheelToRaycastVehicle = function (
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.RigidVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelBodies;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.RaycastVehicle.prototype.GetWheelInfo = function(
|
||||
|
||||
) {
|
||||
// note: need a way to determine which engine we are currently using
|
||||
return this.vehicleObject.wheelInfos;
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateTriMeshShape = function(
|
||||
GameLib.D3.World.prototype.CreateTriMeshShape = function(
|
||||
vertices, // flat list of floats
|
||||
indices // flat list of floats
|
||||
) {
|
||||
|
@ -217,7 +204,7 @@ GameLib.D3.Physics.World.prototype.CreateTriMeshShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateSphereShape = function (
|
||||
GameLib.D3.World.prototype.CreateSphereShape = function (
|
||||
radius
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -225,7 +212,7 @@ GameLib.D3.Physics.World.prototype.CreateSphereShape = function (
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateBoxShape = function(
|
||||
GameLib.D3.World.prototype.CreateBoxShape = function(
|
||||
halfExtensions // vec3
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -233,7 +220,7 @@ GameLib.D3.Physics.World.prototype.CreateBoxShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.CreateCylinderShape = function(
|
||||
GameLib.D3.World.prototype.CreateCylinderShape = function(
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
|
@ -244,7 +231,7 @@ GameLib.D3.Physics.World.prototype.CreateCylinderShape = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddRigidBody = function(
|
||||
GameLib.D3.World.prototype.AddRigidBody = function(
|
||||
rigidBody // Physics.RigidBody
|
||||
) {
|
||||
if(this.physics.engineType === GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -252,7 +239,7 @@ GameLib.D3.Physics.World.prototype.AddRigidBody = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.AddVehicle = function(
|
||||
GameLib.D3.World.prototype.AddVehicle = function(
|
||||
vehicle // note: physics.vehicle
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -260,7 +247,7 @@ GameLib.D3.Physics.World.prototype.AddVehicle = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.Step = function(
|
||||
GameLib.D3.World.prototype.Step = function(
|
||||
timeStep
|
||||
) {
|
||||
if(this.physics.engineType == GameLib.D3.Physics.TYPE_CANNON) {
|
||||
|
@ -286,7 +273,7 @@ GameLib.D3.Physics.World.prototype.Step = function(
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GetIndexedVertices = function(
|
||||
GameLib.D3.World.prototype.GetIndexedVertices = function(
|
||||
triangleMeshShape
|
||||
) {
|
||||
|
||||
|
@ -304,7 +291,7 @@ GameLib.D3.Physics.World.prototype.GetIndexedVertices = function(
|
|||
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GenerateWireframeViewMesh = function(
|
||||
GameLib.D3.World.prototype.GenerateWireframeViewMesh = function(
|
||||
triangleMeshShape,
|
||||
normalLength,
|
||||
scale,
|
||||
|
@ -363,7 +350,7 @@ GameLib.D3.Physics.World.prototype.GenerateWireframeViewMesh = function(
|
|||
return wireframeTHREEMesh;
|
||||
};
|
||||
|
||||
GameLib.D3.Physics.World.prototype.GenerateTriangleCollisionMesh = function(
|
||||
GameLib.D3.World.prototype.GenerateTriangleCollisionMesh = function(
|
||||
threeMesh,
|
||||
mass, // default = 0
|
||||
friction, // default = 10
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
var chai = require('chai'),
|
||||
sinon = require("sinon"),
|
||||
sinonChai = require("sinon-chai"),
|
||||
config = require('../config.js'),
|
||||
assert = chai.assert,
|
||||
GameLib = require('../build/game-lib');
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
describe('Bone', function(){
|
||||
|
||||
this.timeout(0);
|
||||
|
||||
before(function(){
|
||||
|
||||
});
|
||||
|
||||
after(function(){
|
||||
|
||||
});
|
||||
|
||||
beforeEach(function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
afterEach(function(done){
|
||||
done();
|
||||
});
|
||||
|
||||
it('Should create a Bone object', function (done) {
|
||||
|
||||
var bone = new GameLib.D3.Bone(
|
||||
null,
|
||||
1,
|
||||
'test bone 1',
|
||||
[2, 3, 4]
|
||||
);
|
||||
|
||||
assert(bone.position instanceof GameLib.D3.Vector3);
|
||||
assert(bone.rotation instanceof GameLib.D3.Vector3);
|
||||
assert(bone.scale instanceof GameLib.D3.Vector3);
|
||||
assert(bone.up instanceof GameLib.D3.Vector3);
|
||||
assert(bone.quaternion instanceof GameLib.D3.Vector4);
|
||||
assert(bone.parentBoneId == null);
|
||||
assert.deepEqual(bone.childBoneIds, [2,3,4]);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue