2016-10-24 15:56:28 +02:00
|
|
|
var chai = require('chai'),
|
|
|
|
sinon = require("sinon"),
|
|
|
|
sinonChai = require("sinon-chai"),
|
|
|
|
config = require('../config.js'),
|
|
|
|
assert = chai.assert,
|
2018-04-09 10:05:13 +02:00
|
|
|
R3 = require('../build/r3'),
|
2016-10-24 15:56:28 +02:00
|
|
|
CANNON = require('cannon'),
|
|
|
|
THREE = require('three');
|
|
|
|
|
|
|
|
chai.use(sinonChai);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
describe('R3 object creation', function(){
|
2016-10-24 15:56:28 +02:00
|
|
|
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
before(function(){
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function(){
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-10-28 16:02:45 +02:00
|
|
|
beforeEach(function(done, err) {
|
|
|
|
this.xhr = sinon.useFakeXMLHttpRequest();
|
|
|
|
|
|
|
|
this.requests = [];
|
|
|
|
this.xhr.onCreate = function(xhr) {
|
|
|
|
this.requests.push(xhr);
|
|
|
|
}.bind(this);
|
|
|
|
done();
|
2016-10-24 15:56:28 +02:00
|
|
|
});
|
|
|
|
|
2016-10-28 16:02:45 +02:00
|
|
|
afterEach(function(done, err){
|
|
|
|
this.xhr.restore();
|
|
|
|
done();
|
2016-10-24 15:56:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a Bone object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var bone = new R3.D3.Bone(
|
2016-10-24 15:56:28 +02:00
|
|
|
null,
|
|
|
|
1,
|
|
|
|
'test bone 1',
|
|
|
|
[2, 3, 4]
|
|
|
|
);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
assert(bone.position instanceof R3.D3.Vector3);
|
|
|
|
assert(bone.rotation instanceof R3.D3.Vector3);
|
|
|
|
assert(bone.scale instanceof R3.D3.Vector3);
|
|
|
|
assert(bone.up instanceof R3.D3.Vector3);
|
|
|
|
assert(bone.quaternion instanceof R3.D3.Vector4);
|
2016-10-24 15:56:28 +02:00
|
|
|
assert(bone.parentBoneId == null);
|
|
|
|
assert.deepEqual(bone.childBoneIds, [2,3,4]);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a BoneWeight object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var boneWeight = new R3.D3.BoneWeight(
|
2016-10-24 15:56:28 +02:00
|
|
|
1,
|
|
|
|
0.5
|
|
|
|
);
|
|
|
|
|
|
|
|
assert(boneWeight.boneIndex == 1);
|
|
|
|
assert(boneWeight.weight == 0.5);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a Broadphase object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var engine = new R3.D3.Engine(
|
|
|
|
R3.D3.Engine.ENGINE_TYPE_CANNON,
|
2016-10-24 15:56:28 +02:00
|
|
|
CANNON
|
|
|
|
);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
assert(engine.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON);
|
2016-10-24 15:56:28 +02:00
|
|
|
assert(engine.instance instanceof Object);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var broadphase = new R3.D3.Broadphase(
|
2016-10-24 15:56:28 +02:00
|
|
|
null,
|
|
|
|
'broad-phase',
|
2018-04-09 10:05:13 +02:00
|
|
|
R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE,
|
2016-10-24 15:56:28 +02:00
|
|
|
engine,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
assert(broadphase.id == null);
|
|
|
|
assert(broadphase.instance instanceof CANNON.NaiveBroadphase);
|
2018-04-09 10:05:13 +02:00
|
|
|
assert(broadphase.engine instanceof R3.D3.Engine);
|
2016-10-24 15:56:28 +02:00
|
|
|
assert(broadphase.name == 'broad-phase');
|
2018-04-09 10:05:13 +02:00
|
|
|
assert(broadphase.broadphaseType == R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE);
|
2016-10-24 15:56:28 +02:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a Color object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var color = new R3.D3.Color(
|
2016-10-24 15:56:28 +02:00
|
|
|
0.1,
|
|
|
|
0.2,
|
|
|
|
0.3,
|
|
|
|
0.4
|
|
|
|
);
|
|
|
|
|
|
|
|
assert(color.r == 0.1);
|
|
|
|
assert(color.g == 0.2);
|
|
|
|
assert(color.b == 0.3);
|
|
|
|
assert(color.a == 0.4);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a Color object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var color = new R3.D3.Color(
|
2016-10-24 15:56:28 +02:00
|
|
|
0.1,
|
|
|
|
0.2,
|
|
|
|
0.3,
|
|
|
|
0.4
|
|
|
|
);
|
|
|
|
|
|
|
|
assert(color.r == 0.1);
|
|
|
|
assert(color.g == 0.2);
|
|
|
|
assert(color.b == 0.3);
|
|
|
|
assert(color.a == 0.4);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('Should create an Engine object', function (done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var engine = new R3.D3.Engine(
|
|
|
|
R3.D3.Engine.ENGINE_TYPE_CANNON,
|
2016-10-24 15:56:28 +02:00
|
|
|
CANNON
|
|
|
|
);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
assert(engine.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON);
|
2016-10-24 15:56:28 +02:00
|
|
|
assert(engine.instance instanceof Object);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should create a FlyControls object', function (done) {
|
|
|
|
console.log("Cannot test FlyControls server side");
|
|
|
|
done();
|
|
|
|
});
|
2016-10-28 15:28:34 +02:00
|
|
|
|
2016-10-28 16:02:45 +02:00
|
|
|
it('Should load the scene via API', function(done) {
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var scene = new R3.D3.Scene(
|
2016-10-28 16:02:45 +02:00
|
|
|
null,
|
|
|
|
'/gamewheel/root/root/test',
|
|
|
|
'test'
|
|
|
|
);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
var graphics = new R3.D3.Graphics(
|
|
|
|
R3.D3.Graphics.GRAPHICS_TYPE_THREE,
|
2016-10-28 16:02:45 +02:00
|
|
|
THREE
|
|
|
|
);
|
|
|
|
|
2018-04-09 10:05:13 +02:00
|
|
|
R3.D3.Scene.LoadSceneFromApi(
|
2016-10-28 16:02:45 +02:00
|
|
|
scene,
|
|
|
|
function(stuff){
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
graphics,
|
|
|
|
'/uploads/gamewheel/root/root/test',
|
|
|
|
null,
|
|
|
|
'http://api.gamewheel.local'
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-10-24 15:56:28 +02:00
|
|
|
});
|