window.Physijs=function(){"use strict";var SUPPORT_TRANSFERABLE,_is_simulating=false,_Physijs=Physijs,Physijs={},Eventable,getObjectId,getEulerXYZFromQuaternion,getQuatertionFromEuler,convertWorldPositionToObject,addObjectChildren,_temp1,_temp2,_temp_vector3_1=new THREE.Vector3,_temp_vector3_2=new THREE.Vector3,_temp_matrix4_1=new THREE.Matrix4,_quaternion_1=new THREE.Quaternion,MESSAGE_TYPES={WORLDREPORT:0,COLLISIONREPORT:1,VEHICLEREPORT:2,CONSTRAINTREPORT:3},REPORT_ITEMSIZE=14,COLLISIONREPORT_ITEMSIZE=5,VEHICLEREPORT_ITEMSIZE=9,CONSTRAINTREPORT_ITEMSIZE=6;Physijs.scripts={};Eventable=function(){this._eventListeners={}};Eventable.prototype.addEventListener=function(event_name,callback){if(!this._eventListeners.hasOwnProperty(event_name)){this._eventListeners[event_name]=[]}this._eventListeners[event_name].push(callback)};Eventable.prototype.removeEventListener=function(event_name,callback){var index;if(!this._eventListeners.hasOwnProperty(event_name))return false;if((index=this._eventListeners[event_name].indexOf(callback))>=0){this._eventListeners[event_name].splice(index,1);return true}return false};Eventable.prototype.dispatchEvent=function(event_name){var i,parameters=Array.prototype.splice.call(arguments,1);if(this._eventListeners.hasOwnProperty(event_name)){for(i=0;i0){_temp_vector3_1.set(-data[normal_offset],-data[normal_offset+1],-data[normal_offset+2])}else{normal_offset*=-1;_temp_vector3_1.set(data[normal_offset],data[normal_offset+1],data[normal_offset+2])}object.dispatchEvent("collision",object2,_temp1,_temp2,_temp_vector3_1)}}}}else{object._physijs.touches.length=0}}this.collisions=collisions;if(SUPPORT_TRANSFERABLE){this._worker.transferableMessage(data.buffer,[data.buffer])}};Physijs.Scene.prototype.addConstraint=function(constraint,show_marker){this._constraints[constraint.id]=constraint;this.execute("addConstraint",constraint.getDefinition());if(show_marker){var marker;switch(constraint.type){case"point":marker=new THREE.Mesh(new THREE.SphereGeometry(1.5),new THREE.MeshNormalMaterial);marker.position.copy(constraint.positiona);this._objects[constraint.objecta].add(marker);break;case"hinge":marker=new THREE.Mesh(new THREE.SphereGeometry(1.5),new THREE.MeshNormalMaterial);marker.position.copy(constraint.positiona);this._objects[constraint.objecta].add(marker);break;case"slider":marker=new THREE.Mesh(new THREE.BoxGeometry(10,1,1),new THREE.MeshNormalMaterial);marker.position.copy(constraint.positiona);marker.rotation.set(constraint.axis.y,constraint.axis.x,constraint.axis.z);this._objects[constraint.objecta].add(marker);break;case"conetwist":marker=new THREE.Mesh(new THREE.SphereGeometry(1.5),new THREE.MeshNormalMaterial);marker.position.copy(constraint.positiona);this._objects[constraint.objecta].add(marker);break;case"dof":marker=new THREE.Mesh(new THREE.SphereGeometry(1.5),new THREE.MeshNormalMaterial);marker.position.copy(constraint.positiona);this._objects[constraint.objecta].add(marker);break}}return constraint};Physijs.Scene.prototype.onSimulationResume=function(){this.execute("onSimulationResume",{})};Physijs.Scene.prototype.removeConstraint=function(constraint){if(this._constraints[constraint.id]!==undefined){this.execute("removeConstraint",{id:constraint.id});delete this._constraints[constraint.id]}};Physijs.Scene.prototype.execute=function(cmd,params){this._worker.postMessage({cmd:cmd,params:params})};addObjectChildren=function(parent,object){var i;for(i=0;i0){for(var i=0;i0){for(var i=0;i0){for(var i=0;i