2016-12-23 16:07:10 +01:00
|
|
|
/**
|
|
|
|
* Bone Superset
|
|
|
|
* @constructor
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param apiBone GameLib.D3.API.Bone
|
|
|
|
*/
|
2017-01-05 19:34:28 +01:00
|
|
|
GameLib.D3.Bone = function (
|
2016-12-23 16:07:10 +01:00
|
|
|
graphics,
|
|
|
|
apiBone
|
|
|
|
) {
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
2017-01-12 17:40:17 +01:00
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiBone)) {
|
|
|
|
apiBone = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiBone instanceof GameLib.D3.Bone) {
|
|
|
|
return apiBone;
|
|
|
|
}
|
|
|
|
|
2016-12-23 16:07:10 +01:00
|
|
|
GameLib.D3.API.Bone.call(
|
|
|
|
this,
|
|
|
|
apiBone.id,
|
|
|
|
apiBone.name,
|
|
|
|
apiBone.childBoneIds,
|
|
|
|
apiBone.parentBoneIds,
|
|
|
|
apiBone.position,
|
|
|
|
apiBone.quaternion,
|
|
|
|
apiBone.scale,
|
|
|
|
apiBone.up
|
|
|
|
);
|
|
|
|
|
|
|
|
this.position = new GameLib.Vector3(
|
|
|
|
graphics,
|
2017-01-17 13:24:45 +01:00
|
|
|
this.position,
|
|
|
|
this
|
2016-12-23 16:07:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
this.quaternion = new GameLib.Quaternion(
|
|
|
|
graphics,
|
2017-01-17 13:24:45 +01:00
|
|
|
this.quaternion,
|
|
|
|
this
|
2016-12-23 16:07:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
this.scale = new GameLib.Vector3(
|
|
|
|
graphics,
|
2017-01-17 13:24:45 +01:00
|
|
|
this.scale,
|
|
|
|
this
|
2016-12-23 16:07:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
this.up = new GameLib.Vector3(
|
|
|
|
graphics,
|
2017-01-17 13:24:45 +01:00
|
|
|
this.up,
|
|
|
|
this
|
2016-12-23 16:07:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
this.instance = this.createInstance();
|
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.Bone.prototype = Object.create(GameLib.D3.API.Bone.prototype);
|
|
|
|
GameLib.D3.Bone.prototype.constructor = GameLib.D3.Bone;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance bone
|
|
|
|
* @param update boolean
|
|
|
|
*/
|
|
|
|
GameLib.D3.Bone.prototype.createInstance = function(update) {
|
|
|
|
|
|
|
|
var instance = null;
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
instance = this.instance;
|
|
|
|
} else {
|
|
|
|
instance = new THREE.Bone();
|
|
|
|
}
|
|
|
|
|
|
|
|
instance.name = this.name;
|
|
|
|
|
|
|
|
instance.position.x = this.position.x;
|
|
|
|
instance.position.y = this.position.y;
|
|
|
|
instance.position.z = this.position.z;
|
|
|
|
|
|
|
|
instance.quaternion.x = this.quaternion.x;
|
|
|
|
instance.quaternion.y = this.quaternion.y;
|
|
|
|
instance.quaternion.z = this.quaternion.z;
|
|
|
|
instance.quaternion.w = this.quaternion.w;
|
|
|
|
|
|
|
|
instance.scale.x = this.scale.x;
|
|
|
|
instance.scale.y = this.scale.y;
|
|
|
|
instance.scale.z = this.scale.z;
|
|
|
|
|
|
|
|
instance.up.x = this.up.x;
|
|
|
|
instance.up.y = this.up.y;
|
|
|
|
instance.up.z = this.up.z;
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance
|
|
|
|
*/
|
|
|
|
GameLib.D3.Bone.prototype.updateInstance = function() {
|
|
|
|
this.instance = this.createInstance(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a GameLib.D3.Bone to GameLib.D3.API.Bone
|
|
|
|
* @returns {GameLib.D3.API.Bone}
|
|
|
|
*/
|
2017-05-16 14:51:57 +02:00
|
|
|
GameLib.D3.Bone.prototype.toApiObject = function() {
|
2016-12-23 16:07:10 +01:00
|
|
|
|
|
|
|
var apiBone = new GameLib.D3.API.Bone(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.childBoneIds,
|
|
|
|
this.parentBoneIds,
|
2017-05-16 14:51:57 +02:00
|
|
|
this.position.toApiObject(),
|
|
|
|
this.quaternion.toApiObject(),
|
|
|
|
this.scale.toApiObject(),
|
|
|
|
this.up.toApiObject()
|
2016-12-23 16:07:10 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return apiBone;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a GameLib.D3.Bone from a bone Object
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param objectBone Object
|
2017-01-05 19:34:28 +01:00
|
|
|
* @returns {GameLib.D3.Bone}
|
2016-12-23 16:07:10 +01:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.Bone.FromObjectBone = function(
|
|
|
|
graphics,
|
|
|
|
objectBone
|
|
|
|
) {
|
2017-01-05 19:34:28 +01:00
|
|
|
var apiBone = GameLib.D3.API.Bone.FromObjectBone(objectBone);
|
2016-12-23 16:07:10 +01:00
|
|
|
|
2017-01-05 19:34:28 +01:00
|
|
|
var bone = GameLib.D3.Bone(
|
2016-12-23 16:07:10 +01:00
|
|
|
graphics,
|
|
|
|
apiBone
|
|
|
|
);
|
|
|
|
|
|
|
|
return bone;
|
|
|
|
};
|