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); }; ///////////////////////// 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)); 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); } };