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);
|
|
|
|
};
|
|
|
|
|
2016-11-09 12:37:46 +01:00
|
|
|
if(typeof THREE != "undefined") {
|
|
|
|
ComponentMeshPermutation_quaternion = new THREE.Quaternion();
|
|
|
|
ComponentMeshPermutation_quaternionCopy = new THREE.Quaternion();
|
|
|
|
ComponentMeshPermutation_position = new THREE.Vector3();
|
|
|
|
ComponentMeshPermutation_scale = new THREE.Vector3();
|
|
|
|
ComponentMeshPermutation_offsetQuaternion = new THREE.Quaternion();
|
|
|
|
ComponentMeshPermutation_offsetPosition = new THREE.Vector3();
|
|
|
|
ComponentMeshPermutation_offsetScale = new THREE.Vector3();
|
|
|
|
}
|
2016-11-08 11:26:08 +01:00
|
|
|
|
2016-11-03 11:57:05 +01:00
|
|
|
///////////////////////// Methods to override //////////////////////////
|
|
|
|
GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate = function(
|
|
|
|
deltaTime,
|
|
|
|
parentEntity
|
|
|
|
) {
|
|
|
|
|
|
|
|
if(parentEntity && parentEntity.mesh) {
|
2016-11-08 11:26:08 +01:00
|
|
|
ComponentMeshPermutation_quaternion.copy(parentEntity.mesh.quaternion);
|
|
|
|
ComponentMeshPermutation_quaternionCopy.copy(ComponentMeshPermutation_quaternion);
|
|
|
|
ComponentMeshPermutation_position.copy(parentEntity.mesh.position);
|
2016-11-03 11:57:05 +01:00
|
|
|
|
2016-11-08 11:26:08 +01:00
|
|
|
ComponentMeshPermutation_offsetQuaternion.copy(this.quaternionOffset);
|
|
|
|
ComponentMeshPermutation_quaternion = ComponentMeshPermutation_quaternion.multiply(ComponentMeshPermutation_offsetQuaternion).normalize();
|
2016-11-03 11:57:05 +01:00
|
|
|
|
2016-11-08 11:26:08 +01:00
|
|
|
ComponentMeshPermutation_offsetPosition.copy(this.positionOffset);
|
|
|
|
ComponentMeshPermutation_position = ComponentMeshPermutation_position.add(ComponentMeshPermutation_offsetPosition.applyQuaternion(ComponentMeshPermutation_quaternionCopy));
|
2016-11-03 11:57:05 +01:00
|
|
|
|
2016-11-08 11:26:08 +01:00
|
|
|
ComponentMeshPermutation_scale.copy(parentEntity.mesh.scale);
|
2016-11-04 14:57:48 +01:00
|
|
|
|
2016-11-08 11:26:08 +01:00
|
|
|
ComponentMeshPermutation_offsetScale.copy(this.scaleOffset);
|
|
|
|
ComponentMeshPermutation_scale = ComponentMeshPermutation_scale.add(ComponentMeshPermutation_offsetScale);
|
2016-11-04 14:57:48 +01:00
|
|
|
|
2016-11-08 11:26:08 +01:00
|
|
|
parentEntity.mesh.position.copy(ComponentMeshPermutation_position);
|
|
|
|
parentEntity.mesh.quaternion.copy(ComponentMeshPermutation_quaternion);
|
|
|
|
parentEntity.mesh.scale.copy(ComponentMeshPermutation_scale);
|
2016-11-03 11:57:05 +01:00
|
|
|
}
|
|
|
|
};
|