2016-11-03 11:57:05 +01:00
|
|
|
GameLib.D3.ComponentMeshPermutation = function(
|
|
|
|
componentId,
|
|
|
|
positionOffset,
|
2016-11-04 14:57:48 +01:00
|
|
|
quaternionOffset,
|
|
|
|
scaleOffset
|
2016-11-03 11:57:05 +01:00
|
|
|
) {
|
|
|
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
|
|
|
this.parentEntity = null;
|
|
|
|
|
|
|
|
this.positionOffset = positionOffset || new GameLib.D3.Vector3(0, 0, 0);
|
|
|
|
this.quaternionOffset = quaternionOffset || new GameLib.D3.Quaternion(0, 0, 0, 1);
|
2016-11-04 14:57:48 +01:00
|
|
|
this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0);
|
2016-11-03 11:57:05 +01:00
|
|
|
|
|
|
|
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
|
|
|
|
GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface);
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////// Methods to override //////////////////////////
|
|
|
|
GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate = function(
|
|
|
|
deltaTime,
|
|
|
|
parentEntity
|
|
|
|
) {
|
|
|
|
|
|
|
|
if(parentEntity && parentEntity.mesh) {
|
|
|
|
var quaternion = new THREE.Quaternion();
|
|
|
|
quaternion.copy(parentEntity.mesh.quaternion);
|
|
|
|
|
|
|
|
var quaternionCopy = quaternion.clone();
|
|
|
|
|
|
|
|
var position = new THREE.Vector3();
|
|
|
|
position.copy(parentEntity.mesh.position);
|
|
|
|
|
|
|
|
var offsetQuaternion = new THREE.Quaternion();
|
|
|
|
offsetQuaternion.copy(this.quaternionOffset);
|
|
|
|
quaternion = quaternion.multiply(offsetQuaternion).normalize();
|
|
|
|
|
|
|
|
var offsetPosition = new THREE.Vector3();
|
|
|
|
offsetPosition.copy(this.positionOffset);
|
|
|
|
position = position.add(offsetPosition.applyQuaternion(quaternionCopy));
|
|
|
|
|
2016-11-04 14:57:48 +01:00
|
|
|
var scale = new THREE.Vector3();
|
|
|
|
scale.copy(parentEntity.mesh.scale);
|
|
|
|
|
|
|
|
var scaleOffset = new THREE.Vector3();
|
|
|
|
scaleOffset.copy(this.scaleOffset);
|
|
|
|
scale = scale.add(scaleOffset);
|
|
|
|
|
2016-11-03 11:57:05 +01:00
|
|
|
parentEntity.mesh.position.copy(position);
|
|
|
|
parentEntity.mesh.quaternion.copy(quaternion);
|
2016-11-04 14:57:48 +01:00
|
|
|
parentEntity.mesh.scale.copy(scale);
|
2016-11-03 11:57:05 +01:00
|
|
|
}
|
|
|
|
};
|