90 lines
3.5 KiB
JavaScript
90 lines
3.5 KiB
JavaScript
/**
|
|
*
|
|
* @param id
|
|
* @param name
|
|
* @param positionOffset
|
|
* @param quaternionOffset
|
|
* @param scaleOffset
|
|
* @constructor
|
|
*/
|
|
GameLib.D3.ComponentEntityPermutation = function ComponentEntityPermutation(
|
|
id,
|
|
name,
|
|
positionOffset,
|
|
quaternionOffset,
|
|
scaleOffset
|
|
) {
|
|
this.id = id || GameLib.D3.Tools.RandomId();
|
|
|
|
if (typeof name == 'undefined') {
|
|
name = this.constructor.name;
|
|
}
|
|
this.name = name;
|
|
|
|
this.parentEntity = null;
|
|
|
|
if(GameLib.D3.Utils.UndefinedOrNull(positionOffset)) {
|
|
positionOffset = new GameLib.D3.Vector3(0, 0, 0);
|
|
} this.positionOffset = positionOffset;
|
|
|
|
|
|
if(GameLib.D3.Utils.UndefinedOrNull(quaternionOffset)) {
|
|
quaternionOffset = new GameLib.D3.Vector4(0, 0, 0, 1);
|
|
} this.quaternionOffset = quaternionOffset;
|
|
|
|
|
|
if(GameLib.D3.Utils.UndefinedOrNull(scaleOffset)) {
|
|
scaleOffset = new GameLib.D3.Vector3(0, 0, 0);
|
|
} this.scaleOffset = scaleOffset;
|
|
|
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentEntityPermutation, GameLib.D3.ComponentInterface);
|
|
};
|
|
|
|
//#ifdef RUNTIME__
|
|
if(typeof THREE != "undefined") {
|
|
ComponentEntityPermutation_quaternion = new THREE.Quaternion();
|
|
ComponentEntityPermutation_quaternionCopy = new THREE.Quaternion();
|
|
ComponentEntityPermutation_position = new THREE.Vector3();
|
|
ComponentEntityPermutation_scale = new THREE.Vector3();
|
|
ComponentEntityPermutation_offsetQuaternion = new THREE.Quaternion();
|
|
ComponentEntityPermutation_offsetPosition = new THREE.Vector3();
|
|
ComponentEntityPermutation_offsetScale = new THREE.Vector3();
|
|
}
|
|
|
|
///////////////////////// Methods to override //////////////////////////
|
|
GameLib.D3.ComponentEntityPermutation.prototype.onUpdate = function(
|
|
deltaTime,
|
|
parentEntity
|
|
) {
|
|
|
|
if(parentEntity && parentEntity.mesh) {
|
|
ComponentEntityPermutation_quaternion.copy(parentEntity.quaternion);
|
|
ComponentEntityPermutation_quaternionCopy.copy(ComponentEntityPermutation_quaternion);
|
|
ComponentEntityPermutation_position.copy(parentEntity.position);
|
|
|
|
ComponentEntityPermutation_offsetQuaternion.copy(this.quaternionOffset);
|
|
ComponentEntityPermutation_quaternion = ComponentEntityPermutation_quaternion.multiply(ComponentEntityPermutation_offsetQuaternion).normalize();
|
|
|
|
ComponentEntityPermutation_offsetPosition.copy(this.positionOffset);
|
|
ComponentEntityPermutation_position = ComponentEntityPermutation_position.add(ComponentEntityPermutation_offsetPosition.applyQuaternion(ComponentEntityPermutation_quaternionCopy));
|
|
|
|
ComponentEntityPermutation_scale.copy(parentEntity.scale);
|
|
|
|
ComponentEntityPermutation_offsetScale.copy(this.scaleOffset);
|
|
ComponentEntityPermutation_scale = ComponentEntityPermutation_scale.add(ComponentEntityPermutation_offsetScale);
|
|
|
|
parentEntity.position.x = ComponentEntityPermutation_position.x;
|
|
parentEntity.position.y = ComponentEntityPermutation_position.y;
|
|
parentEntity.position.z = ComponentEntityPermutation_position.z;
|
|
|
|
parentEntity.quaternion.x = ComponentEntityPermutation_quaternion.x;
|
|
parentEntity.quaternion.y = ComponentEntityPermutation_quaternion.y;
|
|
parentEntity.quaternion.z = ComponentEntityPermutation_quaternion.z;
|
|
parentEntity.quaternion.w = ComponentEntityPermutation_quaternion.w;
|
|
|
|
parentEntity.scale.x = ComponentEntityPermutation_scale.x;
|
|
parentEntity.scale.y = ComponentEntityPermutation_scale.y;
|
|
parentEntity.scale.z = ComponentEntityPermutation_scale.z;
|
|
}
|
|
};
|
|
//#endif
|