@class

A rigid body composed of one or more fixtures.

@param {World} world
@param {BodyDef} def
438761
function Body(world, def) {

  def = options(def, BodyDef);

  _ASSERT && common.assert(Vec2.isValid(def.position));
  _ASSERT && common.assert(Vec2.isValid(def.linearVelocity));
  _ASSERT && common.assert(Math.isFinite(def.angle));
  _ASSERT && common.assert(Math.isFinite(def.angularVelocity));
  _ASSERT && common.assert(Math.isFinite(def.angularDamping) && def.angularDamping >= 0.0);
  _ASSERT && common.assert(Math.isFinite(def.linearDamping) && def.linearDamping >= 0.0);

  this.m_world = world;

  this.m_awakeFlag = def.awake;
  this.m_autoSleepFlag = def.allowSleep;
  this.m_bulletFlag = def.bullet;
  this.m_fixedRotationFlag = def.fixedRotation;
  this.m_activeFlag = def.active;

  this.m_islandFlag = false;
  this.m_toiFlag = false;

  this.m_userData = def.userData;
  this.m_type = def.type;

  if (this.m_type == dynamicBody) {
    this.m_mass = 1.0;
    this.m_invMass = 1.0;
  } else {
    this.m_mass = 0.0;
    this.m_invMass = 0.0;
  }

  // Rotational inertia about the center of mass.
  this.m_I = 0.0;
  this.m_invI = 0.0;

  // the body origin transform
  this.m_xf = Transform.identity();
  this.m_xf.p = Vec2.clone(def.position);
  this.m_xf.q.setAngle(def.angle);

  // the swept motion for CCD
  this.m_sweep = new Sweep();
  this.m_sweep.setTransform(this.m_xf);

  // position and velocity correction
  this.c_velocity = new Velocity();
  this.c_position = new Position();

  this.m_force = Vec2.zero();
  this.m_torque = 0.0;

  this.m_linearVelocity = Vec2.clone(def.linearVelocity);
  this.m_angularVelocity = def.angularVelocity;

  this.m_linearDamping = def.linearDamping;
  this.m_angularDamping = def.angularDamping;
  this.m_gravityScale = def.gravityScale;

  this.m_sleepTime = 0.0;

  this.m_jointList = null;
  this.m_contactList = null;
  this.m_fixtureList = null;

  this.m_prev = null;
  this.m_next = null;

  this.m_destroyed = false;
}
87264
function(items)
	{
		var register = [];

		/// Export as module if running under nodejs
		if (typeof global === 'object') {
			register.push(global);
		}

		if (typeof window === 'object') {
			register.push(window);
		}

		// Browse all resolved global objects and bind pwf items
		for (var i = 0; i < register.length; i++) {
			var obj = register[i];

			// Bind all requested items as global
			for (var key in items) {
				if (!items.hasOwnProperty(key)) {
					continue;
				}

				obj[key] = items[key];
			}

			// Check for all callbacks bound to this global object and call them
			if (typeof obj.on_pwf !== 'undefined') {
				var calls = obj.on_pwf;

				// Expecting list/array
				if (!(calls instanceof Array)) {
					calls = [calls];
				}

				for (var j = 0; j < calls.length; j++) {
					if (typeof calls[j] !== 'function') {
						throw new Error('on_pwf:not-a-method:' + j);
					}

					calls[j].apply(obj.pwf);
				}
			}
		}
	}
712629
function () {
    var data = this.data;

    // If true, show wireframes around physics bodies.
    this.debug = data.debug;

    this.callbacks = {beforeStep: [], step: [], afterStep: []};

    this.listeners = {};

    this.driver = null;
    switch (data.driver) {
      case 'local':
        this.driver = new LocalDriver();
        break;

      case 'network':
        this.driver = new NetworkDriver(data.networkUrl);
        break;

      case 'worker':
        this.driver = new WorkerDriver({
          fps: data.workerFps,
          engine: data.workerEngine,
          interpolate: data.workerInterpolate,
          interpolationBufferSize: data.workerInterpBufferSize,
          debug: data.workerDebug
        });
        break;

      default:
        throw new Error('[physics] Driver not recognized: "%s".', data.driver);
    }

    this.driver.init({
      quatNormalizeSkip: 0,
      quatNormalizeFast: false,
      solverIterations: data.iterations,
      gravity: data.gravity
    });

    this.driver.addMaterial({name: 'defaultMaterial'});
    this.driver.addMaterial({name: 'staticMaterial'});
    this.driver.addContactMaterial('defaultMaterial', 'defaultMaterial', {
      friction: data.friction,
      restitution: data.restitution,
      contactEquationStiffness: data.contactEquationStiffness,
      contactEquationRelaxation: data.contactEquationRelaxation,
      frictionEquationStiffness: data.frictionEquationStiffness,
      frictionEquationRegularization: data.frictionEquationRegularization
    });
    this.driver.addContactMaterial('staticMaterial', 'defaultMaterial', {
      friction: 1.0,
      restitution: 0.0,
      contactEquationStiffness: data.contactEquationStiffness,
      contactEquationRelaxation: data.contactEquationRelaxation,
      frictionEquationStiffness: data.frictionEquationStiffness,
      frictionEquationRegularization: data.frictionEquationRegularization
    });
  }
556330
function Physics(width, height, ballRadius) {
  this._height = height;
  this._width = width;
  this._ballRadius = ballRadius || 0.2;
  this._world = null;
  this._ballScored = function () {
  };
  this._paddleFixtures = {};
  this._init();
}
909040
function getWorldPosition(obj) {
	obj.updateMatrixWorld();
	var vec = new THREE.Vector3();
	vec.setFromMatrixPosition(obj.matrixWorld);
	return vec;
}
1056975
function( bodies, meta ){

            var body
                ,view
                ,pos
                ;

            if (this.beforeRender){

                this.beforeRender();
            }

            this._world.emit('beforeRender', {
                renderer: this,
                bodies: bodies,
                meta: meta
            });

            if (this.options.meta){
                this.drawMeta( meta );
            }

            this._interpolateTime = meta.interpolateTime;

            for ( var i = 0, l = bodies.length; i < l; ++i ){

                body = bodies[ i ];
                view = body.view || ( body.view = this.createView(body.geometry, body.styles) );

                if ( !body.hidden ){
                    this.drawBody( body, view );
                }
            }

            return this;
        }
354390
function(){

            var self = this
                ,gui = this.gui = new window.dat.GUI({ autoPlace: false })
                ,op = this.options
                ,getset
                ,f
                ;

            getset = {
                get timestep(){
                    return self._world ? self._world.timestep() : 6;
                }
                ,set timestep( dt ){
                    if ( self._world ) {
                        self._world.timestep( dt );
                    }
                }
                ,get warp(){
                    return self._world ? self._world.warp() : 1;
                }
                ,set warp( w ){
                    if ( self._world ) {
                        self._world.warp( w );
                    }
                }
                ,get maxIPF(){
                    return self._world ? self._world.options.maxIPF : 16;
                }
                ,set maxIPF( m ){
                    if ( self._world ){
                        self._world.options({ maxIPF: m });
                    }
                }
                ,get sleepDisabled(){
                    return self._world ? self._world.options.sleepDisabled : false;
                }
                ,set sleepDisabled( t ){
                    if ( self._world ){
                        self._world.options.sleepDisabled = t;
                        if ( t ){
                            self._world.wakeUpAll();
                        }
                    }
                }
                ,get sleepTimeLimit(){
                    return self._world ? self._world.options.sleepTimeLimit : 500;
                }
                ,set sleepTimeLimit( t ){
                    if ( self._world ){
                        self._world.options.sleepTimeLimit = t;
                    }
                }
                ,get sleepSpeedLimit(){
                    return self._world ? self._world.options.sleepSpeedLimit : 0.005;
                }
                ,set sleepSpeedLimit( t ){
                    if ( self._world ){
                        self._world.options.sleepSpeedLimit = t;
                    }
                }
                ,get sleepVarianceLimit(){
                    return self._world ? self._world.options.sleepVarianceLimit : 0.2;
                }
                ,set sleepVarianceLimit( t ){
                    if ( self._world ){
                        self._world.options.sleepVarianceLimit = t;
                    }
                }
                ,get integrator(){
                    return self._world ? self._world.integrator().name : 'verlet';
                }
                ,set integrator( t ){
                    var intr;
                    if ( self._world ){
                        intr = self._world.integrator();
                        self._world.integrator( Physics.integrator(t, Physics.util.extend({}, intr, null)) );
                    }
                }
            };

            function pauseWorld(){
                if ( self._world ){
                    if ( self._world.isPaused() ){
                        self._world.unpause();
                    } else {
                        self._world.pause();
                    }
                }
            }

            f = gui.addFolder( 'General' );
            f.add( getset, 'integrator', [ 'improved-euler', 'verlet', 'velocity-verlet' ]);
            f.add( getset, 'timestep', 1, 20).step( 1 );
            f.add( getset, 'maxIPF', 1, 100).step( 1 );
            f.add( getset, 'warp', 0.01, 2);
            f.add( getset, 'sleepDisabled');
            f.add( getset, 'sleepTimeLimit', 1, 10000).step( 10 );
            f.add( getset, 'sleepSpeedLimit', 0.001, 1);
            f.add( getset, 'sleepVarianceLimit', 0.01, 1);
            f.add( { pause: pauseWorld }, 'pause');
            f.open();

            f = gui.addFolder( 'Draw Options' );
            f.add( op, 'drawAABB' );
            f.add( op, 'drawRealPosition' );
            f.add( op, 'drawIntervals' );
            f.add( op, 'drawContacts' );
            f.add( op, 'drawSleepState' );
            f.add( op, 'drawBodyState' );
            f.open();

            f = gui.addFolder( 'Colors' );
            f.addColor( op, 'aabbColor' );
            f.addColor( op, 'realBodyStyle' );
            f.addColor( op, 'intervalMinColor' );
            f.addColor( op, 'intervalMaxColor' );
            f.addColor( op, 'mtvColor' );
            f.addColor( op, 'contactColor' );

            gui.domElement.style.zIndex = '100';
            gui.domElement.style.position = 'absolute';
            gui.domElement.style.top = '0';
            gui.domElement.style.left = '0';
            this.el.parentNode.appendChild( gui.domElement );
        }
363589
function generateDebugBody( body ) {

		var frameUnit           = 2;// In pixels
		var debugBody           = Crafty.e( RenderingMode );
        var debugBodyBody       = Crafty.e( RenderingMode + ', Color' );
        var debugBodyTopFrame   = Crafty.e( RenderingMode + ', Color' );
		var debugBodyRightFrame = Crafty.e( RenderingMode + ', Color' );
        var debugBodyDownFrame  = Crafty.e( RenderingMode + ', Color' );
        var debugBodyLeftFrame  = Crafty.e( RenderingMode + ', Color' );

		debugBody.attach( debugBodyBody );
		debugBody.attach( debugBodyTopFrame );
		debugBody.attach( debugBodyRightFrame );
		debugBody.attach( debugBodyDownFrame );
		debugBody.attach( debugBodyLeftFrame );

		// TODO cleaner code.
		var attr = {
			x: body.vertices[ 0 ].x,
			y: body.vertices[ 0 ].y,
			w: body.vertices[ 0 ].x,
			h: body.vertices[ 0 ].y
		};

		//We iterate to have a square shape for circles and polygons/
		for ( var i = 1; i < body.vertices.length; i++ ) {
			if ( body.vertices[ i ].x < attr.x ) {
				attr.x = body.vertices[ i ].x;
			}

			if ( body.vertices[ i ].y < attr.y ) {
				attr.y = body.vertices[ i ].y;
			}

			if ( body.vertices[ i ].x > attr.w ) {
				attr.w = body.vertices[ i ].x;
			}

			if ( body.vertices[ i ].y > attr.h ) {
				attr.h = body.vertices[ i ].y;
			}
		}

		debugBody.attr( {
			x: attr.x,
			y: attr.y,
			w: Math.abs( attr.w - attr.x ),
			h: Math.abs( attr.h - attr.y )
		} );

		debugBody.origin( 'center' );

		debugBodyBody.color( 'blue' );
		debugBodyBody.alpha = 0.5;
		debugBodyBody.z = debugBody._z + 1;
		debugBodyBody.origin( 'center' );

		debugBodyTopFrame.color( 'blue' );
		debugBodyTopFrame.h = frameUnit;
		debugBodyTopFrame.z = debugBody._z + 1;
		debugBodyTopFrame.origin( 'center' );

		debugBodyRightFrame.color( 'blue' );
		debugBodyRightFrame.x = debugBodyBody._x + ( debugBodyBody._w - frameUnit );
		debugBodyRightFrame.w = frameUnit;
		debugBodyRightFrame.z = debugBody._z + 1;
		debugBodyRightFrame.origin( 'center' );

		debugBodyDownFrame.color( 'blue' );
		debugBodyDownFrame.y = debugBodyBody._y + ( debugBodyBody._h - frameUnit );
		debugBodyDownFrame.h = frameUnit;
		debugBodyDownFrame.z = debugBody._z + 1;
		debugBodyDownFrame.origin( 'center' );

		debugBodyLeftFrame.color( 'blue' );
		debugBodyLeftFrame.w = frameUnit;
		debugBodyLeftFrame.z = debugBody._z + 1;
		debugBodyLeftFrame.origin( 'center' );

		return debugBody;
	}
298383
function callFunction (globalObjects, body) {
  const globalKeys = []
  const globalValues = []
  for (const key in globalObjects) {
    globalKeys.push(key)
    globalValues.push(globalObjects[key])
  }
  globalKeys.push(body)

  const result = new Function(...globalKeys)
  return result(...globalValues)
}
1267654
function buildNodeHierachy( nodeId, parentObject, json, allNodes, skins ) {

			var node = allNodes[ nodeId ];
			var nodeDef = json.nodes[ nodeId ];

			// build skeleton here as well

			if ( nodeDef.skin !== undefined ) {

				var meshes = node.isGroup === true ? node.children : [ node ];

				for ( var i = 0, il = meshes.length; i < il; i ++ ) {

					var mesh = meshes[ i ];
					var skinEntry = skins[ nodeDef.skin ];

					var bones = [];
					var boneInverses = [];

					for ( var j = 0, jl = skinEntry.joints.length; j < jl; j ++ ) {

						var jointId = skinEntry.joints[ j ];
						var jointNode = allNodes[ jointId ];

						if ( jointNode ) {

							bones.push( jointNode );

							var mat = new THREE.Matrix4();

							if ( skinEntry.inverseBindMatrices !== undefined ) {

								mat.fromArray( skinEntry.inverseBindMatrices.array, j * 16 );

							}

							boneInverses.push( mat );

						} else {

							console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', jointId );

						}

					}

					mesh.bind( new THREE.Skeleton( bones, boneInverses ), mesh.matrixWorld );

				}

			}

			// build node hierachy

			parentObject.add( node );

			if ( nodeDef.children ) {

				var children = nodeDef.children;

				for ( var i = 0, il = children.length; i < il; i ++ ) {

					var child = children[ i ];
					buildNodeHierachy( child, node, json, allNodes, skins );

				}

			}

		}
709026
function () {
        var flipX = this.flipX;
        var flipY = this.flipY;
        var bones = this.bones;
        for (var i = 0, n = bones.length; i < n; i++)
            bones[i].updateWorldTransform(flipX, flipY);
    }
821153
function _getWorldPositionFromLocalPosition(transform) {
  if (transform.parent === undefined)
    return transform.localPosition;
  else
    return transform.parent.position.add(transform.parent.rotation.mulVector3(transform.localPosition));
}
1365533
function( body ){

            var notify;

            // don't allow duplicates
            if ( this.has( body ) ){
                return this;
            }

            body.setWorld( this );
            this._bodies.push( body );

            this.emit( 'add:body', {
                body: body
            });

            return this;
        }
688938
function() {

        // disable gravity
        me.sys.gravity = 0;

        // load a level
        me.levelDirector.loadLevel("isometric");

        // display a basic tile selector
        me.game.world.addChild(new (me.Renderable.extend({
            /** Constructor */
            init: function() {
                // reference to the main layer
                this.refLayer = me.game.world.getChildByName("level 1")[0];

                // call the parent constructor using the tile size
                this._super(me.Renderable, 'init', [ 0, 0,
                    this.refLayer.tilewidth / 2,
                    this.refLayer.tileheight
                ]);

                this.anchorPoint.set(0, 0);

                // configure it as floating
                this.floating = true;

                // create a corresponding diamond polygon shape with an isometric projection
                this.diamondShape = this.clone().toPolygon().toIso();

                // currently selected tile
                this.currentTile = null;

                // simple font to display tile coordinates
                this.font = new me.Font("Arial", 10, "#FFFFFF");
                this.font.textAlign = "center";

                // dirty flag to enable/disable redraw
                this.dirty = false;

                this.isKinematic = false;

                // subscribe to pointer and viewport move event
                this.pointerEvent = me.event.subscribe("pointermove", this.pointerMove.bind(this));
                this.viewportEvent = me.event.subscribe(me.event.VIEWPORT_ONCHANGE, this.viewportMove.bind(this));
            },
            /** pointer move event callback */
            pointerMove : function (event) {
                var tile = this.refLayer.getTile(event.gameWorldX, event.gameWorldY);
                if (tile && tile !== this.currentTile) {
                    // get the tile x/y world isometric coordinates
                    this.refLayer.getRenderer().tileToPixelCoords(tile.col, tile.row, this.diamondShape.pos);
                    // convert thhe diamon shape pos to floating coordinates
                    me.game.viewport.worldToLocal(
                        this.diamondShape.pos.x,
                        this.diamondShape.pos.y,
                        this.diamondShape.pos
                    );
                    // store the current tile
                    this.currentTile = tile;
                };
            },
            /** viewport move event callback */
            viewportMove : function (pos) {
                // invalidate the current tile when the viewport is moved
                this.currentTile = null;
            },
            /** Update function */
            update : function (dt) {
                return (typeof(this.currentTile) === "object");
            },
            /** draw function */
            draw: function(renderer) {
                if (this.currentTile) {
                    // draw our diamond shape
                    renderer.save();
                    renderer.setColor("#FF0000");
                    renderer.stroke(this.diamondShape);

                    renderer.setColor("#FFFFFF");
                    // draw the tile col/row in the middle
                    this.font.draw (
                        renderer,
                        "( " + this.currentTile.col + "/" + this.currentTile.row + " )",
                        this.diamondShape.pos.x,
                        (this.diamondShape.pos.y + (this.currentTile.height / 2) - 8)
                    );
                    renderer.restore();
                }
            }
        })));

        // register on mouse event
        me.input.registerPointerEvent("pointermove", me.game.viewport, function (event) {
            me.event.publish("pointermove", [ event ]);
        }, false);
    }
645349
function () {

		var targetObject = this.node,
			parsedPath = this.parsedPath,

			objectName = parsedPath.objectName,
			propertyName = parsedPath.propertyName,
			propertyIndex = parsedPath.propertyIndex;

		if ( ! targetObject ) {

			targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;

			this.node = targetObject;

		}

		// set fail state so we can just 'return' on error
		this.getValue = this._getValue_unavailable;
		this.setValue = this._setValue_unavailable;

		// ensure there is a value node
		if ( ! targetObject ) {

			console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
			return;

		}

		if ( objectName ) {

			var objectIndex = parsedPath.objectIndex;

			// special cases were we need to reach deeper into the hierarchy to get the face materials....
			switch ( objectName ) {

				case 'materials':

					if ( ! targetObject.material ) {

						console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
						return;

					}

					if ( ! targetObject.material.materials ) {

						console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
						return;

					}

					targetObject = targetObject.material.materials;

					break;

				case 'bones':

					if ( ! targetObject.skeleton ) {

						console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
						return;

					}

					// potential future optimization: skip this if propertyIndex is already an integer
					// and convert the integer string to a true integer.

					targetObject = targetObject.skeleton.bones;

					// support resolving morphTarget names into indices.
					for ( var i = 0; i < targetObject.length; i ++ ) {

						if ( targetObject[ i ].name === objectIndex ) {

							objectIndex = i;
							break;

						}

					}

					break;

				default:

					if ( targetObject[ objectName ] === undefined ) {

						console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
						return;

					}

					targetObject = targetObject[ objectName ];

			}


			if ( objectIndex !== undefined ) {

				if ( targetObject[ objectIndex ] === undefined ) {

					console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
					return;

				}

				targetObject = targetObject[ objectIndex ];

			}

		}

		// resolve property
		var nodeProperty = targetObject[ propertyName ];

		if ( nodeProperty === undefined ) {

			var nodeName = parsedPath.nodeName;

			console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
				'.' + propertyName + ' but it wasn\'t found.', targetObject );
			return;

		}

		// determine versioning scheme
		var versioning = this.Versioning.None;

		this.targetObject = targetObject;

		if ( targetObject.needsUpdate !== undefined ) { // material

			versioning = this.Versioning.NeedsUpdate;

		} else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform

			versioning = this.Versioning.MatrixWorldNeedsUpdate;

		}

		// determine how the property gets bound
		var bindingType = this.BindingType.Direct;

		if ( propertyIndex !== undefined ) {

			// access a sub element of the property array (only primitives are supported right now)

			if ( propertyName === "morphTargetInfluences" ) {

				// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.

				// support resolving morphTarget names into indices.
				if ( ! targetObject.geometry ) {

					console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
					return;

				}

				if ( targetObject.geometry.isBufferGeometry ) {

					if ( ! targetObject.geometry.morphAttributes ) {

						console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
						return;

					}

					for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {

						if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {

							propertyIndex = i;
							break;

						}

					}


				} else {

					if ( ! targetObject.geometry.morphTargets ) {

						console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
						return;

					}

					for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {

						if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {

							propertyIndex = i;
							break;

						}

					}

				}

			}

			bindingType = this.BindingType.ArrayElement;

			this.resolvedProperty = nodeProperty;
			this.propertyIndex = propertyIndex;

		} else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {

			// must use copy for Object3D.Euler/Quaternion

			bindingType = this.BindingType.HasFromToArray;

			this.resolvedProperty = nodeProperty;

		} else if ( Array.isArray( nodeProperty ) ) {

			bindingType = this.BindingType.EntireArray;

			this.resolvedProperty = nodeProperty;

		} else {

			this.propertyName = propertyName;

		}

		// select getter / setter
		this.getValue = this.GetterByBindingType[ bindingType ];
		this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];

	}
478978
function ()
	{
		for ( var cli in ZeroClipboard_TableTools.clients )
		{
			if ( cli )
			{
				var client = ZeroClipboard_TableTools.clients[cli];
				if ( typeof client.domElement != 'undefined' &&
					 client.domElement.parentNode )
				{
					client.positionElement();
				}
			}
		}
	}
103554
function () {
    var data = this.data;
    var els;

    // If objects not defined, intersect with everything.
    els = data.objects
      ? this.el.sceneEl.querySelectorAll(data.objects)
      : this.el.sceneEl.querySelectorAll('*');
    this.objects = this.flattenObject3DMaps(els);
    this.dirty = false;
  }