r3-legacy/src/game-lib-d3-bone.js

161 lines
3.6 KiB
JavaScript
Raw Normal View History

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 = {};
}
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,
this.position,
this
2016-12-23 16:07:10 +01:00
);
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
2016-12-23 16:07:10 +01:00
);
this.scale = new GameLib.Vector3(
graphics,
this.scale,
this
2016-12-23 16:07:10 +01:00
);
this.up = new GameLib.Vector3(
graphics,
this.up,
this
2016-12-23 16:07:10 +01:00
);
2017-10-23 14:52:35 +02:00
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_BONE
);
2016-12-23 16:07:10 +01:00
};
GameLib.D3.Bone.prototype = Object.create(GameLib.D3.API.Bone.prototype);
GameLib.D3.Bone.prototype.constructor = GameLib.D3.Bone;
/**
* Creates an instance bone
2017-06-28 17:09:06 +02:00
*/
GameLib.D3.Bone.prototype.createInstance = function() {
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
this.instance = new THREE.Bone();
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
this.instance.name = this.name;
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
this.instance.position.x = this.position.x;
this.instance.position.y = this.position.y;
this.instance.position.z = this.position.z;
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
this.instance.quaternion.x = this.quaternion.x;
this.instance.quaternion.y = this.quaternion.y;
this.instance.quaternion.z = this.quaternion.z;
this.instance.quaternion.w = this.quaternion.w;
this.instance.scale.x = this.scale.x;
this.instance.scale.y = this.scale.y;
this.instance.scale.z = this.scale.z;
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
this.instance.up.x = this.up.x;
this.instance.up.y = this.up.y;
this.instance.up.z = this.up.z;
2016-12-23 16:07:10 +01:00
2017-10-23 14:52:35 +02:00
GameLib.Component.prototype.createInstance.call(this);
2016-12-23 16:07:10 +01:00
};
/**
* Updates the instance
*/
GameLib.D3.Bone.prototype.updateInstance = function() {
2017-06-28 17:09:06 +02:00
this.instance.name = this.name;
this.instance.position.x = this.position.x;
this.instance.position.y = this.position.y;
this.instance.position.z = this.position.z;
this.instance.quaternion.x = this.quaternion.x;
this.instance.quaternion.y = this.quaternion.y;
this.instance.quaternion.z = this.quaternion.z;
this.instance.quaternion.w = this.quaternion.w;
this.instance.scale.x = this.scale.x;
this.instance.scale.y = this.scale.y;
this.instance.scale.z = this.scale.z;
this.instance.up.x = this.up.x;
this.instance.up.y = this.up.y;
this.instance.up.z = this.up.z;
2016-12-23 16:07:10 +01:00
};
/**
* 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
*/
2017-06-14 14:21:57 +02:00
GameLib.D3.Bone.FromObject = function(
2016-12-23 16:07:10 +01:00
graphics,
objectBone
) {
2017-06-14 14:21:57 +02:00
var apiBone = GameLib.D3.API.Bone.FromObject(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;
};