From de5961456fbefacd687ae6df2401cc66af495664 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 8 Nov 2016 11:26:08 +0100 Subject: [PATCH] reusing vars inside mesh permutation component --- src/game-lib-component-mesh-permutation.js | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/game-lib-component-mesh-permutation.js b/src/game-lib-component-mesh-permutation.js index 0ad3c36..e0ded90 100644 --- a/src/game-lib-component-mesh-permutation.js +++ b/src/game-lib-component-mesh-permutation.js @@ -15,6 +15,15 @@ GameLib.D3.ComponentMeshPermutation = function( GameLib.D3.Utils.Extend(GameLib.D3.ComponentMeshPermutation, GameLib.D3.ComponentInterface); }; +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(); + ///////////////////////// Methods to override ////////////////////////// GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate = function( deltaTime, @@ -22,31 +31,23 @@ GameLib.D3.ComponentMeshPermutation.prototype.onLateUpdate = function( ) { if(parentEntity && parentEntity.mesh) { - var quaternion = new THREE.Quaternion(); - quaternion.copy(parentEntity.mesh.quaternion); + ComponentMeshPermutation_quaternion.copy(parentEntity.mesh.quaternion); + ComponentMeshPermutation_quaternionCopy.copy(ComponentMeshPermutation_quaternion); + ComponentMeshPermutation_position.copy(parentEntity.mesh.position); - var quaternionCopy = quaternion.clone(); + ComponentMeshPermutation_offsetQuaternion.copy(this.quaternionOffset); + ComponentMeshPermutation_quaternion = ComponentMeshPermutation_quaternion.multiply(ComponentMeshPermutation_offsetQuaternion).normalize(); - var position = new THREE.Vector3(); - position.copy(parentEntity.mesh.position); + ComponentMeshPermutation_offsetPosition.copy(this.positionOffset); + ComponentMeshPermutation_position = ComponentMeshPermutation_position.add(ComponentMeshPermutation_offsetPosition.applyQuaternion(ComponentMeshPermutation_quaternionCopy)); - var offsetQuaternion = new THREE.Quaternion(); - offsetQuaternion.copy(this.quaternionOffset); - quaternion = quaternion.multiply(offsetQuaternion).normalize(); + ComponentMeshPermutation_scale.copy(parentEntity.mesh.scale); - var offsetPosition = new THREE.Vector3(); - offsetPosition.copy(this.positionOffset); - position = position.add(offsetPosition.applyQuaternion(quaternionCopy)); + ComponentMeshPermutation_offsetScale.copy(this.scaleOffset); + ComponentMeshPermutation_scale = ComponentMeshPermutation_scale.add(ComponentMeshPermutation_offsetScale); - var scale = new THREE.Vector3(); - scale.copy(parentEntity.mesh.scale); - - var scaleOffset = new THREE.Vector3(); - scaleOffset.copy(this.scaleOffset); - scale = scale.add(scaleOffset); - - parentEntity.mesh.position.copy(position); - parentEntity.mesh.quaternion.copy(quaternion); - parentEntity.mesh.scale.copy(scale); + parentEntity.mesh.position.copy(ComponentMeshPermutation_position); + parentEntity.mesh.quaternion.copy(ComponentMeshPermutation_quaternion); + parentEntity.mesh.scale.copy(ComponentMeshPermutation_scale); } }; \ No newline at end of file