GameLib.D3.ComponentMeshPermutation = function( componentId, positionOffset, quaternionOffset, scaleOffset ) { 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); this.scaleOffset = scaleOffset || new GameLib.D3.Vector3(0, 0, 0); // 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); }; 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, parentEntity ) { if(parentEntity && parentEntity.mesh) { ComponentMeshPermutation_quaternion.copy(parentEntity.mesh.quaternion); ComponentMeshPermutation_quaternionCopy.copy(ComponentMeshPermutation_quaternion); ComponentMeshPermutation_position.copy(parentEntity.mesh.position); ComponentMeshPermutation_offsetQuaternion.copy(this.quaternionOffset); ComponentMeshPermutation_quaternion = ComponentMeshPermutation_quaternion.multiply(ComponentMeshPermutation_offsetQuaternion).normalize(); ComponentMeshPermutation_offsetPosition.copy(this.positionOffset); ComponentMeshPermutation_position = ComponentMeshPermutation_position.add(ComponentMeshPermutation_offsetPosition.applyQuaternion(ComponentMeshPermutation_quaternionCopy)); ComponentMeshPermutation_scale.copy(parentEntity.mesh.scale); ComponentMeshPermutation_offsetScale.copy(this.scaleOffset); ComponentMeshPermutation_scale = ComponentMeshPermutation_scale.add(ComponentMeshPermutation_offsetScale); parentEntity.mesh.position.copy(ComponentMeshPermutation_position); parentEntity.mesh.quaternion.copy(ComponentMeshPermutation_quaternion); parentEntity.mesh.scale.copy(ComponentMeshPermutation_scale); } };