diff --git a/build/cannon.demo.js b/build/cannon.demo.js index 7c757ac75..16a8f7e3e 100644 --- a/build/cannon.demo.js +++ b/build/cannon.demo.js @@ -210,7 +210,7 @@ CANNON.Demo = function(options){ * Add a scene to the demo app * @method addScene * @param {String} title Title of the scene - * @param {Function} A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc. + * @param {Function} initfunc A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc. */ function addScene(title,initfunc){ if(typeof(title) !== "string"){ @@ -815,6 +815,7 @@ CANNON.Demo = function(options){ function changeScene(n){ + that.dispatchEvent({ type: 'destroy' }); settings.paused = false; updategui(); buildScene(n); @@ -880,6 +881,8 @@ CANNON.Demo = function(options){ }; } }; +CANNON.Demo.prototype = new CANNON.EventTarget(); +CANNON.Demo.constructor = CANNON.Demo; CANNON.Demo.prototype.setGlobalSpookParams = function(k,d,h){ var world = this.world; @@ -1070,6 +1073,27 @@ CANNON.Demo.prototype.shape2mesh = function(body){ mesh = new THREE.Mesh(geometry, this.currentMaterial); break; + case CANNON.Shape.types.TRIMESH: + var geometry = new THREE.Geometry(); + + var v0 = new CANNON.Vec3(); + var v1 = new CANNON.Vec3(); + var v2 = new CANNON.Vec3(); + for (var i = 0; i < shape.indices.length / 3; i++) { + shape.getTriangleVertices(i, v0, v1, v2); + geometry.vertices.push( + new THREE.Vector3(v0.x, v0.y, v0.z), + new THREE.Vector3(v1.x, v1.y, v1.z), + new THREE.Vector3(v2.x, v2.y, v2.z) + ); + var j = geometry.vertices.length - 3; + geometry.faces.push(new THREE.Face3(j, j+1, j+2)); + } + geometry.computeBoundingSphere(); + geometry.computeFaceNormals(); + mesh = new THREE.Mesh(geometry, this.currentMaterial); + break; + default: throw "Visual type not recognized: "+shape.type; } diff --git a/build/cannon.js b/build/cannon.js index 4640474cc..331ecc5fe 100644 --- a/build/cannon.js +++ b/build/cannon.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 cannon.js Authors + * Copyright (c) 2015 cannon.js Authors * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -24,7 +24,7 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&false)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.CANNON=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o (http://steffe.se)", @@ -72,6 +72,7 @@ module.exports={ module.exports = { version : _dereq_('../package.json').version, + AABB : _dereq_('./collision/AABB'), ArrayCollisionMatrix : _dereq_('./collision/ArrayCollisionMatrix'), Body : _dereq_('./objects/Body'), Box : _dereq_('./shapes/Box'), @@ -79,6 +80,7 @@ module.exports = { Constraint : _dereq_('./constraints/Constraint'), ContactEquation : _dereq_('./equations/ContactEquation'), Narrowphase : _dereq_('./world/Narrowphase'), + ConeTwistConstraint : _dereq_('./constraints/ConeTwistConstraint'), ContactMaterial : _dereq_('./material/ContactMaterial'), ConvexPolyhedron : _dereq_('./shapes/ConvexPolyhedron'), Cylinder : _dereq_('./shapes/Cylinder'), @@ -90,6 +92,7 @@ module.exports = { GridBroadphase : _dereq_('./collision/GridBroadphase'), Heightfield : _dereq_('./shapes/Heightfield'), HingeConstraint : _dereq_('./constraints/HingeConstraint'), + LockConstraint : _dereq_('./constraints/LockConstraint'), Mat3 : _dereq_('./math/Mat3'), Material : _dereq_('./material/Material'), NaiveBroadphase : _dereq_('./collision/NaiveBroadphase'), @@ -112,12 +115,13 @@ module.exports = { Sphere : _dereq_('./shapes/Sphere'), SplitSolver : _dereq_('./solver/SplitSolver'), Spring : _dereq_('./objects/Spring'), + Trimesh : _dereq_('./shapes/Trimesh'), Vec3 : _dereq_('./math/Vec3'), Vec3Pool : _dereq_('./utils/Vec3Pool'), World : _dereq_('./world/World'), }; -},{"../package.json":1,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/Constraint":12,"./constraints/DistanceConstraint":13,"./constraints/HingeConstraint":14,"./constraints/PointToPointConstraint":15,"./equations/ContactEquation":16,"./equations/Equation":17,"./equations/FrictionEquation":18,"./equations/RotationalEquation":19,"./equations/RotationalMotorEquation":20,"./material/ContactMaterial":21,"./material/Material":22,"./math/Mat3":24,"./math/Quaternion":25,"./math/Vec3":27,"./objects/Body":28,"./objects/RaycastVehicle":29,"./objects/RigidVehicle":30,"./objects/SPHSystem":31,"./objects/Spring":32,"./shapes/Box":34,"./shapes/ConvexPolyhedron":35,"./shapes/Cylinder":36,"./shapes/Heightfield":37,"./shapes/Particle":38,"./shapes/Plane":39,"./shapes/Shape":40,"./shapes/Sphere":41,"./solver/GSSolver":42,"./solver/Solver":43,"./solver/SplitSolver":44,"./utils/EventTarget":45,"./utils/Pool":46,"./utils/Vec3Pool":49,"./world/Narrowphase":50,"./world/World":51}],3:[function(_dereq_,module,exports){ +},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(_dereq_,module,exports){ var Vec3 = _dereq_('../math/Vec3'); var Utils = _dereq_('../utils/Utils'); @@ -127,9 +131,9 @@ module.exports = AABB; * Axis aligned bounding box class. * @class AABB * @constructor - * @param {Object} [options] - * @param {Array} [options.upperBound] - * @param {Array} [options.lowerBound] + * @param {Object} [options] + * @param {Vec3} [options.upperBound] + * @param {Vec3} [options.lowerBound] */ function AABB(options){ options = options || {}; @@ -137,7 +141,7 @@ function AABB(options){ /** * The lower bound of the bounding box. * @property lowerBound - * @type {Array} + * @type {Vec3} */ this.lowerBound = new Vec3(); if(options.lowerBound){ @@ -147,7 +151,7 @@ function AABB(options){ /** * The upper bound of the bounding box. * @property upperBound - * @type {Array} + * @type {Vec3} */ this.upperBound = new Vec3(); if(options.upperBound){ @@ -164,6 +168,7 @@ var tmp = new Vec3(); * @param {Vec3} position * @param {Quaternion} quaternion * @param {number} skinSize + * @return {AABB} The self object */ AABB.prototype.setFromPoints = function(points, position, quaternion, skinSize){ var l = this.lowerBound, @@ -207,16 +212,28 @@ AABB.prototype.setFromPoints = function(points, position, quaternion, skinSize){ u.y += skinSize; u.z += skinSize; } + + return this; }; /** * Copy bounds from an AABB to this AABB * @method copy * @param {AABB} aabb Source to copy from + * @return {AABB} The this object, for chainability */ AABB.prototype.copy = function(aabb){ this.lowerBound.copy(aabb.lowerBound); this.upperBound.copy(aabb.upperBound); + return this; +}; + +/** + * Clone an AABB + * @method clone + */ +AABB.prototype.clone = function(){ + return new AABB().copy(this); }; /** @@ -284,7 +301,129 @@ AABB.prototype.overlaps = function(aabb){ ((l2.z <= u1.z && u1.z <= u2.z) || (l1.z <= u2.z && u2.z <= u1.z)); }; -},{"../math/Vec3":27,"../utils/Utils":48}],4:[function(_dereq_,module,exports){ +/** + * Returns true if the given AABB is fully contained in this AABB. + * @method contains + * @param {AABB} aabb + * @return {Boolean} + */ +AABB.prototype.contains = function(aabb){ + var l1 = this.lowerBound, + u1 = this.upperBound, + l2 = aabb.lowerBound, + u2 = aabb.upperBound; + + // l2 u2 + // |---------| + // |---------------| + // l1 u1 + + return ( + (l1.x <= l2.x && u1.x >= u2.x) && + (l1.y <= l2.y && u1.y >= u2.y) && + (l1.z <= l2.z && u1.z >= u2.z) + ); +}; + +/** + * @method getCorners + * @param {Vec3} a + * @param {Vec3} b + * @param {Vec3} c + * @param {Vec3} d + * @param {Vec3} e + * @param {Vec3} f + * @param {Vec3} g + * @param {Vec3} h + */ +AABB.prototype.getCorners = function(a, b, c, d, e, f, g, h){ + var l = this.lowerBound, + u = this.upperBound; + + a.copy(l); + b.set( u.x, l.y, l.z ); + c.set( u.x, u.y, l.z ); + d.set( l.x, u.y, u.z ); + e.set( u.x, l.y, l.z ); + f.set( l.x, u.y, l.z ); + g.set( l.x, l.y, u.z ); + h.copy(u); +}; + +var transformIntoFrame_corners = [ + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3() +]; + +/** + * Get the representation of an AABB in another frame. + * @method toLocalFrame + * @param {Transform} frame + * @param {AABB} target + * @return {AABB} The "target" AABB object. + */ +AABB.prototype.toLocalFrame = function(frame, target){ + + var corners = transformIntoFrame_corners; + var a = corners[0]; + var b = corners[1]; + var c = corners[2]; + var d = corners[3]; + var e = corners[4]; + var f = corners[5]; + var g = corners[6]; + var h = corners[7]; + + // Get corners in current frame + this.getCorners(a, b, c, d, e, f, g, h); + + // Transform them to new local frame + for(var i=0; i !== 8; i++){ + var corner = corners[i]; + frame.pointToLocal(corner, corner); + } + + return target.setFromPoints(corners); +}; + +/** + * Get the representation of an AABB in the global frame. + * @method toWorldFrame + * @param {Transform} frame + * @param {AABB} target + * @return {AABB} The "target" AABB object. + */ +AABB.prototype.toWorldFrame = function(frame, target){ + + var corners = transformIntoFrame_corners; + var a = corners[0]; + var b = corners[1]; + var c = corners[2]; + var d = corners[3]; + var e = corners[4]; + var f = corners[5]; + var g = corners[6]; + var h = corners[7]; + + // Get corners in current frame + this.getCorners(a, b, c, d, e, f, g, h); + + // Transform them to new local frame + for(var i=0; i !== 8; i++){ + var corner = corners[i]; + frame.pointToWorld(corner, corner); + } + + return target.setFromPoints(corners); +}; + +},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(_dereq_,module,exports){ module.exports = ArrayCollisionMatrix; /** @@ -559,13 +698,14 @@ Broadphase.boundingSphereCheck = function(bodyA,bodyB){ * @method aabbQuery * @param {World} world * @param {AABB} aabb + * @param {array} result An array to store resulting bodies in. * @return {array} */ -Broadphase.prototype.aabbQuery = function(world, aabb){ +Broadphase.prototype.aabbQuery = function(world, aabb, result){ console.warn('.aabbQuery is not implemented in this Broadphase subclass.'); return []; }; -},{"../math/Quaternion":25,"../math/Vec3":27,"../objects/Body":28,"../shapes/Plane":39,"../shapes/Shape":40}],6:[function(_dereq_,module,exports){ +},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Plane":42,"../shapes/Shape":43}],6:[function(_dereq_,module,exports){ module.exports = GridBroadphase; var Broadphase = _dereq_('./Broadphase'); @@ -795,7 +935,7 @@ GridBroadphase.prototype.collisionPairs = function(world,pairs1,pairs2){ this.makePairsUnique(pairs1,pairs2); }; -},{"../math/Vec3":27,"../shapes/Shape":40,"./Broadphase":5}],7:[function(_dereq_,module,exports){ +},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(_dereq_,module,exports){ module.exports = NaiveBroadphase; var Broadphase = _dereq_('./Broadphase'); @@ -862,7 +1002,7 @@ NaiveBroadphase.prototype.aabbQuery = function(world, aabb, result){ b.computeAABB(); } - // Ugly hack until RigidBody gets aabb + // Ugly hack until Body gets aabb if(b.aabb.overlaps(aabb)){ result.push(b); } @@ -973,6 +1113,10 @@ function Ray(from, to){ */ this.to = to ? to.clone() : new Vec3(); + /** + * @private + * @property {Vec3} _direction + */ this._direction = new Vec3(); /** @@ -986,15 +1130,98 @@ function Ray(from, to){ * @property {Boolean} checkCollisionResponse */ this.checkCollisionResponse = true; + + /** + * If set to true, the ray skips any hits with normal.dot(rayDirection) < 0. + * @property {Boolean} skipBackfaces + */ + this.skipBackfaces = false; + + /** + * @property {number} collisionFilterMask + * @default -1 + */ + this.collisionFilterMask = -1; + + /** + * @property {number} collisionFilterGroup + * @default -1 + */ + this.collisionFilterGroup = -1; + + /** + * The intersection mode. Should be Ray.ANY, Ray.ALL or Ray.CLOSEST. + * @property {number} mode + */ + this.mode = Ray.ANY; + + /** + * Current result object. + * @property {RaycastResult} result + */ + this.result = new RaycastResult(); + + /** + * Will be set to true during intersectWorld() if the ray hit anything. + * @property {Boolean} hasHit + */ + this.hasHit = false; + + /** + * Current, user-provided result callback. Will be used if mode is Ray.ALL. + * @property {Function} callback + */ + this.callback = function(result){}; } Ray.prototype.constructor = Ray; +Ray.CLOSEST = 1; +Ray.ANY = 2; +Ray.ALL = 4; + +var tmpAABB = new AABB(); +var tmpArray = []; + +/** + * Do itersection against all bodies in the given World. + * @method intersectWorld + * @param {World} world + * @param {object} options + * @return {Boolean} True if the ray hit anything, otherwise false. + */ +Ray.prototype.intersectWorld = function (world, options) { + this.mode = options.mode || Ray.ANY; + this.result = options.result || new RaycastResult(); + this.skipBackfaces = !!options.skipBackfaces; + this.collisionFilterMask = typeof(options.collisionFilterMask) !== 'undefined' ? options.collisionFilterMask : -1; + this.collisionFilterGroup = typeof(options.collisionFilterGroup) !== 'undefined' ? options.collisionFilterGroup : -1; + if(options.from){ + this.from.copy(options.from); + } + if(options.to){ + this.to.copy(options.to); + } + this.callback = options.callback || function(){}; + this.hasHit = false; + + this.result.reset(); + this._updateDirection(); + + this.getAABB(tmpAABB); + tmpArray.length = 0; + world.broadphase.aabbQuery(world, tmpAABB, tmpArray); + this.intersectBodies(tmpArray); + + return this.hasHit; +}; + var v1 = new Vec3(), v2 = new Vec3(); /* * As per "Barycentric Technique" as named here http://www.blackpawn.com/texts/pointinpoly/default.html But without the division */ +Ray.pointInTriangle = pointInTriangle; function pointInTriangle(p, a, b, c) { c.vsub(a,v0); b.vsub(a,v1); @@ -1018,24 +1245,29 @@ function pointInTriangle(p, a, b, c) { * @method intersectBody * @private * @param {Body} body - * @param {RaycastResult} result - * @param {Vec3} [direction] + * @param {RaycastResult} [result] Deprecated - set the result property of the Ray instead. */ -Ray.prototype.intersectBody = function (body, result, direction) { +var intersectBody_xi = new Vec3(); +var intersectBody_qi = new Quaternion(); +Ray.prototype.intersectBody = function (body, result) { + if(result){ + this.result = result; + this._updateDirection(); + } var checkCollisionResponse = this.checkCollisionResponse; if(checkCollisionResponse && !body.collisionResponse){ - return result; + return; } - if(!direction){ - this._updateDirection(); - direction = this._direction; + if((this.collisionFilterGroup & body.collisionFilterMask)===0 || (body.collisionFilterGroup & this.collisionFilterMask)===0){ + return; } - var xi = new Vec3(); - var qi = new Quaternion(); - for (var i = 0; i < body.shapes.length; i++) { + var xi = intersectBody_xi; + var qi = intersectBody_qi; + + for (var i = 0, N = body.shapes.length; i < N; i++) { var shape = body.shapes[i]; if(checkCollisionResponse && !shape.collisionResponse){ @@ -1050,33 +1282,36 @@ Ray.prototype.intersectBody = function (body, result, direction) { shape, qi, xi, - body, - direction, - result + body ); - } - return result; + if(this.result._shouldStop){ + break; + } + } }; /** * @method intersectBodies * @param {Array} bodies An array of Body objects. - * @param {RaycastResult} result + * @param {RaycastResult} [result] Deprecated */ Ray.prototype.intersectBodies = function (bodies, result) { - this._updateDirection(); - var direction = this._direction; - - if(result instanceof RaycastResult){ - result.reset(); + if(result){ + this.result = result; + this._updateDirection(); } - for ( var i = 0, l = bodies.length; i < l; i ++ ) { - this.intersectBody(bodies[i], result, direction); + for ( var i = 0, l = bodies.length; !this.result._shouldStop && i < l; i ++ ) { + this.intersectBody(bodies[i]); } }; +/** + * Updates the _direction vector. + * @private + * @method _updateDirection + */ Ray.prototype._updateDirection = function(){ this.to.vsub(this.from, this._direction); this._direction.normalize(); @@ -1089,21 +1324,21 @@ Ray.prototype._updateDirection = function(){ * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectShape = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectShape = function(shape, quat, position, body){ var from = this.from; + // Checking boundingSphere - var distance = distanceFromIntersection(from, direction, position); + var distance = distanceFromIntersection(from, this._direction, position); if ( distance > shape.boundingSphereRadius ) { - return result; + return; } - this[shape.type](shape, quat, position, body, direction, result); - - return result; + var intersectMethod = this[shape.type]; + if(intersectMethod){ + intersectMethod.call(this, shape, quat, position, body); + } }; var vector = new Vec3(); @@ -1124,11 +1359,9 @@ var tmpRaycastResult = new RaycastResult(); * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectBox = function(shape, quat, position, body, direction, result){ - return this.intersectConvex(shape.convexPolyhedronRepresentation, quat, position, body, direction, result); +Ray.prototype.intersectBox = function(shape, quat, position, body){ + return this.intersectConvex(shape.convexPolyhedronRepresentation, quat, position, body); }; Ray.prototype[Shape.types.BOX] = Ray.prototype.intersectBox; @@ -1139,12 +1372,11 @@ Ray.prototype[Shape.types.BOX] = Ray.prototype.intersectBox; * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectPlane = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectPlane = function(shape, quat, position, body){ var from = this.from; var to = this.to; + var direction = this._direction; // Get plane normal var worldNormal = new Vec3(0, 0, 1); @@ -1158,18 +1390,18 @@ Ray.prototype.intersectPlane = function(shape, quat, position, body, direction, if(planeToFrom * planeToTo > 0){ // "from" and "to" are on the same side of the plane... bail out - return result; + return; } if(from.distanceTo(to) < planeToFrom){ - return result; + return; } var n_dot_dir = worldNormal.dot(direction); if (Math.abs(n_dot_dir) < this.precision) { // No intersection - return result; + return; } var planePointToFrom = new Vec3(); @@ -1181,16 +1413,12 @@ Ray.prototype.intersectPlane = function(shape, quat, position, body, direction, direction.scale(t, dir_scaled_with_t); from.vadd(dir_scaled_with_t, hitPointWorld); - if(this.reportIntersection(worldNormal, hitPointWorld, shape, body, result)){ - return result; - } - - return result; + this.reportIntersection(worldNormal, hitPointWorld, shape, body, -1); }; Ray.prototype[Shape.types.PLANE] = Ray.prototype.intersectPlane; /** - * Get the AABB of the ray. + * Get the world AABB of the ray. * @method getAABB * @param {AABB} aabb */ @@ -1216,10 +1444,8 @@ var intersectConvexOptions = { * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectHeightfield = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectHeightfield = function(shape, quat, position, body){ var data = shape.data, w = shape.elementSize, worldPillarOffset = new Vec3(); @@ -1252,7 +1478,7 @@ Ray.prototype.intersectHeightfield = function(shape, quat, position, body, direc } if(iMinX === null){ - return result; + return; } var minMax = []; @@ -1271,22 +1497,31 @@ Ray.prototype.intersectHeightfield = function(shape, quat, position, body, direc for(var i = iMinX; i <= iMaxX; i++){ for(var j = iMinY; j <= iMaxY; j++){ + if(this.result._shouldStop){ + return; + } + // Lower triangle shape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset); - this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, direction, result, intersectConvexOptions); + this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, intersectConvexOptions); + + if(this.result._shouldStop){ + return; + } // Upper triangle shape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset); - this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, direction, result, intersectConvexOptions); + this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, intersectConvexOptions); } } - - return result; }; Ray.prototype[Shape.types.HEIGHTFIELD] = Ray.prototype.intersectHeightfield; +var Ray_intersectSphere_intersectionPoint = new Vec3(); +var Ray_intersectSphere_normal = new Vec3(); + /** * @method intersectSphere * @private @@ -1294,10 +1529,8 @@ Ray.prototype[Shape.types.HEIGHTFIELD] = Ray.prototype.intersectHeightfield; * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectSphere = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectSphere = function(shape, quat, position, body){ var from = this.from, to = this.to, r = shape.radius; @@ -1308,45 +1541,44 @@ Ray.prototype.intersectSphere = function(shape, quat, position, body, direction, var delta = Math.pow(b, 2) - 4 * a * c; + var intersectionPoint = Ray_intersectSphere_intersectionPoint; + var normal = Ray_intersectSphere_normal; + if(delta < 0){ // No intersection - return result; + return; } else if(delta === 0){ // single intersection point - var intersectionPoint = new Vec3(); from.lerp(to, delta, intersectionPoint); - var normal = new Vec3(); intersectionPoint.vsub(position, normal); normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; - } + this.reportIntersection(normal, intersectionPoint, shape, body, -1); + } else { var d1 = (- b - Math.sqrt(delta)) / (2 * a); var d2 = (- b + Math.sqrt(delta)) / (2 * a); - var intersectionPoint = new Vec3(); - from.lerp(to, d1, intersectionPoint); - var normal = new Vec3(); - intersectionPoint.vsub(position, normal); - normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; + if(d1 >= 0 && d1 <= 1){ + from.lerp(to, d1, intersectionPoint); + intersectionPoint.vsub(position, normal); + normal.normalize(); + this.reportIntersection(normal, intersectionPoint, shape, body, -1); } - from.lerp(to, d2, intersectionPoint); - var normal = new Vec3(); - intersectionPoint.vsub(position, normal); - normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; + if(this.result._shouldStop){ + return; } - } - return result; + if(d2 >= 0 && d2 <= 1){ + from.lerp(to, d2, intersectionPoint); + intersectionPoint.vsub(position, normal); + normal.normalize(); + this.reportIntersection(normal, intersectionPoint, shape, body, -1); + } + } }; Ray.prototype[Shape.types.SPHERE] = Ray.prototype.intersectSphere; @@ -1363,12 +1595,16 @@ var intersectConvex_vector = new Vec3(); * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result * @param {object} [options] * @param {array} [options.faceList] */ -Ray.prototype.intersectConvex = function intersectConvex(shape, quat, position, body, direction, result, options){ +Ray.prototype.intersectConvex = function intersectConvex( + shape, + quat, + position, + body, + options +){ var minDistNormal = intersectConvex_minDistNormal; var normal = intersectConvex_normal; var vector = intersectConvex_vector; @@ -1379,16 +1615,17 @@ Ray.prototype.intersectConvex = function intersectConvex(shape, quat, position, var faces = shape.faces, vertices = shape.vertices, normals = shape.faceNormals; + var direction = this._direction; var from = this.from; var to = this.to; var fromToDistance = from.distanceTo(to); - var reportClosest = result instanceof RaycastResult; var minDist = -1; var Nfaces = faceList ? faceList.length : faces.length; + var result = this.result; - for (var j = 0; j < Nfaces; j++) { + for (var j = 0; !result._shouldStop && j < Nfaces; j++) { var fi = faceList ? faceList[j] : j; var face = faces[fi]; @@ -1426,49 +1663,163 @@ Ray.prototype.intersectConvex = function intersectConvex(shape, quat, position, continue; } - if (dot < 0) { + // if (dot < 0) { - // Intersection point is from + direction * scalar - direction.mult(scalar,intersectPoint); - intersectPoint.vadd(from,intersectPoint); + // Intersection point is from + direction * scalar + direction.mult(scalar,intersectPoint); + intersectPoint.vadd(from,intersectPoint); - // a is the point we compare points b and c with. - a.copy(vertices[face[0]]); - q.vmult(a,a); - x.vadd(a,a); + // a is the point we compare points b and c with. + a.copy(vertices[face[0]]); + q.vmult(a,a); + x.vadd(a,a); - for(var i = 1; i < face.length - 1; i++){ - // Transform 3 vertices to world coords - b.copy(vertices[face[i]]); - c.copy(vertices[face[i+1]]); - q.vmult(b,b); - q.vmult(c,c); - x.vadd(b,b); - x.vadd(c,c); + for(var i = 1; !result._shouldStop && i < face.length - 1; i++){ + // Transform 3 vertices to world coords + b.copy(vertices[face[i]]); + c.copy(vertices[face[i+1]]); + q.vmult(b,b); + q.vmult(c,c); + x.vadd(b,b); + x.vadd(c,c); - var distance = intersectPoint.distanceTo(from); + var distance = intersectPoint.distanceTo(from); - if(!pointInTriangle(intersectPoint, a, b, c) || distance > fromToDistance){ - continue; - } - - if(minDist === -1 || distance < minDist){ - minDist = distance; - minDistNormal.copy(normal); - minDistIntersect.copy(intersectPoint); - } + if(!(pointInTriangle(intersectPoint, a, b, c) || pointInTriangle(intersectPoint, b, a, c)) || distance > fromToDistance){ + continue; } + + this.reportIntersection(normal, intersectPoint, shape, body, fi); } + // } } +}; +Ray.prototype[Shape.types.CONVEXPOLYHEDRON] = Ray.prototype.intersectConvex; - if(minDist !== -1 && this.reportIntersection(minDistNormal, minDistIntersect, shape, body, result)){ - return result; - } +var intersectTrimesh_normal = new Vec3(); +var intersectTrimesh_localDirection = new Vec3(); +var intersectTrimesh_localFrom = new Vec3(); +var intersectTrimesh_localTo = new Vec3(); +var intersectTrimesh_worldNormal = new Vec3(); +var intersectTrimesh_worldIntersectPoint = new Vec3(); +var intersectTrimesh_localAABB = new AABB(); +var intersectTrimesh_triangles = []; +var intersectTrimesh_treeTransform = new Transform(); - return result; +/** + * @method intersectTrimesh + * @private + * @param {Shape} shape + * @param {Quaternion} quat + * @param {Vec3} position + * @param {Body} body + * @param {object} [options] + * @todo Optimize by transforming the world to local space first. + * @todo Use Octree lookup + */ +Ray.prototype.intersectTrimesh = function intersectTrimesh( + mesh, + quat, + position, + body, + options +){ + var normal = intersectTrimesh_normal; + var triangles = intersectTrimesh_triangles; + var treeTransform = intersectTrimesh_treeTransform; + var minDistNormal = intersectConvex_minDistNormal; + var vector = intersectConvex_vector; + var minDistIntersect = intersectConvex_minDistIntersect; + var localAABB = intersectTrimesh_localAABB; + var localDirection = intersectTrimesh_localDirection; + var localFrom = intersectTrimesh_localFrom; + var localTo = intersectTrimesh_localTo; + var worldIntersectPoint = intersectTrimesh_worldIntersectPoint; + var worldNormal = intersectTrimesh_worldNormal; + var faceList = (options && options.faceList) || null; + + // Checking faces + var indices = mesh.indices, + vertices = mesh.vertices, + normals = mesh.faceNormals; + + var from = this.from; + var to = this.to; + var direction = this._direction; + + var minDist = -1; + treeTransform.position.copy(position); + treeTransform.quaternion.copy(quat); + + // Transform ray to local space! + Transform.vectorToLocalFrame(position, quat, direction, localDirection); + //body.vectorToLocalFrame(direction, localDirection); + Transform.pointToLocalFrame(position, quat, from, localFrom); + //body.pointToLocalFrame(from, localFrom); + Transform.pointToLocalFrame(position, quat, to, localTo); + //body.pointToLocalFrame(to, localTo); + var fromToDistanceSquared = localFrom.distanceSquared(localTo); + + mesh.tree.rayQuery(this, treeTransform, triangles); + + for (var i = 0, N = triangles.length; !this.result._shouldStop && i !== N; i++) { + var trianglesIndex = triangles[i]; + + mesh.getNormal(trianglesIndex, normal); + + // determine if ray intersects the plane of the face + // note: this works regardless of the direction of the face normal + + // Get plane point in world coordinates... + mesh.getVertex(indices[trianglesIndex * 3], a); + + // ...but make it relative to the ray from. We'll fix this later. + a.vsub(localFrom,vector); + + // Get plane normal + // quat.vmult(normal, normal); + + // If this dot product is negative, we have something interesting + var dot = localDirection.dot(normal); + + // Bail out if ray and plane are parallel + // if (Math.abs( dot ) < this.precision){ + // continue; + // } + + // calc distance to plane + var scalar = normal.dot(vector) / dot; + + // if negative distance, then plane is behind ray + if (scalar < 0){ + continue; + } + + // Intersection point is from + direction * scalar + localDirection.scale(scalar,intersectPoint); + intersectPoint.vadd(localFrom,intersectPoint); + + // Get triangle vertices + mesh.getVertex(indices[trianglesIndex * 3 + 1], b); + mesh.getVertex(indices[trianglesIndex * 3 + 2], c); + + var squaredDistance = intersectPoint.distanceSquared(localFrom); + + if(!(pointInTriangle(intersectPoint, b, a, c) || pointInTriangle(intersectPoint, a, b, c)) || squaredDistance > fromToDistanceSquared){ + continue; + } + + // transform intersectpoint and normal to world + Transform.vectorToWorldFrame(quat, normal, worldNormal); + //body.vectorToWorldFrame(normal, worldNormal); + Transform.pointToWorldFrame(position, quat, intersectPoint, worldIntersectPoint); + //body.pointToWorldFrame(intersectPoint, worldIntersectPoint); + this.reportIntersection(worldNormal, worldIntersectPoint, mesh, body, trianglesIndex); + } + triangles.length = 0; }; +Ray.prototype[Shape.types.TRIMESH] = Ray.prototype.intersectTrimesh; -Ray.prototype[Shape.types.CONVEXPOLYHEDRON] = Ray.prototype.intersectConvex; /** * @method reportIntersection @@ -1477,17 +1828,25 @@ Ray.prototype[Shape.types.CONVEXPOLYHEDRON] = Ray.prototype.intersectConvex; * @param {Vec3} hitPointWorld * @param {Shape} shape * @param {Body} body - * @param {RaycastResult} result * @return {boolean} True if the intersections should continue */ -Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, result){ +Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, hitFaceIndex){ var from = this.from; var to = this.to; var distance = from.distanceTo(hitPointWorld); + var result = this.result; + + // Skip back faces? + if(this.skipBackfaces && normal.dot(this._direction) > 0){ + return; + } - if(!(result instanceof RaycastResult)){ - // Got a callback - tmpRaycastResult.set( + result.hitFaceIndex = typeof(hitFaceIndex) !== 'undefined' ? hitFaceIndex : -1; + + switch(this.mode){ + case Ray.ALL: + this.hasHit = true; + result.set( from, to, normal, @@ -1496,15 +1855,15 @@ Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, body, distance ); - tmpRaycastResult.hasHit = true; - result(tmpRaycastResult); - - return true; + result.hasHit = true; + this.callback(result); + break; - } else { + case Ray.CLOSEST: - // Store if closer than current cloest + // Store if closer than current closest if(distance < result.distance || !result.hasHit){ + this.hasHit = true; result.hasHit = true; result.set( from, @@ -1516,8 +1875,24 @@ Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, distance ); } + break; - return false; + case Ray.ANY: + + // Report and stop. + this.hasHit = true; + result.hasHit = true; + result.set( + from, + to, + normal, + hitPointWorld, + shape, + body, + distance + ); + result._shouldStop = true; + break; } }; @@ -1527,7 +1902,7 @@ function distanceFromIntersection(from, direction, position) { // v0 is vector from from to position position.vsub(from,v0); - var dot = v0.dot( direction ); + var dot = v0.dot(direction); // intersect = direction*dot + from direction.mult(dot,intersect); @@ -1539,7 +1914,7 @@ function distanceFromIntersection(from, direction, position) { } -},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":25,"../math/Transform":26,"../math/Vec3":27,"../shapes/Box":34,"../shapes/ConvexPolyhedron":35,"../shapes/Shape":40}],10:[function(_dereq_,module,exports){ +},{"../collision/AABB":3,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/Box":37,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43}],10:[function(_dereq_,module,exports){ var Vec3 = _dereq_('../math/Vec3'); module.exports = RaycastResult; @@ -1588,11 +1963,27 @@ function RaycastResult(){ */ this.body = null; + /** + * The index of the hit triangle, if the hit shape was a trimesh. + * @property {number} hitFaceIndex + * @default -1 + */ + this.hitFaceIndex = -1; + /** * Distance to the hit. Will be set to -1 if there was no hit. * @property {number} distance + * @default -1 */ this.distance = -1; + + /** + * If the ray should stop traversing the bodies. + * @private + * @property {Boolean} _shouldStop + * @default false + */ + this._shouldStop = false; } /** @@ -1607,7 +1998,16 @@ RaycastResult.prototype.reset = function () { this.hasHit = false; this.shape = null; this.body = null; + this.hitFaceIndex = -1; this.distance = -1; + this._shouldStop = false; +}; + +/** + * @method abort + */ +RaycastResult.prototype.abort = function(){ + this._shouldStop = true; }; /** @@ -1637,7 +2037,7 @@ RaycastResult.prototype.set = function( this.body = body; this.distance = distance; }; -},{"../math/Vec3":27}],11:[function(_dereq_,module,exports){ +},{"../math/Vec3":30}],11:[function(_dereq_,module,exports){ var Shape = _dereq_('../shapes/Shape'); var Broadphase = _dereq_('../collision/Broadphase'); @@ -1851,14 +2251,21 @@ SAPBroadphase.prototype.sortList = function(){ * @return {Boolean} */ SAPBroadphase.checkBounds = function(bi, bj, axisIndex){ - var axis; - if(axisIndex === 0){ axis = 'x'; } - if(axisIndex === 1){ axis = 'y'; } - if(axisIndex === 2){ axis = 'z'; } + var biPos; + var bjPos; + + if(axisIndex === 0){ + biPos = bi.position.x; + bjPos = bj.position.x; + } else if(axisIndex === 1){ + biPos = bi.position.y; + bjPos = bj.position.y; + } else if(axisIndex === 2){ + biPos = bi.position.z; + bjPos = bj.position.z; + } - var biPos = bi.position[axis], - ri = bi.boundingRadius, - bjPos = bj.position[axis], + var ri = bi.boundingRadius, rj = bj.boundingRadius, boundA1 = biPos - ri, boundA2 = biPos + ri, @@ -1954,7 +2361,98 @@ SAPBroadphase.prototype.aabbQuery = function(world, aabb, result){ return result; }; -},{"../collision/Broadphase":5,"../shapes/Shape":40}],12:[function(_dereq_,module,exports){ +},{"../collision/Broadphase":5,"../shapes/Shape":43}],12:[function(_dereq_,module,exports){ +module.exports = ConeTwistConstraint; + +var Constraint = _dereq_('./Constraint'); +var PointToPointConstraint = _dereq_('./PointToPointConstraint'); +var ConeEquation = _dereq_('../equations/ConeEquation'); +var RotationalEquation = _dereq_('../equations/RotationalEquation'); +var ContactEquation = _dereq_('../equations/ContactEquation'); +var Vec3 = _dereq_('../math/Vec3'); + +/** + * @class ConeTwistConstraint + * @constructor + * @author schteppe + * @param {Body} bodyA + * @param {Body} bodyB + * @param {object} [options] + * @param {Vec3} [options.pivotA] + * @param {Vec3} [options.pivotB] + * @param {Vec3} [options.axisA] + * @param {Vec3} [options.axisB] + * @param {Number} [options.maxForce=1e6] + * @extends PointToPointConstraint + */ +function ConeTwistConstraint(bodyA, bodyB, options){ + options = options || {}; + var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6; + + // Set pivot point in between + var pivotA = options.pivotA ? options.pivotA.clone() : new Vec3(); + var pivotB = options.pivotB ? options.pivotB.clone() : new Vec3(); + this.axisA = options.axisA ? options.axisA.clone() : new Vec3(); + this.axisB = options.axisB ? options.axisB.clone() : new Vec3(); + + PointToPointConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce); + + this.collideConnected = !!options.collideConnected; + + this.angle = typeof(options.angle) !== 'undefined' ? options.angle : 0; + + /** + * @property {ConeEquation} coneEquation + */ + var c = this.coneEquation = new ConeEquation(bodyA,bodyB,options); + + /** + * @property {RotationalEquation} twistEquation + */ + var t = this.twistEquation = new RotationalEquation(bodyA,bodyB,options); + this.twistAngle = typeof(options.twistAngle) !== 'undefined' ? options.twistAngle : 0; + + // Make the cone equation push the bodies toward the cone axis, not outward + c.maxForce = 0; + c.minForce = -maxForce; + + // Make the twist equation add torque toward the initial position + t.maxForce = 0; + t.minForce = -maxForce; + + this.equations.push(c, t); +} +ConeTwistConstraint.prototype = new PointToPointConstraint(); +ConeTwistConstraint.constructor = ConeTwistConstraint; + +var ConeTwistConstraint_update_tmpVec1 = new Vec3(); +var ConeTwistConstraint_update_tmpVec2 = new Vec3(); + +ConeTwistConstraint.prototype.update = function(){ + var bodyA = this.bodyA, + bodyB = this.bodyB, + cone = this.coneEquation, + twist = this.twistEquation; + + PointToPointConstraint.prototype.update.call(this); + + // Update the axes to the cone constraint + bodyA.vectorToWorldFrame(this.axisA, cone.axisA); + bodyB.vectorToWorldFrame(this.axisB, cone.axisB); + + // Update the world axes in the twist constraint + this.axisA.tangents(twist.axisA, twist.axisA); + bodyA.vectorToWorldFrame(twist.axisA, twist.axisA); + + this.axisB.tangents(twist.axisB, twist.axisB); + bodyB.vectorToWorldFrame(twist.axisB, twist.axisB); + + cone.angle = this.angle; + twist.maxAngle = this.twistAngle; +}; + + +},{"../equations/ConeEquation":18,"../equations/ContactEquation":19,"../equations/RotationalEquation":22,"../math/Vec3":30,"./Constraint":13,"./PointToPointConstraint":17}],13:[function(_dereq_,module,exports){ module.exports = Constraint; var Utils = _dereq_('../utils/Utils'); @@ -2016,238 +2514,317 @@ function Constraint(bodyA, bodyB, options){ } /** + * Update all the equations with data. * @method update */ Constraint.prototype.update = function(){ throw new Error("method update() not implmemented in this Constraint subclass!"); }; +/** + * Enables all equations in the constraint. + * @method enable + */ +Constraint.prototype.enable = function(){ + var eqs = this.equations; + for(var i=0; i // G = [0 axisA 0 -axisB] - // W = [vi wi vj wj] GA.rotational.copy(axisA); axisB.negate(GB.rotational); var GW = this.computeGW() - this.targetVelocity, - GiMf = this.computeGiMf();//axis.dot(invIi.vmult(taui)) + axis.dot(invIj.vmult(tauj)); + GiMf = this.computeGiMf(); - var B = - GW * b - h*GiMf; + var B = - GW * b - h * GiMf; return B; }; -/* -// Compute C = GMG+eps -RotationalMotorEquation.prototype.computeC = function(){ - var bi = this.bi; - var bj = this.bj; - var axisA = this.axisA; - var axisB = this.axisB; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - var C = this.eps; - - C += bi.invInertiaWorld.vmult(axisA).dot(axisB); - C += bj.invInertiaWorld.vmult(axisB).dot(axisB); - - return C; -}; - -var computeGWlambda_ulambda = new Vec3(); -RotationalMotorEquation.prototype.computeGWlambda = function(){ - var bi = this.bi; - var bj = this.bj; - var ulambda = computeGWlambda_ulambda; - var axisA = this.axisA; - var axisB = this.axisB; - - var GWlambda = 0.0; - //bj.vlambda.vsub(bi.vlambda, ulambda); - //GWlambda += ulambda.dot(this.ni); - - // Angular - if(bi.wlambda){ - GWlambda += bi.wlambda.dot(axisA); - } - if(bj.wlambda){ - GWlambda += bj.wlambda.dot(axisB); - } - - //console.log("GWlambda:",GWlambda); - - return GWlambda; -}; - -RotationalMotorEquation.prototype.addToWlambda = function(deltalambda){ - var bi = this.bi; - var bj = this.bj; - var axisA = this.axisA; - var axisB = this.axisB; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - // Add to linear velocity - //bi.vlambda.vsub(n.mult(invMassi * deltalambda),bi.vlambda); - //bj.vlambda.vadd(n.mult(invMassj * deltalambda),bj.vlambda); - - // Add to angular velocity - if(bi.wlambda){ - var I = bi.invInertiaWorld; - bi.wlambda.vsub(I.vmult(axisA).mult(deltalambda),bi.wlambda); - } - if(bj.wlambda){ - var I = bj.invInertiaWorld; - bj.wlambda.vadd(I.vmult(axisB).mult(deltalambda),bj.wlambda); - } -}; -*/ - -},{"../math/Mat3":24,"../math/Vec3":27,"./Equation":17}],21:[function(_dereq_,module,exports){ +},{"../math/Mat3":27,"../math/Vec3":30,"./Equation":20}],24:[function(_dereq_,module,exports){ var Utils = _dereq_('../utils/Utils'); module.exports = ContactMaterial; @@ -3366,33 +3685,57 @@ function ContactMaterial(m1, m2, options){ ContactMaterial.idCounter = 0; -},{"../utils/Utils":48}],22:[function(_dereq_,module,exports){ +},{"../utils/Utils":53}],25:[function(_dereq_,module,exports){ module.exports = Material; /** * Defines a physics material. * @class Material * @constructor - * @param {String} name + * @param {object} [options] * @author schteppe */ -function Material(name){ +function Material(options){ + var name = ''; + options = options || {}; + + // Backwards compatibility fix + if(typeof(options) === 'string'){ + name = options; + options = {}; + } else if(typeof(options) === 'object') { + name = ''; + } + /** * @property name * @type {String} */ this.name = name; - + /** * material id. * @property id + * @type {number} */ this.id = Material.idCounter++; + + /** + * Friction for this material. If non-negative, it will be used instead of the friction given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used. + * @property {number} friction + */ + this.friction = typeof(options.friction) !== 'undefined' ? options.friction : -1; + + /** + * Restitution for this material. If non-negative, it will be used instead of the restitution given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used. + * @property {number} restitution + */ + this.restitution = typeof(options.restitution) !== 'undefined' ? options.restitution : -1; } Material.idCounter = 0; -},{}],23:[function(_dereq_,module,exports){ +},{}],26:[function(_dereq_,module,exports){ module.exports = JacobianElement; var Vec3 = _dereq_('./Vec3'); @@ -3436,7 +3779,7 @@ JacobianElement.prototype.multiplyVectors = function(spatial,rotational){ return spatial.dot(this.spatial) + rotational.dot(this.rotational); }; -},{"./Vec3":27}],24:[function(_dereq_,module,exports){ +},{"./Vec3":30}],27:[function(_dereq_,module,exports){ module.exports = Mat3; var Vec3 = _dereq_('./Vec3'); @@ -3467,17 +3810,18 @@ function Mat3(elements){ * @todo Create another function that immediately creates an identity matrix eg. eye() */ Mat3.prototype.identity = function(){ - this.elements[0] = 1; - this.elements[1] = 0; - this.elements[2] = 0; + var e = this.elements; + e[0] = 1; + e[1] = 0; + e[2] = 0; - this.elements[3] = 0; - this.elements[4] = 1; - this.elements[5] = 0; + e[3] = 0; + e[4] = 1; + e[5] = 0; - this.elements[6] = 0; - this.elements[7] = 0; - this.elements[8] = 1; + e[6] = 0; + e[7] = 0; + e[8] = 1; }; /** @@ -3500,6 +3844,7 @@ Mat3.prototype.setZero = function(){ /** * Sets the matrix diagonal elements from a Vec3 * @method setTrace + * @param {Vec3} vec3 */ Mat3.prototype.setTrace = function(vec3){ var e = this.elements; @@ -3509,8 +3854,9 @@ Mat3.prototype.setTrace = function(vec3){ }; /** - * Sets the matrix diagonal elements from a Vec3 - * @method setTrace + * Gets the matrix diagonal elements + * @method getTrace + * @return {Vec3} */ Mat3.prototype.getTrace = function(target){ var target = target || new Vec3(); @@ -3857,7 +4203,7 @@ Mat3.prototype.transpose = function( target ) { return target; }; -},{"./Vec3":27}],25:[function(_dereq_,module,exports){ +},{"./Vec3":30}],28:[function(_dereq_,module,exports){ module.exports = Quaternion; var Vec3 = _dereq_('./Vec3'); @@ -3944,7 +4290,7 @@ Quaternion.prototype.setFromAxisAngle = function(axis,angle){ /** * Converts the quaternion to axis/angle representation. - * @method setFromAxisAngle + * @method toAxisAngle * @param {Vec3} targetAxis Optional. A vector object to reuse for storing the axis. * @return Array An array, first elemnt is the axis and the second is the angle in radians. */ @@ -4257,7 +4603,7 @@ Quaternion.prototype.setFromEuler = function ( x, y, z, order ) { Quaternion.prototype.clone = function(){ return new Quaternion(this.x, this.y, this.z, this.w); }; -},{"./Vec3":27}],26:[function(_dereq_,module,exports){ +},{"./Vec3":30}],29:[function(_dereq_,module,exports){ var Vec3 = _dereq_('./Vec3'); var Quaternion = _dereq_('./Quaternion'); @@ -4267,16 +4613,24 @@ module.exports = Transform; * @class Transform * @constructor */ -function Transform() { +function Transform(options) { + options = options || {}; + /** * @property {Vec3} position */ this.position = new Vec3(); - + if(options.position){ + this.position.copy(options.position); + } + /** * @property {Quaternion} quaternion */ this.quaternion = new Quaternion(); + if(options.quaternion){ + this.quaternion.copy(options.quaternion); + } } var tmpQuat = new Quaternion(); @@ -4297,6 +4651,17 @@ Transform.pointToLocalFrame = function(position, quaternion, worldPoint, result) return result; }; +/** + * Get a global point in local transform coordinates. + * @method pointToLocal + * @param {Vec3} point + * @param {Vec3} result + * @return {Vec3} The "result" vector object + */ +Transform.prototype.pointToLocal = function(worldPoint, result){ + return Transform.pointToLocalFrame(this.position, this.quaternion, worldPoint, result); +}; + /** * @static * @method pointToWorldFrame @@ -4312,12 +4677,29 @@ Transform.pointToWorldFrame = function(position, quaternion, localPoint, result) return result; }; +/** + * Get a local point in global transform coordinates. + * @method pointToWorld + * @param {Vec3} point + * @param {Vec3} result + * @return {Vec3} The "result" vector object + */ +Transform.prototype.pointToWorld = function(localPoint, result){ + return Transform.pointToWorldFrame(this.position, this.quaternion, localPoint, result); +}; + + Transform.prototype.vectorToWorldFrame = function(localVector, result){ var result = result || new Vec3(); this.quaternion.vmult(localVector, result); return result; }; +Transform.vectorToWorldFrame = function(quaternion, localVector, result){ + quaternion.vmult(localVector, result); + return result; +}; + Transform.vectorToLocalFrame = function(position, quaternion, worldVector, result){ var result = result || new Vec3(); quaternion.w *= -1; @@ -4326,7 +4708,7 @@ Transform.vectorToLocalFrame = function(position, quaternion, worldVector, resul return result; }; -},{"./Quaternion":25,"./Vec3":27}],27:[function(_dereq_,module,exports){ +},{"./Quaternion":28,"./Vec3":30}],30:[function(_dereq_,module,exports){ module.exports = Vec3; var Mat3 = _dereq_('./Mat3'); @@ -4363,8 +4745,30 @@ function Vec3(x,y,z){ this.z = z||0.0; } +/** + * @static + * @property {Vec3} ZERO + */ Vec3.ZERO = new Vec3(0, 0, 0); +/** + * @static + * @property {Vec3} UNIT_X + */ +Vec3.UNIT_X = new Vec3(1, 0, 0); + +/** + * @static + * @property {Vec3} UNIT_Y + */ +Vec3.UNIT_Y = new Vec3(0, 1, 0); + +/** + * @static + * @property {Vec3} UNIT_Z + */ +Vec3.UNIT_Z = new Vec3(0, 0, 1); + /** * Vector cross product * @method cross @@ -4502,24 +4906,40 @@ Vec3.prototype.unit = function(target){ }; /** - * Get the 2-norm (length) of the vector + * Get the length of the vector * @method norm * @return {Number} + * @deprecated Use .length() instead */ Vec3.prototype.norm = function(){ var x=this.x, y=this.y, z=this.z; return Math.sqrt(x*x + y*y + z*z); }; +/** + * Get the length of the vector + * @method length + * @return {Number} + */ +Vec3.prototype.length = Vec3.prototype.norm; + /** * Get the squared length of the vector * @method norm2 * @return {Number} + * @deprecated Use .lengthSquared() instead. */ Vec3.prototype.norm2 = function(){ return this.dot(this); }; +/** + * Get the squared length of the vector. + * @method lengthSquared + * @return {Number} + */ +Vec3.prototype.lengthSquared = Vec3.prototype.norm2; + /** * Get distance from this point to another point * @method distanceTo @@ -4535,12 +4955,25 @@ Vec3.prototype.distanceTo = function(p){ }; /** - * Multiply the vector with a scalar + * Get squared distance from this point to another point + * @method distanceSquared + * @param {Vec3} p + * @return {Number} + */ +Vec3.prototype.distanceSquared = function(p){ + var x=this.x, y=this.y, z=this.z; + var px=p.x, py=p.y, pz=p.z; + return (px-x)*(px-x) + (py-y)*(py-y) + (pz-z)*(pz-z); +}; + +/** + * Multiply all the components of the vector with a scalar. * @deprecated Use .scale instead * @method mult * @param {Number} scalar - * @param {Vec3} target + * @param {Vec3} target The vector to save the result in. * @return {Vec3} + * @deprecated Use .scale() instead */ Vec3.prototype.mult = function(scalar,target){ target = target || new Vec3(); @@ -4619,8 +5052,8 @@ Vec3.prototype.tangents = function(t1,t2){ n.cross(t1,t2); } else { // The normal length is zero, make something up - t1.set(1,0,0).normalize(); - t2.set(0,1,0).normalize(); + t1.set(1, 0, 0); + t2.set(0, 1, 0); } }; @@ -4728,7 +5161,7 @@ Vec3.prototype.isAntiparallelTo = function(v,precision){ Vec3.prototype.clone = function(){ return new Vec3(this.x, this.y, this.z); }; -},{"./Mat3":24}],28:[function(_dereq_,module,exports){ +},{"./Mat3":27}],31:[function(_dereq_,module,exports){ module.exports = Body; var EventTarget = _dereq_('../utils/EventTarget'); @@ -4751,8 +5184,17 @@ var Box = _dereq_('../shapes/Box'); * @param {Vec3} [options.angularVelocity] * @param {Quaternion} [options.quaternion] * @param {number} [options.mass] + * @param {Material} [options.material] * @param {number} [options.type] - * @param {number} [options.linearDamping] + * @param {number} [options.linearDamping=0.01] + * @param {number} [options.angularDamping=0.01] + * @param {boolean} [options.allowSleep=true] + * @param {number} [options.sleepSpeedLimit=0.1] + * @param {number} [options.sleepTimeLimit=1] + * @param {number} [options.collisionFilterGroup=1] + * @param {number} [options.collisionFilterMask=1] + * @param {boolean} [options.fixedRotation=false] + * @param {Body} [options.shape] * @example * var body = new Body({ * mass: 1 @@ -4796,12 +5238,12 @@ function Body(options){ /** * @property {Number} collisionFilterGroup */ - this.collisionFilterGroup = 1; + this.collisionFilterGroup = typeof(options.collisionFilterGroup) === 'number' ? options.collisionFilterGroup : 1; /** * @property {Number} collisionFilterMask */ - this.collisionFilterMask = 1; + this.collisionFilterMask = typeof(options.collisionFilterMask) === 'number' ? options.collisionFilterMask : 1; /** * Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled. @@ -4859,6 +5301,7 @@ function Body(options){ /** * @property mass * @type {Number} + * @default 0 */ this.mass = mass; @@ -4894,8 +5337,9 @@ function Body(options){ * If true, the body will automatically fall to sleep. * @property allowSleep * @type {Boolean} + * @default true */ - this.allowSleep = true; + this.allowSleep = typeof(options.allowSleep) !== 'undefined' ? options.allowSleep : true; /** * Current sleep state. @@ -4908,15 +5352,17 @@ function Body(options){ * If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy. * @property sleepSpeedLimit * @type {Number} + * @default 0.1 */ - this.sleepSpeedLimit = 0.1; + this.sleepSpeedLimit = typeof(options.sleepSpeedLimit) !== 'undefined' ? options.sleepSpeedLimit : 0.1; /** * If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping. * @property sleepTimeLimit * @type {Number} + * @default 1 */ - this.sleepTimeLimit = 1; + this.sleepTimeLimit = typeof(options.sleepTimeLimit) !== 'undefined' ? options.sleepTimeLimit : 1; this.timeLastSleepy = 0; @@ -5014,17 +5460,18 @@ function Body(options){ /** * Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this. * @property {Boolean} fixedRotation + * @default false */ - this.fixedRotation = false; + this.fixedRotation = typeof(options.fixedRotation) !== "undefined" ? options.fixedRotation : false; /** * @property {Number} angularDamping */ - this.angularDamping = 0.01; // Perhaps default should be zero here? + this.angularDamping = typeof(options.angularDamping) !== 'undefined' ? options.angularDamping : 0.01; /** * @property aabb - * @type {Vec3} + * @type {AABB} */ this.aabb = new AABB(); @@ -5037,6 +5484,10 @@ function Body(options){ this.wlambda = new Vec3(); + if(options.shape){ + this.addShape(options.shape); + } + this.updateMassProperties(); } Body.prototype = new EventTarget(); @@ -5174,6 +5625,19 @@ Body.prototype.pointToLocalFrame = function(worldPoint,result){ return result; }; +/** + * Convert a world vector to local body frame. + * @method vectorToLocalFrame + * @param {Vec3} worldPoint + * @param {Vec3} result + * @return {Vec3} + */ +Body.prototype.vectorToLocalFrame = function(worldVector, result){ + var result = result || new Vec3(); + this.quaternion.conjugate().vmult(worldVector,result); + return result; +}; + /** * Convert a local body point to world frame. * @method pointToWorldFrame @@ -5204,9 +5668,16 @@ Body.prototype.vectorToWorldFrame = function(localVector, result){ var tmpVec = new Vec3(); var tmpQuat = new Quaternion(); - -Body.prototype.addShape = function(shape, _offset, _orientation){ - var offset = new Vec3(); +/** + * Add a shape to the body with a local offset and orientation. + * @method addShape + * @param {Shape} shape + * @param {Vec3} offset + * @param {Quaternion} quaternion + * @return {Body} The body object, for chainability. + */ +Body.prototype.addShape = function(shape, _offset, _orientation){ + var offset = new Vec3(); var orientation = new Quaternion(); if(_offset){ @@ -5223,6 +5694,8 @@ Body.prototype.addShape = function(shape, _offset, _orientation){ this.updateBoundingRadius(); this.aabbNeedsUpdate = true; + + return this; }; /** @@ -5353,6 +5826,29 @@ Body.prototype.applyForce = function(force,worldPoint){ this.torque.vadd(rotForce,this.torque); }; +/** + * Apply force to a local point in the body. + * @method applyLocalForce + * @param {Vec3} force The force vector to apply, defined locally in the body frame. + * @param {Vec3} localPoint A local point in the body to apply the force on. + */ +var Body_applyLocalForce_worldForce = new Vec3(); +var Body_applyLocalForce_worldPoint = new Vec3(); +Body.prototype.applyLocalForce = function(localForce, localPoint){ + if(this.type !== Body.DYNAMIC){ + return; + } + + var worldForce = Body_applyLocalForce_worldForce; + var worldPoint = Body_applyLocalForce_worldPoint; + + // Transform the force vector to world space + this.vectorToWorldFrame(localForce, worldForce); + this.pointToWorldFrame(localPoint, worldPoint); + + this.applyForce(worldForce, worldPoint); +}; + /** * Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity. * @method applyImpulse @@ -5395,39 +5891,49 @@ Body.prototype.applyImpulse = function(impulse, worldPoint){ }; /** - * Should be called whenever you change the body mass. - * @method updateMassProperties + * Apply locally-defined impulse to a local point in the body. + * @method applyLocalImpulse + * @param {Vec3} force The force vector to apply, defined locally in the body frame. + * @param {Vec3} localPoint A local point in the body to apply the force on. */ -/*Body.prototype.updateMassProperties = function(){ - this.invMass = this.mass>0 ? 1.0/this.mass : 0; - this.shape.calculateLocalInertia(this.mass, this.inertia); - var I = this.inertia; - var fixed = this.fixedRotation; - this.invInertia.set( - I.x > 0 && !fixed ? 1.0 / I.x : 0, - I.y > 0 && !fixed ? 1.0 / I.y : 0, - I.z > 0 && !fixed ? 1.0 / I.z : 0 - ); - this.updateInertiaWorld(true); +var Body_applyLocalImpulse_worldImpulse = new Vec3(); +var Body_applyLocalImpulse_worldPoint = new Vec3(); +Body.prototype.applyLocalImpulse = function(localImpulse, localPoint){ + if(this.type !== Body.DYNAMIC){ + return; + } + + var worldImpulse = Body_applyLocalImpulse_worldImpulse; + var worldPoint = Body_applyLocalImpulse_worldPoint; + + // Transform the force vector to world space + this.vectorToWorldFrame(localImpulse, worldImpulse); + this.pointToWorldFrame(localPoint, worldPoint); + + this.applyImpulse(worldImpulse, worldPoint); }; -*/ -Body.prototype.updateMassProperties = function(){ - var target = new Vec3(); +var Body_updateMassProperties_halfExtents = new Vec3(); - // TODO: check if only 1 shape at origin, use shape inertia in that case +/** + * Should be called whenever you change the body shape or mass. + * @method updateMassProperties + */ +Body.prototype.updateMassProperties = function(){ + var halfExtents = Body_updateMassProperties_halfExtents; this.invMass = this.mass > 0 ? 1.0 / this.mass : 0; var I = this.inertia; var fixed = this.fixedRotation; - // Approximate with AABB + // Approximate with AABB box this.computeAABB(); - Box.calculateInertia(new Vec3( + halfExtents.set( (this.aabb.upperBound.x-this.aabb.lowerBound.x) / 2, (this.aabb.upperBound.y-this.aabb.lowerBound.y) / 2, (this.aabb.upperBound.z-this.aabb.lowerBound.z) / 2 - ), this.mass, I); + ); + Box.calculateInertia(halfExtents, this.mass, I); this.invInertia.set( I.x > 0 && !fixed ? 1.0 / I.x : 0, @@ -5452,7 +5958,7 @@ Body.prototype.getVelocityAtWorldPoint = function(worldPoint, result){ return result; }; -},{"../collision/AABB":3,"../material/Material":22,"../math/Mat3":24,"../math/Quaternion":25,"../math/Vec3":27,"../shapes/Box":34,"../shapes/Shape":40,"../utils/EventTarget":45}],29:[function(_dereq_,module,exports){ +},{"../collision/AABB":3,"../material/Material":25,"../math/Mat3":27,"../math/Quaternion":28,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Shape":43,"../utils/EventTarget":49}],32:[function(_dereq_,module,exports){ var Body = _dereq_('./Body'); var Vec3 = _dereq_('../math/Vec3'); var Quaternion = _dereq_('../math/Quaternion'); @@ -5583,9 +6089,10 @@ RaycastVehicle.prototype.addToWorld = function(world){ var constraints = this.constraints; world.add(this.chassisBody); var that = this; - world.addEventListener('preStep', function(){ + this.preStepCallback = function(){ that.updateVehicle(world.dt); - }); + }; + world.addEventListener('preStep', this.preStepCallback); this.world = world; }; @@ -5611,7 +6118,7 @@ RaycastVehicle.prototype.updateVehicle = function(timeStep){ var chassisBody = this.chassisBody; for (var i = 0; i < numWheels; i++) { - this.updateWheelTransform(i, false); + this.updateWheelTransform(i); } this.currentVehicleSpeedKmHour = 3.6 * chassisBody.velocity.norm(); @@ -5738,7 +6245,7 @@ RaycastVehicle.prototype.updateSuspension = function(deltaTime) { RaycastVehicle.prototype.removeFromWorld = function(world){ var constraints = this.constraints; world.remove(this.chassisBody); - world.removeEventListener('preStep', this.updateVehicle); + world.removeEventListener('preStep', this.preStepCallback); this.world = null; }; @@ -5830,6 +6337,13 @@ RaycastVehicle.prototype.updateWheelTransformWorld = function(wheel){ chassisBody.vectorToWorldFrame(wheel.axleLocal, wheel.axleWorld); }; + +/** + * Update one of the wheel transform. + * Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example. + * @method updateWheelTransform + * @param {integer} wheelIndex The wheel index to update. + */ RaycastVehicle.prototype.updateWheelTransform = function(wheelIndex){ var up = tmpVec4; var right = tmpVec5; @@ -6148,7 +6662,7 @@ function resolveSingleBilateral(body1, pos1, body2, pos2, normal, impulse){ return impulse; } -},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":25,"../math/Vec3":27,"../objects/WheelInfo":33,"./Body":28}],30:[function(_dereq_,module,exports){ +},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,"../objects/WheelInfo":36,"./Body":31}],33:[function(_dereq_,module,exports){ var Body = _dereq_('./Body'); var Sphere = _dereq_('../shapes/Sphere'); var Box = _dereq_('../shapes/Box'); @@ -6161,7 +6675,7 @@ module.exports = RigidVehicle; * Simple vehicle helper class with spherical rigid body wheels. * @class RigidVehicle * @constructor - * @param {object} [options.chassisBody] + * @param {Body} [options.chassisBody] */ function RigidVehicle(options){ this.wheelBodies = []; @@ -6197,7 +6711,7 @@ function RigidVehicle(options){ * Add a wheel * @method addWheel * @param {object} options - * @param {object} [options.isFrontWheel] + * @param {boolean} [options.isFrontWheel] * @param {Vec3} [options.position] Position of the wheel, locally in the chassis body. * @param {Vec3} [options.direction] Slide direction of the wheel along the suspension. * @param {Vec3} [options.axis] Axis of rotation of the wheel, locally defined in the chassis. @@ -6370,7 +6884,7 @@ RigidVehicle.prototype.getWheelSpeed = function(wheelIndex){ return w.dot(worldAxis); }; -},{"../constraints/HingeConstraint":14,"../math/Vec3":27,"../shapes/Box":34,"../shapes/Sphere":41,"./Body":28}],31:[function(_dereq_,module,exports){ +},{"../constraints/HingeConstraint":15,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Sphere":44,"./Body":31}],34:[function(_dereq_,module,exports){ module.exports = SPHSystem; var Shape = _dereq_('../shapes/Shape'); @@ -6387,9 +6901,25 @@ var Material = _dereq_('../material/Material'); */ function SPHSystem(){ this.particles = []; - this.density = 1; // kg/m3 - this.smoothingRadius = 1; // Adjust so there are about 15-20 neighbor particles within this radius + + /** + * Density of the system (kg/m3). + * @property {number} density + */ + this.density = 1; + + /** + * Distance below which two particles are considered to be neighbors. + * It should be adjusted so there are about 15-20 neighbor particles within this radius. + * @property {number} smoothingRadius + */ + this.smoothingRadius = 1; this.speedOfSound = 1; + + /** + * Viscosity of the system. + * @property {number} viscosity + */ this.viscosity = 0.01; this.eps = 0.000001; @@ -6399,6 +6929,11 @@ function SPHSystem(){ this.neighbors = []; } +/** + * Add a particle to the system. + * @method add + * @param {Body} particle + */ SPHSystem.prototype.add = function(particle){ this.particles.push(particle); if(this.neighbors.length < this.particles.length){ @@ -6406,6 +6941,11 @@ SPHSystem.prototype.add = function(particle){ } }; +/** + * Remove a particle from the system. + * @method remove + * @param {Body} particle + */ SPHSystem.prototype.remove = function(particle){ var idx = this.particles.indexOf(particle); if(idx !== -1){ @@ -6559,7 +7099,7 @@ SPHSystem.prototype.nablaw = function(r){ return nabla; }; -},{"../material/Material":22,"../math/Quaternion":25,"../math/Vec3":27,"../objects/Body":28,"../shapes/Particle":38,"../shapes/Shape":40}],32:[function(_dereq_,module,exports){ +},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Particle":41,"../shapes/Shape":43}],35:[function(_dereq_,module,exports){ var Vec3 = _dereq_('../math/Vec3'); module.exports = Spring; @@ -6754,7 +7294,7 @@ Spring.prototype.applyForce = function(){ bodyB.torque.vadd(rj_x_f,bodyB.torque); }; -},{"../math/Vec3":27}],33:[function(_dereq_,module,exports){ +},{"../math/Vec3":30}],36:[function(_dereq_,module,exports){ var Vec3 = _dereq_('../math/Vec3'); var Transform = _dereq_('../math/Transform'); var RaycastResult = _dereq_('../collision/RaycastResult'); @@ -6785,14 +7325,14 @@ module.exports = WheelInfo; * @param {number} [options.deltaRotation=0] * @param {number} [options.rollInfluence=0.01] * @param {number} [options.maxSuspensionForce] - * @param {number} [options.isFrontWheel=true] + * @param {boolean} [options.isFrontWheel=true] * @param {number} [options.clippedInvContactDotSuspension=1] * @param {number} [options.suspensionRelativeVelocity=0] * @param {number} [options.suspensionForce=0] * @param {number} [options.skidInfo=0] * @param {number} [options.suspensionLength=0] * @param {number} [options.maxSuspensionTravel=1] - * @param {number} [options.useCustomSlidingRotationalSpeed=false] + * @param {boolean} [options.useCustomSlidingRotationalSpeed=false] * @param {number} [options.customSlidingRotationalSpeed=-0.1] */ function WheelInfo(options){ @@ -7037,7 +7577,7 @@ WheelInfo.prototype.updateWheel = function(chassis){ this.clippedInvContactDotSuspension = 1.0; } }; -},{"../collision/RaycastResult":10,"../math/Transform":26,"../math/Vec3":27,"../utils/Utils":48}],34:[function(_dereq_,module,exports){ +},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(_dereq_,module,exports){ module.exports = Box; var Shape = _dereq_('./Shape'); @@ -7086,28 +7626,35 @@ Box.prototype.updateConvexPolyhedronRepresentation = function(){ var sz = this.halfExtents.z; var V = Vec3; - var h = new ConvexPolyhedron([new V(-sx,-sy,-sz), - new V( sx,-sy,-sz), - new V( sx, sy,-sz), - new V(-sx, sy,-sz), - new V(-sx,-sy, sz), - new V( sx,-sy, sz), - new V( sx, sy, sz), - new V(-sx, sy, sz)], - [[3,2,1,0], // -z - [4,5,6,7], // +z - [5,4,0,1], // -y - [2,3,7,6], // +y - [0,4,7,3], // -x - [1,2,6,5], // +x - ], - [new V( 0, 0,-1), - new V( 0, 0, 1), - new V( 0,-1, 0), - new V( 0, 1, 0), - new V(-1, 0, 0), - new V( 1, 0, 0)]); + var vertices = [ + new V(-sx,-sy,-sz), + new V( sx,-sy,-sz), + new V( sx, sy,-sz), + new V(-sx, sy,-sz), + new V(-sx,-sy, sz), + new V( sx,-sy, sz), + new V( sx, sy, sz), + new V(-sx, sy, sz) + ]; + + var indices = [ + [3,2,1,0], // -z + [4,5,6,7], // +z + [5,4,0,1], // -y + [2,3,7,6], // +y + [0,4,7,3], // -x + [1,2,6,5], // +x + ]; + + var axes = [ + new V(0, 0, 1), + new V(0, 1, 0), + new V(1, 0, 0) + ]; + + var h = new ConvexPolyhedron(vertices, indices); this.convexPolyhedronRepresentation = h; + h.material = this.material; }; /** @@ -7132,8 +7679,8 @@ Box.calculateInertia = function(halfExtents,mass,target){ /** * Get the box 6 side normals * @method getSideNormals - * @param {Boolean} includeNegative If true, this function returns 6 vectors. If false, it only returns 3 (but you get 6 by reversing those 3) - * @param {Quaternion} quat Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame. + * @param {array} sixTargetVectors An array of 6 vectors, to store the resulting side normals in. + * @param {Quaternion} quat Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame. * @return {array} */ Box.prototype.getSideNormals = function(sixTargetVectors,quat){ @@ -7267,7 +7814,7 @@ Box.prototype.calculateWorldAABB = function(pos,quat,min,max){ // }); }; -},{"../math/Vec3":27,"./ConvexPolyhedron":35,"./Shape":40}],35:[function(_dereq_,module,exports){ +},{"../math/Vec3":30,"./ConvexPolyhedron":38,"./Shape":43}],38:[function(_dereq_,module,exports){ module.exports = ConvexPolyhedron; var Shape = _dereq_('./Shape'); @@ -7294,7 +7841,7 @@ var Transform = _dereq_('../math/Transform'); * @todo Move the clipping functions to ContactGenerator? * @todo Automatically merge coplanar polygons in constructor. */ -function ConvexPolyhedron(points, faces) { +function ConvexPolyhedron(points, faces, uniqueAxes) { var that = this; Shape.call(this); this.type = Shape.types.CONVEXPOLYHEDRON; @@ -7334,12 +7881,19 @@ function ConvexPolyhedron(points, faces) { */ this.uniqueEdges = []; + /** + * If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check. + * @property {Array} uniqueAxes + */ + this.uniqueAxes = uniqueAxes ? uniqueAxes.slice() : null; + this.computeEdges(); this.updateBoundingSphereRadius(); } ConvexPolyhedron.prototype = new Shape(); ConvexPolyhedron.prototype.constructor = ConvexPolyhedron; +var computeEdges_tmpEdge = new Vec3(); /** * Computes uniqueEdges * @method computeEdges @@ -7352,24 +7906,17 @@ ConvexPolyhedron.prototype.computeEdges = function(){ edges.length = 0; - for(var pi=0; pi0.0){ target.negate(target); } + return true; }; +var maxminA=[], maxminB=[]; + /** * Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one. * @method testSepAxis @@ -7637,10 +8205,10 @@ ConvexPolyhedron.prototype.findSeparatingAxis = function(hullB,posA,quatA,posB,q * @param {Quaternion} quatA * @param {Vec3} posB * @param {Quaternion} quatB - * @return {float} The overlap depth, or FALSE if no penetration. + * @return {number} The overlap depth, or FALSE if no penetration. */ ConvexPolyhedron.prototype.testSepAxis = function(axis, hullB, posA, quatA, posB, quatB){ - var maxminA=[], maxminB=[], hullA=this; + var hullA=this; ConvexPolyhedron.project(hullA, axis, posA, quatA, maxminA); ConvexPolyhedron.project(hullB, axis, posB, quatB, maxminB); var maxA = maxminA[0]; @@ -7648,7 +8216,6 @@ ConvexPolyhedron.prototype.testSepAxis = function(axis, hullB, posA, quatA, posB var maxB = maxminB[0]; var minB = maxminB[1]; if(maxA max){ max = height; @@ -8507,7 +9055,7 @@ Heightfield.prototype.getHeightAt = function(x, y, edgeClamp){ var idx = []; this.getIndexOfPosition(x, y, idx, edgeClamp); - // TODO: do it better + // TODO: get upper or lower triangle, then use barycentric interpolation to get the height in the triangle. var minmax = []; this.getRectMinMax(idx[0], idx[1] + 1, idx[0], idx[1] + 1, minmax); @@ -8761,7 +9309,8 @@ Heightfield.prototype.updateBoundingSphereRadius = function(){ s = this.elementSize; this.boundingSphereRadius = new Vec3(data.length * s, data[0].length * s, Math.max(Math.abs(this.maxValue), Math.abs(this.minValue))).norm(); }; -},{"../math/Vec3":27,"../utils/Utils":48,"./ConvexPolyhedron":35,"./Shape":40}],38:[function(_dereq_,module,exports){ + +},{"../math/Vec3":30,"../utils/Utils":53,"./ConvexPolyhedron":38,"./Shape":43}],41:[function(_dereq_,module,exports){ module.exports = Particle; var Shape = _dereq_('./Shape'); @@ -8808,7 +9357,7 @@ Particle.prototype.calculateWorldAABB = function(pos,quat,min,max){ max.copy(pos); }; -},{"../math/Vec3":27,"./Shape":40}],39:[function(_dereq_,module,exports){ +},{"../math/Vec3":30,"./Shape":43}],42:[function(_dereq_,module,exports){ module.exports = Plane; var Shape = _dereq_('./Shape'); @@ -8871,7 +9420,7 @@ Plane.prototype.calculateWorldAABB = function(pos, quat, min, max){ Plane.prototype.updateBoundingSphereRadius = function(){ this.boundingSphereRadius = Number.MAX_VALUE; }; -},{"../math/Vec3":27,"./Shape":40}],40:[function(_dereq_,module,exports){ +},{"../math/Vec3":30,"./Shape":43}],43:[function(_dereq_,module,exports){ module.exports = Shape; var Shape = _dereq_('./Shape'); @@ -8888,6 +9437,12 @@ var Material = _dereq_('../material/Material'); */ function Shape(){ + /** + * Identifyer of the Shape. + * @property {number} id + */ + this.id = Shape.idCounter++; + /** * The type of this shape. Must be set to an int > 0 by subclasses. * @property type @@ -8907,6 +9462,11 @@ function Shape(){ * @property {boolean} collisionResponse */ this.collisionResponse = true; + + /** + * @property {Material} material + */ + this.material = null; } Shape.prototype.constructor = Shape; @@ -8938,6 +9498,8 @@ Shape.prototype.calculateLocalInertia = function(mass,target){ throw "calculateLocalInertia() not implemented for shape type "+this.type; }; +Shape.idCounter = 0; + /** * The available shape types. * @static @@ -8952,11 +9514,12 @@ Shape.types = { CONVEXPOLYHEDRON:16, HEIGHTFIELD:32, PARTICLE:64, - CYLINDER:128 + CYLINDER:128, + TRIMESH:256 }; -},{"../material/Material":22,"../math/Quaternion":25,"../math/Vec3":27,"./Shape":40}],41:[function(_dereq_,module,exports){ +},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"./Shape":43}],44:[function(_dereq_,module,exports){ module.exports = Sphere; var Shape = _dereq_('./Shape'); @@ -8967,7 +9530,7 @@ var Vec3 = _dereq_('../math/Vec3'); * @class Sphere * @constructor * @extends Shape - * @param {Number} radius + * @param {Number} radius The radius of the sphere, a non-negative number. * @author schteppe / http://github.com/schteppe */ function Sphere(radius){ @@ -8979,6 +9542,10 @@ function Sphere(radius){ this.radius = radius!==undefined ? Number(radius) : 1.0; this.type = Shape.types.SPHERE; + if(this.radius < 0){ + throw new Error('The sphere radius cannot be negative.'); + } + this.updateBoundingSphereRadius(); } Sphere.prototype = new Shape(); @@ -9011,125 +9578,687 @@ Sphere.prototype.calculateWorldAABB = function(pos,quat,min,max){ } }; -},{"../math/Vec3":27,"./Shape":40}],42:[function(_dereq_,module,exports){ -module.exports = GSSolver; +},{"../math/Vec3":30,"./Shape":43}],45:[function(_dereq_,module,exports){ +module.exports = Trimesh; +var Shape = _dereq_('./Shape'); var Vec3 = _dereq_('../math/Vec3'); var Quaternion = _dereq_('../math/Quaternion'); -var Solver = _dereq_('./Solver'); +var Transform = _dereq_('../math/Transform'); +var AABB = _dereq_('../collision/AABB'); +var Octree = _dereq_('../utils/Octree'); /** - * Constraint equation Gauss-Seidel solver. - * @class GSSolver + * @class Trimesh * @constructor - * @todo The spook parameters should be specified for each constraint, not globally. - * @author schteppe / https://github.com/schteppe - * @see https://www8.cs.umu.se/kurser/5DV058/VT09/lectures/spooknotes.pdf - * @extends Solver - */ -function GSSolver(){ - Solver.call(this); + * @param {array} vertices + * @param {array} indices + * @extends Shape + * @example + * // How to make a mesh with a single triangle + * var vertices = [ + * 0, 0, 0, // vertex 0 + * 1, 0, 0, // vertex 1 + * 0, 1, 0 // vertex 2 + * ]; + * var indices = [ + * 0, 1, 2 // triangle 0 + * ]; + * var trimeshShape = new Trimesh(vertices, indices); + */ +function Trimesh(vertices, indices) { + Shape.call(this); + this.type = Shape.types.TRIMESH; /** - * The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations. - * @property iterations - * @type {Number} - * @todo write more about solver and iterations in the wiki + * @property vertices + * @type {Array} */ - this.iterations = 10; + this.vertices = new Float32Array(vertices); /** - * When tolerance is reached, the system is assumed to be converged. - * @property tolerance - * @type {Number} + * Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles. + * @property indices + * @type {Array} */ - this.tolerance = 0; -} -GSSolver.prototype = new Solver(); - -var GSSolver_solve_lambda = []; // Just temporary number holders that we want to reuse each solve. -var GSSolver_solve_invCs = []; -var GSSolver_solve_Bs = []; -GSSolver.prototype.solve = function(dt,world){ - var iter = 0, - maxIter = this.iterations, - tolSquared = this.tolerance*this.tolerance, - equations = this.equations, - Neq = equations.length, - bodies = world.bodies, - Nbodies = bodies.length, - h = dt, - q, B, invC, deltalambda, deltalambdaTot, GWlambda, lambdaj; + this.indices = new Int16Array(indices); - // Update solve mass - if(Neq !== 0){ - for(var i=0; i!==Nbodies; i++){ - bodies[i].updateSolveMassProperties(); - } - } + /** + * The normals data. + * @property normals + * @type {Array} + */ + this.normals = new Float32Array(indices.length); - // Things that does not change during iteration can be computed once - var invCs = GSSolver_solve_invCs, - Bs = GSSolver_solve_Bs, - lambda = GSSolver_solve_lambda; - invCs.length = Neq; - Bs.length = Neq; - lambda.length = Neq; - for(var i=0; i!==Neq; i++){ - var c = equations[i]; - lambda[i] = 0.0; - Bs[i] = c.computeB(h); - invCs[i] = 1.0 / c.computeC(); - } + /** + * The local AABB of the mesh. + * @property aabb + * @type {Array} + */ + this.aabb = new AABB(); - if(Neq !== 0){ + /** + * References to vertex pairs, making up all unique edges in the trimesh. + * @property {array} edges + */ + this.edges = null; - // Reset vlambda - for(var i=0; i!==Nbodies; i++){ - var b=bodies[i], - vlambda=b.vlambda, - wlambda=b.wlambda; - vlambda.set(0,0,0); - if(wlambda){ - wlambda.set(0,0,0); - } - } + /** + * Local scaling of the mesh. Use .setScale() to set it. + * @property {Vec3} scale + */ + this.scale = new Vec3(1, 1, 1); - // Iterate over equations - for(iter=0; iter!==maxIter; iter++){ + /** + * The indexed triangles. Use .updateTree() to update it. + * @property {Octree} tree + */ + this.tree = new Octree(); - // Accumulate the total error for each iteration. - deltalambdaTot = 0.0; + this.updateEdges(); + this.updateNormals(); + this.updateAABB(); + this.updateBoundingSphereRadius(); + this.updateTree(); +} +Trimesh.prototype = new Shape(); +Trimesh.prototype.constructor = Trimesh; - for(var j=0; j!==Neq; j++){ +var computeNormals_n = new Vec3(); - var c = equations[j]; +/** + * @method updateTree + */ +Trimesh.prototype.updateTree = function(){ + var tree = this.tree; - // Compute iteration - B = Bs[j]; - invC = invCs[j]; - lambdaj = lambda[j]; - GWlambda = c.computeGWlambda(); - deltalambda = invC * ( B - GWlambda - c.eps * lambdaj ); + tree.reset(); + tree.aabb.copy(this.aabb); + var scale = this.scale; // The local mesh AABB is scaled, but the octree AABB should be unscaled + tree.aabb.lowerBound.x *= 1 / scale.x; + tree.aabb.lowerBound.y *= 1 / scale.y; + tree.aabb.lowerBound.z *= 1 / scale.z; + tree.aabb.upperBound.x *= 1 / scale.x; + tree.aabb.upperBound.y *= 1 / scale.y; + tree.aabb.upperBound.z *= 1 / scale.z; - // Clamp if we are not within the min/max interval - if(lambdaj + deltalambda < c.minForce){ - deltalambda = c.minForce - lambdaj; - } else if(lambdaj + deltalambda > c.maxForce){ - deltalambda = c.maxForce - lambdaj; - } - lambda[j] += deltalambda; + // Insert all triangles + var triangleAABB = new AABB(); + var a = new Vec3(); + var b = new Vec3(); + var c = new Vec3(); + var points = [a, b, c]; + for (var i = 0; i < this.indices.length / 3; i++) { + //this.getTriangleVertices(i, a, b, c); - deltalambdaTot += deltalambda > 0.0 ? deltalambda : -deltalambda; // abs(deltalambda) + // Get unscaled triangle verts + var i3 = i * 3; + this._getUnscaledVertex(this.indices[i3], a); + this._getUnscaledVertex(this.indices[i3 + 1], b); + this._getUnscaledVertex(this.indices[i3 + 2], c); - c.addToWlambda(deltalambda); - } + triangleAABB.setFromPoints(points); + tree.insert(triangleAABB, i); + } + tree.removeEmptyNodes(); +}; - // If the total error is small enough - stop iterate - if(deltalambdaTot*deltalambdaTot < tolSquared){ - break; - } - } +var unscaledAABB = new AABB(); + +/** + * Get triangles in a local AABB from the trimesh. + * @method getTrianglesInAABB + * @param {AABB} aabb + * @param {array} result An array of integers, referencing the queried triangles. + */ +Trimesh.prototype.getTrianglesInAABB = function(aabb, result){ + unscaledAABB.copy(aabb); + + // Scale it to local + var scale = this.scale; + var isx = scale.x; + var isy = scale.y; + var isz = scale.z; + var l = unscaledAABB.lowerBound; + var u = unscaledAABB.upperBound; + l.x /= isx; + l.y /= isy; + l.z /= isz; + u.x /= isx; + u.y /= isy; + u.z /= isz; + + return this.tree.aabbQuery(unscaledAABB, result); +}; + +/** + * @method setScale + * @param {Vec3} scale + */ +Trimesh.prototype.setScale = function(scale){ + var wasUniform = this.scale.x === this.scale.y === this.scale.z; + var isUniform = scale.x === scale.y === scale.z; + + if(!(wasUniform && isUniform)){ + // Non-uniform scaling. Need to update normals. + this.updateNormals(); + } + this.scale.copy(scale); + this.updateAABB(); + this.updateBoundingSphereRadius(); +}; + +/** + * Compute the normals of the faces. Will save in the .normals array. + * @method updateNormals + */ +Trimesh.prototype.updateNormals = function(){ + var n = computeNormals_n; + + // Generate normals + var normals = this.normals; + for(var i=0; i < this.indices.length / 3; i++){ + var i3 = i * 3; + + var a = this.indices[i3], + b = this.indices[i3 + 1], + c = this.indices[i3 + 2]; + + this.getVertex(a, va); + this.getVertex(b, vb); + this.getVertex(c, vc); + + Trimesh.computeNormal(vb, va, vc, n); + + normals[i3] = n.x; + normals[i3 + 1] = n.y; + normals[i3 + 2] = n.z; + } +}; + +/** + * Update the .edges property + * @method updateEdges + */ +Trimesh.prototype.updateEdges = function(){ + var edges = {}; + var add = function(indexA, indexB){ + var key = a < b ? a + '_' + b : b + '_' + a; + edges[key] = true; + }; + for(var i=0; i < this.indices.length / 3; i++){ + var i3 = i * 3; + var a = this.indices[i3], + b = this.indices[i3 + 1], + c = this.indices[i3 + 2]; + add(a,b); + add(b,c); + add(c,a); + } + var keys = Object.keys(edges); + this.edges = new Int16Array(keys.length * 2); + for (var i = 0; i < keys.length; i++) { + var indices = keys[i].split('_'); + this.edges[2 * i] = parseInt(indices[0], 10); + this.edges[2 * i + 1] = parseInt(indices[1], 10); + } +}; + +/** + * Get an edge vertex + * @method getEdgeVertex + * @param {number} edgeIndex + * @param {number} firstOrSecond 0 or 1, depending on which one of the vertices you need. + * @param {Vec3} vertexStore Where to store the result + */ +Trimesh.prototype.getEdgeVertex = function(edgeIndex, firstOrSecond, vertexStore){ + var vertexIndex = this.edges[edgeIndex * 2 + (firstOrSecond ? 1 : 0)]; + this.getVertex(vertexIndex, vertexStore); +}; + +var getEdgeVector_va = new Vec3(); +var getEdgeVector_vb = new Vec3(); + +/** + * Get a vector along an edge. + * @method getEdgeVector + * @param {number} edgeIndex + * @param {Vec3} vectorStore + */ +Trimesh.prototype.getEdgeVector = function(edgeIndex, vectorStore){ + var va = getEdgeVector_va; + var vb = getEdgeVector_vb; + this.getEdgeVertex(edgeIndex, 0, va); + this.getEdgeVertex(edgeIndex, 1, vb); + vb.vsub(va, vectorStore); +}; + +/** + * Get face normal given 3 vertices + * @static + * @method computeNormal + * @param {Vec3} va + * @param {Vec3} vb + * @param {Vec3} vc + * @param {Vec3} target + */ +var cb = new Vec3(); +var ab = new Vec3(); +Trimesh.computeNormal = function ( va, vb, vc, target ) { + vb.vsub(va,ab); + vc.vsub(vb,cb); + cb.cross(ab,target); + if ( !target.isZero() ) { + target.normalize(); + } +}; + +var va = new Vec3(); +var vb = new Vec3(); +var vc = new Vec3(); + +/** + * Get vertex i. + * @method getVertex + * @param {number} i + * @param {Vec3} out + * @return {Vec3} The "out" vector object + */ +Trimesh.prototype.getVertex = function(i, out){ + var scale = this.scale; + this._getUnscaledVertex(i, out); + out.x *= scale.x; + out.y *= scale.y; + out.z *= scale.z; + return out; +}; + +/** + * Get raw vertex i + * @private + * @method _getUnscaledVertex + * @param {number} i + * @param {Vec3} out + * @return {Vec3} The "out" vector object + */ +Trimesh.prototype._getUnscaledVertex = function(i, out){ + var i3 = i * 3; + var vertices = this.vertices; + return out.set( + vertices[i3], + vertices[i3 + 1], + vertices[i3 + 2] + ); +}; + +/** + * Get a vertex from the trimesh,transformed by the given position and quaternion. + * @method getWorldVertex + * @param {number} i + * @param {Vec3} pos + * @param {Quaternion} quat + * @param {Vec3} out + * @return {Vec3} The "out" vector object + */ +Trimesh.prototype.getWorldVertex = function(i, pos, quat, out){ + this.getVertex(i, out); + Transform.pointToWorldFrame(pos, quat, out, out); + return out; +}; + +/** + * Get the three vertices for triangle i. + * @method getTriangleVertices + * @param {number} i + * @param {Vec3} a + * @param {Vec3} b + * @param {Vec3} c + */ +Trimesh.prototype.getTriangleVertices = function(i, a, b, c){ + var i3 = i * 3; + this.getVertex(this.indices[i3], a); + this.getVertex(this.indices[i3 + 1], b); + this.getVertex(this.indices[i3 + 2], c); +}; + +/** + * Compute the normal of triangle i. + * @method getNormal + * @param {Number} i + * @param {Vec3} target + * @return {Vec3} The "target" vector object + */ +Trimesh.prototype.getNormal = function(i, target){ + var i3 = i * 3; + return target.set( + this.normals[i3], + this.normals[i3 + 1], + this.normals[i3 + 2] + ); +}; + +var cli_aabb = new AABB(); + +/** + * @method calculateLocalInertia + * @param {Number} mass + * @param {Vec3} target + * @return {Vec3} The "target" vector object + */ +Trimesh.prototype.calculateLocalInertia = function(mass,target){ + // Approximate with box inertia + // Exact inertia calculation is overkill, but see http://geometrictools.com/Documentation/PolyhedralMassProperties.pdf for the correct way to do it + this.computeLocalAABB(cli_aabb); + var x = cli_aabb.upperBound.x - cli_aabb.lowerBound.x, + y = cli_aabb.upperBound.y - cli_aabb.lowerBound.y, + z = cli_aabb.upperBound.z - cli_aabb.lowerBound.z; + return target.set( + 1.0 / 12.0 * mass * ( 2*y*2*y + 2*z*2*z ), + 1.0 / 12.0 * mass * ( 2*x*2*x + 2*z*2*z ), + 1.0 / 12.0 * mass * ( 2*y*2*y + 2*x*2*x ) + ); +}; + +var computeLocalAABB_worldVert = new Vec3(); + +/** + * Compute the local AABB for the trimesh + * @method computeLocalAABB + * @param {AABB} aabb + */ +Trimesh.prototype.computeLocalAABB = function(aabb){ + var l = aabb.lowerBound, + u = aabb.upperBound, + n = this.vertices.length, + vertices = this.vertices, + v = computeLocalAABB_worldVert; + + this.getVertex(0, v); + l.copy(v); + u.copy(v); + + for(var i=0; i !== n; i++){ + this.getVertex(i, v); + + if(v.x < l.x){ + l.x = v.x; + } else if(v.x > u.x){ + u.x = v.x; + } + + if(v.y < l.y){ + l.y = v.y; + } else if(v.y > u.y){ + u.y = v.y; + } + + if(v.z < l.z){ + l.z = v.z; + } else if(v.z > u.z){ + u.z = v.z; + } + } +}; + + +/** + * Update the .aabb property + * @method updateAABB + */ +Trimesh.prototype.updateAABB = function(){ + this.computeLocalAABB(this.aabb); +}; + +/** + * Will update the .boundingSphereRadius property + * @method updateBoundingSphereRadius + */ +Trimesh.prototype.updateBoundingSphereRadius = function(){ + // Assume points are distributed with local (0,0,0) as center + var max2 = 0; + var vertices = this.vertices; + var v = new Vec3(); + for(var i=0, N=vertices.length / 3; i !== N; i++) { + this.getVertex(i, v); + var norm2 = v.norm2(); + if(norm2 > max2){ + max2 = norm2; + } + } + this.boundingSphereRadius = Math.sqrt(max2); +}; + +var tempWorldVertex = new Vec3(); +var calculateWorldAABB_frame = new Transform(); +var calculateWorldAABB_aabb = new AABB(); + +/** + * @method calculateWorldAABB + * @param {Vec3} pos + * @param {Quaternion} quat + * @param {Vec3} min + * @param {Vec3} max + */ +Trimesh.prototype.calculateWorldAABB = function(pos,quat,min,max){ + /* + var n = this.vertices.length / 3, + verts = this.vertices; + var minx,miny,minz,maxx,maxy,maxz; + + var v = tempWorldVertex; + for(var i=0; i maxx || maxx===undefined){ + maxx = v.x; + } + + if (v.y < miny || miny===undefined){ + miny = v.y; + } else if(v.y > maxy || maxy===undefined){ + maxy = v.y; + } + + if (v.z < minz || minz===undefined){ + minz = v.z; + } else if(v.z > maxz || maxz===undefined){ + maxz = v.z; + } + } + min.set(minx,miny,minz); + max.set(maxx,maxy,maxz); + */ + + // Faster approximation using local AABB + var frame = calculateWorldAABB_frame; + var result = calculateWorldAABB_aabb; + frame.position = pos; + frame.quaternion = quat; + this.aabb.toWorldFrame(frame, result); + min.copy(result.lowerBound); + max.copy(result.upperBound); +}; + +/** + * Get approximate volume + * @method volume + * @return {Number} + */ +Trimesh.prototype.volume = function(){ + return 4.0 * Math.PI * this.boundingSphereRadius / 3.0; +}; + +/** + * Create a Trimesh instance, shaped as a torus. + * @static + * @method createTorus + * @param {number} [radius=1] + * @param {number} [tube=0.5] + * @param {number} [radialSegments=8] + * @param {number} [tubularSegments=6] + * @param {number} [arc=6.283185307179586] + * @return {Trimesh} A torus + */ +Trimesh.createTorus = function (radius, tube, radialSegments, tubularSegments, arc) { + radius = radius || 1; + tube = tube || 0.5; + radialSegments = radialSegments || 8; + tubularSegments = tubularSegments || 6; + arc = arc || Math.PI * 2; + + var vertices = []; + var indices = []; + + for ( var j = 0; j <= radialSegments; j ++ ) { + for ( var i = 0; i <= tubularSegments; i ++ ) { + var u = i / tubularSegments * arc; + var v = j / radialSegments * Math.PI * 2; + + var x = ( radius + tube * Math.cos( v ) ) * Math.cos( u ); + var y = ( radius + tube * Math.cos( v ) ) * Math.sin( u ); + var z = tube * Math.sin( v ); + + vertices.push( x, y, z ); + } + } + + for ( var j = 1; j <= radialSegments; j ++ ) { + for ( var i = 1; i <= tubularSegments; i ++ ) { + var a = ( tubularSegments + 1 ) * j + i - 1; + var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1; + var c = ( tubularSegments + 1 ) * ( j - 1 ) + i; + var d = ( tubularSegments + 1 ) * j + i; + + indices.push(a, b, d); + indices.push(b, c, d); + } + } + + return new Trimesh(vertices, indices); +}; + +},{"../collision/AABB":3,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(_dereq_,module,exports){ +module.exports = GSSolver; + +var Vec3 = _dereq_('../math/Vec3'); +var Quaternion = _dereq_('../math/Quaternion'); +var Solver = _dereq_('./Solver'); + +/** + * Constraint equation Gauss-Seidel solver. + * @class GSSolver + * @constructor + * @todo The spook parameters should be specified for each constraint, not globally. + * @author schteppe / https://github.com/schteppe + * @see https://www8.cs.umu.se/kurser/5DV058/VT09/lectures/spooknotes.pdf + * @extends Solver + */ +function GSSolver(){ + Solver.call(this); + + /** + * The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations. + * @property iterations + * @type {Number} + * @todo write more about solver and iterations in the wiki + */ + this.iterations = 10; + + /** + * When tolerance is reached, the system is assumed to be converged. + * @property tolerance + * @type {Number} + */ + this.tolerance = 1e-7; +} +GSSolver.prototype = new Solver(); + +var GSSolver_solve_lambda = []; // Just temporary number holders that we want to reuse each solve. +var GSSolver_solve_invCs = []; +var GSSolver_solve_Bs = []; +GSSolver.prototype.solve = function(dt,world){ + var iter = 0, + maxIter = this.iterations, + tolSquared = this.tolerance*this.tolerance, + equations = this.equations, + Neq = equations.length, + bodies = world.bodies, + Nbodies = bodies.length, + h = dt, + q, B, invC, deltalambda, deltalambdaTot, GWlambda, lambdaj; + + // Update solve mass + if(Neq !== 0){ + for(var i=0; i!==Nbodies; i++){ + bodies[i].updateSolveMassProperties(); + } + } + + // Things that does not change during iteration can be computed once + var invCs = GSSolver_solve_invCs, + Bs = GSSolver_solve_Bs, + lambda = GSSolver_solve_lambda; + invCs.length = Neq; + Bs.length = Neq; + lambda.length = Neq; + for(var i=0; i!==Neq; i++){ + var c = equations[i]; + lambda[i] = 0.0; + Bs[i] = c.computeB(h); + invCs[i] = 1.0 / c.computeC(); + } + + if(Neq !== 0){ + + // Reset vlambda + for(var i=0; i!==Nbodies; i++){ + var b=bodies[i], + vlambda=b.vlambda, + wlambda=b.wlambda; + vlambda.set(0,0,0); + if(wlambda){ + wlambda.set(0,0,0); + } + } + + // Iterate over equations + for(iter=0; iter!==maxIter; iter++){ + + // Accumulate the total error for each iteration. + deltalambdaTot = 0.0; + + for(var j=0; j!==Neq; j++){ + + var c = equations[j]; + + // Compute iteration + B = Bs[j]; + invC = invCs[j]; + lambdaj = lambda[j]; + GWlambda = c.computeGWlambda(); + deltalambda = invC * ( B - GWlambda - c.eps * lambdaj ); + + // Clamp if we are not within the min/max interval + if(lambdaj + deltalambda < c.minForce){ + deltalambda = c.minForce - lambdaj; + } else if(lambdaj + deltalambda > c.maxForce){ + deltalambda = c.maxForce - lambdaj; + } + lambda[j] += deltalambda; + + deltalambdaTot += deltalambda > 0.0 ? deltalambda : -deltalambda; // abs(deltalambda) + + c.addToWlambda(deltalambda); + } + + // If the total error is small enough - stop iterate + if(deltalambdaTot*deltalambdaTot < tolSquared){ + break; + } + } // Add result to velocity for(var i=0; i!==Nbodies; i++){ @@ -9146,7 +10275,7 @@ GSSolver.prototype.solve = function(dt,world){ return iter; }; -},{"../math/Quaternion":25,"../math/Vec3":27,"./Solver":43}],43:[function(_dereq_,module,exports){ +},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(_dereq_,module,exports){ module.exports = Solver; /** @@ -9207,7 +10336,7 @@ Solver.prototype.removeAllEquations = function(){ }; -},{}],44:[function(_dereq_,module,exports){ +},{}],48:[function(_dereq_,module,exports){ module.exports = SplitSolver; var Vec3 = _dereq_('../math/Vec3'); @@ -9224,15 +10353,69 @@ var Body = _dereq_('../objects/Body'); */ function SplitSolver(subsolver){ Solver.call(this); + this.iterations = 10; + this.tolerance = 1e-7; this.subsolver = subsolver; + this.nodes = []; + this.nodePool = []; + + // Create needed nodes, reuse if possible + while(this.nodePool.length < 128){ + this.nodePool.push(this.createNode()); + } } SplitSolver.prototype = new Solver(); // Returns the number of subsystems var SplitSolver_solve_nodes = []; // All allocated node objects +var SplitSolver_solve_nodePool = []; // All allocated node objects var SplitSolver_solve_eqs = []; // Temp array var SplitSolver_solve_bds = []; // Temp array -var SplitSolver_solve_dummyWorld = {bodies:null}; // Temp object +var SplitSolver_solve_dummyWorld = {bodies:[]}; // Temp object + +var STATIC = Body.STATIC; +function getUnvisitedNode(nodes){ + var Nnodes = nodes.length; + for(var i=0; i!==Nnodes; i++){ + var node = nodes[i]; + if(!node.visited && !(node.body.type & STATIC)){ + return node; + } + } + return false; +} + +var queue = []; +function bfs(root,visitFunc,bds,eqs){ + queue.push(root); + root.visited = true; + visitFunc(root,bds,eqs); + while(queue.length) { + var node = queue.pop(); + // Loop over unvisited child nodes + var child; + while((child = getUnvisitedNode(node.children))) { + child.visited = true; + visitFunc(child,bds,eqs); + queue.push(child); + } + } +} + +function visitFunc(node,bds,eqs){ + bds.push(node.body); + var Neqs = node.eqs.length; + for(var i=0; i!==Neqs; i++){ + var eq = node.eqs[i]; + if(eqs.indexOf(eq) === -1){ + eqs.push(eq); + } + } +} + +SplitSolver.prototype.createNode = function(){ + return { body:null, children:[], eqs:[], visited:false }; +}; /** * Solve the subsystems @@ -9242,17 +10425,20 @@ var SplitSolver_solve_dummyWorld = {bodies:null}; // Temp object */ SplitSolver.prototype.solve = function(dt,world){ var nodes=SplitSolver_solve_nodes, + nodePool=this.nodePool, bodies=world.bodies, equations=this.equations, Neq=equations.length, Nbodies=bodies.length, subsolver=this.subsolver; + // Create needed nodes, reuse if possible - if(nodes.length>Nbodies){ - nodes.length = Nbodies; + while(nodePool.length < Nbodies){ + nodePool.push(this.createNode()); } - while(nodes.length= 0; i--) { + if(!node.children[i].data.length){ + node.children.splice(i, 1); } } - return this; + Array.prototype.push.apply(queue, node.children); } }; -},{}],46:[function(_dereq_,module,exports){ +},{"../collision/AABB":3,"../math/Vec3":30}],51:[function(_dereq_,module,exports){ module.exports = Pool; /** @@ -9480,7 +10871,7 @@ Pool.prototype.constructObject = function(){ throw new Error("constructObject() not implemented in this Pool subclass yet!"); }; -},{}],47:[function(_dereq_,module,exports){ +},{}],52:[function(_dereq_,module,exports){ module.exports = TupleDictionary; /** @@ -9547,7 +10938,7 @@ TupleDictionary.prototype.reset = function() { } }; -},{}],48:[function(_dereq_,module,exports){ +},{}],53:[function(_dereq_,module,exports){ function Utils(){} module.exports = Utils; @@ -9572,7 +10963,7 @@ Utils.defaults = function(options, defaults){ return options; }; -},{}],49:[function(_dereq_,module,exports){ +},{}],54:[function(_dereq_,module,exports){ module.exports = Vec3Pool; var Vec3 = _dereq_('../math/Vec3'); @@ -9598,10 +10989,12 @@ Vec3Pool.prototype.constructObject = function(){ return new Vec3(); }; -},{"../math/Vec3":27,"./Pool":46}],50:[function(_dereq_,module,exports){ +},{"../math/Vec3":30,"./Pool":51}],55:[function(_dereq_,module,exports){ module.exports = Narrowphase; +var AABB = _dereq_('../collision/AABB'); var Shape = _dereq_('../shapes/Shape'); +var Ray = _dereq_('../collision/Ray'); var Vec3 = _dereq_('../math/Vec3'); var Transform = _dereq_('../math/Transform'); var ConvexPolyhedron = _dereq_('../shapes/ConvexPolyhedron'); @@ -9609,6 +11002,7 @@ var Quaternion = _dereq_('../math/Quaternion'); var Solver = _dereq_('../solver/Solver'); var Vec3Pool = _dereq_('../utils/Vec3Pool'); var ContactEquation = _dereq_('../equations/ContactEquation'); +var FrictionEquation = _dereq_('../equations/FrictionEquation'); /** * Helper class for the World. Generates ContactEquations. @@ -9618,7 +11012,7 @@ var ContactEquation = _dereq_('../equations/ContactEquation'); * @todo Contact reduction * @todo should move methods to prototype */ -function Narrowphase(){ +function Narrowphase(world){ /** * Internal storage of pooled contact points. @@ -9626,19 +11020,32 @@ function Narrowphase(){ */ this.contactPointPool = []; + this.frictionEquationPool = []; + + this.result = []; + this.frictionResult = []; + /** * Pooled vectors. * @property {Vec3Pool} v3pool */ this.v3pool = new Vec3Pool(); + + this.world = world; + this.currentContactMaterial = null; + + /** + * @property {Boolean} enableFrictionReduction + */ + this.enableFrictionReduction = false; } /** * Make a contact object, by using the internal pool or creating a new one. - * @method makeResult + * @method createContactEquation * @return {ContactEquation} */ -Narrowphase.prototype.makeResult = function(bi, bj, si, sj, rsi, rsj){ +Narrowphase.prototype.createContactEquation = function(bi, bj, si, sj, rsi, rsj){ var c; if(this.contactPointPool.length){ c = this.contactPointPool.pop(); @@ -9648,13 +11055,134 @@ Narrowphase.prototype.makeResult = function(bi, bj, si, sj, rsi, rsj){ c = new ContactEquation(bi, bj); } - c.enabled = true; + c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; + + var cm = this.currentContactMaterial; + + c.restitution = cm.restitution; + + c.setSpookParams( + cm.contactEquationStiffness, + cm.contactEquationRelaxation, + this.world.dt + ); + + var matA = si.material || bi.material; + var matB = sj.material || bj.material; + if(matA && matB && matA.restitution >= 0 && matB.restitution >= 0){ + c.restitution = matA.restitution * matB.restitution; + } + c.si = rsi || si; c.sj = rsj || sj; return c; }; +Narrowphase.prototype.createFrictionEquationsFromContact = function(contactEquation, outArray){ + var bodyA = contactEquation.bi; + var bodyB = contactEquation.bj; + var shapeA = contactEquation.si; + var shapeB = contactEquation.sj; + + var world = this.world; + var cm = this.currentContactMaterial; + + // If friction or restitution were specified in the material, use them + var friction = cm.friction; + var matA = shapeA.material || bodyA.material; + var matB = shapeB.material || bodyB.material; + if(matA && matB && matA.friction >= 0 && matB.friction >= 0){ + friction = matA.friction * matB.friction; + } + + if(friction > 0){ + + // Create 2 tangent equations + var mug = friction * world.gravity.length(); + var reducedMass = (bodyA.invMass + bodyB.invMass); + if(reducedMass > 0){ + reducedMass = 1/reducedMass; + } + var pool = this.frictionEquationPool; + var c1 = pool.length ? pool.pop() : new FrictionEquation(bodyA,bodyB,mug*reducedMass); + var c2 = pool.length ? pool.pop() : new FrictionEquation(bodyA,bodyB,mug*reducedMass); + + c1.bi = c2.bi = bodyA; + c1.bj = c2.bj = bodyB; + c1.minForce = c2.minForce = -mug*reducedMass; + c1.maxForce = c2.maxForce = mug*reducedMass; + + // Copy over the relative vectors + c1.ri.copy(contactEquation.ri); + c1.rj.copy(contactEquation.rj); + c2.ri.copy(contactEquation.ri); + c2.rj.copy(contactEquation.rj); + + // Construct tangents + contactEquation.ni.tangents(c1.t, c2.t); + + // Set spook params + c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt); + c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt); + + c1.enabled = c2.enabled = contactEquation.enabled; + + outArray.push(c1, c2); + + return true; + } + + return false; +}; + +var averageNormal = new Vec3(); +var averageContactPointA = new Vec3(); +var averageContactPointB = new Vec3(); + +// Take the average N latest contact point on the plane. +Narrowphase.prototype.createFrictionFromAverage = function(numContacts){ + // The last contactEquation + var c = this.result[this.result.length - 1]; + + // Create the result: two "average" friction equations + if (!this.createFrictionEquationsFromContact(c, this.frictionResult) || numContacts === 1) { + return; + } + + var f1 = this.frictionResult[this.frictionResult.length - 2]; + var f2 = this.frictionResult[this.frictionResult.length - 1]; + + averageNormal.setZero(); + averageContactPointA.setZero(); + averageContactPointB.setZero(); + + var bodyA = c.bi; + var bodyB = c.bj; + for(var i=0; i!==numContacts; i++){ + c = this.result[this.result.length - 1 - i]; + if(c.bodyA !== bodyA){ + averageNormal.vadd(c.ni, averageNormal); // vec2.add(eq.t, eq.t, c.normalA); + averageContactPointA.vadd(c.ri, averageContactPointA); // vec2.add(eq.contactPointA, eq.contactPointA, c.contactPointA); + averageContactPointB.vadd(c.rj, averageContactPointB); + } else { + averageNormal.vsub(c.ni, averageNormal); // vec2.sub(eq.t, eq.t, c.normalA); + averageContactPointA.vadd(c.rj, averageContactPointA); // vec2.add(eq.contactPointA, eq.contactPointA, c.contactPointA); + averageContactPointB.vadd(c.ri, averageContactPointB); + } + } + + var invNumContacts = 1 / numContacts; + averageContactPointA.scale(invNumContacts, f1.ri); // vec2.scale(eq.contactPointA, eq.contactPointA, invNumContacts); + averageContactPointB.scale(invNumContacts, f1.rj); // vec2.scale(eq.contactPointB, eq.contactPointB, invNumContacts); + f2.ri.copy(f1.ri); // Should be the same + f2.rj.copy(f1.rj); + averageNormal.normalize(); + averageNormal.tangents(f1.t, f2.t); + // return eq; +}; + + var tmpVec1 = new Vec3(); var tmpVec2 = new Vec3(); var tmpQuat1 = new Quaternion(); @@ -9669,9 +11197,12 @@ var tmpQuat2 = new Quaternion(); * @param {array} result Array to store generated contacts * @param {array} oldcontacts Optional. Array of reusable contact objects */ -Narrowphase.prototype.getContacts = function(p1,p2,world,result,oldcontacts){ +Narrowphase.prototype.getContacts = function(p1, p2, world, result, oldcontacts, frictionResult, frictionPool){ // Save old contact objects this.contactPointPool = oldcontacts; + this.frictionEquationPool = frictionPool; + this.result = result; + this.frictionResult = frictionResult; var qi = tmpQuat1; var qj = tmpQuat2; @@ -9684,6 +11215,12 @@ Narrowphase.prototype.getContacts = function(p1,p2,world,result,oldcontacts){ var bi = p1[k], bj = p2[k]; + // Get contact material + var bodyContactMaterial = null; + if(bi.material && bj.material){ + bodyContactMaterial = world.getContactMaterial(bi.material,bj.material) || null; + } + for (var i = 0; i < bi.shapes.length; i++) { bi.quaternion.mult(bi.shapeOrientations[i], qi); bi.quaternion.vmult(bi.shapeOffsets[i], xi); @@ -9702,13 +11239,21 @@ Narrowphase.prototype.getContacts = function(p1,p2,world,result,oldcontacts){ continue; } + // Get collision material + var shapeContactMaterial = null; + if(si.material && sj.material){ + shapeContactMaterial = world.getContactMaterial(si.material,sj.material) || null; + } + + this.currentContactMaterial = shapeContactMaterial || bodyContactMaterial || world.defaultContactMaterial; + // Get contacts var resolver = this[si.type | sj.type]; if(resolver){ if (si.type < sj.type) { - resolver.call(this, result, si,sj,xi,xj,qi,qj,bi,bj,si,sj); + resolver.call(this, si, sj, xi, xj, qi, qj, bi, bj, si, sj); } else { - resolver.call(this, result, sj,si,xj,xi,qj,qi,bj,bi,si,sj); + resolver.call(this, sj, si, xj, xi, qj, qi, bj, bi, si, sj); } } } @@ -9730,23 +11275,30 @@ function warn(msg){ } Narrowphase.prototype[Shape.types.BOX | Shape.types.BOX] = -Narrowphase.prototype.boxBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexConvex(result,si.convexPolyhedronRepresentation,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxBox = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + sj.convexPolyhedronRepresentation.material = sj.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + sj.convexPolyhedronRepresentation.collisionResponse = sj.collisionResponse; + this.convexConvex(si.convexPolyhedronRepresentation,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj,si,sj); }; Narrowphase.prototype[Shape.types.BOX | Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.boxConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexConvex(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxConvex = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexConvex(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); }; Narrowphase.prototype[Shape.types.BOX | Shape.types.PARTICLE] = -Narrowphase.prototype.boxParticle = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexParticle(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxParticle = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexParticle(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); }; /** * @method sphereSphere - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -9757,12 +11309,12 @@ Narrowphase.prototype.boxParticle = function(result,si,sj,xi,xj,qi,qj,bi,bj){ * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE] = -Narrowphase.prototype.sphereSphere = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.sphereSphere = function(si,sj,xi,xj,qi,qj,bi,bj){ // We will have only one contact in this case - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); // Contact normal - bj.position.vsub(xi, r.ni); + xj.vsub(xi, r.ni); r.ni.normalize(); // Contact point locations @@ -9770,7 +11322,280 @@ Narrowphase.prototype.sphereSphere = function(result,si,sj,xi,xj,qi,qj,bi,bj){ r.rj.copy(r.ni); r.ri.mult(si.radius, r.ri); r.rj.mult(-sj.radius, r.rj); - result.push(r); + + r.ri.vadd(xi, r.ri); + r.ri.vsub(bi.position, r.ri); + + r.rj.vadd(xj, r.rj); + r.rj.vsub(bj.position, r.rj); + + this.result.push(r); + + this.createFrictionEquationsFromContact(r, this.frictionResult); +}; + +/** + * @method planeTrimesh + * @param {Shape} si + * @param {Shape} sj + * @param {Vec3} xi + * @param {Vec3} xj + * @param {Quaternion} qi + * @param {Quaternion} qj + * @param {Body} bi + * @param {Body} bj + */ +var planeTrimesh_normal = new Vec3(); +var planeTrimesh_relpos = new Vec3(); +var planeTrimesh_projected = new Vec3(); +Narrowphase.prototype[Shape.types.PLANE | Shape.types.TRIMESH] = +Narrowphase.prototype.planeTrimesh = function( + planeShape, + trimeshShape, + planePos, + trimeshPos, + planeQuat, + trimeshQuat, + planeBody, + trimeshBody +){ + // Make contacts! + var v = new Vec3(); + + var normal = planeTrimesh_normal; + normal.set(0,0,1); + planeQuat.vmult(normal,normal); // Turn normal according to plane + + for(var i=0; i 0 && positionAlongEdgeB < 0){ + + // Now check the orthogonal distance from edge to sphere center + localSpherePos.vsub(edgeVertexA, tmp); + + edgeVectorUnit.copy(edgeVector); + edgeVectorUnit.normalize(); + positionAlongEdgeA = tmp.dot(edgeVectorUnit); + + edgeVectorUnit.scale(positionAlongEdgeA, tmp); + tmp.vadd(edgeVertexA, tmp); + + // tmp is now the sphere center position projected to the edge, defined locally in the trimesh frame + var dist = tmp.distanceTo(localSpherePos); + if(dist < sphereShape.radius){ + var r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape); + + tmp.vsub(localSpherePos, r.ni); + r.ni.normalize(); + r.ni.scale(sphereShape.radius, r.ri); + + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); + tmp.vsub(trimeshBody.position, r.rj); + + Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni); + Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + } + } + + // Triangle faces + var va = sphereTrimesh_va; + var vb = sphereTrimesh_vb; + var vc = sphereTrimesh_vc; + var normal = sphereTrimesh_normal; + for(var i=0, N = triangles.length; i !== N; i++){ + trimeshShape.getTriangleVertices(triangles[i], va, vb, vc); + trimeshShape.getNormal(triangles[i], normal); + localSpherePos.vsub(va, tmp); + var dist = tmp.dot(normal); + normal.scale(dist, tmp); + localSpherePos.vsub(tmp, tmp); + + // tmp is now the sphere position projected to the triangle plane + dist = tmp.distanceTo(localSpherePos); + if(Ray.pointInTriangle(tmp, va, vb, vc) && dist < sphereShape.radius){ + var r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape); + + tmp.vsub(localSpherePos, r.ni); + r.ni.normalize(); + r.ni.scale(sphereShape.radius, r.ri); + + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); + tmp.vsub(trimeshBody.position, r.rj); + + Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni); + Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + + triangles.length = 0; }; var point_on_plane_to_sphere = new Vec3(); @@ -9778,7 +11603,6 @@ var plane_to_sphere_ortho = new Vec3(); /** * @method spherePlane - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -9789,9 +11613,9 @@ var plane_to_sphere_ortho = new Vec3(); * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.PLANE] = -Narrowphase.prototype.spherePlane = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.spherePlane = function(si,sj,xi,xj,qi,qj,bi,bj){ // We will have one contact in this case - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); // Contact normal r.ni.set(0,0,1); @@ -9807,8 +11631,7 @@ Narrowphase.prototype.spherePlane = function(result,si,sj,xi,xj,qi,qj,bi,bj){ r.ni.mult(r.ni.dot(point_on_plane_to_sphere), plane_to_sphere_ortho); point_on_plane_to_sphere.vsub(plane_to_sphere_ortho,r.rj); // The sphere position projected to plane - if(plane_to_sphere_ortho.norm2() <= si.radius * si.radius){ - result.push(r); + if(-point_on_plane_to_sphere.dot(r.ni) <= si.radius){ // Make it relative to the body var ri = r.ri; @@ -9817,6 +11640,9 @@ Narrowphase.prototype.spherePlane = function(result,si,sj,xi,xj,qi,qj,bi,bj){ ri.vsub(bi.position, ri); rj.vadd(xj, rj); rj.vsub(bj.position, rj); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -9873,7 +11699,6 @@ var sphereBox_side_ns2 = new Vec3(); /** * @method sphereBox - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -9884,7 +11709,7 @@ var sphereBox_side_ns2 = new Vec3(); * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.BOX] = -Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.sphereBox = function(si,sj,xi,xj,qi,qj,bi,bj){ var v3pool = this.v3pool; // we refer to the box as body j @@ -9946,7 +11771,7 @@ Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ } if(side_penetrations){ found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); side_ns.mult(-R,r.ri); // Sphere r r.ni.copy(side_ns); r.ni.negate(r.ni); // Normal should be out of sphere @@ -9962,7 +11787,8 @@ Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ r.rj.vadd(xj, r.rj); r.rj.vsub(bj.position, r.rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } // Check corners @@ -9994,7 +11820,7 @@ Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ if(sphere_to_corner.norm2() < R*R){ found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); r.ri.copy(sphere_to_corner); r.ri.normalize(); r.ni.copy(r.ri); @@ -10007,7 +11833,8 @@ Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ r.rj.vadd(xj, r.rj); r.rj.vsub(bj.position, r.rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } } } @@ -10053,7 +11880,7 @@ Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ if(tdist < sides[l].norm() && ndist 0 && dot*dot si.boundingSphereRadius + sj.boundingSphereRadius){ @@ -10426,8 +12264,9 @@ Narrowphase.prototype.convexConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj,rsi var res = []; var q = convexConvex_q; si.clipAgainstHull(xi,qi,sj,xj,qj,sepAxis,-100,100,res); + var numContacts = 0; for(var j = 0; j !== res.length; j++){ - var r = this.makeResult(bi,bj,si,sj,rsi,rsj), + var r = this.createContactEquation(bi,bj,si,sj,rsi,rsj), ri = r.ri, rj = r.rj; sepAxis.negate(r.ni); @@ -10446,11 +12285,99 @@ Narrowphase.prototype.convexConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj,rsi rj.vadd(xj, rj); rj.vsub(bj.position, rj); - result.push(r); + this.result.push(r); + numContacts++; + if(!this.enableFrictionReduction){ + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + if(this.enableFrictionReduction && numContacts){ + this.createFrictionFromAverage(numContacts); } } }; + +/** + * @method convexTrimesh + * @param {Array} result + * @param {Shape} si + * @param {Shape} sj + * @param {Vec3} xi + * @param {Vec3} xj + * @param {Quaternion} qi + * @param {Quaternion} qj + * @param {Body} bi + * @param {Body} bj + */ +// Narrowphase.prototype[Shape.types.CONVEXPOLYHEDRON | Shape.types.TRIMESH] = +// Narrowphase.prototype.convexTrimesh = function(si,sj,xi,xj,qi,qj,bi,bj,rsi,rsj,faceListA,faceListB){ +// var sepAxis = convexConvex_sepAxis; + +// if(xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius){ +// return; +// } + +// // Construct a temp hull for each triangle +// var hullB = new ConvexPolyhedron(); + +// hullB.faces = [[0,1,2]]; +// var va = new Vec3(); +// var vb = new Vec3(); +// var vc = new Vec3(); +// hullB.vertices = [ +// va, +// vb, +// vc +// ]; + +// for (var i = 0; i < sj.indices.length / 3; i++) { + +// var triangleNormal = new Vec3(); +// sj.getNormal(i, triangleNormal); +// hullB.faceNormals = [triangleNormal]; + +// sj.getTriangleVertices(i, va, vb, vc); + +// var d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj); +// if(!d){ +// triangleNormal.scale(-1, triangleNormal); +// d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj); + +// if(!d){ +// continue; +// } +// } + +// var res = []; +// var q = convexConvex_q; +// si.clipAgainstHull(xi,qi,hullB,xj,qj,triangleNormal,-100,100,res); +// for(var j = 0; j !== res.length; j++){ +// var r = this.createContactEquation(bi,bj,si,sj,rsi,rsj), +// ri = r.ri, +// rj = r.rj; +// r.ni.copy(triangleNormal); +// r.ni.negate(r.ni); +// res[j].normal.negate(q); +// q.mult(res[j].depth, q); +// res[j].point.vadd(q, ri); +// rj.copy(res[j].point); + +// // Contact points are in world coordinates. Transform back to relative +// ri.vsub(xi,ri); +// rj.vsub(xj,rj); + +// // Make relative to bodies +// ri.vadd(xi, ri); +// ri.vsub(bi.position, ri); +// rj.vadd(xj, rj); +// rj.vsub(bj.position, rj); + +// result.push(r); +// } +// } +// }; + var particlePlane_normal = new Vec3(); var particlePlane_relpos = new Vec3(); var particlePlane_projected = new Vec3(); @@ -10468,7 +12395,7 @@ var particlePlane_projected = new Vec3(); * @param {Body} bj */ Narrowphase.prototype[Shape.types.PLANE | Shape.types.PARTICLE] = -Narrowphase.prototype.planeParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.planeParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ var normal = particlePlane_normal; normal.set(0,0,1); bj.quaternion.vmult(normal,normal); // Turn normal according to plane orientation @@ -10476,7 +12403,7 @@ Narrowphase.prototype.planeParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ xi.vsub(bj.position,relpos); var dot = normal.dot(relpos); if(dot <= 0.0){ - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); r.ni.copy(normal); // Contact normal is the plane normal r.ni.negate(r.ni); r.ri.set(0,0,0); // Center of particle @@ -10489,7 +12416,8 @@ Narrowphase.prototype.planeParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ // rj is now the projected world position minus plane position r.rj.copy(projected); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -10508,7 +12436,7 @@ var particleSphere_normal = new Vec3(); * @param {Body} bj */ Narrowphase.prototype[Shape.types.PARTICLE | Shape.types.SPHERE] = -Narrowphase.prototype.sphereParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.sphereParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ // The normal is the unit vector from sphere center to particle center var normal = particleSphere_normal; normal.set(0,0,1); @@ -10516,14 +12444,15 @@ Narrowphase.prototype.sphereParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ var lengthSquared = normal.norm2(); if(lengthSquared <= sj.radius * sj.radius){ - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); normal.normalize(); r.rj.copy(normal); r.rj.mult(sj.radius,r.rj); r.ni.copy(normal); // Contact normal r.ni.negate(r.ni); r.ri.set(0,0,0); // Center of particle - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -10548,7 +12477,7 @@ var convexParticle_worldPenetrationVec = new Vec3(); * @param {Body} bj */ Narrowphase.prototype[Shape.types.PARTICLE | Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.convexParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.convexParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ var penetratedFaceIndex = -1; var penetratedFaceNormal = convexParticle_penetratedFaceNormal; var worldPenetrationVec = convexParticle_worldPenetrationVec; @@ -10591,7 +12520,7 @@ Narrowphase.prototype.convexParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ if(penetratedFaceIndex!==-1){ // Setup contact - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); penetratedFaceNormal.mult(minPenetration, worldPenetrationVec); // rj is the particle position projected to the face @@ -10614,7 +12543,8 @@ Narrowphase.prototype.convexParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ rj.vadd(xj, rj); rj.vsub(bj.position, rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } else { console.warn("Point found inside convex, but did not find penetrating face!"); } @@ -10622,8 +12552,10 @@ Narrowphase.prototype.convexParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ }; Narrowphase.prototype[Shape.types.BOX | Shape.types.HEIGHTFIELD] = -Narrowphase.prototype.boxHeightfield = function (result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexHeightfield(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj); +Narrowphase.prototype.boxHeightfield = function (si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexHeightfield(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj); }; var convexHeightfield_tmp1 = new Vec3(); @@ -10631,11 +12563,10 @@ var convexHeightfield_tmp2 = new Vec3(); var convexHeightfield_faceList = [0]; /** - * @method sphereHeightfield + * @method convexHeightfield */ Narrowphase.prototype[Shape.types.CONVEXPOLYHEDRON | Shape.types.HEIGHTFIELD] = Narrowphase.prototype.convexHeightfield = function ( - result, convexShape, hfShape, convexPos, @@ -10662,7 +12593,7 @@ Narrowphase.prototype.convexHeightfield = function ( iMaxY = Math.ceil((localConvexPos.y + radius) / w) + 1; // Bail out if we are out of the terrain - if(iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMaxY > data[0].length){ + if(iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMinY > data[0].length){ return; } @@ -10693,22 +12624,19 @@ Narrowphase.prototype.convexHeightfield = function ( hfShape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) { - this.convexConvex(result, convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); + this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); } // Upper triangle hfShape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) { - this.convexConvex(result, convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); + this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); } } } }; - - - var sphereHeightfield_tmp1 = new Vec3(); var sphereHeightfield_tmp2 = new Vec3(); @@ -10717,7 +12645,6 @@ var sphereHeightfield_tmp2 = new Vec3(); */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.HEIGHTFIELD] = Narrowphase.prototype.sphereHeightfield = function ( - result, sphereShape, hfShape, spherePos, @@ -10767,6 +12694,7 @@ Narrowphase.prototype.sphereHeightfield = function ( return; } + var result = this.result; for(var i = iMinX; i < iMaxX; i++){ for(var j = iMinY; j < iMaxY; j++){ @@ -10776,14 +12704,14 @@ Narrowphase.prototype.sphereHeightfield = function ( hfShape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) { - this.sphereConvex(result, sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); + this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); } // Upper triangle hfShape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) { - this.sphereConvex(result, sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); + this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); } var numContacts = result.length - numContactsBefore; @@ -10800,7 +12728,8 @@ Narrowphase.prototype.sphereHeightfield = function ( } } }; -},{"../equations/ContactEquation":16,"../math/Quaternion":25,"../math/Transform":26,"../math/Vec3":27,"../shapes/ConvexPolyhedron":35,"../shapes/Shape":40,"../solver/Solver":43,"../utils/Vec3Pool":49}],51:[function(_dereq_,module,exports){ + +},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(_dereq_,module,exports){ /* global performance */ module.exports = World; @@ -10834,7 +12763,7 @@ function World(){ EventTarget.apply(this); /** - * Last used timestep. Is set to -1 if not available. + * Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks. * @property {Number} dt */ this.dt = -1; @@ -10922,7 +12851,7 @@ function World(){ * @property narrowphase * @type {Narrowphase} */ - this.narrowphase = new Narrowphase(); + this.narrowphase = new Narrowphase(this); /** * @property {ArrayCollisionMatrix} collisionMatrix @@ -10984,7 +12913,7 @@ function World(){ }; /** - * @property subystems + * @property subsystems * @type {Array} */ this.subsystems = []; @@ -11011,7 +12940,7 @@ var tmpRay = new Ray(); * @method getContactMaterial * @param {Material} m1 * @param {Material} m2 - * @return {Contactmaterial} The contact material if it was found. + * @return {ContactMaterial} The contact material if it was found. */ World.prototype.getContactMaterial = function(m1,m2){ return this.contactMaterialTable.get(m1.id,m2.id); //this.contactmaterials[this.mats2cmat[i+j*this.materials.length]]; @@ -11092,25 +13021,90 @@ World.prototype.removeConstraint = function(c){ * @param {Vec3} from * @param {Vec3} to * @param {Function|RaycastResult} result + * @deprecated Use .raycastAll, .raycastClosest or .raycastAny instead. */ World.prototype.rayTest = function(from, to, result){ - // result = result || new RaycastResult(); - - tmpRay.from.copy(from); - tmpRay.to.copy(to); - tmpRay.getAABB(tmpAABB1); - - tmpArray1.length = 0; - this.broadphase.aabbQuery(this, tmpAABB1, tmpArray1); - - tmpRay.intersectBodies(tmpArray1, result); + if(result instanceof RaycastResult){ + // Do raycastclosest + this.raycastClosest(from, to, { + skipBackfaces: true + }, result); + } else { + // Do raycastAll + this.raycastAll(from, to, { + skipBackfaces: true + }, result); + } +}; + +/** + * Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument. + * @method raycastAll + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {Function} callback + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastAll = function(from, to, options, callback){ + options.mode = Ray.ALL; + options.from = from; + options.to = to; + options.callback = callback; + return tmpRay.intersectWorld(this, options); +}; + +/** + * Ray cast, and stop at the first result. Note that the order is random - but the method is fast. + * @method raycastAny + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {RaycastResult} result + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastAny = function(from, to, options, result){ + options.mode = Ray.ANY; + options.from = from; + options.to = to; + options.result = result; + return tmpRay.intersectWorld(this, options); +}; + +/** + * Ray cast, and return information of the closest hit. + * @method raycastClosest + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {RaycastResult} result + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastClosest = function(from, to, options, result){ + options.mode = Ray.CLOSEST; + options.from = from; + options.to = to; + options.result = result; + return tmpRay.intersectWorld(this, options); }; /** * Remove a rigid body from the simulation. * @method remove * @param {Body} body - * @todo Rename to .removeBody + * @deprecated Use .removeBody instead */ World.prototype.remove = function(body){ body.world = null; @@ -11131,6 +13125,13 @@ World.prototype.remove = function(body){ } }; +/** + * Remove a rigid body from the simulation. + * @method removeBody + * @param {Body} body + */ +World.prototype.removeBody = World.prototype.remove; + /** * Adds a material to the World. * @method addMaterial @@ -11348,11 +13349,23 @@ World.prototype.internalStep = function(dt){ } contacts.length = 0; - this.narrowphase.getContacts(p1,p2, - this, - contacts, - oldcontacts // To be reused - ); + // Transfer FrictionEquation from current list to the pool for reuse + var NoldFrictionEquations = this.frictionEquations.length; + for(i=0; i!==NoldFrictionEquations; i++){ + frictionEquationPool.push(this.frictionEquations[i]); + } + this.frictionEquations.length = 0; + + this.narrowphase.getContacts( + p1, + p2, + this, + contacts, + oldcontacts, // To be reused + this.frictionEquations, + frictionEquationPool + ); + if(doProfiling){ profile.narrowphase = performance.now() - profilingStart; } @@ -11361,15 +13374,13 @@ World.prototype.internalStep = function(dt){ if(doProfiling){ profilingStart = performance.now(); } - var ncontacts = contacts.length; - // Transfer FrictionEquation from current list to the pool for reuse - var NoldFrictionEquations = this.frictionEquations.length; - for(i=0; i!==NoldFrictionEquations; i++){ - frictionEquationPool.push(this.frictionEquations[i]); + // Add all friction eqs + for (var i = 0; i < this.frictionEquations.length; i++) { + solver.addEquation(this.frictionEquations[i]); } - this.frictionEquations.length = 0; + var ncontacts = contacts.length; for(var k=0; k!==ncontacts; k++){ // Current contact @@ -11381,9 +13392,6 @@ World.prototype.internalStep = function(dt){ si = c.si, sj = c.sj; - // Resolve indices - var i = bodies.indexOf(bi), j = bodies.indexOf(bj); - // Get collision properties var cm; if(bi.material && bj.material){ @@ -11391,112 +13399,108 @@ World.prototype.internalStep = function(dt){ } else { cm = this.defaultContactMaterial; } - var mu = cm.friction; - - // g = ( xj + rj - xi - ri ) .dot ( ni ) - var gvec = World_step_gvec; - gvec.set(bj.position.x + c.rj.x - bi.position.x - c.ri.x, - bj.position.y + c.rj.y - bi.position.y - c.ri.y, - bj.position.z + c.rj.z - bi.position.z - c.ri.z); - var g = gvec.dot(c.ni); // Gap, negative if penetration - - // Action if penetration - if(g < 0.0){ - c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; + // c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; - c.restitution = cm.restitution; - c.penetration = g; - c.setSpookParams(cm.contactEquationStiffness, - cm.contactEquationRelaxation, - dt); - - solver.addEquation(c); - - // Add friction constraint equation - if(mu > 0){ + var mu = cm.friction; + // c.restitution = cm.restitution; - // Create 2 tangent equations - var mug = mu*gnorm; - var reducedMass = (bi.invMass + bj.invMass); - if(reducedMass > 0){ - reducedMass = 1/reducedMass; - } - var pool = frictionEquationPool; - var c1 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); - var c2 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); - this.frictionEquations.push(c1); - this.frictionEquations.push(c2); - - c1.bi = c2.bi = bi; - c1.bj = c2.bj = bj; - c1.minForce = c2.minForce = -mug*reducedMass; - c1.maxForce = c2.maxForce = mug*reducedMass; - - // Copy over the relative vectors - c1.ri.copy(c.ri); - c1.rj.copy(c.rj); - c2.ri.copy(c.ri); - c2.rj.copy(c.rj); - - // Construct tangents - c.ni.tangents(c1.t, c2.t); - - // Set spook params - c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); - c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); - - c1.enabled = c2.enabled = c.enabled; - - // Add equations to solver - solver.addEquation(c1); - solver.addEquation(c2); - } + // If friction or restitution were specified in the material, use them + if(bi.material && bj.material){ + if(bi.material.friction >= 0 && bj.material.friction >= 0){ + mu = bi.material.friction * bj.material.friction; + } - if( bi.allowSleep && - bi.type === Body.DYNAMIC && - bi.sleepState === Body.SLEEPING && - bj.sleepState === Body.AWAKE && - bj.type !== Body.STATIC - ){ - var speedSquaredB = bj.velocity.norm2() + bj.angularVelocity.norm2(); - var speedLimitSquaredB = Math.pow(bj.sleepSpeedLimit,2); - if(speedSquaredB >= speedLimitSquaredB*2){ - bi._wakeUpAfterNarrowphase = true; - } + if(bi.material.restitution >= 0 && bj.material.restitution >= 0){ + c.restitution = bi.material.restitution * bj.material.restitution; } + } - if( bj.allowSleep && - bj.type === Body.DYNAMIC && - bj.sleepState === Body.SLEEPING && - bi.sleepState === Body.AWAKE && - bi.type !== Body.STATIC - ){ - var speedSquaredA = bi.velocity.norm2() + bi.angularVelocity.norm2(); - var speedLimitSquaredA = Math.pow(bi.sleepSpeedLimit,2); - if(speedSquaredA >= speedLimitSquaredA*2){ - bj._wakeUpAfterNarrowphase = true; - } + // c.setSpookParams( + // cm.contactEquationStiffness, + // cm.contactEquationRelaxation, + // dt + // ); + + solver.addEquation(c); + + // // Add friction constraint equation + // if(mu > 0){ + + // // Create 2 tangent equations + // var mug = mu * gnorm; + // var reducedMass = (bi.invMass + bj.invMass); + // if(reducedMass > 0){ + // reducedMass = 1/reducedMass; + // } + // var pool = frictionEquationPool; + // var c1 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); + // var c2 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); + // this.frictionEquations.push(c1, c2); + + // c1.bi = c2.bi = bi; + // c1.bj = c2.bj = bj; + // c1.minForce = c2.minForce = -mug*reducedMass; + // c1.maxForce = c2.maxForce = mug*reducedMass; + + // // Copy over the relative vectors + // c1.ri.copy(c.ri); + // c1.rj.copy(c.rj); + // c2.ri.copy(c.ri); + // c2.rj.copy(c.rj); + + // // Construct tangents + // c.ni.tangents(c1.t, c2.t); + + // // Set spook params + // c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); + // c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); + + // c1.enabled = c2.enabled = c.enabled; + + // // Add equations to solver + // solver.addEquation(c1); + // solver.addEquation(c2); + // } + + if( bi.allowSleep && + bi.type === Body.DYNAMIC && + bi.sleepState === Body.SLEEPING && + bj.sleepState === Body.AWAKE && + bj.type !== Body.STATIC + ){ + var speedSquaredB = bj.velocity.norm2() + bj.angularVelocity.norm2(); + var speedLimitSquaredB = Math.pow(bj.sleepSpeedLimit,2); + if(speedSquaredB >= speedLimitSquaredB*2){ + bi._wakeUpAfterNarrowphase = true; } + } - // Now we know that i and j are in contact. Set collision matrix state - this.collisionMatrix.set(bi, bj, true); + if( bj.allowSleep && + bj.type === Body.DYNAMIC && + bj.sleepState === Body.SLEEPING && + bi.sleepState === Body.AWAKE && + bi.type !== Body.STATIC + ){ + var speedSquaredA = bi.velocity.norm2() + bi.angularVelocity.norm2(); + var speedLimitSquaredA = Math.pow(bi.sleepSpeedLimit,2); + if(speedSquaredA >= speedLimitSquaredA*2){ + bj._wakeUpAfterNarrowphase = true; + } + } - if (this.collisionMatrix.get(bi, bj) !== this.collisionMatrixPrevious.get(bi, bj)) { - // First contact! - // We reuse the collideEvent object, otherwise we will end up creating new objects for each new contact, even if there's no event listener attached. - World_step_collideEvent.body = bj; - World_step_collideEvent.contact = c; - bi.dispatchEvent(World_step_collideEvent); + // Now we know that i and j are in contact. Set collision matrix state + this.collisionMatrix.set(bi, bj, true); - World_step_collideEvent.body = bi; - bj.dispatchEvent(World_step_collideEvent); + if (!this.collisionMatrixPrevious.get(bi, bj)) { + // First contact! + // We reuse the collideEvent object, otherwise we will end up creating new objects for each new contact, even if there's no event listener attached. + World_step_collideEvent.body = bj; + World_step_collideEvent.contact = c; + bi.dispatchEvent(World_step_collideEvent); - /* - bi.wakeUp(); - bj.wakeUp(); - */ - } + World_step_collideEvent.body = bi; + bj.dispatchEvent(World_step_collideEvent); } } if(doProfiling){ @@ -11579,7 +13583,6 @@ World.prototype.internalStep = function(dt){ for(i=0; i!==N; i++){ var b = bodies[i], - s = b.shape, force = b.force, tau = b.torque; if((b.type & DYNAMIC_OR_KINEMATIC) && b.sleepState !== Body.SLEEPING){ // Only for dynamic @@ -11598,12 +13601,6 @@ World.prototype.internalStep = function(dt){ invInertia.vmult(tau,invI_tau_dt); invI_tau_dt.mult(dt,invI_tau_dt); invI_tau_dt.vadd(angularVelo,angularVelo); - //console.log(invI_tau_dt); - /* - angularVelo.x += tau.x * invInertia.x * dt; - angularVelo.y += tau.y * invInertia.y * dt; - angularVelo.z += tau.z * invInertia.z * dt; - */ } // Use new velocity - leap frog @@ -11631,29 +13628,13 @@ World.prototype.internalStep = function(dt){ b.aabbNeedsUpdate = true; } - if(s){ - switch(s.type){ - case PLANE: - s.worldNormalNeedsUpdate = true; - break; - case CONVEX: - s.worldFaceNormalsNeedsUpdate = true; - s.worldVerticesNeedsUpdate = true; - break; - } - } - // Update world inertia if(b.updateInertiaWorld){ b.updateInertiaWorld(); } } - b.force.set(0,0,0); - if(b.torque){ - b.torque.set(0,0,0); - } - } + this.clearForces(); this.broadphase.dirty = true; @@ -11684,6 +13665,23 @@ World.prototype.internalStep = function(dt){ } }; -},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":16,"../equations/FrictionEquation":18,"../material/ContactMaterial":21,"../material/Material":22,"../math/Quaternion":25,"../math/Vec3":27,"../objects/Body":28,"../shapes/Shape":40,"../solver/GSSolver":42,"../utils/EventTarget":45,"../utils/TupleDictionary":47,"../utils/Vec3Pool":49,"./Narrowphase":50}]},{},[2]) +/** + * Sets all body forces in the world to zero. + * @method clearForces + */ +World.prototype.clearForces = function(){ + var bodies = this.bodies; + var N = bodies.length; + for(var i=0; i !== N; i++){ + var b = bodies[i], + force = b.force, + tau = b.torque; + + b.force.set(0,0,0); + b.torque.set(0,0,0); + } +}; + +},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../material/ContactMaterial":24,"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Shape":43,"../solver/GSSolver":46,"../utils/EventTarget":49,"../utils/TupleDictionary":52,"../utils/Vec3Pool":54,"./Narrowphase":55}]},{},[2]) (2) }); \ No newline at end of file diff --git a/build/cannon.min.js b/build/cannon.min.js index 2dd2d2e3c..01a53bc6d 100644 --- a/build/cannon.min.js +++ b/build/cannon.min.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 cannon.js Authors + * Copyright (c) 2015 cannon.js Authors * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -21,7 +21,8 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&false)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.CANNON=e()}}(function(){return function e(f,n,o){function d(t,l){if(!n[t]){if(!f[t]){var u="function"==typeof require&&require;if(!l&&u)return u(t,!0);if(i)return i(t,!0);throw new Error("Cannot find module '"+t+"'")}var p=n[t]={exports:{}};f[t][0].call(p.exports,function(e){var n=f[t][1][e];return d(n?n:e)},p,p.exports,e,f,n,o)}return n[t].exports}for(var i="function"==typeof require&&require,t=0;t (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(e,f){f.exports={version:e("../package.json").version,ArrayCollisionMatrix:e("./collision/ArrayCollisionMatrix"),Body:e("./objects/Body"),Box:e("./shapes/Box"),Broadphase:e("./collision/Broadphase"),Constraint:e("./constraints/Constraint"),ContactEquation:e("./equations/ContactEquation"),Narrowphase:e("./world/Narrowphase"),ContactMaterial:e("./material/ContactMaterial"),ConvexPolyhedron:e("./shapes/ConvexPolyhedron"),Cylinder:e("./shapes/Cylinder"),DistanceConstraint:e("./constraints/DistanceConstraint"),Equation:e("./equations/Equation"),EventTarget:e("./utils/EventTarget"),FrictionEquation:e("./equations/FrictionEquation"),GSSolver:e("./solver/GSSolver"),GridBroadphase:e("./collision/GridBroadphase"),Heightfield:e("./shapes/Heightfield"),HingeConstraint:e("./constraints/HingeConstraint"),Mat3:e("./math/Mat3"),Material:e("./material/Material"),NaiveBroadphase:e("./collision/NaiveBroadphase"),ObjectCollisionMatrix:e("./collision/ObjectCollisionMatrix"),Pool:e("./utils/Pool"),Particle:e("./shapes/Particle"),Plane:e("./shapes/Plane"),PointToPointConstraint:e("./constraints/PointToPointConstraint"),Quaternion:e("./math/Quaternion"),Ray:e("./collision/Ray"),RaycastVehicle:e("./objects/RaycastVehicle"),RaycastResult:e("./collision/RaycastResult"),RigidVehicle:e("./objects/RigidVehicle"),RotationalEquation:e("./equations/RotationalEquation"),RotationalMotorEquation:e("./equations/RotationalMotorEquation"),SAPBroadphase:e("./collision/SAPBroadphase"),SPHSystem:e("./objects/SPHSystem"),Shape:e("./shapes/Shape"),Solver:e("./solver/Solver"),Sphere:e("./shapes/Sphere"),SplitSolver:e("./solver/SplitSolver"),Spring:e("./objects/Spring"),Vec3:e("./math/Vec3"),Vec3Pool:e("./utils/Vec3Pool"),World:e("./world/World")}},{"../package.json":1,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/Constraint":12,"./constraints/DistanceConstraint":13,"./constraints/HingeConstraint":14,"./constraints/PointToPointConstraint":15,"./equations/ContactEquation":16,"./equations/Equation":17,"./equations/FrictionEquation":18,"./equations/RotationalEquation":19,"./equations/RotationalMotorEquation":20,"./material/ContactMaterial":21,"./material/Material":22,"./math/Mat3":24,"./math/Quaternion":25,"./math/Vec3":27,"./objects/Body":28,"./objects/RaycastVehicle":29,"./objects/RigidVehicle":30,"./objects/SPHSystem":31,"./objects/Spring":32,"./shapes/Box":34,"./shapes/ConvexPolyhedron":35,"./shapes/Cylinder":36,"./shapes/Heightfield":37,"./shapes/Particle":38,"./shapes/Plane":39,"./shapes/Shape":40,"./shapes/Sphere":41,"./solver/GSSolver":42,"./solver/Solver":43,"./solver/SplitSolver":44,"./utils/EventTarget":45,"./utils/Pool":46,"./utils/Vec3Pool":49,"./world/Narrowphase":50,"./world/World":51}],3:[function(e,f){function n(e){e=e||{},this.lowerBound=new o,e.lowerBound&&this.lowerBound.copy(e.lowerBound),this.upperBound=new o,e.upperBound&&this.upperBound.copy(e.upperBound)}{var o=e("../math/Vec3");e("../utils/Utils")}f.exports=n;var d=new o;n.prototype.setFromPoints=function(e,f,n,o){var i=this.lowerBound,t=this.upperBound,l=n;i.copy(e[0]),l&&l.vmult(i,i),t.copy(i);for(var u=1;ut.x&&(t.x=p.x),p.xt.y&&(t.y=p.y),p.yt.z&&(t.z=p.z),p.zf&&(this.lowerBound.x=f);var n=e.upperBound.x;this.upperBound.xf&&(this.lowerBound.y=f);var n=e.upperBound.y;this.upperBound.yf&&(this.lowerBound.z=f);var n=e.upperBound.z;this.upperBound.ze){var n=f;f=e,e=n}return this.matrix[(e*(e+1)>>1)+f-1]},n.prototype.set=function(e,f,n){if(e=e.index,f=f.index,f>e){var o=f;f=e,e=o}this.matrix[(e*(e+1)>>1)+f-1]=n?1:0},n.prototype.reset=function(){for(var e=0,f=this.matrix.length;e!==f;e++)this.matrix[e]=0},n.prototype.setNumObjects=function(e){this.matrix.length=e*(e-1)>>1}},{}],5:[function(e,f){function n(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}{var o=e("../objects/Body"),d=e("../math/Vec3"),i=e("../math/Quaternion");e("../shapes/Shape"),e("../shapes/Plane")}f.exports=n,n.prototype.collisionPairs=function(){throw new Error("collisionPairs not implemented for this BroadPhase class!")};var t=o.STATIC|o.KINEMATIC;n.prototype.needBroadphaseCollision=function(e,f){return 0===(e.collisionFilterGroup&f.collisionFilterMask)||0===(f.collisionFilterGroup&e.collisionFilterMask)?!1:0===(e.type&t)&&e.sleepState!==o.SLEEPING||0===(f.type&t)&&f.sleepState!==o.SLEEPING?!0:!1},n.prototype.intersectionTest=function(e,f,n,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(e,f,n,o):this.doBoundingSphereBroadphase(e,f,n,o)};{var l=new d;new d,new i,new d}n.prototype.doBoundingSphereBroadphase=function(e,f,n,o){var d=l;f.position.vsub(e.position,d);var i=Math.pow(e.boundingRadius+f.boundingRadius,2),t=d.norm2();i>t&&(n.push(e),o.push(f))},n.prototype.doBoundingBoxBroadphase=function(e,f,n,o){e.aabbNeedsUpdate&&e.computeAABB(),f.aabbNeedsUpdate&&f.computeAABB(),e.aabb.overlaps(f.aabb)&&(n.push(e),o.push(f))};var u={keys:[]},p=[],s=[];n.prototype.makePairsUnique=function(e,f){for(var n=u,o=p,d=s,i=e.length,t=0;t!==i;t++)o[t]=e[t],d[t]=f[t];e.length=0,f.length=0;for(var t=0;t!==i;t++){var l=o[t].id,y=d[t].id,c=y>l?l+","+y:y+","+l;n[c]=t,n.keys.push(c)}for(var t=0;t!==n.keys.length;t++){var c=n.keys.pop(),a=n[c];e.push(o[a]),f.push(d[a]),delete n[c]}},n.prototype.setWorld=function(){};var y=new d;n.boundingSphereCheck=function(e,f){var n=y;return e.position.vsub(f.position,n),Math.pow(e.shape.boundingSphereRadius+f.shape.boundingSphereRadius,2)>n.norm2()},n.prototype.aabbQuery=function(){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":25,"../math/Vec3":27,"../objects/Body":28,"../shapes/Plane":39,"../shapes/Shape":40}],6:[function(e,f){function n(e,f,n,i,t){o.apply(this),this.nx=n||10,this.ny=i||10,this.nz=t||10,this.aabbMin=e||new d(100,100,100),this.aabbMax=f||new d(-100,-100,-100);var l=this.nx*this.ny*this.nz;if(0>=l)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=l,this.binLengths.length=l;for(var u=0;l>u;u++)this.bins[u]=[],this.binLengths[u]=0}f.exports=n;var o=e("./Broadphase"),d=e("../math/Vec3"),i=e("../shapes/Shape");n.prototype=new o,n.prototype.constructor=n;{var t=new d;new d}n.prototype.collisionPairs=function(e,f,n){function o(e,f,n,o,d,i,t){var l=(e-g)*v|0,u=(f-x)*A|0,p=(n-j)*C|0,b=I((o-g)*v),m=I((d-x)*A),N=I((i-j)*C);0>l?l=0:l>=s&&(l=s-1),0>u?u=0:u>=y&&(u=y-1),0>p?p=0:p>=c&&(p=c-1),0>b?b=0:b>=s&&(b=s-1),0>m?m=0:m>=y&&(m=y-1),0>N?N=0:N>=c&&(N=c-1),l*=a,u*=r,p*=w,b*=a,m*=r,N*=w;for(var O=l;b>=O;O+=a)for(var h=u;m>=h;h+=r)for(var k=p;N>=k;k+=w){var q=O+h+k;E[q][F[q]++]=t}}for(var d=e.numObjects(),l=e.bodies,u=this.aabbMax,p=this.aabbMin,s=this.nx,y=this.ny,c=this.nz,a=y*c,r=c,w=1,b=u.x,m=u.y,N=u.z,g=p.x,x=p.y,j=p.z,v=s/(b-g),A=y/(m-x),C=c/(N-j),O=(b-g)/s,h=(m-x)/y,k=(N-j)/c,q=.5*Math.sqrt(O*O+h*h+k*k),z=i.types,B=z.SPHERE,D=z.PLANE,E=(z.BOX,z.COMPOUND,z.CONVEXPOLYHEDRON,this.bins),F=this.binLengths,G=this.bins.length,H=0;H!==G;H++)F[H]=0;for(var I=Math.ceil,p=Math.min,u=Math.max,H=0;H!==d;H++){var J=l[H],K=J.shape;switch(K.type){case B:var L=J.position.x,M=J.position.y,P=J.position.z,Q=K.radius;o(L-Q,M-Q,P-Q,L+Q,M+Q,P+Q,J);break;case D:K.worldNormalNeedsUpdate&&K.computeWorldNormal(J.quaternion);var R=K.worldNormal,S=g+.5*O-J.position.x,T=x+.5*h-J.position.y,U=j+.5*k-J.position.z,V=t;V.set(S,T,U);for(var W=0,X=0;W!==s;W++,X+=a,V.y=T,V.x+=O)for(var Y=0,Z=0;Y!==y;Y++,Z+=r,V.z=U,V.y+=h)for(var $=0,_=0;$!==c;$++,_+=w,V.z+=k)if(V.dot(R)1)for(var nf=E[H],W=0;W!==ff;W++)for(var J=nf[W],Y=0;Y!==W;Y++){var of=nf[Y];this.needBroadphaseCollision(J,of)&&this.intersectionTest(J,of,f,n)}}this.makePairsUnique(f,n)}},{"../math/Vec3":27,"../shapes/Shape":40,"./Broadphase":5}],7:[function(e,f){function n(){o.apply(this)}f.exports=n;var o=e("./Broadphase"),d=e("./AABB");n.prototype=new o,n.prototype.constructor=n,n.prototype.collisionPairs=function(e,f,n){var o,d,i,t,l=e.bodies,u=l.length;for(o=0;o!==u;o++)for(d=0;d!==o;d++)i=l[o],t=l[d],this.needBroadphaseCollision(i,t)&&this.intersectionTest(i,t,f,n)};new d;n.prototype.aabbQuery=function(e,f,n){n=n||[];for(var o=0;oe){var n=f;f=e,e=n}return e+"-"+f in this.matrix},n.prototype.set=function(e,f,n){if(e=e.id,f=f.id,f>e){var o=f;f=e,e=o}n?this.matrix[e+"-"+f]=!0:delete this.matrix[e+"-"+f]},n.prototype.reset=function(){this.matrix={}},n.prototype.setNumObjects=function(){}},{}],9:[function(e,f){function n(e,f){this.from=e?e.clone():new i,this.to=f?f.clone():new i,this._direction=new i,this.precision=1e-4,this.checkCollisionResponse=!0}function o(e,f,n,o){o.vsub(f,v),n.vsub(f,s),e.vsub(f,y);var d,i,t=v.dot(v),l=v.dot(s),u=v.dot(y),p=s.dot(s),c=s.dot(y);return(d=p*u-l*c)>=0&&(i=t*c-l*u)>=0&&t*p-l*l>d+i}function d(e,f,n){n.vsub(e,v);var o=v.dot(f);f.mult(o,A),A.vadd(e,A);var d=n.distanceTo(A);return d}f.exports=n;{var i=e("../math/Vec3"),t=e("../math/Quaternion"),l=e("../math/Transform"),u=(e("../shapes/ConvexPolyhedron"),e("../shapes/Box"),e("../collision/RaycastResult")),p=e("../shapes/Shape");e("../collision/AABB")}n.prototype.constructor=n;var s=new i,y=new i;n.prototype.intersectBody=function(e,f,n){var o=this.checkCollisionResponse;if(o&&!e.collisionResponse)return f;n||(this._updateDirection(),n=this._direction);for(var d=new i,l=new t,u=0;uo;o++)this.intersectBody(e[o],f,n)},n.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},n.prototype.intersectShape=function(e,f,n,o,i,t){var l=this.from,u=d(l,i,n);return u>e.boundingSphereRadius?t:(this[e.type](e,f,n,o,i,t),t)};var c=(new i,new i,new i),a=new i,r=new i,w=new i,b=(new i,new u);n.prototype.intersectBox=function(e,f,n,o,d,i){return this.intersectConvex(e.convexPolyhedronRepresentation,f,n,o,d,i)},n.prototype[p.types.BOX]=n.prototype.intersectBox,n.prototype.intersectPlane=function(e,f,n,o,d,t){var l=this.from,u=this.to,p=new i(0,0,1);f.vmult(p,p);var s=new i;l.vsub(n,s);var y=s.dot(p);u.vsub(n,s);var c=s.dot(p);if(y*c>0)return t;if(l.distanceTo(u)r)&&(r=y[0]),(null===a||y[1]w)&&(w=y[1])),null===c)return u;var N=[];e.getRectMinMax(c,a,r,w,N);for(var g=(N[0],N[1],c);r>=g;g++)for(var x=a;w>=x;x++)e.getConvexTrianglePillar(g,x,!1),l.pointToWorldFrame(o,f,e.pillarOffset,p),this.intersectConvex(e.pillarConvex,f,p,d,t,u,m),e.getConvexTrianglePillar(g,x,!0),l.pointToWorldFrame(o,f,e.pillarOffset,p),this.intersectConvex(e.pillarConvex,f,p,d,t,u,m);return u},n.prototype[p.types.HEIGHTFIELD]=n.prototype.intersectHeightfield,n.prototype.intersectSphere=function(e,f,n,o,d,t){var l=this.from,u=this.to,p=e.radius,s=Math.pow(u.x-l.x,2)+Math.pow(u.y-l.y,2)+Math.pow(u.z-l.z,2),y=2*((u.x-l.x)*(l.x-n.x)+(u.y-l.y)*(l.y-n.y)+(u.z-l.z)*(l.z-n.z)),c=Math.pow(l.x-n.x,2)+Math.pow(l.y-n.y,2)+Math.pow(l.z-n.z,2)-Math.pow(p,2),a=Math.pow(y,2)-4*s*c;if(0>a)return t;if(0===a){var r=new i;l.lerp(u,a,r);var w=new i;if(r.vsub(n,w),w.normalize(),this.reportIntersection(w,r,e,o,t))return t}else{var b=(-y-Math.sqrt(a))/(2*s),m=(-y+Math.sqrt(a))/(2*s),r=new i;l.lerp(u,b,r);var w=new i;if(r.vsub(n,w),w.normalize(),this.reportIntersection(w,r,e,o,t))return t;l.lerp(u,m,r);var w=new i;if(r.vsub(n,w),w.normalize(),this.reportIntersection(w,r,e,o,t))return t}return t},n.prototype[p.types.SPHERE]=n.prototype.intersectSphere;var N=new i,g=new i,x=new i,j=new i;n.prototype.intersectConvex=function(e,f,n,d,i,t,l){for(var u=g,p=N,s=j,y=x,b=l&&l.faceList||null,m=e.faces,v=e.vertices,A=e.faceNormals,C=this.from,O=this.to,h=C.distanceTo(O),k=-1,q=b?b.length:m.length,z=0;q>z;z++){var B=b?b[z]:z,D=m[B],E=A[B],F=f,G=n;s.copy(v[D[0]]),F.vmult(s,s),s.vadd(G,s),s.vsub(C,s),F.vmult(E,p);var H=i.dot(p);if(!(Math.abs(H)I)&&0>H){i.mult(I,c),c.vadd(C,c),a.copy(v[D[0]]),F.vmult(a,a),G.vadd(a,a);for(var J=1;Jh||(-1===k||k>K)&&(k=K,u.copy(p),y.copy(c))}}}}return-1!==k&&this.reportIntersection(u,y,e,d,t)?t:t},n.prototype[p.types.CONVEXPOLYHEDRON]=n.prototype.intersectConvex,n.prototype.reportIntersection=function(e,f,n,o,d){var i=this.from,t=this.to,l=i.distanceTo(f);return d instanceof u?((lf;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.x<=o.aabb.lowerBound.x);d--)e[d+1]=e[d];e[d+1]=o}return e},n.insertionSortY=function(e){for(var f=1,n=e.length;n>f;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.y<=o.aabb.lowerBound.y);d--)e[d+1]=e[d];e[d+1]=o}return e},n.insertionSortZ=function(e){for(var f=1,n=e.length;n>f;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.z<=o.aabb.lowerBound.z);d--)e[d+1]=e[d];e[d+1]=o}return e},n.prototype.collisionPairs=function(e,f,o){var d,i,t=this.axisList,l=t.length,u=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),d=0;d!==l;d++){var p=t[d];for(i=d+1;l>i;i++){var s=t[i];if(this.needBroadphaseCollision(p,s)){if(!n.checkBounds(p,s,u))break;this.intersectionTest(p,s,f,o)}}}},n.prototype.sortList=function(){for(var e=this.axisList,f=this.axisIndex,o=e.length,d=0;d!==o;d++){var i=e[d];i.aabbNeedsUpdate&&i.computeAABB()}0===f?n.insertionSortX(e):1===f?n.insertionSortY(e):2===f&&n.insertionSortZ(e)},n.checkBounds=function(e,f,n){var o;0===n&&(o="x"),1===n&&(o="y"),2===n&&(o="z");var d=e.position[o],i=e.boundingRadius,t=f.position[o],l=f.boundingRadius,u=d+i,p=t-l;return u>p},n.prototype.autoDetectAxis=function(){for(var e=0,f=0,n=0,o=0,d=0,i=0,t=this.axisList,l=t.length,u=1/l,p=0;p!==l;p++){var s=t[p],y=s.position.x;e+=y,f+=y*y;var c=s.position.y;n+=c,o+=c*c;var a=s.position.z;d+=a,i+=a*a}var r=f-e*e*u,w=o-n*n*u,b=i-d*d*u;this.axisIndex=r>w?r>b?0:2:w>b?1:2},n.prototype.aabbQuery=function(e,f,n){n=n||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,d="x";1===o&&(d="y"),2===o&&(d="z");for(var i=this.axisList,t=(f.lowerBound[d],f.upperBound[d],0);td;d++)for(var i=0;3>i;i++){for(var t=0,l=0;3>l;l++)t+=e.elements[d+3*l]*this.elements[l+3*i];o.elements[d+3*i]=t}return o},n.prototype.scale=function(e,f){f=f||new n;for(var o=this.elements,d=f.elements,i=0;3!==i;i++)d[3*i+0]=e.x*o[3*i+0],d[3*i+1]=e.y*o[3*i+1],d[3*i+2]=e.z*o[3*i+2];return f},n.prototype.solve=function(e,f){f=f||new o;for(var n=3,d=4,i=[],t=0;n*d>t;t++)i.push(0);var t,l;for(t=0;3>t;t++)for(l=0;3>l;l++)i[t+d*l]=this.elements[t+3*l];i[3]=e.x,i[7]=e.y,i[11]=e.z;var u,p,s=3,y=s,c=4;do{if(t=y-s,0===i[t+d*t])for(l=t+1;y>l;l++)if(0!==i[t+d*l]){u=c;do p=c-u,i[p+d*t]+=i[p+d*l];while(--u);break}if(0!==i[t+d*t])for(l=t+1;y>l;l++){var a=i[t+d*l]/i[t+d*t];u=c;do p=c-u,i[p+d*l]=t>=p?0:i[p+d*l]-i[p+d*t]*a;while(--u)}}while(--s);if(f.z=i[2*d+3]/i[2*d+2],f.y=(i[1*d+3]-i[1*d+2]*f.z)/i[1*d+1],f.x=(i[0*d+3]-i[0*d+2]*f.z-i[0*d+1]*f.y)/i[0*d+0],isNaN(f.x)||isNaN(f.y)||isNaN(f.z)||1/0===f.x||1/0===f.y||1/0===f.z)throw"Could not solve equation! Got x=["+f.toString()+"], b=["+e.toString()+"], A=["+this.toString()+"]";return f},n.prototype.e=function(e,f,n){return void 0===n?this.elements[f+3*e]:void(this.elements[f+3*e]=n)},n.prototype.copy=function(e){for(var f=0;fn;n++)e+=this.elements[n]+f;return e},n.prototype.reverse=function(e){e=e||new n;for(var f=3,o=6,d=[],i=0;f*o>i;i++)d.push(0);var i,t;for(i=0;3>i;i++)for(t=0;3>t;t++)d[i+o*t]=this.elements[i+3*t];d[3]=1,d[9]=0,d[15]=0,d[4]=0,d[10]=1,d[16]=0,d[5]=0,d[11]=0,d[17]=1;var l,u,p=3,s=p,y=o;do{if(i=s-p,0===d[i+o*i])for(t=i+1;s>t;t++)if(0!==d[i+o*t]){l=y;do u=y-l,d[u+o*i]+=d[u+o*t];while(--l);break}if(0!==d[i+o*i])for(t=i+1;s>t;t++){var c=d[i+o*t]/d[i+o*i];l=y;do u=y-l,d[u+o*t]=i>=u?0:d[u+o*t]-d[u+o*i]*c;while(--l)}}while(--p);i=2;do{t=i-1;do{var c=d[i+o*t]/d[i+o*i];l=o;do u=o-l,d[u+o*t]=d[u+o*t]-d[u+o*i]*c;while(--l)}while(t--)}while(--i);i=2;do{var c=1/d[i+o*i];l=o;do u=o-l,d[u+o*i]=d[u+o*i]*c;while(--l)}while(i--);i=2;do{t=2;do{if(u=d[f+t+o*i],isNaN(u)||1/0===u)throw"Could not reverse! A=["+this.toString()+"]";e.e(i,t,u)}while(t--)}while(i--);return e},n.prototype.setRotationFromQuaternion=function(e){var f=e.x,n=e.y,o=e.z,d=e.w,i=f+f,t=n+n,l=o+o,u=f*i,p=f*t,s=f*l,y=n*t,c=n*l,a=o*l,r=d*i,w=d*t,b=d*l,m=this.elements;return m[0]=1-(y+a),m[1]=p-b,m[2]=s+w,m[3]=p+b,m[4]=1-(u+a),m[5]=c-r,m[6]=s-w,m[7]=c+r,m[8]=1-(u+y),this},n.prototype.transpose=function(e){e=e||new n;for(var f=e.elements,o=this.elements,d=0;3!==d;d++)for(var i=0;3!==i;i++)f[3*d+i]=o[3*i+d];return e}},{"./Vec3":27}],25:[function(e,f){function n(e,f,n,o){this.x=void 0!==e?e:0,this.y=void 0!==f?f:0,this.z=void 0!==n?n:0,this.w=void 0!==o?o:1}f.exports=n;var o=e("./Vec3");n.prototype.set=function(e,f,n,o){this.x=e,this.y=f,this.z=n,this.w=o},n.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},n.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},n.prototype.setFromAxisAngle=function(e,f){var n=Math.sin(.5*f);this.x=e.x*n,this.y=e.y*n,this.z=e.z*n,this.w=Math.cos(.5*f)},n.prototype.toAxisAngle=function(e){e=e||new o,this.normalize();var f=2*Math.acos(this.w),n=Math.sqrt(1-this.w*this.w);return.001>n?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/n,e.y=this.y/n,e.z=this.z/n),[e,f]};var d=new o,i=new o;n.prototype.setFromVectors=function(e,f){if(e.isAntiparallelTo(f)){var n=d,o=i;e.tangents(n,o),this.setFromAxisAngle(n,Math.PI)}else{var t=e.cross(f);this.x=t.x,this.y=t.y,this.z=t.z,this.w=Math.sqrt(Math.pow(e.norm(),2)*Math.pow(f.norm(),2))+e.dot(f),this.normalize()}};var t=new o,l=new o,u=new o;n.prototype.mult=function(e,f){f=f||new n;var o=this.w,d=t,i=l,p=u;return d.set(this.x,this.y,this.z),i.set(e.x,e.y,e.z),f.w=o*e.w-d.dot(i),d.cross(i,p),f.x=o*i.x+e.w*d.x+p.x,f.y=o*i.y+e.w*d.y+p.y,f.z=o*i.z+e.w*d.z+p.z,f},n.prototype.inverse=function(e){var f=this.x,o=this.y,d=this.z,i=this.w;e=e||new n,this.conjugate(e);var t=1/(f*f+o*o+d*d+i*i);return e.x*=t,e.y*=t,e.z*=t,e.w*=t,e},n.prototype.conjugate=function(e){return e=e||new n,e.x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},n.prototype.normalize=function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(e=1/e,this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.normalizeFast=function(){var e=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.vmult=function(e,f){f=f||new o;var n=e.x,d=e.y,i=e.z,t=this.x,l=this.y,u=this.z,p=this.w,s=p*n+l*i-u*d,y=p*d+u*n-t*i,c=p*i+t*d-l*n,a=-t*n-l*d-u*i;return f.x=s*p+a*-t+y*-u-c*-l,f.y=y*p+a*-l+c*-t-s*-u,f.z=c*p+a*-u+s*-l-y*-t,f},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},n.prototype.toEuler=function(e,f){f=f||"YZX";var n,o,d,i=this.x,t=this.y,l=this.z,u=this.w;switch(f){case"YZX":var p=i*t+l*u;if(p>.499&&(n=2*Math.atan2(i,u),o=Math.PI/2,d=0),-.499>p&&(n=-2*Math.atan2(i,u),o=-Math.PI/2,d=0),isNaN(n)){var s=i*i,y=t*t,c=l*l;n=Math.atan2(2*t*u-2*i*l,1-2*y-2*c),o=Math.asin(2*p),d=Math.atan2(2*i*u-2*t*l,1-2*s-2*c)}break;default:throw new Error("Euler order "+f+" not supported yet.")}e.y=n,e.z=o,e.x=d},n.prototype.setFromEuler=function(e,f,n,o){o=o||"XYZ";var d=Math.cos(e/2),i=Math.cos(f/2),t=Math.cos(n/2),l=Math.sin(e/2),u=Math.sin(f/2),p=Math.sin(n/2);return"XYZ"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t-l*u*p):"YXZ"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t+l*u*p):"ZXY"===o?(this.x=l*i*t-d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t-l*u*p):"ZYX"===o?(this.x=l*i*t-d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t+l*u*p):"YZX"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t-l*u*p):"XZY"===o&&(this.x=l*i*t-d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t+l*u*p),this},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)}},{"./Vec3":27}],26:[function(e,f){function n(){this.position=new o,this.quaternion=new d}var o=e("./Vec3"),d=e("./Quaternion");f.exports=n;var i=new d;n.pointToLocalFrame=function(e,f,n,d){var d=d||new o;return n.vsub(e,d),f.conjugate(i),i.vmult(d,d),d},n.pointToWorldFrame=function(e,f,n,d){var d=d||new o;return f.vmult(n,d),d.vadd(e,d),d},n.prototype.vectorToWorldFrame=function(e,f){var f=f||new o;return this.quaternion.vmult(e,f),f},n.vectorToLocalFrame=function(e,f,n,d){var d=d||new o;return f.w*=-1,f.vmult(n,d),f.w*=-1,d}},{"./Quaternion":25,"./Vec3":27}],27:[function(e,f){function n(e,f,n){this.x=e||0,this.y=f||0,this.z=n||0}f.exports=n;var o=e("./Mat3");n.ZERO=new n(0,0,0),n.prototype.cross=function(e,f){var o=e.x,d=e.y,i=e.z,t=this.x,l=this.y,u=this.z;return f=f||new n,f.x=l*i-u*d,f.y=u*o-t*i,f.z=t*d-l*o,f},n.prototype.set=function(e,f,n){return this.x=e,this.y=f,this.z=n,this},n.prototype.setZero=function(){this.x=this.y=this.z=0},n.prototype.vadd=function(e,f){return f?(f.x=e.x+this.x,f.y=e.y+this.y,f.z=e.z+this.z,void 0):new n(this.x+e.x,this.y+e.y,this.z+e.z)},n.prototype.vsub=function(e,f){return f?(f.x=this.x-e.x,f.y=this.y-e.y,f.z=this.z-e.z,void 0):new n(this.x-e.x,this.y-e.y,this.z-e.z)},n.prototype.crossmat=function(){return new o([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},n.prototype.normalize=function(){var e=this.x,f=this.y,n=this.z,o=Math.sqrt(e*e+f*f+n*n);if(o>0){var d=1/o;this.x*=d,this.y*=d,this.z*=d}else this.x=0,this.y=0,this.z=0;return o},n.prototype.unit=function(e){e=e||new n;var f=this.x,o=this.y,d=this.z,i=Math.sqrt(f*f+o*o+d*d);return i>0?(i=1/i,e.x=f*i,e.y=o*i,e.z=d*i):(e.x=1,e.y=0,e.z=0),e},n.prototype.norm=function(){var e=this.x,f=this.y,n=this.z;return Math.sqrt(e*e+f*f+n*n)},n.prototype.norm2=function(){return this.dot(this)},n.prototype.distanceTo=function(e){var f=this.x,n=this.y,o=this.z,d=e.x,i=e.y,t=e.z;return Math.sqrt((d-f)*(d-f)+(i-n)*(i-n)+(t-o)*(t-o))},n.prototype.mult=function(e,f){f=f||new n;var o=this.x,d=this.y,i=this.z;return f.x=e*o,f.y=e*d,f.z=e*i,f},n.prototype.scale=n.prototype.mult,n.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},n.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},n.prototype.negate=function(e){return e=e||new n,e.x=-this.x,e.y=-this.y,e.z=-this.z,e};var d=new n,i=new n;n.prototype.tangents=function(e,f){var n=this.norm();if(n>0){var o=d,t=1/n;o.set(this.x*t,this.y*t,this.z*t);var l=i;Math.abs(o.x)<.9?(l.set(1,0,0),o.cross(l,e)):(l.set(0,1,0),o.cross(l,e)),o.cross(e,f)}else e.set(1,0,0).normalize(),f.set(0,1,0).normalize()},n.prototype.toString=function(){return this.x+","+this.y+","+this.z},n.prototype.toArray=function(){return[this.x,this.y,this.z]},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},n.prototype.lerp=function(e,f,n){var o=this.x,d=this.y,i=this.z;n.x=o+(e.x-o)*f,n.y=d+(e.y-d)*f,n.z=i+(e.z-i)*f},n.prototype.almostEquals=function(e,f){return void 0===f&&(f=1e-6),Math.abs(this.x-e.x)>f||Math.abs(this.y-e.y)>f||Math.abs(this.z-e.z)>f?!1:!0},n.prototype.almostZero=function(e){return void 0===e&&(e=1e-6),Math.abs(this.x)>e||Math.abs(this.y)>e||Math.abs(this.z)>e?!1:!0};var t=new n;n.prototype.isAntiparallelTo=function(e,f){return this.negate(t),t.almostEquals(e,f)},n.prototype.clone=function(){return new n(this.x,this.y,this.z)}},{"./Mat3":24}],28:[function(e,f){function n(e){e=e||{},o.apply(this),this.id=n.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new d,this.collisionFilterGroup=1,this.collisionFilterMask=1,this.collisionResponse=!0,this.position=new d,e.position&&this.position.copy(e.position),this.previousPosition=new d,this.initPosition=new d,this.velocity=new d,e.velocity&&this.velocity.copy(e.velocity),this.initVelocity=new d,this.force=new d;var f="number"==typeof e.mass?e.mass:0;this.mass=f,this.invMass=f>0?1/f:0,this.material=e.material||null,this.linearDamping="number"==typeof e.linearDamping?e.linearDamping:.01,this.type=0>=f?n.STATIC:n.DYNAMIC,typeof e.type==typeof n.STATIC&&(this.type=e.type),this.allowSleep=!0,this.sleepState=0,this.sleepSpeedLimit=.1,this.sleepTimeLimit=1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new d,this.quaternion=new t,e.quaternion&&this.quaternion.copy(e.quaternion),this.initQuaternion=new t,this.angularVelocity=new d,e.angularVelocity&&this.angularVelocity.copy(e.angularVelocity),this.initAngularVelocity=new d,this.interpolatedPosition=new d,this.interpolatedQuaternion=new t,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new d,this.invInertia=new d,this.invInertiaWorld=new i,this.invMassSolve=0,this.invInertiaSolve=new d,this.invInertiaWorldSolve=new i,this.fixedRotation=!1,this.angularDamping=.01,this.aabb=new l,this.aabbNeedsUpdate=!0,this.wlambda=new d,this.updateMassProperties()}f.exports=n;var o=e("../utils/EventTarget"),d=(e("../shapes/Shape"),e("../math/Vec3")),i=e("../math/Mat3"),t=e("../math/Quaternion"),l=(e("../material/Material"),e("../collision/AABB")),u=e("../shapes/Box");n.prototype=new o,n.prototype.constructor=n,n.DYNAMIC=1,n.STATIC=2,n.KINEMATIC=4,n.AWAKE=0,n.SLEEPY=1,n.SLEEPING=2,n.idCounter=0,n.prototype.wakeUp=function(){var e=this.sleepState;this.sleepState=0,e===n.SLEEPING&&this.dispatchEvent({type:"wakeup"})},n.prototype.sleep=function(){this.sleepState=n.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0)},n.sleepyEvent={type:"sleepy"},n.sleepEvent={type:"sleep"},n.prototype.sleepTick=function(e){if(this.allowSleep){var f=this.sleepState,o=this.velocity.norm2()+this.angularVelocity.norm2(),d=Math.pow(this.sleepSpeedLimit,2);f===n.AWAKE&&d>o?(this.sleepState=n.SLEEPY,this.timeLastSleepy=e,this.dispatchEvent(n.sleepyEvent)):f===n.SLEEPY&&o>d?this.wakeUp():f===n.SLEEPY&&e-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(n.sleepEvent))}},n.prototype.updateSolveMassProperties=function(){this.sleepState===n.SLEEPING||this.type===n.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},n.prototype.pointToLocalFrame=function(e,f){var f=f||new d;return e.vsub(this.position,f),this.quaternion.conjugate().vmult(f,f),f},n.prototype.pointToWorldFrame=function(e,f){var f=f||new d;return this.quaternion.vmult(e,f),f.vadd(this.position,f),f},n.prototype.vectorToWorldFrame=function(e,f){var f=f||new d;return this.quaternion.vmult(e,f),f};var p=new d,s=new t;n.prototype.addShape=function(e,f,n){var o=new d,i=new t;f&&o.copy(f),n&&i.copy(n),this.shapes.push(e),this.shapeOffsets.push(o),this.shapeOrientations.push(i),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0},n.prototype.updateBoundingRadius=function(){for(var e=this.shapes,f=this.shapeOffsets,n=e.length,o=0,d=0;d!==n;d++){var i=e[d];i.updateBoundingSphereRadius();var t=f[d].norm(),l=i.boundingSphereRadius;t+l>o&&(o=t+l)}this.boundingRadius=o};var y=new l;n.prototype.computeAABB=function(){for(var e=this.shapes,f=this.shapeOffsets,n=this.shapeOrientations,o=e.length,d=p,i=s,t=this.quaternion,l=this.aabb,u=y,c=0;c!==o;c++){var a=e[c];n[c].mult(t,i),i.vmult(f[c],d),d.vadd(this.position,d),a.calculateWorldAABB(d,i,u.lowerBound,u.upperBound),0===c?l.copy(u):l.extend(u)}this.aabbNeedsUpdate=!1};{var c=new i,a=new i;new i}n.prototype.updateInertiaWorld=function(e){var f=this.invInertia;if(f.x!==f.y||f.y!==f.z||e){var n=c,o=a;n.setRotationFromQuaternion(this.quaternion),n.transpose(o),n.scale(f,n),n.mmult(o,this.invInertiaWorld)}else;};var r=new d,w=new d;n.prototype.applyForce=function(e,f){if(this.type===n.DYNAMIC){var o=r;f.vsub(this.position,o);var d=w;o.cross(e,d),this.force.vadd(e,this.force),this.torque.vadd(d,this.torque)}};var b=new d,m=new d,N=new d;n.prototype.applyImpulse=function(e,f){if(this.type===n.DYNAMIC){var o=b;f.vsub(this.position,o);var d=m;d.copy(e),d.mult(this.invMass,d),this.velocity.vadd(d,this.velocity);var i=N;o.cross(e,i),this.invInertiaWorld.vmult(i,i),this.angularVelocity.vadd(i,this.angularVelocity)}},n.prototype.updateMassProperties=function(){new d;this.invMass=this.mass>0?1/this.mass:0;var e=this.inertia,f=this.fixedRotation;this.computeAABB(),u.calculateInertia(new d((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),this.mass,e),this.invInertia.set(e.x>0&&!f?1/e.x:0,e.y>0&&!f?1/e.y:0,e.z>0&&!f?1/e.z:0),this.updateInertiaWorld(!0)},n.prototype.getVelocityAtWorldPoint=function(e,f){var n=new d;return e.vsub(this.position,n),this.angularVelocity.cross(n,f),this.velocity.vadd(f,f),f}},{"../collision/AABB":3,"../material/Material":22,"../math/Mat3":24,"../math/Quaternion":25,"../math/Vec3":27,"../shapes/Box":34,"../shapes/Shape":40,"../utils/EventTarget":45}],29:[function(e,f){function n(e){this.chassisBody=e.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis="undefined"!=typeof e.indexRightAxis?e.indexRightAxis:1,this.indexForwardAxis="undefined"!=typeof e.indexForwardAxis?e.indexForwardAxis:0,this.indexUpAxis="undefined"!=typeof e.indexUpAxis?e.indexUpAxis:2}function o(e,f,n,o,i){var t=0,l=n,u=x,p=j,s=v;e.getVelocityAtWorldPoint(l,u),f.getVelocityAtWorldPoint(l,p),u.vsub(p,s);var y=o.dot(s),c=d(e,n,o),a=d(f,n,o),r=1,w=r/(c+a);return t=-y*w,t>i&&(t=i),-i>t&&(t=-i),t}function d(e,f,n){var o=A,d=C,i=O,t=h;return f.vsub(e.position,o),o.cross(n,d),e.invInertiaWorld.vmult(d,t),t.cross(o,i),e.invMass+n.dot(i)}function i(e,f,n,o,d,i){var t=d.norm2();if(t>1.1)return 0;var l=k,u=q,p=z;e.getVelocityAtWorldPoint(f,l),n.getVelocityAtWorldPoint(o,u),l.vsub(u,p);var s=d.dot(p),y=.2,c=1/(e.invMass+n.invMass),i=-y*s*c;return i}var t=(e("./Body"),e("../math/Vec3")),l=e("../math/Quaternion"),u=(e("../collision/RaycastResult"),e("../collision/Ray")),p=e("../objects/WheelInfo");f.exports=n;{var s=(new t,new t,new t,new t),y=new t,c=new t;new u}n.prototype.addWheel=function(e){e=e||{};var f=new p(e),n=this.wheelInfos.length;return this.wheelInfos.push(f),n},n.prototype.setSteeringValue=function(e,f){var n=this.wheelInfos[f];n.steering=e};new t;n.prototype.applyEngineForce=function(e,f){this.wheelInfos[f].engineForce=e},n.prototype.setBrake=function(e,f){this.wheelInfos[f].brake=e},n.prototype.addToWorld=function(e){this.constraints;e.add(this.chassisBody);var f=this;e.addEventListener("preStep",function(){f.updateVehicle(e.dt)}),this.world=e},n.prototype.getVehicleAxisWorld=function(e,f){f.set(0===e?1:0,1===e?1:0,2===e?1:0),this.chassisBody.vectorToWorldFrame(f,f)},n.prototype.updateVehicle=function(e){for(var f=this.wheelInfos,n=f.length,o=this.chassisBody,d=0;n>d;d++)this.updateWheelTransform(d,!1);this.currentVehicleSpeedKmHour=3.6*o.velocity.norm();var i=new t;this.getVehicleAxisWorld(this.indexForwardAxis,i),i.dot(o.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(var d=0;n>d;d++)this.castRay(f[d]);this.updateSuspension(e);for(var l=new t,u=new t,d=0;n>d;d++){var p=f[d],s=p.suspensionForce;s>p.maxSuspensionForce&&(s=p.maxSuspensionForce),p.raycastResult.hitNormalWorld.scale(s*e,l),p.raycastResult.hitPointWorld.vsub(o.position,u),o.applyImpulse(l,p.raycastResult.hitPointWorld)}this.updateFriction(e);var y=new t,c=new t,a=new t;for(d=0;n>d;d++){var p=f[d];o.getVelocityAtWorldPoint(p.chassisConnectionPointWorld,a);var r=1;switch(this.indexUpAxis){case 1:r=-1}if(p.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,c);var w=c.dot(p.raycastResult.hitNormalWorld);p.raycastResult.hitNormalWorld.scale(w,y),c.vsub(y,c);var b=c.dot(a);p.deltaRotation=r*b*e/p.radius}!p.sliding&&p.isInContact||0===p.engineForce||!p.useCustomSlidingRotationalSpeed||(p.deltaRotation=(p.engineForce>0?1:-1)*p.customSlidingRotationalSpeed*e),Math.abs(p.brake)>Math.abs(p.engineForce)&&(p.deltaRotation=0),p.rotation+=p.deltaRotation,p.deltaRotation*=.99}},n.prototype.updateSuspension=function(){for(var e=this.chassisBody,f=e.mass,n=this.wheelInfos,o=n.length,d=0;o>d;d++){var i=n[d];if(i.isInContact){var t,l=i.suspensionRestLength,u=i.suspensionLength,p=l-u;t=i.suspensionStiffness*p*i.clippedInvContactDotSuspension;var s,y=i.suspensionRelativeVelocity;s=0>y?i.dampingCompression:i.dampingRelaxation,t-=s*y,i.suspensionForce=t*f,i.suspensionForce<0&&(i.suspensionForce=0)}else i.suspensionForce=0}},n.prototype.removeFromWorld=function(e){this.constraints;e.remove(this.chassisBody),e.removeEventListener("preStep",this.updateVehicle),this.world=null};var a=new t,r=new t;n.prototype.castRay=function(e){var f=a,n=r;this.updateWheelTransformWorld(e);var o=this.chassisBody,d=-1,i=e.suspensionRestLength+e.radius;e.directionWorld.scale(i,f);var l=e.chassisConnectionPointWorld;l.vadd(f,n);var u=e.raycastResult;u.reset();var p=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(l,n,u),o.collisionResponse=p;var s=u.body;if(e.raycastResult.groundObject=0,s){d=u.distance,e.raycastResult.hitNormalWorld=u.hitNormalWorld,e.isInContact=!0;var y=u.distance;e.suspensionLength=y-e.radius;var c=e.suspensionRestLength-e.maxSuspensionTravel,w=e.suspensionRestLength+e.maxSuspensionTravel;e.suspensionLengthw&&(e.suspensionLength=w,e.raycastResult.reset());var b=e.raycastResult.hitNormalWorld.dot(e.directionWorld),m=new t;o.getVelocityAtWorldPoint(e.raycastResult.hitPointWorld,m);var N=e.raycastResult.hitNormalWorld.dot(m);if(b>=-.1)e.suspensionRelativeVelocity=0,e.clippedInvContactDotSuspension=10;else{var g=-1/b;e.suspensionRelativeVelocity=N*g,e.clippedInvContactDotSuspension=g}}else e.suspensionLength=e.suspensionRestLength+0*e.maxSuspensionTravel,e.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.raycastResult.hitNormalWorld),e.clippedInvContactDotSuspension=1;return d},n.prototype.updateWheelTransformWorld=function(e){e.isInContact=!1;var f=this.chassisBody;f.pointToWorldFrame(e.chassisConnectionPointLocal,e.chassisConnectionPointWorld),f.vectorToWorldFrame(e.directionLocal,e.directionWorld),f.vectorToWorldFrame(e.axleLocal,e.axleWorld)},n.prototype.updateWheelTransform=function(e){var f=s,n=y,o=c,d=this.wheelInfos[e];this.updateWheelTransformWorld(d),d.directionLocal.scale(-1,f),n.copy(d.axleLocal),f.cross(n,o),o.normalize(),n.normalize();var i=d.steering,t=new l;t.setFromAxisAngle(f,i);var u=new l;u.setFromAxisAngle(n,d.rotation);var p=d.worldTransform.quaternion;this.chassisBody.quaternion.mult(t,p),p.mult(u,p),p.normalize();var a=d.worldTransform.position;a.copy(d.directionWorld),a.scale(d.suspensionLength,a),a.vadd(d.chassisConnectionPointWorld,a)};var w=[new t(1,0,0),new t(0,1,0),new t(0,0,1)];n.prototype.getWheelTransformWorld=function(e){return this.wheelInfos[e].worldTransform};var b=new t,m=[],N=[],g=1;n.prototype.updateFriction=function(e){for(var f=b,n=this.wheelInfos,d=n.length,l=this.chassisBody,u=N,p=m,s=0,y=0;d>y;y++){var c=n[y],a=c.raycastResult.body;a&&s++,c.sideImpulse=0,c.forwardImpulse=0,u[y]||(u[y]=new t),p[y]||(p[y]=new t)}for(var y=0;d>y;y++){var c=n[y],a=c.raycastResult.body;if(a){var r=p[y],x=this.getWheelTransformWorld(y);x.vectorToWorldFrame(w[this.indexRightAxis],r);var j=c.raycastResult.hitNormalWorld,v=r.dot(j);j.scale(v,f),r.vsub(f,r),r.normalize(),j.cross(r,u[y]),u[y].normalize(),c.sideImpulse=i(l,c.raycastResult.hitPointWorld,a,c.raycastResult.hitPointWorld,r),c.sideImpulse*=g}}var A=1,C=.5;this.sliding=!1;for(var y=0;d>y;y++){var c=n[y],a=c.raycastResult.body,O=0;if(c.slipInfo=1,a){var h=0,k=c.brake?c.brake:h;O=o(l,a,c.raycastResult.hitPointWorld,u[y],k),O+=c.engineForce*e;var q=k/O;c.slipInfo*=q}if(c.forwardImpulse=0,c.skidInfo=1,a){c.skidInfo=1;var z=c.suspensionForce*e*c.frictionSlip,B=z,D=z*B;c.forwardImpulse=O;var E=c.forwardImpulse*C,F=c.sideImpulse*A,G=E*E+F*F;if(c.sliding=!1,G>D){this.sliding=!0,c.sliding=!0;var q=z/Math.sqrt(G);c.skidInfo*=q}}}if(this.sliding)for(var y=0;d>y;y++){var c=n[y];0!==c.sideImpulse&&c.skidInfo<1&&(c.forwardImpulse*=c.skidInfo,c.sideImpulse*=c.skidInfo)}for(var y=0;d>y;y++){var c=n[y],H=new t;if(H.copy(c.raycastResult.hitPointWorld),0!==c.forwardImpulse){var I=new t;u[y].scale(c.forwardImpulse,I),l.applyImpulse(I,H)}if(0!==c.sideImpulse){var a=c.raycastResult.body,J=new t;J.copy(c.raycastResult.hitPointWorld);var K=new t;p[y].scale(c.sideImpulse,K),l.pointToLocalFrame(H,H),H["xyz"[this.indexUpAxis]]*=c.rollInfluence,l.pointToWorldFrame(H,H),l.applyImpulse(K,H),K.scale(-1,K),a.applyImpulse(K,J)}}};var x=new t,j=new t,v=new t,A=new t,C=new t,O=new t,h=new t,k=new t,q=new t,z=new t},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":25,"../math/Vec3":27,"../objects/WheelInfo":33,"./Body":28}],30:[function(e,f){function n(e){if(this.wheelBodies=[],this.coordinateSystem="undefined"==typeof e.coordinateSystem?new t(1,2,3):e.coordinateSystem.clone(),this.chassisBody=e.chassisBody,!this.chassisBody){var f=new i(new t(5,2,.5));this.chassisBody=new o(1,f)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var o=e("./Body"),d=e("../shapes/Sphere"),i=e("../shapes/Box"),t=e("../math/Vec3"),l=e("../constraints/HingeConstraint");f.exports=n,n.prototype.addWheel=function(e){e=e||{};var f=e.body;f||(f=new o(1,new d(1.2))),this.wheelBodies.push(f),this.wheelForces.push(0);var n=(new t,"undefined"!=typeof e.position?e.position.clone():new t),i=new t;this.chassisBody.pointToWorldFrame(n,i),f.position.set(i.x,i.y,i.z);var u="undefined"!=typeof e.axis?e.axis.clone():new t(0,1,0);this.wheelAxes.push(u);var p=new l(this.chassisBody,f,{pivotA:n,axisA:u,pivotB:t.ZERO,axisB:u,collideConnected:!1});return this.constraints.push(p),this.wheelBodies.length-1},n.prototype.setSteeringValue=function(e,f){var n=this.wheelAxes[f],o=Math.cos(e),d=Math.sin(e),i=n.x,t=n.y;this.constraints[f].axisA.set(o*i-d*t,d*i+o*t,0)},n.prototype.setMotorSpeed=function(e,f){var n=this.constraints[f];n.enableMotor(),n.motorTargetVelocity=e},n.prototype.disableMotor=function(e){var f=this.constraints[e];f.disableMotor()};var u=new t;n.prototype.setWheelForce=function(e,f){this.wheelForces[f]=e},n.prototype.applyWheelForce=function(e,f){var n=this.wheelAxes[f],o=this.wheelBodies[f],d=o.torque;n.scale(e,u),o.vectorToWorldFrame(u,u),d.vadd(u,d)},n.prototype.addToWorld=function(e){for(var f=this.constraints,n=this.wheelBodies.concat([this.chassisBody]),o=0;othis.particles.length&&this.neighbors.pop())};var d=new o;n.prototype.getNeighbors=function(e,f){for(var n=this.particles.length,o=e.id,i=this.smoothingRadius*this.smoothingRadius,t=d,l=0;l!==n;l++){var u=this.particles[l];u.position.vsub(e.position,t),o!==u.id&&t.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var d=-1/n;this.suspensionRelativeVelocity=o*d,this.clippedInvContactDotSuspension=d}}else f.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,f.directionWorld.scale(-1,f.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":26,"../math/Vec3":27,"../utils/Utils":48}],34:[function(e,f){function n(e){o.call(this),this.type=o.types.BOX,this.halfExtents=e,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3"),i=e("./ConvexPolyhedron");n.prototype=new o,n.prototype.constructor=n,n.prototype.updateConvexPolyhedronRepresentation=function(){var e=this.halfExtents.x,f=this.halfExtents.y,n=this.halfExtents.z,o=d,t=new i([new o(-e,-f,-n),new o(e,-f,-n),new o(e,f,-n),new o(-e,f,-n),new o(-e,-f,n),new o(e,-f,n),new o(e,f,n),new o(-e,f,n)],[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],[new o(0,0,-1),new o(0,0,1),new o(0,-1,0),new o(0,1,0),new o(-1,0,0),new o(1,0,0)]);this.convexPolyhedronRepresentation=t},n.prototype.calculateLocalInertia=function(e,f){return f=f||new d,n.calculateInertia(this.halfExtents,e,f),f},n.calculateInertia=function(e,f,n){var o=e;n.x=1/12*f*(2*o.y*2*o.y+2*o.z*2*o.z),n.y=1/12*f*(2*o.x*2*o.x+2*o.z*2*o.z),n.z=1/12*f*(2*o.y*2*o.y+2*o.x*2*o.x)},n.prototype.getSideNormals=function(e,f){var n=e,o=this.halfExtents;if(n[0].set(o.x,0,0),n[1].set(0,o.y,0),n[2].set(0,0,o.z),n[3].set(-o.x,0,0),n[4].set(0,-o.y,0),n[5].set(0,0,-o.z),void 0!==f)for(var d=0;d!==n.length;d++)f.vmult(n[d],n[d]);return n},n.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};{var t=new d;new d}n.prototype.forEachWorldCorner=function(e,f,n){for(var o=this.halfExtents,d=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],i=0;it;t++){var i=l[t];f.vmult(i,i),e.vadd(i,i);var u=i.x,p=i.y,s=i.z;u>o.x&&(o.x=u),p>o.y&&(o.y=p),s>o.z&&(o.z=s),ui;i++){var t=f[i];if(!(t instanceof d))throw"Argument 1 must be instance of Vec3";this.uniqueEdges.push(t)}for(var l=0;ls;s++){var y=(s+1)%p,c=new d;f[u[s]].vsub(f[u[y]],c),c.normalize();for(var a=!1,t=0;tr&&(r=b,a=w)}for(var m=[],N=n.faces[a],g=N.length,x=0;g>x;x++){var j=n.vertices[N[x]],v=new d;v.copy(j),t.vmult(v,v),o.vadd(v,v),m.push(v)}a>=0&&this.clipFaceAgainstHull(l,e,f,m,u,s,y)};var s=new d,y=new d,c=new d,a=new d,r=new d,w=new d;n.prototype.findSeparatingAxis=function(e,f,n,o,d,i,t,l){for(var u=s,p=y,b=c,m=a,N=r,g=w,x=1/0,j=this,v=0,A=t?t.length:j.faces.length,C=0;A>C;C++){var O=t?t[C]:C;u.copy(j.faceNormals[O]),n.vmult(u,u);var h=j.testSepAxis(u,e,f,n,o,d);if(h===!1)return!1;x>h&&(x=h,i.copy(u))}for(var k=l?l.length:e.faces.length,C=0;k>C;C++){var O=l?l[C]:C;p.copy(e.faceNormals[O]),d.vmult(p,p),v++;var h=j.testSepAxis(p,e,f,n,o,d);if(h===!1)return!1;x>h&&(x=h,i.copy(p))}for(var q=0,z=0;zD&&(x=D,i.copy(g))}}return o.vsub(f,b),b.dot(i)>0&&i.negate(i),!0},n.prototype.testSepAxis=function(e,f,o,d,i,t){var l=[],u=[],p=this;n.project(p,e,o,d,l),n.project(f,e,i,t,u);var s=l[0],y=l[1],c=u[0],a=u[1];if(a>s||y>c)return!1;var r=s-a,w=c-y,b=w>r?r:w;return b};var b=new d,m=new d;n.prototype.calculateLocalInertia=function(e,f){this.computeLocalAABB(b,m);var n=m.x-b.x,o=m.y-b.y,d=m.z-b.z;f.x=1/12*e*(2*o*2*o+2*d*2*d),f.y=1/12*e*(2*n*2*n+2*d*2*d),f.z=1/12*e*(2*o*2*o+2*n*2*n)},n.prototype.getPlaneConstantOfFace=function(e){var f=this.faces[e],n=this.faceNormals[e],o=this.vertices[f[0]],d=-n.dot(o);return d};var N=new d,g=new d,x=new d,j=new d,v=new d,A=new d,C=new d,O=new d;n.prototype.clipFaceAgainstHull=function(e,f,n,o,i,t,l){if(!(e instanceof d))throw new Error("sep normal must be vector");if(!(o instanceof Array))throw new Error("world verts must be array");var u=N,p=g,s=x,y=j,c=v,a=A,r=C,w=O;i=Number(i),t=Number(t);for(var b=this,m=[],h=o,k=m,q=-1,z=1/0,B=0;BD&&(z=D,q=B)}if(0>q)return void console.log("--- did not find any closest face... ---");var E=b.faces[q];E.connectedFaces=[];for(var F=0;FI;I++){var J=b.vertices[E[I]],K=b.vertices[E[(I+1)%H]];J.vsub(K,p),s.copy(p),n.vmult(s,s),f.vadd(s,s),y.copy(this.faceNormals[q]),n.vmult(y,y),f.vadd(y,y),s.cross(y,c),c.negate(c),a.copy(J),n.vmult(a,a),f.vadd(a,a);var L,M=(-a.dot(c),E.connectedFaces[I]);r.copy(this.faceNormals[M]);var P=this.getPlaneConstantOfFace(M);w.copy(r),n.vmult(w,w);var L=P-w.dot(f);for(this.clipFaceAgainstPlane(h,k,w,L);h.length;)h.shift();for(;k.length;)h.push(k.shift())}r.copy(this.faceNormals[q]);var P=this.getPlaneConstantOfFace(q);w.copy(r),n.vmult(w,w);for(var L=P-w.dot(f),F=0;F=Q&&(console.log("clamped: depth="+Q+" to minDist="+(i+"")),Q=i),t>=Q){var R=h[F];if(0>=Q){var S={point:R,normal:w,depth:Q};l.push(S)}}}},n.prototype.clipFaceAgainstPlane=function(e,f,n,o){if(!(n instanceof d))throw new Error("planeNormal must be Vec3, "+n+" given");if(!(e instanceof Array))throw new Error("invertices must be Array, "+e+" given");if(!(f instanceof Array))throw new Error("outvertices must be Array, "+f+" given");var i,t,l=e.length;if(2>l)return f;var u=e[e.length-1],p=e[0];i=n.dot(u)+o;for(var s=0;l>s;s++){if(p=e[s],t=n.dot(p)+o,0>i)if(0>t){var y=new d;y.copy(p),f.push(y)}else{var y=new d;u.lerp(p,i/(i-t),y),f.push(y)}else if(0>t){var y=new d;u.lerp(p,i/(i-t),y),f.push(y),f.push(p)}u=p,i=t}return f},n.prototype.computeWorldVertices=function(e,f){for(var n=this.vertices.length;this.worldVertices.lengthd;d++){var i=o[d];i.xf.x&&(f.x=i.x),i.yf.y&&(f.y=i.y),i.zf.z&&(f.z=i.z)}},n.prototype.computeWorldFaceNormals=function(e){for(var f=this.faceNormals.length;this.worldFaceNormals.lengthe&&(e=d)}this.boundingSphereRadius=Math.sqrt(e)};var h=new d;n.prototype.calculateWorldAABB=function(e,f,n,o){for(var d,i,t,l,u,p,s=this.vertices.length,y=this.vertices,c=0;s>c;c++){h.copy(y[c]),f.vmult(h,h),e.vadd(h,h);var a=h;a.xl||void 0===l)&&(l=a.x),a.yu||void 0===u)&&(u=a.y),a.zp||void 0===p)&&(p=a.z)}n.set(d,i,t),o.set(l,u,p)},n.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},n.prototype.getAveragePointLocal=function(e){e=e||new d;for(var f=this.vertices.length,n=this.vertices,o=0;f>o;o++)e.vadd(n[o],e);return e.mult(1/f,e),e},n.prototype.transformAllPoints=function(e,f){var n=this.vertices.length,o=this.vertices;if(f){for(var d=0;n>d;d++){var i=o[d];f.vmult(i,i)}for(var d=0;dd;d++){var i=o[d];i.vadd(e,i)}};var k=new d,q=new d,z=new d;n.prototype.pointIsInside=function(e){var f=this.vertices.length,n=this.vertices,o=this.faces,d=this.faceNormals,i=null,t=this.faces.length,l=k;this.getAveragePointLocal(l);for(var u=0;t>u;u++){var f=(this.faces[u].length,d[u]),p=n[o[u][0]],s=q;e.vsub(p,s);var y=f.dot(s),c=z;l.vsub(p,c);var a=f.dot(c);if(0>y&&a>0||y>0&&0>a)return!1}return i?1:-1};var B=(new d,new d),D=new d;n.project=function(e,f,n,o,d){var i=e.vertices.length,l=B,u=0,p=0,s=D,y=e.vertices;s.setZero(),t.vectorToLocalFrame(n,o,f,l),t.pointToLocalFrame(n,o,s,s);var c=s.dot(l);p=u=y[0].dot(l);for(var a=1;i>a;a++){var r=y[a].dot(l);r>u&&(u=r),p>r&&(p=r)}if(p-=c,u-=c,p>u){var w=p;p=u,u=w}d[0]=u,d[1]=p}},{"../math/Quaternion":25,"../math/Transform":26,"../math/Vec3":27,"./Shape":40}],36:[function(e,f){function n(e,f,n,t){var l=t,u=[],p=[],s=[],y=[],c=[],a=Math.cos,r=Math.sin;u.push(new d(f*a(0),f*r(0),.5*-n)),y.push(0),u.push(new d(e*a(0),e*r(0),.5*n)),c.push(1);for(var w=0;l>w;w++){var b=2*Math.PI/l*(w+1),m=2*Math.PI/l*(w+.5);l-1>w?(u.push(new d(f*a(b),f*r(b),.5*-n)),y.push(2*w+2),u.push(new d(e*a(b),e*r(b),.5*n)),c.push(2*w+3),p.push(new d(a(m),r(m),0)),s.push([2*w+2,2*w+3,2*w+1,2*w])):(s.push([0,1,2*w+1,2*w]),p.push(new d(a(m),r(m),0)))}s.push(c),p.push(new d(0,0,1));for(var N=[],w=0;wd&&(f=d)}this.minValue=f},n.prototype.updateMaxValue=function(){for(var e=this.data,f=e[0][0],n=0;n!==e.length;n++)for(var o=0;o!==e[n].length;o++){var d=e[n][o];d>f&&(f=d)}this.maxValue=f},n.prototype.setHeightValueAtIndex=function(e,f,n){var o=this.data;o[e][f]=n,this.clearCachedConvexTrianglePillar(e,f,!1),e>0&&(this.clearCachedConvexTrianglePillar(e-1,f,!0),this.clearCachedConvexTrianglePillar(e-1,f,!1)),f>0&&(this.clearCachedConvexTrianglePillar(e,f-1,!0),this.clearCachedConvexTrianglePillar(e,f-1,!1)),f>0&&e>0&&this.clearCachedConvexTrianglePillar(e-1,f-1,!0)},n.prototype.getRectMinMax=function(e,f,n,o,d){d=d||[];for(var i=this.data,t=this.minValue,l=e;n>l;l++)for(var u=f;o>u;u++){var p=i[l][u];p>t&&(t=p)}d[0]=this.minValue,d[1]=t},n.prototype.getIndexOfPosition=function(e,f,n,o){var d=this.elementSize,i=this.data,t=Math.floor(e/d),l=Math.floor(f/d);return n[0]=t,n[1]=l,o&&(0>t&&(t=0),0>l&&(l=0),t>=i.length-1&&(t=i.length-1),l>=i[0].length-1&&(l=i[0].length-1)),0>t||0>l||t>=i.length-1||l>=i[0].length-1?!1:!0},n.prototype.getHeightAt=function(e,f,n){var o=[];this.getIndexOfPosition(e,f,o,n);var d=[];return this.getRectMinMax(o[0],o[1]+1,o[0],o[1]+1,d),(d[0]+d[1])/2},n.prototype.getCacheConvexTrianglePillarKey=function(e,f,n){return e+"_"+f+"_"+(n?1:0)},n.prototype.getCachedConvexTrianglePillar=function(e,f,n){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]},n.prototype.setCachedConvexTrianglePillar=function(e,f,n,o,d){this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]={convex:o,offset:d}},n.prototype.clearCachedConvexTrianglePillar=function(e,f,n){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]},n.prototype.getConvexTrianglePillar=function(e,f,n){var o=this.pillarConvex,t=this.pillarOffset;if(this.cacheEnabled){var l=this.getCachedConvexTrianglePillar(e,f,n);if(l)return this.pillarConvex=l.convex,void(this.pillarOffset=l.offset);o=new d,t=new i,this.pillarConvex=o,this.pillarOffset=t}var l=this.data,u=this.elementSize,p=o.faces;o.vertices.length=6;for(var s=0;6>s;s++)o.vertices[s]||(o.vertices[s]=new i);p.length=5;for(var s=0;5>s;s++)p[s]||(p[s]=[]);var y=o.vertices,c=(Math.min(l[e][f],l[e+1][f],l[e][f+1],l[e+1][f+1])-this.minValue)/2+this.minValue;n?(t.set((e+.75)*u,(f+.75)*u,c),y[0].set(.25*u,.25*u,l[e+1][f+1]-c),y[1].set(-.75*u,.25*u,l[e][f+1]-c),y[2].set(.25*u,-.75*u,l[e+1][f]-c),y[3].set(.25*u,.25*u,-c-1),y[4].set(-.75*u,.25*u,-c-1),y[5].set(.25*u,-.75*u,-c-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=2,p[2][1]=5,p[2][2]=3,p[2][3]=0,p[3][0]=3,p[3][1]=4,p[3][2]=1,p[3][3]=0,p[4][0]=1,p[4][1]=4,p[4][2]=5,p[4][3]=2):(t.set((e+.25)*u,(f+.25)*u,c),y[0].set(-.25*u,-.25*u,l[e][f]-c),y[1].set(.75*u,-.25*u,l[e+1][f]-c),y[2].set(-.25*u,.75*u,l[e][f+1]-c),y[3].set(-.25*u,-.25*u,-c-1),y[4].set(.75*u,-.25*u,-c-1),y[5].set(-.25*u,.75*u,-c-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=0,p[2][1]=2,p[2][2]=5,p[2][3]=3,p[3][0]=1,p[3][1]=0,p[3][2]=3,p[3][3]=4,p[4][0]=4,p[4][1]=5,p[4][2]=2,p[4][3]=1),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(e,f,n,o,t)},n.prototype.calculateLocalInertia=function(e,f){return f=f||new i,f.set(0,0,0),f},n.prototype.volume=function(){return Number.MAX_VALUE},n.prototype.calculateWorldAABB=function(e,f,n,o){n.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},n.prototype.updateBoundingSphereRadius=function(){var e=this.data,f=this.elementSize;this.boundingSphereRadius=new i(e.length*f,e[0].length*f,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()}},{"../math/Vec3":27,"../utils/Utils":48,"./ConvexPolyhedron":35,"./Shape":40}],38:[function(e,f){function n(){o.call(this),this.type=o.types.PARTICLE}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.calculateLocalInertia=function(e,f){return f=f||new d,f.set(0,0,0),f},n.prototype.volume=function(){return 0},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},n.prototype.calculateWorldAABB=function(e,f,n,o){n.copy(e),o.copy(e)}},{"../math/Vec3":27,"./Shape":40}],39:[function(e,f){function n(){o.call(this),this.type=o.types.PLANE,this.worldNormal=new d,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.computeWorldNormal=function(e){var f=this.worldNormal;f.set(0,0,1),e.vmult(f,f),this.worldNormalNeedsUpdate=!1},n.prototype.calculateLocalInertia=function(e,f){return f=f||new d},n.prototype.volume=function(){return Number.MAX_VALUE};var i=new d;n.prototype.calculateWorldAABB=function(e,f,n,o){i.set(0,0,1),f.vmult(i,i);var d=Number.MAX_VALUE;n.set(-d,-d,-d),o.set(d,d,d),1===i.x&&(o.x=e.x),1===i.y&&(o.y=e.y),1===i.z&&(o.z=e.z),-1===i.x&&(n.x=e.x),-1===i.y&&(n.y=e.y),-1===i.z&&(n.z=e.z)},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":27,"./Shape":40}],40:[function(e,f){function n(){this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0}f.exports=n;{var n=e("./Shape");e("../math/Vec3"),e("../math/Quaternion"),e("../material/Material")}n.prototype.constructor=n,n.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},n.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},n.prototype.calculateLocalInertia=function(){throw"calculateLocalInertia() not implemented for shape type "+this.type},n.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128}},{"../material/Material":22,"../math/Quaternion":25,"../math/Vec3":27,"./Shape":40}],41:[function(e,f){function n(e){o.call(this),this.radius=void 0!==e?Number(e):1,this.type=o.types.SPHERE,this.updateBoundingSphereRadius()}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.calculateLocalInertia=function(e,f){f=f||new d;var n=2*e*this.radius*this.radius/5;return f.x=n,f.y=n,f.z=n,f},n.prototype.volume=function(){return 4*Math.PI*this.radius/3},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},n.prototype.calculateWorldAABB=function(e,f,n,o){for(var d=this.radius,i=["x","y","z"],t=0;tA.maxForce&&(l=A.maxForce-s),v[k]+=l,u+=l>0?l:-l,A.addToWlambda(l)}if(a>u*u)break}for(var g=0;g!==m;g++){var C=b[g],q=C.velocity,z=C.angularVelocity;q.vadd(C.vlambda,q),z&&z.vadd(C.wlambda,z)}}return y}},{"../math/Quaternion":25,"../math/Vec3":27,"./Solver":43}],43:[function(e,f){function n(){this.equations=[]}f.exports=n,n.prototype.solve=function(){return 0},n.prototype.addEquation=function(e){e.enabled&&this.equations.push(e)},n.prototype.removeEquation=function(e){var f=this.equations,n=f.indexOf(e);-1!==n&&f.splice(n,1)},n.prototype.removeAllEquations=function(){this.equations.length=0}},{}],44:[function(e,f){function n(e){o.call(this),this.subsolver=e}f.exports=n;var o=(e("../math/Vec3"),e("../math/Quaternion"),e("./Solver")),d=e("../objects/Body");n.prototype=new o;var i=[],t=[],l=[],u={bodies:null};n.prototype.solve=function(e,f){function n(e){for(var f=e.length,n=0;n!==f;n++){var o=e[n];if(!(o.visited||o.body.type&C))return o}return!1}function o(e,f){var o=[];for(o.push(e),e.visited=!0,f(e);o.length;)for(var d,i=o.pop();d=n(i.children);)d.visited=!0,f(d),o.push(d)}function p(e){k.push(e.body);for(var f=e.eqs.length,n=0;n!==f;n++){var o=e.eqs[n];-1===h.indexOf(o)&&h.push(o)}}var s=i,y=f.bodies,c=this.equations,a=c.length,r=y.length,w=this.subsolver;for(s.length>r&&(s.length=r);s.lengtho;o++)n[o].call(this,e)}return this}}},{}],46:[function(e,f){function n(){this.objects=[],this.type=Object}f.exports=n,n.prototype.release=function(){for(var e=arguments.length,f=0;f!==e;f++)this.objects.push(arguments[f])},n.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},n.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}},{}],47:[function(e,f){function n(){this.data={keys:[]}}f.exports=n,n.prototype.get=function(e,f){if(e>f){var n=f;f=e,e=n}return this.data[e+"-"+f]},n.prototype.set=function(e,f,n){if(e>f){var o=f;f=e,e=o}var d=e+"-"+f;this.get(e,f)||this.data.keys.push(d),this.data[d]=n},n.prototype.reset=function(){for(var e=this.data,f=e.keys;f.length>0;){var n=f.pop();delete e[n]}}},{}],48:[function(e,f){function n(){}f.exports=n,n.defaults=function(e,f){e=e||{};for(var n in f)n in e||(e[n]=f[n]);return e}},{}],49:[function(e,f){function n(){d.call(this),this.type=o}f.exports=n;var o=e("../math/Vec3"),d=e("./Pool");n.prototype=new d,n.prototype.constructObject=function(){return new o}},{"../math/Vec3":27,"./Pool":46}],50:[function(e,f){function n(){this.contactPointPool=[],this.v3pool=new u}function o(e,f,n){for(var o=null,d=e.length,i=0;i!==d;i++){var t=e[i],l=b;e[(i+1)%d].vsub(t,l);var u=m;l.cross(f,u);var p=N;n.vsub(t,p);var s=u.dot(p);if(!(null===o||s>0&&o===!0||0>=s&&o===!1))return!1;null===o&&(o=s>0)}return!0}f.exports=n;var d=e("../shapes/Shape"),i=e("../math/Vec3"),t=e("../math/Transform"),l=(e("../shapes/ConvexPolyhedron"),e("../math/Quaternion")),u=(e("../solver/Solver"),e("../utils/Vec3Pool")),p=e("../equations/ContactEquation");n.prototype.makeResult=function(e,f,n,o,d,i){var t;return this.contactPointPool.length?(t=this.contactPointPool.pop(),t.bi=e,t.bj=f):t=new p(e,f),t.enabled=!0,t.si=d||n,t.sj=i||o,t};var s=new i,y=new i,c=new l,a=new l;n.prototype.getContacts=function(e,f,n,o,d){this.contactPointPool=d;for(var i=c,t=a,l=s,u=y,p=0,r=e.length;p!==r;p++)for(var w=e[p],b=f[p],m=0;mN.boundingSphereRadius+x.boundingSphereRadius)){var j=this[N.type|x.type];j&&(N.typeG&&G>0){var H=j,I=v;H.copy(s[(B+1)%3]),I.copy(s[(B+2)%3]);var J=H.norm(),K=I.norm();H.normalize(),I.normalize();var L=g.dot(H),M=g.dot(I);if(J>L&&L>-J&&K>M&&M>-K){var P=Math.abs(G-F-y);(null===z||z>P)&&(z=P,N=L,q=M,b=F,a.copy(E),r.copy(H),w.copy(I),m++)}}}if(m){c=!0;var Q=this.makeResult(l,u,f,n);a.mult(-y,Q.ri),Q.ni.copy(a),Q.ni.negate(Q.ni),a.mult(b,a),r.mult(N,r),a.vadd(r,a),w.mult(q,w),a.vadd(w,Q.rj),Q.ri.vadd(o,Q.ri),Q.ri.vsub(l.position,Q.ri),Q.rj.vadd(d,Q.rj),Q.rj.vsub(u.position,Q.rj),e.push(Q)}for(var R=p.get(),S=C,T=0;2!==T&&!c;T++)for(var U=0;2!==U&&!c;U++)for(var V=0;2!==V&&!c;V++)if(R.set(0,0,0),T?R.vadd(s[0],R):R.vsub(s[0],R),U?R.vadd(s[1],R):R.vsub(s[1],R),V?R.vadd(s[2],R):R.vsub(s[2],R),d.vadd(R,S),S.vsub(o,S),S.norm2()ef){c=!0;var ff=this.makeResult(l,u,f,n);X.vadd(Y,ff.rj),ff.rj.copy(ff.rj),P.negate(ff.ni),ff.ni.normalize(),ff.ri.copy(ff.rj),ff.ri.vadd(d,ff.ri),ff.ri.vsub(o,ff.ri),ff.ri.normalize(),ff.ri.mult(y,ff.ri),ff.ri.vadd(o,ff.ri),ff.ri.vsub(l.position,ff.ri),ff.rj.vadd(d,ff.rj),ff.rj.vsub(u.position,ff.rj),e.push(ff)}}p.release(W,X,Q,Y,P)};var q=new i,z=new i,B=new i,D=new i,E=new i,F=new i,G=new i,H=new i,I=new i,J=new i;n.prototype[d.types.SPHERE|d.types.CONVEXPOLYHEDRON]=n.prototype.sphereConvex=function(e,f,n,d,i,t,l,u,p){var s=this.v3pool;d.vsub(i,q);for(var y=n.faceNormals,c=n.faces,a=n.vertices,r=f.radius,w=0;w!==a.length;w++){var b=a[w],m=E;l.vmult(b,m),i.vadd(m,m);var N=D;if(m.vsub(d,N),N.norm2()K&&L.dot(C)>0){for(var M=[],P=0,Q=A.length;P!==Q;P++){var R=s.get();l.vmult(a[A[P]],R),i.vadd(R,R),M.push(R)}if(o(M,C,d)){x=!0;var g=this.makeResult(u,p,f,n);C.mult(-r,g.ri),C.negate(g.ni);var S=s.get();C.mult(-K,S);var T=s.get();C.mult(-r,T),d.vsub(i,g.rj),g.rj.vadd(T,g.rj),g.rj.vadd(S,g.rj),g.rj.vadd(i,g.rj),g.rj.vsub(p.position,g.rj),g.ri.vadd(d,g.ri),g.ri.vsub(u.position,g.ri),s.release(S),s.release(T),e.push(g);for(var P=0,U=M.length;P!==U;P++)s.release(M[P]);return}for(var P=0;P!==A.length;P++){var V=s.get(),W=s.get();l.vmult(a[A[(P+1)%A.length]],V),l.vmult(a[A[(P+2)%A.length]],W),i.vadd(V,V),i.vadd(W,W);var X=z;W.vsub(V,X);var Y=B;X.unit(Y);var Z=s.get(),$=s.get();d.vsub(V,$);var _=$.dot(Y);Y.mult(_,Z),Z.vadd(V,Z);var ef=s.get();if(Z.vsub(d,ef),_>0&&_*_=a){var r=this.makeResult(l,u,f,n),w=P;s.mult(s.dot(y),w),p.vsub(w,w),w.vsub(o,r.ri),r.ni.copy(s),p.vsub(d,r.rj),r.ri.vadd(o,r.ri),r.ri.vsub(l.position,r.ri),r.rj.vadd(d,r.rj),r.rj.vsub(u.position,r.rj),e.push(r) -}}};var Q=new i,R=new i;n.prototype[d.types.CONVEXPOLYHEDRON]=n.prototype.convexConvex=function(e,f,n,o,d,i,t,l,u,p,s,y,c){var a=Q;if(!(o.distanceTo(d)>f.boundingSphereRadius+n.boundingSphereRadius)&&f.findSeparatingAxis(n,o,i,d,t,a,y,c)){var r=[],w=R;f.clipAgainstHull(o,i,n,d,t,a,-100,100,r);for(var b=0;b!==r.length;b++){var m=this.makeResult(l,u,f,n,p,s),N=m.ri,g=m.rj;a.negate(m.ni),r[b].normal.negate(w),w.mult(r[b].depth,w),r[b].point.vadd(w,N),g.copy(r[b].point),N.vsub(o,N),g.vsub(d,g),N.vadd(o,N),N.vsub(l.position,N),g.vadd(d,g),g.vsub(u.position,g),e.push(m)}}};var S=new i,T=new i,U=new i;n.prototype[d.types.PLANE|d.types.PARTICLE]=n.prototype.planeParticle=function(e,f,n,o,d,i,t,l,u){var p=S;p.set(0,0,1),l.quaternion.vmult(p,p);var s=T;d.vsub(l.position,s);var y=p.dot(s);if(0>=y){var c=this.makeResult(u,l,n,f);c.ni.copy(p),c.ni.negate(c.ni),c.ri.set(0,0,0);var a=U;p.mult(p.dot(d),a),d.vsub(a,a),c.rj.copy(a),e.push(c)}};var V=new i;n.prototype[d.types.PARTICLE|d.types.SPHERE]=n.prototype.sphereParticle=function(e,f,n,o,d,i,t,l,u){var p=V;p.set(0,0,1),d.vsub(o,p);var s=p.norm2();if(s<=f.radius*f.radius){var y=this.makeResult(u,l,n,f);p.normalize(),y.rj.copy(p),y.rj.mult(f.radius,y.rj),y.ni.copy(p),y.ni.negate(y.ni),y.ri.set(0,0,0),e.push(y)}};var W=new l,X=new i,Y=(new i,new i),Z=new i,$=new i;n.prototype[d.types.PARTICLE|d.types.CONVEXPOLYHEDRON]=n.prototype.convexParticle=function(e,f,n,o,d,i,t,l,u){var p=-1,s=Y,y=$,c=null,a=0,r=X;if(r.copy(d),r.vsub(o,r),i.conjugate(W),W.vmult(r,r),f.pointIsInside(r)){f.worldVerticesNeedsUpdate&&f.computeWorldVertices(o,i),f.worldFaceNormalsNeedsUpdate&&f.computeWorldFaceNormals(i);for(var w=0,b=f.faces.length;w!==b;w++){var m=[f.worldVertices[f.faces[w][0]]],N=f.worldFaceNormals[w];d.vsub(m[0],Z);var g=-N.dot(Z);(null===c||Math.abs(g)m||0>g||b>s.length||g>s[0].length)){0>b&&(b=0),0>m&&(m=0),0>N&&(N=0),0>g&&(g=0),b>=s.length&&(b=s.length-1),m>=s.length&&(m=s.length-1),g>=s[0].length&&(g=s[0].length-1),N>=s[0].length&&(N=s[0].length-1);var x=[];n.getRectMinMax(b,N,m,g,x);var j=x[0],v=x[1];if(!(w.z-c>v||w.z+cA;A++)for(var C=N;g>C;C++)n.getConvexTrianglePillar(A,C,!1),t.pointToWorldFrame(d,l,n.pillarOffset,a),o.distanceTo(a)b||0>N||w>s.length||N>s[0].length)){0>w&&(w=0),0>b&&(b=0),0>m&&(m=0),0>N&&(N=0),w>=s.length&&(w=s.length-1),b>=s.length&&(b=s.length-1),N>=s[0].length&&(N=s[0].length-1),m>=s[0].length&&(m=s[0].length-1);var g=[];n.getRectMinMax(w,m,b,N,g);var x=g[0],j=g[1];if(!(r.z-y>j||r.z+yv;v++)for(var A=m;N>A;A++){var C=e.length;n.getConvexTrianglePillar(v,A,!1),t.pointToWorldFrame(d,l,n.pillarOffset,a),o.distanceTo(a)2)return}}}},{"../equations/ContactEquation":16,"../math/Quaternion":25,"../math/Transform":26,"../math/Vec3":27,"../shapes/ConvexPolyhedron":35,"../shapes/Shape":40,"../solver/Solver":43,"../utils/Vec3Pool":49}],51:[function(e,f){function n(){p.apply(this),this.dt=-1,this.allowSleep=!1,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new d,this.broadphase=new m,this.bodies=[],this.solver=new t,this.constraints=[],this.narrowphase=new u,this.collisionMatrix=new s,this.collisionMatrixPrevious=new s,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new r,this.defaultMaterial=new y("default"),this.defaultContactMaterial=new c(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null}}f.exports=n;var o=e("../shapes/Shape"),d=e("../math/Vec3"),i=e("../math/Quaternion"),t=e("../solver/GSSolver"),l=(e("../utils/Vec3Pool"),e("../equations/ContactEquation"),e("../equations/FrictionEquation")),u=e("./Narrowphase"),p=e("../utils/EventTarget"),s=e("../collision/ArrayCollisionMatrix"),y=e("../material/Material"),c=e("../material/ContactMaterial"),a=e("../objects/Body"),r=e("../utils/TupleDictionary"),w=(e("../collision/RaycastResult"),e("../collision/AABB")),b=e("../collision/Ray"),m=e("../collision/NaiveBroadphase");n.prototype=new p;var N=new w,g=[],x=new b;if(n.prototype.getContactMaterial=function(e,f){return this.contactMaterialTable.get(e.id,f.id)},n.prototype.numObjects=function(){return this.bodies.length},n.prototype.collisionMatrixTick=function(){var e=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=e,this.collisionMatrix.reset()},n.prototype.add=n.prototype.addBody=function(e){-1===this.bodies.indexOf(e)&&(e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.initPosition.copy(e.position),e.initVelocity.copy(e.velocity),e.timeLastSleepy=this.time,e instanceof a&&(e.initAngularVelocity.copy(e.angularVelocity),e.initQuaternion.copy(e.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=e,this.dispatchEvent(this.addBodyEvent))},n.prototype.addConstraint=function(e){this.constraints.push(e)},n.prototype.removeConstraint=function(e){var f=this.constraints.indexOf(e);-1!==f&&this.constraints.splice(f,1)},n.prototype.rayTest=function(e,f,n){x.from.copy(e),x.to.copy(f),x.getAABB(N),g.length=0,this.broadphase.aabbQuery(this,N,g),x.intersectBodies(g,n)},n.prototype.remove=function(e){e.world=null;var f=this.bodies.length-1,n=this.bodies,o=n.indexOf(e);if(-1!==o){n.splice(o,1);for(var d=0;d!==n.length;d++)n[d].index=d;this.collisionMatrix.setNumObjects(f),this.removeBodyEvent.body=e,this.dispatchEvent(this.removeBodyEvent)}},n.prototype.addMaterial=function(e){this.materials.push(e)},n.prototype.addContactMaterial=function(e){this.contactmaterials.push(e),this.contactMaterialTable.set(e.materials[0].id,e.materials[1].id,e)},"undefined"==typeof performance&&(performance={}),!performance.now){var j=Date.now();performance.timing&&performance.timing.navigationStart&&(j=performance.timing.navigationStart),performance.now=function(){return Date.now()-j}}var v=new d;n.prototype.step=function(e,f,n){if(n=n||10,f=f||0,0===f)this.internalStep(e),this.time+=e;else{var o=Math.floor((this.time+f)/e)-Math.floor(this.time/e);o=Math.min(o,n);for(var d=performance.now(),i=0;i!==o&&(this.internalStep(e),!(performance.now()-d>1e3*e));i++);this.time+=f;for(var t=this.time%e,l=t/e,u=v,p=this.bodies,s=0;s!==p.length;s++){var y=p[s];y.type!==a.STATIC&&y.sleepState!==a.SLEEPING?(y.position.vsub(y.previousPosition,u),u.scale(l,u),y.position.vadd(u,y.interpolatedPosition)):(y.interpolatedPosition.copy(y.position),y.interpolatedQuaternion.copy(y.quaternion))}}};var A={type:"postStep"},C={type:"preStep"},O={type:"collide",body:null,contact:null},h=[],k=[],q=[],z=[],B=new d,D=(new d,new d,new d,new d,new d,new d,new d,new d,new i,new i),E=new i,F=new d;n.prototype.internalStep=function(e){this.dt=e;var f,n=this.contacts,d=q,i=z,t=this.numObjects(),u=this.bodies,p=this.solver,s=this.gravity,y=this.doProfiling,c=this.profile,r=a.DYNAMIC,w=this.constraints,b=k,m=s.norm(),N=s.x,g=s.y,x=s.z,j=0;for(y&&(f=performance.now()),j=0;j!==t;j++){var v=u[j];if(v.type&r){var G=v.force,H=v.mass;G.x+=H*N,G.y+=H*g,G.z+=H*x}}for(var j=0,I=this.subsystems.length;j!==I;j++)this.subsystems[j].update();y&&(f=performance.now()),d.length=0,i.length=0,this.broadphase.collisionPairs(this,d,i),y&&(c.broadphase=performance.now()-f);var J=w.length;for(j=0;j!==J;j++){var K=w[j];if(!K.collideConnected)for(var L=d.length-1;L>=0;L-=1)(K.bodyA===d[L]&&K.bodyB===i[L]||K.bodyB===d[L]&&K.bodyA===i[L])&&(d.splice(L,1),i.splice(L,1))}this.collisionMatrixTick(),y&&(f=performance.now());var M=h,P=n.length;for(j=0;j!==P;j++)M.push(n[j]);n.length=0,this.narrowphase.getContacts(d,i,this,n,M),y&&(c.narrowphase=performance.now()-f),y&&(f=performance.now());var Q=n.length,R=this.frictionEquations.length;for(j=0;j!==R;j++)b.push(this.frictionEquations[j]);this.frictionEquations.length=0;for(var S=0;S!==Q;S++){var T,K=n[S],v=K.bi,U=K.bj,V=K.si,W=K.sj,j=u.indexOf(v),L=u.indexOf(U);T=v.material&&U.material?this.getContactMaterial(v.material,U.material)||this.defaultContactMaterial:this.defaultContactMaterial;var X=T.friction,Y=B;Y.set(U.position.x+K.rj.x-v.position.x-K.ri.x,U.position.y+K.rj.y-v.position.y-K.ri.y,U.position.z+K.rj.z-v.position.z-K.ri.z);var Z=Y.dot(K.ni);if(0>Z){if(K.enabled=v.collisionResponse&&U.collisionResponse&&V.collisionResponse&&W.collisionResponse,K.restitution=T.restitution,K.penetration=Z,K.setSpookParams(T.contactEquationStiffness,T.contactEquationRelaxation,e),p.addEquation(K),X>0){var $=X*m,_=v.invMass+U.invMass;_>0&&(_=1/_);var ef=b,ff=ef.length?ef.pop():new l(v,U,$*_),nf=ef.length?ef.pop():new l(v,U,$*_);this.frictionEquations.push(ff),this.frictionEquations.push(nf),ff.bi=nf.bi=v,ff.bj=nf.bj=U,ff.minForce=nf.minForce=-$*_,ff.maxForce=nf.maxForce=$*_,ff.ri.copy(K.ri),ff.rj.copy(K.rj),nf.ri.copy(K.ri),nf.rj.copy(K.rj),K.ni.tangents(ff.t,nf.t),ff.setSpookParams(T.frictionEquationStiffness,T.frictionEquationRelaxation,e),nf.setSpookParams(T.frictionEquationStiffness,T.frictionEquationRelaxation,e),ff.enabled=nf.enabled=K.enabled,p.addEquation(ff),p.addEquation(nf)}if(v.allowSleep&&v.type===a.DYNAMIC&&v.sleepState===a.SLEEPING&&U.sleepState===a.AWAKE&&U.type!==a.STATIC){var of=U.velocity.norm2()+U.angularVelocity.norm2(),df=Math.pow(U.sleepSpeedLimit,2);of>=2*df&&(v._wakeUpAfterNarrowphase=!0)}if(U.allowSleep&&U.type===a.DYNAMIC&&U.sleepState===a.SLEEPING&&v.sleepState===a.AWAKE&&v.type!==a.STATIC){var tf=v.velocity.norm2()+v.angularVelocity.norm2(),lf=Math.pow(v.sleepSpeedLimit,2);tf>=2*lf&&(U._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(v,U,!0),this.collisionMatrix.get(v,U)!==this.collisionMatrixPrevious.get(v,U)&&(O.body=U,O.contact=K,v.dispatchEvent(O),O.body=v,U.dispatchEvent(O))}}for(y&&(c.makeContactConstraints=performance.now()-f,f=performance.now()),j=0;j!==t;j++){var v=u[j];v._wakeUpAfterNarrowphase&&(v.wakeUp(),v._wakeUpAfterNarrowphase=!1)}var J=w.length;for(j=0;j!==J;j++){var K=w[j];K.update();for(var L=0,uf=K.equations.length;L!==uf;L++){var pf=K.equations[L];p.addEquation(pf)}}p.solve(e,this),y&&(c.solve=performance.now()-f),p.removeAllEquations();var sf=Math.pow;for(j=0;j!==t;j++){var v=u[j];if(v.type&r){var yf=sf(1-v.linearDamping,e),cf=v.velocity;cf.mult(yf,cf);var af=v.angularVelocity;if(af){var rf=sf(1-v.angularDamping,e);af.mult(rf,af)}}}for(this.dispatchEvent(C),j=0;j!==t;j++){var v=u[j];v.preStep&&v.preStep.call(v)}y&&(f=performance.now());var wf=D,bf=E,mf=this.stepnumber,Nf=a.DYNAMIC|a.KINEMATIC,gf=mf%(this.quatNormalizeSkip+1)===0,xf=this.quatNormalizeFast,jf=.5*e,vf=o.types.PLANE,Af=o.types.CONVEXPOLYHEDRON;for(j=0;j!==t;j++){var Cf=u[j],Of=Cf.shape,hf=Cf.force,kf=Cf.torque;if(Cf.type&Nf&&Cf.sleepState!==a.SLEEPING){var qf=Cf.velocity,zf=Cf.angularVelocity,Bf=Cf.position,Df=Cf.quaternion,Ef=Cf.invMass,Ff=Cf.invInertiaWorld;if(qf.x+=hf.x*Ef*e,qf.y+=hf.y*Ef*e,qf.z+=hf.z*Ef*e,Cf.angularVelocity&&(Ff.vmult(kf,F),F.mult(e,F),F.vadd(zf,zf)),Bf.x+=qf.x*e,Bf.y+=qf.y*e,Bf.z+=qf.z*e,Cf.angularVelocity&&(wf.set(zf.x,zf.y,zf.z,0),wf.mult(Df,bf),Df.x+=jf*bf.x,Df.y+=jf*bf.y,Df.z+=jf*bf.z,Df.w+=jf*bf.w,gf&&(xf?Df.normalizeFast():Df.normalize())),Cf.aabb&&(Cf.aabbNeedsUpdate=!0),Of)switch(Of.type){case vf:Of.worldNormalNeedsUpdate=!0;break;case Af:Of.worldFaceNormalsNeedsUpdate=!0,Of.worldVerticesNeedsUpdate=!0}Cf.updateInertiaWorld&&Cf.updateInertiaWorld()}Cf.force.set(0,0,0),Cf.torque&&Cf.torque.set(0,0,0)}for(this.broadphase.dirty=!0,y&&(c.integrate=performance.now()-f),this.time+=e,this.stepnumber+=1,this.dispatchEvent(A),j=0;j!==t;j++){var v=u[j],Gf=v.postStep;Gf&&Gf.call(v)}if(this.allowSleep)for(j=0;j!==t;j++)u[j].sleepTick(this.time)}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":16,"../equations/FrictionEquation":18,"../material/ContactMaterial":21,"../material/Material":22,"../math/Quaternion":25,"../math/Vec3":27,"../objects/Body":28,"../shapes/Shape":40,"../solver/GSSolver":42,"../utils/EventTarget":45,"../utils/TupleDictionary":47,"../utils/Vec3Pool":49,"./Narrowphase":50}]},{},[2])(2)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&false)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.CANNON=e()}}(function(){return function e(f,n,o){function d(t,l){if(!n[t]){if(!f[t]){var u="function"==typeof require&&require;if(!l&&u)return u(t,!0);if(i)return i(t,!0);throw new Error("Cannot find module '"+t+"'")}var p=n[t]={exports:{}};f[t][0].call(p.exports,function(e){var n=f[t][1][e];return d(n?n:e)},p,p.exports,e,f,n,o)}return n[t].exports}for(var i="function"==typeof require&&require,t=0;t (http://steffe.se)",keywords:["cannon.js","cannon","physics","engine","3d"],main:"./build/cannon.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/cannon.js.git"},bugs:{url:"https://github.com/schteppe/cannon.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest","uglify-js":"latest",nodeunit:"^0.9.0",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"^0.5.1","grunt-browserify":"^2.1.4","grunt-contrib-yuidoc":"^0.5.2",browserify:"*"},dependencies:{}}},{}],2:[function(e,f){f.exports={version:e("../package.json").version,AABB:e("./collision/AABB"),ArrayCollisionMatrix:e("./collision/ArrayCollisionMatrix"),Body:e("./objects/Body"),Box:e("./shapes/Box"),Broadphase:e("./collision/Broadphase"),Constraint:e("./constraints/Constraint"),ContactEquation:e("./equations/ContactEquation"),Narrowphase:e("./world/Narrowphase"),ConeTwistConstraint:e("./constraints/ConeTwistConstraint"),ContactMaterial:e("./material/ContactMaterial"),ConvexPolyhedron:e("./shapes/ConvexPolyhedron"),Cylinder:e("./shapes/Cylinder"),DistanceConstraint:e("./constraints/DistanceConstraint"),Equation:e("./equations/Equation"),EventTarget:e("./utils/EventTarget"),FrictionEquation:e("./equations/FrictionEquation"),GSSolver:e("./solver/GSSolver"),GridBroadphase:e("./collision/GridBroadphase"),Heightfield:e("./shapes/Heightfield"),HingeConstraint:e("./constraints/HingeConstraint"),LockConstraint:e("./constraints/LockConstraint"),Mat3:e("./math/Mat3"),Material:e("./material/Material"),NaiveBroadphase:e("./collision/NaiveBroadphase"),ObjectCollisionMatrix:e("./collision/ObjectCollisionMatrix"),Pool:e("./utils/Pool"),Particle:e("./shapes/Particle"),Plane:e("./shapes/Plane"),PointToPointConstraint:e("./constraints/PointToPointConstraint"),Quaternion:e("./math/Quaternion"),Ray:e("./collision/Ray"),RaycastVehicle:e("./objects/RaycastVehicle"),RaycastResult:e("./collision/RaycastResult"),RigidVehicle:e("./objects/RigidVehicle"),RotationalEquation:e("./equations/RotationalEquation"),RotationalMotorEquation:e("./equations/RotationalMotorEquation"),SAPBroadphase:e("./collision/SAPBroadphase"),SPHSystem:e("./objects/SPHSystem"),Shape:e("./shapes/Shape"),Solver:e("./solver/Solver"),Sphere:e("./shapes/Sphere"),SplitSolver:e("./solver/SplitSolver"),Spring:e("./objects/Spring"),Trimesh:e("./shapes/Trimesh"),Vec3:e("./math/Vec3"),Vec3Pool:e("./utils/Vec3Pool"),World:e("./world/World")}},{"../package.json":1,"./collision/AABB":3,"./collision/ArrayCollisionMatrix":4,"./collision/Broadphase":5,"./collision/GridBroadphase":6,"./collision/NaiveBroadphase":7,"./collision/ObjectCollisionMatrix":8,"./collision/Ray":9,"./collision/RaycastResult":10,"./collision/SAPBroadphase":11,"./constraints/ConeTwistConstraint":12,"./constraints/Constraint":13,"./constraints/DistanceConstraint":14,"./constraints/HingeConstraint":15,"./constraints/LockConstraint":16,"./constraints/PointToPointConstraint":17,"./equations/ContactEquation":19,"./equations/Equation":20,"./equations/FrictionEquation":21,"./equations/RotationalEquation":22,"./equations/RotationalMotorEquation":23,"./material/ContactMaterial":24,"./material/Material":25,"./math/Mat3":27,"./math/Quaternion":28,"./math/Vec3":30,"./objects/Body":31,"./objects/RaycastVehicle":32,"./objects/RigidVehicle":33,"./objects/SPHSystem":34,"./objects/Spring":35,"./shapes/Box":37,"./shapes/ConvexPolyhedron":38,"./shapes/Cylinder":39,"./shapes/Heightfield":40,"./shapes/Particle":41,"./shapes/Plane":42,"./shapes/Shape":43,"./shapes/Sphere":44,"./shapes/Trimesh":45,"./solver/GSSolver":46,"./solver/Solver":47,"./solver/SplitSolver":48,"./utils/EventTarget":49,"./utils/Pool":51,"./utils/Vec3Pool":54,"./world/Narrowphase":55,"./world/World":56}],3:[function(e,f){function n(e){e=e||{},this.lowerBound=new o,e.lowerBound&&this.lowerBound.copy(e.lowerBound),this.upperBound=new o,e.upperBound&&this.upperBound.copy(e.upperBound)}{var o=e("../math/Vec3");e("../utils/Utils")}f.exports=n;var d=new o;n.prototype.setFromPoints=function(e,f,n,o){var i=this.lowerBound,t=this.upperBound,l=n;i.copy(e[0]),l&&l.vmult(i,i),t.copy(i);for(var u=1;ut.x&&(t.x=p.x),p.xt.y&&(t.y=p.y),p.yt.z&&(t.z=p.z),p.zf&&(this.lowerBound.x=f);var n=e.upperBound.x;this.upperBound.xf&&(this.lowerBound.y=f);var n=e.upperBound.y;this.upperBound.yf&&(this.lowerBound.z=f);var n=e.upperBound.z;this.upperBound.z=d.x&&f.y<=o.y&&n.y>=d.y&&f.z<=o.z&&n.z>=d.z},n.prototype.getCorners=function(e,f,n,o,d,i,t,l){var u=this.lowerBound,p=this.upperBound;e.copy(u),f.set(p.x,u.y,u.z),n.set(p.x,p.y,u.z),o.set(u.x,p.y,p.z),d.set(p.x,u.y,u.z),i.set(u.x,p.y,u.z),t.set(u.x,u.y,p.z),l.copy(p)};var i=[new o,new o,new o,new o,new o,new o,new o,new o];n.prototype.toLocalFrame=function(e,f){var n=i,o=n[0],d=n[1],t=n[2],l=n[3],u=n[4],p=n[5],s=n[6],y=n[7];this.getCorners(o,d,t,l,u,p,s,y);for(var c=0;8!==c;c++){var a=n[c];e.pointToLocal(a,a)}return f.setFromPoints(n)},n.prototype.toWorldFrame=function(e,f){var n=i,o=n[0],d=n[1],t=n[2],l=n[3],u=n[4],p=n[5],s=n[6],y=n[7];this.getCorners(o,d,t,l,u,p,s,y);for(var c=0;8!==c;c++){var a=n[c];e.pointToWorld(a,a)}return f.setFromPoints(n)}},{"../math/Vec3":30,"../utils/Utils":53}],4:[function(e,f){function n(){this.matrix=[]}f.exports=n,n.prototype.get=function(e,f){if(e=e.index,f=f.index,f>e){var n=f;f=e,e=n}return this.matrix[(e*(e+1)>>1)+f-1]},n.prototype.set=function(e,f,n){if(e=e.index,f=f.index,f>e){var o=f;f=e,e=o}this.matrix[(e*(e+1)>>1)+f-1]=n?1:0},n.prototype.reset=function(){for(var e=0,f=this.matrix.length;e!==f;e++)this.matrix[e]=0},n.prototype.setNumObjects=function(e){this.matrix.length=e*(e-1)>>1}},{}],5:[function(e,f){function n(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}{var o=e("../objects/Body"),d=e("../math/Vec3"),i=e("../math/Quaternion");e("../shapes/Shape"),e("../shapes/Plane")}f.exports=n,n.prototype.collisionPairs=function(){throw new Error("collisionPairs not implemented for this BroadPhase class!")};var t=o.STATIC|o.KINEMATIC;n.prototype.needBroadphaseCollision=function(e,f){return 0===(e.collisionFilterGroup&f.collisionFilterMask)||0===(f.collisionFilterGroup&e.collisionFilterMask)?!1:0===(e.type&t)&&e.sleepState!==o.SLEEPING||0===(f.type&t)&&f.sleepState!==o.SLEEPING?!0:!1},n.prototype.intersectionTest=function(e,f,n,o){this.useBoundingBoxes?this.doBoundingBoxBroadphase(e,f,n,o):this.doBoundingSphereBroadphase(e,f,n,o)};{var l=new d;new d,new i,new d}n.prototype.doBoundingSphereBroadphase=function(e,f,n,o){var d=l;f.position.vsub(e.position,d);var i=Math.pow(e.boundingRadius+f.boundingRadius,2),t=d.norm2();i>t&&(n.push(e),o.push(f))},n.prototype.doBoundingBoxBroadphase=function(e,f,n,o){e.aabbNeedsUpdate&&e.computeAABB(),f.aabbNeedsUpdate&&f.computeAABB(),e.aabb.overlaps(f.aabb)&&(n.push(e),o.push(f))};var u={keys:[]},p=[],s=[];n.prototype.makePairsUnique=function(e,f){for(var n=u,o=p,d=s,i=e.length,t=0;t!==i;t++)o[t]=e[t],d[t]=f[t];e.length=0,f.length=0;for(var t=0;t!==i;t++){var l=o[t].id,y=d[t].id,c=y>l?l+","+y:y+","+l;n[c]=t,n.keys.push(c)}for(var t=0;t!==n.keys.length;t++){var c=n.keys.pop(),a=n[c];e.push(o[a]),f.push(d[a]),delete n[c]}},n.prototype.setWorld=function(){};var y=new d;n.boundingSphereCheck=function(e,f){var n=y;return e.position.vsub(f.position,n),Math.pow(e.shape.boundingSphereRadius+f.shape.boundingSphereRadius,2)>n.norm2()},n.prototype.aabbQuery=function(){return console.warn(".aabbQuery is not implemented in this Broadphase subclass."),[]}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Plane":42,"../shapes/Shape":43}],6:[function(e,f){function n(e,f,n,i,t){o.apply(this),this.nx=n||10,this.ny=i||10,this.nz=t||10,this.aabbMin=e||new d(100,100,100),this.aabbMax=f||new d(-100,-100,-100);var l=this.nx*this.ny*this.nz;if(0>=l)throw"GridBroadphase: Each dimension's n must be >0";this.bins=[],this.binLengths=[],this.bins.length=l,this.binLengths.length=l;for(var u=0;l>u;u++)this.bins[u]=[],this.binLengths[u]=0}f.exports=n;var o=e("./Broadphase"),d=e("../math/Vec3"),i=e("../shapes/Shape");n.prototype=new o,n.prototype.constructor=n;{var t=new d;new d}n.prototype.collisionPairs=function(e,f,n){function o(e,f,n,o,d,i,t){var l=(e-g)*v|0,u=(f-x)*A|0,p=(n-j)*C|0,b=I((o-g)*v),m=I((d-x)*A),N=I((i-j)*C);0>l?l=0:l>=s&&(l=s-1),0>u?u=0:u>=y&&(u=y-1),0>p?p=0:p>=c&&(p=c-1),0>b?b=0:b>=s&&(b=s-1),0>m?m=0:m>=y&&(m=y-1),0>N?N=0:N>=c&&(N=c-1),l*=a,u*=r,p*=w,b*=a,m*=r,N*=w;for(var O=l;b>=O;O+=a)for(var h=u;m>=h;h+=r)for(var k=p;N>=k;k+=w){var q=O+h+k;E[q][F[q]++]=t}}for(var d=e.numObjects(),l=e.bodies,u=this.aabbMax,p=this.aabbMin,s=this.nx,y=this.ny,c=this.nz,a=y*c,r=c,w=1,b=u.x,m=u.y,N=u.z,g=p.x,x=p.y,j=p.z,v=s/(b-g),A=y/(m-x),C=c/(N-j),O=(b-g)/s,h=(m-x)/y,k=(N-j)/c,q=.5*Math.sqrt(O*O+h*h+k*k),z=i.types,B=z.SPHERE,D=z.PLANE,E=(z.BOX,z.COMPOUND,z.CONVEXPOLYHEDRON,this.bins),F=this.binLengths,G=this.bins.length,H=0;H!==G;H++)F[H]=0;for(var I=Math.ceil,p=Math.min,u=Math.max,H=0;H!==d;H++){var J=l[H],K=J.shape;switch(K.type){case B:var L=J.position.x,M=J.position.y,P=J.position.z,Q=K.radius;o(L-Q,M-Q,P-Q,L+Q,M+Q,P+Q,J);break;case D:K.worldNormalNeedsUpdate&&K.computeWorldNormal(J.quaternion);var R=K.worldNormal,S=g+.5*O-J.position.x,T=x+.5*h-J.position.y,U=j+.5*k-J.position.z,V=t;V.set(S,T,U);for(var W=0,X=0;W!==s;W++,X+=a,V.y=T,V.x+=O)for(var Y=0,Z=0;Y!==y;Y++,Z+=r,V.z=U,V.y+=h)for(var $=0,_=0;$!==c;$++,_+=w,V.z+=k)if(V.dot(R)1)for(var nf=E[H],W=0;W!==ff;W++)for(var J=nf[W],Y=0;Y!==W;Y++){var of=nf[Y];this.needBroadphaseCollision(J,of)&&this.intersectionTest(J,of,f,n)}}this.makePairsUnique(f,n)}},{"../math/Vec3":30,"../shapes/Shape":43,"./Broadphase":5}],7:[function(e,f){function n(){o.apply(this)}f.exports=n;var o=e("./Broadphase"),d=e("./AABB");n.prototype=new o,n.prototype.constructor=n,n.prototype.collisionPairs=function(e,f,n){var o,d,i,t,l=e.bodies,u=l.length;for(o=0;o!==u;o++)for(d=0;d!==o;d++)i=l[o],t=l[d],this.needBroadphaseCollision(i,t)&&this.intersectionTest(i,t,f,n)};new d;n.prototype.aabbQuery=function(e,f,n){n=n||[];for(var o=0;oe){var n=f;f=e,e=n}return e+"-"+f in this.matrix},n.prototype.set=function(e,f,n){if(e=e.id,f=f.id,f>e){var o=f;f=e,e=o}n?this.matrix[e+"-"+f]=!0:delete this.matrix[e+"-"+f]},n.prototype.reset=function(){this.matrix={}},n.prototype.setNumObjects=function(){}},{}],9:[function(e,f){function n(e,f){this.from=e?e.clone():new i,this.to=f?f.clone():new i,this._direction=new i,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=n.ANY,this.result=new u,this.hasHit=!1,this.callback=function(){}}function o(e,f,n,o){o.vsub(f,G),n.vsub(f,a),e.vsub(f,r);var d,i,t=G.dot(G),l=G.dot(a),u=G.dot(r),p=a.dot(a),s=a.dot(r);return(d=p*u-l*s)>=0&&(i=t*s-l*u)>=0&&t*p-l*l>d+i}function d(e,f,n){n.vsub(e,G);var o=G.dot(f);f.mult(o,H),H.vadd(e,H);var d=n.distanceTo(H);return d}f.exports=n;var i=e("../math/Vec3"),t=e("../math/Quaternion"),l=e("../math/Transform"),u=(e("../shapes/ConvexPolyhedron"),e("../shapes/Box"),e("../collision/RaycastResult")),p=e("../shapes/Shape"),s=e("../collision/AABB");n.prototype.constructor=n,n.CLOSEST=1,n.ANY=2,n.ALL=4;var y=new s,c=[];n.prototype.intersectWorld=function(e,f){return this.mode=f.mode||n.ANY,this.result=f.result||new u,this.skipBackfaces=!!f.skipBackfaces,this.collisionFilterMask="undefined"!=typeof f.collisionFilterMask?f.collisionFilterMask:-1,this.collisionFilterGroup="undefined"!=typeof f.collisionFilterGroup?f.collisionFilterGroup:-1,f.from&&this.from.copy(f.from),f.to&&this.to.copy(f.to),this.callback=f.callback||function(){},this.hasHit=!1,this.result.reset(),this._updateDirection(),this.getAABB(y),c.length=0,e.broadphase.aabbQuery(e,y,c),this.intersectBodies(c),this.hasHit};var a=new i,r=new i;n.pointInTriangle=o;var w=new i,b=new t;n.prototype.intersectBody=function(e,f){f&&(this.result=f,this._updateDirection());var n=this.checkCollisionResponse;if((!n||e.collisionResponse)&&0!==(this.collisionFilterGroup&e.collisionFilterMask)&&0!==(e.collisionFilterGroup&this.collisionFilterMask))for(var o=w,d=b,i=0,t=e.shapes.length;t>i;i++){var l=e.shapes[i];if((!n||l.collisionResponse)&&(e.quaternion.mult(e.shapeOrientations[i],d),e.quaternion.vmult(e.shapeOffsets[i],o),o.vadd(e.position,o),this.intersectShape(l,d,o,e),this.result._shouldStop))break}},n.prototype.intersectBodies=function(e,f){f&&(this.result=f,this._updateDirection());for(var n=0,o=e.length;!this.result._shouldStop&&o>n;n++)this.intersectBody(e[n])},n.prototype._updateDirection=function(){this.to.vsub(this.from,this._direction),this._direction.normalize()},n.prototype.intersectShape=function(e,f,n,o){var i=this.from,t=d(i,this._direction,n);if(!(t>e.boundingSphereRadius)){var l=this[e.type];l&&l.call(this,e,f,n,o)}};{var m=(new i,new i,new i),N=new i,g=new i,x=new i;new i,new u}n.prototype.intersectBox=function(e,f,n,o){return this.intersectConvex(e.convexPolyhedronRepresentation,f,n,o)},n.prototype[p.types.BOX]=n.prototype.intersectBox,n.prototype.intersectPlane=function(e,f,n,o){var d=this.from,t=this.to,l=this._direction,u=new i(0,0,1);f.vmult(u,u);var p=new i;d.vsub(n,p);var s=p.dot(u);t.vsub(n,p);var y=p.dot(u);if(!(s*y>0||d.distanceTo(t)c)&&(c=p[0]),(null===y||p[1]a)&&(a=p[1])),null!==s){var w=[];e.getRectMinMax(s,y,c,a,w);for(var b=(w[0],w[1],s);c>=b;b++)for(var m=y;a>=m;m++){if(this.result._shouldStop)return;if(e.getConvexTrianglePillar(b,m,!1),l.pointToWorldFrame(o,f,e.pillarOffset,t),this.intersectConvex(e.pillarConvex,f,t,d,j),this.result._shouldStop)return;e.getConvexTrianglePillar(b,m,!0),l.pointToWorldFrame(o,f,e.pillarOffset,t),this.intersectConvex(e.pillarConvex,f,t,d,j)}}},n.prototype[p.types.HEIGHTFIELD]=n.prototype.intersectHeightfield;var v=new i,A=new i;n.prototype.intersectSphere=function(e,f,n,o){var d=this.from,i=this.to,t=e.radius,l=Math.pow(i.x-d.x,2)+Math.pow(i.y-d.y,2)+Math.pow(i.z-d.z,2),u=2*((i.x-d.x)*(d.x-n.x)+(i.y-d.y)*(d.y-n.y)+(i.z-d.z)*(d.z-n.z)),p=Math.pow(d.x-n.x,2)+Math.pow(d.y-n.y,2)+Math.pow(d.z-n.z,2)-Math.pow(t,2),s=Math.pow(u,2)-4*l*p,y=v,c=A;if(!(0>s))if(0===s)d.lerp(i,s,y),y.vsub(n,c),c.normalize(),this.reportIntersection(c,y,e,o,-1);else{var a=(-u-Math.sqrt(s))/(2*l),r=(-u+Math.sqrt(s))/(2*l);if(a>=0&&1>=a&&(d.lerp(i,a,y),y.vsub(n,c),c.normalize(),this.reportIntersection(c,y,e,o,-1)),this.result._shouldStop)return;r>=0&&1>=r&&(d.lerp(i,r,y),y.vsub(n,c),c.normalize(),this.reportIntersection(c,y,e,o,-1))}},n.prototype[p.types.SPHERE]=n.prototype.intersectSphere;var C=new i,O=(new i,new i,new i);n.prototype.intersectConvex=function(e,f,n,d,i){for(var t=C,l=O,u=i&&i.faceList||null,p=e.faces,s=e.vertices,y=e.faceNormals,c=this._direction,a=this.from,r=this.to,w=a.distanceTo(r),b=u?u.length:p.length,j=this.result,v=0;!j._shouldStop&&b>v;v++){var A=u?u[v]:v,h=p[A],k=y[A],q=f,z=n;l.copy(s[h[0]]),q.vmult(l,l),l.vadd(z,l),l.vsub(a,l),q.vmult(k,t);var B=c.dot(t);if(!(Math.abs(B)D)){c.mult(D,m),m.vadd(a,m),N.copy(s[h[0]]),q.vmult(N,N),z.vadd(N,N);for(var E=1;!j._shouldStop&&Ew||this.reportIntersection(t,m,e,d,A)}}}}},n.prototype[p.types.CONVEXPOLYHEDRON]=n.prototype.intersectConvex;var h=new i,k=new i,q=new i,z=new i,B=new i,D=new i,E=(new s,[]),F=new l;n.prototype.intersectTrimesh=function(e,f,n,d,i){var t=h,u=E,p=F,s=O,y=k,c=q,a=z,r=D,w=B,b=(i&&i.faceList||null,e.indices),j=(e.vertices,e.faceNormals,this.from),v=this.to,A=this._direction;p.position.copy(n),p.quaternion.copy(f),l.vectorToLocalFrame(n,f,A,y),l.pointToLocalFrame(n,f,j,c),l.pointToLocalFrame(n,f,v,a);var C=c.distanceSquared(a);e.tree.rayQuery(this,p,u);for(var G=0,H=u.length;!this.result._shouldStop&&G!==H;G++){var I=u[G];e.getNormal(I,t),e.getVertex(b[3*I],N),N.vsub(c,s);var J=y.dot(t),K=t.dot(s)/J;if(!(0>K)){y.scale(K,m),m.vadd(c,m),e.getVertex(b[3*I+1],g),e.getVertex(b[3*I+2],x);var L=m.distanceSquared(c);!o(m,g,N,x)&&!o(m,N,g,x)||L>C||(l.vectorToWorldFrame(f,t,w),l.pointToWorldFrame(n,f,m,r),this.reportIntersection(w,r,e,d,I))}}u.length=0},n.prototype[p.types.TRIMESH]=n.prototype.intersectTrimesh,n.prototype.reportIntersection=function(e,f,o,d,i){var t=this.from,l=this.to,u=t.distanceTo(f),p=this.result;if(!(this.skipBackfaces&&e.dot(this._direction)>0))switch(p.hitFaceIndex="undefined"!=typeof i?i:-1,this.mode){case n.ALL:this.hasHit=!0,p.set(t,l,e,f,o,d,u),p.hasHit=!0,this.callback(p);break;case n.CLOSEST:(uf;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.x<=o.aabb.lowerBound.x);d--)e[d+1]=e[d];e[d+1]=o}return e},n.insertionSortY=function(e){for(var f=1,n=e.length;n>f;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.y<=o.aabb.lowerBound.y);d--)e[d+1]=e[d];e[d+1]=o}return e},n.insertionSortZ=function(e){for(var f=1,n=e.length;n>f;f++){for(var o=e[f],d=f-1;d>=0&&!(e[d].aabb.lowerBound.z<=o.aabb.lowerBound.z);d--)e[d+1]=e[d];e[d+1]=o}return e},n.prototype.collisionPairs=function(e,f,o){var d,i,t=this.axisList,l=t.length,u=this.axisIndex;for(this.dirty&&(this.sortList(),this.dirty=!1),d=0;d!==l;d++){var p=t[d];for(i=d+1;l>i;i++){var s=t[i];if(this.needBroadphaseCollision(p,s)){if(!n.checkBounds(p,s,u))break;this.intersectionTest(p,s,f,o)}}}},n.prototype.sortList=function(){for(var e=this.axisList,f=this.axisIndex,o=e.length,d=0;d!==o;d++){var i=e[d];i.aabbNeedsUpdate&&i.computeAABB()}0===f?n.insertionSortX(e):1===f?n.insertionSortY(e):2===f&&n.insertionSortZ(e)},n.checkBounds=function(e,f,n){var o,d;0===n?(o=e.position.x,d=f.position.x):1===n?(o=e.position.y,d=f.position.y):2===n&&(o=e.position.z,d=f.position.z);var i=e.boundingRadius,t=f.boundingRadius,l=o+i,u=d-t;return l>u},n.prototype.autoDetectAxis=function(){for(var e=0,f=0,n=0,o=0,d=0,i=0,t=this.axisList,l=t.length,u=1/l,p=0;p!==l;p++){var s=t[p],y=s.position.x;e+=y,f+=y*y;var c=s.position.y;n+=c,o+=c*c;var a=s.position.z;d+=a,i+=a*a}var r=f-e*e*u,w=o-n*n*u,b=i-d*d*u;this.axisIndex=r>w?r>b?0:2:w>b?1:2},n.prototype.aabbQuery=function(e,f,n){n=n||[],this.dirty&&(this.sortList(),this.dirty=!1);var o=this.axisIndex,d="x";1===o&&(d="y"),2===o&&(d="z");for(var i=this.axisList,t=(f.lowerBound[d],f.upperBound[d],0);td;d++)for(var i=0;3>i;i++){for(var t=0,l=0;3>l;l++)t+=e.elements[d+3*l]*this.elements[l+3*i];o.elements[d+3*i]=t}return o},n.prototype.scale=function(e,f){f=f||new n;for(var o=this.elements,d=f.elements,i=0;3!==i;i++)d[3*i+0]=e.x*o[3*i+0],d[3*i+1]=e.y*o[3*i+1],d[3*i+2]=e.z*o[3*i+2];return f},n.prototype.solve=function(e,f){f=f||new o;for(var n=3,d=4,i=[],t=0;n*d>t;t++)i.push(0);var t,l;for(t=0;3>t;t++)for(l=0;3>l;l++)i[t+d*l]=this.elements[t+3*l];i[3]=e.x,i[7]=e.y,i[11]=e.z;var u,p,s=3,y=s,c=4;do{if(t=y-s,0===i[t+d*t])for(l=t+1;y>l;l++)if(0!==i[t+d*l]){u=c;do p=c-u,i[p+d*t]+=i[p+d*l];while(--u);break}if(0!==i[t+d*t])for(l=t+1;y>l;l++){var a=i[t+d*l]/i[t+d*t];u=c;do p=c-u,i[p+d*l]=t>=p?0:i[p+d*l]-i[p+d*t]*a;while(--u)}}while(--s);if(f.z=i[2*d+3]/i[2*d+2],f.y=(i[1*d+3]-i[1*d+2]*f.z)/i[1*d+1],f.x=(i[0*d+3]-i[0*d+2]*f.z-i[0*d+1]*f.y)/i[0*d+0],isNaN(f.x)||isNaN(f.y)||isNaN(f.z)||1/0===f.x||1/0===f.y||1/0===f.z)throw"Could not solve equation! Got x=["+f.toString()+"], b=["+e.toString()+"], A=["+this.toString()+"]";return f},n.prototype.e=function(e,f,n){return void 0===n?this.elements[f+3*e]:void(this.elements[f+3*e]=n)},n.prototype.copy=function(e){for(var f=0;fn;n++)e+=this.elements[n]+f;return e},n.prototype.reverse=function(e){e=e||new n;for(var f=3,o=6,d=[],i=0;f*o>i;i++)d.push(0);var i,t;for(i=0;3>i;i++)for(t=0;3>t;t++)d[i+o*t]=this.elements[i+3*t];d[3]=1,d[9]=0,d[15]=0,d[4]=0,d[10]=1,d[16]=0,d[5]=0,d[11]=0,d[17]=1;var l,u,p=3,s=p,y=o;do{if(i=s-p,0===d[i+o*i])for(t=i+1;s>t;t++)if(0!==d[i+o*t]){l=y;do u=y-l,d[u+o*i]+=d[u+o*t];while(--l);break}if(0!==d[i+o*i])for(t=i+1;s>t;t++){var c=d[i+o*t]/d[i+o*i];l=y;do u=y-l,d[u+o*t]=i>=u?0:d[u+o*t]-d[u+o*i]*c;while(--l)}}while(--p);i=2;do{t=i-1;do{var c=d[i+o*t]/d[i+o*i];l=o;do u=o-l,d[u+o*t]=d[u+o*t]-d[u+o*i]*c;while(--l)}while(t--)}while(--i);i=2;do{var c=1/d[i+o*i];l=o;do u=o-l,d[u+o*i]=d[u+o*i]*c;while(--l)}while(i--);i=2;do{t=2;do{if(u=d[f+t+o*i],isNaN(u)||1/0===u)throw"Could not reverse! A=["+this.toString()+"]";e.e(i,t,u)}while(t--)}while(i--);return e},n.prototype.setRotationFromQuaternion=function(e){var f=e.x,n=e.y,o=e.z,d=e.w,i=f+f,t=n+n,l=o+o,u=f*i,p=f*t,s=f*l,y=n*t,c=n*l,a=o*l,r=d*i,w=d*t,b=d*l,m=this.elements;return m[0]=1-(y+a),m[1]=p-b,m[2]=s+w,m[3]=p+b,m[4]=1-(u+a),m[5]=c-r,m[6]=s-w,m[7]=c+r,m[8]=1-(u+y),this},n.prototype.transpose=function(e){e=e||new n;for(var f=e.elements,o=this.elements,d=0;3!==d;d++)for(var i=0;3!==i;i++)f[3*d+i]=o[3*i+d];return e}},{"./Vec3":30}],28:[function(e,f){function n(e,f,n,o){this.x=void 0!==e?e:0,this.y=void 0!==f?f:0,this.z=void 0!==n?n:0,this.w=void 0!==o?o:1}f.exports=n;var o=e("./Vec3");n.prototype.set=function(e,f,n,o){this.x=e,this.y=f,this.z=n,this.w=o},n.prototype.toString=function(){return this.x+","+this.y+","+this.z+","+this.w},n.prototype.toArray=function(){return[this.x,this.y,this.z,this.w]},n.prototype.setFromAxisAngle=function(e,f){var n=Math.sin(.5*f);this.x=e.x*n,this.y=e.y*n,this.z=e.z*n,this.w=Math.cos(.5*f)},n.prototype.toAxisAngle=function(e){e=e||new o,this.normalize();var f=2*Math.acos(this.w),n=Math.sqrt(1-this.w*this.w);return.001>n?(e.x=this.x,e.y=this.y,e.z=this.z):(e.x=this.x/n,e.y=this.y/n,e.z=this.z/n),[e,f]};var d=new o,i=new o;n.prototype.setFromVectors=function(e,f){if(e.isAntiparallelTo(f)){var n=d,o=i;e.tangents(n,o),this.setFromAxisAngle(n,Math.PI)}else{var t=e.cross(f);this.x=t.x,this.y=t.y,this.z=t.z,this.w=Math.sqrt(Math.pow(e.norm(),2)*Math.pow(f.norm(),2))+e.dot(f),this.normalize()}};var t=new o,l=new o,u=new o;n.prototype.mult=function(e,f){f=f||new n;var o=this.w,d=t,i=l,p=u;return d.set(this.x,this.y,this.z),i.set(e.x,e.y,e.z),f.w=o*e.w-d.dot(i),d.cross(i,p),f.x=o*i.x+e.w*d.x+p.x,f.y=o*i.y+e.w*d.y+p.y,f.z=o*i.z+e.w*d.z+p.z,f},n.prototype.inverse=function(e){var f=this.x,o=this.y,d=this.z,i=this.w;e=e||new n,this.conjugate(e);var t=1/(f*f+o*o+d*d+i*i);return e.x*=t,e.y*=t,e.z*=t,e.w*=t,e},n.prototype.conjugate=function(e){return e=e||new n,e.x=-this.x,e.y=-this.y,e.z=-this.z,e.w=this.w,e},n.prototype.normalize=function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(e=1/e,this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.normalizeFast=function(){var e=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;0===e?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=e,this.y*=e,this.z*=e,this.w*=e)},n.prototype.vmult=function(e,f){f=f||new o;var n=e.x,d=e.y,i=e.z,t=this.x,l=this.y,u=this.z,p=this.w,s=p*n+l*i-u*d,y=p*d+u*n-t*i,c=p*i+t*d-l*n,a=-t*n-l*d-u*i;return f.x=s*p+a*-t+y*-u-c*-l,f.y=y*p+a*-l+c*-t-s*-u,f.z=c*p+a*-u+s*-l-y*-t,f},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},n.prototype.toEuler=function(e,f){f=f||"YZX";var n,o,d,i=this.x,t=this.y,l=this.z,u=this.w;switch(f){case"YZX":var p=i*t+l*u;if(p>.499&&(n=2*Math.atan2(i,u),o=Math.PI/2,d=0),-.499>p&&(n=-2*Math.atan2(i,u),o=-Math.PI/2,d=0),isNaN(n)){var s=i*i,y=t*t,c=l*l;n=Math.atan2(2*t*u-2*i*l,1-2*y-2*c),o=Math.asin(2*p),d=Math.atan2(2*i*u-2*t*l,1-2*s-2*c)}break;default:throw new Error("Euler order "+f+" not supported yet.")}e.y=n,e.z=o,e.x=d},n.prototype.setFromEuler=function(e,f,n,o){o=o||"XYZ";var d=Math.cos(e/2),i=Math.cos(f/2),t=Math.cos(n/2),l=Math.sin(e/2),u=Math.sin(f/2),p=Math.sin(n/2);return"XYZ"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t-l*u*p):"YXZ"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t+l*u*p):"ZXY"===o?(this.x=l*i*t-d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t-l*u*p):"ZYX"===o?(this.x=l*i*t-d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t+l*u*p):"YZX"===o?(this.x=l*i*t+d*u*p,this.y=d*u*t+l*i*p,this.z=d*i*p-l*u*t,this.w=d*i*t-l*u*p):"XZY"===o&&(this.x=l*i*t-d*u*p,this.y=d*u*t-l*i*p,this.z=d*i*p+l*u*t,this.w=d*i*t+l*u*p),this},n.prototype.clone=function(){return new n(this.x,this.y,this.z,this.w)}},{"./Vec3":30}],29:[function(e,f){function n(e){e=e||{},this.position=new o,e.position&&this.position.copy(e.position),this.quaternion=new d,e.quaternion&&this.quaternion.copy(e.quaternion)}var o=e("./Vec3"),d=e("./Quaternion");f.exports=n;var i=new d;n.pointToLocalFrame=function(e,f,n,d){var d=d||new o;return n.vsub(e,d),f.conjugate(i),i.vmult(d,d),d},n.prototype.pointToLocal=function(e,f){return n.pointToLocalFrame(this.position,this.quaternion,e,f)},n.pointToWorldFrame=function(e,f,n,d){var d=d||new o;return f.vmult(n,d),d.vadd(e,d),d},n.prototype.pointToWorld=function(e,f){return n.pointToWorldFrame(this.position,this.quaternion,e,f)},n.prototype.vectorToWorldFrame=function(e,f){var f=f||new o;return this.quaternion.vmult(e,f),f},n.vectorToWorldFrame=function(e,f,n){return e.vmult(f,n),n},n.vectorToLocalFrame=function(e,f,n,d){var d=d||new o;return f.w*=-1,f.vmult(n,d),f.w*=-1,d}},{"./Quaternion":28,"./Vec3":30}],30:[function(e,f){function n(e,f,n){this.x=e||0,this.y=f||0,this.z=n||0}f.exports=n;var o=e("./Mat3");n.ZERO=new n(0,0,0),n.UNIT_X=new n(1,0,0),n.UNIT_Y=new n(0,1,0),n.UNIT_Z=new n(0,0,1),n.prototype.cross=function(e,f){var o=e.x,d=e.y,i=e.z,t=this.x,l=this.y,u=this.z;return f=f||new n,f.x=l*i-u*d,f.y=u*o-t*i,f.z=t*d-l*o,f},n.prototype.set=function(e,f,n){return this.x=e,this.y=f,this.z=n,this},n.prototype.setZero=function(){this.x=this.y=this.z=0},n.prototype.vadd=function(e,f){return f?(f.x=e.x+this.x,f.y=e.y+this.y,f.z=e.z+this.z,void 0):new n(this.x+e.x,this.y+e.y,this.z+e.z)},n.prototype.vsub=function(e,f){return f?(f.x=this.x-e.x,f.y=this.y-e.y,f.z=this.z-e.z,void 0):new n(this.x-e.x,this.y-e.y,this.z-e.z)},n.prototype.crossmat=function(){return new o([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])},n.prototype.normalize=function(){var e=this.x,f=this.y,n=this.z,o=Math.sqrt(e*e+f*f+n*n);if(o>0){var d=1/o;this.x*=d,this.y*=d,this.z*=d}else this.x=0,this.y=0,this.z=0;return o},n.prototype.unit=function(e){e=e||new n;var f=this.x,o=this.y,d=this.z,i=Math.sqrt(f*f+o*o+d*d);return i>0?(i=1/i,e.x=f*i,e.y=o*i,e.z=d*i):(e.x=1,e.y=0,e.z=0),e},n.prototype.norm=function(){var e=this.x,f=this.y,n=this.z;return Math.sqrt(e*e+f*f+n*n)},n.prototype.length=n.prototype.norm,n.prototype.norm2=function(){return this.dot(this)},n.prototype.lengthSquared=n.prototype.norm2,n.prototype.distanceTo=function(e){var f=this.x,n=this.y,o=this.z,d=e.x,i=e.y,t=e.z;return Math.sqrt((d-f)*(d-f)+(i-n)*(i-n)+(t-o)*(t-o))},n.prototype.distanceSquared=function(e){var f=this.x,n=this.y,o=this.z,d=e.x,i=e.y,t=e.z;return(d-f)*(d-f)+(i-n)*(i-n)+(t-o)*(t-o)},n.prototype.mult=function(e,f){f=f||new n;var o=this.x,d=this.y,i=this.z;return f.x=e*o,f.y=e*d,f.z=e*i,f},n.prototype.scale=n.prototype.mult,n.prototype.dot=function(e){return this.x*e.x+this.y*e.y+this.z*e.z},n.prototype.isZero=function(){return 0===this.x&&0===this.y&&0===this.z},n.prototype.negate=function(e){return e=e||new n,e.x=-this.x,e.y=-this.y,e.z=-this.z,e};var d=new n,i=new n;n.prototype.tangents=function(e,f){var n=this.norm();if(n>0){var o=d,t=1/n;o.set(this.x*t,this.y*t,this.z*t);var l=i;Math.abs(o.x)<.9?(l.set(1,0,0),o.cross(l,e)):(l.set(0,1,0),o.cross(l,e)),o.cross(e,f)}else e.set(1,0,0),f.set(0,1,0)},n.prototype.toString=function(){return this.x+","+this.y+","+this.z},n.prototype.toArray=function(){return[this.x,this.y,this.z]},n.prototype.copy=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},n.prototype.lerp=function(e,f,n){var o=this.x,d=this.y,i=this.z;n.x=o+(e.x-o)*f,n.y=d+(e.y-d)*f,n.z=i+(e.z-i)*f},n.prototype.almostEquals=function(e,f){return void 0===f&&(f=1e-6),Math.abs(this.x-e.x)>f||Math.abs(this.y-e.y)>f||Math.abs(this.z-e.z)>f?!1:!0},n.prototype.almostZero=function(e){return void 0===e&&(e=1e-6),Math.abs(this.x)>e||Math.abs(this.y)>e||Math.abs(this.z)>e?!1:!0};var t=new n;n.prototype.isAntiparallelTo=function(e,f){return this.negate(t),t.almostEquals(e,f)},n.prototype.clone=function(){return new n(this.x,this.y,this.z)}},{"./Mat3":27}],31:[function(e,f){function n(e){e=e||{},o.apply(this),this.id=n.idCounter++,this.world=null,this.preStep=null,this.postStep=null,this.vlambda=new d,this.collisionFilterGroup="number"==typeof e.collisionFilterGroup?e.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof e.collisionFilterMask?e.collisionFilterMask:1,this.collisionResponse=!0,this.position=new d,e.position&&this.position.copy(e.position),this.previousPosition=new d,this.initPosition=new d,this.velocity=new d,e.velocity&&this.velocity.copy(e.velocity),this.initVelocity=new d,this.force=new d;var f="number"==typeof e.mass?e.mass:0;this.mass=f,this.invMass=f>0?1/f:0,this.material=e.material||null,this.linearDamping="number"==typeof e.linearDamping?e.linearDamping:.01,this.type=0>=f?n.STATIC:n.DYNAMIC,typeof e.type==typeof n.STATIC&&(this.type=e.type),this.allowSleep="undefined"!=typeof e.allowSleep?e.allowSleep:!0,this.sleepState=0,this.sleepSpeedLimit="undefined"!=typeof e.sleepSpeedLimit?e.sleepSpeedLimit:.1,this.sleepTimeLimit="undefined"!=typeof e.sleepTimeLimit?e.sleepTimeLimit:1,this.timeLastSleepy=0,this._wakeUpAfterNarrowphase=!1,this.torque=new d,this.quaternion=new t,e.quaternion&&this.quaternion.copy(e.quaternion),this.initQuaternion=new t,this.angularVelocity=new d,e.angularVelocity&&this.angularVelocity.copy(e.angularVelocity),this.initAngularVelocity=new d,this.interpolatedPosition=new d,this.interpolatedQuaternion=new t,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new d,this.invInertia=new d,this.invInertiaWorld=new i,this.invMassSolve=0,this.invInertiaSolve=new d,this.invInertiaWorldSolve=new i,this.fixedRotation="undefined"!=typeof e.fixedRotation?e.fixedRotation:!1,this.angularDamping="undefined"!=typeof e.angularDamping?e.angularDamping:.01,this.aabb=new l,this.aabbNeedsUpdate=!0,this.wlambda=new d,e.shape&&this.addShape(e.shape),this.updateMassProperties()}f.exports=n;var o=e("../utils/EventTarget"),d=(e("../shapes/Shape"),e("../math/Vec3")),i=e("../math/Mat3"),t=e("../math/Quaternion"),l=(e("../material/Material"),e("../collision/AABB")),u=e("../shapes/Box");n.prototype=new o,n.prototype.constructor=n,n.DYNAMIC=1,n.STATIC=2,n.KINEMATIC=4,n.AWAKE=0,n.SLEEPY=1,n.SLEEPING=2,n.idCounter=0,n.prototype.wakeUp=function(){var e=this.sleepState;this.sleepState=0,e===n.SLEEPING&&this.dispatchEvent({type:"wakeup"})},n.prototype.sleep=function(){this.sleepState=n.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0)},n.sleepyEvent={type:"sleepy"},n.sleepEvent={type:"sleep"},n.prototype.sleepTick=function(e){if(this.allowSleep){var f=this.sleepState,o=this.velocity.norm2()+this.angularVelocity.norm2(),d=Math.pow(this.sleepSpeedLimit,2);f===n.AWAKE&&d>o?(this.sleepState=n.SLEEPY,this.timeLastSleepy=e,this.dispatchEvent(n.sleepyEvent)):f===n.SLEEPY&&o>d?this.wakeUp():f===n.SLEEPY&&e-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(n.sleepEvent))}},n.prototype.updateSolveMassProperties=function(){this.sleepState===n.SLEEPING||this.type===n.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))},n.prototype.pointToLocalFrame=function(e,f){var f=f||new d;return e.vsub(this.position,f),this.quaternion.conjugate().vmult(f,f),f},n.prototype.vectorToLocalFrame=function(e,f){var f=f||new d;return this.quaternion.conjugate().vmult(e,f),f},n.prototype.pointToWorldFrame=function(e,f){var f=f||new d;return this.quaternion.vmult(e,f),f.vadd(this.position,f),f},n.prototype.vectorToWorldFrame=function(e,f){var f=f||new d;return this.quaternion.vmult(e,f),f};var p=new d,s=new t;n.prototype.addShape=function(e,f,n){var o=new d,i=new t;return f&&o.copy(f),n&&i.copy(n),this.shapes.push(e),this.shapeOffsets.push(o),this.shapeOrientations.push(i),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,this},n.prototype.updateBoundingRadius=function(){for(var e=this.shapes,f=this.shapeOffsets,n=e.length,o=0,d=0;d!==n;d++){var i=e[d];i.updateBoundingSphereRadius();var t=f[d].norm(),l=i.boundingSphereRadius;t+l>o&&(o=t+l)}this.boundingRadius=o};var y=new l;n.prototype.computeAABB=function(){for(var e=this.shapes,f=this.shapeOffsets,n=this.shapeOrientations,o=e.length,d=p,i=s,t=this.quaternion,l=this.aabb,u=y,c=0;c!==o;c++){var a=e[c];n[c].mult(t,i),i.vmult(f[c],d),d.vadd(this.position,d),a.calculateWorldAABB(d,i,u.lowerBound,u.upperBound),0===c?l.copy(u):l.extend(u)}this.aabbNeedsUpdate=!1};{var c=new i,a=new i;new i}n.prototype.updateInertiaWorld=function(e){var f=this.invInertia;if(f.x!==f.y||f.y!==f.z||e){var n=c,o=a;n.setRotationFromQuaternion(this.quaternion),n.transpose(o),n.scale(f,n),n.mmult(o,this.invInertiaWorld)}else;};var r=new d,w=new d;n.prototype.applyForce=function(e,f){if(this.type===n.DYNAMIC){var o=r;f.vsub(this.position,o);var d=w;o.cross(e,d),this.force.vadd(e,this.force),this.torque.vadd(d,this.torque)}};var b=new d,m=new d;n.prototype.applyLocalForce=function(e,f){if(this.type===n.DYNAMIC){var o=b,d=m;this.vectorToWorldFrame(e,o),this.pointToWorldFrame(f,d),this.applyForce(o,d)}};var N=new d,g=new d,x=new d;n.prototype.applyImpulse=function(e,f){if(this.type===n.DYNAMIC){var o=N;f.vsub(this.position,o);var d=g;d.copy(e),d.mult(this.invMass,d),this.velocity.vadd(d,this.velocity);var i=x;o.cross(e,i),this.invInertiaWorld.vmult(i,i),this.angularVelocity.vadd(i,this.angularVelocity)}};var j=new d,v=new d;n.prototype.applyLocalImpulse=function(e,f){if(this.type===n.DYNAMIC){var o=j,d=v;this.vectorToWorldFrame(e,o),this.pointToWorldFrame(f,d),this.applyImpulse(o,d)}};var A=new d;n.prototype.updateMassProperties=function(){var e=A;this.invMass=this.mass>0?1/this.mass:0;var f=this.inertia,n=this.fixedRotation;this.computeAABB(),e.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),u.calculateInertia(e,this.mass,f),this.invInertia.set(f.x>0&&!n?1/f.x:0,f.y>0&&!n?1/f.y:0,f.z>0&&!n?1/f.z:0),this.updateInertiaWorld(!0)},n.prototype.getVelocityAtWorldPoint=function(e,f){var n=new d;return e.vsub(this.position,n),this.angularVelocity.cross(n,f),this.velocity.vadd(f,f),f}},{"../collision/AABB":3,"../material/Material":25,"../math/Mat3":27,"../math/Quaternion":28,"../math/Vec3":30,"../shapes/Box":37,"../shapes/Shape":43,"../utils/EventTarget":49}],32:[function(e,f){function n(e){this.chassisBody=e.chassisBody,this.wheelInfos=[],this.sliding=!1,this.world=null,this.indexRightAxis="undefined"!=typeof e.indexRightAxis?e.indexRightAxis:1,this.indexForwardAxis="undefined"!=typeof e.indexForwardAxis?e.indexForwardAxis:0,this.indexUpAxis="undefined"!=typeof e.indexUpAxis?e.indexUpAxis:2}function o(e,f,n,o,i){var t=0,l=n,u=x,p=j,s=v;e.getVelocityAtWorldPoint(l,u),f.getVelocityAtWorldPoint(l,p),u.vsub(p,s);var y=o.dot(s),c=d(e,n,o),a=d(f,n,o),r=1,w=r/(c+a);return t=-y*w,t>i&&(t=i),-i>t&&(t=-i),t}function d(e,f,n){var o=A,d=C,i=O,t=h;return f.vsub(e.position,o),o.cross(n,d),e.invInertiaWorld.vmult(d,t),t.cross(o,i),e.invMass+n.dot(i)}function i(e,f,n,o,d,i){var t=d.norm2();if(t>1.1)return 0;var l=k,u=q,p=z;e.getVelocityAtWorldPoint(f,l),n.getVelocityAtWorldPoint(o,u),l.vsub(u,p);var s=d.dot(p),y=.2,c=1/(e.invMass+n.invMass),i=-y*s*c;return i}var t=(e("./Body"),e("../math/Vec3")),l=e("../math/Quaternion"),u=(e("../collision/RaycastResult"),e("../collision/Ray")),p=e("../objects/WheelInfo");f.exports=n;{var s=(new t,new t,new t,new t),y=new t,c=new t;new u}n.prototype.addWheel=function(e){e=e||{};var f=new p(e),n=this.wheelInfos.length;return this.wheelInfos.push(f),n},n.prototype.setSteeringValue=function(e,f){var n=this.wheelInfos[f];n.steering=e};new t;n.prototype.applyEngineForce=function(e,f){this.wheelInfos[f].engineForce=e},n.prototype.setBrake=function(e,f){this.wheelInfos[f].brake=e},n.prototype.addToWorld=function(e){this.constraints;e.add(this.chassisBody);var f=this;this.preStepCallback=function(){f.updateVehicle(e.dt)},e.addEventListener("preStep",this.preStepCallback),this.world=e},n.prototype.getVehicleAxisWorld=function(e,f){f.set(0===e?1:0,1===e?1:0,2===e?1:0),this.chassisBody.vectorToWorldFrame(f,f)},n.prototype.updateVehicle=function(e){for(var f=this.wheelInfos,n=f.length,o=this.chassisBody,d=0;n>d;d++)this.updateWheelTransform(d);this.currentVehicleSpeedKmHour=3.6*o.velocity.norm();var i=new t;this.getVehicleAxisWorld(this.indexForwardAxis,i),i.dot(o.velocity)<0&&(this.currentVehicleSpeedKmHour*=-1);for(var d=0;n>d;d++)this.castRay(f[d]);this.updateSuspension(e);for(var l=new t,u=new t,d=0;n>d;d++){var p=f[d],s=p.suspensionForce;s>p.maxSuspensionForce&&(s=p.maxSuspensionForce),p.raycastResult.hitNormalWorld.scale(s*e,l),p.raycastResult.hitPointWorld.vsub(o.position,u),o.applyImpulse(l,p.raycastResult.hitPointWorld)}this.updateFriction(e);var y=new t,c=new t,a=new t;for(d=0;n>d;d++){var p=f[d];o.getVelocityAtWorldPoint(p.chassisConnectionPointWorld,a);var r=1;switch(this.indexUpAxis){case 1:r=-1}if(p.isInContact){this.getVehicleAxisWorld(this.indexForwardAxis,c);var w=c.dot(p.raycastResult.hitNormalWorld);p.raycastResult.hitNormalWorld.scale(w,y),c.vsub(y,c);var b=c.dot(a);p.deltaRotation=r*b*e/p.radius}!p.sliding&&p.isInContact||0===p.engineForce||!p.useCustomSlidingRotationalSpeed||(p.deltaRotation=(p.engineForce>0?1:-1)*p.customSlidingRotationalSpeed*e),Math.abs(p.brake)>Math.abs(p.engineForce)&&(p.deltaRotation=0),p.rotation+=p.deltaRotation,p.deltaRotation*=.99}},n.prototype.updateSuspension=function(){for(var e=this.chassisBody,f=e.mass,n=this.wheelInfos,o=n.length,d=0;o>d;d++){var i=n[d];if(i.isInContact){var t,l=i.suspensionRestLength,u=i.suspensionLength,p=l-u;t=i.suspensionStiffness*p*i.clippedInvContactDotSuspension;var s,y=i.suspensionRelativeVelocity;s=0>y?i.dampingCompression:i.dampingRelaxation,t-=s*y,i.suspensionForce=t*f,i.suspensionForce<0&&(i.suspensionForce=0)}else i.suspensionForce=0}},n.prototype.removeFromWorld=function(e){this.constraints;e.remove(this.chassisBody),e.removeEventListener("preStep",this.preStepCallback),this.world=null};var a=new t,r=new t;n.prototype.castRay=function(e){var f=a,n=r;this.updateWheelTransformWorld(e);var o=this.chassisBody,d=-1,i=e.suspensionRestLength+e.radius;e.directionWorld.scale(i,f);var l=e.chassisConnectionPointWorld;l.vadd(f,n);var u=e.raycastResult;u.reset();var p=o.collisionResponse;o.collisionResponse=!1,this.world.rayTest(l,n,u),o.collisionResponse=p;var s=u.body;if(e.raycastResult.groundObject=0,s){d=u.distance,e.raycastResult.hitNormalWorld=u.hitNormalWorld,e.isInContact=!0;var y=u.distance;e.suspensionLength=y-e.radius;var c=e.suspensionRestLength-e.maxSuspensionTravel,w=e.suspensionRestLength+e.maxSuspensionTravel;e.suspensionLengthw&&(e.suspensionLength=w,e.raycastResult.reset());var b=e.raycastResult.hitNormalWorld.dot(e.directionWorld),m=new t;o.getVelocityAtWorldPoint(e.raycastResult.hitPointWorld,m);var N=e.raycastResult.hitNormalWorld.dot(m);if(b>=-.1)e.suspensionRelativeVelocity=0,e.clippedInvContactDotSuspension=10;else{var g=-1/b;e.suspensionRelativeVelocity=N*g,e.clippedInvContactDotSuspension=g}}else e.suspensionLength=e.suspensionRestLength+0*e.maxSuspensionTravel,e.suspensionRelativeVelocity=0,e.directionWorld.scale(-1,e.raycastResult.hitNormalWorld),e.clippedInvContactDotSuspension=1;return d},n.prototype.updateWheelTransformWorld=function(e){e.isInContact=!1;var f=this.chassisBody;f.pointToWorldFrame(e.chassisConnectionPointLocal,e.chassisConnectionPointWorld),f.vectorToWorldFrame(e.directionLocal,e.directionWorld),f.vectorToWorldFrame(e.axleLocal,e.axleWorld)},n.prototype.updateWheelTransform=function(e){var f=s,n=y,o=c,d=this.wheelInfos[e];this.updateWheelTransformWorld(d),d.directionLocal.scale(-1,f),n.copy(d.axleLocal),f.cross(n,o),o.normalize(),n.normalize();var i=d.steering,t=new l;t.setFromAxisAngle(f,i);var u=new l;u.setFromAxisAngle(n,d.rotation);var p=d.worldTransform.quaternion;this.chassisBody.quaternion.mult(t,p),p.mult(u,p),p.normalize();var a=d.worldTransform.position;a.copy(d.directionWorld),a.scale(d.suspensionLength,a),a.vadd(d.chassisConnectionPointWorld,a)};var w=[new t(1,0,0),new t(0,1,0),new t(0,0,1)];n.prototype.getWheelTransformWorld=function(e){return this.wheelInfos[e].worldTransform};var b=new t,m=[],N=[],g=1;n.prototype.updateFriction=function(e){for(var f=b,n=this.wheelInfos,d=n.length,l=this.chassisBody,u=N,p=m,s=0,y=0;d>y;y++){var c=n[y],a=c.raycastResult.body;a&&s++,c.sideImpulse=0,c.forwardImpulse=0,u[y]||(u[y]=new t),p[y]||(p[y]=new t)}for(var y=0;d>y;y++){var c=n[y],a=c.raycastResult.body;if(a){var r=p[y],x=this.getWheelTransformWorld(y);x.vectorToWorldFrame(w[this.indexRightAxis],r);var j=c.raycastResult.hitNormalWorld,v=r.dot(j);j.scale(v,f),r.vsub(f,r),r.normalize(),j.cross(r,u[y]),u[y].normalize(),c.sideImpulse=i(l,c.raycastResult.hitPointWorld,a,c.raycastResult.hitPointWorld,r),c.sideImpulse*=g}}var A=1,C=.5;this.sliding=!1;for(var y=0;d>y;y++){var c=n[y],a=c.raycastResult.body,O=0;if(c.slipInfo=1,a){var h=0,k=c.brake?c.brake:h;O=o(l,a,c.raycastResult.hitPointWorld,u[y],k),O+=c.engineForce*e;var q=k/O;c.slipInfo*=q}if(c.forwardImpulse=0,c.skidInfo=1,a){c.skidInfo=1;var z=c.suspensionForce*e*c.frictionSlip,B=z,D=z*B;c.forwardImpulse=O;var E=c.forwardImpulse*C,F=c.sideImpulse*A,G=E*E+F*F;if(c.sliding=!1,G>D){this.sliding=!0,c.sliding=!0;var q=z/Math.sqrt(G);c.skidInfo*=q}}}if(this.sliding)for(var y=0;d>y;y++){var c=n[y];0!==c.sideImpulse&&c.skidInfo<1&&(c.forwardImpulse*=c.skidInfo,c.sideImpulse*=c.skidInfo)}for(var y=0;d>y;y++){var c=n[y],H=new t;if(H.copy(c.raycastResult.hitPointWorld),0!==c.forwardImpulse){var I=new t;u[y].scale(c.forwardImpulse,I),l.applyImpulse(I,H)}if(0!==c.sideImpulse){var a=c.raycastResult.body,J=new t;J.copy(c.raycastResult.hitPointWorld);var K=new t;p[y].scale(c.sideImpulse,K),l.pointToLocalFrame(H,H),H["xyz"[this.indexUpAxis]]*=c.rollInfluence,l.pointToWorldFrame(H,H),l.applyImpulse(K,H),K.scale(-1,K),a.applyImpulse(K,J)}}};var x=new t,j=new t,v=new t,A=new t,C=new t,O=new t,h=new t,k=new t,q=new t,z=new t},{"../collision/Ray":9,"../collision/RaycastResult":10,"../math/Quaternion":28,"../math/Vec3":30,"../objects/WheelInfo":36,"./Body":31}],33:[function(e,f){function n(e){if(this.wheelBodies=[],this.coordinateSystem="undefined"==typeof e.coordinateSystem?new t(1,2,3):e.coordinateSystem.clone(),this.chassisBody=e.chassisBody,!this.chassisBody){var f=new i(new t(5,2,.5));this.chassisBody=new o(1,f)}this.constraints=[],this.wheelAxes=[],this.wheelForces=[]}var o=e("./Body"),d=e("../shapes/Sphere"),i=e("../shapes/Box"),t=e("../math/Vec3"),l=e("../constraints/HingeConstraint");f.exports=n,n.prototype.addWheel=function(e){e=e||{};var f=e.body;f||(f=new o(1,new d(1.2))),this.wheelBodies.push(f),this.wheelForces.push(0);var n=(new t,"undefined"!=typeof e.position?e.position.clone():new t),i=new t;this.chassisBody.pointToWorldFrame(n,i),f.position.set(i.x,i.y,i.z);var u="undefined"!=typeof e.axis?e.axis.clone():new t(0,1,0);this.wheelAxes.push(u);var p=new l(this.chassisBody,f,{pivotA:n,axisA:u,pivotB:t.ZERO,axisB:u,collideConnected:!1});return this.constraints.push(p),this.wheelBodies.length-1},n.prototype.setSteeringValue=function(e,f){var n=this.wheelAxes[f],o=Math.cos(e),d=Math.sin(e),i=n.x,t=n.y;this.constraints[f].axisA.set(o*i-d*t,d*i+o*t,0)},n.prototype.setMotorSpeed=function(e,f){var n=this.constraints[f];n.enableMotor(),n.motorTargetVelocity=e},n.prototype.disableMotor=function(e){var f=this.constraints[e]; +f.disableMotor()};var u=new t;n.prototype.setWheelForce=function(e,f){this.wheelForces[f]=e},n.prototype.applyWheelForce=function(e,f){var n=this.wheelAxes[f],o=this.wheelBodies[f],d=o.torque;n.scale(e,u),o.vectorToWorldFrame(u,u),d.vadd(u,d)},n.prototype.addToWorld=function(e){for(var f=this.constraints,n=this.wheelBodies.concat([this.chassisBody]),o=0;othis.particles.length&&this.neighbors.pop())};var d=new o;n.prototype.getNeighbors=function(e,f){for(var n=this.particles.length,o=e.id,i=this.smoothingRadius*this.smoothingRadius,t=d,l=0;l!==n;l++){var u=this.particles[l];u.position.vsub(e.position,t),o!==u.id&&t.norm2()=-.1)this.suspensionRelativeVelocity=0,this.clippedInvContactDotSuspension=10;else{var d=-1/n;this.suspensionRelativeVelocity=o*d,this.clippedInvContactDotSuspension=d}}else f.suspensionLength=this.suspensionRestLength,this.suspensionRelativeVelocity=0,f.directionWorld.scale(-1,f.hitNormalWorld),this.clippedInvContactDotSuspension=1}},{"../collision/RaycastResult":10,"../math/Transform":29,"../math/Vec3":30,"../utils/Utils":53}],37:[function(e,f){function n(e){o.call(this),this.type=o.types.BOX,this.halfExtents=e,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3"),i=e("./ConvexPolyhedron");n.prototype=new o,n.prototype.constructor=n,n.prototype.updateConvexPolyhedronRepresentation=function(){var e=this.halfExtents.x,f=this.halfExtents.y,n=this.halfExtents.z,o=d,t=[new o(-e,-f,-n),new o(e,-f,-n),new o(e,f,-n),new o(-e,f,-n),new o(-e,-f,n),new o(e,-f,n),new o(e,f,n),new o(-e,f,n)],l=[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],u=([new o(0,0,1),new o(0,1,0),new o(1,0,0)],new i(t,l));this.convexPolyhedronRepresentation=u,u.material=this.material},n.prototype.calculateLocalInertia=function(e,f){return f=f||new d,n.calculateInertia(this.halfExtents,e,f),f},n.calculateInertia=function(e,f,n){var o=e;n.x=1/12*f*(2*o.y*2*o.y+2*o.z*2*o.z),n.y=1/12*f*(2*o.x*2*o.x+2*o.z*2*o.z),n.z=1/12*f*(2*o.y*2*o.y+2*o.x*2*o.x)},n.prototype.getSideNormals=function(e,f){var n=e,o=this.halfExtents;if(n[0].set(o.x,0,0),n[1].set(0,o.y,0),n[2].set(0,0,o.z),n[3].set(-o.x,0,0),n[4].set(0,-o.y,0),n[5].set(0,0,-o.z),void 0!==f)for(var d=0;d!==n.length;d++)f.vmult(n[d],n[d]);return n},n.prototype.volume=function(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.halfExtents.norm()};{var t=new d;new d}n.prototype.forEachWorldCorner=function(e,f,n){for(var o=this.halfExtents,d=[[o.x,o.y,o.z],[-o.x,o.y,o.z],[-o.x,-o.y,o.z],[-o.x,-o.y,-o.z],[o.x,-o.y,-o.z],[o.x,o.y,-o.z],[-o.x,o.y,-o.z],[o.x,-o.y,o.z]],i=0;it;t++){var i=l[t];f.vmult(i,i),e.vadd(i,i);var u=i.x,p=i.y,s=i.z;u>o.x&&(o.x=u),p>o.y&&(o.y=p),s>o.z&&(o.z=s),ua&&(a=w,c=r)}for(var b=[],m=n.faces[c],N=m.length,g=0;N>g;g++){var x=n.vertices[m[g]],j=new d;j.copy(x),i.vmult(j,j),o.vadd(j,j),b.push(j)}c>=0&&this.clipFaceAgainstHull(t,e,f,b,l,u,s)};var s=new d,y=new d,c=new d,a=new d,r=new d,w=new d;n.prototype.findSeparatingAxis=function(e,f,n,o,d,i,t,l){var u=s,p=y,b=c,m=a,N=r,g=w,x=Number.MAX_VALUE,j=this,v=0;if(j.uniqueAxes)for(var A=0;A!==j.uniqueAxes.length;A++){n.vmult(j.uniqueAxes[A],u);var C=j.testSepAxis(u,e,f,n,o,d);if(C===!1)return!1;x>C&&(x=C,i.copy(u))}else for(var O=t?t.length:j.faces.length,A=0;O>A;A++){var h=t?t[A]:A;u.copy(j.faceNormals[h]),n.vmult(u,u);var C=j.testSepAxis(u,e,f,n,o,d);if(C===!1)return!1;x>C&&(x=C,i.copy(u))}if(e.uniqueAxes)for(var A=0;A!==e.uniqueAxes.length;A++){d.vmult(e.uniqueAxes[A],p),v++;var C=j.testSepAxis(p,e,f,n,o,d);if(C===!1)return!1;x>C&&(x=C,i.copy(p))}else for(var k=l?l.length:e.faces.length,A=0;k>A;A++){var h=l?l[A]:A;p.copy(e.faceNormals[h]),d.vmult(p,p),v++;var C=j.testSepAxis(p,e,f,n,o,d);if(C===!1)return!1;x>C&&(x=C,i.copy(p))}for(var q=0;q!==j.uniqueEdges.length;q++){n.vmult(j.uniqueEdges[q],m);for(var z=0;z!==e.uniqueEdges.length;z++)if(d.vmult(e.uniqueEdges[z],N),m.cross(N,g),!g.almostZero()){g.normalize();var B=j.testSepAxis(g,e,f,n,o,d);if(B===!1)return!1;x>B&&(x=B,i.copy(g))}}return o.vsub(f,b),b.dot(i)>0&&i.negate(i),!0};var b=[],m=[];n.prototype.testSepAxis=function(e,f,o,d,i,t){var l=this;n.project(l,e,o,d,b),n.project(f,e,i,t,m);var u=b[0],p=b[1],s=m[0],y=m[1];if(y>u||p>s)return!1;var c=u-y,a=s-p,r=a>c?c:a;return r};var N=new d,g=new d;n.prototype.calculateLocalInertia=function(e,f){this.computeLocalAABB(N,g);var n=g.x-N.x,o=g.y-N.y,d=g.z-N.z;f.x=1/12*e*(2*o*2*o+2*d*2*d),f.y=1/12*e*(2*n*2*n+2*d*2*d),f.z=1/12*e*(2*o*2*o+2*n*2*n)},n.prototype.getPlaneConstantOfFace=function(e){var f=this.faces[e],n=this.faceNormals[e],o=this.vertices[f[0]],d=-n.dot(o);return d};var x=new d,j=new d,v=new d,A=new d,C=new d,O=new d,h=new d,k=new d;n.prototype.clipFaceAgainstHull=function(e,f,n,o,d,i,t){for(var l=x,u=j,p=v,s=A,y=C,c=O,a=h,r=k,w=this,b=[],m=o,N=b,g=-1,q=Number.MAX_VALUE,z=0;zB&&(q=B,g=z)}if(!(0>g)){var D=w.faces[g];D.connectedFaces=[];for(var E=0;EH;H++){var I=w.vertices[D[H]],J=w.vertices[D[(H+1)%G]];I.vsub(J,u),p.copy(u),n.vmult(p,p),f.vadd(p,p),s.copy(this.faceNormals[g]),n.vmult(s,s),f.vadd(s,s),p.cross(s,y),y.negate(y),c.copy(I),n.vmult(c,c),f.vadd(c,c);var K,L=(-c.dot(y),D.connectedFaces[H]);a.copy(this.faceNormals[L]);var M=this.getPlaneConstantOfFace(L);r.copy(a),n.vmult(r,r);var K=M-r.dot(f);for(this.clipFaceAgainstPlane(m,N,r,K);m.length;)m.shift();for(;N.length;)m.push(N.shift())}a.copy(this.faceNormals[g]);var M=this.getPlaneConstantOfFace(g);r.copy(a),n.vmult(r,r);for(var K=M-r.dot(f),E=0;E=P&&(console.log("clamped: depth="+P+" to minDist="+(d+"")),P=d),i>=P){var Q=m[E];if(0>=P){var R={point:Q,normal:r,depth:P};t.push(R)}}}}},n.prototype.clipFaceAgainstPlane=function(e,f,n,o){var i,t,l=e.length;if(2>l)return f;var u=e[e.length-1],p=e[0];i=n.dot(u)+o;for(var s=0;l>s;s++){if(p=e[s],t=n.dot(p)+o,0>i)if(0>t){var y=new d;y.copy(p),f.push(y)}else{var y=new d;u.lerp(p,i/(i-t),y),f.push(y)}else if(0>t){var y=new d;u.lerp(p,i/(i-t),y),f.push(y),f.push(p)}u=p,i=t}return f},n.prototype.computeWorldVertices=function(e,f){for(var n=this.vertices.length;this.worldVertices.lengthd;d++){var i=o[d];i.xf.x&&(f.x=i.x),i.yf.y&&(f.y=i.y),i.zf.z&&(f.z=i.z)}},n.prototype.computeWorldFaceNormals=function(e){for(var f=this.faceNormals.length;this.worldFaceNormals.lengthe&&(e=d)}this.boundingSphereRadius=Math.sqrt(e)};var q=new d;n.prototype.calculateWorldAABB=function(e,f,n,o){for(var d,i,t,l,u,p,s=this.vertices.length,y=this.vertices,c=0;s>c;c++){q.copy(y[c]),f.vmult(q,q),e.vadd(q,q);var a=q;a.xl||void 0===l)&&(l=a.x),a.yu||void 0===u)&&(u=a.y),a.zp||void 0===p)&&(p=a.z)}n.set(d,i,t),o.set(l,u,p)},n.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},n.prototype.getAveragePointLocal=function(e){e=e||new d;for(var f=this.vertices.length,n=this.vertices,o=0;f>o;o++)e.vadd(n[o],e);return e.mult(1/f,e),e},n.prototype.transformAllPoints=function(e,f){var n=this.vertices.length,o=this.vertices;if(f){for(var d=0;n>d;d++){var i=o[d];f.vmult(i,i)}for(var d=0;dd;d++){var i=o[d];i.vadd(e,i)}};var z=new d,B=new d,D=new d;n.prototype.pointIsInside=function(e){var f=this.vertices.length,n=this.vertices,o=this.faces,d=this.faceNormals,i=null,t=this.faces.length,l=z;this.getAveragePointLocal(l);for(var u=0;t>u;u++){var f=(this.faces[u].length,d[u]),p=n[o[u][0]],s=B;e.vsub(p,s);var y=f.dot(s),c=D;l.vsub(p,c);var a=f.dot(c);if(0>y&&a>0||y>0&&0>a)return!1}return i?1:-1};var E=(new d,new d),F=new d;n.project=function(e,f,n,o,d){var t=e.vertices.length,l=E,u=0,p=0,s=F,y=e.vertices;s.setZero(),i.vectorToLocalFrame(n,o,f,l),i.pointToLocalFrame(n,o,s,s);var c=s.dot(l);p=u=y[0].dot(l);for(var a=1;t>a;a++){var r=y[a].dot(l);r>u&&(u=r),p>r&&(p=r)}if(p-=c,u-=c,p>u){var w=p;p=u,u=w}d[0]=u,d[1]=p}},{"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"./Shape":43}],39:[function(e,f){function n(e,f,n,t){var l=t,u=[],p=[],s=[],y=[],c=[],a=Math.cos,r=Math.sin;u.push(new d(f*a(0),f*r(0),.5*-n)),y.push(0),u.push(new d(e*a(0),e*r(0),.5*n)),c.push(1);for(var w=0;l>w;w++){var b=2*Math.PI/l*(w+1),m=2*Math.PI/l*(w+.5);l-1>w?(u.push(new d(f*a(b),f*r(b),.5*-n)),y.push(2*w+2),u.push(new d(e*a(b),e*r(b),.5*n)),c.push(2*w+3),s.push([2*w+2,2*w+3,2*w+1,2*w])):s.push([0,1,2*w+1,2*w]),(l%2===1||l/2>w)&&p.push(new d(a(m),r(m),0))}s.push(c),p.push(new d(0,0,1));for(var N=[],w=0;wd&&(f=d)}this.minValue=f},n.prototype.updateMaxValue=function(){for(var e=this.data,f=e[0][0],n=0;n!==e.length;n++)for(var o=0;o!==e[n].length;o++){var d=e[n][o];d>f&&(f=d)}this.maxValue=f},n.prototype.setHeightValueAtIndex=function(e,f,n){var o=this.data;o[e][f]=n,this.clearCachedConvexTrianglePillar(e,f,!1),e>0&&(this.clearCachedConvexTrianglePillar(e-1,f,!0),this.clearCachedConvexTrianglePillar(e-1,f,!1)),f>0&&(this.clearCachedConvexTrianglePillar(e,f-1,!0),this.clearCachedConvexTrianglePillar(e,f-1,!1)),f>0&&e>0&&this.clearCachedConvexTrianglePillar(e-1,f-1,!0)},n.prototype.getRectMinMax=function(e,f,n,o,d){d=d||[];for(var i=this.data,t=this.minValue,l=e;n>=l;l++)for(var u=f;o>=u;u++){var p=i[l][u];p>t&&(t=p)}d[0]=this.minValue,d[1]=t},n.prototype.getIndexOfPosition=function(e,f,n,o){var d=this.elementSize,i=this.data,t=Math.floor(e/d),l=Math.floor(f/d);return n[0]=t,n[1]=l,o&&(0>t&&(t=0),0>l&&(l=0),t>=i.length-1&&(t=i.length-1),l>=i[0].length-1&&(l=i[0].length-1)),0>t||0>l||t>=i.length-1||l>=i[0].length-1?!1:!0},n.prototype.getHeightAt=function(e,f,n){var o=[];this.getIndexOfPosition(e,f,o,n);var d=[];return this.getRectMinMax(o[0],o[1]+1,o[0],o[1]+1,d),(d[0]+d[1])/2},n.prototype.getCacheConvexTrianglePillarKey=function(e,f,n){return e+"_"+f+"_"+(n?1:0)},n.prototype.getCachedConvexTrianglePillar=function(e,f,n){return this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]},n.prototype.setCachedConvexTrianglePillar=function(e,f,n,o,d){this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]={convex:o,offset:d}},n.prototype.clearCachedConvexTrianglePillar=function(e,f,n){delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(e,f,n)]},n.prototype.getConvexTrianglePillar=function(e,f,n){var o=this.pillarConvex,t=this.pillarOffset;if(this.cacheEnabled){var l=this.getCachedConvexTrianglePillar(e,f,n);if(l)return this.pillarConvex=l.convex,void(this.pillarOffset=l.offset);o=new d,t=new i,this.pillarConvex=o,this.pillarOffset=t}var l=this.data,u=this.elementSize,p=o.faces;o.vertices.length=6;for(var s=0;6>s;s++)o.vertices[s]||(o.vertices[s]=new i);p.length=5;for(var s=0;5>s;s++)p[s]||(p[s]=[]);var y=o.vertices,c=(Math.min(l[e][f],l[e+1][f],l[e][f+1],l[e+1][f+1])-this.minValue)/2+this.minValue;n?(t.set((e+.75)*u,(f+.75)*u,c),y[0].set(.25*u,.25*u,l[e+1][f+1]-c),y[1].set(-.75*u,.25*u,l[e][f+1]-c),y[2].set(.25*u,-.75*u,l[e+1][f]-c),y[3].set(.25*u,.25*u,-c-1),y[4].set(-.75*u,.25*u,-c-1),y[5].set(.25*u,-.75*u,-c-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=2,p[2][1]=5,p[2][2]=3,p[2][3]=0,p[3][0]=3,p[3][1]=4,p[3][2]=1,p[3][3]=0,p[4][0]=1,p[4][1]=4,p[4][2]=5,p[4][3]=2):(t.set((e+.25)*u,(f+.25)*u,c),y[0].set(-.25*u,-.25*u,l[e][f]-c),y[1].set(.75*u,-.25*u,l[e+1][f]-c),y[2].set(-.25*u,.75*u,l[e][f+1]-c),y[3].set(-.25*u,-.25*u,-c-1),y[4].set(.75*u,-.25*u,-c-1),y[5].set(-.25*u,.75*u,-c-1),p[0][0]=0,p[0][1]=1,p[0][2]=2,p[1][0]=5,p[1][1]=4,p[1][2]=3,p[2][0]=0,p[2][1]=2,p[2][2]=5,p[2][3]=3,p[3][0]=1,p[3][1]=0,p[3][2]=3,p[3][3]=4,p[4][0]=4,p[4][1]=5,p[4][2]=2,p[4][3]=1),o.computeNormals(),o.computeEdges(),o.updateBoundingSphereRadius(),this.setCachedConvexTrianglePillar(e,f,n,o,t)},n.prototype.calculateLocalInertia=function(e,f){return f=f||new i,f.set(0,0,0),f},n.prototype.volume=function(){return Number.MAX_VALUE},n.prototype.calculateWorldAABB=function(e,f,n,o){n.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),o.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},n.prototype.updateBoundingSphereRadius=function(){var e=this.data,f=this.elementSize;this.boundingSphereRadius=new i(e.length*f,e[0].length*f,Math.max(Math.abs(this.maxValue),Math.abs(this.minValue))).norm()}},{"../math/Vec3":30,"../utils/Utils":53,"./ConvexPolyhedron":38,"./Shape":43}],41:[function(e,f){function n(){o.call(this),this.type=o.types.PARTICLE}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.calculateLocalInertia=function(e,f){return f=f||new d,f.set(0,0,0),f},n.prototype.volume=function(){return 0},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=0},n.prototype.calculateWorldAABB=function(e,f,n,o){n.copy(e),o.copy(e)}},{"../math/Vec3":30,"./Shape":43}],42:[function(e,f){function n(){o.call(this),this.type=o.types.PLANE,this.worldNormal=new d,this.worldNormalNeedsUpdate=!0,this.boundingSphereRadius=Number.MAX_VALUE}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.computeWorldNormal=function(e){var f=this.worldNormal;f.set(0,0,1),e.vmult(f,f),this.worldNormalNeedsUpdate=!1},n.prototype.calculateLocalInertia=function(e,f){return f=f||new d},n.prototype.volume=function(){return Number.MAX_VALUE};var i=new d;n.prototype.calculateWorldAABB=function(e,f,n,o){i.set(0,0,1),f.vmult(i,i);var d=Number.MAX_VALUE;n.set(-d,-d,-d),o.set(d,d,d),1===i.x&&(o.x=e.x),1===i.y&&(o.y=e.y),1===i.z&&(o.z=e.z),-1===i.x&&(n.x=e.x),-1===i.y&&(n.y=e.y),-1===i.z&&(n.z=e.z)},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=Number.MAX_VALUE}},{"../math/Vec3":30,"./Shape":43}],43:[function(e,f){function n(){this.id=n.idCounter++,this.type=0,this.boundingSphereRadius=0,this.collisionResponse=!0,this.material=null}f.exports=n;{var n=e("./Shape");e("../math/Vec3"),e("../math/Quaternion"),e("../material/Material")}n.prototype.constructor=n,n.prototype.updateBoundingSphereRadius=function(){throw"computeBoundingSphereRadius() not implemented for shape type "+this.type},n.prototype.volume=function(){throw"volume() not implemented for shape type "+this.type},n.prototype.calculateLocalInertia=function(){throw"calculateLocalInertia() not implemented for shape type "+this.type},n.idCounter=0,n.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256}},{"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"./Shape":43}],44:[function(e,f){function n(e){if(o.call(this),this.radius=void 0!==e?Number(e):1,this.type=o.types.SPHERE,this.radius<0)throw new Error("The sphere radius cannot be negative.");this.updateBoundingSphereRadius()}f.exports=n;var o=e("./Shape"),d=e("../math/Vec3");n.prototype=new o,n.prototype.constructor=n,n.prototype.calculateLocalInertia=function(e,f){f=f||new d;var n=2*e*this.radius*this.radius/5;return f.x=n,f.y=n,f.z=n,f},n.prototype.volume=function(){return 4*Math.PI*this.radius/3},n.prototype.updateBoundingSphereRadius=function(){this.boundingSphereRadius=this.radius},n.prototype.calculateWorldAABB=function(e,f,n,o){for(var d=this.radius,i=["x","y","z"],t=0;td?d+"_"+i:i+"_"+d;e[f]=!0},n=0;nn.x&&(n.x=d.x),d.yn.y&&(n.y=d.y),d.zn.z&&(n.z=d.z)},n.prototype.updateAABB=function(){this.computeLocalAABB(this.aabb)},n.prototype.updateBoundingSphereRadius=function(){for(var e=0,f=this.vertices,n=new d,o=0,i=f.length/3;o!==i;o++){this.getVertex(o,n);var t=n.norm2();t>e&&(e=t)}this.boundingSphereRadius=Math.sqrt(e)};var g=(new d,new i),x=new t;n.prototype.calculateWorldAABB=function(e,f,n,o){var d=g,i=x;d.position=e,d.quaternion=f,this.aabb.toWorldFrame(d,i),n.copy(i.lowerBound),o.copy(i.upperBound)},n.prototype.volume=function(){return 4*Math.PI*this.boundingSphereRadius/3},n.createTorus=function(e,f,o,d,i){e=e||1,f=f||.5,o=o||8,d=d||6,i=i||2*Math.PI;for(var t=[],l=[],u=0;o>=u;u++)for(var p=0;d>=p;p++){var s=p/d*i,y=u/o*Math.PI*2,c=(e+f*Math.cos(y))*Math.cos(s),a=(e+f*Math.cos(y))*Math.sin(s),r=f*Math.sin(y);t.push(c,a,r)}for(var u=1;o>=u;u++)for(var p=1;d>=p;p++){var w=(d+1)*u+p-1,b=(d+1)*(u-1)+p-1,m=(d+1)*(u-1)+p,N=(d+1)*u+p;l.push(w,b,N),l.push(b,m,N)}return new n(t,l)}},{"../collision/AABB":3,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../utils/Octree":50,"./Shape":43}],46:[function(e,f){function n(){o.call(this),this.iterations=10,this.tolerance=1e-7}f.exports=n;var o=(e("../math/Vec3"),e("../math/Quaternion"),e("./Solver"));n.prototype=new o;var d=[],i=[],t=[];n.prototype.solve=function(e,f){var n,o,l,u,p,s,y=0,c=this.iterations,a=this.tolerance*this.tolerance,r=this.equations,w=r.length,b=f.bodies,m=b.length,N=e;if(0!==w)for(var g=0;g!==m;g++)b[g].updateSolveMassProperties();var x=i,j=t,v=d; +x.length=w,j.length=w,v.length=w;for(var g=0;g!==w;g++){var A=r[g];v[g]=0,j[g]=A.computeB(N),x[g]=1/A.computeC()}if(0!==w){for(var g=0;g!==m;g++){var C=b[g],O=C.vlambda,h=C.wlambda;O.set(0,0,0),h&&h.set(0,0,0)}for(y=0;y!==c;y++){u=0;for(var k=0;k!==w;k++){var A=r[k];n=j[k],o=x[k],s=v[k],p=A.computeGWlambda(),l=o*(n-p-A.eps*s),s+lA.maxForce&&(l=A.maxForce-s),v[k]+=l,u+=l>0?l:-l,A.addToWlambda(l)}if(a>u*u)break}for(var g=0;g!==m;g++){var C=b[g],q=C.velocity,z=C.angularVelocity;q.vadd(C.vlambda,q),z&&z.vadd(C.wlambda,z)}}return y}},{"../math/Quaternion":28,"../math/Vec3":30,"./Solver":47}],47:[function(e,f){function n(){this.equations=[]}f.exports=n,n.prototype.solve=function(){return 0},n.prototype.addEquation=function(e){e.enabled&&this.equations.push(e)},n.prototype.removeEquation=function(e){var f=this.equations,n=f.indexOf(e);-1!==n&&f.splice(n,1)},n.prototype.removeAllEquations=function(){this.equations.length=0}},{}],48:[function(e,f){function n(e){for(l.call(this),this.iterations=10,this.tolerance=1e-7,this.subsolver=e,this.nodes=[],this.nodePool=[];this.nodePool.length<128;)this.nodePool.push(this.createNode())}function o(e){for(var f=e.length,n=0;n!==f;n++){var o=e[n];if(!(o.visited||o.body.type&c))return o}return!1}function d(e,f,n,d){for(a.push(e),e.visited=!0,f(e,n,d);a.length;)for(var i,t=a.pop();i=o(t.children);)i.visited=!0,f(i,n,d),a.push(i)}function i(e,f,n){f.push(e.body);for(var o=e.eqs.length,d=0;d!==o;d++){var i=e.eqs[d];-1===n.indexOf(i)&&n.push(i)}}function t(e,f){return f.id-e.id}f.exports=n;var l=(e("../math/Vec3"),e("../math/Quaternion"),e("./Solver")),u=e("../objects/Body");n.prototype=new l;var p=[],s=[],y={bodies:[]},c=u.STATIC,a=[];n.prototype.createNode=function(){return{body:null,children:[],eqs:[],visited:!1}},n.prototype.solve=function(e,f){for(var n=p,l=this.nodePool,u=f.bodies,c=this.equations,a=c.length,r=u.length,w=this.subsolver;l.lengthb;b++)n[b]=l[b];for(var b=0;b!==r;b++){var m=n[b];m.body=u[b],m.children.length=0,m.eqs.length=0,m.visited=!1}for(var N=0;N!==a;N++){var g=c[N],b=u.indexOf(g.bi),x=u.indexOf(g.bj),j=n[b],v=n[x];j.children.push(v),j.eqs.push(g),v.children.push(j),v.eqs.push(g)}var A,C=0,O=s;w.tolerance=this.tolerance,w.iterations=this.iterations;for(var h=y;A=o(n);){O.length=0,h.bodies.length=0,d(A,i,h.bodies,O);var k=O.length;O=O.sort(t);for(var b=0;b!==k;b++)w.addEquation(O[b]);{w.solve(e,h)}w.removeAllEquations(),C++}return C}},{"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"./Solver":47}],49:[function(e,f){var n=function(){};f.exports=n,n.prototype={constructor:n,addEventListener:function(e,f){void 0===this._listeners&&(this._listeners={});var n=this._listeners;return void 0===n[e]&&(n[e]=[]),-1===n[e].indexOf(f)&&n[e].push(f),this},hasEventListener:function(e,f){if(void 0===this._listeners)return!1;var n=this._listeners;return void 0!==n[e]&&-1!==n[e].indexOf(f)?!0:!1},removeEventListener:function(e,f){if(void 0===this._listeners)return this;var n=this._listeners;if(void 0===n[e])return this;var o=n[e].indexOf(f);return-1!==o&&n[e].splice(o,1),this},dispatchEvent:function(e){if(void 0===this._listeners)return this;var f=this._listeners,n=f[e.type];if(void 0!==n){e.target=this;for(var o=0,d=n.length;d>o;o++)n[o].call(this,e)}return this}}},{}],50:[function(e,f){function n(e){e=e||{},this.root=e.root||null,this.aabb=e.aabb?e.aabb.clone():new d,this.data=[],this.children=[]}function o(e,f){f=f||{},f.root=null,f.aabb=e,n.call(this,f),this.maxDepth="undefined"!=typeof f.maxDepth?f.maxDepth:8}var d=e("../collision/AABB"),i=e("../math/Vec3");f.exports=o,o.prototype=new n,n.prototype.reset=function(){this.children.length=this.data.length=0},n.prototype.insert=function(e,f,n){var o=this.data;if(n=n||0,!this.aabb.contains(e))return!1;var d=this.children;if(n<(this.maxDepth||this.root.maxDepth)){var i=!1;d.length||(this.subdivide(),i=!0);for(var t=0;8!==t;t++)if(d[t].insert(e,f,n+1))return!0;i&&(d.length=0)}return o.push(f),!0};var t=new i;n.prototype.subdivide=function(){var e=this.aabb,f=e.lowerBound,o=e.upperBound,l=this.children;l.push(new n({aabb:new d({lowerBound:new i(0,0,0)})}),new n({aabb:new d({lowerBound:new i(1,0,0)})}),new n({aabb:new d({lowerBound:new i(1,1,0)})}),new n({aabb:new d({lowerBound:new i(1,1,1)})}),new n({aabb:new d({lowerBound:new i(0,1,1)})}),new n({aabb:new d({lowerBound:new i(0,0,1)})}),new n({aabb:new d({lowerBound:new i(1,0,1)})}),new n({aabb:new d({lowerBound:new i(0,1,0)})})),o.vsub(f,t),t.scale(.5,t);for(var u=this.root||this,p=0;8!==p;p++){var s=l[p];s.root=u;var y=s.aabb.lowerBound;y.x*=t.x,y.y*=t.y,y.z*=t.z,y.vadd(f,y),y.vadd(t,s.aabb.upperBound)}},n.prototype.aabbQuery=function(e,f){for(var n=(this.data,this.children,[this]);n.length;){var o=n.pop();o.aabb.overlaps(e)&&Array.prototype.push.apply(f,o.data),Array.prototype.push.apply(n,o.children)}return f};var l=new d;n.prototype.rayQuery=function(e,f,n){return e.getAABB(l),l.toLocalFrame(f,l),this.aabbQuery(l,n),n},n.prototype.removeEmptyNodes=function(){for(var e=[this];e.length;){for(var f=e.pop(),n=f.children.length-1;n>=0;n--)f.children[n].data.length||f.children.splice(n,1);Array.prototype.push.apply(e,f.children)}}},{"../collision/AABB":3,"../math/Vec3":30}],51:[function(e,f){function n(){this.objects=[],this.type=Object}f.exports=n,n.prototype.release=function(){for(var e=arguments.length,f=0;f!==e;f++)this.objects.push(arguments[f])},n.prototype.get=function(){return 0===this.objects.length?this.constructObject():this.objects.pop()},n.prototype.constructObject=function(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}},{}],52:[function(e,f){function n(){this.data={keys:[]}}f.exports=n,n.prototype.get=function(e,f){if(e>f){var n=f;f=e,e=n}return this.data[e+"-"+f]},n.prototype.set=function(e,f,n){if(e>f){var o=f;f=e,e=o}var d=e+"-"+f;this.get(e,f)||this.data.keys.push(d),this.data[d]=n},n.prototype.reset=function(){for(var e=this.data,f=e.keys;f.length>0;){var n=f.pop();delete e[n]}}},{}],53:[function(e,f){function n(){}f.exports=n,n.defaults=function(e,f){e=e||{};for(var n in f)n in e||(e[n]=f[n]);return e}},{}],54:[function(e,f){function n(){d.call(this),this.type=o}f.exports=n;var o=e("../math/Vec3"),d=e("./Pool");n.prototype=new d,n.prototype.constructObject=function(){return new o}},{"../math/Vec3":30,"./Pool":51}],55:[function(e,f){function n(e){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new s,this.world=e,this.currentContactMaterial=null,this.enableFrictionReduction=!1}function o(e,f,n){for(var o=null,d=e.length,i=0;i!==d;i++){var t=e[i],l=M;e[(i+1)%d].vsub(t,l);var u=P;l.cross(f,u);var p=Q;n.vsub(t,p);var s=u.dot(p);if(!(null===o||s>0&&o===!0||0>=s&&o===!1))return!1;null===o&&(o=s>0)}return!0}f.exports=n;var d=e("../collision/AABB"),i=e("../shapes/Shape"),t=e("../collision/Ray"),l=e("../math/Vec3"),u=e("../math/Transform"),p=(e("../shapes/ConvexPolyhedron"),e("../math/Quaternion")),s=(e("../solver/Solver"),e("../utils/Vec3Pool")),y=e("../equations/ContactEquation"),c=e("../equations/FrictionEquation");n.prototype.createContactEquation=function(e,f,n,o,d,i){var t;this.contactPointPool.length?(t=this.contactPointPool.pop(),t.bi=e,t.bj=f):t=new y(e,f),t.enabled=e.collisionResponse&&f.collisionResponse&&n.collisionResponse&&o.collisionResponse;var l=this.currentContactMaterial;t.restitution=l.restitution,t.setSpookParams(l.contactEquationStiffness,l.contactEquationRelaxation,this.world.dt);var u=n.material||e.material,p=o.material||f.material;return u&&p&&u.restitution>=0&&p.restitution>=0&&(t.restitution=u.restitution*p.restitution),t.si=d||n,t.sj=i||o,t},n.prototype.createFrictionEquationsFromContact=function(e,f){var n=e.bi,o=e.bj,d=e.si,i=e.sj,t=this.world,l=this.currentContactMaterial,u=l.friction,p=d.material||n.material,s=i.material||o.material;if(p&&s&&p.friction>=0&&s.friction>=0&&(u=p.friction*s.friction),u>0){var y=u*t.gravity.length(),a=n.invMass+o.invMass;a>0&&(a=1/a);var r=this.frictionEquationPool,w=r.length?r.pop():new c(n,o,y*a),b=r.length?r.pop():new c(n,o,y*a);return w.bi=b.bi=n,w.bj=b.bj=o,w.minForce=b.minForce=-y*a,w.maxForce=b.maxForce=y*a,w.ri.copy(e.ri),w.rj.copy(e.rj),b.ri.copy(e.ri),b.rj.copy(e.rj),e.ni.tangents(w.t,b.t),w.setSpookParams(l.frictionEquationStiffness,l.frictionEquationRelaxation,t.dt),b.setSpookParams(l.frictionEquationStiffness,l.frictionEquationRelaxation,t.dt),w.enabled=b.enabled=e.enabled,f.push(w,b),!0}return!1};var a=new l,r=new l,w=new l;n.prototype.createFrictionFromAverage=function(e){var f=this.result[this.result.length-1];if(this.createFrictionEquationsFromContact(f,this.frictionResult)&&1!==e){var n=this.frictionResult[this.frictionResult.length-2],o=this.frictionResult[this.frictionResult.length-1];a.setZero(),r.setZero(),w.setZero();for(var d=f.bi,i=(f.bj,0);i!==e;i++)f=this.result[this.result.length-1-i],f.bodyA!==d?(a.vadd(f.ni,a),r.vadd(f.ri,r),w.vadd(f.rj,w)):(a.vsub(f.ni,a),r.vadd(f.rj,r),w.vadd(f.ri,w));var t=1/e;r.scale(t,n.ri),w.scale(t,n.rj),o.ri.copy(n.ri),o.rj.copy(n.rj),a.normalize(),a.tangents(n.t,o.t)}};var b=new l,m=new l,N=new p,g=new p;n.prototype.getContacts=function(e,f,n,o,d,i,t){this.contactPointPool=d,this.frictionEquationPool=t,this.result=o,this.frictionResult=i;for(var l=N,u=g,p=b,s=m,y=0,c=e.length;y!==c;y++){var a=e[y],r=f[y],w=null;a.material&&r.material&&(w=n.getContactMaterial(a.material,r.material)||null);for(var x=0;xj.boundingSphereRadius+A.boundingSphereRadius)){var C=null;j.material&&A.material&&(C=n.getContactMaterial(j.material,A.material)||null),this.currentContactMaterial=C||w||n.defaultContactMaterial;var O=this[j.type|A.type];O&&(j.type=w){var b=this.createContactEquation(t,p,e,f);b.ni.copy(y);var m=v;y.scale(r.dot(y),m),s.vsub(m,m),b.ri.copy(m),b.ri.vsub(t.position,b.ri),b.rj.copy(s),b.rj.vsub(p.position,b.rj),this.result.push(b),this.createFrictionEquationsFromContact(b,this.frictionResult)}}};var A=new l,C=new l,O=(new l,new l),h=new l,k=new l,q=new l,z=new l,B=new l,D=new l,E=new l,F=new l,G=new l,H=new l,I=new d,J=[];n.prototype[i.types.SPHERE|i.types.TRIMESH]=n.prototype.sphereTrimesh=function(e,f,n,o,d,i,l,p){var s=k,y=q,c=z,a=B,r=D,w=E,b=I,m=h,N=C,g=J;u.pointToLocalFrame(o,i,n,r);var x=e.radius;b.lowerBound.set(r.x-x,r.y-x,r.z-x),b.upperBound.set(r.x+x,r.y+x,r.z+x),f.getTrianglesInAABB(b,g);for(var j=O,v=e.radius*e.radius,K=0;KL;L++)if(f.getVertex(f.indices[3*g[K]+L],j),j.vsub(r,N),N.norm2()<=v){m.copy(j),u.pointToWorldFrame(o,i,m,j),j.vsub(n,N);var M=this.createContactEquation(l,p,e,f);M.ni.copy(N),M.ni.normalize(),M.ri.copy(M.ni),M.ri.scale(e.radius,M.ri),M.ri.vadd(n,M.ri),M.ri.vsub(l.position,M.ri),M.rj.copy(j),M.rj.vsub(p.position,M.rj),this.result.push(M),this.createFrictionEquationsFromContact(M,this.frictionResult)}for(var K=0;KL;L++){f.getVertex(f.indices[3*g[K]+L],s),f.getVertex(f.indices[3*g[K]+(L+1)%3],y),y.vsub(s,c),r.vsub(y,w);var P=w.dot(c);r.vsub(s,w);var Q=w.dot(c);if(Q>0&&0>P){r.vsub(s,w),a.copy(c),a.normalize(),Q=w.dot(a),a.scale(Q,w),w.vadd(s,w);var R=w.distanceTo(r);if(RC&&C>0){var O=T,h=U;O.copy(p[(x+1)%3]),h.copy(p[(x+2)%3]);var k=O.norm(),q=h.norm();O.normalize(),h.normalize();var z=R.dot(O),B=R.dot(h);if(k>z&&z>-k&&q>B&&B>-q){var D=Math.abs(C-A-s);(null===g||g>D)&&(g=D,m=z,N=B,w=A,c.copy(v),a.copy(O),r.copy(h),b++)}}}if(b){y=!0;var E=this.createContactEquation(t,l,e,f);c.mult(-s,E.ri),E.ni.copy(c),E.ni.negate(E.ni),c.mult(w,c),a.mult(m,a),c.vadd(a,c),r.mult(N,r),c.vadd(r,E.rj),E.ri.vadd(n,E.ri),E.ri.vsub(t.position,E.ri),E.rj.vadd(o,E.rj),E.rj.vsub(l.position,E.rj),this.result.push(E),this.createFrictionEquationsFromContact(E,this.frictionResult)}for(var F=u.get(),G=W,H=0;2!==H&&!y;H++)for(var I=0;2!==I&&!y;I++)for(var J=0;2!==J&&!y;J++)if(F.set(0,0,0),H?F.vadd(p[0],F):F.vsub(p[0],F),I?F.vadd(p[1],F):F.vsub(p[1],F),J?F.vadd(p[2],F):F.vsub(p[2],F),o.vadd(F,G),G.vsub(n,G),G.norm2()_){y=!0;var ef=this.createContactEquation(t,l,e,f);L.vadd(M,ef.rj),ef.rj.copy(ef.rj),D.negate(ef.ni),ef.ni.normalize(),ef.ri.copy(ef.rj),ef.ri.vadd(o,ef.ri),ef.ri.vsub(n,ef.ri),ef.ri.normalize(),ef.ri.mult(s,ef.ri),ef.ri.vadd(n,ef.ri),ef.ri.vsub(t.position,ef.ri),ef.rj.vadd(o,ef.rj),ef.rj.vsub(l.position,ef.rj),this.result.push(ef),this.createFrictionEquationsFromContact(ef,this.frictionResult)}}u.release(K,L,E,M,D)};var $=new l,_=new l,ef=new l,ff=new l,nf=new l,of=new l,df=new l,tf=new l,lf=new l,uf=new l;n.prototype[i.types.SPHERE|i.types.CONVEXPOLYHEDRON]=n.prototype.sphereConvex=function(e,f,n,d,i,t,l,u){var p=this.v3pool;n.vsub(d,$);for(var s=f.faceNormals,y=f.faces,c=f.vertices,a=e.radius,r=0;r!==c.length;r++){var w=c[r],b=nf;t.vmult(w,b),d.vadd(b,b);var m=ff;if(b.vsub(n,m),m.norm2()k&&q.dot(A)>0){for(var z=[],B=0,D=v.length;B!==D;B++){var E=p.get();t.vmult(c[v[B]],E),d.vadd(E,E),z.push(E)}if(o(z,A,n)){g=!0;var N=this.createContactEquation(l,u,e,f);A.mult(-a,N.ri),A.negate(N.ni);var F=p.get();A.mult(-k,F);var G=p.get();A.mult(-a,G),n.vsub(d,N.rj),N.rj.vadd(G,N.rj),N.rj.vadd(F,N.rj),N.rj.vadd(d,N.rj),N.rj.vsub(u.position,N.rj),N.ri.vadd(n,N.ri),N.ri.vsub(l.position,N.ri),p.release(F),p.release(G),this.result.push(N),this.createFrictionEquationsFromContact(N,this.frictionResult);for(var B=0,H=z.length;B!==H;B++)p.release(z[B]);return}for(var B=0;B!==v.length;B++){var I=p.get(),J=p.get();t.vmult(c[v[(B+1)%v.length]],I),t.vmult(c[v[(B+2)%v.length]],J),d.vadd(I,I),d.vadd(J,J);var K=_;J.vsub(I,K);var L=ef;K.unit(L);var M=p.get(),P=p.get();n.vsub(I,P);var Q=P.dot(L);L.mult(Q,M),M.vadd(I,M);var R=p.get();if(M.vsub(n,R),Q>0&&Q*Q=a){var r=this.createContactEquation(t,l,e,f),w=cf;p.mult(p.dot(y),w),u.vsub(w,w),w.vsub(n,r.ri),r.ni.copy(p),u.vsub(o,r.rj),r.ri.vadd(n,r.ri),r.ri.vsub(t.position,r.ri),r.rj.vadd(o,r.rj),r.rj.vsub(l.position,r.rj),this.result.push(r),s++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(r,this.frictionResult)}}this.enableFrictionReduction&&s&&this.createFrictionFromAverage(s)};var af=new l,rf=new l;n.prototype[i.types.CONVEXPOLYHEDRON]=n.prototype.convexConvex=function(e,f,n,o,d,i,t,l,u,p,s,y){var c=af;if(!(n.distanceTo(o)>e.boundingSphereRadius+f.boundingSphereRadius)&&e.findSeparatingAxis(f,n,d,o,i,c,s,y)){var a=[],r=rf;e.clipAgainstHull(n,d,f,o,i,c,-100,100,a);for(var w=0,b=0;b!==a.length;b++){var m=this.createContactEquation(t,l,e,f,u,p),N=m.ri,g=m.rj;c.negate(m.ni),a[b].normal.negate(r),r.mult(a[b].depth,r),a[b].point.vadd(r,N),g.copy(a[b].point),N.vsub(n,N),g.vsub(o,g),N.vadd(n,N),N.vsub(t.position,N),g.vadd(o,g),g.vsub(l.position,g),this.result.push(m),w++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(m,this.frictionResult)}this.enableFrictionReduction&&w&&this.createFrictionFromAverage(w)}};var wf=new l,bf=new l,mf=new l;n.prototype[i.types.PLANE|i.types.PARTICLE]=n.prototype.planeParticle=function(e,f,n,o,d,i,t,l){var u=wf;u.set(0,0,1),t.quaternion.vmult(u,u);var p=bf;o.vsub(t.position,p);var s=u.dot(p);if(0>=s){var y=this.createContactEquation(l,t,f,e);y.ni.copy(u),y.ni.negate(y.ni),y.ri.set(0,0,0);var c=mf;u.mult(u.dot(o),c),o.vsub(c,c),y.rj.copy(c),this.result.push(y),this.createFrictionEquationsFromContact(y,this.frictionResult)}};var Nf=new l;n.prototype[i.types.PARTICLE|i.types.SPHERE]=n.prototype.sphereParticle=function(e,f,n,o,d,i,t,l){var u=Nf;u.set(0,0,1),o.vsub(n,u);var p=u.norm2();if(p<=e.radius*e.radius){var s=this.createContactEquation(l,t,f,e);u.normalize(),s.rj.copy(u),s.rj.mult(e.radius,s.rj),s.ni.copy(u),s.ni.negate(s.ni),s.ri.set(0,0,0),this.result.push(s),this.createFrictionEquationsFromContact(s,this.frictionResult)}};var gf=new p,xf=new l,jf=(new l,new l),vf=new l,Af=new l;n.prototype[i.types.PARTICLE|i.types.CONVEXPOLYHEDRON]=n.prototype.convexParticle=function(e,f,n,o,d,i,t,l){var u=-1,p=jf,s=Af,y=null,c=0,a=xf;if(a.copy(o),a.vsub(n,a),d.conjugate(gf),gf.vmult(a,a),e.pointIsInside(a)){e.worldVerticesNeedsUpdate&&e.computeWorldVertices(n,d),e.worldFaceNormalsNeedsUpdate&&e.computeWorldFaceNormals(d);for(var r=0,w=e.faces.length;r!==w;r++){var b=[e.worldVertices[e.faces[r][0]]],m=e.worldFaceNormals[r];o.vsub(b[0],vf);var N=-m.dot(vf);(null===y||Math.abs(N)b||0>N||w>p.length||m>p[0].length)){0>w&&(w=0),0>b&&(b=0),0>m&&(m=0),0>N&&(N=0),w>=p.length&&(w=p.length-1),b>=p.length&&(b=p.length-1),N>=p[0].length&&(N=p[0].length-1),m>=p[0].length&&(m=p[0].length-1);var g=[];f.getRectMinMax(w,m,b,N,g);var x=g[0],j=g[1];if(!(r.z-y>j||r.z+yv;v++)for(var A=m;N>A;A++)f.getConvexTrianglePillar(v,A,!1),u.pointToWorldFrame(o,i,f.pillarOffset,c),n.distanceTo(c)w||0>m||r>p.length||m>p[0].length)){0>r&&(r=0),0>w&&(w=0),0>b&&(b=0),0>m&&(m=0),r>=p.length&&(r=p.length-1),w>=p.length&&(w=p.length-1),m>=p[0].length&&(m=p[0].length-1),b>=p[0].length&&(b=p[0].length-1);var N=[];f.getRectMinMax(r,b,w,m,N);var g=N[0],x=N[1];if(!(a.z-s>x||a.z+sv;v++)for(var A=b;m>A;A++){var C=j.length;f.getConvexTrianglePillar(v,A,!1),u.pointToWorldFrame(o,i,f.pillarOffset,c),n.distanceTo(c)2)return}}}},{"../collision/AABB":3,"../collision/Ray":9,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../math/Quaternion":28,"../math/Transform":29,"../math/Vec3":30,"../shapes/ConvexPolyhedron":38,"../shapes/Shape":43,"../solver/Solver":47,"../utils/Vec3Pool":54}],56:[function(e,f){function n(){u.apply(this),this.dt=-1,this.allowSleep=!1,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=0,this.quatNormalizeFast=!1,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new d,this.broadphase=new m,this.bodies=[],this.solver=new t,this.constraints=[],this.narrowphase=new l(this),this.collisionMatrix=new p,this.collisionMatrixPrevious=new p,this.materials=[],this.contactmaterials=[],this.contactMaterialTable=new a,this.defaultMaterial=new s("default"),this.defaultContactMaterial=new y(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null}}f.exports=n;var o=e("../shapes/Shape"),d=e("../math/Vec3"),i=e("../math/Quaternion"),t=e("../solver/GSSolver"),l=(e("../utils/Vec3Pool"),e("../equations/ContactEquation"),e("../equations/FrictionEquation"),e("./Narrowphase")),u=e("../utils/EventTarget"),p=e("../collision/ArrayCollisionMatrix"),s=e("../material/Material"),y=e("../material/ContactMaterial"),c=e("../objects/Body"),a=e("../utils/TupleDictionary"),r=e("../collision/RaycastResult"),w=e("../collision/AABB"),b=e("../collision/Ray"),m=e("../collision/NaiveBroadphase");n.prototype=new u;var N=(new w,new b);if(n.prototype.getContactMaterial=function(e,f){return this.contactMaterialTable.get(e.id,f.id)},n.prototype.numObjects=function(){return this.bodies.length},n.prototype.collisionMatrixTick=function(){var e=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=e,this.collisionMatrix.reset()},n.prototype.add=n.prototype.addBody=function(e){-1===this.bodies.indexOf(e)&&(e.index=this.bodies.length,this.bodies.push(e),e.world=this,e.initPosition.copy(e.position),e.initVelocity.copy(e.velocity),e.timeLastSleepy=this.time,e instanceof c&&(e.initAngularVelocity.copy(e.angularVelocity),e.initQuaternion.copy(e.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=e,this.dispatchEvent(this.addBodyEvent))},n.prototype.addConstraint=function(e){this.constraints.push(e)},n.prototype.removeConstraint=function(e){var f=this.constraints.indexOf(e);-1!==f&&this.constraints.splice(f,1)},n.prototype.rayTest=function(e,f,n){n instanceof r?this.raycastClosest(e,f,{skipBackfaces:!0},n):this.raycastAll(e,f,{skipBackfaces:!0},n)},n.prototype.raycastAll=function(e,f,n,o){return n.mode=b.ALL,n.from=e,n.to=f,n.callback=o,N.intersectWorld(this,n)},n.prototype.raycastAny=function(e,f,n,o){return n.mode=b.ANY,n.from=e,n.to=f,n.result=o,N.intersectWorld(this,n)},n.prototype.raycastClosest=function(e,f,n,o){return n.mode=b.CLOSEST,n.from=e,n.to=f,n.result=o,N.intersectWorld(this,n)},n.prototype.remove=function(e){e.world=null;var f=this.bodies.length-1,n=this.bodies,o=n.indexOf(e);if(-1!==o){n.splice(o,1);for(var d=0;d!==n.length;d++)n[d].index=d;this.collisionMatrix.setNumObjects(f),this.removeBodyEvent.body=e,this.dispatchEvent(this.removeBodyEvent)}},n.prototype.removeBody=n.prototype.remove,n.prototype.addMaterial=function(e){this.materials.push(e)},n.prototype.addContactMaterial=function(e){this.contactmaterials.push(e),this.contactMaterialTable.set(e.materials[0].id,e.materials[1].id,e)},"undefined"==typeof performance&&(performance={}),!performance.now){var g=Date.now();performance.timing&&performance.timing.navigationStart&&(g=performance.timing.navigationStart),performance.now=function(){return Date.now()-g}}var x=new d;n.prototype.step=function(e,f,n){if(n=n||10,f=f||0,0===f)this.internalStep(e),this.time+=e;else{var o=Math.floor((this.time+f)/e)-Math.floor(this.time/e);o=Math.min(o,n);for(var d=performance.now(),i=0;i!==o&&(this.internalStep(e),!(performance.now()-d>1e3*e));i++);this.time+=f;for(var t=this.time%e,l=t/e,u=x,p=this.bodies,s=0;s!==p.length;s++){var y=p[s];y.type!==c.STATIC&&y.sleepState!==c.SLEEPING?(y.position.vsub(y.previousPosition,u),u.scale(l,u),y.position.vadd(u,y.interpolatedPosition)):(y.interpolatedPosition.copy(y.position),y.interpolatedQuaternion.copy(y.quaternion))}}};var j={type:"postStep"},v={type:"preStep"},A={type:"collide",body:null,contact:null},C=[],O=[],h=[],k=[],q=(new d,new d,new d,new d,new d,new d,new d,new d,new d,new i,new i),z=new i,B=new d;n.prototype.internalStep=function(e){this.dt=e;var f,n=this.contacts,d=h,i=k,t=this.numObjects(),l=this.bodies,u=this.solver,p=this.gravity,s=this.doProfiling,y=this.profile,a=c.DYNAMIC,r=this.constraints,w=O,b=(p.norm(),p.x),m=p.y,N=p.z,g=0;for(s&&(f=performance.now()),g=0;g!==t;g++){var x=l[g];if(x.type&a){var D=x.force,E=x.mass;D.x+=E*b,D.y+=E*m,D.z+=E*N}}for(var g=0,F=this.subsystems.length;g!==F;g++)this.subsystems[g].update();s&&(f=performance.now()),d.length=0,i.length=0,this.broadphase.collisionPairs(this,d,i),s&&(y.broadphase=performance.now()-f);var G=r.length;for(g=0;g!==G;g++){var H=r[g];if(!H.collideConnected)for(var I=d.length-1;I>=0;I-=1)(H.bodyA===d[I]&&H.bodyB===i[I]||H.bodyB===d[I]&&H.bodyA===i[I])&&(d.splice(I,1),i.splice(I,1))}this.collisionMatrixTick(),s&&(f=performance.now());var J=C,K=n.length;for(g=0;g!==K;g++)J.push(n[g]);n.length=0;var L=this.frictionEquations.length;for(g=0;g!==L;g++)w.push(this.frictionEquations[g]);this.frictionEquations.length=0,this.narrowphase.getContacts(d,i,this,n,J,this.frictionEquations,w),s&&(y.narrowphase=performance.now()-f),s&&(f=performance.now());for(var g=0;g=0&&R.material.friction>=0&&(S=x.material.friction*R.material.friction),x.material.restitution>=0&&R.material.restitution>=0&&(H.restitution=x.material.restitution*R.material.restitution)),u.addEquation(H),x.allowSleep&&x.type===c.DYNAMIC&&x.sleepState===c.SLEEPING&&R.sleepState===c.AWAKE&&R.type!==c.STATIC){var T=R.velocity.norm2()+R.angularVelocity.norm2(),U=Math.pow(R.sleepSpeedLimit,2); +T>=2*U&&(x._wakeUpAfterNarrowphase=!0)}if(R.allowSleep&&R.type===c.DYNAMIC&&R.sleepState===c.SLEEPING&&x.sleepState===c.AWAKE&&x.type!==c.STATIC){var V=x.velocity.norm2()+x.angularVelocity.norm2(),W=Math.pow(x.sleepSpeedLimit,2);V>=2*W&&(R._wakeUpAfterNarrowphase=!0)}this.collisionMatrix.set(x,R,!0),this.collisionMatrixPrevious.get(x,R)||(A.body=R,A.contact=H,x.dispatchEvent(A),A.body=x,R.dispatchEvent(A))}for(s&&(y.makeContactConstraints=performance.now()-f,f=performance.now()),g=0;g!==t;g++){var x=l[g];x._wakeUpAfterNarrowphase&&(x.wakeUp(),x._wakeUpAfterNarrowphase=!1)}var G=r.length;for(g=0;g!==G;g++){var H=r[g];H.update();for(var I=0,X=H.equations.length;I!==X;I++){var Y=H.equations[I];u.addEquation(Y)}}u.solve(e,this),s&&(y.solve=performance.now()-f),u.removeAllEquations();var Z=Math.pow;for(g=0;g!==t;g++){var x=l[g];if(x.type&a){var $=Z(1-x.linearDamping,e),_=x.velocity;_.mult($,_);var ef=x.angularVelocity;if(ef){var ff=Z(1-x.angularDamping,e);ef.mult(ff,ef)}}}for(this.dispatchEvent(v),g=0;g!==t;g++){var x=l[g];x.preStep&&x.preStep.call(x)}s&&(f=performance.now());{var nf=q,of=z,df=this.stepnumber,tf=c.DYNAMIC|c.KINEMATIC,lf=df%(this.quatNormalizeSkip+1)===0,uf=this.quatNormalizeFast,pf=.5*e;o.types.PLANE,o.types.CONVEXPOLYHEDRON}for(g=0;g!==t;g++){var sf=l[g],yf=sf.force,cf=sf.torque;if(sf.type&tf&&sf.sleepState!==c.SLEEPING){var af=sf.velocity,rf=sf.angularVelocity,wf=sf.position,bf=sf.quaternion,mf=sf.invMass,Nf=sf.invInertiaWorld;af.x+=yf.x*mf*e,af.y+=yf.y*mf*e,af.z+=yf.z*mf*e,sf.angularVelocity&&(Nf.vmult(cf,B),B.mult(e,B),B.vadd(rf,rf)),wf.x+=af.x*e,wf.y+=af.y*e,wf.z+=af.z*e,sf.angularVelocity&&(nf.set(rf.x,rf.y,rf.z,0),nf.mult(bf,of),bf.x+=pf*of.x,bf.y+=pf*of.y,bf.z+=pf*of.z,bf.w+=pf*of.w,lf&&(uf?bf.normalizeFast():bf.normalize())),sf.aabb&&(sf.aabbNeedsUpdate=!0),sf.updateInertiaWorld&&sf.updateInertiaWorld()}}for(this.clearForces(),this.broadphase.dirty=!0,s&&(y.integrate=performance.now()-f),this.time+=e,this.stepnumber+=1,this.dispatchEvent(j),g=0;g!==t;g++){var x=l[g],gf=x.postStep;gf&&gf.call(x)}if(this.allowSleep)for(g=0;g!==t;g++)l[g].sleepTick(this.time)},n.prototype.clearForces=function(){for(var e=this.bodies,f=e.length,n=0;n!==f;n++){{var o=e[n];o.force,o.torque}o.force.set(0,0,0),o.torque.set(0,0,0)}}},{"../collision/AABB":3,"../collision/ArrayCollisionMatrix":4,"../collision/NaiveBroadphase":7,"../collision/Ray":9,"../collision/RaycastResult":10,"../equations/ContactEquation":19,"../equations/FrictionEquation":21,"../material/ContactMaterial":24,"../material/Material":25,"../math/Quaternion":28,"../math/Vec3":30,"../objects/Body":31,"../shapes/Shape":43,"../solver/GSSolver":46,"../utils/EventTarget":49,"../utils/TupleDictionary":52,"../utils/Vec3Pool":54,"./Narrowphase":55}]},{},[2])(2)}); \ No newline at end of file diff --git a/docs/api.js b/docs/api.js index 8e66e2b69..af08abf34 100644 --- a/docs/api.js +++ b/docs/api.js @@ -6,6 +6,8 @@ YUI.add("yuidoc-meta", function(Y) { "Body", "Box", "Broadphase", + "ConeEquation", + "ConeTwistConstraint", "Constraint", "ContactEquation", "ContactMaterial", @@ -21,11 +23,14 @@ YUI.add("yuidoc-meta", function(Y) { "Heightfield", "HingeConstraint", "JacobianElement", + "LockConstraint", "Mat3", "Material", "NaiveBroadphase", "Narrowphase", "ObjectCollisionMatrix", + "Octree", + "OctreeNode", "Particle", "Plane", "PointToPointConstraint", @@ -45,6 +50,7 @@ YUI.add("yuidoc-meta", function(Y) { "SplitSolver", "Spring", "Transform", + "Trimesh", "TupleDictionary", "Vec3", "Vec3Pool", diff --git a/docs/assets/css/logo.png b/docs/assets/css/logo.png index 609b336c7..c82444af9 100644 Binary files a/docs/assets/css/logo.png and b/docs/assets/css/logo.png differ diff --git a/docs/assets/favicon.ico b/docs/assets/favicon.ico new file mode 100644 index 000000000..414ac4fb9 Binary files /dev/null and b/docs/assets/favicon.ico differ diff --git a/docs/assets/favicon.png b/docs/assets/favicon.png deleted file mode 100644 index 5a95ddab6..000000000 Binary files a/docs/assets/favicon.png and /dev/null differ diff --git a/docs/classes/AABB.html b/docs/classes/AABB.html index 3f839b6ef..874802676 100644 --- a/docs/classes/AABB.html +++ b/docs/classes/AABB.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
- -

- +

API Docs for: 0.6.1 @@ -27,446 +25,405 @@

- Show: - - - - - - - -
- - + Show: + + + + + + + +
+
-

AABB Class

+

AABB Class

- - - - - -
-

Axis aligned bounding box class.

-

Constructor

-

AABB

- - -
- (
    - -
  • - - [options] - -
  • - -
) -
- - - - - - - - - - - - - - - - -
+

AABB

- - -

- - Defined in +

+ (
    +
  • + [options] +
  • +
) +
+ + + + + + + + +
+

+ Defined in + src/collision/AABB.js:6 +

+ + + +
+ +
- +
+
+

Parameters:

- src/collision/AABB.js:6 +
    +
  • + [options] + Object + optional -

    - - - +
    + +
    + +
      +
    • + [upperBound] + Vec3 + optional + +
      + +
      + +
    • +
    • + [lowerBound] + Vec3 + optional + +
      + +
      + +
    • +
    +
  • +
+
+ -
- -
-
- - -
-

Parameters:

- -
    - -
  • - - [options] - Object - optional - - - - -
    - -
    - - -
      - -
    • - - [upperBound] - Array - optional - - -
      - -
      - - -
    • - -
    • - - [lowerBound] - Array - optional - - -
      - -
      - - -
    • - -
    - -
  • - -
- - - - - -
-
-

Item Index

-

Methods

- -

Properties

- - -
-

Methods

- -
+
+

clone

+ + () + + + + + + + + +
+

+ Defined in + src/collision/AABB.js:107 +

+ + + +
+ +
+

Clone an AABB

+ +
+ + + + +
+
+

contains

+ +
+ (
    +
  • + aabb +
  • +
) +
+ + + Boolean + + + + + + + + +
+

+ Defined in + src/collision/AABB.js:180 +

+ + + +
+ +
+

Returns true if the given AABB is fully contained in this AABB.

+ +
+ +
+

Parameters:

+ +
    +
  • + aabb + AABB + + +
    + +
    + +
  • +
+
+ +
+

Returns:

+ +
+ Boolean: +
+
+ + +
+

copy

-
(
    -
  • - aabb -
  • -
)
- - + + AABB + - - - - - -
- - -

- Defined in - - - - - src/collision/AABB.js:92 - + src/collision/AABB.js:95

- -
@@ -474,88 +431,62 @@

copy

-

Parameters:

    -
  • - aabb AABB - -

    Source to copy from

    -
  • -
- - +
+

Returns:

- -
+
+ AABB: +

The this object, for chainability

- -
+
+
+ + +
+

extend

-
(
    -
  • - aabb -
  • -
)
- - - - - - - -
- - -

- Defined in - - - - - src/collision/AABB.js:102 - + src/collision/AABB.js:115

- -
@@ -563,91 +494,198 @@

extend

-

Parameters:

-
    - +
      +
    • + aabb + AABB + + +
      + +
      + +
    • +
    +
+ + + +
+
+

getCorners

+ +
+ (
    +
  • + a +
  • +
  • + b +
  • +
  • + c +
  • +
  • + d +
  • +
  • + e +
  • +
  • + f +
  • +
  • + g +
  • +
  • + h +
  • +
) +
+ + + + + + + + +
+

+ Defined in + src/collision/AABB.js:204 +

+ + + +
+ +
+ +
+ +
+

Parameters:

+ +
    +
  • + a + Vec3 + + +
    + +
    + +
  • +
  • + b + Vec3 + + +
    + +
    + +
  • +
  • + c + Vec3 + + +
    + +
    + +
  • +
  • + d + Vec3 + + +
    + +
    + +
  • +
  • + e + Vec3 + + +
    + +
    + +
  • +
  • + f + Vec3 + + +
    + +
    + +
  • +
  • + g + Vec3 + + +
    + +
    + +
  • - - aabb - AABB - + h + Vec3 -
    -
  • -
- - - -
- -
+
+

overlaps

-
(
    -
  • - aabb -
  • -
)
- - Boolean - - - - - - -
- - -

- Defined in - - - - - src/collision/AABB.js:145 - + src/collision/AABB.js:158

- -
@@ -655,117 +693,71 @@

overlaps

-

Parameters:

    -
  • - aabb AABB - -
    -
  • -
- -

Returns:

- - Boolean: - -
- - -
- -
+
+

setFromPoints

-
(
    -
  • - points -
  • -
  • - position -
  • -
  • - quaternion -
  • -
  • - skinSize -
  • -
)
- - + + AABB + - - - - - -
- - -

- Defined in - - - - src/collision/AABB.js:40 -

- -
@@ -773,190 +765,282 @@

setFromPoints

-

Parameters:

    -
  • - points Array - -

    An array of Vec3's.

    -
  • -
  • - position Vec3 - -
    -
  • -
  • - quaternion Quaternion - -
    -
  • -
  • - skinSize Number - -
    -
  • -
- - +
+

Returns:

- -
+
+ AABB: +

The self object

-
- +
+ + +
+
+

toLocalFrame

+ +
+ (
    +
  • + frame +
  • +
  • + target +
  • +
) +
+ + + AABB + - -
-

Properties

- -
-

lowerBound

- Array - - - -
- - -

- Defined in - - - - - src/collision/AABB.js:17 - + src/collision/AABB.js:240

- - +
-

The lower bound of the bounding box.

+

Get the representation of an AABB in another frame.

- +
+

Parameters:

+ +
    +
  • + frame + Transform + + +
    + +
    + +
  • +
  • + target + AABB + + +
    + +
    + +
  • +
+
+ +
+

Returns:

+ +
+ AABB: +

The "target" AABB object.

+ +
+
- -
+
+

toWorldFrame

+ +
+ (
    +
  • + frame +
  • +
  • + target +
  • +
) +
+ + + AABB + + - -
-

upperBound

- Array - - - -
- - -

- Defined in - - - - - src/collision/AABB.js:27 - + src/collision/AABB.js:271

- - +
-

The upper bound of the bounding box.

+

Get the representation of an AABB in the global frame.

- +
+

Parameters:

+ +
    +
  • + frame + Transform + + +
    + +
    + +
  • +
  • + target + AABB + + +
    + +
    + +
  • +
+
+ +
+

Returns:

+ +
+ AABB: +

The "target" AABB object.

+ +
+
- -
+
- +
+

Properties

+ +
+

lowerBound

+ Vec3 + + + + + +
+

+ Defined in + src/collision/AABB.js:17 +

+ + +
+ +
+

The lower bound of the bounding box.

+ +
+ + + +
+
+

upperBound

+ Vec3 + + + + + +
+

+ Defined in + src/collision/AABB.js:27 +

+ + +
+ +
+

The upper bound of the bounding box.

+ +
+ + + +
- - -
-
diff --git a/docs/classes/ArrayCollisionMatrix.html b/docs/classes/ArrayCollisionMatrix.html index 039ac54dc..0c8715e16 100644 --- a/docs/classes/ArrayCollisionMatrix.html +++ b/docs/classes/ArrayCollisionMatrix.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
- -

- +

API Docs for: 0.6.1 @@ -27,383 +25,245 @@

- Show: - - - - - - - -
- - + Show: + + + + + + + +
+
-

ArrayCollisionMatrix Class

+

ArrayCollisionMatrix Class

- - - - - -
-

Collision "matrix". It's actually a triangular-shaped array of whether two bodies are touching this step, for reference next step

-

Constructor

-

ArrayCollisionMatrix

- - - () - - - - - - - - - - - - - - - - -
+

ArrayCollisionMatrix

- - -

- - Defined in - - + () - src/collision/ArrayCollisionMatrix.js:3 -

- - - -
- -
+ + +
+

+ Defined in + src/collision/ArrayCollisionMatrix.js:3 +

+ + + +
+ +
+ +
+ + + + +
- - - - - -
- -
- -

Item Index

-

Methods

- -

Properties

- - -
-

Methods

- -
+

get

-
(
    -
  • - i -
  • -
  • - j -
  • -
)
- - Number - - - - - - -
- - -

- Defined in - - - - src/collision/ArrayCollisionMatrix.js:18 -

- -
@@ -411,104 +271,63 @@

get

-

Parameters:

    -
  • - i Number - -
    -
  • -
  • - j Number - -
    -
  • -
- -

Returns:

- - Number: - -
- - -
- -
+
+

reset

- () - - - - - - - -
- - -

- Defined in - - - - src/collision/ArrayCollisionMatrix.js:54 -

- -
@@ -516,76 +335,42 @@

reset

- - - -
- -
+
+

set

-
(
    -
  • - i -
  • -
  • - j -
  • -
  • - value -
  • -
)
- - - - - - - -
- - -

- Defined in - - - - src/collision/ArrayCollisionMatrix.js:36 -

- -
@@ -593,117 +378,72 @@

set

-

Parameters:

    -
  • - i Number - -
    -
  • -
  • - j Number - -
    -
  • -
  • - value Number - -
    -
  • -
- - - -
- -
+
+

setNumObjects

-
(
    -
  • - n -
  • -
)
- - - - - - - -
- - -

- Defined in - - - - src/collision/ArrayCollisionMatrix.js:64 -

- -
@@ -711,99 +451,61 @@

setNumObjects

-

Parameters:

    -
  • - n Number - -
    -
  • -
- - - -
- +
- -

Properties

-
-

matrix

- Array - - - - - - - - - -
- - - -

- - Defined in - - - - - src/collision/ArrayCollisionMatrix.js:10 - -

- - - - -
- -
-

The matrix storage

- -
- - - - - - -
- - +

matrix

+ Array + + + + + +
+

+ Defined in + src/collision/ArrayCollisionMatrix.js:10 +

+ + +
+ +
+

The matrix storage

+ +
+ + + +
- - -
-
diff --git a/docs/classes/Body.html b/docs/classes/Body.html index e0afcb826..5c3633fba 100644 --- a/docs/classes/Body.html +++ b/docs/classes/Body.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
- -

- +

API Docs for: 0.6.1 @@ -27,949 +25,698 @@

- Show: - - - - - - - -
- - + Show: + + + + + + + +
+
-

Body Class

+

Body Class

- -
Extends EventTarget
- - - - -
-

Base class for all body types.

-

Constructor

-

Body

- - -
- (
    - -
  • - - [options] - -
  • - -
) -
- - - - - - - - - - - - - - - - -
+

Body

+ +
+ (
    +
  • + [options] +
  • +
) +
- - -

- - Defined in - - - src/objects/Body.js:12 -

- - - -
- -
-
- - -
-

Parameters:

- -
    - -
  • - - [options] - Object - optional - - - - -
    - -
    - - -
      - -
    • - - [position] - Vec3 - optional - - -
      - -
      - - -
    • - -
    • - - [velocity] - Vec3 - optional - - -
      - -
      - - -
    • - -
    • - - [angularVelocity] - Vec3 - optional - - -
      - -
      - - -
    • - -
    • - - [quaternion] - Quaternion - optional - - -
      - -
      - - -
    • - -
    • - - [mass] - Number - optional - - -
      - -
      - - -
    • - -
    • - - [type] - Number - optional - - -
      - -
      - - -
    • - -
    • - - [linearDamping] - Number - optional - - -
      - -
      - - -
    • - -
    - -
  • - -
-
- - - - - -
-

Example:

- -
-
var body = new Body({
-    mass: 1
-});
-var shape = new Sphere(1);
-body.addShape(shape);
-world.add(body);
- + +
+

+ Defined in + src/objects/Body.js:12 +

+ + + +
+ +
+
+ +
+

Parameters:

+ +
    +
  • + [options] + Object + optional + + +
    + +
    + +
      +
    • + [position] + Vec3 + optional + +
      + +
      + +
    • +
    • + [velocity] + Vec3 + optional + +
      + +
      + +
    • +
    • + [angularVelocity] + Vec3 + optional + +
      + +
      + +
    • +
    • + [quaternion] + Quaternion + optional + +
      + +
      + +
    • +
    • + [mass] + Number + optional + +
      + +
      + +
    • +
    • + [material] + Material + optional + +
      + +
      + +
    • +
    • + [type] + Number + optional + +
      + +
      + +
    • +
    • + [linearDamping=0.01] + Number + optional + +
      + +
      + +
    • +
    • + [angularDamping=0.01] + Number + optional + +
      + +
      + +
    • +
    • + [allowSleep=true] + Boolean + optional + +
      + +
      + +
    • +
    • + [sleepSpeedLimit=0.1] + Number + optional + +
      + +
      + +
    • +
    • + [sleepTimeLimit=1] + Number + optional + +
      + +
      + +
    • +
    • + [collisionFilterGroup=1] + Number + optional + +
      + +
      + +
    • +
    • + [collisionFilterMask=1] + Number + optional + +
      + +
      + +
    • +
    • + [fixedRotation=false] + Boolean + optional + +
      + +
      + +
    • +
    • + [shape] + Body + optional + +
      + +
      + +
    • +
    +
  • +
+
+ + + +
+

Example:

+ +
+
var body = new Body({
+            mass: 1
+        });
+        var shape = new Sphere(1);
+        body.addShape(shape);
+        world.add(body);
+        
+
+
- -
-
-

Item Index

- - -

Properties

- - -
-

Methods

- -
+

addEventListener

-
(
    -
  • - type -
  • -
  • - listener -
  • -
)
- - EventTarget - - - - - - -
- -

Inherited from EventTarget: - - - src/utils/EventTarget.js:15 -

- -
@@ -977,122 +724,165 @@

addEventListener

-

Parameters:

    -
  • - type String - -
    -
  • -
  • - listener Function - -
    -
  • -
- -

Returns:

- - EventTarget: -

The self object, for chainability.

-
- - +
+
+

addShape

- -
+
+ (
    +
  • + shape +
  • +
  • + offset +
  • +
  • + quaternion +
  • +
) +
+ + + Body + + + + + + + + +
+

+ Defined in + src/objects/Body.js:507 +

+ + + +
+ +
+

Add a shape to the body with a local offset and orientation.

+ +
+ +
+

Parameters:

+ +
    +
  • + shape + Shape + + +
    + +
    + +
  • +
  • + offset + Vec3 + + +
    + +
    + +
  • +
  • + quaternion + Quaternion + + +
    + +
    + +
  • +
+
+ +
+

Returns:

+ +
+ Body: +

The body object, for chainability.

+ +
+
+ + +
+

applyForce

-
(
    -
  • - force -
  • -
  • - worldPoint -
  • -
)
- - - - - - - -
- - -

- Defined in - - - - - src/objects/Body.js:597 - + src/objects/Body.js:637

- -
@@ -1100,110 +890,67 @@

applyForce

-

Parameters:

    -
  • - force Vec3 - -

    The amount of force to add.

    -
  • -
  • - worldPoint Vec3 - -

    A world point to apply the force on.

    -
  • -
- - - -
- -
+
+

applyImpulse

-
(
    -
  • - impulse -
  • -
  • - worldPoint -
  • -
)
- - - - - - - -
- - -

- Defined in - - - - - src/objects/Body.js:625 - + src/objects/Body.js:688

- -
@@ -1211,289 +958,313 @@

applyImpulse

-

Parameters:

    -
  • - impulse Vec3 - -

    The amount of impulse to add.

    -
  • -
  • - worldPoint Vec3 - -

    A world point to apply the force on.

    -
  • -
- - - -
- -
-

computeAABB

+
+
+

applyLocalForce

- - () - +
+ (
    +
  • + force +
  • +
  • + localPoint +
  • +
) +
- - - - - - -
- - -

- Defined in - - - - - src/objects/Body.js:522 - + src/objects/Body.js:665

- -
-

Updates the .aabb

+

Apply force to a local point in the body.

- +
+

Parameters:

+ +
    +
  • + force + Vec3 - - -
+
+

The force vector to apply, defined locally in the body frame.

+ +
+ + +
  • + localPoint + Vec3 + + +
    +

    A local point in the body to apply the force on.

    + +
    + +
  • + +
    - -
    -

    dispatchEvent

    - + +
    +
    +

    applyLocalImpulse

    +
    (
      -
    • - - event - + force +
    • +
    • + localPoint
    • -
    )
    - - - - EventTarget - - - - - - - -
    - - -

    Inherited from - EventTarget: - - - - src/utils/EventTarget.js:68 - +

    + Defined in + src/objects/Body.js:729

    - -
    -

    Emit an event.

    +

    Apply locally-defined impulse to a local point in the body.

    -

    Parameters:

      -
    • - - event - Object - + force + Vec3 -
      - -
      +

      The force vector to apply, defined locally in the body frame.

      - -
        - -
      • - - type - String - +
    -
    - + +
  • + localPoint + Vec3 + + +
    +

    A local point in the body to apply the force on.

    + +
    + +
  • + +
    + + + +
    +
    +

    computeAABB

    + + () + + + + + + + + +
    +

    + Defined in + src/objects/Body.js:562 +

    + + + +
    + +
    +

    Updates the .aabb

    + +
    + + + + +
    +
    +

    dispatchEvent

    + +
    + (
      +
    • + event +
    • +
    ) +
    + + + EventTarget + + + + + + + + +
    +

    Inherited from + EventTarget: + src/utils/EventTarget.js:68 +

    + + + +
    + +
    +

    Emit an event.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + event + Object + + +
      + +
      + +
        +
      • + type + String + +
        +
        -
      • -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    getVelocityAtWorldPoint

    -
    (
      -
    • - worldPoint -
    • -
    • - result -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:709 - + src/objects/Body.js:782

    - -
    @@ -1501,123 +1272,77 @@

    getVelocityAtWorldPoint

    -

    Parameters:

      -
    • - worldPoint Vec3 - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: -

    The result vector.

    -
    - - -
    - -
    +
    +

    hasEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - Boolean - - - - - - -
    - -

    Inherited from EventTarget: - - - src/utils/EventTarget.js:34 -

    - -
    @@ -1625,124 +1350,75 @@

    hasEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    pointToLocalFrame

    -
    (
      -
    • - worldPoint -
    • -
    • - result -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:432 - + src/objects/Body.js:450

    - -
    @@ -1750,124 +1426,75 @@

    pointToLocalFrame

    -

    Parameters:

      -
    • - worldPoint Vec3 - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    pointToWorldFrame

    -
    (
      -
    • - localPoint -
    • -
    • - result -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:446 - + src/objects/Body.js:477

    - -
    @@ -1875,121 +1502,75 @@

    pointToWorldFrame

    -

    Parameters:

      -
    • - localPoint Vec3 - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    removeEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - EventTarget - - - - - - -
    - -

    Inherited from EventTarget: - - - src/utils/EventTarget.js:50 -

    - -
    @@ -1997,106 +1578,65 @@

    removeEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    sleep

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:375 - + src/objects/Body.js:393

    - -
    @@ -2104,64 +1644,36 @@

    sleep

    - - - -
    - -
    +
    +

    sleepTick

    -
    (
      -
    • - time -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:393 - + src/objects/Body.js:411

    - -
    @@ -2169,78 +1681,47 @@

    sleepTick

    -

    Parameters:

      -
    • - time Number - -

      The world time in seconds

      -
    • -
    - - - -
    - -
    +
    +

    updateBoundingRadius

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:497 - + src/objects/Body.js:537

    - -
    @@ -2248,54 +1729,30 @@

    updateBoundingRadius

    - - - -
    - -
    +
    +

    updateInertiaWorld

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:568 - + src/objects/Body.js:608

    - -
    @@ -2303,109 +1760,61 @@

    updateInertiaWorld

    - - - -
    - -
    +
    +

    updateMassProperties

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:666 - + src/objects/Body.js:754

    - -
    -

    Should be called whenever you change the body mass.

    +

    Should be called whenever you change the body shape or mass.

    - - - -
    - -
    +
    +

    updateSolveMassProperties

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:416 - + src/objects/Body.js:434

    - -
    @@ -2413,2185 +1822,1292 @@

    updateSolveMassProperties

    - - - -
    - -
    -

    vectorToWorldFrame

    +
    +
    +

    vectorToLocalFrame

    -
    (
      -
    • - - localVector - + worldPoint
    • -
    • - result -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:460 - + src/objects/Body.js:464

    - -
    -

    Convert a local body point to world frame.

    +

    Convert a world vector to local body frame.

    -

    Parameters:

      -
    • - - localVector + worldPoint Vec3 - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    -

    wakeUp

    +
    +
    +

    vectorToWorldFrame

    - - () - +
    + (
      +
    • + localVector +
    • +
    • + result +
    • +
    ) +
    - + + Vec3 + - - - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:363 - + src/objects/Body.js:491

    - -
    -

    Wake the body up.

    +

    Convert a local body point to world frame.

    - +
    +

    Parameters:

    + +
      +
    • + localVector + Vec3 - - -
    +
    + +
    - + +
  • + result + Vec3 + + +
    + +
    + +
  • + +
    + +
    +

    Returns:

    + +
    + Vec3:
    - +
    + + +
    +
    +

    wakeUp

    + + () + - -
    -

    Properties

    - -
    -

    aabb

    - Vec3 - - - -
    - - -

    - Defined in - - - - - src/objects/Body.js:294 - + src/objects/Body.js:381

    - - +
    - +

    Wake the body up.

    +
    - - - -
    - - -
    -

    aabbNeedsUpdate

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:300 - -

    - - - - -
    - -
    -

    Indicates if the AABB needs to be updated before use.

    - -
    - - - - -
    +
    - -
    -

    allowSleep

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:162 - -

    - - - - -
    - -
    -

    If true, the body will automatically fall to sleep.

    - -
    - - - - - - -
    +
    +

    Properties

    - +
    +

    aabb

    + AABB + + + + + +
    +

    + Defined in + src/objects/Body.js:308 +

    + + +
    + +
    + +
    + + + +
    +
    +

    aabbNeedsUpdate

    + Boolean + + + + + +
    +

    + Defined in + src/objects/Body.js:314 +

    + + +
    + +
    +

    Indicates if the AABB needs to be updated before use.

    + +
    + + + +
    +
    +

    allowSleep

    + Boolean + + + + + +
    +

    + Defined in + src/objects/Body.js:172 +

    + + +
    + +
    +

    If true, the body will automatically fall to sleep.

    + +
    + +

    Default: true

    + + +
    -

    angularDamping

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:289 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    angularDamping

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:303 +

    + + +
    + +
    + +
    + + + +
    -

    angularVelocity

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:218 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    angularVelocity

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:231 +

    + + +
    + +
    + +
    + + + +
    -

    AWAKE

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:340 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    AWAKE

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:358 +

    + + +
    + +
    + +
    + + + +
    -

    collisionFilterGroup

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:65 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    collisionFilterGroup

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:74 +

    + + +
    + +
    + +
    + + + +
    -

    collisionFilterMask

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:70 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    collisionFilterMask

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:79 +

    + + +
    + +
    + +
    + + + +
    -

    collisionResponse

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:75 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:84 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    -

    DYNAMIC

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:314 - -

    - - - - -
    - -
    -

    A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.

    - -
    - - - - - - -
    - - +

    DYNAMIC

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:332 +

    + + +
    + +
    +

    A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.

    + +
    + + + +
    -

    fixedRotation

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:283 - -

    - - - - -
    - -
    -

    Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.

    - -
    - - - - - - -
    - - +

    fixedRotation

    + Boolean + + + + + +
    +

    + Defined in + src/objects/Body.js:296 +

    + + +
    + +
    +

    Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.

    + +
    + +

    Default: false

    + + +
    -

    force

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:119 - -

    - - - - -
    - -
    -

    Linear force on the body

    - -
    - - - - - - -
    - - +

    force

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:128 +

    + + +
    + +
    +

    Linear force on the body

    + +
    + + + +
    -

    inertia

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:255 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    inertia

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:268 +

    + + +
    + +
    + +
    + + + +
    -

    initAngularVelocity

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:228 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    initAngularVelocity

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:241 +

    + + +
    + +
    + +
    + + + +
    -

    initPosition

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:96 - -

    - - - - -
    - -
    -

    Initial position of the body

    - -
    - - - - - - -
    - - +

    initPosition

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:105 +

    + + +
    + +
    +

    Initial position of the body

    + +
    + + + +
    -

    initQuaternion

    - Quaternion - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:212 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    initQuaternion

    + Quaternion + + + + + +
    +

    + Defined in + src/objects/Body.js:225 +

    + + +
    + +
    + +
    + + + +
    -

    initVelocity

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:113 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    initVelocity

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:122 +

    + + +
    + +
    + +
    + + + +
    -

    invInertia

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:261 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    invInertia

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:274 +

    + + +
    + +
    + +
    + + + +
    -

    invInertiaSolve

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:273 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    invInertiaSolve

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:286 +

    + + +
    + +
    + +
    + + + +
    -

    invInertiaWorld

    - Mat3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:266 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    invInertiaWorld

    + Mat3 + + + + + +
    +

    + Defined in + src/objects/Body.js:279 +

    + + +
    + +
    + +
    + + + +
    -

    invInertiaWorldSolve

    - Mat3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:278 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    invInertiaWorldSolve

    + Mat3 + + + + + +
    +

    + Defined in + src/objects/Body.js:291 +

    + + +
    + +
    + +
    + + + +
    -

    invMass

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:134 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    invMass

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:144 +

    + + +
    + +
    + +
    + + + +
    -

    KINEMATIC

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:330 - -

    - - - - -
    - -
    -

    A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.

    - -
    - - - - - - -
    - - +

    KINEMATIC

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:348 +

    + + +
    + +
    +

    A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.

    + +
    + + + +
    -

    linearDamping

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:146 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    linearDamping

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:156 +

    + + +
    + +
    + +
    + + + +
    -

    mass

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:128 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    mass

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:137 +

    + + +
    + +
    + +
    + +

    Default: 0

    + + +
    -

    material

    - Material - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:140 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    material

    + Material + + + + + +
    +

    + Defined in + src/objects/Body.js:150 +

    + + +
    + +
    + +
    + + + +
    -

    position

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:81 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    position

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:90 +

    + + +
    + +
    + +
    + + + +
    -

    postStep

    - Function - - - deprecated - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:55 - -

    - - -

    Deprecated: Use World events instead

    - - - -
    - -
    -

    Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.

    - -
    - - - - - - -
    - - -
    -

    preStep

    - Function - - - deprecated - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:47 - -

    - - -

    Deprecated: Use World events instead

    - - - -
    - -
    -

    Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, "this" will refer to this Body object.

    - -
    - - - - - - -
    - - +

    postStep

    + Function + + deprecated + + + + +
    +

    + Defined in + src/objects/Body.js:64 +

    + +

    Deprecated: Use World events instead

    + +
    + +
    +

    Callback function that is used AFTER stepping the system. Inside the function, "this" will refer to this Body object.

    + +
    + + + + +
    +

    preStep

    + Function + + deprecated + + + + +
    +

    + Defined in + src/objects/Body.js:56 +

    + +

    Deprecated: Use World events instead

    + +
    + +
    +

    Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, "this" will refer to this Body object.

    + +
    + + + +
    -

    previousPosition

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:91 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    previousPosition

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:100 +

    + + +
    + +
    + +
    + + + +
    -

    quaternion

    - Quaternion - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:201 - -

    - - - - -
    - -
    -

    Orientation of the body

    - -
    - - - - - - -
    - - +

    quaternion

    + Quaternion + + + + + +
    +

    + Defined in + src/objects/Body.js:214 +

    + + +
    + +
    +

    Orientation of the body

    + +
    + + + +
    -

    shapeOffsets

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:243 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    shapeOffsets

    + Array + + + + + +
    +

    + Defined in + src/objects/Body.js:256 +

    + + +
    + +
    + +
    + + + +
    -

    shapeOrientations

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:249 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    shapeOrientations

    + Array + + + + + +
    +

    + Defined in + src/objects/Body.js:262 +

    + + +
    + +
    + +
    + + + +
    -

    shapes

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:237 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    shapes

    + Array + + + + + +
    +

    + Defined in + src/objects/Body.js:250 +

    + + +
    + +
    + +
    + + + +
    -

    SLEEPING

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:354 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    SLEEPING

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:372 +

    + + +
    + +
    + +
    + + + +
    -

    sleepSpeedLimit

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:176 - -

    - - - - -
    - -
    -

    If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.

    - -
    - - - - - - -
    - - +

    sleepSpeedLimit

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:187 +

    + + +
    + +
    +

    If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.

    + +
    + +

    Default: 0.1

    + + +
    -

    sleepState

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:169 - -

    - - - - -
    - -
    -

    Current sleep state.

    - -
    - - - - - - -
    - - +

    sleepState

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:180 +

    + + +
    + +
    +

    Current sleep state.

    + +
    + + + +
    -

    sleepTimeLimit

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:183 - -

    - - - - -
    - -
    -

    If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.

    - -
    - - - - - - -
    - - -
    -

    SLEEPY

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:347 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    sleepTimeLimit

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:195 +

    + + +
    + +
    +

    If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.

    + +
    + +

    Default: 1

    + + + +
    +

    SLEEPY

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:365 +

    + + +
    + +
    + +
    + + + +
    -

    STATIC

    - Number - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:322 - -

    - - - - -
    - -
    -

    A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.

    - -
    - - - - - - -
    - - +

    STATIC

    + Number + + + + + static + +
    +

    + Defined in + src/objects/Body.js:340 +

    + + +
    + +
    +

    A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.

    + +
    + + + +
    -

    torque

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:195 - -

    - - - - -
    - -
    -

    Rotational force on the body, around center of mass

    - -
    - - - - - - -
    - - +

    torque

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:208 +

    + + +
    + +
    +

    Rotational force on the body, around center of mass

    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:152 - -

    - - - - -
    - -
    -

    One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    + Defined in + src/objects/Body.js:162 +

    + + +
    + +
    +

    One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.

    + +
    + + + +
    -

    velocity

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:103 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    velocity

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Body.js:112 +

    + + +
    + +
    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Body.js:40 - -

    - - - - -
    - -
    -

    Reference to the world the body is living in

    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    + Defined in + src/objects/Body.js:49 +

    + + +
    + +
    +

    Reference to the world the body is living in

    + +
    + + + + - - - - diff --git a/docs/classes/Box.html b/docs/classes/Box.html index a08c86af0..2452db7a1 100644 --- a/docs/classes/Box.html +++ b/docs/classes/Box.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,579 +25,376 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Box Class

    +

    Box Class

    - -
    Extends Shape
    - -
    Defined in: src/shapes/Box.js:7
    - - -
    -

    A 3d box shape.

    -

    Constructor

    -

    Box

    - - -
    - (
      - -
    • - - halfExtents - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Box

    + +
    + (
      +
    • + halfExtents +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/shapes/Box.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/shapes/Box.js:7 +
      +
    • + halfExtents + Vec3 -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - halfExtents - Vec3 - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    -
    (
      -
    • - mass -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/Box.js:73 - + src/shapes/Box.js:80

    - -
    -

    Parameters:

      -
    • - mass Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    getSideNormals

    -
    (
      -
    • - - includeNegative - + sixTargetVectors
    • -
    • - quat -
    • -
    )
    - - Array - - - - - - -
    - - -

    - Defined in - - - - - src/shapes/Box.js:92 - + src/shapes/Box.js:99

    - -
    @@ -607,107 +402,68 @@

    getSideNormals

    -

    Parameters:

      -
    • - - includeNegative - Boolean - + sixTargetVectors + Array -
      -

      If true, this function returns 6 vectors. If false, it only returns 3 (but you get 6 by reversing those 3)

      +

      An array of 6 vectors, to store the resulting side normals in.

      -
    • -
    • - quat Quaternion - -

      Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame.

      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -715,66 +471,37 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    updateConvexPolyhedronRepresentation

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Box.js:39 -

    - -
    @@ -782,55 +509,33 @@

    updateConvexPolyhedronRepresentation

    - - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -838,258 +543,200 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    -

    convexPolyhedronRepresentation

    - ConvexPolyhedron - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Box.js:26 - -

    - - - - -
    - -
    -

    Used by the contact generator to make contacts with other convex polyhedra for example

    - -
    - - - - - - -
    - - +

    convexPolyhedronRepresentation

    + ConvexPolyhedron + + + + + +
    +

    + Defined in + src/shapes/Box.js:26 +

    + + +
    + +
    +

    Used by the contact generator to make contacts with other convex polyhedra for example

    + +
    + + + +
    -

    halfExtents

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Box.js:20 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    halfExtents

    + Vec3 + + + + + +
    +

    + Defined in + src/shapes/Box.js:20 +

    + + +
    + +
    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    - - -
    - diff --git a/docs/classes/Broadphase.html b/docs/classes/Broadphase.html index 97f512d4d..0df398b70 100644 --- a/docs/classes/Broadphase.html +++ b/docs/classes/Broadphase.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,432 +25,276 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Broadphase Class

    +

    Broadphase Class

    - - - - - -
    -

    Base class for broadphase implementations

    -

    Constructor

    -

    Broadphase

    - - - () - - - - - - - - - - - - - - - - -
    +

    Broadphase

    - - -

    - - Defined in - - + () - src/collision/Broadphase.js:9 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/collision/Broadphase.js:9 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    aabbQuery

    -
    (
      -
    • - world -
    • -
    • - aabb -
    • - +
    • + result +
    )
    - - Array - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:197 -

    - -
    @@ -460,124 +302,86 @@

    aabbQuery

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - aabb AABB - -
      -
    • - +
    • + result + Array + + +
      +

      An array to store resulting bodies in.

      + +
      + +
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    boundingSphereCheck

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Boolean - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:183 -

    - -
    @@ -585,126 +389,75 @@

    boundingSphereCheck

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    collisionPairs

    -
    (
      -
    • - world -
    • -
    • - p1 -
    • -
    • - p2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:37 -

    - -
    @@ -712,138 +465,84 @@

    collisionPairs

    -

    Parameters:

      -
    • - world World - -

      The world to search in

      -
    • -
    • - p1 Array - -

      Empty array to be filled with body objects

      -
    • -
    • - p2 Array - -

      Empty array to be filled with body objects

      -
    • -
    - - - -
    - -
    +
    +

    doBoundingBoxBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:112 -

    - -
    @@ -851,150 +550,91 @@

    doBoundingBoxBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingSphereBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:89 -

    - -
    @@ -1002,152 +642,93 @@

    doBoundingSphereBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -

      bodyA is appended to this array if intersection

      -
    • -
    • - pairs2 Array - -

      bodyB is appended to this array if intersection

      -
    • -
    - - - -
    - -
    +
    +

    intersectionTest

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:73 -

    - -
    @@ -1155,138 +736,85 @@

    intersectionTest

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    makePairsUnique

    -
    (
      -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:135 -

    - -
    @@ -1294,112 +822,68 @@

    makePairsUnique

    -

    Parameters:

      -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    needBroadphaseCollision

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Bool - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:48 -

    - -
    @@ -1407,114 +891,69 @@

    needBroadphaseCollision

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Bool: - -
    - - -
    - -
    +
    +

    setWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/Broadphase.js:175 -

    - -
    @@ -1522,189 +961,111 @@

    setWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    dirty

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/Broadphase.js:30 - -

    - - - - -
    - -
    -

    Set to true if the objects in the world moved.

    - -
    - - - - - - -
    - - +

    dirty

    + Boolean + + + + + +
    +

    + Defined in + src/collision/Broadphase.js:30 +

    + + +
    + +
    +

    Set to true if the objects in the world moved.

    + +
    + + + +
    -

    useBoundingBoxes

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/Broadphase.js:23 - -

    - - - - -
    - -
    -

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    - -
    - - - - - - -
    - - +

    useBoundingBoxes

    + Boolean + + + + + +
    +

    + Defined in + src/collision/Broadphase.js:23 +

    + + +
    + +
    +

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/Broadphase.js:16 - -

    - - - - -
    - -
    -

    The world to search for collisions in.

    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    + Defined in + src/collision/Broadphase.js:16 +

    + + +
    + +
    +

    The world to search for collisions in.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/ConeEquation.html b/docs/classes/ConeEquation.html new file mode 100644 index 000000000..d2f07a3c8 --- /dev/null +++ b/docs/classes/ConeEquation.html @@ -0,0 +1,1079 @@ + + + + + ConeEquation - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    ConeEquation Class

    +
    + +
    + Extends Equation +
    + + + + +
    + + +
    +

    Cone equation. Works to keep the given body world vectors aligned, or tilted within a given angle from each other.

    + +
    + +
    +

    Constructor

    +
    +

    ConeEquation

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options.axisA] +
    • +
    • + [options.axisB] +
    • +
    • + [options.angle] +
    • +
    • + [options.maxForce=1e6] +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/equations/ConeEquation.js:7 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + bodyA + Body + + +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options.axisA] + Vec3 + optional + + +
      +

      Local axis in A

      + +
      + +
    • +
    • + [options.axisB] + Vec3 + optional + + +
      +

      Local axis in B

      + +
      + +
    • +
    • + [options.angle] + Vec3 + optional + + +
      +

      The "cone angle" to keep

      + +
      + +
    • +
    • + [options.maxForce=1e6] + Number + optional + + +
      + +
      + +
    • +
    +
    + + + +
    +
    + +
    + + +
    +
    +

    Item Index

    + +
    +

    Methods

    + + +
    + +
    +

    Properties

    + + +
    + + +
    + +
    +

    Methods

    + +
    +

    addToWlambda

    + +
    + (
      +
    • + deltalambda +
    • +
    ) +
    + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:228 +

    + + + +
    + +
    +

    Add constraint velocity to the bodies.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + deltalambda + Number + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    computeB

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:95 +

    + + + +
    + +
    +

    Computes the RHS of the SPOOK equation

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeGiMf

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:159 +

    + + + +
    + +
    +

    Computes Ginv(M)f, where M is the mass matrix with diagonal blocks for each body, and f are the forces on the bodies.

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeGiMGt

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:191 +

    + + + +
    + +
    +

    Computes Ginv(M)G'

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeGq

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:107 +

    + + + +
    + +
    +

    Computes G*q, where q are the generalized body coordinates

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeGW

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:124 +

    + + + +
    + +
    +

    Computes G*W, where W are the body velocities

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeGWlambda

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:142 +

    + + + +
    + +
    +

    Computes G*Wlambda, where W are the body velocities

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    computeInvC

    + +
    + (
      +
    • + eps +
    • +
    ) +
    + + + Number + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:262 +

    + + + +
    + +
    +

    Compute the denominator part of the SPOOK equation: C = Ginv(M)G' + eps

    + +
    + +
    +

    Parameters:

    + +
      +
    • + eps + Number + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    setSpookParams

    + + () + + + + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:82 +

    + + + +
    + +
    +

    Recalculates a,b,eps.

    + +
    + + + + +
    +
    + +
    +

    Properties

    + +
    +

    a

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    angle

    + Number + + + + + +
    +

    + Defined in + src/equations/ConeEquation.js:29 +

    + + +
    + +
    +

    The cone angle to keep

    + +
    + + + +
    +
    +

    b

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    bi

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bj

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    +
    +

    eps

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    +
    +

    maxForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    +
    +

    minForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/ConeTwistConstraint.html b/docs/classes/ConeTwistConstraint.html new file mode 100644 index 000000000..b4bfe32bf --- /dev/null +++ b/docs/classes/ConeTwistConstraint.html @@ -0,0 +1,788 @@ + + + + + ConeTwistConstraint - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    ConeTwistConstraint Class

    +
    + + + + + + +
    + + +
    + +
    + +
    +

    Constructor

    +
    +

    ConeTwistConstraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options] +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/constraints/ConeTwistConstraint.js:10 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + bodyA + Body + + +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [pivotA] + Vec3 + optional + +
        + +
        + +
      • +
      • + [pivotB] + Vec3 + optional + +
        + +
        + +
      • +
      • + [axisA] + Vec3 + optional + +
        + +
        + +
      • +
      • + [axisB] + Vec3 + optional + +
        + +
        + +
      • +
      • + [maxForce=1e6] + Number + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + + + +
    +
    + +
    + + +
    +
    +

    Item Index

    + +
    +

    Methods

    + + +
    + +
    +

    Properties

    + + +
    + + +
    + +
    +

    Methods

    + +
    +

    disable

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:80 +

    + + + +
    + +
    +

    Disables all equations in the constraint.

    + +
    + + + + +
    +
    +

    enable

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:69 +

    + + + +
    + +
    +

    Enables all equations in the constraint.

    + +
    + + + + +
    +
    +

    update

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:61 +

    + + + +
    + +
    +

    Update all the equations with data.

    + +
    + + + + +
    +
    + +
    +

    Properties

    + +
    +

    bodyA

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    coneEquation

    + ConeEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    equationX

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationY

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationZ

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    +
    +

    pivotA

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyA.

    + +
    + + + +
    +
    +

    pivotB

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyB.

    + +
    + + + +
    +
    +

    twistEquation

    + RotationalEquation + + + + + + + +
    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Constraint.html b/docs/classes/Constraint.html index 4e2357108..f835f2c1f 100644 --- a/docs/classes/Constraint.html +++ b/docs/classes/Constraint.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,731 +25,521 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Constraint Class

    +

    Constraint Class

    - - - - - -
    -

    Constraint base class

    -

    Constructor

    -

    Constraint

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - bodyB - -
    • - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Constraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/constraints/Constraint.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/constraints/Constraint.js:5 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [collideConnected=true] + Boolean + optional + +
        + +
        + +
      • +
      • + [wakeUpBodies=true] + Boolean + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - Body - - - - -
      - -
      - - -
    • - -
    • - - bodyB - Body - - - - -
      - -
      - - -
    • - -
    • - - [options] - Object - optional - - - - -
      - -
      - - -
        - -
      • - - [collideConnected=true] - Boolean - optional - - -
        - -
        - - -
      • - -
      • - - [wakeUpBodies=true] - Boolean - optional - - -
        - -
        - - -
      • - -
      - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    -

    update

    +
    +

    disable

    - () - - - - - - - -
    - -
    - - +

    Disables all equations in the constraint.

    - - - -
    - - -
    - - - -
    -

    Properties

    - - -
    -

    bodyA

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/constraints/Constraint.js:29 - -

    - - - -
    -
    - -
    - - -
    +
    +

    enable

    - -
    -

    bodyB

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/constraints/Constraint.js:34 - -

    - - + () - -
    -
    - -
    - - - -
    - -
    -

    collideConnected

    - Boolean - - - - - - -
    -

    Set to true if you want the bodies to collide when they are connected.

    +

    Enables all equations in the constraint.

    - - - - - -
    - - -
    -

    equations

    - Array - - - - - - -
    - - - -

    - - Defined in - - - - - src/constraints/Constraint.js:22 - -

    - - - - -
    - -
    -

    Equations to be solved in this constraint

    - -
    +
    +
    +

    update

    - + () - - -
    - -
    -

    id

    - Number - - - -
    - +

    Update all the equations with data.

    +
    - - - +
    +
    - +
    +

    Properties

    + +
    +

    bodyA

    + Body + + + + + +
    +

    + Defined in + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    + Defined in + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    + Defined in + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    + Defined in + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    + Defined in + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/ContactEquation.html b/docs/classes/ContactEquation.html index 4eeef09ec..f2abf9b9d 100644 --- a/docs/classes/ContactEquation.html +++ b/docs/classes/ContactEquation.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,540 +25,353 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    ContactEquation Class

    +

    ContactEquation Class

    - -
    Extends Equation
    - - - - -
    -

    Contact/non-penetration constraint equation

    -

    Constructor

    -

    ContactEquation

    - - -
    - (
      - -
    • - - bj - -
    • - -
    • - - bi - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    ContactEquation

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/equations/ContactEquation.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/equations/ContactEquation.js:7 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bj - Body - - - - -
      - -
      - - -
    • - -
    • - - bi - Body - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWlambda

    -
    (
      -
    • - deltalambda -
    • -
    )
    - - - - - - - -
    @@ -568,78 +379,49 @@

    addToWlambda

    -

    Parameters:

      -
    • - deltalambda Number - -
      - +
      -
    • -
    - - - -
    - -
    +
    +

    computeB

    - () - - Number - - - - - - -
    @@ -647,67 +429,40 @@

    computeB

    - -

    Returns:

    - - Number: - -
    - - +
    +
    +

    computeGiMf

    - -
    -

    computeGiMf

    - - () - - Number - - - - - - -
    @@ -715,67 +470,40 @@

    computeGiMf

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMGt

    - () - - Number - - - - - - -
    @@ -783,67 +511,40 @@

    computeGiMGt

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGq

    - () - - Number - - - - - - -
    @@ -851,67 +552,40 @@

    computeGq

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGW

    - () - - Number - - - - - - -
    @@ -919,67 +593,40 @@

    computeGW

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGWlambda

    - () - - Number - - - - - - -
    @@ -987,77 +634,46 @@

    computeGWlambda

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeInvC

    -
    (
      -
    • - eps -
    • -
    )
    - - Number - - - - - - -
    @@ -1065,631 +681,458 @@

    computeInvC

    -

    Parameters:

      -
    • - eps Number - -
      - +
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    -

    setSpookParams

    +
    +
    +

    getImpactVelocityAlongNormal

    - () - - + + Number + - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:76 - +

    + Defined in + src/equations/ContactEquation.js:113

    - -
    -

    Recalculates a,b,eps.

    +

    Get the current relative velocity in the contact point.

    - - - - -
    +
    +

    Returns:

    - +
    + Number:
    - - - -
    -

    Properties

    - - -
    -

    a

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:41 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - +
    - -
    +
    +

    setSpookParams

    - -
    -

    b

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:47 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - + () - - -
    - -
    -

    bi

    - Body - - - -
    - -

    Inherited from - Equation: - - - - src/equations/Equation.js:29 - + Equation: + src/equations/Equation.js:82

    - - -
    -
    -
    - - - - - -
    - - -
    -

    bj

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:35 - -

    - - +
    +

    Recalculates a,b,eps.

    -
    -
    - -
    - - -
    +
    - -
    -

    eps

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:53 - -

    - - - - -
    +
    +

    Properties

    -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +
    +

    a

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    b

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    bi

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bj

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    +
    +

    eps

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - -

    Inherited from - - Equation - - - but overwritten in - - - - src/equations/Equation.js:59 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    -

    maxForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    minForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    minForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    -

    ni

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/ContactEquation.js:39 - -

    - - - - -
    - -
    -

    Contact normal, pointing out of body i.

    - -
    - - - - - - -
    - - +

    ni

    + Vec3 + + + + + +
    +

    + Defined in + src/equations/ContactEquation.js:38 +

    + + +
    + +
    +

    Contact normal, pointing out of body i.

    + +
    + + + +
    -

    restitution

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/ContactEquation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    restitution

    + Number + + + + + +
    +

    + Defined in + src/equations/ContactEquation.js:20 +

    + + +
    + +
    + +
    + + + +
    -

    ri

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/ContactEquation.js:25 - -

    - - - - -
    - -
    -

    World-oriented vector that goes from the center of bi to the contact point.

    - -
    - - - - - - -
    - - +

    ri

    + Vec3 + + + + + +
    +

    + Defined in + src/equations/ContactEquation.js:26 +

    + + +
    + +
    +

    World-oriented vector that goes from the center of bi to the contact point.

    + +
    + + + +
    -

    rj

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/ContactEquation.js:31 - -

    - - - - -
    - -
    -

    World-oriented vector that starts in body j position and goes to the contact point.

    - -
    - - - - - - -
    - - +

    rj

    + Vec3 + + + + + +
    +

    + Defined in + src/equations/ContactEquation.js:32 +

    + + +
    + +
    +

    World-oriented vector that starts in body j position and goes to the contact point.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/ContactMaterial.html b/docs/classes/ContactMaterial.html index 3507b249b..a01ab3430 100644 --- a/docs/classes/ContactMaterial.html +++ b/docs/classes/ContactMaterial.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,869 +25,535 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    ContactMaterial Class

    +

    ContactMaterial Class

    - - - - - -
    -

    Defines what happens when two materials meet.

    -

    Constructor

    -

    ContactMaterial

    - - -
    - (
      - -
    • - - m1 - -
    • - -
    • - - m2 - -
    • - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    ContactMaterial

    + +
    + (
      +
    • + m1 +
    • +
    • + m2 +
    • +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in - - - src/material/ContactMaterial.js:5 -

    - - - -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - m1 - Material - - - - -
      - -
      - - -
    • - -
    • - - m2 - Material - - - - -
      - -
      - - -
    • - -
    • - - [options] - Object - optional - - - - -
      - -
      - - -
        - -
      • - - [friction=0.3] - Number - optional - - -
        - -
        - - -
      • - -
      • - - [restitution=0.3] - Number - optional - - -
        - -
        - - -
      • - -
      • - - [contactEquationStiffness=1e7] - Number - optional - - -
        - -
        - - -
      • - -
      • - - [contactEquationRelaxation=3] - Number - optional - - -
        - -
        - - -
      • - -
      • - - [frictionEquationStiffness=1e7] - Number - optional - - -
        - -
        - - -
      • - -
      • - - [frictionEquationRelaxation=3] - Number - optional - - -
        - -
        - - -
      • - -
      - -
    • - -
    + +
    +

    + Defined in + src/material/ContactMaterial.js:5 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + m1 + Material + + +
      + +
      + +
    • +
    • + m2 + Material + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [friction=0.3] + Number + optional + +
        + +
        + +
      • +
      • + [restitution=0.3] + Number + optional + +
        + +
        + +
      • +
      • + [contactEquationStiffness=1e7] + Number + optional + +
        + +
        + +
      • +
      • + [contactEquationRelaxation=3] + Number + optional + +
        + +
        + +
      • +
      • + [frictionEquationStiffness=1e7] + Number + optional + +
        + +
        + +
      • +
      • + [frictionEquationRelaxation=3] + Number + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + + +
    - - - - - -
    -
    -

    Item Index

    - - - - -
    - -

    Properties

    -
    -

    contactEquationRelaxation

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:60 - -

    - - - - -
    - -
    -

    Relaxation time of the produced contact equations

    - -
    - - - - - - -
    - - +

    contactEquationRelaxation

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:60 +

    + + +
    + +
    +

    Relaxation time of the produced contact equations

    + +
    + + + +
    -

    contactEquationStiffness

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:54 - -

    - - - - -
    - -
    -

    Stiffness of the produced contact equations

    - -
    - - - - - - -
    - - +

    contactEquationStiffness

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:54 +

    + + +
    + +
    +

    Stiffness of the produced contact equations

    + +
    + + + +
    -

    friction

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:42 - -

    - - - - -
    - -
    -

    Friction coefficient

    - -
    - - - - - - -
    - - +

    friction

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:42 +

    + + +
    + +
    +

    Friction coefficient

    + +
    + + + +
    -

    frictionEquationRelaxation

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:72 - -

    - - - - -
    - -
    -

    Relaxation time of the produced friction equations

    - -
    - - - - - - -
    - - +

    frictionEquationRelaxation

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:72 +

    + + +
    + +
    +

    Relaxation time of the produced friction equations

    + +
    + + + +
    -

    frictionEquationStiffness

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:66 - -

    - - - - -
    - -
    -

    Stiffness of the produced friction equations

    - -
    - - - - - - -
    - - +

    frictionEquationStiffness

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:66 +

    + + +
    + +
    +

    Stiffness of the produced friction equations

    + +
    + + + +
    -

    id

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:29 - -

    - - - - -
    - -
    -

    Identifier of this material

    - -
    - - - - - - -
    - - +

    id

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:29 +

    + + +
    + +
    +

    Identifier of this material

    + +
    + + + +
    -

    materials

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:35 - -

    - - - - -
    - -
    -

    Participating materials

    - -
    - - - - - - -
    - - +

    materials

    + Array + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:35 +

    + + +
    + +
    +

    Participating materials

    + +
    + + + +
    -

    restitution

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/ContactMaterial.js:48 - -

    - - - - -
    - -
    -

    Restitution coefficient

    - -
    - - - - - - -
    - - +

    restitution

    + Number + + + + + +
    +

    + Defined in + src/material/ContactMaterial.js:48 +

    + + +
    + +
    +

    Restitution coefficient

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/ConvexPolyhedron.html b/docs/classes/ConvexPolyhedron.html index 6faed45fc..63d853bb4 100644 --- a/docs/classes/ConvexPolyhedron.html +++ b/docs/classes/ConvexPolyhedron.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,1135 +25,712 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    ConvexPolyhedron Class

    +

    ConvexPolyhedron Class

    - -
    Extends Shape
    - - - - -
    -

    A set of polygons describing a convex shape.

    -

    Constructor

    -

    ConvexPolyhedron

    - - -
    - (
      - -
    • - - points - -
    • - -
    • - - faces - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    ConvexPolyhedron

    + +
    + (
      +
    • + points +
    • +
    • + faces +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/shapes/ConvexPolyhedron.js:8 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/shapes/ConvexPolyhedron.js:8 +
      +
    • + points + Array -

      - - - +
      +

      An array of Vec3's

      + +
      + +
    • +
    • + faces + Array + + +
      +

      Array of integer arrays, describing which vertices that is included in each face.

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - points - Array - - - - -
      -

      An array of Vec3's

      - -
      - - -
    • - -
    • - - faces - Array - - - - -
      -

      Array of integer arrays, describing which vertices that is included in each face.

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    -
    (
      -
    • - mass -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:393 - + src/shapes/ConvexPolyhedron.js:413

    - -
    -

    Parameters:

      -
    • - mass Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    calculateWorldAABB

    -
    (
      -
    • - pos -
    • -
    • - quat -
    • -
    • - min -
    • -
    • - max -
    • -
    )
    - - - - - - - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    clipAgainstHull

    -
    (
      -
    • - posA -
    • -
    • - quatA -
    • -
    • - hullB -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    • - separatingNormal -
    • -
    • - minDist -
    • -
    • - maxDist -
    • -
    • - result -
    • -
    )
    - - - - - - - -
    -

    Parameters:

      -
    • - posA Vec3 - -
      -
    • -
    • - quatA Quaternion - -
      -
    • -
    • - hullB ConvexPolyhedron - -
      -
    • -
    • - posB Vec3 - -
      -
    • -
    • - quatB Quaternion - -
      -
    • -
    • - separatingNormal Vec3 - -
      -
    • -
    • - minDist Number - -

      Clamp distance

      -
    • -
    • - maxDist Number - -
      -
    • -
    • - result Array - -

      The an array of contact point objects, see clipFaceAgainstHull

      -
    • -
    - - - -
    - -
    +
    +

    clipFaceAgainstHull

    -
    (
      -
    • - separatingNormal -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - worldVertsB1 -
    • -
    • - minDist -
    • -
    • - maxDist -
    • -
    • - Array -
    • -
    )
    - - - - - - - -
    @@ -1163,198 +738,124 @@

    clipFaceAgainstHull

    -

    Parameters:

      -
    • - separatingNormal Vec3 - -
      -
    • -
    • - posA Vec3 - -
      -
    • -
    • - quatA Quaternion - -
      -
    • -
    • - worldVertsB1 Array - -

      An array of Vec3 with vertices in the world frame.

      -
    • -
    • - minDist Number - -

      Distance clamping

      -
    • -
    • - maxDist Number - -
      -
    • -
    • - Array Object - -

      result Array to store resulting contact points in. Will be objects with properties: point, depth, normal. These are represented in world coordinates.

      -
    • -
    - - - -
    - -
    +
    +

    clipFaceAgainstPlane

    -
    (
      -
    • - inVertices -
    • -
    • - outVertices -
    • -
    • - planeNormal -
    • -
    • - planeConstant -
    • -
    )
    - - - - - - - -
    @@ -1362,123 +863,77 @@

    clipFaceAgainstPlane

    -

    Parameters:

      -
    • - inVertices Array - -
      -
    • -
    • - outVertices Array - -
      -
    • -
    • - planeNormal Vec3 - -
      -
    • -
    • - planeConstant Number - -

      The constant in the mathematical plane equation

      -
    • -
    - - - -
    - -
    +
    +

    computeEdges

    - () - - - - - - - -
    @@ -1486,54 +941,30 @@

    computeEdges

    - - - -
    - -
    +
    +

    computeNormals

    - () - - - - - - - -
    @@ -1541,64 +972,36 @@

    computeNormals

    - - - -
    - -
    +
    +

    computeWorldFaceNormals

    -
    (
      -
    • - quat -
    • -
    )
    - - - - - - - -
    @@ -1606,121 +1009,70 @@

    computeWorldFaceNormals

    -

    Parameters:

    - - - -
    - -
    +
    +

    findSeparatingAxis

    -
    (
      -
    • - hullB -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    • - target -
    • -
    )
    - - Bool - - - - - - -
    @@ -1728,181 +1080,115 @@

    findSeparatingAxis

    -

    Parameters:

    - -

    Returns:

    - - Bool: -

    Returns false if a separation is found, else true

    -
    - - -
    - -
    +
    +

    getAveragePointLocal

    -
    (
      -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    @@ -1910,105 +1196,62 @@

    getAveragePointLocal

    -

    Parameters:

      -
    • - target Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    getFaceNormal

    -
    (
      -
    • - i -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    @@ -2016,122 +1259,72 @@

    getFaceNormal

    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    getFaceNormal

    -
    (
      -
    • - va -
    • -
    • - vb -
    • -
    • - vc -
    • -
    • - target -
    • -
    )
    - - - - - - static - - -
    @@ -2139,240 +1332,148 @@

    getFaceNormal

    -

    Parameters:

    - - - -
    - -
    +
    +

    getPlaneConstantOfFace

    -
    (
      -
    • - face_i -
    • -
    )
    - - Number - - - - - - -
    -

    Parameters:

      -
    • - face_i Number - -

      Index of the face

      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    pointIsInside

    -
    (
      -
    • - p -
    • -
    )
    - - Boolean - - - - - - -
    @@ -2380,126 +1481,73 @@

    pointIsInside

    -

    Parameters:

      -
    • - p Vec3 - -

      A point given in local coordinates

      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    project

    -
    (
      -
    • - hull -
    • -
    • - axis -
    • -
    • - pos -
    • -
    • - quat -
    • -
    • - result -
    • -
    )
    - - - - - - static - - -
    @@ -2507,182 +1555,111 @@

    project

    -

    Parameters:

      -
    • - hull ConvexPolyhedron - -
      -
    • -
    • - axis Vec3 - -
      -
    • -
    • - pos Vec3 - -
      -
    • -
    • - quat Quaternion - -
      -
    • -
    • - result Array - -

      result[0] and result[1] will be set to maximum and minimum, respectively.

      -
    • -
    - - - -
    - -
    +
    +

    testSepAxis

    -
    (
      -
    • - axis -
    • -
    • - hullB -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    )
    - - - Float + Number - - - - - - -
    @@ -2690,182 +1667,114 @@

    testSepAxis

    -

    Parameters:

    - -

    Returns:

    - - - Float: - + Number:

    The overlap depth, or FALSE if no penetration.

    -
    - - -
    - -
    +
    +

    transformAllPoints

    -
    (
      -
    • - offset -
    • -
    • - quat -
    • -
    )
    - - - - - - - -
    @@ -2873,150 +1782,95 @@

    transformAllPoints

    -

    Parameters:

    - - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:707 - + src/shapes/ConvexPolyhedron.js:709

    - -
    - - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:762 - + src/shapes/ConvexPolyhedron.js:764

    - -
    @@ -3024,349 +1878,276 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    -

    faceNormals

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/ConvexPolyhedron.js:49 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    faceNormals

    + Array + + + + + +
    +

    + Defined in + src/shapes/ConvexPolyhedron.js:49 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    -

    faces

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/ConvexPolyhedron.js:42 - -

    - - - - -
    - -
    -

    Array of integer arrays, indicating which vertices each face consists of

    - -
    - - - - - - -
    - - +

    faces

    + Array + + + + + +
    +

    + Defined in + src/shapes/ConvexPolyhedron.js:42 +

    + + +
    + +
    +

    Array of integer arrays, indicating which vertices each face consists of

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    +
    +

    uniqueAxes

    + Array + + + + + +
    +

    + Defined in + src/shapes/ConvexPolyhedron.js:67 +

    + + +
    + +
    +

    If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.

    + +
    + + + +
    -

    uniqueEdges

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/ConvexPolyhedron.js:60 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    uniqueEdges

    + Array + + + + + +
    +

    + Defined in + src/shapes/ConvexPolyhedron.js:60 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    -

    vertices

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/ConvexPolyhedron.js:32 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    vertices

    + Array + + + + + +
    +

    + Defined in + src/shapes/ConvexPolyhedron.js:32 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    - - - - diff --git a/docs/classes/Cylinder.html b/docs/classes/Cylinder.html index c08e4e4de..070c35267 100644 --- a/docs/classes/Cylinder.html +++ b/docs/classes/Cylinder.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,1148 +25,726 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Cylinder Class

    +

    Cylinder Class

    - - - - - - -
    -
    -

    Constructor

    -

    Cylinder

    - - -
    - (
      - -
    • - - radiusTop - -
    • - -
    • - - radiusBottom - -
    • - -
    • - - height - -
    • - -
    • - - numSegments - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Cylinder

    + +
    + (
      +
    • + radiusTop +
    • +
    • + radiusBottom +
    • +
    • + height +
    • +
    • + numSegments +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/shapes/Cylinder.js:8 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/shapes/Cylinder.js:8 +
      +
    • + radiusTop + Number -

      - - - +
      + +
      + +
    • +
    • + radiusBottom + Number + + +
      + +
      + +
    • +
    • + height + Number + + +
      + +
      + +
    • +
    • + numSegments + Number + + +
      +

      The number of segments to build the cylinder out of

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - radiusTop - Number - - - - -
      - -
      - - -
    • - -
    • - - radiusBottom - Number - - - - -
      - -
      - - -
    • - -
    • - - height - Number - - - - -
      - -
      - - -
    • - -
    • - - numSegments - Number - - - - -
      -

      The number of segments to build the cylinder out of

      - -
      - - -
    • - -
    - - - - - -
    -
    -
    -

    Methods

    - -
    +

    calculateLocalInertia

    -
    (
      -
    • - mass -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:393 - + src/shapes/ConvexPolyhedron.js:413

    - -
    -

    Parameters:

      -
    • - mass Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    calculateWorldAABB

    -
    (
      -
    • - pos -
    • -
    • - quat -
    • -
    • - min -
    • -
    • - max -
    • -
    )
    - - - - - - - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    clipAgainstHull

    -
    (
      -
    • - posA -
    • -
    • - quatA -
    • -
    • - hullB -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    • - separatingNormal -
    • -
    • - minDist -
    • -
    • - maxDist -
    • -
    • - result -
    • -
    )
    - - - - - - - -
    -

    Parameters:

      -
    • - posA Vec3 - -
      -
    • -
    • - quatA Quaternion - -
      -
    • -
    • - hullB ConvexPolyhedron - -
      -
    • -
    • - posB Vec3 - -
      -
    • -
    • - quatB Quaternion - -
      -
    • -
    • - separatingNormal Vec3 - -
      -
    • -
    • - minDist Number - -

      Clamp distance

      -
    • -
    • - maxDist Number - -
      -
    • -
    • - result Array - -

      The an array of contact point objects, see clipFaceAgainstHull

      -
    • -
    - - - -
    - -
    +
    +

    clipFaceAgainstHull

    -
    (
      -
    • - separatingNormal -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - worldVertsB1 -
    • -
    • - minDist -
    • -
    • - maxDist -
    • -
    • - Array -
    • -
    )
    - - - - - - - -
    @@ -1176,195 +752,124 @@

    clipFaceAgainstHull

    -

    Parameters:

      -
    • - separatingNormal Vec3 - -
      -
    • -
    • - posA Vec3 - -
      -
    • -
    • - quatA Quaternion - -
      -
    • -
    • - worldVertsB1 Array - -

      An array of Vec3 with vertices in the world frame.

      -
    • -
    • - minDist Number - -

      Distance clamping

      -
    • -
    • - maxDist Number - -
      -
    • -
    • - Array Object - -

      result Array to store resulting contact points in. Will be objects with properties: point, depth, normal. These are represented in world coordinates.

      -
    • -
    - - - -
    - -
    +
    +

    clipFaceAgainstPlane

    -
    (
      -
    • - inVertices -
    • -
    • - outVertices -
    • -
    • - planeNormal -
    • -
    • - planeConstant -
    • -
    )
    - - - - - - - -
    @@ -1372,120 +877,77 @@

    clipFaceAgainstPlane

    -

    Parameters:

      -
    • - inVertices Array - -
      -
    • -
    • - outVertices Array - -
      -
    • -
    • - planeNormal Vec3 - -
      -
    • -
    • - planeConstant Number - -

      The constant in the mathematical plane equation

      -
    • -
    - - - -
    - -
    +
    +

    computeEdges

    - () - - - - - - - -
    @@ -1493,51 +955,30 @@

    computeEdges

    - - - -
    - -
    +
    +

    computeNormals

    - () - - - - - - - -
    @@ -1545,61 +986,36 @@

    computeNormals

    - - - -
    - -
    +
    +

    computeWorldFaceNormals

    -
    (
      -
    • - quat -
    • -
    )
    - - - - - - - -
    @@ -1607,118 +1023,70 @@

    computeWorldFaceNormals

    -

    Parameters:

    - - - -
    - -
    +
    +

    findSeparatingAxis

    -
    (
      -
    • - hullB -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    • - target -
    • -
    )
    - - Bool - - - - - - -
    @@ -1726,178 +1094,115 @@

    findSeparatingAxis

    -

    Parameters:

    - -

    Returns:

    - - Bool: -

    Returns false if a separation is found, else true

    -
    - - -
    - -
    +
    +

    getAveragePointLocal

    -
    (
      -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    @@ -1905,102 +1210,62 @@

    getAveragePointLocal

    -

    Parameters:

      -
    • - target Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    getFaceNormal

    -
    (
      -
    • - i -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    @@ -2008,204 +1273,128 @@

    getFaceNormal

    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    getPlaneConstantOfFace

    -
    (
      -
    • - face_i -
    • -
    )
    - - Number - - - - - - -
    -

    Parameters:

      -
    • - face_i Number - -

      Index of the face

      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    pointIsInside

    -
    (
      -
    • - p -
    • -
    )
    - - Boolean - - - - - - -
    @@ -2213,131 +1402,78 @@

    pointIsInside

    -

    Parameters:

      -
    • - p Vec3 - -

      A point given in local coordinates

      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    testSepAxis

    -
    (
      -
    • - axis -
    • -
    • - hullB -
    • -
    • - posA -
    • -
    • - quatA -
    • -
    • - posB -
    • -
    • - quatB -
    • -
    )
    - - - Float + Number - - - - - - -
    @@ -2345,179 +1481,114 @@

    testSepAxis

    -

    Parameters:

    - -

    Returns:

    - - - Float: - + Number:

    The overlap depth, or FALSE if no penetration.

    -
    - - -
    - -
    +
    +

    transformAllPoints

    -
    (
      -
    • - offset -
    • -
    • - quat -
    • -
    )
    - - - - - - - -
    @@ -2525,150 +1596,95 @@

    transformAllPoints

    -

    Parameters:

    - - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:707 - + src/shapes/ConvexPolyhedron.js:709

    - -
    - - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - - src/shapes/ConvexPolyhedron.js:762 - + src/shapes/ConvexPolyhedron.js:764

    - -
    @@ -2676,337 +1692,276 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    -

    faceNormals

    - Array - - - - - - - - - -
    - - -

    Inherited from - ConvexPolyhedron: - - - - src/shapes/ConvexPolyhedron.js:49 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    faceNormals

    + Array + + + + + +
    +

    Inherited from + ConvexPolyhedron: + src/shapes/ConvexPolyhedron.js:49 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    -

    faces

    - Array - - - - - - - - - -
    - - -

    Inherited from - ConvexPolyhedron: - - - - src/shapes/ConvexPolyhedron.js:42 - -

    - - - - -
    - -
    -

    Array of integer arrays, indicating which vertices each face consists of

    - -
    - - - - - - -
    - - +

    faces

    + Array + + + + + +
    +

    Inherited from + ConvexPolyhedron: + src/shapes/ConvexPolyhedron.js:42 +

    + + +
    + +
    +

    Array of integer arrays, indicating which vertices each face consists of

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    +
    +

    uniqueAxes

    + Array + + + + + +
    +

    Inherited from + ConvexPolyhedron: + src/shapes/ConvexPolyhedron.js:67 +

    + + +
    + +
    +

    If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.

    + +
    + + + +
    -

    uniqueEdges

    - Array - - - - - - - - - -
    - - -

    Inherited from - ConvexPolyhedron: - - - - src/shapes/ConvexPolyhedron.js:60 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    uniqueEdges

    + Array + + + + + +
    +

    Inherited from + ConvexPolyhedron: + src/shapes/ConvexPolyhedron.js:60 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    -

    vertices

    - Array - - - - - - - - - -
    - - -

    Inherited from - ConvexPolyhedron: - - - - src/shapes/ConvexPolyhedron.js:32 - -

    - - - - -
    - -
    -

    Array of Vec3

    - -
    - - - - - - -
    - - +

    vertices

    + Array + + + + + +
    +

    Inherited from + ConvexPolyhedron: + src/shapes/ConvexPolyhedron.js:32 +

    + + +
    + +
    +

    Array of Vec3

    + +
    + + + +
    - - - - diff --git a/docs/classes/Demo.html b/docs/classes/Demo.html index 392487f69..ad97e9bfe 100644 --- a/docs/classes/Demo.html +++ b/docs/classes/Demo.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,381 +25,245 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Demo Class

    +

    Demo Class

    - - -
    Defined in: src/demo/Demo.js:5
    - - -
    -

    Demo framework class. If you want to learn how to connect Cannon.js with Three.js, please look at the examples/ instead.

    -

    Constructor

    -

    Demo

    - - -
    - (
      - -
    • - - options - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Demo

    - - -

    - - Defined in +

    + (
      +
    • + options +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/demo/Demo.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/demo/Demo.js:5 +
      +
    • + options + Object -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - options - Object - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - - - -
    -

    Methods

    - -
    +

    addScene

    -
    (
      -
    • - title -
    • -
    • - - A - + initfunc
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/demo/Demo.js:209 -

    - -
    @@ -409,94 +271,58 @@

    addScene

    -

    Parameters:

      -
    • - title String - -

      Title of the scene

      -
    • -
    • - - A + initfunc Function - -
      -

      function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc.

      +

      A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc.

      -
    • -
    - - - -
    - -
    +
    +

    restartCurrentScene

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/demo/Demo.js:230 -

    - -
    @@ -504,25 +330,16 @@

    restartCurrentScene

    - - - -
    - +
    - - - -
    -
    diff --git a/docs/classes/DistanceConstraint.html b/docs/classes/DistanceConstraint.html index 4572bfcd2..d91a94742 100644 --- a/docs/classes/DistanceConstraint.html +++ b/docs/classes/DistanceConstraint.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,705 +25,573 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    DistanceConstraint Class

    +

    DistanceConstraint Class

    - -
    Extends Constraint
    - - - - -
    -
    -

    Constrains two bodies to be at a constant distance from each other.

    +

    Constrains two bodies to be at a constant distance from each others center of mass.

    -

    Constructor

    -

    DistanceConstraint

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - bodyB - -
    • - -
    • - - distance - -
    • - -
    • - - maxForce - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    DistanceConstraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [distance] +
    • +
    • + [maxForce=1e6] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/constraints/DistanceConstraint.js:6 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/constraints/DistanceConstraint.js:6 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [distance] + Number + optional + + +
      +

      The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB

      + +
      + +
    • +
    • + [maxForce=1e6] + Number + optional + + +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - Body - - - - -
      - -
      - - -
    • - -
    • - - bodyB - Body - - - - -
      - -
      - - -
    • - -
    • - - distance - Number - - - - -
      - -
      - - -
    • - -
    • - - maxForce - Number - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    -

    update

    +
    +

    disable

    - () - - - - - - - -
    - -
    - - +

    Disables all equations in the constraint.

    - - - -
    - - -
    - - - -
    -

    Properties

    - - -
    -

    bodyA

    - Body - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:29 - -

    - - - -
    -
    - -
    - - -
    +
    +

    enable

    - -
    -

    bodyB

    - Body - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:34 - -

    - - - - -
    - -
    - -
    - - + () - - -
    - -
    -

    collideConnected

    - Boolean - - - -
    -

    Set to true if you want the bodies to collide when they are connected.

    +

    Enables all equations in the constraint.

    - - - - - -
    - - -
    -

    equations

    - Array - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:22 - -

    - - -
    - -
    -

    Equations to be solved in this constraint

    -
    +
    +
    +

    update

    - + () - - -
    - -
    -

    id

    - Number - - - -
    - +

    Update all the equations with data.

    +
    - - - +
    +
    - +
    +

    Properties

    + +
    +

    bodyA

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    distance

    + Number + + + + + +
    +

    + Defined in + src/constraints/DistanceConstraint.js:28 +

    + + +
    + +
    + +
    + + + +
    +
    +

    distanceEquation

    + ContactEquation + + + + + +
    +

    + Defined in + src/constraints/DistanceConstraint.js:33 +

    + + +
    + +
    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Equation.html b/docs/classes/Equation.html index 4bd0f7118..c3829c22c 100644 --- a/docs/classes/Equation.html +++ b/docs/classes/Equation.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,562 +25,358 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Equation Class

    +

    Equation Class

    - - - - - -
    -

    Equation base class

    -

    Constructor

    -

    Equation

    - - -
    - (
      - -
    • - - bi - -
    • - -
    • - - bj - -
    • - -
    • - - minForce - -
    • - -
    • - - maxForce - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Equation

    + +
    + (
      +
    • + bi +
    • +
    • + bj +
    • +
    • + minForce +
    • +
    • + maxForce +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/equations/Equation.js:6 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/equations/Equation.js:6 +
      +
    • + bi + Body -

      - - - +
      + +
      + +
    • +
    • + bj + Body + + +
      + +
      + +
    • +
    • + minForce + Number + + +
      +

      Minimum (read: negative max) force to be applied by the constraint.

      + +
      + +
    • +
    • + maxForce + Number + + +
      +

      Maximum (read: positive max) force to be applied by the constraint.

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bi - Body - - - - -
      - -
      - - -
    • - -
    • - - bj - Body - - - - -
      - -
      - - -
    • - -
    • - - minForce - Number - - - - -
      -

      Minimum (read: negative max) force to be applied by the constraint.

      - -
      - - -
    • - -
    • - - maxForce - Number - - - - -
      -

      Maximum (read: positive max) force to be applied by the constraint.

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWlambda

    -
    (
      -
    • - deltalambda -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:222 - + src/equations/Equation.js:228

    - -
    @@ -590,81 +384,49 @@

    addToWlambda

    -

    Parameters:

      -
    • - deltalambda Number - -
      - +
      -
    • -
    - - - -
    - -
    +
    +

    computeB

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:89 - + src/equations/Equation.js:95

    - -
    @@ -672,70 +434,40 @@

    computeB

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMf

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:153 - + src/equations/Equation.js:159

    - -
    @@ -743,70 +475,40 @@

    computeGiMf

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMGt

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:185 - + src/equations/Equation.js:191

    - -
    @@ -814,70 +516,40 @@

    computeGiMGt

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGq

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:101 - + src/equations/Equation.js:107

    - -
    @@ -885,70 +557,40 @@

    computeGq

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGW

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:118 - + src/equations/Equation.js:124

    - -
    @@ -956,70 +598,40 @@

    computeGW

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGWlambda

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:136 - + src/equations/Equation.js:142

    - -
    @@ -1027,80 +639,46 @@

    computeGWlambda

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeInvC

    -
    (
      -
    • - eps -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:256 - + src/equations/Equation.js:262

    - -
    @@ -1108,89 +686,53 @@

    computeInvC

    -

    Parameters:

      -
    • - eps Number - -
      - +
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    setSpookParams

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/equations/Equation.js:76 - + src/equations/Equation.js:82

    - -
    @@ -1198,430 +740,264 @@

    setSpookParams

    - - - -
    - +
    - -

    Properties

    -
    -

    a

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:41 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    a

    + Number + + + + + +
    +

    + Defined in + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    b

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:47 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    b

    + Number + + + + + +
    +

    + Defined in + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    bi

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:29 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bi

    + Body + + + + + +
    +

    + Defined in + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    -

    bj

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:35 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bj

    + Body + + + + + +
    +

    + Defined in + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    + Defined in + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    -

    eps

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:53 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - -
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:59 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    eps

    + Number + + + + + +
    +

    + Defined in + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:64 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    + Defined in + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    + Defined in + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    -

    maxForce

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxForce

    + Number + + + + + +
    +

    + Defined in + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    minForce

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/Equation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    minForce

    + Number + + + + + +
    +

    + Defined in + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/EventTarget.html b/docs/classes/EventTarget.html index db9b6e239..2a4c186fd 100644 --- a/docs/classes/EventTarget.html +++ b/docs/classes/EventTarget.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,366 +25,234 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    EventTarget Class

    +

    EventTarget Class

    - - - - - -
    -

    Base class for objects that dispatches events.

    -

    Constructor

    -

    EventTarget

    - - - () - - - - - - - - - - - - - - - - -
    +

    EventTarget

    - - -

    - - Defined in - - + () - src/utils/EventTarget.js:1 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/utils/EventTarget.js:1 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - - - -
    -

    Methods

    - -
    +

    addEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - EventTarget - - - - - - -
    - - -

    - Defined in - - - - src/utils/EventTarget.js:15 -

    - -
    @@ -394,120 +260,74 @@

    addEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    dispatchEvent

    -
    (
      -
    • - event -
    • -
    )
    - - EventTarget - - - - - - -
    - - -

    - Defined in - - - - src/utils/EventTarget.js:68 -

    - -
    @@ -515,128 +335,78 @@

    dispatchEvent

    -

    Parameters:

      -
    • - event Object - -
      -
        -
      • - type String -
        -
      • -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    hasEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - Boolean - - - - - - -
    - - -

    - Defined in - - - - src/utils/EventTarget.js:34 -

    - -
    @@ -644,124 +414,75 @@

    hasEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    removeEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - EventTarget - - - - - - -
    - - -

    - Defined in - - - - src/utils/EventTarget.js:50 -

    - -
    @@ -769,77 +490,51 @@

    removeEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - +
    - - - -
    -
    diff --git a/docs/classes/FrictionEquation.html b/docs/classes/FrictionEquation.html index be8fe9f3d..930f4a21c 100644 --- a/docs/classes/FrictionEquation.html +++ b/docs/classes/FrictionEquation.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,534 +25,347 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    FrictionEquation Class

    +

    FrictionEquation Class

    - -
    Extends Equation
    - - - - -
    -

    Constrains the slipping in a contact along a tangent

    -

    Constructor

    -

    FrictionEquation

    - - -
    - (
      - -
    • - - bi - -
    • - -
    • - - bj - -
    • - -
    • - - slipForce - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    FrictionEquation

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + slipForce +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/equations/FrictionEquation.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/equations/FrictionEquation.js:7 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + slipForce + Number + + +
      +

      should be +-F_friction = +-mu F_normal = +-mu m * g

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bi - Body - - - - -
      - -
      - - -
    • - -
    • - - bj - Body - - - - -
      - -
      - - -
    • - -
    • - - slipForce - Number - - - - -
      -

      should be +-F_friction = +-mu F_normal = +-mu m * g

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWlambda

    -
    (
      -
    • - deltalambda -
    • -
    )
    - - - - - - - -
    @@ -562,78 +373,49 @@

    addToWlambda

    -

    Parameters:

      -
    • - deltalambda Number - -
      - +
      -
    • -
    - - - -
    - -
    +
    +

    computeB

    - () - - Number - - - - - - -
    @@ -641,67 +423,40 @@

    computeB

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMf

    - () - - Number - - - - - - -
    @@ -709,67 +464,40 @@

    computeGiMf

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMGt

    - () - - Number - - - - - - -
    @@ -777,67 +505,40 @@

    computeGiMGt

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGq

    - () - - Number - - - - - - -
    @@ -845,67 +546,40 @@

    computeGq

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGW

    - () - - Number - - - - - - -
    @@ -913,67 +587,40 @@

    computeGW

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGWlambda

    - () - - Number - - - - - - -
    @@ -981,77 +628,46 @@

    computeGWlambda

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeInvC

    -
    (
      -
    • - eps -
    • -
    )
    - - Number - - - - - - -
    @@ -1059,86 +675,53 @@

    computeInvC

    -

    Parameters:

      -
    • - eps Number - -
      - +
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    setSpookParams

    - () - - - - - - - -
    @@ -1146,365 +729,264 @@

    setSpookParams

    - - - -
    - +
    - -

    Properties

    -
    -

    a

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:41 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    a

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    b

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:47 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    b

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    bi

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:29 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bi

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    -

    bj

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:35 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bj

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    -

    eps

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:53 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    eps

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - -

    Inherited from - - Equation - - - but overwritten in - - - - src/equations/Equation.js:59 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    -

    maxForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    minForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    minForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    - - - - diff --git a/docs/classes/GSSolver.html b/docs/classes/GSSolver.html index 0ac46a843..0016556da 100644 --- a/docs/classes/GSSolver.html +++ b/docs/classes/GSSolver.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,388 +25,250 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    GSSolver Class

    +

    GSSolver Class

    - -
    Extends Solver
    - - - - -
    -

    Constraint equation Gauss-Seidel solver.

    -

    Constructor

    -

    GSSolver

    - - - () - - - - - - - - - - - - - - - - -
    +

    GSSolver

    - - -

    - - Defined in - - + () - src/solver/GSSolver.js:7 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/solver/GSSolver.js:7 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:28 -

    - -
    @@ -416,74 +276,46 @@

    addEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    removeAllEquations

    - () - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:52 -

    - -
    @@ -491,61 +323,36 @@

    removeAllEquations

    - - - -
    - -
    +
    +

    removeEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:39 -

    - -
    @@ -553,90 +360,55 @@

    removeEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    solve

    -
    (
      -
    • - dt -
    • -
    • - world -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:17 -

    - -
    @@ -644,201 +416,121 @@

    solve

    -

    Parameters:

      -
    • - dt Number - -
      -
    • -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    equations

    - Array - - - - - - - - - -
    - - -

    Inherited from - Solver: - - - - src/solver/Solver.js:10 - -

    - - - - -
    - -
    -

    All equations to be solved

    - -
    - - - - - - -
    - - +

    equations

    + Array + + + + + +
    +

    Inherited from + Solver: + src/solver/Solver.js:10 +

    + + +
    + +
    +

    All equations to be solved

    + +
    + + + +
    -

    iterations

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/solver/GSSolver.js:19 - -

    - - - - -
    - -
    -

    The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.

    - -
    - - - - - - -
    - - +

    iterations

    + Number + + + + + +
    +

    + Defined in + src/solver/GSSolver.js:19 +

    + + +
    + +
    +

    The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.

    + +
    + + + +
    -

    tolerance

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/solver/GSSolver.js:27 - -

    - - - - -
    - -
    -

    When tolerance is reached, the system is assumed to be converged.

    - -
    - - - - - - -
    - - +

    tolerance

    + Number + + + + + +
    +

    + Defined in + src/solver/GSSolver.js:27 +

    + + +
    + +
    +

    When tolerance is reached, the system is assumed to be converged.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/GridBroadphase.html b/docs/classes/GridBroadphase.html index e140ae477..b45aa8c40 100644 --- a/docs/classes/GridBroadphase.html +++ b/docs/classes/GridBroadphase.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,553 +25,356 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    GridBroadphase Class

    +

    GridBroadphase Class

    - -
    Extends Broadphase
    - - - - -
    -

    Axis aligned uniform grid broadphase.

    -

    Constructor

    -

    GridBroadphase

    - - -
    - (
      - -
    • - - aabbMin - -
    • - -
    • - - aabbMax - -
    • - -
    • - - nx - -
    • - -
    • - - ny - -
    • - -
    • - - nz - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    GridBroadphase

    + +
    + (
      +
    • + aabbMin +
    • +
    • + aabbMax +
    • +
    • + nx +
    • +
    • + ny +
    • +
    • + nz +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/collision/GridBroadphase.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/collision/GridBroadphase.js:7 +
      +
    • + aabbMin + Vec3 -

      - - - +
      + +
      + +
    • +
    • + aabbMax + Vec3 + + +
      + +
      + +
    • +
    • + nx + Number + + +
      +

      Number of boxes along x

      + +
      + +
    • +
    • + ny + Number + + +
      +

      Number of boxes along y

      + +
      + +
    • +
    • + nz + Number + + +
      +

      Number of boxes along z

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - aabbMin - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - aabbMax - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - nx - Number - - - - -
      -

      Number of boxes along x

      - -
      - - -
    • - -
    • - - ny - Number - - - - -
      -

      Number of boxes along y

      - -
      - - -
    • - -
    • - - nz - Number - - - - -
      -

      Number of boxes along z

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    aabbQuery

    -
    (
      -
    • - world -
    • -
    • - aabb -
    • - +
    • + result +
    )
    - - Array - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:197 -

    - -
    @@ -581,121 +382,86 @@

    aabbQuery

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - aabb AABB - -
      -
    • - +
    • + result + Array + + +
      +

      An array to store resulting bodies in.

      + +
      + +
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    boundingSphereCheck

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Boolean - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:183 -

    - -
    @@ -703,126 +469,78 @@

    boundingSphereCheck

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    collisionPairs

    -
    (
      -
    • - world -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - src/collision/GridBroadphase.js:42 -

    - -
    @@ -830,132 +548,81 @@

    collisionPairs

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingBoxBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:112 -

    - -
    @@ -963,147 +630,91 @@

    doBoundingBoxBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingSphereBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:89 -

    - -
    @@ -1111,149 +722,93 @@

    doBoundingSphereBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -

      bodyA is appended to this array if intersection

      -
    • -
    • - pairs2 Array - -

      bodyB is appended to this array if intersection

      -
    • -
    - - - -
    - -
    +
    +

    intersectionTest

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:73 -

    - -
    @@ -1261,135 +816,85 @@

    intersectionTest

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    makePairsUnique

    -
    (
      -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:135 -

    - -
    @@ -1397,109 +902,68 @@

    makePairsUnique

    -

    Parameters:

      -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    needBroadphaseCollision

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Bool - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:48 -

    - -
    @@ -1507,111 +971,69 @@

    needBroadphaseCollision

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Bool: - -
    - - -
    - -
    +
    +

    setWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:175 -

    - -
    @@ -1619,180 +1041,111 @@

    setWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    dirty

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:30 - -

    - - - - -
    - -
    -

    Set to true if the objects in the world moved.

    - -
    - - - - - - -
    - - +

    dirty

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:30 +

    + + +
    + +
    +

    Set to true if the objects in the world moved.

    + +
    + + + +
    -

    useBoundingBoxes

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:23 - -

    - - - - -
    - -
    -

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    - -
    - - - - - - -
    - - +

    useBoundingBoxes

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:23 +

    + + +
    + +
    +

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:16 - -

    - - - - -
    - -
    -

    The world to search for collisions in.

    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:16 +

    + + +
    + +
    +

    The world to search for collisions in.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Heightfield.html b/docs/classes/Heightfield.html index 6742be1ea..c3cd786f8 100644 --- a/docs/classes/Heightfield.html +++ b/docs/classes/Heightfield.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,580 +25,387 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Heightfield Class

    +

    Heightfield Class

    - -
    Extends Shape
    - - - - -
    -

    Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a given distance.

    -

    Constructor

    -

    Heightfield

    - - -
    - (
      - -
    • - - data - -
    • - -
    • - - options - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Heightfield

    + +
    + (
      +
    • + data +
    • +
    • + options +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/shapes/Heightfield.js:8 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/shapes/Heightfield.js:8 +
      +
    • + data + Array -

      - - - +
      +

      An array of Y values that will be used to construct the terrain.

      -
      - -
      +
      -
    - - -
    -

    Parameters:

    - -
      - -
    • - - data - Array - - - - -
      -

      An array of Y values that will be used to construct the terrain.

      - -
      - - -
    • - -
    • - - options - Object - - - - -
      - +
    • +
    • + options + Object + + +
      + +
      + +
        +
      • + [minValue] + Number + optional + +
        +

        Minimum value of the data points in the data array. Will be computed automatically if not given.

        + +
        + +
      • +
      • + [maxValue] + Number + optional + +
        +

        Maximum value.

        + +
        + +
      • +
      • + [elementSize=0.1] + Number + optional + +
        +

        World spacing between the data points in X direction.

        + +
        + +
      • +
      +
    • +
    +
    + + + +
    +

    Example:

    + +
    +
    // Generate some height data (y-values).
    +        var data = [];
    +        for(var i = 0; i < 1000; i++){
    +            var y = 0.5 * Math.cos(0.2 * i);
    +            data.push(y);
    +        }
    +        
    +        // Create the heightfield shape
    +        var heightfieldShape = new Heightfield(data, {
    +            elementSize: 1 // Distance between the data points in X and Y directions
    +        });
    +        var heightfieldBody = new Body();
    +        heightfieldBody.addShape(heightfieldShape);
    +        world.addBody(heightfieldBody);
    +        
    - - -
      - -
    • - - [minValue] - Number - optional - - -
      -

      Minimum value of the data points in the data array. Will be computed automatically if not given.

      - -
      - - -
    • - -
    • - - [maxValue] - Number - optional - - -
      -

      Maximum value.

      - -
      - - -
    • - -
    • - - [elementSize=0.1] - Number - optional - - -
      -

      World spacing between the data points in X direction.

      - -
      - - -
    • - -
    - - - - -
    - - - - - -
    -

    Example:

    - -
    -
    // Generate some height data (y-values).
    -var data = [];
    -for(var i = 0; i < 1000; i++){
    -    var y = 0.5 * Math.cos(0.2 * i);
    -    data.push(y);
    -}
    -
    -// Create the heightfield shape
    -var heightfieldShape = new Heightfield(data, {
    -    elementSize: 1 // Distance between the data points in X and Y directions
    -});
    -var heightfieldBody = new Body();
    -heightfieldBody.addShape(heightfieldShape);
    -world.addBody(heightfieldBody);
    - -
    +
    - -
    -
    -
    -

    Methods

    - -
    +

    calculateLocalInertia

    - () - - Vec3 - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:57 - + src/shapes/Shape.js:68

    - -
    @@ -608,88 +413,49 @@

    calculateLocalInertia

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    getConvexTrianglePillar

    -
    (
      -
    • - i -
    • -
    • - j -
    • -
    • - getUpperTriangle -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:257 -

    - -
    @@ -697,139 +463,84 @@

    getConvexTrianglePillar

    -

    Parameters:

      -
    • - i Integer - -
      -
    • -
    • - j Integer - -
      -
    • -
    • - getUpperTriangle Boolean - -
      -
    • -
    - - - -
    - -
    +
    +

    getIndexOfPosition

    -
    (
      -
    • - x -
    • -
    • - y -
    • -
    • - result -
    • -
    • - clamp -
    • -
    )
    - - Boolean - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:191 -

    - -
    @@ -837,174 +548,106 @@

    getIndexOfPosition

    -

    Parameters:

      -
    • - x Number - -
      -
    • -
    • - y Number - -
      -
    • -
    • - result Array - -

      Two-element array

      -
    • -
    • - clamp Boolean - -

      If the position should be clamped to the heightfield edge.

      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    getRectMinMax

    -
    (
      -
    • - iMinX -
    • -
    • - iMinY -
    • -
    • - iMaxX -
    • -
    • - iMaxY -
    • -
    • - [result] -
    • -
    )
    - - Array - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:162 -

    - -
    @@ -1012,175 +655,109 @@

    getRectMinMax

    -

    Parameters:

      -
    • - iMinX Integer - -
      -
    • -
    • - iMinY Integer - -
      -
    • -
    • - iMaxX Integer - -
      -
    • -
    • - iMaxY Integer - -
      -
    • -
    • - [result] Array optional - -

      An array to store the results in.

      -
    • -
    - -

    Returns:

    - - Array: -

    The result array, if it was passed in. Minimum will be at position 0 and max at 1.

    -
    - - -
    - -
    +
    +

    setHeightValueAtIndex

    -
    (
      -
    • - xi -
    • -
    • - yi -
    • -
    • - value -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:136 -

    - -
    @@ -1188,107 +765,66 @@

    setHeightValueAtIndex

    -

    Parameters:

      -
    • - xi Integer - -
      -
    • -
    • - yi Integer - -
      -
    • -
    • - value Number - -
      -
    • -
    - - - -
    - -
    +
    +

    update

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:92 -

    - -
    @@ -1296,55 +832,33 @@

    update

    - - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -1352,66 +866,37 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    updateMaxValue

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:118 -

    - -
    @@ -1419,111 +904,64 @@

    updateMaxValue

    - - - -
    - -
    -

    updateMinValue -Update the .minValue property

    +
    +
    +

    updateMinValue

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/shapes/Heightfield.js:100 -

    - -
    - +

    Update the .minValue property

    +
    - - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -1531,349 +969,251 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    -

    data

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Heightfield.js:43 - -

    - - - - -
    - -
    -

    An array of numbers, or height values, that are spread out along the x axis.

    - -
    - - - - - - -
    - - +

    data

    + Array + + + + + +
    +

    + Defined in + src/shapes/Heightfield.js:43 +

    + + +
    + +
    +

    An array of numbers, or height values, that are spread out along the x axis.

    + +
    + + + +
    -

    elementSize

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Heightfield.js:61 - -

    - - - - -
    - -
    -

    The width of each element

    - -
    - - - - - - -
    - - +

    elementSize

    + Number + + + + + +
    +

    + Defined in + src/shapes/Heightfield.js:61 +

    + + +
    + +
    +

    The width of each element

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    maxValue

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Heightfield.js:49 - -

    - - - - -
    - -
    -

    Max value of the data

    - -
    - - - - - - -
    - - +

    maxValue

    + Number + + + + + +
    +

    + Defined in + src/shapes/Heightfield.js:49 +

    + + +
    + +
    +

    Max value of the data

    + +
    + + + +
    -

    minValue

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Heightfield.js:55 - -

    - - - - -
    - -
    -

    Max value of the data

    - -
    - - - - - - -
    - - +

    minValue

    + Number + + + + + +
    +

    + Defined in + src/shapes/Heightfield.js:55 +

    + + +
    + +
    +

    Max value of the data

    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    - - - - diff --git a/docs/classes/HingeConstraint.html b/docs/classes/HingeConstraint.html index 741d69630..7121e6787 100644 --- a/docs/classes/HingeConstraint.html +++ b/docs/classes/HingeConstraint.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,883 +25,1020 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    HingeConstraint Class

    +

    HingeConstraint Class

    -
    -

    Hinge constraint. Tries to keep the local body axes equal.

    +

    Hinge constraint. Think of it as a door hinge. It tries to keep the door in the correct place and with the correct orientation.

    -

    Constructor

    -

    HingeConstraint

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - bodyB - -
    • - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    HingeConstraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/constraints/HingeConstraint.js:10 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/constraints/HingeConstraint.js:9 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [pivotA] + Vec3 + optional + +
        +

        A point defined locally in bodyA. This defines the offset of axisA.

        + +
        + +
      • +
      • + [axisA] + Vec3 + optional + +
        +

        An axis that bodyA can rotate around, defined locally in bodyA.

        + +
        + +
      • +
      • + [pivotB] + Vec3 + optional + +
        + +
        + +
      • +
      • + [axisB] + Vec3 + optional + +
        + +
        + +
      • +
      • + [maxForce=1e6] + Number + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - bodyB - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - [options] - Object - optional - - - - -
      - -
      - - -
        - -
      • - - [pivotA] - Vec3 - optional - - -
        -

        A point defined locally in bodyA. This defines the offset of axisA.

        - -
        - - -
      • - -
      • - - [axisA] - Vec3 - optional - - -
        -

        an axis that bodyA can rotate around.

        - -
        - - -
      • - -
      • - - [pivotB] - Vec3 - optional - - -
        - -
        - - -
      • - -
      • - - [axisB] - Vec3 - optional - - -
        - -
        - - -
      • - -
      • - - [maxForce=1e6] - Number - optional - - -
        - -
        - - -
      • - -
      - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    -
    - +
  • + equationY + +
  • +
  • + equationZ + +
  • +
  • + id + +
  • +
  • + motorEquation + +
  • +
  • + pivotA + +
  • +
  • + pivotB + +
  • +
  • + rotationalEquation1 + +
  • +
  • + rotationalEquation2 + +
  • + +
    - -
    -

    Methods

    - -
    -

    disableMotor

    +
    +

    disable

    - () - - - - - - - -
    - - - -

    - - Defined in - - - - - src/constraints/HingeConstraint.js:94 - +

    Inherited from + Constraint: + src/constraints/Constraint.js:80

    - -
    - +

    Disables all equations in the constraint.

    +
    - - - -
    - -
    -

    enableMotor

    +
    +
    +

    disableMotor

    - () - - - - - - - -
    - - - -
    - -
    -

    update

    +
    +
    +

    enable

    - () - - - - - - - -
    - +

    Enables all equations in the constraint.

    +
    - - - +
    +
    +

    enableMotor

    + + () - -
    - - -
    -

    Properties

    - -
    -

    bodyA

    - Body - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:29 - +

    + Defined in + src/constraints/HingeConstraint.js:73

    - - +
    - - - +
    +
    +

    setMotorMaxForce

    + +
    + (
      +
    • + maxForce +
    • +
    ) +
    + + - -
    -

    bodyB

    - Body - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:34 - +

    + Defined in + src/constraints/HingeConstraint.js:95

    - - +
    - - - +
    +

    Parameters:

    - -
    +
      +
    • + maxForce + Number - -
      -

      collideConnected

      - Boolean - +
      + +
      - +
    • +
    +
    - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:44 - -

    +
    +
    +

    setMotorSpeed

    - +
    + (
      +
    • + speed +
    • +
    ) +
    - -
    -
    -

    Set to true if you want the bodies to collide when they are connected.

    -
    - - - -
    - -
    -

    equations

    - Array - +
    +

    + Defined in + src/constraints/HingeConstraint.js:87 +

    - - - +
    -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:22 +

    -

    +
    - +
    +

    Parameters:

    - -
    +
      +
    • + speed + Number -
      -

      Equations to be solved in this constraint

      -
      +
      + +
      + +
    • +
    +
    - - -
    +
    +

    update

    + + () + + - -
    -

    id

    - Number - - - -
    - +

    Update all the equations with data.

    +
    - - - +
    +
    - +
    +

    Properties

    + +
    +

    axisA

    + Vec3 + + + + + +
    +

    + Defined in + src/constraints/HingeConstraint.js:33 +

    + + +
    + +
    +

    Rotation axis, defined locally in bodyA.

    + +
    + + + +
    +
    +

    axisB

    + Vec3 + + + + + +
    +

    + Defined in + src/constraints/HingeConstraint.js:40 +

    + + +
    + +
    +

    Rotation axis, defined locally in bodyB.

    + +
    + + + +
    +
    +

    bodyA

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    equationX

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationY

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationZ

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    +
    +

    motorEquation

    + RotationalMotorEquation + + + + + +
    +

    + Defined in + src/constraints/HingeConstraint.js:57 +

    + + +
    + +
    + +
    + + + +
    +
    +

    pivotA

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyA.

    + +
    + + + +
    +
    +

    pivotB

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyB.

    + +
    + + + +
    +
    +

    rotationalEquation1

    + RotationalEquation + + + + + +
    +

    + Defined in + src/constraints/HingeConstraint.js:47 +

    + + +
    + +
    + +
    + + + +
    +
    +

    rotationalEquation2

    + RotationalEquation + + + + + +
    +

    + Defined in + src/constraints/HingeConstraint.js:52 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/JacobianElement.html b/docs/classes/JacobianElement.html index 21c560ee3..bcafaf930 100644 --- a/docs/classes/JacobianElement.html +++ b/docs/classes/JacobianElement.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,370 +25,238 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    JacobianElement Class

    +

    JacobianElement Class

    - - - - - -
    -

    An element containing 6 entries, 3 spatial and 3 rotational degrees of freedom.

    -

    Constructor

    -

    JacobianElement

    - - - () - - - - - - - - - - - - - - - - -
    +

    JacobianElement

    - - -

    - - Defined in - - + () - src/math/JacobianElement.js:5 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/math/JacobianElement.js:5 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    multiplyElement

    -
    (
      -
    • - element -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - src/math/JacobianElement.js:23 -

    - -
    @@ -398,109 +264,65 @@

    multiplyElement

    -

    Parameters:

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    multiplyVectors

    -
    (
      -
    • - spatial -
    • -
    • - rotational -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - src/math/JacobianElement.js:33 -

    - -
    @@ -508,169 +330,101 @@

    multiplyVectors

    -

    Parameters:

      -
    • - spatial Vec3 - -
      -
    • -
    • - rotational Vec3 - -
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    rotational

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/JacobianElement.js:17 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    rotational

    + Vec3 + + + + + +
    +

    + Defined in + src/math/JacobianElement.js:17 +

    + + +
    + +
    + +
    + + + +
    -

    spatial

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/JacobianElement.js:12 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    spatial

    + Vec3 + + + + + +
    +

    + Defined in + src/math/JacobianElement.js:12 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/LockConstraint.html b/docs/classes/LockConstraint.html new file mode 100644 index 000000000..1400d9a68 --- /dev/null +++ b/docs/classes/LockConstraint.html @@ -0,0 +1,777 @@ + + + + + LockConstraint - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    LockConstraint Class

    +
    + + + + + + +
    + + +
    +

    Lock constraint. Will remove all degrees of freedom between the bodies.

    + +
    + +
    +

    Constructor

    +
    +

    LockConstraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options] +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/constraints/LockConstraint.js:10 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + bodyA + Body + + +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [maxForce=1e6] + Number + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + + + +
    +
    + +
    + + +
    +
    +

    Item Index

    + +
    +

    Methods

    + + +
    + +
    +

    Properties

    + + +
    + + +
    + +
    +

    Methods

    + +
    +

    disable

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:80 +

    + + + +
    + +
    +

    Disables all equations in the constraint.

    + +
    + + + + +
    +
    +

    enable

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:69 +

    + + + +
    + +
    +

    Enables all equations in the constraint.

    + +
    + + + + +
    +
    +

    update

    + + () + + + + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:61 +

    + + + +
    + +
    +

    Update all the equations with data.

    + +
    + + + + +
    +
    + +
    +

    Properties

    + +
    +

    bodyA

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    equationX

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationY

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationZ

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    +
    +

    pivotA

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyA.

    + +
    + + + +
    +
    +

    pivotB

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyB.

    + +
    + + + +
    +
    +

    rotationalEquation1

    + RotationalEquation + + + + + +
    +

    + Defined in + src/constraints/LockConstraint.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    rotationalEquation2

    + RotationalEquation + + + + + +
    +

    + Defined in + src/constraints/LockConstraint.js:40 +

    + + +
    + +
    + +
    + + + +
    +
    +

    rotationalEquation3

    + RotationalEquation + + + + + +
    +

    + Defined in + src/constraints/LockConstraint.js:45 +

    + + +
    + +
    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Mat3.html b/docs/classes/Mat3.html index c7368dbfe..36d82d63a 100644 --- a/docs/classes/Mat3.html +++ b/docs/classes/Mat3.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,488 +25,309 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Mat3 Class

    +

    Mat3 Class

    - - -
    Defined in: src/math/Mat3.js:5
    - - -
    -

    A 3x3 matrix.

    -

    Constructor

    -

    Mat3

    - - -
    - (
      - -
    • - - array - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Mat3

    + +
    + (
      +
    • + array +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/math/Mat3.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/math/Mat3.js:5 +
      +
    • + array + Object -

      - - - +
      +

      elements Array of nine elements. Optional.

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - array - Object - - - - -
      -

      elements Array of nine elements. Optional.

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    copy

    -
    (
      -
    • - source -
    • -
    )
    - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:241 - + src/math/Mat3.js:244

    - -
    @@ -516,117 +335,70 @@

    copy

    -

    Parameters:

      -
    • - source Mat3 - -
      -
    • -
    - -

    Returns:

    - - Mat3: -

    this

    -
    - - -
    - -
    +
    +

    e

    -
    (
      -
    • - row -
    • -
    • - column -
    • -
    • - value -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:224 - + src/math/Mat3.js:227

    - -
    @@ -634,120 +406,115 @@

    e

    -

    Parameters:

      -
    • - row Number - -
      -
    • -
    • - column Number - -
      -
    • -
    • - value Number - -

      Optional. If provided, the matrix element will be set to this value.

      -
    • -
    - -

    Returns:

    - - Number: - -
    - - +
    +
    +

    getTrace

    - -
    + () + + + Vec3 + + + + + + + + +
    +

    + Defined in + src/math/Mat3.js:74 +

    + + + +
    + +
    +

    Gets the matrix diagonal elements

    + +
    + + +
    +

    Returns:

    + +
    + Vec3: +
    +
    + + +
    +

    identity

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/math/Mat3.js:24 -

    - -
    @@ -755,68 +522,39 @@

    identity

    - - - -
    - -
    +
    +

    mmult

    -
    (
      -
    • - m -
    • -
    )
    - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:115 - + src/math/Mat3.js:118

    - -
    @@ -824,106 +562,65 @@

    mmult

    -

    Parameters:

      -
    • - m Mat3 - -

      Matrix to multiply with from left side.

      -
    • -
    - -

    Returns:

    - - Mat3: -

    The result.

    -
    - - -
    - -
    +
    +

    reverse

    -
    (
      -
    • - target -
    • -
    )
    - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:268 - + src/math/Mat3.js:271

    - -
    @@ -931,106 +628,65 @@

    reverse

    -

    Parameters:

      -
    • - target Mat3 - -

      Optional. Target matrix to save in.

      -
    • -
    - -

    Returns:

    - - Mat3: -

    The solution x

    -
    - - -
    - -
    +
    +

    scale

    -
    (
      -
    • - v -
    • -
    )
    - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:135 - + src/math/Mat3.js:138

    - -
    @@ -1038,101 +694,61 @@

    scale

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    - -

    Returns:

    - - Mat3: -

    The result.

    -
    - - -
    - -
    +
    +

    setRotationFromQuaternion

    -
    (
      -
    • - q -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:372 - + src/math/Mat3.js:375

    - -
    @@ -1140,132 +756,52 @@

    setRotationFromQuaternion

    -

    Parameters:

    -
    - - - - - -
    - - -
    -

    setTrace

    - - - () - - - - - - - - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Mat3.js:72 - -

    - - - +
  • + q + Quaternion - -
  • -
    -

    Sets the matrix diagonal elements from a Vec3

    +
    + +
    -
    + + +
    - - -
    - - -
    +

    setTrace

    - - () - +
    + (
      +
    • + vec3 +
    • +
    ) +
    - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:61 - + src/math/Mat3.js:62

    - -
    @@ -1273,54 +809,46 @@

    setTrace

    - +
    +

    Parameters:

    - +
      +
    • + vec3 + Vec3 - -
    - -
    +
    + +
    + + + +
    + + + +
    +

    setZero

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:44 - + src/math/Mat3.js:45

    - -
    @@ -1328,64 +856,36 @@

    setZero

    - - - -
    - -
    +
    +

    smult

    -
    (
      -
    • - s -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:104 - + src/math/Mat3.js:107

    - -
    @@ -1393,97 +893,58 @@

    smult

    -

    Parameters:

      -
    • - s Number - -
      -
    • -
    - - - -
    - -
    +
    +

    solve

    -
    (
      -
    • - b -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:153 - + src/math/Mat3.js:156

    - -
    @@ -1491,112 +952,70 @@

    solve

    -

    Parameters:

      -
    • - b Vec3 - -

      The right hand side

      -
    • -
    • - target Vec3 - -

      Optional. Target vector to save in.

      -
    • -
    - -

    Returns:

    - - Vec3: -

    The solution x

    -
    - - -
    - -
    +
    +

    toString

    - () - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:254 - + src/math/Mat3.js:257

    - -
    @@ -1604,80 +1023,47 @@

    toString

    - -

    Returns:

    - -

    string

    -
    - - -
    - -
    +
    +

    transpose

    -
    (
      -
    • - target -
    • -
    )
    - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:400 - + src/math/Mat3.js:403

    - -
    @@ -1685,108 +1071,65 @@

    transpose

    -

    Parameters:

      -
    • - target Mat3 - -

      Where to store the result.

      -
    • -
    - -

    Returns:

    - - Mat3: -

    The target Mat3, or a new Mat3 if target was omitted.

    -
    - - -
    - -
    +
    +

    vmult

    -
    (
      -
    • - v -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Mat3.js:84 - + src/math/Mat3.js:87

    - -
    @@ -1794,116 +1137,73 @@

    vmult

    -

    Parameters:

      -
    • - v Vec3 - -

      The vector to multiply with

      -
    • -
    • - target Vec3 - -

      Optional, target to save the result in.

      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    elements

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Mat3.js:13 - -

    - - - - -
    - -
    -

    A vector of length 9, containing all matrix elements

    - -
    - - - - - - -
    - - +

    elements

    + Array + + + + + +
    +

    + Defined in + src/math/Mat3.js:13 +

    + + +
    + +
    +

    A vector of length 9, containing all matrix elements

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Material.html b/docs/classes/Material.html index 7adc301c4..e8915d876 100644 --- a/docs/classes/Material.html +++ b/docs/classes/Material.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,425 +25,330 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Material Class

    +

    Material Class

    - - - - - -
    -

    Defines a physics material.

    -

    Constructor

    -

    Material

    - - -
    - (
      - -
    • - - name - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Material

    - - -

    - - Defined in +

    + (
      +
    • + [options] +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/material/Material.js:3 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/material/Material.js:3 +
      +
    • + [options] + Object + optional -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - name - String - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - -

    Properties

    - - -
    - -

    Properties

    - +
    +

    friction

    + Number + + + + + +
    +

    + Defined in + src/material/Material.js:35 +

    + + +
    + +
    +

    Friction for this material. If non-negative, it will be used instead of the friction given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used.

    + +
    + + + +
    -

    id

    - Unknown - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/Material.js:17 - -

    - - - - -
    - -
    -

    material id.

    - -
    - - - - - - -
    - - +

    id

    + Number + + + + + +
    +

    + Defined in + src/material/Material.js:28 +

    + + +
    + +
    +

    material id.

    + +
    + + + +
    -

    name

    - String - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/material/Material.js:11 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    name

    + String + + + + + +
    +

    + Defined in + src/material/Material.js:22 +

    + + +
    + +
    + +
    + + + +
    +
    +

    restitution

    + Number + + + + + +
    +

    + Defined in + src/material/Material.js:41 +

    + + +
    + +
    +

    Restitution for this material. If non-negative, it will be used instead of the restitution given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/NaiveBroadphase.html b/docs/classes/NaiveBroadphase.html index f6f9f7e2f..248cf81fd 100644 --- a/docs/classes/NaiveBroadphase.html +++ b/docs/classes/NaiveBroadphase.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,442 +25,282 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    NaiveBroadphase Class

    +

    NaiveBroadphase Class

    - -
    Extends Broadphase
    - - - - -
    -

    Naive broadphase implementation, used in lack of better ones.

    -

    Constructor

    -

    NaiveBroadphase

    - - - () - - - - - - - - - - - - - - - - -
    +

    NaiveBroadphase

    - - -

    - - Defined in - - + () - src/collision/NaiveBroadphase.js:6 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/collision/NaiveBroadphase.js:6 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    aabbQuery

    -
    (
      -
    • - world -
    • -
    • - aabb -
    • -
    • - result -
    • -
    )
    - - Array - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - src/collision/NaiveBroadphase.js:49 -

    - -
    @@ -470,137 +308,86 @@

    aabbQuery

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - aabb AABB - -
      -
    • -
    • - result Array - -

      An array to store resulting bodies in.

      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    boundingSphereCheck

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Boolean - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:183 -

    - -
    @@ -608,126 +395,78 @@

    boundingSphereCheck

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    collisionPairs

    -
    (
      -
    • - world -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - src/collision/NaiveBroadphase.js:19 -

    - -
    @@ -735,132 +474,81 @@

    collisionPairs

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingBoxBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:112 -

    - -
    @@ -868,147 +556,91 @@

    doBoundingBoxBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingSphereBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:89 -

    - -
    @@ -1016,149 +648,93 @@

    doBoundingSphereBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -

      bodyA is appended to this array if intersection

      -
    • -
    • - pairs2 Array - -

      bodyB is appended to this array if intersection

      -
    • -
    - - - -
    - -
    +
    +

    intersectionTest

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:73 -

    - -
    @@ -1166,135 +742,85 @@

    intersectionTest

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    makePairsUnique

    -
    (
      -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:135 -

    - -
    @@ -1302,109 +828,68 @@

    makePairsUnique

    -

    Parameters:

      -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    needBroadphaseCollision

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Bool - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:48 -

    - -
    @@ -1412,111 +897,69 @@

    needBroadphaseCollision

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Bool: - -
    - - -
    - -
    +
    +

    setWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:175 -

    - -
    @@ -1524,180 +967,111 @@

    setWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    dirty

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:30 - -

    - - - - -
    - -
    -

    Set to true if the objects in the world moved.

    - -
    - - - - - - -
    - - +

    dirty

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:30 +

    + + +
    + +
    +

    Set to true if the objects in the world moved.

    + +
    + + + +
    -

    useBoundingBoxes

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:23 - -

    - - - - -
    - -
    -

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    - -
    - - - - - - -
    - - +

    useBoundingBoxes

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:23 +

    + + +
    + +
    +

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:16 - -

    - - - - -
    - -
    -

    The world to search for collisions in.

    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:16 +

    + + +
    + +
    +

    The world to search for collisions in.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Narrowphase.html b/docs/classes/Narrowphase.html index ebf17e14e..98bc47c08 100644 --- a/docs/classes/Narrowphase.html +++ b/docs/classes/Narrowphase.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,1130 +25,781 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Narrowphase Class

    +

    Narrowphase Class

    - - - - - -
    -

    Helper class for the World. Generates ContactEquations.

    -

    Constructor

    -

    Narrowphase

    - - - () - - - - - - - - - - - - - - - - -
    +

    Narrowphase

    - - -

    - - Defined in - - + () - src/world/Narrowphase.js:12 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/world/Narrowphase.js:15 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    convexConvex

    -
    (
      - -
    • - - result - -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:804 - + src/world/Narrowphase.js:1252

    - -
    -

    Parameters:

    - - - +
    +
    +

    convexHeightfield

    - -
    -

    convexParticle

    + () - -
    - (
    +
    +

    convexParticle

    + +
    + (
    • - result -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:937 - + src/world/Narrowphase.js:1475

    - -
    -

    Parameters:

    - - - -
    - -
    -

    getContacts

    +
    +
    +

    convexTrimesh

    -
    (
      -
    • - - p1 - + result
    • -
    • - - p2 - + si
    • -
    • - - world - + sj
    • -
    • - - result - + xi
    • -
    • - - oldcontacts - + xj +
    • +
    • + qi +
    • +
    • + qj +
    • +
    • + bi +
    • +
    • + bj
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:62 - + src/world/Narrowphase.js:1309

    - -
    -

    Generate all contacts between a list of body pairs

    - +
    -

    Parameters:

      -
    • - - p1 + result Array - -
      -

      Array of body indices

      - +
      -
    • -
    • - - p2 - Array - + si + Shape -
      -

      Array of body indices

      - +
      -
    • -
    • - - world - World - + sj + Shape -
      -
    • -
    • - - result - Array - + xi + Vec3 -
      -

      Array to store generated contacts

      - +
      -
    • -
    • - - oldcontacts - Array - + xj + Vec3 -
      -

      Optional. Array of reusable contact objects

      - +
      -
    • - -
    -
    - - - - - -
    - - -
    -

    makeResult

    +
  • + qi + Quaternion - - () - - - - ContactEquation - - +
    + +
    + +
  • +
  • + qj + Quaternion + + +
    + +
    + +
  • +
  • + bi + Body + + +
    + +
    + +
  • +
  • + bj + Body + + +
    + +
    + +
  • + +
    + + + +
    +
    +

    createContactEquation

    + + () + + + ContactEquation + - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:35 - + src/world/Narrowphase.js:51

    - -
    @@ -1158,2281 +807,1709 @@

    makeResult

    - -

    Returns:

    - - ContactEquation: - -
    - - +
    +
    +

    getContacts

    - -
    +
    + (
      +
    • + p1 +
    • +
    • + p2 +
    • +
    • + world +
    • +
    • + result +
    • +
    • + oldcontacts +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/world/Narrowphase.js:199 +

    + + + +
    + +
    +

    Generate all contacts between a list of body pairs

    + +
    + +
    +

    Parameters:

    + +
      +
    • + p1 + Array + + +
      +

      Array of body indices

      + +
      + +
    • +
    • + p2 + Array + + +
      +

      Array of body indices

      + +
      + +
    • +
    • + world + World + + +
      + +
      + +
    • +
    • + result + Array + + +
      +

      Array to store generated contacts

      + +
      + +
    • +
    • + oldcontacts + Array + + +
      +

      Optional. Array of reusable contact objects

      + +
      + +
    • +
    +
    + + + +
    +

    particlePlane

    -
    (
      -
    • - result -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:857 - + src/world/Narrowphase.js:1393

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    particleSphere

    -
    (
      -
    • - result -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:897 - + src/world/Narrowphase.js:1434

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    planeBox

    -
    (
      -
    • - result -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:713 - + src/world/Narrowphase.js:1152

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    planeConvex

    -
    (
      - -
    • - - result - -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:735 - + src/world/Narrowphase.js:1176

    - -
    -

    Parameters:

    - - - -
    - -
    -

    sphereBox

    +
    +
    +

    planeTrimesh

    -
    (
      -
    • - - result - -
    • - -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:273 - + src/world/Narrowphase.js:345

    - -
    -

    Parameters:

    - - - -
    - -
    -

    sphereConvex

    +
    +
    +

    sphereBox

    -
    (
      - -
    • - - result - -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:492 - + src/world/Narrowphase.js:708

    - -
    -

    Parameters:

    - - - -
    - -
    -

    sphereHeightfield

    +
    +
    +

    sphereConvex

    - - () - +
    + (
      +
    • + si +
    • +
    • + sj +
    • +
    • + xi +
    • +
    • + xj +
    • +
    • + qi +
    • +
    • + qj +
    • +
    • + bi +
    • +
    • + bj +
    • +
    ) +
    - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:1032 - + src/world/Narrowphase.js:929

    - -
    - - - +
    +

    Parameters:

    - -
    +
      +
    • + si + Shape - -
      + +
      + +
      + +
    • +
    • + sj + Shape + + +
      + +
      + +
    • +
    • + xi + Vec3 + + +
      + +
      + +
    • +
    • + xj + Vec3 + + +
      + +
      + +
    • +
    • + qi + Quaternion + + +
      + +
      + +
    • +
    • + qj + Quaternion + + +
      + +
      + +
    • +
    • + bi + Body + + +
      + +
      + +
    • +
    • + bj + Body + + +
      + +
      + +
    • +
    +
    + + + +
    +

    sphereHeightfield

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:1114 - + src/world/Narrowphase.js:1651

    - -
    - - - -
    - -
    +
    +

    spherePlane

    -
    (
      - -
    • - - result - -
    • -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:178 - + src/world/Narrowphase.js:612

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    sphereSphere

    -
    (
      -
    • - - result - -
    • - -
    • - si -
    • -
    • - sj -
    • -
    • - xi -
    • -
    • - xj -
    • -
    • - qi -
    • -
    • - qj -
    • -
    • - bi -
    • -
    • - bj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:146 - + src/world/Narrowphase.js:308

    - -
    -

    Parameters:

    - - - +
    +
    +

    sphereTrimesh

    + +
    + (
      +
    • + sphereShape +
    • +
    • + trimeshShape +
    • +
    • + spherePos +
    • +
    • + trimeshPos +
    • +
    • + sphereQuat +
    • +
    • + trimeshQuat +
    • +
    • + sphereBody +
    • +
    • + trimeshBody +
    • +
    ) +
    - -
    - - -
    -

    Properties

    - -
    -

    contactPointPool

    - Array - - - -
    - - -

    - Defined in - - - - - src/world/Narrowphase.js:22 - + src/world/Narrowphase.js:416

    - - +
    -

    Internal storage of pooled contact points.

    - +
    - +
    +

    Parameters:

    - +
      +
    • + sphereShape + Shape - -
    - -
    -

    v3pool

    - Vec3Pool +
    + +
    - + +
  • + trimeshShape + Shape - - +
    + +
    - +
  • +
  • + spherePos + Vec3 -
    - - - -

    - - Defined in - - - - - src/world/Narrowphase.js:28 - -

    - +
    + +
    - -
    +
  • +
  • + trimeshPos + Vec3 -
    -

    Pooled vectors.

    -
    +
    + +
    + +
  • +
  • + sphereQuat + Quaternion + + +
    + +
    + +
  • +
  • + trimeshQuat + Quaternion + + +
    + +
    + +
  • +
  • + sphereBody + Body + + +
    + +
    + +
  • +
  • + trimeshBody + Body + + +
    + +
    + +
  • + +
    - - -
    +
    - +
    +

    Properties

    + +
    +

    contactPointPool

    + Array + + + + + +
    +

    + Defined in + src/world/Narrowphase.js:25 +

    + + +
    + +
    +

    Internal storage of pooled contact points.

    + +
    + + + +
    +
    +

    enableFrictionReduction

    + Boolean + + + + + +
    +

    + Defined in + src/world/Narrowphase.js:45 +

    + + +
    + +
    + +
    + + + +
    +
    +

    v3pool

    + Vec3Pool + + + + + +
    +

    + Defined in + src/world/Narrowphase.js:36 +

    + + +
    + +
    +

    Pooled vectors.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/ObjectCollisionMatrix.html b/docs/classes/ObjectCollisionMatrix.html index 25e51e848..61b7c2f18 100644 --- a/docs/classes/ObjectCollisionMatrix.html +++ b/docs/classes/ObjectCollisionMatrix.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,487 +25,308 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    ObjectCollisionMatrix Class

    +

    ObjectCollisionMatrix Class

    -

    Records what objects are colliding with each other

    -

    Constructor

    -

    ObjectCollisionMatrix

    - - - () - - - - - - - - - - - - - - - - -
    +

    ObjectCollisionMatrix

    - - -

    - - Defined in - - + () - src/collision/ObjectCollisionMatrix.js:3 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/collision/ObjectCollisionMatrix.js:3 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    get

    -
    (
      -
    • - i -
    • -
    • - j -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - src/collision/ObjectCollisionMatrix.js:18 -

    - -
    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - j Number - -
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    reset

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/collision/ObjectCollisionMatrix.js:57 -

    - -
    @@ -515,193 +334,114 @@

    reset

    - - - -
    - -
    +
    +

    set

    -
    (
      -
    • - i -
    • -
    • - j -
    • -
    • - value -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/ObjectCollisionMatrix.js:35 -

    - -
    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - j Number - -
      -
    • -
    • - value Number - -
      -
    • -
    - - - -
    - -
    +
    +

    setNumObjects

    -
    (
      -
    • - n -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/collision/ObjectCollisionMatrix.js:65 -

    - -
    @@ -709,99 +449,61 @@

    setNumObjects

    -

    Parameters:

      -
    • - n Number - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    matrix

    - Object - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/ObjectCollisionMatrix.js:10 - -

    - - - - -
    - -
    -

    The matrix storage

    - -
    - - - - - - -
    - - +

    matrix

    + Object + + + + + + + +
    +

    The matrix storage

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Octree.html b/docs/classes/Octree.html new file mode 100644 index 000000000..e05d3acc6 --- /dev/null +++ b/docs/classes/Octree.html @@ -0,0 +1,682 @@ + + + + + Octree - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    Octree Class

    +
    + +
    + Extends OctreeNode +
    + +
    + Defined in: src/utils/Octree.js:40 +
    + + +
    + + +
    + +
    + + +
    + + +
    +
    +

    Item Index

    + +
    +

    Methods

    + + +
    + +
    +

    Properties

    + + +
    + + +
    + +
    +

    Methods

    + +
    +

    aabbQuery

    + +
    + (
      +
    • + aabb +
    • +
    • + result +
    • +
    ) +
    + + + Array + + + + + + + + +
    +

    + Defined in + src/utils/Octree.js:158 +

    + + + +
    + +
    +

    Get all data, potentially within an AABB

    + +
    + +
    +

    Parameters:

    + +
      +
    • + aabb + AABB + + +
      + +
      + +
    • +
    • + result + Array + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Array: +

    The "result" object

    + +
    +
    + + +
    +
    +

    insert

    + +
    + (
      +
    • + aabb +
    • +
    • + elementData +
    • +
    ) +
    + + + Boolean + + + + + + + + +
    +

    + Defined in + src/utils/Octree.js:65 +

    + + + +
    + +
    +

    Insert data into this node

    + +
    + +
    +

    Parameters:

    + +
      +
    • + aabb + AABB + + +
      + +
      + +
    • +
    • + elementData + Object + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Boolean: +

    True if successful, otherwise false

    + +
    +
    + + +
    +
    +

    rayQuery

    + +
    + (
      +
    • + ray +
    • +
    • + treeTransform +
    • +
    • + result +
    • +
    ) +
    + + + Array + + + + + + + + +
    +

    + Defined in + src/utils/Octree.js:200 +

    + + + +
    + +
    +

    Get all data, potentially intersected by a ray.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + ray + Ray + + +
      + +
      + +
    • +
    • + treeTransform + Transform + + +
      + +
      + +
    • +
    • + result + Array + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Array: +

    The "result" object

    + +
    +
    + + +
    +
    +

    removeEmptyNodes

    + + () + + + + + + + + +
    +

    + Defined in + src/utils/Octree.js:219 +

    + + + +
    + +
    + +
    + + + + +
    +
    +

    subdivide

    + + () + + + + + + + + +
    +

    + Defined in + src/utils/Octree.js:112 +

    + + + +
    + +
    +

    Create 8 equally sized children nodes and put them in the .children array.

    + +
    + + + + +
    +
    + +
    +

    Properties

    + +
    +

    aabb

    + AABB + + + + + +
    +

    Inherited from + OctreeNode: + src/utils/Octree.js:21 +

    + + +
    + +
    +

    Boundary of this node

    + +
    + + + +
    +
    +

    children

    + Array + + + + + +
    +

    Inherited from + OctreeNode: + src/utils/Octree.js:33 +

    + + +
    + +
    +

    Children to this node

    + +
    + + + +
    +
    +

    data

    + Array + + + + + +
    +

    Inherited from + OctreeNode: + src/utils/Octree.js:27 +

    + + +
    + +
    +

    Contained data at the current node level.

    + +
    + + + +
    +
    +

    maxDepth

    + Number + + + + + +
    +

    + Defined in + src/utils/Octree.js:53 +

    + + +
    + +
    +

    Maximum subdivision depth

    + +
    + + + +
    +
    +

    root

    + OctreeNode + + + + + +
    +

    Inherited from + OctreeNode: + src/utils/Octree.js:15 +

    + + +
    + +
    +

    The root node

    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/OctreeNode.html b/docs/classes/OctreeNode.html new file mode 100644 index 000000000..5f3b2da4c --- /dev/null +++ b/docs/classes/OctreeNode.html @@ -0,0 +1,311 @@ + + + + + OctreeNode - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    OctreeNode Class

    +
    + + +
    + Defined in: src/utils/Octree.js:6 +
    + + +
    + + +
    + +
    + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Properties

    + + +
    + + +
    + + +
    +

    Properties

    + +
    +

    aabb

    + AABB + + + + + +
    +

    + Defined in + src/utils/Octree.js:21 +

    + + +
    + +
    +

    Boundary of this node

    + +
    + + + +
    +
    +

    children

    + Array + + + + + +
    +

    + Defined in + src/utils/Octree.js:33 +

    + + +
    + +
    +

    Children to this node

    + +
    + + + +
    +
    +

    data

    + Array + + + + + +
    +

    + Defined in + src/utils/Octree.js:27 +

    + + +
    + +
    +

    Contained data at the current node level.

    + +
    + + + +
    +
    +

    root

    + OctreeNode + + + + + +
    +

    + Defined in + src/utils/Octree.js:15 +

    + + +
    + +
    +

    The root node

    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/Particle.html b/docs/classes/Particle.html index 396155fc1..eeda31a61 100644 --- a/docs/classes/Particle.html +++ b/docs/classes/Particle.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,499 +25,329 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Particle Class

    +

    Particle Class

    - -
    Extends Shape
    - - - - -
    -

    Particle shape.

    -

    Constructor

    -

    Particle

    - - - () - - - - - - - - - - - - - - - - -
    +

    Particle

    - - -

    - - Defined in - - + () - src/shapes/Particle.js:6 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/shapes/Particle.js:6 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    -
    (
      -
    • - mass -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    -

    Inherited from Shape - but overwritten in - - - src/shapes/Particle.js:21 -

    - -
    -

    Parameters:

      -
    • - mass Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -527,67 +355,40 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -595,169 +396,151 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Plane.html b/docs/classes/Plane.html index d79d550bd..05e62b01e 100644 --- a/docs/classes/Plane.html +++ b/docs/classes/Plane.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,375 +25,251 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Plane Class

    +

    Plane Class

    - -
    Extends Shape
    - -
    Defined in: src/shapes/Plane.js:6
    - - -
    -

    A plane, facing in the Z direction. The plane has its surface at z=0 and everything below z=0 is assumed to be solid plane. To make the plane face in some other direction than z, you must put it inside a RigidBody and rotate that body. See the demos.

    -

    Constructor

    -

    Plane

    - - - () - - - - - - - - - - - - - - - - -
    +

    Plane

    - - -

    - - Defined in - - + () - src/shapes/Plane.js:6 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/shapes/Plane.js:6 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    - () - - Vec3 - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:57 - + src/shapes/Shape.js:68

    - -
    @@ -403,67 +277,40 @@

    calculateLocalInertia

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -471,67 +318,40 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -539,169 +359,151 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/PointToPointConstraint.html b/docs/classes/PointToPointConstraint.html index 14bdef897..dcb57bb7b 100644 --- a/docs/classes/PointToPointConstraint.html +++ b/docs/classes/PointToPointConstraint.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,750 +25,692 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    PointToPointConstraint Class

    +

    PointToPointConstraint Class

    -

    Connects two bodies at given offset points.

    -

    Constructor

    -

    PointToPointConstraint

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - pivotA - -
    • - -
    • - - bodyB - -
    • - -
    • - - pivotB - -
    • - -
    • - - maxForce - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    PointToPointConstraint

    + +
    + (
      +
    • + bodyA +
    • +
    • + pivotA +
    • +
    • + bodyB +
    • +
    • + pivotB +
    • +
    • + maxForce +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/constraints/PointToPointConstraint.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/constraints/PointToPointConstraint.js:6 +
      +
    • + bodyA + Body -

      - - - +
      + +
      -
    - -
    + +
  • + pivotA + Vec3 -
  • - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - Body - - - - -
      - -
      - - -
    • - -
    • - - pivotA - Vec3 - - - - -
      -

      The point relative to the center of mass of bodyA which bodyA is constrained to.

      - -
      - - -
    • - -
    • - - bodyB - Body - - - - -
      -

      Body that will be constrained in a similar way to the same point as bodyA. We will therefore get sort of a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point.

      - -
      - - -
    • - -
    • - - pivotB - Vec3 - - - - -
      -

      See pivotA.

      - -
      - - -
    • - -
    • - - maxForce - Number - - - - -
      -

      The maximum force that should be applied to constrain the bodies.

      - + +
      +

      The point relative to the center of mass of bodyA which bodyA is constrained to.

      + +
      + +
    • +
    • + bodyB + Body + + +
      +

      Body that will be constrained in a similar way to the same point as bodyA. We will therefore get a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point.

      + +
      + +
    • +
    • + pivotB + Vec3 + + +
      +

      See pivotA.

      + +
      + +
    • +
    • + maxForce + Number + + +
      +

      The maximum force that should be applied to constrain the bodies.

      + +
      + +
    • +
    +
    + + + +
    +

    Example:

    + +
    +
    var bodyA = new Body({ mass: 1 });
    +        var bodyB = new Body({ mass: 1 });
    +        bodyA.position.set(-1, 0, 0);
    +        bodyB.position.set(1, 0, 0);
    +        bodyA.addShape(shapeA);
    +        bodyB.addShape(shapeB);
    +        world.addBody(bodyA);
    +        world.addBody(bodyB);
    +        var localPivotA = new Vec3(1, 0, 0);
    +        var localPivotB = new Vec3(-1, 0, 0);
    +        var constraint = new PointToPointConstraint(bodyA, localPivotA, bodyB, localPivotB);
    +        world.addConstraint(constraint);
    +        
    - - - - - -
    - - - - - -
    -

    Example:

    - -
    -
    var bodyA = new Body({ mass: 1 });
    -var bodyB = new Body({ mass: 1 });
    -bodyA.position.set(-1, 0, 0);
    -bodyB.position.set(1, 0, 0);
    -bodyA.addShape(shapeA);
    -bodyB.addShape(shapeB);
    -world.addBody(bodyA);
    -world.addBody(bodyB);
    -var localPivotA = new Vec3(1, 0, 0);
    -var localPivotB = new Vec3(-1, 0, 0);
    -var constraint = new PointToPointConstraint(bodyA, localPivotA, bodyB, localPivotB);
    -world.addConstraint(constraint);
    - -
    +
    - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    -

    update

    +
    +

    disable

    - () - - - - - - - -
    - +

    Disables all equations in the constraint.

    +
    - - - +
    +
    +

    enable

    + + () - -
    - - -
    -

    Properties

    - -
    -

    bodyA

    - Body - - - - -
    -
    - - - - - -
    - - -
    -

    bodyB

    - Body - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:34 - -

    - - +
    +

    Enables all equations in the constraint.

    -
    -
    - -
    - - -
    +
    +

    update

    - -
    -

    collideConnected

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:44 - -

    - - - - -
    + () -
    -

    Set to true if you want the bodies to collide when they are connected.

    -
    - - - -
    - -
    -

    equations

    - Array - - - - - - - -
    -

    Equations to be solved in this constraint

    - - - - - -
    - - -
    -

    id

    - Number - - - - - - - - - -
    - - -

    Inherited from - Constraint: - - - - src/constraints/Constraint.js:39 - -

    - - +
    +

    Update all the equations with data.

    -
    -
    - -
    - - -
    +
    - +
    +

    Properties

    + +
    +

    bodyA

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:29 +

    + + +
    + +
    + +
    + + + +
    +
    +

    bodyB

    + Body + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:34 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collideConnected

    + Boolean + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:44 +

    + + +
    + +
    +

    Set to true if you want the bodies to collide when they are connected.

    + +
    + + + +
    +
    +

    equations

    + Array + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:22 +

    + + +
    + +
    +

    Equations to be solved in this constraint

    + +
    + + + +
    +
    +

    equationX

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationY

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    equationZ

    + ContactEquation + + + + + + + +
    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Constraint: + src/constraints/Constraint.js:39 +

    + + +
    + +
    + +
    + + + +
    +
    +

    pivotA

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyA.

    + +
    + + + +
    +
    +

    pivotB

    + Vec3 + + + + + + + +
    +

    Pivot, defined locally in bodyB.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Pool.html b/docs/classes/Pool.html index c087ad6ad..581d99a6f 100644 --- a/docs/classes/Pool.html +++ b/docs/classes/Pool.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,367 +25,236 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Pool Class

    +

    Pool Class

    - - -
    Defined in: src/utils/Pool.js:3
    - - -
    -

    For pooling objects that can be reused.

    -

    Constructor

    -

    Pool

    - - - () - - - - - - - - - - - - - - - - -
    +

    Pool

    - - -

    - - Defined in - - + () - src/utils/Pool.js:3 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/utils/Pool.js:3 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    constructObject

    - () - - Mixed - - - - - - -
    - - -

    - Defined in - - - - src/utils/Pool.js:47 -

    - -
    @@ -395,70 +262,40 @@

    constructObject

    - -

    Returns:

    - - Mixed: - -
    - - -
    - -
    +
    +

    get

    - () - - Mixed - - - - - - -
    - - -

    - Defined in - - - - src/utils/Pool.js:34 -

    - -
    @@ -466,76 +303,43 @@

    get

    - -

    Returns:

    - - Mixed: - -
    - - -
    - -
    +
    +

    release

    -
    (
      -
    • - obj -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/utils/Pool.js:22 -

    - -
    @@ -543,144 +347,86 @@

    release

    -

    Parameters:

      -
    • - obj Object - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    objects

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/utils/Pool.js:9 - -

    - - - - -
    - -
    -

    The pooled objects

    - -
    - - - - - - -
    - - +

    objects

    + Array + + + + + +
    +

    + Defined in + src/utils/Pool.js:9 +

    + + +
    + +
    +

    The pooled objects

    + +
    + + + +
    -

    type

    - Mixed - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/utils/Pool.js:15 - -

    - - - - -
    - -
    -

    Constructor of the objects

    - -
    - - - - - - -
    - - +

    type

    + Mixed + + + + + +
    +

    + Defined in + src/utils/Pool.js:15 +

    + + +
    + +
    +

    Constructor of the objects

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Quaternion.html b/docs/classes/Quaternion.html index 39119b747..e903f2ba3 100644 --- a/docs/classes/Quaternion.html +++ b/docs/classes/Quaternion.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,575 +25,363 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Quaternion Class

    +

    Quaternion Class

    - - - - - -
    -

    A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = xi + yj + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.

    -

    Constructor

    -

    Quaternion

    - - -
    - (
      - -
    • - - x - -
    • - -
    • - - y - -
    • - -
    • - - z - -
    • - -
    • - - w - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Quaternion

    + +
    + (
      +
    • + x +
    • +
    • + y +
    • +
    • + z +
    • +
    • + w +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/math/Quaternion.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/math/Quaternion.js:5 +
      +
    • + x + Number -

      - - - +
      +

      Multiplier of the imaginary basis vector i.

      + +
      + +
    • +
    • + y + Number + + +
      +

      Multiplier of the imaginary basis vector j.

      + +
      + +
    • +
    • + z + Number + + +
      +

      Multiplier of the imaginary basis vector k.

      + +
      + +
    • +
    • + w + Number + + +
      +

      Multiplier of the real part.

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - x - Number - - - - -
      -

      Multiplier of the imaginary basis vector i.

      - -
      - - -
    • - -
    • - - y - Number - - - - -
      -

      Multiplier of the imaginary basis vector j.

      - -
      - - -
    • - -
    • - - z - Number - - - - -
      -

      Multiplier of the imaginary basis vector k.

      - -
      - - -
    • - -
    • - - w - Number - - - - -
      -

      Multiplier of the real part.

      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

      -
    • w - -
    • -
    • x - -
    • -
    • y - -
    • -
    • z - -
    • -
    - - -
    -

    Methods

    - -
    +

    conjugate

    -
    (
      -
    • - target -
    • -
    )
    - - Quaternion - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:184 -

    - -
    @@ -603,103 +389,62 @@

    conjugate

    -

    Parameters:

    - -

    Returns:

    - - Quaternion: - -
    - - -
    - -
    +
    +

    copy

    -
    (
      -
    • - source -
    • -
    )
    - - Quaternion - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:274 -

    - -
    @@ -707,105 +452,64 @@

    copy

    -

    Parameters:

    - -

    Returns:

    - - Quaternion: -

    this

    -
    - - -
    - -
    +
    +

    inverse

    -
    (
      -
    • - target -
    • -
    )
    - - Quaternion - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:164 -

    - -
    @@ -813,109 +517,65 @@

    inverse

    -

    Parameters:

    - -

    Returns:

    - - Quaternion: - -
    - - -
    - -
    +
    +

    mult

    -
    (
      -
    • - q -
    • -
    • - target -
    • -
    )
    - - Quaternion - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:135 -

    - -
    @@ -923,105 +583,64 @@

    mult

    -

    Parameters:

    - -

    Returns:

    - - Quaternion: - -
    - - -
    - -
    +
    +

    normalize

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:201 -

    - -
    @@ -1029,54 +648,30 @@

    normalize

    - - - -
    - -
    +
    +

    normalizeFast

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:221 -

    - -
    @@ -1084,82 +679,45 @@

    normalizeFast

    - - - -
    - -
    +
    +

    set

    -
    (
      -
    • - x -
    • -
    • - y -
    • -
    • - z -
    • -
    • - w -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:38 -

    - -
    @@ -1167,365 +725,158 @@

    set

    -

    Parameters:

      -
    • - x Number - -
      -
    • -
    • - y Number - -
      -
    • -
    • - z Number - -
      -
    • -
    • - w Number - -
      -
    • -
    - - - -
    - -
    +
    +

    setFromAxisAngle

    -
    (
      -
    • - - targetAxis - + axis +
    • +
    • + angle
    • -
    )
    - - - - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Quaternion.js:85 - + src/math/Quaternion.js:71

    - -
    -

    Converts the quaternion to axis/angle representation.

    +

    Set the quaternion components given an axis and an angle.

    -

    Parameters:

      -
    • - - targetAxis + axis Vec3 - -
      -

      Optional. A vector object to reuse for storing the axis.

      + +
      + +
    • +
    • + angle + Number + + +
      +

      in radians

      -
    • -
    - - - -
    -

    Returns:

    -
    - - -

    Array An array, first elemnt is the axis and the second is the angle in radians.

    - -
    -
    - -
    +
    +

    setFromEuler

    - -
    -

    setFromAxisAngle

    - -
    (
      -
    • - - axis - + x
    • - -
    • - - angle - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Quaternion.js:71 - -

    - - - - - -
    - -
    -

    Set the quaternion components given an axis and an angle.

    - -
    - - -
    -

    Parameters:

    - -
      - -
    • - - axis - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - angle - Number - - - - -
      -

      in radians

      - -
      - - -
    • - -
    -
    - - - - - -
    - - -
    -

    setFromEuler

    - - -
    - (
      - -
    • - - x - -
    • -
    • - y -
    • -
    • - z -
    • -
    • - order -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:331 -

    - -
    @@ -1533,139 +884,86 @@

    setFromEuler

    -

    Parameters:

      -
    • - x Number - -
      -
    • -
    • - y Number - -
      -
    • -
    • - z Number - -
      -
    • -
    • - order String - -

      The order to apply angles: 'XYZ' or 'YXZ' or any other combination

      -
    • -
    - - - -
    - -
    +
    +

    setFromVectors

    -
    (
      -
    • - u -
    • -
    • - v -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:112 -

    - -
    @@ -1673,96 +971,59 @@

    setFromVectors

    -

    Parameters:

    - - - -
    - -
    +
    +

    toArray

    - () - - - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:62 -

    - -
    @@ -1770,180 +1031,173 @@

    toArray

    - -

    Returns:

    - -

    Array

    -
    - - -
    - -
    -

    toEuler

    +
    +
    +

    toAxisAngle

    -
    (
      -
    • - - target - -
    • - -
    • - - string - + targetAxis
    • -
    )
    - - + + + - - - - - -
    - - -

    - Defined in - - - - - src/math/Quaternion.js:288 - + src/math/Quaternion.js:85

    - -
    -

    Convert the quaternion to euler angle representation. Order: YZX, as this page describes: http://www.euclideanspace.com/maths/standards/index.htm

    +

    Converts the quaternion to axis/angle representation.

    -

    Parameters:

      -
    • - - target + targetAxis Vec3 - - - - -
      - -
      - - -
    • - -
    • - - string - Object - -
      -

      order Three-character string e.g. "YZX", which also is default.

      +

      Optional. A vector object to reuse for storing the axis.

      -
    • -
    - - +
    +

    Returns:

    - -
    +
    +

    Array An array, first elemnt is the axis and the second is the angle in radians.

    - -
    -

    toString

    +
    +
    - - () - - +
    +
    +

    toEuler

    + +
    + (
      +
    • + target +
    • +
    • + string +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/math/Quaternion.js:288 +

    + + + +
    + +
    +

    Convert the quaternion to euler angle representation. Order: YZX, as this page describes: http://www.euclideanspace.com/maths/standards/index.htm

    + +
    + +
    +

    Parameters:

    + +
      +
    • + target + Vec3 + + +
      + +
      + +
    • +
    • + string + Object + + +
      +

      order Three-character string e.g. "YZX", which also is default.

      + +
      + +
    • +
    +
    + + + +
    +
    +

    toString

    + + () + - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:53 -

    - -
    @@ -1951,86 +1205,50 @@

    toString

    - -

    Returns:

    - -

    string

    -
    - - -
    - -
    +
    +

    vmult

    -
    (
      -
    • - v -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - src/math/Quaternion.js:242 -

    - -
    @@ -2038,259 +1256,151 @@

    vmult

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - target Vec3 - -

      Optional

      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - +
    - -

    Properties

    -
    -

    w

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Quaternion.js:31 - -

    - - - - -
    - -
    -

    The multiplier of the real quaternion basis vector.

    - -
    - - - - - - -
    - - +

    w

    + Number + + + + + +
    +

    + Defined in + src/math/Quaternion.js:31 +

    + + +
    + +
    +

    The multiplier of the real quaternion basis vector.

    + +
    + + + +
    -

    x

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Quaternion.js:16 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    x

    + Number + + + + + +
    +

    + Defined in + src/math/Quaternion.js:16 +

    + + +
    + +
    + +
    + + + +
    -

    y

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Quaternion.js:21 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    y

    + Number + + + + + +
    +

    + Defined in + src/math/Quaternion.js:21 +

    + + +
    + +
    + +
    + + + +
    -

    z

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Quaternion.js:26 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    z

    + Number + + + + + +
    +

    + Defined in + src/math/Quaternion.js:26 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Ray.html b/docs/classes/Ray.html index 0a9bbc092..070aaadf1 100644 --- a/docs/classes/Ray.html +++ b/docs/classes/Ray.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,701 +25,511 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Ray Class

    +

    Ray Class

    - - - - - -
    -

    A line in 3D space that intersects bodies and return points.

    -

    Constructor

    -

    Ray

    - - -
    - (
      - -
    • - - from - -
    • - -
    • - - to - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Ray

    + +
    + (
      +
    • + from +
    • +
    • + to +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/collision/Ray.js:12 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/collision/Ray.js:12 +
      +
    • + from + Vec3 -

      - - - +
      + +
      + +
    • +
    • + to + Vec3 + + +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - from - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - to - Vec3 - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    -

    getAABB

    +
    +

    _updateDirection

    - -
    - (
      - -
    • - - aabb - -
    • - -
    ) -
    - + () - - - + private - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:246 - + src/collision/Ray.js:224

    - -
    -

    Get the AABB of the ray.

    +

    Updates the _direction vector.

    - -
    -

    Parameters:

    -
      - -
    • - - aabb - AABB - - + +
    +
    +

    getAABB

    + +
    + (
      +
    • + aabb +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/collision/Ray.js:334 +

    + + + +
    + +
    +

    Get the world AABB of the ray.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + aabb + AABB +
      -
    • -
    - - - -
    - -
    +
    +

    intersectBodies

    -
    (
      -
    • - bodies -
    • -
    • - - result - + [result]
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:116 - + src/collision/Ray.js:208

    - -
    -

    Parameters:

      -
    • - bodies Array - -

      An array of Body objects.

      -
    • -
    • - - result + [result] RaycastResult - + optional -
      - +

      Deprecated

      +
      -
    • -
    - - - -
    - -
    +
    +

    intersectBody

    -
    (
      -
    • - body - -
    • - -
    • - - result -
    • -
    • - - [direction] - + [result]
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:70 - + src/collision/Ray.js:157

    - -
    @@ -729,1658 +537,1212 @@

    intersectBody

    -

    Parameters:

      -
    • - body Body - -
      -
    • -
    • - - result + [result] RaycastResult - - - - -
      - -
      - - -
    • - -
    • - - [direction] - Vec3 optional - -
      - +

      Deprecated - set the result property of the Ray instead.

      +
      -
    • -
    - - - -
    - -
    +
    +

    intersectBox

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction - -
    • - -
    • - - result -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:174 - + src/collision/Ray.js:269

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    intersectConvex

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction - -
    • - -
    • - - result -
    • -
    • - [options] -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:413 - + src/collision/Ray.js:505

    - -
    -

    Parameters:

      -
    • - shape Shape - -
      -
    • -
    • - quat Quaternion - -
      -
    • -
    • - position Vec3 - -
      -
    • -
    • - body Body - - - - -
      - -
      - - -
    • - -
    • - - direction - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - result - RaycastResult - -
      -
    • -
    • - [options] Object optional - -
      -
        -
      • - [faceList] Array optional -
        -
      • -
      -
    • -
    - - - -
    - -
    +
    +

    intersectHeightfield

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction - -
    • - -
    • - - result -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:266 - + src/collision/Ray.js:354

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    intersectPlane

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction - -
    • - -
    • - - result -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:189 - + src/collision/Ray.js:282

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    intersectShape

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction - -
    • - -
    • - - result -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:139 - + src/collision/Ray.js:234

    - -
    -

    Parameters:

    - - - -
    - -
    +
    +

    intersectSphere

    -
    (
      -
    • - shape -
    • -
    • - quat -
    • -
    • - position -
    • -
    • - body - -
    • - -
    • - - direction -
    • - -
    • - - result - -
    • -
    )
    - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:344 - + src/collision/Ray.js:439

    - -
    -

    Parameters:

    - - - -
    - -
    -

    reportIntersection

    +
    +
    +

    intersectTrimesh

    -
    (
      -
    • - - normal - + shape
    • -
    • - - hitPointWorld - + quat
    • -
    • - - shape - + position
    • -
    • - body -
    • -
    • - - result - + [options]
    • -
    )
    - - - - Boolean - - - - private - - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:527 - + src/collision/Ray.js:623

    - -
    -

    Parameters:

    - - -
    -

    Returns:

    -
    - - - Boolean: - -

    True if the intersections should continue

    - -
    +
    +
    +

    intersectWorld

    + +
    + (
      +
    • + world +
    • +
    • + options +
    • +
    )
    - - -
    + + Boolean + - -
    - - -
    -

    Properties

    - - -
    -

    checkCollisionResponse

    - Boolean - - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:38 - + src/collision/Ray.js:99

    - - +
    -

    Set to true if you want the Ray to take .collisionResponse flags into account on bodies and shapes.

    +

    Do itersection against all bodies in the given World.

    - +
    +

    Parameters:

    - +
    - -
    -

    from

    - Vec3 +
    + +
    - + +
  • + options + Object - - +
    + +
    - +
  • + +
    -
    - - - -

    - - Defined in - - - - - src/collision/Ray.js:20 - -

    +
    +

    Returns:

    - +
    + Boolean: +

    True if the ray hit anything, otherwise false.

    - -
    +
    +
    -
    - -
    - +
    +
    +

    reportIntersection

    - +
    + (
      +
    • + normal +
    • +
    • + hitPointWorld +
    • +
    • + shape +
    • +
    • + body +
    • +
    ) +
    - -
    + + Boolean + - -
    -

    precision

    - Number - + private + - - -
    - - -

    - Defined in - - - - - src/collision/Ray.js:32 - + src/collision/Ray.js:738

    - - +
    -

    The precision of the ray. Used when checking parallelity etc.

    - +
    - +
    +

    Parameters:

    - +
      +
    • + normal + Vec3 - -
    - -
    -

    to

    - Vec3 +
    + +
    - + +
  • + hitPointWorld + Vec3 - - +
    + +
    - +
  • +
  • + shape + Shape -
    - - - -

    - - Defined in - - - - - src/collision/Ray.js:25 - -

    - +
    + +
    - -
    +
  • +
  • + body + Body -
    - -
    - +
    + +
    + +
  • + +
    + +
    +

    Returns:

    + +
    + Boolean: +

    True if the intersections should continue

    + +
    +
    - -
    +
    - +
    +

    Properties

    + +
    +

    _direction

    + Vec3 + + + private + + + +
    +

    + Defined in + src/collision/Ray.js:30 +

    + + +
    + +
    + +
    + + + +
    +
    +

    callback

    + Function + + + + + +
    +

    + Defined in + src/collision/Ray.js:84 +

    + + +
    + +
    +

    Current, user-provided result callback. Will be used if mode is Ray.ALL.

    + +
    + + + +
    +
    +

    checkCollisionResponse

    + Boolean + + + + + +
    +

    + Defined in + src/collision/Ray.js:42 +

    + + +
    + +
    +

    Set to true if you want the Ray to take .collisionResponse flags into account on bodies and shapes.

    + +
    + + + +
    +
    +

    collisionFilterGroup

    + Number + + + + + +
    +

    + Defined in + src/collision/Ray.js:60 +

    + + +
    + +
    + +
    + +

    Default: -1

    + + +
    +
    +

    collisionFilterMask

    + Number + + + + + +
    +

    + Defined in + src/collision/Ray.js:54 +

    + + +
    + +
    + +
    + +

    Default: -1

    + + +
    +
    +

    from

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/Ray.js:20 +

    + + +
    + +
    + +
    + + + +
    +
    +

    hasHit

    + Boolean + + + + + +
    +

    + Defined in + src/collision/Ray.js:78 +

    + + +
    + +
    +

    Will be set to true during intersectWorld() if the ray hit anything.

    + +
    + + + +
    +
    +

    mode

    + Number + + + + + +
    +

    + Defined in + src/collision/Ray.js:66 +

    + + +
    + +
    +

    The intersection mode. Should be Ray.ANY, Ray.ALL or Ray.CLOSEST.

    + +
    + + + +
    +
    +

    precision

    + Number + + + + + +
    +

    + Defined in + src/collision/Ray.js:36 +

    + + +
    + +
    +

    The precision of the ray. Used when checking parallelity etc.

    + +
    + + + +
    +
    +

    result

    + RaycastResult + + + + + +
    +

    + Defined in + src/collision/Ray.js:72 +

    + + +
    + +
    +

    Current result object.

    + +
    + + + +
    +
    +

    skipBackfaces

    + Boolean + + + + + +
    +

    + Defined in + src/collision/Ray.js:48 +

    + + +
    + +
    +

    If set to true, the ray skips any hits with normal.dot(rayDirection) < 0.

    + +
    + + + +
    +
    +

    to

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/Ray.js:25 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/RaycastResult.html b/docs/classes/RaycastResult.html index 1a74435ab..2737a83e1 100644 --- a/docs/classes/RaycastResult.html +++ b/docs/classes/RaycastResult.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,998 +25,695 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    RaycastResult Class

    +

    RaycastResult Class

    - - - - - -
    -

    Storage for Ray casting data.

    -

    Constructor

    -

    RaycastResult

    - - - () - - - - - - - - - - - - - - - - -
    +

    RaycastResult

    - - -

    - - Defined in - - + () - src/collision/RaycastResult.js:5 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/collision/RaycastResult.js:5 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    -

    reset

    +
    +

    abort

    - () - - - - - - - - + +
    + + + +
    +
    +

    reset

    + + () + + + + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:72 +

    + + + +
    +

    Reset all result data.

    - - - -
    - -
    +
    +

    set

    -
    (
      -
    • - rayFromWorld -
    • -
    • - rayToWorld -
    • -
    • - hitNormalWorld -
    • -
    • - hitPointWorld -
    • -
    • - shape -
    • -
    • - body -
    • -
    • - distance -
    • -
    )
    - - - - - - - -
    -

    Parameters:

      -
    • - rayFromWorld Vec3 - -
      -
    • -
    • - rayToWorld Vec3 - -
      -
    • -
    • - hitNormalWorld Vec3 - -
      -
    • -
    • - hitPointWorld Vec3 - -
      -
    • -
    • - shape Shape - -
      -
    • -
    • - body Body - -
      -
    • -
    • - distance Number - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    - +
    +

    _shouldStop

    + Boolean + + + private + + + +
    +

    + Defined in + src/collision/RaycastResult.js:63 +

    + + +
    + +
    +

    If the ray should stop traversing the bodies.

    + +
    + +

    Default: false

    + + +
    -

    body

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:43 - -

    - - - - -
    - -
    -

    The hit body, or null.

    - -
    - - - - - - -
    - - +

    body

    + Body + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:43 +

    + + +
    + +
    +

    The hit body, or null.

    + +
    + + + +
    -

    distance

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:49 - -

    - - - - -
    - -
    -

    Distance to the hit. Will be set to -1 if there was no hit.

    - -
    - - - - - - -
    - - +

    distance

    + Number + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:56 +

    + + +
    + +
    +

    Distance to the hit. Will be set to -1 if there was no hit.

    + +
    + +

    Default: -1

    + + +
    -

    hasHit

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:32 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    hasHit

    + Boolean + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:32 +

    + + +
    + +
    + +
    + + + +
    +
    +

    hitFaceIndex

    + Number + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:49 +

    + + +
    + +
    +

    The index of the hit triangle, if the hit shape was a trimesh.

    + +
    + +

    Default: -1

    + + +
    -

    hitNormalWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:22 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    hitNormalWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:22 +

    + + +
    + +
    + +
    + + + +
    -

    hitPointWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:27 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    hitPointWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:27 +

    + + +
    + +
    + +
    + + + +
    -

    rayFromWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:12 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    rayFromWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:12 +

    + + +
    + +
    + +
    + + + +
    -

    rayToWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:17 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    rayToWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:17 +

    + + +
    + +
    + +
    + + + +
    -

    shape

    - Shape - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/RaycastResult.js:37 - -

    - - - - -
    - -
    -

    The hit shape, or null.

    - -
    - - - - - - -
    - - +

    shape

    + Shape + + + + + +
    +

    + Defined in + src/collision/RaycastResult.js:37 +

    + + +
    + +
    +

    The hit shape, or null.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/RaycastVehicle.html b/docs/classes/RaycastVehicle.html index 34f592a42..cd524af44 100644 --- a/docs/classes/RaycastVehicle.html +++ b/docs/classes/RaycastVehicle.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,539 +25,350 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    RaycastVehicle Class

    +

    RaycastVehicle Class

    - - - - - -
    -

    Vehicle helper class that casts rays from the wheel positions towards the ground and applies forces.

    -

    Constructor

    -

    RaycastVehicle

    - - -
    - (
      - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    RaycastVehicle

    + +
    + (
      +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/objects/RaycastVehicle.js:10 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/objects/RaycastVehicle.js:10 +
      +
    • + [options] + Object + optional -

      - - - +
      + +
      + +
        +
      • + [chassisBody] + Body + optional + +
        +

        The car chassis body.

        + +
        + +
      • +
      • + [indexRightAxis] + Integer + optional + +
        +

        Axis to use for right. x=0, y=1, z=2

        + +
        + +
      • +
      • + [indexLeftAxis] + Integer + optional + +
        + +
        + +
      • +
      • + [indexUpAxis] + Integer + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - [options] - Object - optional - - - - -
      - -
      - - -
        - -
      • - - [chassisBody] - Body - optional - - -
        -

        The car chassis body.

        - -
        - - -
      • - -
      • - - [indexRightAxis] - Integer - optional - - -
        -

        Axis to use for right. x=0, y=1, z=2

        - -
        - - -
      • - -
      • - - [indexLeftAxis] - Integer - optional - - -
        - -
        - - -
      • - -
      • - - [indexUpAxis] - Integer - optional - - -
        - -
        - - -
      • - -
      - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RaycastVehicle.js:122 -

    - -
    @@ -567,87 +376,52 @@

    addToWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - -
    +
    +

    addWheel

    -
    (
      -
    • - [options] -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RaycastVehicle.js:74 -

    - -
    @@ -655,94 +429,56 @@

    addWheel

    -

    Parameters:

      -
    • - [options] Object optional - -
      -
    • -
    - - - -
    - -
    +
    +

    applyEngineForce

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RaycastVehicle.js:102 -

    - -
    @@ -750,110 +486,66 @@

    applyEngineForce

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    getVehicleAxisWorld

    -
    (
      -
    • - axisIndex -
    • -
    • - result -
    • -
    )
    - - - - private - - - - -
    @@ -861,106 +553,65 @@

    getVehicleAxisWorld

    -

    Parameters:

      -
    • - axisIndex Integer - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    getWheelTransformWorld

    -
    (
      -
    • - wheelIndex -
    • -
    )
    - - Transform - - - - - - -
    @@ -968,99 +619,59 @@

    getWheelTransformWorld

    -

    Parameters:

      -
    • - wheelIndex Integer - -
      -
    • -
    - -

    Returns:

    - - Transform: - -
    - - -
    - -
    +
    +

    removeFromWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    @@ -1068,93 +679,55 @@

    removeFromWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - -
    +
    +

    setBrake

    -
    (
      -
    • - brake -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RaycastVehicle.js:112 -

    - -
    @@ -1162,108 +735,65 @@

    setBrake

    -

    Parameters:

      -
    • - brake Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    setSteeringValue

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RaycastVehicle.js:89 -

    - -
    @@ -1271,388 +801,277 @@

    setSteeringValue

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - - - -
    - - -
    - - - -
    -

    Properties

    - - -
    -

    chassisBody

    - Body - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:22 - -

    - - - - -
    - -
    - -
    - - - - - -
    +
    +

    updateWheelTransform

    - -
    -

    indexForwardAxis

    - Integer - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:51 - -

    - - - - -
    - -
    -

    Index of the forward axis, 0=x, 1=y, 2=z

    - -
    +
    + (
      +
    • + wheelIndex +
    • +
    ) +
    - -

    Default: 0

    - - - -
    - -
    -

    indexRightAxis

    - Integer - - - - -
    - - -

    - Defined in - - - - - src/objects/RaycastVehicle.js:44 - + src/objects/RaycastVehicle.js:380

    - - - -
    - -
    -

    Index of the right axis, 0=x, 1=y, 2=z

    - -
    - - -

    Default: 1

    - - - - - -
    - - -
    -

    indexUpAxis

    - Integer - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:58 - -

    - -
    -

    Index of the up axis, 0=x, 1=y, 2=z

    +

    Update one of the wheel transform. +Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example.

    - -

    Default: 2

    - - - - - -
    - - -
    -

    sliding

    - Boolean - - - - - - - - +
    +

    Parameters:

    -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:33 - -

    +
      +
    • + wheelIndex + Integer - - -
    +
    +

    The wheel index to update.

    -
    -

    Will be set to true if the car is sliding.

    +
    -
    + + +
    - - -
    +
    - -
    -

    wheelInfos

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:27 - -

    - - - - -
    - -
    -

    An array of WheelInfo objects.

    - -
    - - - - - - -
    +
    +

    Properties

    - +
    +

    chassisBody

    + Body + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:22 +

    + + +
    + +
    + +
    + + + +
    +
    +

    indexForwardAxis

    + Integer + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:51 +

    + + +
    + +
    +

    Index of the forward axis, 0=x, 1=y, 2=z

    + +
    + +

    Default: 0

    + + +
    +
    +

    indexRightAxis

    + Integer + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:44 +

    + + +
    + +
    +

    Index of the right axis, 0=x, 1=y, 2=z

    + +
    + +

    Default: 1

    + + +
    +
    +

    indexUpAxis

    + Integer + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:58 +

    + + +
    + +
    +

    Index of the up axis, 0=x, 1=y, 2=z

    + +
    + +

    Default: 2

    + + +
    +
    +

    sliding

    + Boolean + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:33 +

    + + +
    + +
    +

    Will be set to true if the car is sliding.

    + +
    + + + +
    +
    +

    wheelInfos

    + Array + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:27 +

    + + +
    + +
    +

    An array of WheelInfo objects.

    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RaycastVehicle.js:39 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    + Defined in + src/objects/RaycastVehicle.js:39 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/RigidVehicle.html b/docs/classes/RigidVehicle.html index 37f801f86..16772e259 100644 --- a/docs/classes/RigidVehicle.html +++ b/docs/classes/RigidVehicle.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,456 +25,290 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    RigidVehicle Class

    +

    RigidVehicle Class

    - - - - - -
    -

    Simple vehicle helper class with spherical rigid body wheels.

    -

    Constructor

    -

    RigidVehicle

    - - -
    - (
      - -
    • - - [options.chassisBody] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    RigidVehicle

    + +
    + (
      +
    • + [options.chassisBody] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/objects/RigidVehicle.js:9 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/objects/RigidVehicle.js:9 +
      +
    • + [options.chassisBody] + Body + optional -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - [options.chassisBody] - Object - optional - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:162 -

    - -
    @@ -484,87 +316,52 @@

    addToWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - -
    +
    +

    addWheel

    -
    (
      -
    • - options -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:45 -

    - -
    @@ -572,171 +369,111 @@

    addWheel

    -

    Parameters:

      -
    • - options Object - -
      -
        -
      • - [isFrontWheel] - Object + Boolean optional -
        -
      • -
      • - [position] Vec3 optional -

        Position of the wheel, locally in the chassis body.

        -
      • -
      • - [direction] Vec3 optional -

        Slide direction of the wheel along the suspension.

        -
      • -
      • - [axis] Vec3 optional -

        Axis of rotation of the wheel, locally defined in the chassis.

        -
      • -
      • - [body] Body optional -

        The wheel body.

        -
      • -
      -
    • -
    - - - -
    - -
    +
    +

    applyWheelForce

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:146 -

    - -
    @@ -744,108 +481,65 @@

    applyWheelForce

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    disableMotor

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:123 -

    - -
    @@ -853,102 +547,62 @@

    disableMotor

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    getWheelSpeed

    -
    (
      -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:209 -

    - -
    @@ -956,87 +610,52 @@

    getWheelSpeed

    -

    Parameters:

      -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    removeFromWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:189 -

    - -
    @@ -1044,93 +663,55 @@

    removeFromWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - -
    +
    +

    setMotorSpeed

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:111 -

    - -
    @@ -1138,108 +719,65 @@

    setMotorSpeed

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    setSteeringValue

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:89 -

    - -
    @@ -1247,108 +785,65 @@

    setSteeringValue

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - -
    +
    +

    setWheelForce

    -
    (
      -
    • - value -
    • -
    • - wheelIndex -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/RigidVehicle.js:136 -

    - -
    @@ -1356,201 +851,118 @@

    setWheelForce

    -

    Parameters:

      -
    • - value Number - -
      -
    • -
    • - wheelIndex Integer - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    chassisBody

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RigidVehicle.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    chassisBody

    + Body + + + + + +
    +

    + Defined in + src/objects/RigidVehicle.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    constraints

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RigidVehicle.js:35 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    constraints

    + Array + + + + + +
    +

    + Defined in + src/objects/RigidVehicle.js:35 +

    + + +
    + +
    + +
    + + + +
    -

    coordinateSystem

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/RigidVehicle.js:18 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    coordinateSystem

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/RigidVehicle.js:18 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/RotationalEquation.html b/docs/classes/RotationalEquation.html index 9d44ee8bf..b4e0f66f0 100644 --- a/docs/classes/RotationalEquation.html +++ b/docs/classes/RotationalEquation.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,554 +25,375 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    RotationalEquation Class

    +

    RotationalEquation Class

    - -
    Extends Equation
    - - - - -
    -
    -

    Rotational constraint. Works to keep the local vectors orthogonal to each other.

    +

    Rotational constraint. Works to keep the local vectors orthogonal to each other in world space.

    -

    Constructor

    -

    RotationalEquation

    - - -
    - (
      - -
    • - - bj - -
    • - -
    • - - localVectorInBodyA - -
    • - -
    • - - bi - -
    • - -
    • - - localVectorInBodyB - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    RotationalEquation

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options.axisA] +
    • +
    • + [options.axisB] +
    • +
    • + [options.maxForce] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/equations/RotationalEquation.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/equations/RotationalEquation.js:7 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options.axisA] + Vec3 + optional + + +
      + +
      + +
    • +
    • + [options.axisB] + Vec3 + optional + + +
      + +
      + +
    • +
    • + [options.maxForce] + Number + optional + + +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bj - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - localVectorInBodyA - Vec3 - - - - -
      - -
      - - -
    • - -
    • - - bi - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - localVectorInBodyB - Vec3 - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWlambda

    -
    (
      -
    • - deltalambda -
    • -
    )
    - - - - - - - -
    @@ -582,78 +401,49 @@

    addToWlambda

    -

    Parameters:

      -
    • - deltalambda Number - -
      - +
      -
    • -
    - - - -
    - -
    +
    +

    computeB

    - () - - Number - - - - - - -
    @@ -661,67 +451,40 @@

    computeB

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMf

    - () - - Number - - - - - - -
    @@ -729,67 +492,40 @@

    computeGiMf

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMGt

    - () - - Number - - - - - - -
    @@ -797,67 +533,40 @@

    computeGiMGt

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGq

    - () - - Number - - - - - - -
    @@ -865,67 +574,40 @@

    computeGq

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGW

    - () - - Number - - - - - - -
    @@ -933,67 +615,40 @@

    computeGW

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGWlambda

    - () - - Number - - - - - - -
    @@ -1001,77 +656,46 @@

    computeGWlambda

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeInvC

    -
    (
      -
    • - eps -
    • -
    )
    - - Number - - - - - - -
    @@ -1079,86 +703,53 @@

    computeInvC

    -

    Parameters:

      -
    • - eps Number - -
      - +
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    setSpookParams

    - () - - - - - - - -
    @@ -1166,365 +757,264 @@

    setSpookParams

    - - - -
    - +
    - -

    Properties

    -
    -

    a

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:41 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    a

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    b

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:47 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    b

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    bi

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:29 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bi

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    -

    bj

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:35 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bj

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    -

    eps

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:53 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    eps

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - -

    Inherited from - - Equation - - - but overwritten in - - - - src/equations/Equation.js:59 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    -

    maxForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    minForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    minForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/RotationalMotorEquation.html b/docs/classes/RotationalMotorEquation.html index 0b9b3e17a..47e8ff48d 100644 --- a/docs/classes/RotationalMotorEquation.html +++ b/docs/classes/RotationalMotorEquation.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,540 +25,358 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    RotationalMotorEquation Class

    +

    RotationalMotorEquation Class

    - -
    Extends Equation
    - - - - -
    -
    -

    Rotational motor constraint. Works to keep the relative angular velocity of the bodies to a given value

    +

    Rotational motor constraint. Tries to keep the relative angular velocity of the bodies to a given value.

    -

    Constructor

    -

    RotationalMotorEquation

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - bodyB - -
    • - -
    • - - maxForce - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    RotationalMotorEquation

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + maxForce +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/equations/RotationalMotorEquation.js:7 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/equations/RotationalMotorEquation.js:7 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + maxForce + Number + + +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - bodyB - RigidBody - - - - -
      - -
      - - -
    • - -
    • - - maxForce - Number - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addToWlambda

    -
    (
      -
    • - deltalambda -
    • -
    )
    - - - - - - - -
    @@ -568,78 +384,49 @@

    addToWlambda

    -

    Parameters:

      -
    • - deltalambda Number - -
      - +
      -
    • -
    - - - -
    - -
    +
    +

    computeB

    - () - - Number - - - - - - -
    @@ -647,67 +434,40 @@

    computeB

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMf

    - () - - Number - - - - - - -
    @@ -715,67 +475,40 @@

    computeGiMf

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGiMGt

    - () - - Number - - - - - - -
    @@ -783,67 +516,40 @@

    computeGiMGt

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGq

    - () - - Number - - - - - - -
    @@ -851,67 +557,40 @@

    computeGq

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGW

    - () - - Number - - - - - - -
    @@ -919,67 +598,40 @@

    computeGW

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeGWlambda

    - () - - Number - - - - - - -
    @@ -987,77 +639,46 @@

    computeGWlambda

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    computeInvC

    -
    (
      -
    • - eps -
    • -
    )
    - - Number - - - - - - -
    @@ -1065,86 +686,53 @@

    computeInvC

    -

    Parameters:

      -
    • - eps Number - -
      - +
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    setSpookParams

    - () - - - - - - - -
    @@ -1152,410 +740,339 @@

    setSpookParams

    - - - -
    - +
    - -

    Properties

    -
    -

    a

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:41 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    a

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:41 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    +
    +

    axisA

    + Vec3 + + + + + + + +
    +

    World oriented rotational axis

    + +
    + + + +
    +
    +

    axisB

    + Vec3 + + + + + + + +
    +

    World oriented rotational axis

    + +
    + + + +
    -

    b

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:47 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    b

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:47 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    bi

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:29 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bi

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:29 +

    + + +
    + +
    + +
    + + + +
    -

    bj

    - Body - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:35 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    bj

    + Body + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:35 +

    + + +
    + +
    + +
    + + + +
    +
    +

    enabled

    + Boolean + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:69 +

    + + +
    + +
    + +
    + +

    Default: true

    + + +
    -

    eps

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:53 - -

    - - - - -
    - -
    -

    SPOOK parameter

    - -
    - - - - - - -
    - - +

    eps

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:53 +

    + + +
    + +
    +

    SPOOK parameter

    + +
    + + + +
    -

    jacobianElementA

    - JacobianElement - - - - - - - - - -
    - -

    Inherited from - - Equation - - - but overwritten in - - - - src/equations/Equation.js:59 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    jacobianElementA

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:59 +

    + + +
    + +
    + +
    + + + +
    +
    +

    jacobianElementB

    + JacobianElement + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:64 +

    + + +
    + +
    + +
    + + + +
    -

    maxForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    minForce

    - Number - - - - - - - - - -
    - - -

    Inherited from - Equation: - - - - src/equations/Equation.js:19 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    minForce

    + Number + + + + + +
    +

    Inherited from + Equation: + src/equations/Equation.js:19 +

    + + +
    + +
    + +
    + + + +
    -

    targetVelocity

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/equations/RotationalMotorEquation.js:26 - -

    - - - - -
    - -
    -

    Motor velocity

    - -
    - - - - - - -
    - - +

    targetVelocity

    + Number + + + + + + + +
    +

    Motor velocity

    + +
    + + + +
    - - - - diff --git a/docs/classes/SAPBroadphase.html b/docs/classes/SAPBroadphase.html index 5f124e73d..89ad06e58 100644 --- a/docs/classes/SAPBroadphase.html +++ b/docs/classes/SAPBroadphase.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,533 +25,337 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    SAPBroadphase Class

    +

    SAPBroadphase Class

    - -
    Extends Broadphase
    - - - - -
    -

    Sweep and prune broadphase along one axis.

    -

    Constructor

    -

    SAPBroadphase

    - - -
    - (
      - -
    • - - [world] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    SAPBroadphase

    + +
    + (
      +
    • + [world] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/collision/SAPBroadphase.js:6 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/collision/SAPBroadphase.js:6 +
      +
    • + [world] + World + optional -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - [world] - World - optional - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    aabbQuery

    -
    (
      -
    • - world -
    • -
    • - aabb -
    • -
    • - result -
    • -
    )
    - - Array - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - - src/collision/SAPBroadphase.js:280 - + src/collision/SAPBroadphase.js:287

    - -
    @@ -561,120 +363,74 @@

    aabbQuery

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - aabb AABB - -
      -
    • -
    • - result Array - -

      An array to store resulting bodies in.

      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    autoDetectAxis

    - () - - - - - - - -
    @@ -683,71 +439,42 @@

    autoDetectAxis

    - - - -
    - -
    +
    +

    boundingSphereCheck

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Boolean - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:183 -

    - -
    @@ -755,132 +482,79 @@

    boundingSphereCheck

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    checkBounds

    -
    (
      -
    • - bi -
    • -
    • - bj -
    • -
    • - axisIndex -
    • -
    )
    - - Boolean - - - - - static - - -
    - - -

    - Defined in - - - - src/collision/SAPBroadphase.js:204 -

    - -
    @@ -888,141 +562,88 @@

    checkBounds

    -

    Parameters:

      -
    • - bi Body - -
      -
    • -
    • - bj Body - -
      -
    • -
    • - axisIndex Number - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    collisionPairs

    -
    (
      -
    • - world -
    • -
    • - p1 -
    • -
    • - p2 -
    • -
    )
    - - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - src/collision/SAPBroadphase.js:143 -

    - -
    @@ -1030,132 +651,81 @@

    collisionPairs

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    • - p1 Array - -
      -
    • -
    • - p2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingBoxBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:112 -

    - -
    @@ -1163,147 +733,91 @@

    doBoundingBoxBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    doBoundingSphereBroadphase

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:89 -

    - -
    @@ -1311,464 +825,282 @@

    doBoundingSphereBroadphase

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -

      bodyA is appended to this array if intersection

      -
    • -
    • - pairs2 Array - -

      bodyB is appended to this array if intersection

      -
    • -
    - - - -
    - -
    +
    +

    insertionSortX

    -
    (
      -
    • - a -
    • -
    )
    - - Array - - - - - static - - -
    - - -

    - Defined in - - - - src/collision/SAPBroadphase.js:83 -

    - -
    -

    Parameters:

      -
    • - a Array - -
      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    insertionSortY

    -
    (
      -
    • - a -
    • -
    )
    - - Array - - - - - static - - -
    - - -

    - Defined in - - - - src/collision/SAPBroadphase.js:103 -

    - -
    -

    Parameters:

      -
    • - a Array - -
      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    insertionSortZ

    -
    (
      -
    • - a -
    • -
    )
    - - Array - - - - - static - - -
    - - -

    - Defined in - - - - src/collision/SAPBroadphase.js:123 -

    - -
    -

    Parameters:

      -
    • - a Array - -
      -
    • -
    - -

    Returns:

    - - Array: - -
    - - -
    - -
    +
    +

    intersectionTest

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:73 -

    - -
    @@ -1776,135 +1108,85 @@

    intersectionTest

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    makePairsUnique

    -
    (
      -
    • - pairs1 -
    • -
    • - pairs2 -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:135 -

    - -
    @@ -1912,109 +1194,68 @@

    makePairsUnique

    -

    Parameters:

      -
    • - pairs1 Array - -
      -
    • -
    • - pairs2 Array - -
      -
    • -
    - - - -
    - -
    +
    +

    needBroadphaseCollision

    -
    (
      -
    • - bodyA -
    • -
    • - bodyB -
    • -
    )
    - - Bool - - - - - - -
    - -

    Inherited from Broadphase: - - - src/collision/Broadphase.js:48 -

    - -
    @@ -2022,114 +1263,72 @@

    needBroadphaseCollision

    -

    Parameters:

      -
    • - bodyA Body - -
      -
    • -
    • - bodyB Body - -
      -
    • -
    - -

    Returns:

    - - Bool: - -
    - - -
    - -
    +
    +

    setWorld

    -
    (
      -
    • - world -
    • -
    )
    - - - - - - - -
    -

    Inherited from Broadphase - but overwritten in - - - src/collision/SAPBroadphase.js:57 -

    - -
    @@ -2137,273 +1336,164 @@

    setWorld

    -

    Parameters:

      -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    axisIndex

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/SAPBroadphase.js:31 - -

    - - - - -
    - -
    -

    Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.

    - -
    - - - - - - -
    - - +

    axisIndex

    + Number + + + + + +
    +

    + Defined in + src/collision/SAPBroadphase.js:31 +

    + + +
    + +
    +

    Axis to sort the bodies along. Set to 0 for x axis, and 1 for y axis. For best performance, choose an axis that the bodies are spread out more on.

    + +
    + + + +
    -

    axisList

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/collision/SAPBroadphase.js:17 - -

    - - - - -
    - -
    -

    List of bodies currently in the broadphase.

    - -
    - - - - - - -
    - - +

    axisList

    + Array + + + + + +
    +

    + Defined in + src/collision/SAPBroadphase.js:17 +

    + + +
    + +
    +

    List of bodies currently in the broadphase.

    + +
    + + + +
    -

    dirty

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:30 - -

    - - - - -
    - -
    -

    Set to true if the objects in the world moved.

    - -
    - - - - - - -
    - - +

    dirty

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:30 +

    + + +
    + +
    +

    Set to true if the objects in the world moved.

    + +
    + + + +
    -

    useBoundingBoxes

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Broadphase: - - - - src/collision/Broadphase.js:23 - -

    - - - - -
    - -
    -

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    - -
    - - - - - - -
    - - +

    useBoundingBoxes

    + Boolean + + + + + +
    +

    Inherited from + Broadphase: + src/collision/Broadphase.js:23 +

    + + +
    + +
    +

    If set to true, the broadphase uses bounding boxes for intersection test, else it uses bounding spheres.

    + +
    + + + +
    -

    world

    - World - - - - - - - - - -
    - -

    Inherited from - - Broadphase - - - but overwritten in - - - - src/collision/SAPBroadphase.js:24 - -

    - - - - -
    - -
    -

    The world to search in.

    - -
    - - - - - - -
    - - +

    world

    + World + + + + + +
    +

    Inherited from + + Broadphase + + but overwritten in + src/collision/SAPBroadphase.js:24 +

    + + +
    + +
    +

    The world to search in.

    + +
    + + + +
    - - -
    - diff --git a/docs/classes/SPHSystem.html b/docs/classes/SPHSystem.html index 28bc6cddd..bce84c032 100644 --- a/docs/classes/SPHSystem.html +++ b/docs/classes/SPHSystem.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,341 +25,299 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    SPHSystem Class

    +

    SPHSystem Class

    - - - - - -
    -

    Smoothed-particle hydrodynamics system

    -

    Constructor

    -

    SPHSystem

    - - - () - - - - - - - - - - - - - - - - -
    +

    SPHSystem

    - - -

    - - Defined in - - + () - src/objects/SPHSystem.js:10 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/objects/SPHSystem.js:10 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - - +
    +

    Properties

    + + +
    - -
    -

    Methods

    - -
    +
    +

    add

    + +
    + (
      +
    • + particle +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/objects/SPHSystem.js:45 +

    + + + +
    + +
    +

    Add a particle to the system.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + particle + Body + + +
      + +
      + +
    • +
    +
    + + + +
    +

    getNeighbors

    -
    (
      -
    • - particle -
    • -
    • - neighbors -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/objects/SPHSystem.js:46 - + src/objects/SPHSystem.js:72

    - -
    @@ -369,63 +325,175 @@

    getNeighbors

    -

    Parameters:

      -
    • - particle Body - -
      -
    • -
    • - neighbors Array - -
      -
    • -
    - - - +
    +
    +

    remove

    - -
    - +
    + (
      +
    • + particle +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/objects/SPHSystem.js:57 +

    - - -
    + +
    +

    Remove a particle from the system.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + particle + Body + + +
      + +
      + +
    • +
    +
    + + +
    +
    + +
    +

    Properties

    + +
    +

    density

    + Number + + + + + +
    +

    + Defined in + src/objects/SPHSystem.js:18 +

    + + +
    + +
    +

    Density of the system (kg/m3).

    + +
    + + + +
    +
    +

    smoothingRadius

    + Number + + + + + +
    +

    + Defined in + src/objects/SPHSystem.js:24 +

    + + +
    + +
    +

    Distance below which two particles are considered to be neighbors. + It should be adjusted so there are about 15-20 neighbor particles within this radius.

    + +
    + + + +
    +
    +

    viscosity

    + Number + + + + + +
    +

    + Defined in + src/objects/SPHSystem.js:32 +

    + + +
    + +
    +

    Viscosity of the system.

    + +
    + + + +
    +
    + +
    +
    diff --git a/docs/classes/Shape.html b/docs/classes/Shape.html index 7cac7b3ae..b44ad9fa8 100644 --- a/docs/classes/Shape.html +++ b/docs/classes/Shape.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,383 +25,253 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Shape Class

    +

    Shape Class

    - - -
    Defined in: src/shapes/Shape.js:8
    - - -
    -

    Base class for shapes

    -

    Constructor

    -

    Shape

    - - - () - - - - - - - - - - - - - - - - -
    +

    Shape

    - - -

    - - Defined in - - + () - src/shapes/Shape.js:8 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/shapes/Shape.js:8 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    - () - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/shapes/Shape.js:57 - + src/shapes/Shape.js:68

    - -
    @@ -411,70 +279,40 @@

    calculateLocalInertia

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -482,70 +320,40 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -553,225 +361,177 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    + Defined in + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    + Defined in + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    + Defined in + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    + Defined in + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    + Defined in + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    -

    types

    - Object - - - - - - - - - static - - -
    - - - -

    - - Defined in - - - - - src/shapes/Shape.js:67 - -

    - - - - -
    - -
    -

    The available shape types.

    - -
    - - - - - - -
    - - +

    types

    + Object + + + + + static + +
    +

    + Defined in + src/shapes/Shape.js:80 +

    + + +
    + +
    +

    The available shape types.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Solver.html b/docs/classes/Solver.html index 77c7e38e8..1ba180750 100644 --- a/docs/classes/Solver.html +++ b/docs/classes/Solver.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,373 +25,239 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Solver Class

    +

    Solver Class

    - - - - - -
    -

    Constraint equation solver base class.

    -

    Constructor

    -

    Solver

    - - - () - - - - - - - - - - - - - - - - -
    +

    Solver

    - - -

    - - Defined in - - + () - src/solver/Solver.js:3 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/solver/Solver.js:3 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/solver/Solver.js:28 -

    - -
    @@ -401,77 +265,46 @@

    addEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    removeAllEquations

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/solver/Solver.js:52 -

    - -
    @@ -479,64 +312,36 @@

    removeAllEquations

    - - - -
    - -
    +
    +

    removeEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/solver/Solver.js:39 -

    - -
    @@ -544,93 +349,55 @@

    removeEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    solve

    -
    (
      -
    • - dt -
    • -
    • - world -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/solver/Solver.js:17 -

    - -
    @@ -638,114 +405,71 @@

    solve

    -

    Parameters:

      -
    • - dt Number - -
      -
    • -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    equations

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/solver/Solver.js:10 - -

    - - - - -
    - -
    -

    All equations to be solved

    - -
    - - - - - - -
    - - +

    equations

    + Array + + + + + +
    +

    + Defined in + src/solver/Solver.js:10 +

    + + +
    + +
    +

    All equations to be solved

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Sphere.html b/docs/classes/Sphere.html index 211f3b663..376b5688e 100644 --- a/docs/classes/Sphere.html +++ b/docs/classes/Sphere.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,415 +25,278 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Sphere Class

    +

    Sphere Class

    - -
    Extends Shape
    - - - - -
    -

    Spherical shape

    -

    Constructor

    -

    Sphere

    - - -
    - (
      - -
    • - - radius - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Sphere

    + +
    + (
      +
    • + radius +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/shapes/Sphere.js:6 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/shapes/Sphere.js:6 +
      +
    • + radius + Number -

      - - - +
      +

      The radius of the sphere, a non-negative number.

      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - radius - Number - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    calculateLocalInertia

    - () - - Vec3 - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:57 - + src/shapes/Shape.js:68

    - -
    @@ -443,67 +304,40 @@

    calculateLocalInertia

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    updateBoundingSphereRadius

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:39 - + src/shapes/Shape.js:50

    - -
    @@ -511,67 +345,40 @@

    updateBoundingSphereRadius

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    volume

    - () - - Number - - - - - - -
    - -

    Inherited from Shape: - - - - src/shapes/Shape.js:48 - + src/shapes/Shape.js:59

    - -
    @@ -579,213 +386,175 @@

    volume

    - -

    Returns:

    - - Number: - -
    - - -
    - +
    - -

    Properties

    -
    -

    boundingSphereRadius

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:25 - -

    - - - - -
    - -
    -

    The local bounding sphere radius of this shape.

    - -
    - - - - - - -
    - - +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    -

    collisionResponse

    - Boolean - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:31 - -

    - - - - -
    - -
    -

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    - -
    - - - - - - -
    - - +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    -

    radius

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/shapes/Sphere.js:17 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    radius

    + Number + + + + + +
    +

    + Defined in + src/shapes/Sphere.js:17 +

    + + +
    + +
    + +
    + + + +
    -

    type

    - Number - - - - - - - - - -
    - - -

    Inherited from - Shape: - - - - src/shapes/Shape.js:17 - -

    - - - - -
    - -
    -

    The type of this shape. Must be set to an int > 0 by subclasses.

    - -
    - - - - - - -
    - - +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/SplitSolver.html b/docs/classes/SplitSolver.html index 7b2c6a5a3..10da0eb08 100644 --- a/docs/classes/SplitSolver.html +++ b/docs/classes/SplitSolver.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,407 +25,264 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    SplitSolver Class

    +

    SplitSolver Class

    - -
    Extends Solver
    - - - - -
    -

    Splits the equations into islands and solves them independently. Can improve performance.

    -

    Constructor

    -

    SplitSolver

    - - -
    - (
      - -
    • - - subsolver - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    SplitSolver

    + +
    + (
      +
    • + subsolver +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/solver/SplitSolver.js:8 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/solver/SplitSolver.js:8 +
      +
    • + subsolver + Solver -

      - - - +
      + +
      + +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - subsolver - Solver - - - - -
      - -
      - - -
    • - -
    - - - - - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    addEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:28 -

    - -
    @@ -435,74 +290,46 @@

    addEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    removeAllEquations

    - () - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:52 -

    - -
    @@ -510,61 +337,36 @@

    removeAllEquations

    - - - -
    - -
    +
    +

    removeEquation

    -
    (
      -
    • - eq -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Solver: - - - src/solver/Solver.js:39 -

    - -
    @@ -572,93 +374,58 @@

    removeEquation

    -

    Parameters:

    - - - -
    - -
    +
    +

    solve

    -
    (
      -
    • - dt -
    • -
    • - world -
    • -
    )
    - - - - - - - -
    -

    Inherited from Solver - but overwritten in - - - - src/solver/SplitSolver.js:27 - + src/solver/SplitSolver.js:81

    - -
    @@ -666,111 +433,71 @@

    solve

    -

    Parameters:

      -
    • - dt Number - -
      -
    • -
    • - world World - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    equations

    - Array - - - - - - - - - -
    - - -

    Inherited from - Solver: - - - - src/solver/Solver.js:10 - -

    - - - - -
    - -
    -

    All equations to be solved

    - -
    - - - - - - -
    - - +

    equations

    + Array + + + + + +
    +

    Inherited from + Solver: + src/solver/Solver.js:10 +

    + + +
    + +
    +

    All equations to be solved

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Spring.html b/docs/classes/Spring.html index d525d01d7..95e01529b 100644 --- a/docs/classes/Spring.html +++ b/docs/classes/Spring.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,595 +25,387 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Spring Class

    +

    Spring Class

    - - - - - -
    -

    A spring, connecting two bodies.

    -

    Constructor

    -

    Spring

    - - -
    - (
      - -
    • - - bodyA - -
    • - -
    • - - bodyB - -
    • - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Spring

    + +
    + (
      +
    • + bodyA +
    • +
    • + bodyB +
    • +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/objects/Spring.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/objects/Spring.js:5 +
      +
    • + bodyA + Body -

      - - - +
      + +
      + +
    • +
    • + bodyB + Body + + +
      + +
      + +
    • +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [restLength] + Number + optional + +
        +

        A number > 0. Default: 1

        + +
        + +
      • +
      • + [stiffness] + Number + optional + +
        +

        A number >= 0. Default: 100

        + +
        + +
      • +
      • + [damping] + Number + optional + +
        +

        A number >= 0. Default: 1

        + +
        + +
      • +
      • + [worldAnchorA] + Vec3 + optional + +
        +

        Where to hook the spring to body A, in world coordinates.

        + +
        + +
      • +
      • + [worldAnchorB] + Vec3 + optional + +
        + +
        + +
      • +
      • + [localAnchorA] + Vec3 + optional + +
        +

        Where to hook the spring to body A, in local body coordinates.

        + +
        + +
      • +
      • + [localAnchorB] + Vec3 + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + -
    - -
    -
    - - -
    -

    Parameters:

    - -
      - -
    • - - bodyA - Body - - - - -
      - -
      - - -
    • - -
    • - - bodyB - Body - - - - -
      - -
      - - -
    • - -
    • - - [options] - Object - optional - - - - -
      - -
      - - -
        - -
      • - - [restLength] - Number - optional - - -
        -

        A number > 0. Default: 1

        - -
        - - -
      • - -
      • - - [stiffness] - Number - optional - - -
        -

        A number >= 0. Default: 100

        - -
        - - -
      • - -
      • - - [damping] - Number - optional - - -
        -

        A number >= 0. Default: 1

        - -
        - - -
      • - -
      • - - [worldAnchorA] - Vec3 - optional - - -
        -

        Where to hook the spring to body A, in world coordinates.

        - -
        - - -
      • - -
      • - - [worldAnchorB] - Vec3 - optional - - -
        - -
        - - -
      • - -
      • - - [localAnchorA] - Vec3 - optional - - -
        -

        Where to hook the spring to body A, in local body coordinates.

        - -
        - - -
      • - -
      • - - [localAnchorB] - Vec3 - optional - - -
        - -
        - - -
      • - -
      - -
    • - -
    - - - - - -
    -
    -

    Item Index

    - - -

    Properties

    - - -
    -

    Methods

    - -
    +

    applyForce

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/objects/Spring.js:135 -

    - -
    @@ -623,64 +413,36 @@

    applyForce

    - - - -
    - -
    +
    +

    getWorldAnchorA

    -
    (
      -
    • - result -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/Spring.js:105 -

    - -
    @@ -688,88 +450,53 @@

    getWorldAnchorA

    -

    Parameters:

      -
    • - result Vec3 - -

      The vector to store the result in.

      -
    • -
    - - - -
    - -
    +
    +

    getWorldAnchorB

    -
    (
      -
    • - result -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/Spring.js:114 -

    - -
    @@ -777,88 +504,53 @@

    getWorldAnchorB

    -

    Parameters:

      -
    • - result Vec3 - -

      The vector to store the result in.

      -
    • -
    - - - -
    - -
    +
    +

    setWorldAnchorA

    -
    (
      -
    • - worldAnchorA -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/Spring.js:87 -

    - -
    @@ -866,87 +558,52 @@

    setWorldAnchorA

    -

    Parameters:

      -
    • - worldAnchorA Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    setWorldAnchorB

    -
    (
      -
    • - worldAnchorB -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/objects/Spring.js:96 -

    - -
    @@ -954,369 +611,211 @@

    setWorldAnchorB

    -

    Parameters:

      -
    • - worldAnchorB Vec3 - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    bodyA

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:45 - -

    - - - - -
    - -
    -

    First connected body.

    - -
    - - - - - - -
    - - +

    bodyA

    + Body + + + + + +
    +

    + Defined in + src/objects/Spring.js:45 +

    + + +
    + +
    +

    First connected body.

    + +
    + + + +
    -

    bodyB

    - Body - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:52 - -

    - - - - -
    - -
    -

    Second connected body.

    - -
    - - - - - - -
    - - +

    bodyB

    + Body + + + + + +
    +

    + Defined in + src/objects/Spring.js:52 +

    + + +
    + +
    +

    Second connected body.

    + +
    + + + +
    -

    damping

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:38 - -

    - - - - -
    - -
    -

    Damping of the spring.

    - -
    - - - - - - -
    - - +

    damping

    + Number + + + + + +
    +

    + Defined in + src/objects/Spring.js:38 +

    + + +
    + +
    +

    Damping of the spring.

    + +
    + + + +
    -

    localAnchorA

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:59 - -

    - - - - -
    - -
    -

    Anchor for bodyA in local bodyA coordinates.

    - -
    - - - - - - -
    - - +

    localAnchorA

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Spring.js:59 +

    + + +
    + +
    +

    Anchor for bodyA in local bodyA coordinates.

    + +
    + + + +
    -

    localAnchorB

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:66 - -

    - - - - -
    - -
    -

    Anchor for bodyB in local bodyB coordinates.

    - -
    - - - - - - -
    - - +

    localAnchorB

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/Spring.js:66 +

    + + +
    + +
    +

    Anchor for bodyB in local bodyB coordinates.

    + +
    + + + +
    -

    restLength

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:24 - -

    - - - - -
    - -
    -

    Rest length of the spring.

    - -
    - - - - - - -
    - - +

    restLength

    + Number + + + + + +
    +

    + Defined in + src/objects/Spring.js:24 +

    + + +
    + +
    +

    Rest length of the spring.

    + +
    + + + +
    -

    stiffness

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/Spring.js:31 - -

    - - - - -
    - -
    -

    Stiffness of the spring.

    - -
    - - - - - - -
    - - +

    stiffness

    + Number + + + + + +
    +

    + Defined in + src/objects/Spring.js:31 +

    + + +
    + +
    +

    Stiffness of the spring.

    + +
    + + + +
    - - -
    - diff --git a/docs/classes/Transform.html b/docs/classes/Transform.html index 5c402b86d..5dce5078e 100644 --- a/docs/classes/Transform.html +++ b/docs/classes/Transform.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,728 +25,616 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Transform Class

    +

    Transform Class

    - - - - - -
    -
    -

    Constructor

    -

    Transform

    - - - () - - - - - - - - - - - - - - - - -
    +

    Transform

    - - -

    - - Defined in - - + () - src/math/Transform.js:6 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/math/Transform.js:6 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    pointToLocaFrame

    -
    (
      -
    • - position -
    • -
    • - quaternion -
    • -
    • - worldPoint -
    • -
    • - result -
    • -
    )
    - - - - - - static - - -
    - - -

    - Defined in - - - - - src/math/Transform.js:24 - + src/math/Transform.js:32

    - -
    -

    Parameters:

    - - - -
    - -
    -

    pointToWorldFrame

    +
    +
    +

    pointToLocal

    -
    (
      - -
    • - - position - -
    • - -
    • - - quaternion - -
    • -
    • - - localPoint - + point
    • -
    • - result -
    • -
    )
    - - + + Vec3 + - - - - - static - - -
    - - -

    - Defined in - - - - - src/math/Transform.js:40 - + src/math/Transform.js:48

    - -
    - +

    Get a global point in local transform coordinates.

    +
    -

    Parameters:

      -
    • - - position + point Vec3 - -
      -
    • -
    • - - quaternion + result Vec3 - -
      -
    • - +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "result" vector object

    + +
    +
    + + +
    +
    +

    pointToWorld

    + +
    + (
      +
    • + point +
    • +
    • + result +
    • +
    ) +
    + + + Vec3 + + + + + + + + +
    +

    + Defined in + src/math/Transform.js:74 +

    + + + +
    + +
    +

    Get a local point in global transform coordinates.

    + +
    + +
    +

    Parameters:

    + +
    • - - localPoint + point Vec3 - -
      -
    • -
    • - result Vec3 - -
      -
    • -
    - - +
    +

    Returns:

    - -
    +
    + Vec3: +

    The "result" vector object

    -
    - +
    - -
    -

    Properties

    - -
    -

    position

    - Vec3 +
    +
    +

    pointToWorldFrame

    - +
    + (
      +
    • + position +
    • +
    • + quaternion +
    • +
    • + localPoint +
    • +
    • + result +
    • +
    ) +
    - - - + + + static + +
    - - -

    - Defined in - - - - - src/math/Transform.js:11 - + src/math/Transform.js:59

    - - +
    - +
    +

    Parameters:

    - +
      +
    • + position + Vec3 - -
    - -
    -

    quaternion

    - Quaternion +
    + +
    - + +
  • + quaternion + Vec3 - - +
    + +
    - +
  • +
  • + localPoint + Vec3 -
    - - - -

    - - Defined in - - - - - src/math/Transform.js:16 - -

    - +
    + +
    - -
    +
  • +
  • + result + Vec3 -
    - -
    - +
    + +
    + +
  • + +
    + - -
    +
    - +
    +

    Properties

    + +
    +

    position

    + Vec3 + + + + + +
    +

    + Defined in + src/math/Transform.js:13 +

    + + +
    + +
    + +
    + + + +
    +
    +

    quaternion

    + Quaternion + + + + + +
    +

    + Defined in + src/math/Transform.js:21 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Trimesh.html b/docs/classes/Trimesh.html new file mode 100644 index 000000000..e5cc00bcc --- /dev/null +++ b/docs/classes/Trimesh.html @@ -0,0 +1,2060 @@ + + + + + Trimesh - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    Trimesh Class

    +
    + +
    + Extends Shape +
    + +
    + Defined in: src/shapes/Trimesh.js:10 +
    + + +
    + + +
    + +
    + +
    +

    Constructor

    +
    +

    Trimesh

    + +
    + (
      +
    • + vertices +
    • +
    • + indices +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:10 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + vertices + Array + + +
      + +
      + +
    • +
    • + indices + Array + + +
      + +
      + +
    • +
    +
    + + + +
    +

    Example:

    + +
    +
    // How to make a mesh with a single triangle
    +        var vertices = [
    +            0, 0, 0, // vertex 0
    +            1, 0, 0, // vertex 1
    +            0, 1, 0  // vertex 2
    +        ];
    +        var indices = [
    +            0, 1, 2  // triangle 0
    +        ];
    +        var trimeshShape = new Trimesh(vertices, indices);
    +        
    +
    +
    +
    +
    + +
    + + +
    +
    +

    Item Index

    + +
    +

    Methods

    + + +
    + +
    +

    Properties

    + + +
    + + +
    + +
    +

    Methods

    + +
    +

    _getUnscaledVertex

    + +
    + (
      +
    • + i +
    • +
    • + out +
    • +
    ) +
    + + + Vec3 + + + + private + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:295 +

    + + + +
    + +
    +

    Get raw vertex i

    + +
    + +
    +

    Parameters:

    + +
      +
    • + i + Number + + +
      + +
      + +
    • +
    • + out + Vec3 + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "out" vector object

    + +
    +
    + + +
    +
    +

    calculateLocalInertia

    + +
    + (
      +
    • + mass +
    • +
    • + target +
    • +
    ) +
    + + + Vec3 + + + + + + + + +
    +

    Inherited from + + Shape + + but overwritten in + src/shapes/Trimesh.js:361 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + mass + Number + + +
      + +
      + +
    • +
    • + target + Vec3 + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "target" vector object

    + +
    +
    + + +
    +
    +

    calculateWorldAABB

    + +
    + (
      +
    • + pos +
    • +
    • + quat +
    • +
    • + min +
    • +
    • + max +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:454 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + pos + Vec3 + + +
      + +
      + +
    • +
    • + quat + Quaternion + + +
      + +
      + +
    • +
    • + min + Vec3 + + +
      + +
      + +
    • +
    • + max + Vec3 + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    computeLocalAABB

    + +
    + (
      +
    • + aabb +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:383 +

    + + + +
    + +
    +

    Compute the local AABB for the trimesh

    + +
    + +
    +

    Parameters:

    + +
      +
    • + aabb + AABB + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    computeNormal

    + +
    + (
      +
    • + va +
    • +
    • + vb +
    • +
    • + vc +
    • +
    • + target +
    • +
    ) +
    + + + + + + static + + + +
    +

    + Defined in + src/shapes/Trimesh.js:255 +

    + + + +
    + +
    +

    Get face normal given 3 vertices

    + +
    + +
    +

    Parameters:

    + +
      +
    • + va + Vec3 + + +
      + +
      + +
    • +
    • + vb + Vec3 + + +
      + +
      + +
    • +
    • + vc + Vec3 + + +
      + +
      + +
    • +
    • + target + Vec3 + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    createTorus

    + +
    + (
      +
    • + [radius=1] +
    • +
    • + [tube=0.5] +
    • +
    • + [radialSegments=8] +
    • +
    • + [tubularSegments=6] +
    • +
    • + [arc=6.283185307179586] +
    • +
    ) +
    + + + Trimesh + + + + + + static + + + +
    +

    + Defined in + src/shapes/Trimesh.js:513 +

    + + + +
    + +
    +

    Create a Trimesh instance, shaped as a torus.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + [radius=1] + Number + optional + + +
      + +
      + +
    • +
    • + [tube=0.5] + Number + optional + + +
      + +
      + +
    • +
    • + [radialSegments=8] + Number + optional + + +
      + +
      + +
    • +
    • + [tubularSegments=6] + Number + optional + + +
      + +
      + +
    • +
    • + [arc=6.283185307179586] + Number + optional + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Trimesh: +

    A torus

    + +
    +
    + + +
    +
    +

    getEdgeVector

    + +
    + (
      +
    • + edgeIndex +
    • +
    • + vectorStore +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:241 +

    + + + +
    + +
    +

    Get a vector along an edge.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + edgeIndex + Number + + +
      + +
      + +
    • +
    • + vectorStore + Vec3 + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    getEdgeVertex

    + +
    + (
      +
    • + edgeIndex +
    • +
    • + firstOrSecond +
    • +
    • + vertexStore +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:226 +

    + + + +
    + +
    +

    Get an edge vertex

    + +
    + +
    +

    Parameters:

    + +
      +
    • + edgeIndex + Number + + +
      + +
      + +
    • +
    • + firstOrSecond + Number + + +
      +

      0 or 1, depending on which one of the vertices you need.

      + +
      + +
    • +
    • + vertexStore + Vec3 + + +
      +

      Where to store the result

      + +
      + +
    • +
    +
    + + + +
    +
    +

    getNormal

    + +
    + (
      +
    • + i +
    • +
    • + target +
    • +
    ) +
    + + + Vec3 + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:343 +

    + + + +
    + +
    +

    Compute the normal of triangle i.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + i + Number + + +
      + +
      + +
    • +
    • + target + Vec3 + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "target" vector object

    + +
    +
    + + +
    +
    +

    getTrianglesInAABB

    + +
    + (
      +
    • + aabb +
    • +
    • + result +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:127 +

    + + + +
    + +
    +

    Get triangles in a local AABB from the trimesh.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + aabb + AABB + + +
      + +
      + +
    • +
    • + result + Array + + +
      +

      An array of integers, referencing the queried triangles.

      + +
      + +
    • +
    +
    + + + +
    +
    +

    getTriangleVertices

    + +
    + (
      +
    • + i +
    • +
    • + a +
    • +
    • + b +
    • +
    • + c +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:328 +

    + + + +
    + +
    +

    Get the three vertices for triangle i.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + i + Number + + +
      + +
      + +
    • +
    • + a + Vec3 + + +
      + +
      + +
    • +
    • + b + Vec3 + + +
      + +
      + +
    • +
    • + c + Vec3 + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    getVertex

    + +
    + (
      +
    • + i +
    • +
    • + out +
    • +
    ) +
    + + + Vec3 + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:279 +

    + + + +
    + +
    +

    Get vertex i.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + i + Number + + +
      + +
      + +
    • +
    • + out + Vec3 + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "out" vector object

    + +
    +
    + + +
    +
    +

    getWorldVertex

    + +
    + (
      +
    • + i +
    • +
    • + pos +
    • +
    • + quat +
    • +
    • + out +
    • +
    ) +
    + + + Vec3 + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:313 +

    + + + +
    + +
    +

    Get a vertex from the trimesh,transformed by the given position and quaternion.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + i + Number + + +
      + +
      + +
    • +
    • + pos + Vec3 + + +
      + +
      + +
    • +
    • + quat + Quaternion + + +
      + +
      + +
    • +
    • + out + Vec3 + + +
      + +
      + +
    • +
    +
    + +
    +

    Returns:

    + +
    + Vec3: +

    The "out" vector object

    + +
    +
    + + +
    +
    +

    setScale

    + +
    + (
      +
    • + scale +
    • +
    ) +
    + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:153 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + scale + Vec3 + + +
      + +
      + +
    • +
    +
    + + + +
    +
    +

    updateAABB

    + + () + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:423 +

    + + + +
    + +
    +

    Update the .aabb property

    + +
    + + + + +
    +
    +

    updateBoundingSphereRadius

    + + () + + + + + + + + +
    +

    Inherited from + + Shape + + but overwritten in + src/shapes/Trimesh.js:431 +

    + + + +
    + +
    +

    Will update the .boundingSphereRadius property

    + +
    + + + + +
    +
    +

    updateEdges

    + + () + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:198 +

    + + + +
    + +
    +

    Update the .edges property

    + +
    + + + + +
    +
    +

    updateNormals

    + + () + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:170 +

    + + + +
    + +
    +

    Compute the normals of the faces. Will save in the .normals array.

    + +
    + + + + +
    +
    +

    updateTree

    + + () + + + + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:88 +

    + + + +
    + +
    + +
    + + + + +
    +
    +

    volume

    + + () + + + Number + + + + + + + + +
    +

    Inherited from + + Shape + + but overwritten in + src/shapes/Trimesh.js:504 +

    + + + +
    + +
    +

    Get approximate volume

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    + +
    +

    Properties

    + +
    +

    aabb

    + Array + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:52 +

    + + +
    + +
    +

    The local AABB of the mesh.

    + +
    + + + +
    +
    +

    boundingSphereRadius

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:31 +

    + + +
    + +
    +

    The local bounding sphere radius of this shape.

    + +
    + + + +
    +
    +

    collisionResponse

    + Boolean + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:37 +

    + + +
    + +
    +

    Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.

    + +
    + + + +
    +
    +

    edges

    + Array + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:59 +

    + + +
    + +
    +

    References to vertex pairs, making up all unique edges in the trimesh.

    + +
    + + + +
    +
    +

    id

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:17 +

    + + +
    + +
    +

    Identifyer of the Shape.

    + +
    + + + +
    +
    +

    indices

    + Array + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:38 +

    + + +
    + +
    +

    Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles.

    + +
    + + + +
    +
    +

    material

    + Material + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:43 +

    + + +
    + +
    + +
    + + + +
    +
    +

    normals

    + Array + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:45 +

    + + +
    + +
    +

    The normals data.

    + +
    + + + +
    +
    +

    scale

    + Vec3 + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:65 +

    + + +
    + +
    +

    Local scaling of the mesh. Use .setScale() to set it.

    + +
    + + + +
    +
    +

    tree

    + Octree + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:71 +

    + + +
    + +
    +

    The indexed triangles. Use .updateTree() to update it.

    + +
    + + + +
    +
    +

    type

    + Number + + + + + +
    +

    Inherited from + Shape: + src/shapes/Shape.js:23 +

    + + +
    + +
    +

    The type of this shape. Must be set to an int > 0 by subclasses.

    + +
    + + + +
    +
    +

    vertices

    + Array + + + + + +
    +

    + Defined in + src/shapes/Trimesh.js:32 +

    + + +
    + +
    + +
    + + + +
    +
    + + +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/classes/TupleDictionary.html b/docs/classes/TupleDictionary.html index 2d9b5b1d1..a42115f92 100644 --- a/docs/classes/TupleDictionary.html +++ b/docs/classes/TupleDictionary.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,684 +25,426 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    TupleDictionary Class

    +

    TupleDictionary Class

    - - - - - -
    -
    -

    Constructor

    -

    TupleDictionary

    - - - () - - - - - - - - - - - - - - - - -
    +

    TupleDictionary

    - - -

    - - Defined in - - + () - src/utils/TupleDictionary.js:3 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/utils/TupleDictionary.js:3 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    get

    -
    (
      -
    • - i -
    • -
    • - j -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - src/utils/TupleDictionary.js:17 -

    - -
    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - j Number - -
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    reset

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/utils/TupleDictionary.js:55 -

    - -
    - - - -
    - -
    +
    +

    set

    -
    (
      -
    • - i -
    • -
    • - j -
    • -
    • - value -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/utils/TupleDictionary.js:33 -

    - -
    -

    Parameters:

      -
    • - i Number - -
      -
    • -
    • - j Number - -
      -
    • -
    • - value Number - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    data

    - Object - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/utils/TupleDictionary.js:9 - -

    - - - - -
    - -
    -

    The data storage

    - -
    - - - - - - -
    - - +

    data

    + Object + + + + + +
    +

    + Defined in + src/utils/TupleDictionary.js:9 +

    + + +
    + +
    +

    The data storage

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Vec3.html b/docs/classes/Vec3.html index fa07f7732..f2cb4578d 100644 --- a/docs/classes/Vec3.html +++ b/docs/classes/Vec3.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,631 +25,429 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Vec3 Class

    +

    Vec3 Class

    - - -
    Defined in: src/math/Vec3.js:5
    - - -
    -

    3-dimensional vector

    -

    Constructor

    -

    Vec3

    - - -
    - (
      - -
    • - - x - -
    • - -
    • - - y - -
    • - -
    • - - z - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    Vec3

    + +
    + (
      +
    • + x +
    • +
    • + y +
    • +
    • + z +
    • +
    ) +
    - - -

    - - Defined in + + + + + + + +

    +

    + Defined in + src/math/Vec3.js:5 +

    + + + +
    + +
    - +
    +
    +

    Parameters:

    - src/math/Vec3.js:5 +
      +
    • + x + Number -

      - - - +
      + +
      -
    - -
    + +
  • + y + Number -
  • - - -
    -

    Parameters:

    - -
      - -
    • - - x - Number - - - - -
      - -
      - - -
    • - -
    • - - y - Number - - - - -
      - -
      - - -
    • - -
    • - - z - Number - - - - -
      - + +
      + +
      + +
    • +
    • + z + Number + + +
      + +
      + +
    • +
    +
    + + + +
    +

    Example:

    + +
    +
    var v = new Vec3(1, 2, 3);
    +        console.log('x=' + v.x); // x=1
    +        
    - - - - - -
    - - - - - -
    -

    Example:

    - -
    -
    var v = new Vec3(1, 2, 3);
    -console.log('x=' + v.x); // x=1
    - -
    +
    - -
    -
    -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    almostEquals

    -
    (
      -
    • - v -
    • -
    • - precision -
    • -
    )
    - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:344 - + src/math/Vec3.js:395

    - -
    @@ -659,114 +455,70 @@

    almostEquals

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - precision Number - -
      -
    • -
    - -

    Returns:

    - -

    bool

    -
    - - -
    - -
    +
    +

    almostZero

    -
    (
      -
    • - precision -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:363 - + src/math/Vec3.js:414

    - -
    @@ -774,81 +526,49 @@

    almostZero

    -

    Parameters:

      -
    • - precision Number - -
      -
    • -
    - - - -
    - -
    +
    +

    clone

    - () - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:394 - + src/math/Vec3.js:445

    - -
    @@ -856,80 +576,46 @@

    clone

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    copy

    -
    (
      -
    • - source -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:316 - + src/math/Vec3.js:367

    - -
    @@ -937,111 +623,67 @@

    copy

    -

    Parameters:

      -
    • - source Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: -

    this

    -
    - - -
    - -
    +
    +

    cross

    -
    (
      -
    • - v -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:39 - + src/math/Vec3.js:61

    - -
    @@ -1049,109 +691,67 @@

    cross

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - target Vec3 - -

      Optional. Target to save in.

      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    crossmat

    - () - - Mat3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:118 - + src/math/Vec3.js:140

    - -
    @@ -1159,492 +759,438 @@

    crossmat

    - -

    Returns:

    - - Mat3: - -
    - - -
    - -
    -

    distanceTo

    +
    +
    +

    distanceSquared

    -
    (
      -
    • - p -
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:194 - + src/math/Vec3.js:246

    - -
    -

    Get distance from this point to another point

    +

    Get squared distance from this point to another point

    -

    Parameters:

      -
    • - p Vec3 - -
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    -

    dot

    +
    +
    +

    distanceTo

    -
    (
      -
    • - - v - + p
    • -
    )
    - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:236 - + src/math/Vec3.js:232

    - -
    -

    Calculate dot product

    +

    Get distance from this point to another point

    -

    Parameters:

      -
    • - - v + p Vec3 - -
      -
    • -
    - -

    Returns:

    - - Number: - -
    - - -
    - -
    -

    isAntiparallelTo

    +
    +
    +

    dot

    -
    (
      -
    • - v - -
    • - -
    • - - precision -
    • -
    )
    - - - Boolean + Number - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:382 - + src/math/Vec3.js:287

    - -
    -

    Check if the vector is anti-parallel to another vector.

    +

    Calculate dot product

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • - -
    • - - precision - Number - +
    +
    + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    isAntiparallelTo

    + +
    + (
      +
    • + v +
    • +
    • + precision +
    • +
    ) +
    + + + Boolean + + + + + + + + +
    +

    + Defined in + src/math/Vec3.js:433 +

    + + + +
    + +
    +

    Check if the vector is anti-parallel to another vector.

    + +
    + +
    +

    Parameters:

    + +
      +
    • + v + Vec3 + + +
      + +
      + +
    • +
    • + precision + Number -

      Set to zero for exact comparisons

      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    isZero

    - () - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:246 - + src/math/Vec3.js:297

    - -
    - -

    Returns:

    - -

    bool

    -
    - - +
    +
    +

    length

    - -
    + () + + + Number + + + + + + + + +
    +

    + Defined in + src/math/Vec3.js:208 +

    + + + +
    + +
    +

    Get the length of the vector

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +
    +

    lengthSquared

    + + () + + + Number + + + + + + + + +
    +

    + Defined in + src/math/Vec3.js:225 +

    + + + +
    + +
    +

    Get the squared length of the vector.

    + +
    + + +
    +

    Returns:

    + +
    + Number: +
    +
    + + +
    +

    lerp

    -
    (
      -
    • - v -
    • -
    • - t -
    • -
    • - target -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:330 - + src/math/Vec3.js:381

    - -
    @@ -1652,251 +1198,155 @@

    lerp

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - t Number - -

      A number between 0 and 1. 0 will make this function return u, and 1 will make it return v. Numbers in between will generate a vector in between them.

      -
    • -
    • - target Vec3 - -
      -
    • -
    - - - -
    - -
    +
    +

    mult

    -
    (
      -
    • - scalar -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - deprecated - + deprecated - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:208 - + src/math/Vec3.js:258

    - -

    Deprecated: Use .scale instead

    - +

    Deprecated: Use .scale() instead

    -
    -

    Multiply the vector with a scalar

    +

    Multiply all the components of the vector with a scalar.

    -

    Parameters:

      -
    • - scalar Number - -
      -
    • -
    • - target Vec3 - -
      - +

      The vector to save the result in.

      +
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    negate

    -
    (
      -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:254 - + src/math/Vec3.js:305

    - -
    @@ -1904,165 +1354,102 @@

    negate

    -

    Parameters:

      -
    • - target Vec3 - -

      Optional target to save in

      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    norm

    - () - - Number - - + deprecated - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:175 - + src/math/Vec3.js:197

    - +

    Deprecated: Use .length() instead

    -
    -

    Get the 2-norm (length) of the vector

    +

    Get the length of the vector

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    norm2

    - () - - Number - - + deprecated - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:185 - + src/math/Vec3.js:215

    - +

    Deprecated: Use .lengthSquared() instead.

    -
    @@ -2070,70 +1457,40 @@

    norm2

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    +
    +

    normalize

    - () - - Number - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:130 - + src/math/Vec3.js:152

    - -
    @@ -2141,88 +1498,51 @@

    normalize

    - -

    Returns:

    - - Number: -

    Returns the norm of the vector

    -
    - - -
    - -
    +
    +

    scale

    -
    (
      -
    • - scalar -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:227 - + src/math/Vec3.js:278

    - -
    @@ -2230,130 +1550,78 @@

    scale

    -

    Parameters:

      -
    • - scalar Number - -
      -
    • -
    • - target Vec3 - -
      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    set

    -
    (
      -
    • - x -
    • -
    • - y -
    • -
    • - z -
    • -
    )
    - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:57 - + src/math/Vec3.js:79

    - -
    @@ -2361,119 +1629,74 @@

    set

    -

    Parameters:

      -
    • - x Number - -
      -
    • -
    • - y Number - -
      -
    • -
    • - z Number - -
      -
    • -
    - -

    Returns:

    - -

    Vec3

    -
    - - -
    - -
    +
    +

    setZero

    - () - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:72 - + src/math/Vec3.js:94

    - -
    @@ -2481,70 +1704,39 @@

    setZero

    - - - -
    - -
    +
    +

    tangents

    -
    (
      -
    • - t1 -
    • -
    • - t2 -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:268 - + src/math/Vec3.js:319

    - -
    @@ -2552,98 +1744,61 @@

    tangents

    -

    Parameters:

      -
    • - t1 Vec3 - -

      Vector object to save the first tangent in

      -
    • -
    • - t2 Vec3 - -

      Vector object to save the second tangent in

      -
    • -
    - - - -
    - -
    +
    +

    toArray

    - () - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:307 - + src/math/Vec3.js:358

    - -
    @@ -2651,70 +1806,41 @@

    toArray

    - -

    Returns:

    - -

    Array

    -
    - - -
    - -
    +
    +

    toString

    - () - - - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:298 - + src/math/Vec3.js:349

    - -
    @@ -2722,80 +1848,47 @@

    toString

    - -

    Returns:

    - -

    string

    -
    - - -
    - -
    +
    +

    unit

    -
    (
      -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:152 - + src/math/Vec3.js:174

    - -
    @@ -2803,112 +1896,68 @@

    unit

    -

    Parameters:

      -
    • - target Vec3 - -

      Optional target to save in

      -
    • -
    - -

    Returns:

    - - Vec3: -

    Returns the unit vector

    -
    - - -
    - -
    +
    +

    vadd

    -
    (
      -
    • - v -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:80 - + src/math/Vec3.js:102

    - -
    @@ -2916,125 +1965,76 @@

    vadd

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - target Vec3 - -

      Optional.

      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    vsub

    -
    (
      -
    • - v -
    • -
    • - target -
    • -
    )
    - - Vec3 - - - - - - -
    - - -

    - Defined in - - - - - src/math/Vec3.js:99 - + src/math/Vec3.js:121

    - -
    @@ -3042,214 +2042,226 @@

    vsub

    -

    Parameters:

      -
    • - v Vec3 - -
      -
    • -
    • - target Vec3 - -

      Optional. Target to save in.

      -
    • -
    - -

    Returns:

    - - Vec3: - -
    - - -
    - +
    - -

    Properties

    - +
    +

    UNIT_X

    + Vec3 + + + + + static + +
    +

    + Defined in + src/math/Vec3.js:43 +

    + + +
    + +
    + +
    + + + +
    +
    +

    UNIT_Y

    + Vec3 + + + + + static + +
    +

    + Defined in + src/math/Vec3.js:49 +

    + + +
    + +
    + +
    + + + +
    +
    +

    UNIT_Z

    + Vec3 + + + + + static + +
    +

    + Defined in + src/math/Vec3.js:55 +

    + + +
    + +
    + +
    + + + +
    -

    x

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Vec3.js:18 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    x

    + Number + + + + + +
    +

    + Defined in + src/math/Vec3.js:18 +

    + + +
    + +
    + +
    + + + +
    -

    y

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Vec3.js:24 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    y

    + Number + + + + + +
    +

    + Defined in + src/math/Vec3.js:24 +

    + + +
    + +
    + +
    + + + +
    -

    z

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/math/Vec3.js:30 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    z

    + Number + + + + + +
    +

    + Defined in + src/math/Vec3.js:30 +

    + + +
    + +
    + +
    + + + +
    +
    +

    ZERO

    + Vec3 + + + + + static + +
    +

    + Defined in + src/math/Vec3.js:37 +

    + + +
    + +
    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/Vec3Pool.html b/docs/classes/Vec3Pool.html index 9e155aa35..f17c517c7 100644 --- a/docs/classes/Vec3Pool.html +++ b/docs/classes/Vec3Pool.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,379 +25,246 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    Vec3Pool Class

    +

    Vec3Pool Class

    - -
    Extends Pool
    - - - - -
    -
    -

    Constructor

    -

    Vec3Pool

    - - - () - - - - - - - - - - - - - - - - -
    +

    Vec3Pool

    - - -

    - - Defined in - - + () - src/utils/Vec3Pool.js:6 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/utils/Vec3Pool.js:6 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - -

    Properties

    - - -
    -

    Methods

    - -
    +

    constructObject

    - () - - Vec3 - - - - - - -
    -

    Inherited from Pool - but overwritten in - - - src/utils/Vec3Pool.js:17 -

    - -
    @@ -407,88 +272,50 @@

    constructObject

    - -

    Returns:

    - - Vec3: - -
    - - -
    - -
    +
    +

    defaults

    -
    (
      -
    • - options -
    • -
    • - defaults -
    • -
    )
    - - Object - - - - - static - - -
    - - -

    - Defined in - - - - src/utils/Utils.js:5 -

    - -
    @@ -496,109 +323,70 @@

    defaults

    -

    Parameters:

      -
    • - options Object - -

      The options object. May be falsy: in this case, a new object is created and returned.

      -
    • -
    • - defaults Object - -

      An object containing default values.

      -
    • -
    - -

    Returns:

    - - Object: -

    The modified options object.

    -
    - - -
    - -
    +
    +

    get

    - () - - Mixed - - - - - - -
    - -

    Inherited from Pool: - - - src/utils/Pool.js:34 -

    - -
    @@ -606,73 +394,43 @@

    get

    - -

    Returns:

    - - Mixed: - -
    - - -
    - -
    +
    +

    release

    -
    (
      -
    • - obj -
    • -
    )
    - - - - - - - -
    - -

    Inherited from Pool: - - - src/utils/Pool.js:22 -

    - -
    @@ -680,138 +438,86 @@

    release

    -

    Parameters:

      -
    • - obj Object - -
      -
    • -
    - - - -
    - +
    - -

    Properties

    -
    -

    objects

    - Array - - - - - - - - - -
    - - -

    Inherited from - Pool: - - - - src/utils/Pool.js:9 - -

    - - - - -
    - -
    -

    The pooled objects

    - -
    - - - - - - -
    - - +

    objects

    + Array + + + + + +
    +

    Inherited from + Pool: + src/utils/Pool.js:9 +

    + + +
    + +
    +

    The pooled objects

    + +
    + + + +
    -

    type

    - Mixed - - - - - - - - - -
    - - -

    Inherited from - Pool: - - - - src/utils/Pool.js:15 - -

    - - - - -
    - -
    -

    Constructor of the objects

    - -
    - - - - - - -
    - - +

    type

    + Mixed + + + + + +
    +

    Inherited from + Pool: + src/utils/Pool.js:15 +

    + + +
    + +
    +

    Constructor of the objects

    + +
    + + + +
    - - -
    -
    diff --git a/docs/classes/WheelInfo.html b/docs/classes/WheelInfo.html index 681748b3f..7341123c6 100644 --- a/docs/classes/WheelInfo.html +++ b/docs/classes/WheelInfo.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,2496 +25,1473 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    WheelInfo Class

    +

    WheelInfo Class

    - - - - - -
    -
    -

    Constructor

    -

    WheelInfo

    - - -
    - (
      - -
    • - - [options] - -
    • - -
    ) -
    - - - - - - - - - - - - - - - - -
    +

    WheelInfo

    + +
    + (
      +
    • + [options] +
    • +
    ) +
    - - -

    - - Defined in - - - src/objects/WheelInfo.js:8 -

    - - - -
    - -
    + +
    +

    + Defined in + src/objects/WheelInfo.js:8 +

    + + + +
    + +
    + +
    + +
    +

    Parameters:

    + +
      +
    • + [options] + Object + optional + + +
      + +
      + +
        +
      • + [chassisConnectionPointLocal] + Vec3 + optional + +
        + +
        + +
      • +
      • + [chassisConnectionPointWorld] + Vec3 + optional + +
        + +
        + +
      • +
      • + [directionLocal] + Vec3 + optional + +
        + +
        + +
      • +
      • + [directionWorld] + Vec3 + optional + +
        + +
        + +
      • +
      • + [axleLocal] + Vec3 + optional + +
        + +
        + +
      • +
      • + [axleWorld] + Vec3 + optional + +
        + +
        + +
      • +
      • + [suspensionRestLength=1] + Number + optional + +
        + +
        + +
      • +
      • + [suspensionMaxLength=2] + Number + optional + +
        + +
        + +
      • +
      • + [radius=1] + Number + optional + +
        + +
        + +
      • +
      • + [suspensionStiffness=100] + Number + optional + +
        + +
        + +
      • +
      • + [dampingCompression=10] + Number + optional + +
        + +
        + +
      • +
      • + [dampingRelaxation=10] + Number + optional + +
        + +
        + +
      • +
      • + [frictionSlip=10000] + Number + optional + +
        + +
        + +
      • +
      • + [steering=0] + Number + optional + +
        + +
        + +
      • +
      • + [rotation=0] + Number + optional + +
        + +
        + +
      • +
      • + [deltaRotation=0] + Number + optional + +
        + +
        + +
      • +
      • + [rollInfluence=0.01] + Number + optional + +
        + +
        + +
      • +
      • + [maxSuspensionForce] + Number + optional + +
        + +
        + +
      • +
      • + [isFrontWheel=true] + Boolean + optional + +
        + +
        + +
      • +
      • + [clippedInvContactDotSuspension=1] + Number + optional + +
        + +
        + +
      • +
      • + [suspensionRelativeVelocity=0] + Number + optional + +
        + +
        + +
      • +
      • + [suspensionForce=0] + Number + optional + +
        + +
        + +
      • +
      • + [skidInfo=0] + Number + optional + +
        + +
        + +
      • +
      • + [suspensionLength=0] + Number + optional + +
        + +
        + +
      • +
      • + [maxSuspensionTravel=1] + Number + optional + +
        + +
        + +
      • +
      • + [useCustomSlidingRotationalSpeed=false] + Boolean + optional + +
        + +
        + +
      • +
      • + [customSlidingRotationalSpeed=-0.1] + Number + optional + +
        + +
        + +
      • +
      +
    • +
    +
    + + + +
    - -
    -

    Parameters:

    +
    +
      +
    • Index
    • -
        - -
      • - - [options] - Object - optional - +
      • Properties
      • +
      - +
      +
      +

      Item Index

      -
      - -
      - -
        - -
      • - - [chassisConnectionPointLocal] - Vec3 - optional - +
        +

        Properties

        -
        - -
        +
          +
        • + axleLocal -
        • - -
        • - - [chassisConnectionPointWorld] - Vec3 - optional - - -
          - -
          +
        • + axleWorld -
        • - -
        • - - [directionLocal] - Vec3 - optional - - -
          - -
          +
        • + brake -
        • - -
        • - - [directionWorld] - Vec3 - optional - - -
          - -
          +
        • + chassisConnectionPointLocal -
        • - -
        • - - [axleLocal] - Vec3 - optional - - -
          - -
          +
        • + chassisConnectionPointWorld -
        • - -
        • - - [axleWorld] - Vec3 - optional - - -
          - -
          +
        • + clippedInvContactDotSuspension -
        • - -
        • - - [suspensionRestLength=1] - Number - optional - - -
          - -
          +
        • + customSlidingRotationalSpeed -
        • - -
        • - - [suspensionMaxLength=2] - Number - optional - - -
          - -
          +
        • + dampingCompression -
        • - -
        • - - [radius=1] - Number - optional - - -
          - -
          +
        • + dampingRelaxation -
        • - -
        • - - [suspensionStiffness=100] - Number - optional - - -
          - -
          +
        • + deltaRotation -
        • - -
        • - - [dampingCompression=10] - Number - optional - - -
          - -
          +
        • + directionLocal -
        • - -
        • - - [dampingRelaxation=10] - Number - optional - - -
          - -
          +
        • + directionWorld -
        • - -
        • - - [frictionSlip=10000] - Number - optional - - -
          - -
          +
        • + engineForce -
        • - -
        • - - [steering=0] - Number - optional - - -
          - -
          +
        • + forwardImpulse -
        • - -
        • - - [rotation=0] - Number - optional - - -
          - -
          +
        • + frictionSlip -
        • - -
        • - - [deltaRotation=0] - Number - optional - - -
          - -
          +
        • + isFrontWheel -
        • - -
        • - - [rollInfluence=0.01] - Number - optional - - -
          - -
          +
        • + isInContact -
        • - -
        • - - [maxSuspensionForce] - Number - optional - - -
          - -
          +
        • + maxSuspensionForce -
        • - -
        • - - [isFrontWheel=true] - Number - optional - - -
          - -
          +
        • + maxSuspensionTravel -
        • - -
        • - - [clippedInvContactDotSuspension=1] - Number - optional - - -
          - -
          +
        • + radius -
        • - -
        • - - [suspensionRelativeVelocity=0] - Number - optional - - -
          - -
          +
        • + raycastResult -
        • - -
        • - - [suspensionForce=0] - Number - optional - - -
          - -
          +
        • + rollInfluence -
        • - -
        • - - [skidInfo=0] - Number - optional - - -
          - -
          +
        • + rotation -
        • - -
        • - - [suspensionLength=0] - Number - optional - - -
          - -
          +
        • + sideImpulse -
        • - -
        • - - [maxSuspensionTravel=1] - Number - optional - - -
          - -
          +
        • + skidInfo -
        • - -
        • - - [useCustomSlidingRotationalSpeed=false] - Number - optional - - -
          - -
          +
        • + sliding -
        • - -
        • - - [customSlidingRotationalSpeed=-0.1] - Number - optional - - -
          - -
          +
        • + steering -
        • - -
        - -
      • - -
      -
      - - - - - -
      - -
    - - -
    - - -
    -
    -

    Item Index

    - - - - -
    -

    Properties

    - -
    - - -
    - -

    Properties

    -
    -

    axleLocal

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:116 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    axleLocal

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:116 +

    + + +
    + +
    + +
    + + + +
    -

    axleWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:121 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    axleWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:121 +

    + + +
    + +
    + +
    + + + +
    -

    brake

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:192 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    brake

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:192 +

    + + +
    + +
    + +
    + + + +
    -

    chassisConnectionPointLocal

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:95 - -

    - - - - -
    - -
    -

    Connection point, defined locally in the chassis body frame.

    - -
    - - - - - - -
    - - +

    chassisConnectionPointLocal

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:95 +

    + + +
    + +
    +

    Connection point, defined locally in the chassis body frame.

    + +
    + + + +
    -

    chassisConnectionPointWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:101 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    chassisConnectionPointWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:101 +

    + + +
    + +
    + +
    + + + +
    -

    clippedInvContactDotSuspension

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:202 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    clippedInvContactDotSuspension

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:202 +

    + + +
    + +
    + +
    + + + +
    -

    customSlidingRotationalSpeed

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:78 - -

    - - - - -
    - -
    -

    Speed to apply to the wheel rotation when the wheel is sliding.

    - -
    - - - - - - -
    - - +

    customSlidingRotationalSpeed

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:78 +

    + + +
    + +
    +

    Speed to apply to the wheel rotation when the wheel is sliding.

    + +
    + + + +
    -

    dampingCompression

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:146 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    dampingCompression

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:146 +

    + + +
    + +
    + +
    + + + +
    -

    dampingRelaxation

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:151 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    dampingRelaxation

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:151 +

    + + +
    + +
    + +
    + + + +
    -

    deltaRotation

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:172 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    deltaRotation

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:172 +

    + + +
    + +
    + +
    + + + +
    -

    directionLocal

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:106 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    directionLocal

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:106 +

    + + +
    + +
    + +
    + + + +
    -

    directionWorld

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:111 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    directionWorld

    + Vec3 + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:111 +

    + + +
    + +
    + +
    + + + +
    -

    engineForce

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:187 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - -
    -

    forwardImpulse

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:232 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    engineForce

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:187 +

    + + +
    + +
    + +
    + + + + +
    +

    forwardImpulse

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:232 +

    + + +
    + +
    + +
    + + + +
    -

    frictionSlip

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:156 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    frictionSlip

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:156 +

    + + +
    + +
    + +
    + + + +
    -

    isFrontWheel

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:197 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    isFrontWheel

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:197 +

    + + +
    + +
    + +
    + + + +
    -

    isInContact

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:249 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    isInContact

    + Boolean + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:249 +

    + + +
    + +
    + +
    + + + +
    -

    maxSuspensionForce

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:182 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    maxSuspensionForce

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:182 +

    + + +
    + +
    + +
    + + + +
    -

    maxSuspensionTravel

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:72 - -

    - - - - -
    - -
    -

    Max travel distance of the suspension, in meters.

    - -
    - - - - - - -
    - - +

    maxSuspensionTravel

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:72 +

    + + +
    + +
    +

    Max travel distance of the suspension, in meters.

    + +
    + + + +
    -

    radius

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:136 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    radius

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:136 +

    + + +
    + +
    + +
    + + + +
    -

    raycastResult

    - RaycastResult - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:237 - -

    - - - - -
    - -
    -

    The result from raycasting

    - -
    - - - - - - -
    - - +

    raycastResult

    + RaycastResult + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:237 +

    + + +
    + +
    +

    The result from raycasting

    + +
    + + + +
    -

    rollInfluence

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:177 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    rollInfluence

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:177 +

    + + +
    + +
    + +
    + + + +
    -

    rotation

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:166 - -

    - - - - -
    - -
    -

    Rotation value, in radians.

    - -
    - - - - - - -
    - - -
    -

    sideImpulse

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:227 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - -
    -

    skidInfo

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:217 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    rotation

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:166 +

    + + +
    + +
    +

    Rotation value, in radians.

    + +
    + + + + +
    +

    sideImpulse

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:227 +

    + + +
    + +
    + +
    + + + +
    +
    +

    skidInfo

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:217 +

    + + +
    + +
    + +
    + + + +
    -

    sliding

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:90 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    sliding

    + Boolean + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:90 +

    + + +
    + +
    + +
    + + + +
    -

    steering

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:161 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    steering

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:161 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionForce

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:212 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionForce

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:212 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionLength

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:222 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionLength

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:222 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionMaxLength

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:131 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionMaxLength

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:131 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionRelativeVelocity

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:207 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionRelativeVelocity

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:207 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionRestLength

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:126 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionRestLength

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:126 +

    + + +
    + +
    + +
    + + + +
    -

    suspensionStiffness

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:141 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    suspensionStiffness

    + Number + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:141 +

    + + +
    + +
    + +
    + + + +
    -

    useCustomSlidingRotationalSpeed

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:84 - -

    - - - - -
    - -
    -

    If the customSlidingRotationalSpeed should be used.

    - -
    - - - - - - -
    - - +

    useCustomSlidingRotationalSpeed

    + Boolean + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:84 +

    + + +
    + +
    +

    If the customSlidingRotationalSpeed should be used.

    + +
    + + + +
    -

    worldTransform

    - Transform - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/objects/WheelInfo.js:243 - -

    - - - - -
    - -
    -

    Wheel world transform

    - -
    - - - - - - -
    - - +

    worldTransform

    + Transform + + + + + +
    +

    + Defined in + src/objects/WheelInfo.js:243 +

    + + +
    + +
    +

    Wheel world transform

    + +
    + + + + - - - - diff --git a/docs/classes/World.html b/docs/classes/World.html index 25c41bf58..d8e544f21 100644 --- a/docs/classes/World.html +++ b/docs/classes/World.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,616 +25,400 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    World Class

    +

    World Class

    - -
    Extends EventTarget
    - -
    Defined in: src/world/World.js:24
    - - -
    -

    The physics world

    -

    Constructor

    -

    World

    - - - () - - - - - - - - - - - - - - - - -
    +

    World

    - - -

    - - Defined in - - + () - src/world/World.js:24 -

    - - - -
    - -
    + + +
    +

    + Defined in + src/world/World.js:24 +

    + + + +
    + +
    + +
    + + + + +
    - - - - - -
    - -
    - -

    Item Index

    -

    Methods

    - - - - -
    -

    Methods

    - -
    +

    add

    -
    (
      -
    • - body -
    • -
    )
    - - - deprecated - - - - - -
    - - -

    - Defined in - - - - src/world/World.js:238 -

    -

    Deprecated: Use .addBody instead

    - -
    @@ -644,87 +426,52 @@

    add

    -

    Parameters:

      -
    • - body Body - -
      -
    • -
    - - - -
    - -
    +
    +

    addConstraint

    -
    (
      -
    • - c -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - src/world/World.js:265 -

    - -
    @@ -732,87 +479,52 @@

    addConstraint

    -

    Parameters:

    - - - -
    - -
    +
    +

    addContactMaterial

    -
    (
      -
    • - cmat -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:341 - + src/world/World.js:413

    - -
    @@ -820,94 +532,58 @@

    addContactMaterial

    -

    Parameters:

    - - - -
    - -
    +
    +

    addEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - EventTarget - - - - - - -
    - -

    Inherited from EventTarget: - - - src/utils/EventTarget.js:15 -

    - -
    @@ -915,116 +591,71 @@

    addEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    addMaterial

    -
    (
      -
    • - m -
    • -
    )
    - - - - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:331 - + src/world/World.js:403

    - -
    @@ -1032,77 +663,77 @@

    addMaterial

    -

    Parameters:

    - - - +
    +
    +

    clearForces

    - -
    + () + + + + + + + + +
    +

    + Defined in + src/world/World.js:936 +

    + + + +
    + +
    +

    Sets all body forces in the world to zero.

    + +
    + + + + +
    +

    collisionMatrixTick

    - () - - - - - - - -
    - - -

    - Defined in - - - - src/world/World.js:227 -

    - -
    @@ -1110,65 +741,39 @@

    collisionMatrixTick

    - - - -
    - -
    +
    +

    dispatchEvent

    -
    (
      -
    • - event -
    • -
    )
    - - EventTarget - - - - - - -
    - -

    Inherited from EventTarget: - - - src/utils/EventTarget.js:68 -

    - -
    @@ -1176,128 +781,78 @@

    dispatchEvent

    -

    Parameters:

      -
    • - event Object - -
      -
        -
      • - type String -
        -
      • -
      -
    • -
    - -

    Returns:

    - - EventTarget: -

    The self object, for chainability.

    -
    - - -
    - -
    +
    +

    getContactMaterial

    -
    (
      -
    • - m1 -
    • -
    • - m2 -
    • -
    )
    - - - Contactmaterial + ContactMaterial - - - - - - -
    - - -

    - Defined in - - - - src/world/World.js:206 -

    - -
    @@ -1305,123 +860,77 @@

    getContactMaterial

    -

    Parameters:

    - -

    Returns:

    - - - Contactmaterial: - + ContactMaterial:

    The contact material if it was found.

    -
    - - -
    - -
    +
    +

    hasEventListener

    -
    (
      -
    • - type -
    • -
    • - listener -
    • -
    )
    - - Boolean - - - - - - -
    - -

    Inherited from EventTarget: - - - src/utils/EventTarget.js:34 -

    - -
    @@ -1429,110 +938,67 @@

    hasEventListener

    -

    Parameters:

      -
    • - type String - -
      -
    • -
    • - listener Function - -
      -
    • -
    - -

    Returns:

    - - Boolean: - -
    - - -
    - -
    +
    +

    numObjects

    - () - - Number - - deprecated - - - - - -
    - - -

    - Defined in - - - - src/world/World.js:217 -

    - -
    @@ -1540,1686 +1006,1471 @@

    numObjects

    - -

    Returns:

    - - Number: - -
    - - -
    - -
    -

    rayTest

    +
    +
    +

    raycastAll

    -
    (
      -
    • - from -
    • -
    • - to -
    • -
    • - - result - + options +
    • +
    • + callback
    • -
    )
    - - + + Boolean + - - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:286 - + src/world/World.js:308

    - -
    -

    Raycast test

    +

    Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.

    -

    Parameters:

      -
    • - from Vec3 - -
      -
    • -
    • - to Vec3 - -
      -
    • -
    • - - result - Function | RaycastResult - + options + Object -
      - -
    • - -
    -
    - +
      +
    • + [collisionFilterMask=-1] + Number + optional - +
      + +
      - -
    + +
  • + [collisionFilterGroup=-1] + Number + optional - -
    -

    remove

    +
    + +
    - -
    - (
      - -
    • - - body - -
    • - + +
    • + [skipBackfaces=false] + Boolean + optional + +
      + +
      + +
    • +
    • + [checkCollisionResponse=true] + Boolean + optional + +
      + +
      + +
    • +
    +
  • +
  • + callback + Function + + +
    + +
    + +
  • + +
    + +
    +

    Returns:

    + +
    + Boolean: +

    True if any body was hit.

    + +
    +
    + + +
    +
    +

    raycastAny

    + +
    + (
      +
    • + from +
    • +
    • + to +
    • +
    • + options +
    • +
    • + result +
    )
    - - + + Boolean + - - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:306 - + src/world/World.js:329

    - -
    -

    Remove a rigid body from the simulation.

    +

    Ray cast, and stop at the first result. Note that the order is random - but the method is fast.

    -

    Parameters:

      -
    • - - body - Body - + from + Vec3 -
      -
    • - -
    -
    - - - +
  • + to + Vec3 - -
  • - -
    -

    removeConstraint

    +
    + +
    - -
    - (
      - -
    • - - c -
    • - -
    ) -
    - - - - - - - - - +
  • + options + Object - - +
    + +
    - +
      +
    • + [collisionFilterMask=-1] + Number + optional -
      - - - -

      - - Defined in - - - - - src/world/World.js:274 - -

      +
      + +
      +
    • +
    • + [collisionFilterGroup=-1] + Number + optional - +
      + +
      - -
  • + +
  • + [skipBackfaces=false] + Boolean + optional -
    -

    Removes a constraint

    +
    + +
    -
    +
  • +
  • + [checkCollisionResponse=true] + Boolean + optional - -
    -

    Parameters:

    +
    + +
    -
      - + +
    +
  • - - c - Constraint - + result + RaycastResult -
    -
  • -
    - - +
    +

    Returns:

    - -
    +
    + Boolean: +

    True if any body was hit.

    - -
    -

    removeEventListener

    +
    +
    + + +
    +
    +

    raycastClosest

    -
    (
      -
    • - - type - + from
    • -
    • - - listener - + to +
    • +
    • + options +
    • +
    • + result
    • -
    )
    - - - EventTarget + Boolean - - - - - - -
    - - -

    Inherited from - EventTarget: - - - - src/utils/EventTarget.js:50 - +

    + Defined in + src/world/World.js:350

    - -
    -

    Remove an event listener

    +

    Ray cast, and return information of the closest hit.

    -

    Parameters:

      -
    • - - type - String - + from + Vec3 -
      -
    • -
    • - - listener - Function - + to + Vec3 -
      -
    • - -
    -
    - +
  • + options + Object - -
    -

    Returns:

    -
    - - - EventTarget: - -

    The self object, for chainability.

    +
    + +
    - -
    -
    - +
      +
    • + [collisionFilterMask=-1] + Number + optional - -
  • +
    + +
    - -
    -

    step

    + +
  • + [collisionFilterGroup=-1] + Number + optional + +
    + +
    + +
  • +
  • + [skipBackfaces=false] + Boolean + optional + +
    + +
    + +
  • +
  • + [checkCollisionResponse=true] + Boolean + optional + +
    + +
    + +
  • + + +
  • + result + RaycastResult + + +
    + +
    + +
  • + +
    + +
    +

    Returns:

    + +
    + Boolean: +

    True if any body was hit.

    + +
    +
    + + +
    +
    +

    rayTest

    -
    (
      -
    • - - dt - + from
    • -
    • - - [timeSinceLastCalled] - + to
    • -
    • - - [maxSubSteps=10] - + result
    • -
    )
    - - - + deprecated - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:371 - + src/world/World.js:286

    - +

    Deprecated: Use .raycastAll, .raycastClosest or .raycastAny instead.

    -
    -

    Step the physics world forward in time.

    -

    There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.

    +

    Raycast test

    -

    Parameters:

      -
    • - - dt - Number - + from + Vec3 -
      -

      The fixed time step size to use.

      - +
      -
    • -
    • - - [timeSinceLastCalled] - Number - optional - + to + Vec3 -
      -

      The time elapsed since the function was last called.

      - +
      -
    • -
    • - - [maxSubSteps=10] - Number - optional - + result + Function | RaycastResult -
      -

      Maximum number of fixed steps to take per function call.

      - +
      -
    • -
    - - - - -
    -

    Example:

    -
    -
    // fixed timestepping without interpolation
    -world.step(1/60);
    -
    -
    -
    +
    +

    remove

    - -
    -

    step

    - -
    (
      -
    • - - dt - + body
    • -
    )
    - - - + deprecated - - - - -
    - - -

    - Defined in - - - - - src/world/World.js:445 - + src/world/World.js:371

    - +

    Deprecated: Use .removeBody instead

    -
    -

    Step the simulation

    +

    Remove a rigid body from the simulation.

    -

    Parameters:

      -
    • - - dt - Number - + body + Body -
      -
    • -
    - - - +
    +
    +

    removeBody

    + +
    + (
      +
    • + body +
    • +
    ) +
    - -
    - - -
    -

    Properties

    - -
    -

    allowSleep

    - Boolean - - - -
    - - -

    - Defined in - - - - - src/world/World.js:39 - + src/world/World.js:396

    - - +
    -

    Makes bodies go to sleep when they've been inactive

    +

    Remove a rigid body from the simulation.

    - - - - - -
    - - -
    -

    bodies

    - Array - - +
    +

    Parameters:

    - + +
    - - -
    -
    - -
    +
    +
    +

    removeConstraint

    - +
    + (
      +
    • + c +
    • +
    ) +
    - - -
    - -
    -

    broadphase

    - Broadphase - - - -
    - - -

    - Defined in - - - - - src/world/World.js:94 - + src/world/World.js:274

    - - +
    - +

    Removes a constraint

    +
    - +
    +

    Parameters:

    - - - -
    - - -
    -

    collisionMatrix

    - ArrayCollisionMatrix - - - - + +
    - - -
    -
    - -
    +
    +
    +

    removeEventListener

    - +
    + (
      +
    • + type +
    • +
    • + listener +
    • +
    ) +
    - + + EventTarget + - -
    - -
    -

    collisionMatrixPrevious

    - ArrayCollisionMatrix - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:130 - +

    Inherited from + EventTarget: + src/utils/EventTarget.js:50

    - - +
    -

    CollisionMatrix from the previous step.

    +

    Remove an event listener

    - +
    +

    Parameters:

    - +
      +
    • + type + String - -
    - -
    -

    constraints

    - Array +
    + +
    - + +
  • + listener + Function - - +
    + +
    - +
  • + +
    -
    - - - -

    - - Defined in - - - - - src/world/World.js:112 - -

    +
    +

    Returns:

    - +
    + EventTarget: +

    The self object, for chainability.

    - -
    +
    +
    -
    - -
    - +
    +
    +

    step

    + +
    + (
      +
    • + dt +
    • +
    • + [timeSinceLastCalled] +
    • +
    • + [maxSubSteps=10] +
    • +
    ) +
    - - -
    - -
    -

    contactmaterials

    - Array - - - -
    - - -

    - Defined in - - - - - src/world/World.js:144 - + src/world/World.js:443

    - - +
    - +

    Step the physics world forward in time.

    +

    There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.

    +
    - +
    +

    Parameters:

    - +
      +
    • + dt + Number - -
    - -
    -

    contactMaterialTable

    - TupleDictionary +
    +

    The fixed time step size to use.

    - +
    - + +
  • + [timeSinceLastCalled] + Number + optional - - +
    +

    The time elapsed since the function was last called.

    -
    - - - -

    - - Defined in - - - - - src/world/World.js:150 - -

    +
    - +
  • +
  • + [maxSubSteps=10] + Number + optional - -
  • -
    -

    Used to look up a ContactMaterial given two instances of Material.

    +
    +

    Maximum number of fixed steps to take per function call.

    + +
    + + + +
    -
    - - +
    +

    Example:

    - +
    +
    // fixed timestepping without interpolation
    +world.step(1/60);
    +
    +
    +
    +
    +

    step

    + +
    + (
      +
    • + dt +
    • +
    ) +
    + + - -
    -

    contacts

    - Array - - - -
    - - -

    - Defined in - - - - - src/world/World.js:46 - + src/world/World.js:517

    - - +
    -

    All the current contacts (instances of ContactEquation) in the world.

    +

    Step the simulation

    - +
    +

    Parameters:

    - +
      +
    • + dt + Number - -
    - -
    -

    defaultContactMaterial

    - ContactMaterial +
    + +
    - + + +
    - - - +
    +
    -
    - - - -

    - - Defined in - - - - - src/world/World.js:158 - -

    - - - - -
    - -
    -

    This contact material is used if no suitable contactmaterial is found for a contact.

    - -
    - - - - - - -
    +
    +

    Properties

    - +
    +

    allowSleep

    + Boolean + + + + + +
    +

    + Defined in + src/world/World.js:39 +

    + + +
    + +
    +

    Makes bodies go to sleep when they've been inactive

    + +
    + + + +
    +
    +

    bodies

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:100 +

    + + +
    + +
    + +
    + + + +
    +
    +

    broadphase

    + Broadphase + + + + + +
    +

    + Defined in + src/world/World.js:94 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collisionMatrix

    + ArrayCollisionMatrix + + + + + +
    +

    + Defined in + src/world/World.js:124 +

    + + +
    + +
    + +
    + + + +
    +
    +

    collisionMatrixPrevious

    + ArrayCollisionMatrix + + + + + +
    +

    + Defined in + src/world/World.js:130 +

    + + +
    + +
    +

    CollisionMatrix from the previous step.

    + +
    + + + +
    +
    +

    constraints

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:112 +

    + + +
    + +
    + +
    + + + +
    +
    +

    contactmaterials

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:144 +

    + + +
    + +
    + +
    + + + +
    +
    +

    contactMaterialTable

    + TupleDictionary + + + + + +
    +

    + Defined in + src/world/World.js:150 +

    + + +
    + +
    +

    Used to look up a ContactMaterial given two instances of Material.

    + +
    + + + +
    +
    +

    contacts

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:46 +

    + + +
    + +
    +

    All the current contacts (instances of ContactEquation) in the world.

    + +
    + + + +
    +
    +

    defaultContactMaterial

    + ContactMaterial + + + + + +
    +

    + Defined in + src/world/World.js:158 +

    + + +
    + +
    +

    This contact material is used if no suitable contactmaterial is found for a contact.

    + +
    + + + +
    -

    doProfiling

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:165 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    doProfiling

    + Boolean + + + + + +
    +

    + Defined in + src/world/World.js:165 +

    + + +
    + +
    + +
    + + + +
    -

    dt

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:33 - -

    - - - - -
    - -
    -

    Last used timestep. Is set to -1 if not available.

    - -
    - - - - - - -
    - - +

    dt

    + Number + + + + + +
    +

    + Defined in + src/world/World.js:33 +

    + + +
    + +
    +

    Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks.

    + +
    + + + +
    -

    gravity

    - Vec3 - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:88 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    gravity

    + Vec3 + + + + + +
    +

    + Defined in + src/world/World.js:88 +

    + + +
    + +
    + +
    + + + +
    -

    materials

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:137 - -

    - - - - -
    - -
    -

    All added materials

    - -
    - - - - - - -
    - - +

    materials

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:137 +

    + + +
    + +
    +

    All added materials

    + +
    + + + +
    -

    narrowphase

    - Narrowphase - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:118 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    narrowphase

    + Narrowphase + + + + + +
    +

    + Defined in + src/world/World.js:118 +

    + + +
    + +
    + +
    + + + +
    -

    profile

    - Object - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:171 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - -
    -

    quatNormalizeFast

    - Boolean - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:61 - -

    - - - - -
    - -
    -

    Set to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.

    - -
    - - - - - - -
    - - +

    profile

    + Object + + + + + +
    +

    + Defined in + src/world/World.js:171 +

    + + +
    + +
    + +
    + + + + +
    +

    quatNormalizeFast

    + Boolean + + + + + +
    +

    + Defined in + src/world/World.js:61 +

    + + +
    + +
    +

    Set to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.

    + +
    + + + +
    -

    quatNormalizeSkip

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:54 - -

    - - - - -
    - -
    -

    How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).

    - -
    - - - - - - -
    - - +

    quatNormalizeSkip

    + Number + + + + + +
    +

    + Defined in + src/world/World.js:54 +

    + + +
    + +
    +

    How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).

    + +
    + + + +
    -

    solver

    - Solver - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:106 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    solver

    + Solver + + + + + +
    +

    + Defined in + src/world/World.js:106 +

    + + +
    + +
    + +
    + + + +
    -

    stepnumber

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:77 - -

    - - - - -
    - -
    -

    Number of timesteps taken since start

    - -
    - - - - - - -
    - - -
    -

    subystems

    - Array - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:183 - -

    - - - - -
    - -
    - -
    - - - - - - -
    - - +

    stepnumber

    + Number + + + + + +
    +

    + Defined in + src/world/World.js:77 +

    + + +
    + +
    +

    Number of timesteps taken since start

    + +
    + + + + +
    +

    subsystems

    + Array + + + + + +
    +

    + Defined in + src/world/World.js:183 +

    + + +
    + +
    + +
    + + + +
    -

    time

    - Number - - - - - - - - - -
    - - - -

    - - Defined in - - - - - src/world/World.js:70 - -

    - - - - -
    - -
    -

    The wall-clock time since simulation start

    - -
    - - - - - - -
    - - +

    time

    + Number + + + + + +
    +

    + Defined in + src/world/World.js:70 +

    + + +
    + +
    +

    The wall-clock time since simulation start

    + +
    + + + + - - - - diff --git a/docs/data.json b/docs/data.json index b12cf932a..28e3c2c9e 100644 --- a/docs/data.json +++ b/docs/data.json @@ -86,6 +86,15 @@ "fors": {}, "namespaces": {} }, + "src/constraints/ConeTwistConstraint.js": { + "name": "src/constraints/ConeTwistConstraint.js", + "modules": {}, + "classes": { + "ConeTwistConstraint": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/constraints/Constraint.js": { "name": "src/constraints/Constraint.js", "modules": {}, @@ -113,6 +122,15 @@ "fors": {}, "namespaces": {} }, + "src/constraints/LockConstraint.js": { + "name": "src/constraints/LockConstraint.js", + "modules": {}, + "classes": { + "LockConstraint": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/constraints/PointToPointConstraint.js": { "name": "src/constraints/PointToPointConstraint.js", "modules": {}, @@ -131,6 +149,15 @@ "fors": {}, "namespaces": {} }, + "src/equations/ConeEquation.js": { + "name": "src/equations/ConeEquation.js", + "modules": {}, + "classes": { + "ConeEquation": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/equations/ContactEquation.js": { "name": "src/equations/ContactEquation.js", "modules": {}, @@ -365,6 +392,15 @@ "fors": {}, "namespaces": {} }, + "src/shapes/Trimesh.js": { + "name": "src/shapes/Trimesh.js", + "modules": {}, + "classes": { + "Trimesh": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/solver/GSSolver.js": { "name": "src/solver/GSSolver.js", "modules": {}, @@ -401,6 +437,16 @@ "fors": {}, "namespaces": {} }, + "src/utils/Octree.js": { + "name": "src/utils/Octree.js", + "modules": {}, + "classes": { + "OctreeNode": 1, + "Octree": 1 + }, + "fors": {}, + "namespaces": {} + }, "src/utils/Pool.js": { "name": "src/utils/Pool.js", "modules": {}, @@ -478,13 +524,13 @@ { "name": "upperBound", "description": "", - "type": "Array", + "type": "Vec3", "optional": true }, { "name": "lowerBound", "description": "", - "type": "Array", + "type": "Vec3", "optional": true } ] @@ -649,6 +695,71 @@ ], "extends": "Broadphase" }, + "ConeTwistConstraint": { + "name": "ConeTwistConstraint", + "shortname": "ConeTwistConstraint", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/constraints/ConeTwistConstraint.js", + "line": 10, + "is_constructor": 1, + "author": "schteppe", + "params": [ + { + "name": "bodyA", + "description": "", + "type": "Body" + }, + { + "name": "bodyB", + "description": "", + "type": "Body" + }, + { + "name": "options", + "description": "", + "type": "Object", + "optional": true, + "props": [ + { + "name": "pivotA", + "description": "", + "type": "Vec3", + "optional": true + }, + { + "name": "pivotB", + "description": "", + "type": "Vec3", + "optional": true + }, + { + "name": "axisA", + "description": "", + "type": "Vec3", + "optional": true + }, + { + "name": "axisB", + "description": "", + "type": "Vec3", + "optional": true + }, + { + "name": "maxForce", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1e6" + } + ] + } + ], + "extends": "PointToPointConstraint" + }, "Constraint": { "name": "Constraint", "shortname": "Constraint", @@ -707,7 +818,7 @@ "extension_for": [], "file": "src/constraints/DistanceConstraint.js", "line": 6, - "description": "Constrains two bodies to be at a constant distance from each other.", + "description": "Constrains two bodies to be at a constant distance from each others center of mass.", "is_constructor": 1, "author": "schteppe", "params": [ @@ -723,13 +834,16 @@ }, { "name": "distance", - "description": "", - "type": "Number" + "description": "The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB", + "type": "Number", + "optional": true }, { "name": "maxForce", "description": "", - "type": "Number" + "type": "Number", + "optional": true, + "optdefault": "1e6" } ], "extends": "Constraint" @@ -743,20 +857,20 @@ "plugin_for": [], "extension_for": [], "file": "src/constraints/HingeConstraint.js", - "line": 9, - "description": "Hinge constraint. Tries to keep the local body axes equal.", + "line": 10, + "description": "Hinge constraint. Think of it as a door hinge. It tries to keep the door in the correct place and with the correct orientation.", "is_constructor": 1, "author": "schteppe", "params": [ { "name": "bodyA", "description": "", - "type": "RigidBody" + "type": "Body" }, { "name": "bodyB", "description": "", - "type": "RigidBody" + "type": "Body" }, { "name": "options", @@ -772,7 +886,7 @@ }, { "name": "axisA", - "description": "an axis that bodyA can rotate around.", + "description": "An axis that bodyA can rotate around, defined locally in bodyA.", "type": "Vec3", "optional": true }, @@ -798,7 +912,49 @@ ] } ], - "extends": "Constraint" + "extends": "PointToPointConstraint" + }, + "LockConstraint": { + "name": "LockConstraint", + "shortname": "LockConstraint", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/constraints/LockConstraint.js", + "line": 10, + "description": "Lock constraint. Will remove all degrees of freedom between the bodies.", + "is_constructor": 1, + "author": "schteppe", + "params": [ + { + "name": "bodyA", + "description": "", + "type": "Body" + }, + { + "name": "bodyB", + "description": "", + "type": "Body" + }, + { + "name": "options", + "description": "", + "type": "Object", + "optional": true, + "props": [ + { + "name": "maxForce", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1e6" + } + ] + } + ], + "extends": "PointToPointConstraint" }, "PointToPointConstraint": { "name": "PointToPointConstraint", @@ -809,7 +965,7 @@ "plugin_for": [], "extension_for": [], "file": "src/constraints/PointToPointConstraint.js", - "line": 6, + "line": 7, "description": "Connects two bodies at given offset points.", "extends": "Constraint", "is_constructor": 1, @@ -826,7 +982,7 @@ }, { "name": "bodyB", - "description": "Body that will be constrained in a similar way to the same point as bodyA. We will therefore get sort of a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point.", + "description": "Body that will be constrained in a similar way to the same point as bodyA. We will therefore get a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point.", "type": "Body" }, { @@ -864,6 +1020,58 @@ } ] }, + "ConeEquation": { + "name": "ConeEquation", + "shortname": "ConeEquation", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/equations/ConeEquation.js", + "line": 7, + "description": "Cone equation. Works to keep the given body world vectors aligned, or tilted within a given angle from each other.", + "is_constructor": 1, + "author": "schteppe", + "params": [ + { + "name": "bodyA", + "description": "", + "type": "Body" + }, + { + "name": "bodyB", + "description": "", + "type": "Body" + }, + { + "name": "options.axisA", + "description": "Local axis in A", + "type": "Vec3", + "optional": true + }, + { + "name": "options.axisB", + "description": "Local axis in B", + "type": "Vec3", + "optional": true + }, + { + "name": "options.angle", + "description": "The \"cone angle\" to keep", + "type": "Vec3", + "optional": true + }, + { + "name": "options.maxForce", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1e6" + } + ], + "extends": "Equation" + }, "ContactEquation": { "name": "ContactEquation", "shortname": "ContactEquation", @@ -879,12 +1087,12 @@ "author": "schteppe", "params": [ { - "name": "bj", + "name": "bodyA", "description": "", "type": "Body" }, { - "name": "bi", + "name": "bodyB", "description": "", "type": "Body" } @@ -942,12 +1150,12 @@ "author": "schteppe", "params": [ { - "name": "bi", + "name": "bodyA", "description": "", "type": "Body" }, { - "name": "bj", + "name": "bodyB", "description": "", "type": "Body" }, @@ -969,29 +1177,37 @@ "extension_for": [], "file": "src/equations/RotationalEquation.js", "line": 7, - "description": "Rotational constraint. Works to keep the local vectors orthogonal to each other.", + "description": "Rotational constraint. Works to keep the local vectors orthogonal to each other in world space.", "is_constructor": 1, "author": "schteppe", "params": [ { - "name": "bj", + "name": "bodyA", "description": "", - "type": "RigidBody" + "type": "Body" }, { - "name": "localVectorInBodyA", + "name": "bodyB", "description": "", - "type": "Vec3" + "type": "Body" }, { - "name": "bi", + "name": "options.axisA", + "description": "", + "type": "Vec3", + "optional": true + }, + { + "name": "options.axisB", "description": "", - "type": "RigidBody" + "type": "Vec3", + "optional": true }, { - "name": "localVectorInBodyB", + "name": "options.maxForce", "description": "", - "type": "Vec3" + "type": "Number", + "optional": true } ], "extends": "Equation" @@ -1006,19 +1222,19 @@ "extension_for": [], "file": "src/equations/RotationalMotorEquation.js", "line": 7, - "description": "Rotational motor constraint. Works to keep the relative angular velocity of the bodies to a given value", + "description": "Rotational motor constraint. Tries to keep the relative angular velocity of the bodies to a given value.", "is_constructor": 1, "author": "schteppe", "params": [ { "name": "bodyA", "description": "", - "type": "RigidBody" + "type": "Body" }, { "name": "bodyB", "description": "", - "type": "RigidBody" + "type": "Body" }, { "name": "maxForce", @@ -1117,9 +1333,10 @@ "is_constructor": 1, "params": [ { - "name": "name", + "name": "options", "description": "", - "type": "String" + "type": "Object", + "optional": true } ], "author": "schteppe" @@ -1291,6 +1508,12 @@ "type": "Number", "optional": true }, + { + "name": "material", + "description": "", + "type": "Material", + "optional": true + }, { "name": "type", "description": "", @@ -1301,44 +1524,100 @@ "name": "linearDamping", "description": "", "type": "Number", - "optional": true - } - ] - } - ], - "example": [ - "\n var body = new Body({\n mass: 1\n });\n var shape = new Sphere(1);\n body.addShape(shape);\n world.add(body);" - ] - }, - "RaycastVehicle": { - "name": "RaycastVehicle", - "shortname": "RaycastVehicle", - "classitems": [], - "plugins": [], - "extensions": [], - "plugin_for": [], - "extension_for": [], - "file": "src/objects/RaycastVehicle.js", - "line": 10, - "description": "Vehicle helper class that casts rays from the wheel positions towards the ground and applies forces.", - "is_constructor": 1, - "params": [ - { - "name": "options", - "description": "", - "type": "Object", - "optional": true, - "props": [ - { - "name": "chassisBody", - "description": "The car chassis body.", - "type": "Body", - "optional": true + "optional": true, + "optdefault": "0.01" }, { - "name": "indexRightAxis", - "description": "Axis to use for right. x=0, y=1, z=2", - "type": "Integer", + "name": "angularDamping", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "0.01" + }, + { + "name": "allowSleep", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "true" + }, + { + "name": "sleepSpeedLimit", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "0.1" + }, + { + "name": "sleepTimeLimit", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1" + }, + { + "name": "collisionFilterGroup", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1" + }, + { + "name": "collisionFilterMask", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1" + }, + { + "name": "fixedRotation", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "false" + }, + { + "name": "shape", + "description": "", + "type": "Body", + "optional": true + } + ] + } + ], + "example": [ + "\n var body = new Body({\n mass: 1\n });\n var shape = new Sphere(1);\n body.addShape(shape);\n world.add(body);" + ] + }, + "RaycastVehicle": { + "name": "RaycastVehicle", + "shortname": "RaycastVehicle", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/objects/RaycastVehicle.js", + "line": 10, + "description": "Vehicle helper class that casts rays from the wheel positions towards the ground and applies forces.", + "is_constructor": 1, + "params": [ + { + "name": "options", + "description": "", + "type": "Object", + "optional": true, + "props": [ + { + "name": "chassisBody", + "description": "The car chassis body.", + "type": "Body", + "optional": true + }, + { + "name": "indexRightAxis", + "description": "Axis to use for right. x=0, y=1, z=2", + "type": "Integer", "optional": true }, { @@ -1373,7 +1652,7 @@ { "name": "options.chassisBody", "description": "", - "type": "Object", + "type": "Body", "optional": true } ] @@ -1606,7 +1885,7 @@ { "name": "isFrontWheel", "description": "", - "type": "Number", + "type": "Boolean", "optional": true, "optdefault": "true" }, @@ -1655,7 +1934,7 @@ { "name": "useCustomSlidingRotationalSpeed", "description": "", - "type": "Number", + "type": "Boolean", "optional": true, "optdefault": "false" }, @@ -1880,12 +2159,40 @@ "params": [ { "name": "radius", - "description": "", + "description": "The radius of the sphere, a non-negative number.", "type": "Number" } ], "author": "schteppe / http://github.com/schteppe" }, + "Trimesh": { + "name": "Trimesh", + "shortname": "Trimesh", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/shapes/Trimesh.js", + "line": 10, + "is_constructor": 1, + "params": [ + { + "name": "vertices", + "description": "", + "type": "Array" + }, + { + "name": "indices", + "description": "", + "type": "Array" + } + ], + "extends": "Shape", + "example": [ + "\n // How to make a mesh with a single triangle\n var vertices = [\n 0, 0, 0, // vertex 0\n 1, 0, 0, // vertex 1\n 0, 1, 0 // vertex 2\n ];\n var indices = [\n 0, 1, 2 // triangle 0\n ];\n var trimeshShape = new Trimesh(vertices, indices);" + ] + }, "GSSolver": { "name": "GSSolver", "shortname": "GSSolver", @@ -1956,6 +2263,73 @@ "description": "Base class for objects that dispatches events.", "is_constructor": 1 }, + "OctreeNode": { + "name": "OctreeNode", + "shortname": "OctreeNode", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/utils/Octree.js", + "line": 6, + "params": [ + { + "name": "options", + "description": "", + "type": "Object", + "optional": true, + "props": [ + { + "name": "root", + "description": "", + "type": "Octree", + "optional": true + }, + { + "name": "aabb", + "description": "", + "type": "AABB", + "optional": true + } + ] + } + ] + }, + "Octree": { + "name": "Octree", + "shortname": "Octree", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "file": "src/utils/Octree.js", + "line": 40, + "params": [ + { + "name": "aabb", + "description": "The total AABB of the tree", + "type": "AABB" + }, + { + "name": "options", + "description": "", + "type": "Object", + "optional": true, + "props": [ + { + "name": "maxDepth", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "8" + } + ] + } + ], + "extends": "OctreeNode" + }, "Pool": { "name": "Pool", "shortname": "Pool", @@ -2003,7 +2377,7 @@ "plugin_for": [], "extension_for": [], "file": "src/world/Narrowphase.js", - "line": 12, + "line": 15, "description": "Helper class for the World. Generates ContactEquations.", "is_constructor": 1, "todo": [ @@ -2034,7 +2408,7 @@ "description": "The lower bound of the bounding box.", "itemtype": "property", "name": "lowerBound", - "type": "{Array}", + "type": "{Vec3}", "class": "AABB" }, { @@ -2043,7 +2417,7 @@ "description": "The upper bound of the bounding box.", "itemtype": "property", "name": "upperBound", - "type": "{Array}", + "type": "{Vec3}", "class": "AABB" }, { @@ -2074,11 +2448,15 @@ "type": "Number" } ], + "return": { + "description": "The self object", + "type": "AABB" + }, "class": "AABB" }, { "file": "src/collision/AABB.js", - "line": 92, + "line": 95, "description": "Copy bounds from an AABB to this AABB", "itemtype": "method", "name": "copy", @@ -2089,11 +2467,23 @@ "type": "AABB" } ], + "return": { + "description": "The this object, for chainability", + "type": "AABB" + }, "class": "AABB" }, { "file": "src/collision/AABB.js", - "line": 102, + "line": 107, + "description": "Clone an AABB", + "itemtype": "method", + "name": "clone", + "class": "AABB" + }, + { + "file": "src/collision/AABB.js", + "line": 115, "description": "Extend this AABB so that it covers the given AABB too.", "itemtype": "method", "name": "extend", @@ -2108,7 +2498,7 @@ }, { "file": "src/collision/AABB.js", - "line": 145, + "line": 158, "description": "Returns true if the given AABB overlaps this AABB.", "itemtype": "method", "name": "overlaps", @@ -2126,72 +2516,188 @@ "class": "AABB" }, { - "file": "src/collision/ArrayCollisionMatrix.js", - "line": 10, - "description": "The matrix storage", - "itemtype": "property", - "name": "matrix", - "type": "{Array}", - "class": "ArrayCollisionMatrix" - }, - { - "file": "src/collision/ArrayCollisionMatrix.js", - "line": 18, - "description": "Get an element", + "file": "src/collision/AABB.js", + "line": 180, + "description": "Returns true if the given AABB is fully contained in this AABB.", "itemtype": "method", - "name": "get", + "name": "contains", "params": [ { - "name": "i", - "description": "", - "type": "Number" - }, - { - "name": "j", + "name": "aabb", "description": "", - "type": "Number" + "type": "AABB" } ], "return": { "description": "", - "type": "Number" + "type": "Boolean" }, - "class": "ArrayCollisionMatrix" + "class": "AABB" }, { - "file": "src/collision/ArrayCollisionMatrix.js", - "line": 36, - "description": "Set an element", + "file": "src/collision/AABB.js", + "line": 204, "itemtype": "method", - "name": "set", + "name": "getCorners", "params": [ { - "name": "i", + "name": "a", "description": "", - "type": "Number" + "type": "Vec3" }, { - "name": "j", + "name": "b", "description": "", - "type": "Number" + "type": "Vec3" }, { - "name": "value", + "name": "c", "description": "", - "type": "Number" + "type": "Vec3" + }, + { + "name": "d", + "description": "", + "type": "Vec3" + }, + { + "name": "e", + "description": "", + "type": "Vec3" + }, + { + "name": "f", + "description": "", + "type": "Vec3" + }, + { + "name": "g", + "description": "", + "type": "Vec3" + }, + { + "name": "h", + "description": "", + "type": "Vec3" } ], - "class": "ArrayCollisionMatrix" + "class": "AABB" }, { - "file": "src/collision/ArrayCollisionMatrix.js", - "line": 54, - "description": "Sets all elements to zero", + "file": "src/collision/AABB.js", + "line": 240, + "description": "Get the representation of an AABB in another frame.", "itemtype": "method", - "name": "reset", - "class": "ArrayCollisionMatrix" - }, - { + "name": "toLocalFrame", + "params": [ + { + "name": "frame", + "description": "", + "type": "Transform" + }, + { + "name": "target", + "description": "", + "type": "AABB" + } + ], + "return": { + "description": "The \"target\" AABB object.", + "type": "AABB" + }, + "class": "AABB" + }, + { + "file": "src/collision/AABB.js", + "line": 271, + "description": "Get the representation of an AABB in the global frame.", + "itemtype": "method", + "name": "toWorldFrame", + "params": [ + { + "name": "frame", + "description": "", + "type": "Transform" + }, + { + "name": "target", + "description": "", + "type": "AABB" + } + ], + "return": { + "description": "The \"target\" AABB object.", + "type": "AABB" + }, + "class": "AABB" + }, + { + "file": "src/collision/ArrayCollisionMatrix.js", + "line": 10, + "description": "The matrix storage", + "itemtype": "property", + "name": "matrix", + "type": "{Array}", + "class": "ArrayCollisionMatrix" + }, + { + "file": "src/collision/ArrayCollisionMatrix.js", + "line": 18, + "description": "Get an element", + "itemtype": "method", + "name": "get", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "j", + "description": "", + "type": "Number" + } + ], + "return": { + "description": "", + "type": "Number" + }, + "class": "ArrayCollisionMatrix" + }, + { + "file": "src/collision/ArrayCollisionMatrix.js", + "line": 36, + "description": "Set an element", + "itemtype": "method", + "name": "set", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "j", + "description": "", + "type": "Number" + }, + { + "name": "value", + "description": "", + "type": "Number" + } + ], + "class": "ArrayCollisionMatrix" + }, + { + "file": "src/collision/ArrayCollisionMatrix.js", + "line": 54, + "description": "Sets all elements to zero", + "itemtype": "method", + "name": "reset", + "class": "ArrayCollisionMatrix" + }, + { "file": "src/collision/ArrayCollisionMatrix.js", "line": 64, "description": "Sets the max number of objects", @@ -2447,6 +2953,11 @@ "name": "aabb", "description": "", "type": "AABB" + }, + { + "name": "result", + "description": "An array to store resulting bodies in.", + "type": "Array" } ], "return": { @@ -2631,7 +3142,17 @@ }, { "file": "src/collision/Ray.js", - "line": 32, + "line": 30, + "access": "private", + "tagname": "", + "itemtype": "property", + "name": "_direction", + "type": "Vec3", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 36, "description": "The precision of the ray. Used when checking parallelity etc.", "itemtype": "property", "name": "precision", @@ -2640,7 +3161,7 @@ }, { "file": "src/collision/Ray.js", - "line": 38, + "line": 42, "description": "Set to true if you want the Ray to take .collisionResponse flags into account on bodies and shapes.", "itemtype": "property", "name": "checkCollisionResponse", @@ -2649,7 +3170,94 @@ }, { "file": "src/collision/Ray.js", - "line": 70, + "line": 48, + "description": "If set to true, the ray skips any hits with normal.dot(rayDirection) < 0.", + "itemtype": "property", + "name": "skipBackfaces", + "type": "Boolean", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 54, + "itemtype": "property", + "name": "collisionFilterMask", + "type": "Number", + "default": "-1", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 60, + "itemtype": "property", + "name": "collisionFilterGroup", + "type": "Number", + "default": "-1", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 66, + "description": "The intersection mode. Should be Ray.ANY, Ray.ALL or Ray.CLOSEST.", + "itemtype": "property", + "name": "mode", + "type": "Number", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 72, + "description": "Current result object.", + "itemtype": "property", + "name": "result", + "type": "RaycastResult", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 78, + "description": "Will be set to true during intersectWorld() if the ray hit anything.", + "itemtype": "property", + "name": "hasHit", + "type": "Boolean", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 84, + "description": "Current, user-provided result callback. Will be used if mode is Ray.ALL.", + "itemtype": "property", + "name": "callback", + "type": "Function", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 99, + "description": "Do itersection against all bodies in the given World.", + "itemtype": "method", + "name": "intersectWorld", + "params": [ + { + "name": "world", + "description": "", + "type": "World" + }, + { + "name": "options", + "description": "", + "type": "Object" + } + ], + "return": { + "description": "True if the ray hit anything, otherwise false.", + "type": "Boolean" + }, + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 157, "description": "Shoot a ray at a body, get back information about the hit.", "itemtype": "method", "name": "intersectBody", @@ -2663,13 +3271,8 @@ }, { "name": "result", - "description": "", - "type": "RaycastResult" - }, - { - "name": "direction", - "description": "", - "type": "Vec3", + "description": "Deprecated - set the result property of the Ray instead.", + "type": "RaycastResult", "optional": true } ], @@ -2677,7 +3280,7 @@ }, { "file": "src/collision/Ray.js", - "line": 116, + "line": 208, "itemtype": "method", "name": "intersectBodies", "params": [ @@ -2688,15 +3291,26 @@ }, { "name": "result", - "description": "", - "type": "RaycastResult" + "description": "Deprecated", + "type": "RaycastResult", + "optional": true } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 139, + "line": 224, + "description": "Updates the _direction vector.", + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "_updateDirection", + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 234, "itemtype": "method", "name": "intersectShape", "access": "private", @@ -2721,23 +3335,13 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 174, + "line": 269, "itemtype": "method", "name": "intersectBox", "access": "private", @@ -2762,23 +3366,13 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 189, + "line": 282, "itemtype": "method", "name": "intersectPlane", "access": "private", @@ -2803,24 +3397,14 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 246, - "description": "Get the AABB of the ray.", + "line": 334, + "description": "Get the world AABB of the ray.", "itemtype": "method", "name": "getAABB", "params": [ @@ -2834,7 +3418,7 @@ }, { "file": "src/collision/Ray.js", - "line": 266, + "line": 354, "itemtype": "method", "name": "intersectHeightfield", "access": "private", @@ -2859,23 +3443,13 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 344, + "line": 439, "itemtype": "method", "name": "intersectSphere", "access": "private", @@ -2900,23 +3474,13 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "class": "Ray" }, { "file": "src/collision/Ray.js", - "line": 413, + "line": 505, "itemtype": "method", "name": "intersectConvex", "access": "private", @@ -2942,16 +3506,6 @@ "description": "", "type": "Body" }, - { - "name": "direction", - "description": "", - "type": "Vec3" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" - }, { "name": "options", "description": "", @@ -2971,7 +3525,48 @@ }, { "file": "src/collision/Ray.js", - "line": 527, + "line": 623, + "itemtype": "method", + "name": "intersectTrimesh", + "access": "private", + "tagname": "", + "params": [ + { + "name": "shape", + "description": "", + "type": "Shape" + }, + { + "name": "quat", + "description": "", + "type": "Quaternion" + }, + { + "name": "position", + "description": "", + "type": "Vec3" + }, + { + "name": "body", + "description": "", + "type": "Body" + }, + { + "name": "options", + "description": "", + "type": "Object", + "optional": true + } + ], + "todo": [ + "Optimize by transforming the world to local space first.", + "Use Octree lookup" + ], + "class": "Ray" + }, + { + "file": "src/collision/Ray.js", + "line": 738, "itemtype": "method", "name": "reportIntersection", "access": "private", @@ -2996,11 +3591,6 @@ "name": "body", "description": "", "type": "Body" - }, - { - "name": "result", - "description": "", - "type": "RaycastResult" } ], "return": { @@ -3070,15 +3660,38 @@ { "file": "src/collision/RaycastResult.js", "line": 49, + "description": "The index of the hit triangle, if the hit shape was a trimesh.", + "itemtype": "property", + "name": "hitFaceIndex", + "type": "Number", + "default": "-1", + "class": "RaycastResult" + }, + { + "file": "src/collision/RaycastResult.js", + "line": 56, "description": "Distance to the hit. Will be set to -1 if there was no hit.", "itemtype": "property", "name": "distance", "type": "Number", + "default": "-1", "class": "RaycastResult" }, { "file": "src/collision/RaycastResult.js", - "line": 56, + "line": 63, + "description": "If the ray should stop traversing the bodies.", + "access": "private", + "tagname": "", + "itemtype": "property", + "name": "_shouldStop", + "type": "Boolean", + "default": "false", + "class": "RaycastResult" + }, + { + "file": "src/collision/RaycastResult.js", + "line": 72, "description": "Reset all result data.", "itemtype": "method", "name": "reset", @@ -3086,7 +3699,14 @@ }, { "file": "src/collision/RaycastResult.js", - "line": 71, + "line": 89, + "itemtype": "method", + "name": "abort", + "class": "RaycastResult" + }, + { + "file": "src/collision/RaycastResult.js", + "line": 96, "itemtype": "method", "name": "set", "params": [ @@ -3284,7 +3904,7 @@ }, { "file": "src/collision/SAPBroadphase.js", - "line": 231, + "line": 238, "description": "Computes the variance of the body positions and estimates the best\naxis to use. Will automatically set property .axisIndex.", "itemtype": "method", "name": "autoDetectAxis", @@ -3292,7 +3912,7 @@ }, { "file": "src/collision/SAPBroadphase.js", - "line": 280, + "line": 287, "description": "Returns all the bodies within an AABB.", "itemtype": "method", "name": "aabbQuery", @@ -3319,6 +3939,22 @@ }, "class": "SAPBroadphase" }, + { + "file": "src/constraints/ConeTwistConstraint.js", + "line": 40, + "itemtype": "property", + "name": "coneEquation", + "type": "ConeEquation", + "class": "ConeTwistConstraint" + }, + { + "file": "src/constraints/ConeTwistConstraint.js", + "line": 45, + "itemtype": "property", + "name": "twistEquation", + "type": "RotationalEquation", + "class": "ConeTwistConstraint" + }, { "file": "src/constraints/Constraint.js", "line": 22, @@ -3364,24 +4000,193 @@ { "file": "src/constraints/Constraint.js", "line": 61, + "description": "Update all the equations with data.", "itemtype": "method", "name": "update", "class": "Constraint" }, + { + "file": "src/constraints/Constraint.js", + "line": 69, + "description": "Enables all equations in the constraint.", + "itemtype": "method", + "name": "enable", + "class": "Constraint" + }, + { + "file": "src/constraints/Constraint.js", + "line": 80, + "description": "Disables all equations in the constraint.", + "itemtype": "method", + "name": "disable", + "class": "Constraint" + }, + { + "file": "src/constraints/DistanceConstraint.js", + "line": 28, + "itemtype": "property", + "name": "distance", + "type": "Number", + "class": "DistanceConstraint" + }, + { + "file": "src/constraints/DistanceConstraint.js", + "line": 33, + "itemtype": "property", + "name": "distanceEquation", + "type": "ContactEquation", + "class": "DistanceConstraint" + }, { "file": "src/constraints/HingeConstraint.js", - "line": 84, + "line": 33, + "description": "Rotation axis, defined locally in bodyA.", + "itemtype": "property", + "name": "axisA", + "type": "Vec3", + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 40, + "description": "Rotation axis, defined locally in bodyB.", + "itemtype": "property", + "name": "axisB", + "type": "Vec3", + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 47, + "itemtype": "property", + "name": "rotationalEquation1", + "type": "RotationalEquation", + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 52, + "itemtype": "property", + "name": "rotationalEquation2", + "type": "RotationalEquation", + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 57, + "itemtype": "property", + "name": "motorEquation", + "type": "RotationalMotorEquation", + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 73, "itemtype": "method", "name": "enableMotor", "class": "HingeConstraint" }, { "file": "src/constraints/HingeConstraint.js", - "line": 94, + "line": 80, "itemtype": "method", "name": "disableMotor", "class": "HingeConstraint" }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 87, + "itemtype": "method", + "name": "setMotorSpeed", + "params": [ + { + "name": "speed", + "description": "", + "type": "Number" + } + ], + "class": "HingeConstraint" + }, + { + "file": "src/constraints/HingeConstraint.js", + "line": 95, + "itemtype": "method", + "name": "setMotorMaxForce", + "params": [ + { + "name": "maxForce", + "description": "", + "type": "Number" + } + ], + "class": "HingeConstraint" + }, + { + "file": "src/constraints/LockConstraint.js", + "line": 35, + "itemtype": "property", + "name": "rotationalEquation1", + "type": "RotationalEquation", + "class": "LockConstraint" + }, + { + "file": "src/constraints/LockConstraint.js", + "line": 40, + "itemtype": "property", + "name": "rotationalEquation2", + "type": "RotationalEquation", + "class": "LockConstraint" + }, + { + "file": "src/constraints/LockConstraint.js", + "line": 45, + "itemtype": "property", + "name": "rotationalEquation3", + "type": "RotationalEquation", + "class": "LockConstraint" + }, + { + "file": "src/constraints/PointToPointConstraint.js", + "line": 37, + "description": "Pivot, defined locally in bodyA.", + "itemtype": "property", + "name": "pivotA", + "type": "Vec3", + "class": "PointToPointConstraint" + }, + { + "file": "src/constraints/PointToPointConstraint.js", + "line": 43, + "description": "Pivot, defined locally in bodyB.", + "itemtype": "property", + "name": "pivotB", + "type": "Vec3", + "class": "PointToPointConstraint" + }, + { + "file": "src/constraints/PointToPointConstraint.js", + "line": 49, + "itemtype": "property", + "name": "equationX", + "type": "ContactEquation", + "class": "PointToPointConstraint" + }, + { + "file": "src/constraints/PointToPointConstraint.js", + "line": 54, + "itemtype": "property", + "name": "equationY", + "type": "ContactEquation", + "class": "PointToPointConstraint" + }, + { + "file": "src/constraints/PointToPointConstraint.js", + "line": 59, + "itemtype": "property", + "name": "equationZ", + "type": "ContactEquation", + "class": "PointToPointConstraint" + }, { "file": "src/demo/Demo.js", "line": 209, @@ -3395,8 +4200,8 @@ "type": "String" }, { - "name": "A", - "description": "function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc.", + "name": "initfunc", + "description": "A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc.", "type": "Function" } ], @@ -3410,9 +4215,18 @@ "name": "restartCurrentScene", "class": "Demo" }, + { + "file": "src/equations/ConeEquation.js", + "line": 29, + "description": "The cone angle to keep", + "itemtype": "property", + "name": "angle", + "type": "Number", + "class": "ConeEquation" + }, { "file": "src/equations/ContactEquation.js", - "line": 19, + "line": 20, "itemtype": "property", "name": "restitution", "type": "{Number}", @@ -3420,7 +4234,7 @@ }, { "file": "src/equations/ContactEquation.js", - "line": 25, + "line": 26, "description": "World-oriented vector that goes from the center of bi to the contact point.", "itemtype": "property", "name": "ri", @@ -3429,7 +4243,7 @@ }, { "file": "src/equations/ContactEquation.js", - "line": 31, + "line": 32, "description": "World-oriented vector that starts in body j position and goes to the contact point.", "itemtype": "property", "name": "rj", @@ -3438,13 +4252,25 @@ }, { "file": "src/equations/ContactEquation.js", - "line": 39, + "line": 38, "description": "Contact normal, pointing out of body i.", "itemtype": "property", "name": "ni", "type": "Vec3", "class": "ContactEquation" }, + { + "file": "src/equations/ContactEquation.js", + "line": 113, + "description": "Get the current relative velocity in the contact point.", + "itemtype": "method", + "name": "getImpactVelocityAlongNormal", + "return": { + "description": "", + "type": "Number" + }, + "class": "ContactEquation" + }, { "file": "src/equations/Equation.js", "line": 19, @@ -3516,13 +4342,22 @@ "file": "src/equations/Equation.js", "line": 64, "itemtype": "property", - "name": "jacobianElementA", + "name": "jacobianElementB", "type": "JacobianElement", "class": "Equation" }, { "file": "src/equations/Equation.js", - "line": 76, + "line": 69, + "itemtype": "property", + "name": "enabled", + "type": "Boolean", + "default": "true", + "class": "Equation" + }, + { + "file": "src/equations/Equation.js", + "line": 82, "description": "Recalculates a,b,eps.", "itemtype": "method", "name": "setSpookParams", @@ -3530,7 +4365,7 @@ }, { "file": "src/equations/Equation.js", - "line": 89, + "line": 95, "description": "Computes the RHS of the SPOOK equation", "itemtype": "method", "name": "computeB", @@ -3542,7 +4377,7 @@ }, { "file": "src/equations/Equation.js", - "line": 101, + "line": 107, "description": "Computes G*q, where q are the generalized body coordinates", "itemtype": "method", "name": "computeGq", @@ -3554,7 +4389,7 @@ }, { "file": "src/equations/Equation.js", - "line": 118, + "line": 124, "description": "Computes G*W, where W are the body velocities", "itemtype": "method", "name": "computeGW", @@ -3566,7 +4401,7 @@ }, { "file": "src/equations/Equation.js", - "line": 136, + "line": 142, "description": "Computes G*Wlambda, where W are the body velocities", "itemtype": "method", "name": "computeGWlambda", @@ -3578,7 +4413,7 @@ }, { "file": "src/equations/Equation.js", - "line": 153, + "line": 159, "description": "Computes G*inv(M)*f, where M is the mass matrix with diagonal blocks for each body, and f are the forces on the bodies.", "itemtype": "method", "name": "computeGiMf", @@ -3590,7 +4425,7 @@ }, { "file": "src/equations/Equation.js", - "line": 185, + "line": 191, "description": "Computes G*inv(M)*G'", "itemtype": "method", "name": "computeGiMGt", @@ -3602,7 +4437,7 @@ }, { "file": "src/equations/Equation.js", - "line": 222, + "line": 228, "description": "Add constraint velocity to the bodies.", "itemtype": "method", "name": "addToWlambda", @@ -3617,7 +4452,7 @@ }, { "file": "src/equations/Equation.js", - "line": 256, + "line": 262, "description": "Compute the denominator part of the SPOOK equation: C = G*inv(M)*G' + eps", "itemtype": "method", "name": "computeInvC", @@ -3636,8 +4471,26 @@ }, { "file": "src/equations/RotationalMotorEquation.js", - "line": 26, - "description": "Motor velocity", + "line": 21, + "description": "World oriented rotational axis", + "itemtype": "property", + "name": "axisA", + "type": "Vec3", + "class": "RotationalMotorEquation" + }, + { + "file": "src/equations/RotationalMotorEquation.js", + "line": 27, + "description": "World oriented rotational axis", + "itemtype": "property", + "name": "axisB", + "type": "Vec3", + "class": "RotationalMotorEquation" + }, + { + "file": "src/equations/RotationalMotorEquation.js", + "line": 33, + "description": "Motor velocity", "itemtype": "property", "name": "targetVelocity", "type": "Number", @@ -3720,7 +4573,7 @@ }, { "file": "src/material/Material.js", - "line": 11, + "line": 22, "itemtype": "property", "name": "name", "type": "{String}", @@ -3728,10 +4581,29 @@ }, { "file": "src/material/Material.js", - "line": 17, + "line": 28, "description": "material id.", "itemtype": "property", "name": "id", + "type": "{number}", + "class": "Material" + }, + { + "file": "src/material/Material.js", + "line": 35, + "description": "Friction for this material. If non-negative, it will be used instead of the friction given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used.", + "itemtype": "property", + "name": "friction", + "type": "Number", + "class": "Material" + }, + { + "file": "src/material/Material.js", + "line": 41, + "description": "Restitution for this material. If non-negative, it will be used instead of the restitution given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used.", + "itemtype": "property", + "name": "restitution", + "type": "Number", "class": "Material" }, { @@ -3816,7 +4688,7 @@ }, { "file": "src/math/Mat3.js", - "line": 44, + "line": 45, "description": "Set all elements to zero", "itemtype": "method", "name": "setZero", @@ -3824,23 +4696,34 @@ }, { "file": "src/math/Mat3.js", - "line": 61, + "line": 62, "description": "Sets the matrix diagonal elements from a Vec3", "itemtype": "method", "name": "setTrace", + "params": [ + { + "name": "vec3", + "description": "", + "type": "Vec3" + } + ], "class": "Mat3" }, { "file": "src/math/Mat3.js", - "line": 72, - "description": "Sets the matrix diagonal elements from a Vec3", + "line": 74, + "description": "Gets the matrix diagonal elements", "itemtype": "method", - "name": "setTrace", + "name": "getTrace", + "return": { + "description": "", + "type": "Vec3" + }, "class": "Mat3" }, { "file": "src/math/Mat3.js", - "line": 84, + "line": 87, "description": "Matrix-Vector multiplication", "itemtype": "method", "name": "vmult", @@ -3860,7 +4743,7 @@ }, { "file": "src/math/Mat3.js", - "line": 104, + "line": 107, "description": "Matrix-scalar multiplication", "itemtype": "method", "name": "smult", @@ -3875,7 +4758,7 @@ }, { "file": "src/math/Mat3.js", - "line": 115, + "line": 118, "description": "Matrix multiplication", "itemtype": "method", "name": "mmult", @@ -3894,7 +4777,7 @@ }, { "file": "src/math/Mat3.js", - "line": 135, + "line": 138, "description": "Scale each column of the matrix", "itemtype": "method", "name": "scale", @@ -3913,7 +4796,7 @@ }, { "file": "src/math/Mat3.js", - "line": 153, + "line": 156, "description": "Solve Ax=b", "itemtype": "method", "name": "solve", @@ -3940,7 +4823,7 @@ }, { "file": "src/math/Mat3.js", - "line": 224, + "line": 227, "description": "Get an element in the matrix by index. Index starts at 0, not 1!!!", "itemtype": "method", "name": "e", @@ -3969,7 +4852,7 @@ }, { "file": "src/math/Mat3.js", - "line": 241, + "line": 244, "description": "Copy another matrix into this matrix object.", "itemtype": "method", "name": "copy", @@ -3988,7 +4871,7 @@ }, { "file": "src/math/Mat3.js", - "line": 254, + "line": 257, "description": "Returns a string representation of the matrix.", "itemtype": "method", "name": "toString", @@ -3999,7 +4882,7 @@ }, { "file": "src/math/Mat3.js", - "line": 268, + "line": 271, "description": "reverse the matrix", "itemtype": "method", "name": "reverse", @@ -4018,7 +4901,7 @@ }, { "file": "src/math/Mat3.js", - "line": 372, + "line": 375, "description": "Set the matrix from a quaterion", "itemtype": "method", "name": "setRotationFromQuaternion", @@ -4033,7 +4916,7 @@ }, { "file": "src/math/Mat3.js", - "line": 400, + "line": 403, "description": "Transpose the matrix", "itemtype": "method", "name": "transpose", @@ -4160,7 +5043,7 @@ "line": 85, "description": "Converts the quaternion to axis/angle representation.", "itemtype": "method", - "name": "setFromAxisAngle", + "name": "toAxisAngle", "params": [ { "name": "targetAxis", @@ -4369,7 +5252,7 @@ }, { "file": "src/math/Transform.js", - "line": 11, + "line": 13, "itemtype": "property", "name": "position", "type": "Vec3", @@ -4377,7 +5260,7 @@ }, { "file": "src/math/Transform.js", - "line": 16, + "line": 21, "itemtype": "property", "name": "quaternion", "type": "Quaternion", @@ -4385,7 +5268,7 @@ }, { "file": "src/math/Transform.js", - "line": 24, + "line": 32, "static": 1, "itemtype": "method", "name": "pointToLocaFrame", @@ -4415,7 +5298,31 @@ }, { "file": "src/math/Transform.js", - "line": 40, + "line": 48, + "description": "Get a global point in local transform coordinates.", + "itemtype": "method", + "name": "pointToLocal", + "params": [ + { + "name": "point", + "description": "", + "type": "Vec3" + }, + { + "name": "result", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"result\" vector object", + "type": "Vec3" + }, + "class": "Transform" + }, + { + "file": "src/math/Transform.js", + "line": 59, "static": 1, "itemtype": "method", "name": "pointToWorldFrame", @@ -4443,6 +5350,30 @@ ], "class": "Transform" }, + { + "file": "src/math/Transform.js", + "line": 74, + "description": "Get a local point in global transform coordinates.", + "itemtype": "method", + "name": "pointToWorld", + "params": [ + { + "name": "point", + "description": "", + "type": "Vec3" + }, + { + "name": "result", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"result\" vector object", + "type": "Vec3" + }, + "class": "Transform" + }, { "file": "src/math/Vec3.js", "line": 18, @@ -4469,7 +5400,43 @@ }, { "file": "src/math/Vec3.js", - "line": 39, + "line": 37, + "static": 1, + "itemtype": "property", + "name": "ZERO", + "type": "Vec3", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 43, + "static": 1, + "itemtype": "property", + "name": "UNIT_X", + "type": "Vec3", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 49, + "static": 1, + "itemtype": "property", + "name": "UNIT_Y", + "type": "Vec3", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 55, + "static": 1, + "itemtype": "property", + "name": "UNIT_Z", + "type": "Vec3", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 61, "description": "Vector cross product", "itemtype": "method", "name": "cross", @@ -4493,7 +5460,7 @@ }, { "file": "src/math/Vec3.js", - "line": 57, + "line": 79, "description": "Set the vectors' 3 elements", "itemtype": "method", "name": "set", @@ -4521,7 +5488,7 @@ }, { "file": "src/math/Vec3.js", - "line": 72, + "line": 94, "description": "Set all components of the vector to zero.", "itemtype": "method", "name": "setZero", @@ -4529,7 +5496,7 @@ }, { "file": "src/math/Vec3.js", - "line": 80, + "line": 102, "description": "Vector addition", "itemtype": "method", "name": "vadd", @@ -4553,7 +5520,7 @@ }, { "file": "src/math/Vec3.js", - "line": 99, + "line": 121, "description": "Vector subtraction", "itemtype": "method", "name": "vsub", @@ -4577,7 +5544,7 @@ }, { "file": "src/math/Vec3.js", - "line": 118, + "line": 140, "description": "Get the cross product matrix a_cross from a vector, such that a x b = a_cross * b = c", "itemtype": "method", "name": "crossmat", @@ -4592,7 +5559,7 @@ }, { "file": "src/math/Vec3.js", - "line": 130, + "line": 152, "description": "Normalize the vector. Note that this changes the values in the vector.", "itemtype": "method", "name": "normalize", @@ -4604,7 +5571,7 @@ }, { "file": "src/math/Vec3.js", - "line": 152, + "line": 174, "description": "Get the version of this vector that is of length 1.", "itemtype": "method", "name": "unit", @@ -4623,19 +5590,33 @@ }, { "file": "src/math/Vec3.js", - "line": 175, - "description": "Get the 2-norm (length) of the vector", + "line": 197, + "description": "Get the length of the vector", "itemtype": "method", "name": "norm", "return": { "description": "", "type": "Number" }, + "deprecated": true, + "deprecationMessage": "Use .length() instead", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 208, + "description": "Get the length of the vector", + "itemtype": "method", + "name": "length", + "return": { + "description": "", + "type": "Number" + }, "class": "Vec3" }, { "file": "src/math/Vec3.js", - "line": 185, + "line": 215, "description": "Get the squared length of the vector", "itemtype": "method", "name": "norm2", @@ -4643,11 +5624,25 @@ "description": "", "type": "Number" }, + "deprecated": true, + "deprecationMessage": "Use .lengthSquared() instead.", + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 225, + "description": "Get the squared length of the vector.", + "itemtype": "method", + "name": "lengthSquared", + "return": { + "description": "", + "type": "Number" + }, "class": "Vec3" }, { "file": "src/math/Vec3.js", - "line": 194, + "line": 232, "description": "Get distance from this point to another point", "itemtype": "method", "name": "distanceTo", @@ -4666,10 +5661,29 @@ }, { "file": "src/math/Vec3.js", - "line": 208, - "description": "Multiply the vector with a scalar", + "line": 246, + "description": "Get squared distance from this point to another point", + "itemtype": "method", + "name": "distanceSquared", + "params": [ + { + "name": "p", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "", + "type": "Number" + }, + "class": "Vec3" + }, + { + "file": "src/math/Vec3.js", + "line": 258, + "description": "Multiply all the components of the vector with a scalar.", "deprecated": true, - "deprecationMessage": "Use .scale instead", + "deprecationMessage": "Use .scale() instead", "itemtype": "method", "name": "mult", "params": [ @@ -4680,7 +5694,7 @@ }, { "name": "target", - "description": "", + "description": "The vector to save the result in.", "type": "Vec3" } ], @@ -4692,7 +5706,7 @@ }, { "file": "src/math/Vec3.js", - "line": 227, + "line": 278, "description": "Multiply the vector with a scalar.", "itemtype": "method", "name": "scale", @@ -4716,7 +5730,7 @@ }, { "file": "src/math/Vec3.js", - "line": 236, + "line": 287, "description": "Calculate dot product", "itemtype": "method", "name": "dot", @@ -4735,7 +5749,7 @@ }, { "file": "src/math/Vec3.js", - "line": 246, + "line": 297, "itemtype": "method", "name": "isZero", "return": { @@ -4745,7 +5759,7 @@ }, { "file": "src/math/Vec3.js", - "line": 254, + "line": 305, "description": "Make the vector point in the opposite direction.", "itemtype": "method", "name": "negate", @@ -4764,7 +5778,7 @@ }, { "file": "src/math/Vec3.js", - "line": 268, + "line": 319, "description": "Compute two artificial tangents to the vector", "itemtype": "method", "name": "tangents", @@ -4784,7 +5798,7 @@ }, { "file": "src/math/Vec3.js", - "line": 298, + "line": 349, "description": "Converts to a more readable format", "itemtype": "method", "name": "toString", @@ -4795,7 +5809,7 @@ }, { "file": "src/math/Vec3.js", - "line": 307, + "line": 358, "description": "Converts to an array", "itemtype": "method", "name": "toArray", @@ -4806,7 +5820,7 @@ }, { "file": "src/math/Vec3.js", - "line": 316, + "line": 367, "description": "Copies value of source to this vector.", "itemtype": "method", "name": "copy", @@ -4825,7 +5839,7 @@ }, { "file": "src/math/Vec3.js", - "line": 330, + "line": 381, "description": "Do a linear interpolation between two vectors", "itemtype": "method", "name": "lerp", @@ -4850,7 +5864,7 @@ }, { "file": "src/math/Vec3.js", - "line": 344, + "line": 395, "description": "Check if a vector equals is almost equal to another one.", "itemtype": "method", "name": "almostEquals", @@ -4873,7 +5887,7 @@ }, { "file": "src/math/Vec3.js", - "line": 363, + "line": 414, "description": "Check if a vector is almost zero", "itemtype": "method", "name": "almostZero", @@ -4888,7 +5902,7 @@ }, { "file": "src/math/Vec3.js", - "line": 382, + "line": 433, "description": "Check if the vector is anti-parallel to another vector.", "itemtype": "method", "name": "isAntiparallelTo", @@ -4912,7 +5926,7 @@ }, { "file": "src/math/Vec3.js", - "line": 394, + "line": 445, "description": "Clone the vector", "itemtype": "method", "name": "clone", @@ -4924,7 +5938,7 @@ }, { "file": "src/objects/Body.js", - "line": 40, + "line": 49, "description": "Reference to the world the body is living in", "itemtype": "property", "name": "world", @@ -4933,7 +5947,7 @@ }, { "file": "src/objects/Body.js", - "line": 47, + "line": 56, "description": "Callback function that is used BEFORE stepping the system. Use it to apply forces, for example. Inside the function, \"this\" will refer to this Body object.", "itemtype": "property", "name": "preStep", @@ -4944,7 +5958,7 @@ }, { "file": "src/objects/Body.js", - "line": 55, + "line": 64, "description": "Callback function that is used AFTER stepping the system. Inside the function, \"this\" will refer to this Body object.", "itemtype": "property", "name": "postStep", @@ -4955,7 +5969,7 @@ }, { "file": "src/objects/Body.js", - "line": 65, + "line": 74, "itemtype": "property", "name": "collisionFilterGroup", "type": "Number", @@ -4963,7 +5977,7 @@ }, { "file": "src/objects/Body.js", - "line": 70, + "line": 79, "itemtype": "property", "name": "collisionFilterMask", "type": "Number", @@ -4971,7 +5985,7 @@ }, { "file": "src/objects/Body.js", - "line": 75, + "line": 84, "description": "Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.", "itemtype": "property", "name": "collisionResponse", @@ -4980,7 +5994,7 @@ }, { "file": "src/objects/Body.js", - "line": 81, + "line": 90, "itemtype": "property", "name": "position", "type": "{Vec3}", @@ -4988,7 +6002,7 @@ }, { "file": "src/objects/Body.js", - "line": 91, + "line": 100, "itemtype": "property", "name": "previousPosition", "type": "Vec3", @@ -4996,7 +6010,7 @@ }, { "file": "src/objects/Body.js", - "line": 96, + "line": 105, "description": "Initial position of the body", "itemtype": "property", "name": "initPosition", @@ -5005,7 +6019,7 @@ }, { "file": "src/objects/Body.js", - "line": 103, + "line": 112, "itemtype": "property", "name": "velocity", "type": "{Vec3}", @@ -5013,7 +6027,7 @@ }, { "file": "src/objects/Body.js", - "line": 113, + "line": 122, "itemtype": "property", "name": "initVelocity", "type": "{Vec3}", @@ -5021,7 +6035,7 @@ }, { "file": "src/objects/Body.js", - "line": 119, + "line": 128, "description": "Linear force on the body", "itemtype": "property", "name": "force", @@ -5030,15 +6044,16 @@ }, { "file": "src/objects/Body.js", - "line": 128, + "line": 137, "itemtype": "property", "name": "mass", "type": "{Number}", + "default": "0", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 134, + "line": 144, "itemtype": "property", "name": "invMass", "type": "{Number}", @@ -5046,7 +6061,7 @@ }, { "file": "src/objects/Body.js", - "line": 140, + "line": 150, "itemtype": "property", "name": "material", "type": "{Material}", @@ -5054,7 +6069,7 @@ }, { "file": "src/objects/Body.js", - "line": 146, + "line": 156, "itemtype": "property", "name": "linearDamping", "type": "{Number}", @@ -5062,7 +6077,7 @@ }, { "file": "src/objects/Body.js", - "line": 152, + "line": 162, "description": "One of: Body.DYNAMIC, Body.STATIC and Body.KINEMATIC.", "itemtype": "property", "name": "type", @@ -5071,16 +6086,17 @@ }, { "file": "src/objects/Body.js", - "line": 162, + "line": 172, "description": "If true, the body will automatically fall to sleep.", "itemtype": "property", "name": "allowSleep", "type": "{Boolean}", + "default": "true", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 169, + "line": 180, "description": "Current sleep state.", "itemtype": "property", "name": "sleepState", @@ -5089,25 +6105,27 @@ }, { "file": "src/objects/Body.js", - "line": 176, + "line": 187, "description": "If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy.", "itemtype": "property", "name": "sleepSpeedLimit", "type": "{Number}", + "default": "0.1", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 183, + "line": 195, "description": "If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.", "itemtype": "property", "name": "sleepTimeLimit", "type": "{Number}", + "default": "1", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 195, + "line": 208, "description": "Rotational force on the body, around center of mass", "itemtype": "property", "name": "torque", @@ -5116,7 +6134,7 @@ }, { "file": "src/objects/Body.js", - "line": 201, + "line": 214, "description": "Orientation of the body", "itemtype": "property", "name": "quaternion", @@ -5125,7 +6143,7 @@ }, { "file": "src/objects/Body.js", - "line": 212, + "line": 225, "itemtype": "property", "name": "initQuaternion", "type": "{Quaternion}", @@ -5133,7 +6151,7 @@ }, { "file": "src/objects/Body.js", - "line": 218, + "line": 231, "itemtype": "property", "name": "angularVelocity", "type": "{Vec3}", @@ -5141,7 +6159,7 @@ }, { "file": "src/objects/Body.js", - "line": 228, + "line": 241, "itemtype": "property", "name": "initAngularVelocity", "type": "{Vec3}", @@ -5149,7 +6167,7 @@ }, { "file": "src/objects/Body.js", - "line": 237, + "line": 250, "itemtype": "property", "name": "shapes", "type": "{array}", @@ -5157,7 +6175,7 @@ }, { "file": "src/objects/Body.js", - "line": 243, + "line": 256, "itemtype": "property", "name": "shapeOffsets", "type": "{array}", @@ -5165,7 +6183,7 @@ }, { "file": "src/objects/Body.js", - "line": 249, + "line": 262, "itemtype": "property", "name": "shapeOrientations", "type": "{array}", @@ -5173,7 +6191,7 @@ }, { "file": "src/objects/Body.js", - "line": 255, + "line": 268, "itemtype": "property", "name": "inertia", "type": "{Vec3}", @@ -5181,7 +6199,7 @@ }, { "file": "src/objects/Body.js", - "line": 261, + "line": 274, "itemtype": "property", "name": "invInertia", "type": "Vec3", @@ -5189,7 +6207,7 @@ }, { "file": "src/objects/Body.js", - "line": 266, + "line": 279, "itemtype": "property", "name": "invInertiaWorld", "type": "Mat3", @@ -5197,7 +6215,7 @@ }, { "file": "src/objects/Body.js", - "line": 273, + "line": 286, "itemtype": "property", "name": "invInertiaSolve", "type": "Vec3", @@ -5205,7 +6223,7 @@ }, { "file": "src/objects/Body.js", - "line": 278, + "line": 291, "itemtype": "property", "name": "invInertiaWorldSolve", "type": "Mat3", @@ -5213,16 +6231,17 @@ }, { "file": "src/objects/Body.js", - "line": 283, + "line": 296, "description": "Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this.", "itemtype": "property", "name": "fixedRotation", "type": "Boolean", + "default": "false", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 289, + "line": 303, "itemtype": "property", "name": "angularDamping", "type": "Number", @@ -5230,15 +6249,15 @@ }, { "file": "src/objects/Body.js", - "line": 294, + "line": 308, "itemtype": "property", "name": "aabb", - "type": "{Vec3}", + "type": "{AABB}", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 300, + "line": 314, "description": "Indicates if the AABB needs to be updated before use.", "itemtype": "property", "name": "aabbNeedsUpdate", @@ -5247,7 +6266,7 @@ }, { "file": "src/objects/Body.js", - "line": 314, + "line": 332, "description": "A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.", "static": 1, "itemtype": "property", @@ -5257,7 +6276,7 @@ }, { "file": "src/objects/Body.js", - "line": 322, + "line": 340, "description": "A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.", "static": 1, "itemtype": "property", @@ -5267,7 +6286,7 @@ }, { "file": "src/objects/Body.js", - "line": 330, + "line": 348, "description": "A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.", "static": 1, "itemtype": "property", @@ -5277,7 +6296,7 @@ }, { "file": "src/objects/Body.js", - "line": 340, + "line": 358, "static": 1, "itemtype": "property", "name": "AWAKE", @@ -5286,7 +6305,7 @@ }, { "file": "src/objects/Body.js", - "line": 347, + "line": 365, "static": 1, "itemtype": "property", "name": "SLEEPY", @@ -5295,7 +6314,7 @@ }, { "file": "src/objects/Body.js", - "line": 354, + "line": 372, "static": 1, "itemtype": "property", "name": "SLEEPING", @@ -5304,7 +6323,7 @@ }, { "file": "src/objects/Body.js", - "line": 363, + "line": 381, "description": "Wake the body up.", "itemtype": "method", "name": "wakeUp", @@ -5312,7 +6331,7 @@ }, { "file": "src/objects/Body.js", - "line": 375, + "line": 393, "description": "Force body sleep", "itemtype": "method", "name": "sleep", @@ -5320,7 +6339,7 @@ }, { "file": "src/objects/Body.js", - "line": 393, + "line": 411, "description": "Called every timestep to update internal sleep timer and change sleep state if needed.", "itemtype": "method", "name": "sleepTick", @@ -5335,7 +6354,7 @@ }, { "file": "src/objects/Body.js", - "line": 416, + "line": 434, "description": "If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate \"solve mass\".", "itemtype": "method", "name": "updateSolveMassProperties", @@ -5343,7 +6362,7 @@ }, { "file": "src/objects/Body.js", - "line": 432, + "line": 450, "description": "Convert a world point to local body frame.", "itemtype": "method", "name": "pointToLocalFrame", @@ -5367,7 +6386,31 @@ }, { "file": "src/objects/Body.js", - "line": 446, + "line": 464, + "description": "Convert a world vector to local body frame.", + "itemtype": "method", + "name": "vectorToLocalFrame", + "params": [ + { + "name": "worldPoint", + "description": "", + "type": "Vec3" + }, + { + "name": "result", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "", + "type": "Vec3" + }, + "class": "Body" + }, + { + "file": "src/objects/Body.js", + "line": 477, "description": "Convert a local body point to world frame.", "itemtype": "method", "name": "pointToWorldFrame", @@ -5391,7 +6434,7 @@ }, { "file": "src/objects/Body.js", - "line": 460, + "line": 491, "description": "Convert a local body point to world frame.", "itemtype": "method", "name": "vectorToWorldFrame", @@ -5415,7 +6458,36 @@ }, { "file": "src/objects/Body.js", - "line": 497, + "line": 507, + "description": "Add a shape to the body with a local offset and orientation.", + "itemtype": "method", + "name": "addShape", + "params": [ + { + "name": "shape", + "description": "", + "type": "Shape" + }, + { + "name": "offset", + "description": "", + "type": "Vec3" + }, + { + "name": "quaternion", + "description": "", + "type": "Quaternion" + } + ], + "return": { + "description": "The body object, for chainability.", + "type": "Body" + }, + "class": "Body" + }, + { + "file": "src/objects/Body.js", + "line": 537, "description": "Update the bounding radius of the body. Should be done if any of the shapes are changed.", "itemtype": "method", "name": "updateBoundingRadius", @@ -5423,7 +6495,7 @@ }, { "file": "src/objects/Body.js", - "line": 522, + "line": 562, "description": "Updates the .aabb", "itemtype": "method", "name": "computeAABB", @@ -5434,7 +6506,7 @@ }, { "file": "src/objects/Body.js", - "line": 568, + "line": 608, "description": "Update .inertiaWorld and .invInertiaWorld", "itemtype": "method", "name": "updateInertiaWorld", @@ -5442,7 +6514,7 @@ }, { "file": "src/objects/Body.js", - "line": 597, + "line": 637, "description": "Apply force to a world point. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque.", "itemtype": "method", "name": "applyForce", @@ -5462,7 +6534,27 @@ }, { "file": "src/objects/Body.js", - "line": 625, + "line": 665, + "description": "Apply force to a local point in the body.", + "itemtype": "method", + "name": "applyLocalForce", + "params": [ + { + "name": "force", + "description": "The force vector to apply, defined locally in the body frame.", + "type": "Vec3" + }, + { + "name": "localPoint", + "description": "A local point in the body to apply the force on.", + "type": "Vec3" + } + ], + "class": "Body" + }, + { + "file": "src/objects/Body.js", + "line": 688, "description": "Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.", "itemtype": "method", "name": "applyImpulse", @@ -5482,15 +6574,35 @@ }, { "file": "src/objects/Body.js", - "line": 666, - "description": "Should be called whenever you change the body mass.", + "line": 729, + "description": "Apply locally-defined impulse to a local point in the body.", + "itemtype": "method", + "name": "applyLocalImpulse", + "params": [ + { + "name": "force", + "description": "The force vector to apply, defined locally in the body frame.", + "type": "Vec3" + }, + { + "name": "localPoint", + "description": "A local point in the body to apply the force on.", + "type": "Vec3" + } + ], + "class": "Body" + }, + { + "file": "src/objects/Body.js", + "line": 754, + "description": "Should be called whenever you change the body shape or mass.", "itemtype": "method", "name": "updateMassProperties", "class": "Body" }, { "file": "src/objects/Body.js", - "line": 709, + "line": 782, "description": "Get world velocity of a point in the body.", "itemtype": "method", "name": "getVelocityAtWorldPoint", @@ -5669,7 +6781,7 @@ }, { "file": "src/objects/RaycastVehicle.js", - "line": 137, + "line": 138, "description": "Get one of the wheel axles, world-oriented.", "access": "private", "tagname": "", @@ -5691,7 +6803,7 @@ }, { "file": "src/objects/RaycastVehicle.js", - "line": 278, + "line": 279, "description": "Remove the vehicle including its constraints from the world.", "itemtype": "method", "name": "removeFromWorld", @@ -5706,7 +6818,22 @@ }, { "file": "src/objects/RaycastVehicle.js", - "line": 420, + "line": 380, + "description": "Update one of the wheel transform.\nNote when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example.", + "itemtype": "method", + "name": "updateWheelTransform", + "params": [ + { + "name": "wheelIndex", + "description": "The wheel index to update.", + "type": "Integer" + } + ], + "class": "RaycastVehicle" + }, + { + "file": "src/objects/RaycastVehicle.js", + "line": 428, "description": "Get the world transform of one of the wheels", "itemtype": "method", "name": "getWheelTransformWorld", @@ -5762,7 +6889,7 @@ { "name": "isFrontWheel", "description": "", - "type": "Object", + "type": "Boolean", "optional": true }, { @@ -5944,7 +7071,64 @@ }, { "file": "src/objects/SPHSystem.js", - "line": 46, + "line": 18, + "description": "Density of the system (kg/m3).", + "itemtype": "property", + "name": "density", + "type": "Number", + "class": "SPHSystem" + }, + { + "file": "src/objects/SPHSystem.js", + "line": 24, + "description": "Distance below which two particles are considered to be neighbors.\nIt should be adjusted so there are about 15-20 neighbor particles within this radius.", + "itemtype": "property", + "name": "smoothingRadius", + "type": "Number", + "class": "SPHSystem" + }, + { + "file": "src/objects/SPHSystem.js", + "line": 32, + "description": "Viscosity of the system.", + "itemtype": "property", + "name": "viscosity", + "type": "Number", + "class": "SPHSystem" + }, + { + "file": "src/objects/SPHSystem.js", + "line": 45, + "description": "Add a particle to the system.", + "itemtype": "method", + "name": "add", + "params": [ + { + "name": "particle", + "description": "", + "type": "Body" + } + ], + "class": "SPHSystem" + }, + { + "file": "src/objects/SPHSystem.js", + "line": 57, + "description": "Remove a particle from the system.", + "itemtype": "method", + "name": "remove", + "params": [ + { + "name": "particle", + "description": "", + "type": "Body" + } + ], + "class": "SPHSystem" + }, + { + "file": "src/objects/SPHSystem.js", + "line": 72, "description": "Get neighbors within smoothing volume, save in the array neighbors", "itemtype": "method", "name": "getNeighbors", @@ -6407,7 +7591,7 @@ }, { "file": "src/shapes/Box.js", - "line": 73, + "line": 80, "itemtype": "method", "name": "calculateLocalInertia", "params": [ @@ -6430,15 +7614,15 @@ }, { "file": "src/shapes/Box.js", - "line": 92, + "line": 99, "description": "Get the box 6 side normals", "itemtype": "method", "name": "getSideNormals", "params": [ { - "name": "includeNegative", - "description": "If true, this function returns 6 vectors. If false, it only returns 3 (but you get 6 by reversing those 3)", - "type": "Boolean" + "name": "sixTargetVectors", + "description": "An array of 6 vectors, to store the resulting side normals in.", + "type": "Array" }, { "name": "quat", @@ -6490,7 +7674,16 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 73, + "line": 67, + "description": "If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.", + "itemtype": "property", + "name": "uniqueAxes", + "type": "Array", + "class": "ConvexPolyhedron" + }, + { + "file": "src/shapes/ConvexPolyhedron.js", + "line": 80, "description": "Computes uniqueEdges", "itemtype": "method", "name": "computeEdges", @@ -6498,7 +7691,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 126, + "line": 116, "description": "Compute the normals of the faces. Will reuse existing Vec3 objects in the .faceNormals array if they exist.", "itemtype": "method", "name": "computeNormals", @@ -6506,7 +7699,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 157, + "line": 147, "description": "Get face normal given 3 vertices", "static": 1, "itemtype": "method", @@ -6537,7 +7730,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 177, + "line": 167, "description": "Compute the normal of a face from its vertices", "itemtype": "method", "name": "getFaceNormal", @@ -6557,7 +7750,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 191, + "line": 181, "itemtype": "method", "name": "clipAgainstHull", "params": [ @@ -6614,7 +7807,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 250, + "line": 234, "description": "Find the separating axis between this hull and another", "itemtype": "method", "name": "findSeparatingAxis", @@ -6658,7 +7851,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 361, + "line": 382, "description": "Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one.", "itemtype": "method", "name": "testSepAxis", @@ -6696,13 +7889,13 @@ ], "return": { "description": "The overlap depth, or FALSE if no penetration.", - "type": "Float" + "type": "Number" }, "class": "ConvexPolyhedron" }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 393, + "line": 413, "itemtype": "method", "name": "calculateLocalInertia", "params": [ @@ -6721,7 +7914,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 410, + "line": 430, "itemtype": "method", "name": "getPlaneConstantOfFace", "params": [ @@ -6739,7 +7932,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 423, + "line": 443, "description": "Clip a face against a hull.", "itemtype": "method", "name": "clipFaceAgainstHull", @@ -6783,7 +7976,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 577, + "line": 588, "description": "Clip a face in a hull against the back of a plane.", "itemtype": "method", "name": "clipFaceAgainstPlane", @@ -6813,7 +8006,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 687, + "line": 689, "description": "Updates .worldVertices and sets .worldVerticesNeedsUpdate to false.", "itemtype": "method", "name": "computeWorldFaceNormals", @@ -6828,14 +8021,14 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 707, + "line": 709, "itemtype": "method", "name": "updateBoundingSphereRadius", "class": "ConvexPolyhedron" }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 725, + "line": 727, "itemtype": "method", "name": "calculateWorldAABB", "params": [ @@ -6864,7 +8057,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 762, + "line": 764, "description": "Get approximate convex volume", "itemtype": "method", "name": "volume", @@ -6876,7 +8069,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 771, + "line": 773, "description": "Get an average of all the vertices positions", "itemtype": "method", "name": "getAveragePointLocal", @@ -6895,7 +8088,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 788, + "line": 790, "description": "Transform all local points. Will change the .vertices", "itemtype": "method", "name": "transformAllPoints", @@ -6915,7 +8108,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 827, + "line": 829, "description": "Checks whether p is inside the polyhedra. Must be in local coords. The point lies outside of the convex hull of the other points if and only if the direction of all the vectors from it to those other points are on less than one half of a sphere around it.", "itemtype": "method", "name": "pointIsInside", @@ -6934,7 +8127,7 @@ }, { "file": "src/shapes/ConvexPolyhedron.js", - "line": 869, + "line": 871, "description": "Get max and min dot product of a convex hull at position (pos,quat) projected onto an axis. Results are saved in the array maxmin.", "static": 1, "itemtype": "method", @@ -7018,8 +8211,9 @@ { "file": "src/shapes/Heightfield.js", "line": 100, + "description": "Update the .minValue property", "itemtype": "method", - "name": "updateMinValue\nUpdate the .minValue property", + "name": "updateMinValue", "class": "Heightfield" }, { @@ -7180,6 +8374,15 @@ { "file": "src/shapes/Shape.js", "line": 17, + "description": "Identifyer of the Shape.", + "itemtype": "property", + "name": "id", + "type": "Number", + "class": "Shape" + }, + { + "file": "src/shapes/Shape.js", + "line": 23, "description": "The type of this shape. Must be set to an int > 0 by subclasses.", "itemtype": "property", "name": "type", @@ -7191,7 +8394,7 @@ }, { "file": "src/shapes/Shape.js", - "line": 25, + "line": 31, "description": "The local bounding sphere radius of this shape.", "itemtype": "property", "name": "boundingSphereRadius", @@ -7200,7 +8403,7 @@ }, { "file": "src/shapes/Shape.js", - "line": 31, + "line": 37, "description": "Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.", "itemtype": "property", "name": "collisionResponse", @@ -7209,7 +8412,15 @@ }, { "file": "src/shapes/Shape.js", - "line": 39, + "line": 43, + "itemtype": "property", + "name": "material", + "type": "Material", + "class": "Shape" + }, + { + "file": "src/shapes/Shape.js", + "line": 50, "description": "Computes the bounding sphere radius. The result is stored in the property .boundingSphereRadius", "itemtype": "method", "name": "updateBoundingSphereRadius", @@ -7221,7 +8432,7 @@ }, { "file": "src/shapes/Shape.js", - "line": 48, + "line": 59, "description": "Get the volume of this shape", "itemtype": "method", "name": "volume", @@ -7233,7 +8444,7 @@ }, { "file": "src/shapes/Shape.js", - "line": 57, + "line": 68, "description": "Calculates the inertia in the local frame for this shape.", "itemtype": "method", "name": "calculateLocalInertia", @@ -7248,7 +8459,7 @@ }, { "file": "src/shapes/Shape.js", - "line": 67, + "line": 80, "description": "The available shape types.", "static": 1, "itemtype": "property", @@ -7265,39 +8476,517 @@ "class": "Sphere" }, { - "file": "src/solver/GSSolver.js", - "line": 19, - "description": "The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.", + "file": "src/shapes/Trimesh.js", + "line": 32, "itemtype": "property", - "name": "iterations", - "type": "{Number}", - "todo": [ - "write more about solver and iterations in the wiki" - ], - "class": "GSSolver" + "name": "vertices", + "type": "{Array}", + "class": "Trimesh" }, { - "file": "src/solver/GSSolver.js", - "line": 27, - "description": "When tolerance is reached, the system is assumed to be converged.", + "file": "src/shapes/Trimesh.js", + "line": 38, + "description": "Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles.", "itemtype": "property", - "name": "tolerance", - "type": "{Number}", - "class": "GSSolver" + "name": "indices", + "type": "{Array}", + "class": "Trimesh" }, { - "file": "src/solver/Solver.js", - "line": 10, - "description": "All equations to be solved", + "file": "src/shapes/Trimesh.js", + "line": 45, + "description": "The normals data.", "itemtype": "property", - "name": "equations", + "name": "normals", + "type": "{Array}", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 52, + "description": "The local AABB of the mesh.", + "itemtype": "property", + "name": "aabb", + "type": "{Array}", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 59, + "description": "References to vertex pairs, making up all unique edges in the trimesh.", + "itemtype": "property", + "name": "edges", "type": "Array", - "class": "Solver" + "class": "Trimesh" }, { - "file": "src/solver/Solver.js", - "line": 17, - "description": "Should be implemented in subclasses!", + "file": "src/shapes/Trimesh.js", + "line": 65, + "description": "Local scaling of the mesh. Use .setScale() to set it.", + "itemtype": "property", + "name": "scale", + "type": "Vec3", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 71, + "description": "The indexed triangles. Use .updateTree() to update it.", + "itemtype": "property", + "name": "tree", + "type": "Octree", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 88, + "itemtype": "method", + "name": "updateTree", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 127, + "description": "Get triangles in a local AABB from the trimesh.", + "itemtype": "method", + "name": "getTrianglesInAABB", + "params": [ + { + "name": "aabb", + "description": "", + "type": "AABB" + }, + { + "name": "result", + "description": "An array of integers, referencing the queried triangles.", + "type": "Array" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 153, + "itemtype": "method", + "name": "setScale", + "params": [ + { + "name": "scale", + "description": "", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 170, + "description": "Compute the normals of the faces. Will save in the .normals array.", + "itemtype": "method", + "name": "updateNormals", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 198, + "description": "Update the .edges property", + "itemtype": "method", + "name": "updateEdges", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 226, + "description": "Get an edge vertex", + "itemtype": "method", + "name": "getEdgeVertex", + "params": [ + { + "name": "edgeIndex", + "description": "", + "type": "Number" + }, + { + "name": "firstOrSecond", + "description": "0 or 1, depending on which one of the vertices you need.", + "type": "Number" + }, + { + "name": "vertexStore", + "description": "Where to store the result", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 241, + "description": "Get a vector along an edge.", + "itemtype": "method", + "name": "getEdgeVector", + "params": [ + { + "name": "edgeIndex", + "description": "", + "type": "Number" + }, + { + "name": "vectorStore", + "description": "", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 255, + "description": "Get face normal given 3 vertices", + "static": 1, + "itemtype": "method", + "name": "computeNormal", + "params": [ + { + "name": "va", + "description": "", + "type": "Vec3" + }, + { + "name": "vb", + "description": "", + "type": "Vec3" + }, + { + "name": "vc", + "description": "", + "type": "Vec3" + }, + { + "name": "target", + "description": "", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 279, + "description": "Get vertex i.", + "itemtype": "method", + "name": "getVertex", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "out", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"out\" vector object", + "type": "Vec3" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 295, + "description": "Get raw vertex i", + "access": "private", + "tagname": "", + "itemtype": "method", + "name": "_getUnscaledVertex", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "out", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"out\" vector object", + "type": "Vec3" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 313, + "description": "Get a vertex from the trimesh,transformed by the given position and quaternion.", + "itemtype": "method", + "name": "getWorldVertex", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "pos", + "description": "", + "type": "Vec3" + }, + { + "name": "quat", + "description": "", + "type": "Quaternion" + }, + { + "name": "out", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"out\" vector object", + "type": "Vec3" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 328, + "description": "Get the three vertices for triangle i.", + "itemtype": "method", + "name": "getTriangleVertices", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "a", + "description": "", + "type": "Vec3" + }, + { + "name": "b", + "description": "", + "type": "Vec3" + }, + { + "name": "c", + "description": "", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 343, + "description": "Compute the normal of triangle i.", + "itemtype": "method", + "name": "getNormal", + "params": [ + { + "name": "i", + "description": "", + "type": "Number" + }, + { + "name": "target", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"target\" vector object", + "type": "Vec3" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 361, + "itemtype": "method", + "name": "calculateLocalInertia", + "params": [ + { + "name": "mass", + "description": "", + "type": "Number" + }, + { + "name": "target", + "description": "", + "type": "Vec3" + } + ], + "return": { + "description": "The \"target\" vector object", + "type": "Vec3" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 383, + "description": "Compute the local AABB for the trimesh", + "itemtype": "method", + "name": "computeLocalAABB", + "params": [ + { + "name": "aabb", + "description": "", + "type": "AABB" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 423, + "description": "Update the .aabb property", + "itemtype": "method", + "name": "updateAABB", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 431, + "description": "Will update the .boundingSphereRadius property", + "itemtype": "method", + "name": "updateBoundingSphereRadius", + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 454, + "itemtype": "method", + "name": "calculateWorldAABB", + "params": [ + { + "name": "pos", + "description": "", + "type": "Vec3" + }, + { + "name": "quat", + "description": "", + "type": "Quaternion" + }, + { + "name": "min", + "description": "", + "type": "Vec3" + }, + { + "name": "max", + "description": "", + "type": "Vec3" + } + ], + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 504, + "description": "Get approximate volume", + "itemtype": "method", + "name": "volume", + "return": { + "description": "", + "type": "Number" + }, + "class": "Trimesh" + }, + { + "file": "src/shapes/Trimesh.js", + "line": 513, + "description": "Create a Trimesh instance, shaped as a torus.", + "static": 1, + "itemtype": "method", + "name": "createTorus", + "params": [ + { + "name": "radius", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "1" + }, + { + "name": "tube", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "0.5" + }, + { + "name": "radialSegments", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "8" + }, + { + "name": "tubularSegments", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "6" + }, + { + "name": "arc", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "6.283185307179586" + } + ], + "return": { + "description": "A torus", + "type": "Trimesh" + }, + "class": "Trimesh" + }, + { + "file": "src/solver/GSSolver.js", + "line": 19, + "description": "The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.", + "itemtype": "property", + "name": "iterations", + "type": "{Number}", + "todo": [ + "write more about solver and iterations in the wiki" + ], + "class": "GSSolver" + }, + { + "file": "src/solver/GSSolver.js", + "line": 27, + "description": "When tolerance is reached, the system is assumed to be converged.", + "itemtype": "property", + "name": "tolerance", + "type": "{Number}", + "class": "GSSolver" + }, + { + "file": "src/solver/Solver.js", + "line": 10, + "description": "All equations to be solved", + "itemtype": "property", + "name": "equations", + "type": "Array", + "class": "Solver" + }, + { + "file": "src/solver/Solver.js", + "line": 17, + "description": "Should be implemented in subclasses!", "itemtype": "method", "name": "solve", "params": [ @@ -7354,7 +9043,7 @@ }, { "file": "src/solver/SplitSolver.js", - "line": 27, + "line": 81, "description": "Solve the subsystems", "itemtype": "method", "name": "solve", @@ -7470,6 +9159,143 @@ }, "class": "EventTarget" }, + { + "file": "src/utils/Octree.js", + "line": 15, + "description": "The root node", + "itemtype": "property", + "name": "root", + "type": "OctreeNode", + "class": "OctreeNode" + }, + { + "file": "src/utils/Octree.js", + "line": 21, + "description": "Boundary of this node", + "itemtype": "property", + "name": "aabb", + "type": "AABB", + "class": "OctreeNode" + }, + { + "file": "src/utils/Octree.js", + "line": 27, + "description": "Contained data at the current node level.", + "itemtype": "property", + "name": "data", + "type": "Array", + "class": "OctreeNode" + }, + { + "file": "src/utils/Octree.js", + "line": 33, + "description": "Children to this node", + "itemtype": "property", + "name": "children", + "type": "Array", + "class": "OctreeNode" + }, + { + "file": "src/utils/Octree.js", + "line": 53, + "description": "Maximum subdivision depth", + "itemtype": "property", + "name": "maxDepth", + "type": "Number", + "class": "Octree" + }, + { + "file": "src/utils/Octree.js", + "line": 65, + "description": "Insert data into this node", + "itemtype": "method", + "name": "insert", + "params": [ + { + "name": "aabb", + "description": "", + "type": "AABB" + }, + { + "name": "elementData", + "description": "", + "type": "Object" + } + ], + "return": { + "description": "True if successful, otherwise false", + "type": "Boolean" + }, + "class": "Octree" + }, + { + "file": "src/utils/Octree.js", + "line": 112, + "description": "Create 8 equally sized children nodes and put them in the .children array.", + "itemtype": "method", + "name": "subdivide", + "class": "Octree" + }, + { + "file": "src/utils/Octree.js", + "line": 158, + "description": "Get all data, potentially within an AABB", + "itemtype": "method", + "name": "aabbQuery", + "params": [ + { + "name": "aabb", + "description": "", + "type": "AABB" + }, + { + "name": "result", + "description": "", + "type": "Array" + } + ], + "return": { + "description": "The \"result\" object", + "type": "Array" + }, + "class": "Octree" + }, + { + "file": "src/utils/Octree.js", + "line": 200, + "description": "Get all data, potentially intersected by a ray.", + "itemtype": "method", + "name": "rayQuery", + "params": [ + { + "name": "ray", + "description": "", + "type": "Ray" + }, + { + "name": "treeTransform", + "description": "", + "type": "Transform" + }, + { + "name": "result", + "description": "", + "type": "Array" + } + ], + "return": { + "description": "The \"result\" object", + "type": "Array" + }, + "class": "Octree" + }, + { + "file": "src/utils/Octree.js", + "line": 219, + "itemtype": "method", + "name": "removeEmptyNodes", + "class": "Octree" + }, { "file": "src/utils/Pool.js", "line": 9, @@ -7629,7 +9455,7 @@ }, { "file": "src/world/Narrowphase.js", - "line": 22, + "line": 25, "description": "Internal storage of pooled contact points.", "itemtype": "property", "name": "contactPointPool", @@ -7638,7 +9464,7 @@ }, { "file": "src/world/Narrowphase.js", - "line": 28, + "line": 36, "description": "Pooled vectors.", "itemtype": "property", "name": "v3pool", @@ -7647,10 +9473,18 @@ }, { "file": "src/world/Narrowphase.js", - "line": 35, + "line": 45, + "itemtype": "property", + "name": "enableFrictionReduction", + "type": "Boolean", + "class": "Narrowphase" + }, + { + "file": "src/world/Narrowphase.js", + "line": 51, "description": "Make a contact object, by using the internal pool or creating a new one.", "itemtype": "method", - "name": "makeResult", + "name": "createContactEquation", "return": { "description": "", "type": "ContactEquation" @@ -7659,50 +9493,192 @@ }, { "file": "src/world/Narrowphase.js", - "line": 62, + "line": 199, "description": "Generate all contacts between a list of body pairs", "itemtype": "method", "name": "getContacts", "params": [ { - "name": "p1", - "description": "Array of body indices", - "type": "Array" + "name": "p1", + "description": "Array of body indices", + "type": "Array" + }, + { + "name": "p2", + "description": "Array of body indices", + "type": "Array" + }, + { + "name": "world", + "description": "", + "type": "World" + }, + { + "name": "result", + "description": "Array to store generated contacts", + "type": "Array" + }, + { + "name": "oldcontacts", + "description": "Optional. Array of reusable contact objects", + "type": "Array" + } + ], + "class": "Narrowphase" + }, + { + "file": "src/world/Narrowphase.js", + "line": 308, + "itemtype": "method", + "name": "sphereSphere", + "params": [ + { + "name": "si", + "description": "", + "type": "Shape" + }, + { + "name": "sj", + "description": "", + "type": "Shape" + }, + { + "name": "xi", + "description": "", + "type": "Vec3" + }, + { + "name": "xj", + "description": "", + "type": "Vec3" + }, + { + "name": "qi", + "description": "", + "type": "Quaternion" + }, + { + "name": "qj", + "description": "", + "type": "Quaternion" + }, + { + "name": "bi", + "description": "", + "type": "Body" + }, + { + "name": "bj", + "description": "", + "type": "Body" + } + ], + "class": "Narrowphase" + }, + { + "file": "src/world/Narrowphase.js", + "line": 345, + "itemtype": "method", + "name": "planeTrimesh", + "params": [ + { + "name": "si", + "description": "", + "type": "Shape" + }, + { + "name": "sj", + "description": "", + "type": "Shape" + }, + { + "name": "xi", + "description": "", + "type": "Vec3" + }, + { + "name": "xj", + "description": "", + "type": "Vec3" + }, + { + "name": "qi", + "description": "", + "type": "Quaternion" + }, + { + "name": "qj", + "description": "", + "type": "Quaternion" + }, + { + "name": "bi", + "description": "", + "type": "Body" + }, + { + "name": "bj", + "description": "", + "type": "Body" + } + ], + "class": "Narrowphase" + }, + { + "file": "src/world/Narrowphase.js", + "line": 416, + "itemtype": "method", + "name": "sphereTrimesh", + "params": [ + { + "name": "sphereShape", + "description": "", + "type": "Shape" + }, + { + "name": "trimeshShape", + "description": "", + "type": "Shape" + }, + { + "name": "spherePos", + "description": "", + "type": "Vec3" }, { - "name": "p2", - "description": "Array of body indices", - "type": "Array" + "name": "trimeshPos", + "description": "", + "type": "Vec3" }, { - "name": "world", + "name": "sphereQuat", "description": "", - "type": "World" + "type": "Quaternion" }, { - "name": "result", - "description": "Array to store generated contacts", - "type": "Array" + "name": "trimeshQuat", + "description": "", + "type": "Quaternion" }, { - "name": "oldcontacts", - "description": "Optional. Array of reusable contact objects", - "type": "Array" + "name": "sphereBody", + "description": "", + "type": "Body" + }, + { + "name": "trimeshBody", + "description": "", + "type": "Body" } ], "class": "Narrowphase" }, { "file": "src/world/Narrowphase.js", - "line": 146, + "line": 612, "itemtype": "method", - "name": "sphereSphere", + "name": "spherePlane", "params": [ - { - "name": "result", - "description": "", - "type": "Array" - }, { "name": "si", "description": "", @@ -7748,15 +9724,10 @@ }, { "file": "src/world/Narrowphase.js", - "line": 178, + "line": 708, "itemtype": "method", - "name": "spherePlane", + "name": "sphereBox", "params": [ - { - "name": "result", - "description": "", - "type": "Array" - }, { "name": "si", "description": "", @@ -7802,15 +9773,10 @@ }, { "file": "src/world/Narrowphase.js", - "line": 273, + "line": 929, "itemtype": "method", - "name": "sphereBox", + "name": "sphereConvex", "params": [ - { - "name": "result", - "description": "", - "type": "Array" - }, { "name": "si", "description": "", @@ -7856,9 +9822,9 @@ }, { "file": "src/world/Narrowphase.js", - "line": 492, + "line": 1152, "itemtype": "method", - "name": "sphereConvex", + "name": "planeBox", "params": [ { "name": "result", @@ -7910,15 +9876,10 @@ }, { "file": "src/world/Narrowphase.js", - "line": 713, + "line": 1176, "itemtype": "method", - "name": "planeBox", + "name": "planeConvex", "params": [ - { - "name": "result", - "description": "", - "type": "Array" - }, { "name": "si", "description": "", @@ -7964,15 +9925,10 @@ }, { "file": "src/world/Narrowphase.js", - "line": 735, + "line": 1252, "itemtype": "method", - "name": "planeConvex", + "name": "convexConvex", "params": [ - { - "name": "result", - "description": "", - "type": "Array" - }, { "name": "si", "description": "", @@ -8018,9 +9974,9 @@ }, { "file": "src/world/Narrowphase.js", - "line": 804, + "line": 1309, "itemtype": "method", - "name": "convexConvex", + "name": "convexTrimesh", "params": [ { "name": "result", @@ -8072,7 +10028,7 @@ }, { "file": "src/world/Narrowphase.js", - "line": 857, + "line": 1393, "itemtype": "method", "name": "particlePlane", "params": [ @@ -8126,7 +10082,7 @@ }, { "file": "src/world/Narrowphase.js", - "line": 897, + "line": 1434, "itemtype": "method", "name": "particleSphere", "params": [ @@ -8180,7 +10136,7 @@ }, { "file": "src/world/Narrowphase.js", - "line": 937, + "line": 1475, "itemtype": "method", "name": "convexParticle", "params": [ @@ -8234,14 +10190,14 @@ }, { "file": "src/world/Narrowphase.js", - "line": 1032, + "line": 1573, "itemtype": "method", - "name": "sphereHeightfield", + "name": "convexHeightfield", "class": "Narrowphase" }, { "file": "src/world/Narrowphase.js", - "line": 1114, + "line": 1651, "itemtype": "method", "name": "sphereHeightfield", "class": "Narrowphase" @@ -8249,7 +10205,7 @@ { "file": "src/world/World.js", "line": 33, - "description": "Last used timestep. Is set to -1 if not available.", + "description": "Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is \"fresh\" inside event callbacks.", "itemtype": "property", "name": "dt", "type": "Number", @@ -8433,7 +10389,7 @@ "file": "src/world/World.js", "line": 183, "itemtype": "property", - "name": "subystems", + "name": "subsystems", "type": "{Array}", "class": "World" }, @@ -8457,7 +10413,7 @@ ], "return": { "description": "The contact material if it was found.", - "type": "Contactmaterial" + "type": "ContactMaterial" }, "class": "World" }, @@ -8557,11 +10513,205 @@ "type": "Function|RaycastResult" } ], + "deprecated": true, + "deprecationMessage": "Use .raycastAll, .raycastClosest or .raycastAny instead.", + "class": "World" + }, + { + "file": "src/world/World.js", + "line": 308, + "description": "Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.", + "itemtype": "method", + "name": "raycastAll", + "params": [ + { + "name": "from", + "description": "", + "type": "Vec3" + }, + { + "name": "to", + "description": "", + "type": "Vec3" + }, + { + "name": "options", + "description": "", + "type": "Object", + "props": [ + { + "name": "collisionFilterMask", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "collisionFilterGroup", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "skipBackfaces", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "false" + }, + { + "name": "checkCollisionResponse", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "true" + } + ] + }, + { + "name": "callback", + "description": "", + "type": "Function" + } + ], + "return": { + "description": "True if any body was hit.", + "type": "Boolean" + }, + "class": "World" + }, + { + "file": "src/world/World.js", + "line": 329, + "description": "Ray cast, and stop at the first result. Note that the order is random - but the method is fast.", + "itemtype": "method", + "name": "raycastAny", + "params": [ + { + "name": "from", + "description": "", + "type": "Vec3" + }, + { + "name": "to", + "description": "", + "type": "Vec3" + }, + { + "name": "options", + "description": "", + "type": "Object", + "props": [ + { + "name": "collisionFilterMask", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "collisionFilterGroup", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "skipBackfaces", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "false" + }, + { + "name": "checkCollisionResponse", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "true" + } + ] + }, + { + "name": "result", + "description": "", + "type": "RaycastResult" + } + ], + "return": { + "description": "True if any body was hit.", + "type": "Boolean" + }, + "class": "World" + }, + { + "file": "src/world/World.js", + "line": 350, + "description": "Ray cast, and return information of the closest hit.", + "itemtype": "method", + "name": "raycastClosest", + "params": [ + { + "name": "from", + "description": "", + "type": "Vec3" + }, + { + "name": "to", + "description": "", + "type": "Vec3" + }, + { + "name": "options", + "description": "", + "type": "Object", + "props": [ + { + "name": "collisionFilterMask", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "collisionFilterGroup", + "description": "", + "type": "Number", + "optional": true, + "optdefault": "-1" + }, + { + "name": "skipBackfaces", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "false" + }, + { + "name": "checkCollisionResponse", + "description": "", + "type": "Boolean", + "optional": true, + "optdefault": "true" + } + ] + }, + { + "name": "result", + "description": "", + "type": "RaycastResult" + } + ], + "return": { + "description": "True if any body was hit.", + "type": "Boolean" + }, "class": "World" }, { "file": "src/world/World.js", - "line": 306, + "line": 371, "description": "Remove a rigid body from the simulation.", "itemtype": "method", "name": "remove", @@ -8572,14 +10722,28 @@ "type": "Body" } ], - "todo": [ - "Rename to .removeBody" + "deprecated": true, + "deprecationMessage": "Use .removeBody instead", + "class": "World" + }, + { + "file": "src/world/World.js", + "line": 396, + "description": "Remove a rigid body from the simulation.", + "itemtype": "method", + "name": "removeBody", + "params": [ + { + "name": "body", + "description": "", + "type": "Body" + } ], "class": "World" }, { "file": "src/world/World.js", - "line": 331, + "line": 403, "description": "Adds a material to the World.", "itemtype": "method", "name": "addMaterial", @@ -8597,7 +10761,7 @@ }, { "file": "src/world/World.js", - "line": 341, + "line": 413, "description": "Adds a contact material to the World", "itemtype": "method", "name": "addContactMaterial", @@ -8612,7 +10776,7 @@ }, { "file": "src/world/World.js", - "line": 371, + "line": 443, "description": "Step the physics world forward in time.\n\nThere are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.", "itemtype": "method", "name": "step", @@ -8646,7 +10810,7 @@ }, { "file": "src/world/World.js", - "line": 445, + "line": 517, "description": "Step the simulation", "itemtype": "method", "name": "step", @@ -8658,6 +10822,14 @@ } ], "class": "World" + }, + { + "file": "src/world/World.js", + "line": 936, + "description": "Sets all body forces in the world to zero.", + "itemtype": "method", + "name": "clearForces", + "class": "World" } ], "warnings": [] diff --git a/docs/files/src_collision_AABB.js.html b/docs/files/src_collision_AABB.js.html index 0ef8ee44a..95c548f3e 100644 --- a/docs/files/src_collision_AABB.js.html +++ b/docs/files/src_collision_AABB.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/AABB.js

    +

    File: src/collision/AABB.js

    @@ -191,9 +142,9 @@ 

    File: src/collision/AABB.js

    * Axis aligned bounding box class. * @class AABB * @constructor - * @param {Object} [options] - * @param {Array} [options.upperBound] - * @param {Array} [options.lowerBound] + * @param {Object} [options] + * @param {Vec3} [options.upperBound] + * @param {Vec3} [options.lowerBound] */ function AABB(options){ options = options || {}; @@ -201,7 +152,7 @@

    File: src/collision/AABB.js

    /** * The lower bound of the bounding box. * @property lowerBound - * @type {Array} + * @type {Vec3} */ this.lowerBound = new Vec3(); if(options.lowerBound){ @@ -211,7 +162,7 @@

    File: src/collision/AABB.js

    /** * The upper bound of the bounding box. * @property upperBound - * @type {Array} + * @type {Vec3} */ this.upperBound = new Vec3(); if(options.upperBound){ @@ -228,6 +179,7 @@

    File: src/collision/AABB.js

    * @param {Vec3} position * @param {Quaternion} quaternion * @param {number} skinSize + * @return {AABB} The self object */ AABB.prototype.setFromPoints = function(points, position, quaternion, skinSize){ var l = this.lowerBound, @@ -271,16 +223,28 @@

    File: src/collision/AABB.js

    u.y += skinSize; u.z += skinSize; } + + return this; }; /** * Copy bounds from an AABB to this AABB * @method copy * @param {AABB} aabb Source to copy from + * @return {AABB} The this object, for chainability */ AABB.prototype.copy = function(aabb){ this.lowerBound.copy(aabb.lowerBound); this.upperBound.copy(aabb.upperBound); + return this; +}; + +/** + * Clone an AABB + * @method clone + */ +AABB.prototype.clone = function(){ + return new AABB().copy(this); }; /** @@ -348,9 +312,130 @@

    File: src/collision/AABB.js

    ((l2.z <= u1.z && u1.z <= u2.z) || (l1.z <= u2.z && u2.z <= u1.z)); }; +/** + * Returns true if the given AABB is fully contained in this AABB. + * @method contains + * @param {AABB} aabb + * @return {Boolean} + */ +AABB.prototype.contains = function(aabb){ + var l1 = this.lowerBound, + u1 = this.upperBound, + l2 = aabb.lowerBound, + u2 = aabb.upperBound; + + // l2 u2 + // |---------| + // |---------------| + // l1 u1 + + return ( + (l1.x <= l2.x && u1.x >= u2.x) && + (l1.y <= l2.y && u1.y >= u2.y) && + (l1.z <= l2.z && u1.z >= u2.z) + ); +}; + +/** + * @method getCorners + * @param {Vec3} a + * @param {Vec3} b + * @param {Vec3} c + * @param {Vec3} d + * @param {Vec3} e + * @param {Vec3} f + * @param {Vec3} g + * @param {Vec3} h + */ +AABB.prototype.getCorners = function(a, b, c, d, e, f, g, h){ + var l = this.lowerBound, + u = this.upperBound; + + a.copy(l); + b.set( u.x, l.y, l.z ); + c.set( u.x, u.y, l.z ); + d.set( l.x, u.y, u.z ); + e.set( u.x, l.y, l.z ); + f.set( l.x, u.y, l.z ); + g.set( l.x, l.y, u.z ); + h.copy(u); +}; + +var transformIntoFrame_corners = [ + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3(), + new Vec3() +]; + +/** + * Get the representation of an AABB in another frame. + * @method toLocalFrame + * @param {Transform} frame + * @param {AABB} target + * @return {AABB} The "target" AABB object. + */ +AABB.prototype.toLocalFrame = function(frame, target){ + + var corners = transformIntoFrame_corners; + var a = corners[0]; + var b = corners[1]; + var c = corners[2]; + var d = corners[3]; + var e = corners[4]; + var f = corners[5]; + var g = corners[6]; + var h = corners[7]; + + // Get corners in current frame + this.getCorners(a, b, c, d, e, f, g, h); + + // Transform them to new local frame + for(var i=0; i !== 8; i++){ + var corner = corners[i]; + frame.pointToLocal(corner, corner); + } + + return target.setFromPoints(corners); +}; + +/** + * Get the representation of an AABB in the global frame. + * @method toWorldFrame + * @param {Transform} frame + * @param {AABB} target + * @return {AABB} The "target" AABB object. + */ +AABB.prototype.toWorldFrame = function(frame, target){ + + var corners = transformIntoFrame_corners; + var a = corners[0]; + var b = corners[1]; + var c = corners[2]; + var d = corners[3]; + var e = corners[4]; + var f = corners[5]; + var g = corners[6]; + var h = corners[7]; + + // Get corners in current frame + this.getCorners(a, b, c, d, e, f, g, h); + + // Transform them to new local frame + for(var i=0; i !== 8; i++){ + var corner = corners[i]; + frame.pointToWorld(corner, corner); + } + + return target.setFromPoints(corners); +}; +
    -
    diff --git a/docs/files/src_collision_ArrayCollisionMatrix.js.html b/docs/files/src_collision_ArrayCollisionMatrix.js.html index 1c4a71f6d..bccca991c 100644 --- a/docs/files/src_collision_ArrayCollisionMatrix.js.html +++ b/docs/files/src_collision_ArrayCollisionMatrix.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/ArrayCollisionMatrix.js

    +

    File: src/collision/ArrayCollisionMatrix.js

    @@ -256,7 +207,6 @@ 

    File: src/collision/ArrayCollisionMatrix.js

    -
    diff --git a/docs/files/src_collision_Broadphase.js.html b/docs/files/src_collision_Broadphase.js.html index 40de27f95..cee40e858 100644 --- a/docs/files/src_collision_Broadphase.js.html +++ b/docs/files/src_collision_Broadphase.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/Broadphase.js

    +

    File: src/collision/Broadphase.js

    @@ -383,15 +334,15 @@ 

    File: src/collision/Broadphase.js

    * @method aabbQuery * @param {World} world * @param {AABB} aabb + * @param {array} result An array to store resulting bodies in. * @return {array} */ -Broadphase.prototype.aabbQuery = function(world, aabb){ +Broadphase.prototype.aabbQuery = function(world, aabb, result){ console.warn('.aabbQuery is not implemented in this Broadphase subclass.'); return []; };
    -
    diff --git a/docs/files/src_collision_GridBroadphase.js.html b/docs/files/src_collision_GridBroadphase.js.html index 33dd4190b..4aa58345f 100644 --- a/docs/files/src_collision_GridBroadphase.js.html +++ b/docs/files/src_collision_GridBroadphase.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/GridBroadphase.js

    +

    File: src/collision/GridBroadphase.js

    @@ -413,7 +364,6 @@ 

    File: src/collision/GridBroadphase.js

    -
    diff --git a/docs/files/src_collision_NaiveBroadphase.js.html b/docs/files/src_collision_NaiveBroadphase.js.html index 1d4476df1..2ca1859dd 100644 --- a/docs/files/src_collision_NaiveBroadphase.js.html +++ b/docs/files/src_collision_NaiveBroadphase.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/NaiveBroadphase.js

    +

    File: src/collision/NaiveBroadphase.js

    @@ -248,7 +199,7 @@ 

    File: src/collision/NaiveBroadphase.js

    b.computeAABB(); } - // Ugly hack until RigidBody gets aabb + // Ugly hack until Body gets aabb if(b.aabb.overlaps(aabb)){ result.push(b); } @@ -258,7 +209,6 @@

    File: src/collision/NaiveBroadphase.js

    };
    -
    diff --git a/docs/files/src_collision_ObjectCollisionMatrix.js.html b/docs/files/src_collision_ObjectCollisionMatrix.js.html index a33909573..09a78e686 100644 --- a/docs/files/src_collision_ObjectCollisionMatrix.js.html +++ b/docs/files/src_collision_ObjectCollisionMatrix.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/ObjectCollisionMatrix.js

    +

    File: src/collision/ObjectCollisionMatrix.js

    @@ -256,7 +207,6 @@ 

    File: src/collision/ObjectCollisionMatrix.js

    -
    diff --git a/docs/files/src_collision_Ray.js.html b/docs/files/src_collision_Ray.js.html index 1a9546489..f594dbb4a 100644 --- a/docs/files/src_collision_Ray.js.html +++ b/docs/files/src_collision_Ray.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/Ray.js

    +

    File: src/collision/Ray.js

    @@ -211,6 +162,10 @@ 

    File: src/collision/Ray.js

    */ this.to = to ? to.clone() : new Vec3(); + /** + * @private + * @property {Vec3} _direction + */ this._direction = new Vec3(); /** @@ -224,15 +179,98 @@

    File: src/collision/Ray.js

    * @property {Boolean} checkCollisionResponse */ this.checkCollisionResponse = true; + + /** + * If set to true, the ray skips any hits with normal.dot(rayDirection) < 0. + * @property {Boolean} skipBackfaces + */ + this.skipBackfaces = false; + + /** + * @property {number} collisionFilterMask + * @default -1 + */ + this.collisionFilterMask = -1; + + /** + * @property {number} collisionFilterGroup + * @default -1 + */ + this.collisionFilterGroup = -1; + + /** + * The intersection mode. Should be Ray.ANY, Ray.ALL or Ray.CLOSEST. + * @property {number} mode + */ + this.mode = Ray.ANY; + + /** + * Current result object. + * @property {RaycastResult} result + */ + this.result = new RaycastResult(); + + /** + * Will be set to true during intersectWorld() if the ray hit anything. + * @property {Boolean} hasHit + */ + this.hasHit = false; + + /** + * Current, user-provided result callback. Will be used if mode is Ray.ALL. + * @property {Function} callback + */ + this.callback = function(result){}; } Ray.prototype.constructor = Ray; +Ray.CLOSEST = 1; +Ray.ANY = 2; +Ray.ALL = 4; + +var tmpAABB = new AABB(); +var tmpArray = []; + +/** + * Do itersection against all bodies in the given World. + * @method intersectWorld + * @param {World} world + * @param {object} options + * @return {Boolean} True if the ray hit anything, otherwise false. + */ +Ray.prototype.intersectWorld = function (world, options) { + this.mode = options.mode || Ray.ANY; + this.result = options.result || new RaycastResult(); + this.skipBackfaces = !!options.skipBackfaces; + this.collisionFilterMask = typeof(options.collisionFilterMask) !== 'undefined' ? options.collisionFilterMask : -1; + this.collisionFilterGroup = typeof(options.collisionFilterGroup) !== 'undefined' ? options.collisionFilterGroup : -1; + if(options.from){ + this.from.copy(options.from); + } + if(options.to){ + this.to.copy(options.to); + } + this.callback = options.callback || function(){}; + this.hasHit = false; + + this.result.reset(); + this._updateDirection(); + + this.getAABB(tmpAABB); + tmpArray.length = 0; + world.broadphase.aabbQuery(world, tmpAABB, tmpArray); + this.intersectBodies(tmpArray); + + return this.hasHit; +}; + var v1 = new Vec3(), v2 = new Vec3(); /* * As per "Barycentric Technique" as named here http://www.blackpawn.com/texts/pointinpoly/default.html But without the division */ +Ray.pointInTriangle = pointInTriangle; function pointInTriangle(p, a, b, c) { c.vsub(a,v0); b.vsub(a,v1); @@ -256,24 +294,29 @@

    File: src/collision/Ray.js

    * @method intersectBody * @private * @param {Body} body - * @param {RaycastResult} result - * @param {Vec3} [direction] + * @param {RaycastResult} [result] Deprecated - set the result property of the Ray instead. */ -Ray.prototype.intersectBody = function (body, result, direction) { +var intersectBody_xi = new Vec3(); +var intersectBody_qi = new Quaternion(); +Ray.prototype.intersectBody = function (body, result) { + if(result){ + this.result = result; + this._updateDirection(); + } var checkCollisionResponse = this.checkCollisionResponse; if(checkCollisionResponse && !body.collisionResponse){ - return result; + return; } - if(!direction){ - this._updateDirection(); - direction = this._direction; + if((this.collisionFilterGroup & body.collisionFilterMask)===0 || (body.collisionFilterGroup & this.collisionFilterMask)===0){ + return; } - var xi = new Vec3(); - var qi = new Quaternion(); - for (var i = 0; i < body.shapes.length; i++) { + var xi = intersectBody_xi; + var qi = intersectBody_qi; + + for (var i = 0, N = body.shapes.length; i < N; i++) { var shape = body.shapes[i]; if(checkCollisionResponse && !shape.collisionResponse){ @@ -288,33 +331,36 @@

    File: src/collision/Ray.js

    shape, qi, xi, - body, - direction, - result + body ); - } - return result; + if(this.result._shouldStop){ + break; + } + } }; /** * @method intersectBodies * @param {Array} bodies An array of Body objects. - * @param {RaycastResult} result + * @param {RaycastResult} [result] Deprecated */ Ray.prototype.intersectBodies = function (bodies, result) { - this._updateDirection(); - var direction = this._direction; - - if(result instanceof RaycastResult){ - result.reset(); + if(result){ + this.result = result; + this._updateDirection(); } - for ( var i = 0, l = bodies.length; i < l; i ++ ) { - this.intersectBody(bodies[i], result, direction); + for ( var i = 0, l = bodies.length; !this.result._shouldStop && i < l; i ++ ) { + this.intersectBody(bodies[i]); } }; +/** + * Updates the _direction vector. + * @private + * @method _updateDirection + */ Ray.prototype._updateDirection = function(){ this.to.vsub(this.from, this._direction); this._direction.normalize(); @@ -327,21 +373,21 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectShape = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectShape = function(shape, quat, position, body){ var from = this.from; + // Checking boundingSphere - var distance = distanceFromIntersection(from, direction, position); + var distance = distanceFromIntersection(from, this._direction, position); if ( distance > shape.boundingSphereRadius ) { - return result; + return; } - this[shape.type](shape, quat, position, body, direction, result); - - return result; + var intersectMethod = this[shape.type]; + if(intersectMethod){ + intersectMethod.call(this, shape, quat, position, body); + } }; var vector = new Vec3(); @@ -362,11 +408,9 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectBox = function(shape, quat, position, body, direction, result){ - return this.intersectConvex(shape.convexPolyhedronRepresentation, quat, position, body, direction, result); +Ray.prototype.intersectBox = function(shape, quat, position, body){ + return this.intersectConvex(shape.convexPolyhedronRepresentation, quat, position, body); }; Ray.prototype[Shape.types.BOX] = Ray.prototype.intersectBox; @@ -377,12 +421,11 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectPlane = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectPlane = function(shape, quat, position, body){ var from = this.from; var to = this.to; + var direction = this._direction; // Get plane normal var worldNormal = new Vec3(0, 0, 1); @@ -396,18 +439,18 @@

    File: src/collision/Ray.js

    if(planeToFrom * planeToTo > 0){ // "from" and "to" are on the same side of the plane... bail out - return result; + return; } if(from.distanceTo(to) < planeToFrom){ - return result; + return; } var n_dot_dir = worldNormal.dot(direction); if (Math.abs(n_dot_dir) < this.precision) { // No intersection - return result; + return; } var planePointToFrom = new Vec3(); @@ -419,16 +462,12 @@

    File: src/collision/Ray.js

    direction.scale(t, dir_scaled_with_t); from.vadd(dir_scaled_with_t, hitPointWorld); - if(this.reportIntersection(worldNormal, hitPointWorld, shape, body, result)){ - return result; - } - - return result; + this.reportIntersection(worldNormal, hitPointWorld, shape, body, -1); }; Ray.prototype[Shape.types.PLANE] = Ray.prototype.intersectPlane; /** - * Get the AABB of the ray. + * Get the world AABB of the ray. * @method getAABB * @param {AABB} aabb */ @@ -454,10 +493,8 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectHeightfield = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectHeightfield = function(shape, quat, position, body){ var data = shape.data, w = shape.elementSize, worldPillarOffset = new Vec3(); @@ -490,7 +527,7 @@

    File: src/collision/Ray.js

    } if(iMinX === null){ - return result; + return; } var minMax = []; @@ -509,22 +546,31 @@

    File: src/collision/Ray.js

    for(var i = iMinX; i <= iMaxX; i++){ for(var j = iMinY; j <= iMaxY; j++){ + if(this.result._shouldStop){ + return; + } + // Lower triangle shape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset); - this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, direction, result, intersectConvexOptions); + this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, intersectConvexOptions); + + if(this.result._shouldStop){ + return; + } // Upper triangle shape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset); - this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, direction, result, intersectConvexOptions); + this.intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, intersectConvexOptions); } } - - return result; }; Ray.prototype[Shape.types.HEIGHTFIELD] = Ray.prototype.intersectHeightfield; +var Ray_intersectSphere_intersectionPoint = new Vec3(); +var Ray_intersectSphere_normal = new Vec3(); + /** * @method intersectSphere * @private @@ -532,10 +578,8 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result */ -Ray.prototype.intersectSphere = function(shape, quat, position, body, direction, result){ +Ray.prototype.intersectSphere = function(shape, quat, position, body){ var from = this.from, to = this.to, r = shape.radius; @@ -546,45 +590,44 @@

    File: src/collision/Ray.js

    var delta = Math.pow(b, 2) - 4 * a * c; + var intersectionPoint = Ray_intersectSphere_intersectionPoint; + var normal = Ray_intersectSphere_normal; + if(delta < 0){ // No intersection - return result; + return; } else if(delta === 0){ // single intersection point - var intersectionPoint = new Vec3(); from.lerp(to, delta, intersectionPoint); - var normal = new Vec3(); intersectionPoint.vsub(position, normal); normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; - } + this.reportIntersection(normal, intersectionPoint, shape, body, -1); + } else { var d1 = (- b - Math.sqrt(delta)) / (2 * a); var d2 = (- b + Math.sqrt(delta)) / (2 * a); - var intersectionPoint = new Vec3(); - from.lerp(to, d1, intersectionPoint); - var normal = new Vec3(); - intersectionPoint.vsub(position, normal); - normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; + if(d1 >= 0 && d1 <= 1){ + from.lerp(to, d1, intersectionPoint); + intersectionPoint.vsub(position, normal); + normal.normalize(); + this.reportIntersection(normal, intersectionPoint, shape, body, -1); } - from.lerp(to, d2, intersectionPoint); - var normal = new Vec3(); - intersectionPoint.vsub(position, normal); - normal.normalize(); - if(this.reportIntersection(normal, intersectionPoint, shape, body, result)){ - return result; + if(this.result._shouldStop){ + return; } - } - return result; + if(d2 >= 0 && d2 <= 1){ + from.lerp(to, d2, intersectionPoint); + intersectionPoint.vsub(position, normal); + normal.normalize(); + this.reportIntersection(normal, intersectionPoint, shape, body, -1); + } + } }; Ray.prototype[Shape.types.SPHERE] = Ray.prototype.intersectSphere; @@ -601,12 +644,16 @@

    File: src/collision/Ray.js

    * @param {Quaternion} quat * @param {Vec3} position * @param {Body} body - * @param {Vec3} direction - * @param {RaycastResult} result * @param {object} [options] * @param {array} [options.faceList] */ -Ray.prototype.intersectConvex = function intersectConvex(shape, quat, position, body, direction, result, options){ +Ray.prototype.intersectConvex = function intersectConvex( + shape, + quat, + position, + body, + options +){ var minDistNormal = intersectConvex_minDistNormal; var normal = intersectConvex_normal; var vector = intersectConvex_vector; @@ -617,16 +664,17 @@

    File: src/collision/Ray.js

    var faces = shape.faces, vertices = shape.vertices, normals = shape.faceNormals; + var direction = this._direction; var from = this.from; var to = this.to; var fromToDistance = from.distanceTo(to); - var reportClosest = result instanceof RaycastResult; var minDist = -1; var Nfaces = faceList ? faceList.length : faces.length; + var result = this.result; - for (var j = 0; j < Nfaces; j++) { + for (var j = 0; !result._shouldStop && j < Nfaces; j++) { var fi = faceList ? faceList[j] : j; var face = faces[fi]; @@ -664,49 +712,163 @@

    File: src/collision/Ray.js

    continue; } - if (dot < 0) { - - // Intersection point is from + direction * scalar - direction.mult(scalar,intersectPoint); - intersectPoint.vadd(from,intersectPoint); - - // a is the point we compare points b and c with. - a.copy(vertices[face[0]]); - q.vmult(a,a); - x.vadd(a,a); - - for(var i = 1; i < face.length - 1; i++){ - // Transform 3 vertices to world coords - b.copy(vertices[face[i]]); - c.copy(vertices[face[i+1]]); - q.vmult(b,b); - q.vmult(c,c); - x.vadd(b,b); - x.vadd(c,c); - - var distance = intersectPoint.distanceTo(from); - - if(!pointInTriangle(intersectPoint, a, b, c) || distance > fromToDistance){ - continue; - } - - if(minDist === -1 || distance < minDist){ - minDist = distance; - minDistNormal.copy(normal); - minDistIntersect.copy(intersectPoint); - } + // if (dot < 0) { + + // Intersection point is from + direction * scalar + direction.mult(scalar,intersectPoint); + intersectPoint.vadd(from,intersectPoint); + + // a is the point we compare points b and c with. + a.copy(vertices[face[0]]); + q.vmult(a,a); + x.vadd(a,a); + + for(var i = 1; !result._shouldStop && i < face.length - 1; i++){ + // Transform 3 vertices to world coords + b.copy(vertices[face[i]]); + c.copy(vertices[face[i+1]]); + q.vmult(b,b); + q.vmult(c,c); + x.vadd(b,b); + x.vadd(c,c); + + var distance = intersectPoint.distanceTo(from); + + if(!(pointInTriangle(intersectPoint, a, b, c) || pointInTriangle(intersectPoint, b, a, c)) || distance > fromToDistance){ + continue; } + + this.reportIntersection(normal, intersectPoint, shape, body, fi); } + // } } +}; +Ray.prototype[Shape.types.CONVEXPOLYHEDRON] = Ray.prototype.intersectConvex; - if(minDist !== -1 && this.reportIntersection(minDistNormal, minDistIntersect, shape, body, result)){ - return result; - } +var intersectTrimesh_normal = new Vec3(); +var intersectTrimesh_localDirection = new Vec3(); +var intersectTrimesh_localFrom = new Vec3(); +var intersectTrimesh_localTo = new Vec3(); +var intersectTrimesh_worldNormal = new Vec3(); +var intersectTrimesh_worldIntersectPoint = new Vec3(); +var intersectTrimesh_localAABB = new AABB(); +var intersectTrimesh_triangles = []; +var intersectTrimesh_treeTransform = new Transform(); + +/** + * @method intersectTrimesh + * @private + * @param {Shape} shape + * @param {Quaternion} quat + * @param {Vec3} position + * @param {Body} body + * @param {object} [options] + * @todo Optimize by transforming the world to local space first. + * @todo Use Octree lookup + */ +Ray.prototype.intersectTrimesh = function intersectTrimesh( + mesh, + quat, + position, + body, + options +){ + var normal = intersectTrimesh_normal; + var triangles = intersectTrimesh_triangles; + var treeTransform = intersectTrimesh_treeTransform; + var minDistNormal = intersectConvex_minDistNormal; + var vector = intersectConvex_vector; + var minDistIntersect = intersectConvex_minDistIntersect; + var localAABB = intersectTrimesh_localAABB; + var localDirection = intersectTrimesh_localDirection; + var localFrom = intersectTrimesh_localFrom; + var localTo = intersectTrimesh_localTo; + var worldIntersectPoint = intersectTrimesh_worldIntersectPoint; + var worldNormal = intersectTrimesh_worldNormal; + var faceList = (options && options.faceList) || null; + + // Checking faces + var indices = mesh.indices, + vertices = mesh.vertices, + normals = mesh.faceNormals; + + var from = this.from; + var to = this.to; + var direction = this._direction; + + var minDist = -1; + treeTransform.position.copy(position); + treeTransform.quaternion.copy(quat); + + // Transform ray to local space! + Transform.vectorToLocalFrame(position, quat, direction, localDirection); + //body.vectorToLocalFrame(direction, localDirection); + Transform.pointToLocalFrame(position, quat, from, localFrom); + //body.pointToLocalFrame(from, localFrom); + Transform.pointToLocalFrame(position, quat, to, localTo); + //body.pointToLocalFrame(to, localTo); + var fromToDistanceSquared = localFrom.distanceSquared(localTo); + + mesh.tree.rayQuery(this, treeTransform, triangles); + + for (var i = 0, N = triangles.length; !this.result._shouldStop && i !== N; i++) { + var trianglesIndex = triangles[i]; + + mesh.getNormal(trianglesIndex, normal); + + // determine if ray intersects the plane of the face + // note: this works regardless of the direction of the face normal - return result; + // Get plane point in world coordinates... + mesh.getVertex(indices[trianglesIndex * 3], a); + + // ...but make it relative to the ray from. We'll fix this later. + a.vsub(localFrom,vector); + + // Get plane normal + // quat.vmult(normal, normal); + + // If this dot product is negative, we have something interesting + var dot = localDirection.dot(normal); + + // Bail out if ray and plane are parallel + // if (Math.abs( dot ) < this.precision){ + // continue; + // } + + // calc distance to plane + var scalar = normal.dot(vector) / dot; + + // if negative distance, then plane is behind ray + if (scalar < 0){ + continue; + } + + // Intersection point is from + direction * scalar + localDirection.scale(scalar,intersectPoint); + intersectPoint.vadd(localFrom,intersectPoint); + + // Get triangle vertices + mesh.getVertex(indices[trianglesIndex * 3 + 1], b); + mesh.getVertex(indices[trianglesIndex * 3 + 2], c); + + var squaredDistance = intersectPoint.distanceSquared(localFrom); + + if(!(pointInTriangle(intersectPoint, b, a, c) || pointInTriangle(intersectPoint, a, b, c)) || squaredDistance > fromToDistanceSquared){ + continue; + } + + // transform intersectpoint and normal to world + Transform.vectorToWorldFrame(quat, normal, worldNormal); + //body.vectorToWorldFrame(normal, worldNormal); + Transform.pointToWorldFrame(position, quat, intersectPoint, worldIntersectPoint); + //body.pointToWorldFrame(intersectPoint, worldIntersectPoint); + this.reportIntersection(worldNormal, worldIntersectPoint, mesh, body, trianglesIndex); + } + triangles.length = 0; }; +Ray.prototype[Shape.types.TRIMESH] = Ray.prototype.intersectTrimesh; -Ray.prototype[Shape.types.CONVEXPOLYHEDRON] = Ray.prototype.intersectConvex; /** * @method reportIntersection @@ -715,17 +877,25 @@

    File: src/collision/Ray.js

    * @param {Vec3} hitPointWorld * @param {Shape} shape * @param {Body} body - * @param {RaycastResult} result * @return {boolean} True if the intersections should continue */ -Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, result){ +Ray.prototype.reportIntersection = function(normal, hitPointWorld, shape, body, hitFaceIndex){ var from = this.from; var to = this.to; var distance = from.distanceTo(hitPointWorld); + var result = this.result; + + // Skip back faces? + if(this.skipBackfaces && normal.dot(this._direction) > 0){ + return; + } - if(!(result instanceof RaycastResult)){ - // Got a callback - tmpRaycastResult.set( + result.hitFaceIndex = typeof(hitFaceIndex) !== 'undefined' ? hitFaceIndex : -1; + + switch(this.mode){ + case Ray.ALL: + this.hasHit = true; + result.set( from, to, normal, @@ -734,15 +904,15 @@

    File: src/collision/Ray.js

    body, distance ); - tmpRaycastResult.hasHit = true; - result(tmpRaycastResult); - - return true; + result.hasHit = true; + this.callback(result); + break; - } else { + case Ray.CLOSEST: - // Store if closer than current cloest + // Store if closer than current closest if(distance < result.distance || !result.hasHit){ + this.hasHit = true; result.hasHit = true; result.set( from, @@ -754,8 +924,24 @@

    File: src/collision/Ray.js

    distance ); } + break; + + case Ray.ANY: - return false; + // Report and stop. + this.hasHit = true; + result.hasHit = true; + result.set( + from, + to, + normal, + hitPointWorld, + shape, + body, + distance + ); + result._shouldStop = true; + break; } }; @@ -765,7 +951,7 @@

    File: src/collision/Ray.js

    // v0 is vector from from to position position.vsub(from,v0); - var dot = v0.dot( direction ); + var dot = v0.dot(direction); // intersect = direction*dot + from direction.mult(dot,intersect); @@ -779,7 +965,6 @@

    File: src/collision/Ray.js

    -
    diff --git a/docs/files/src_collision_RaycastResult.js.html b/docs/files/src_collision_RaycastResult.js.html index b56852b24..df09646ee 100644 --- a/docs/files/src_collision_RaycastResult.js.html +++ b/docs/files/src_collision_RaycastResult.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/RaycastResult.js

    +

    File: src/collision/RaycastResult.js

    @@ -230,11 +181,27 @@ 

    File: src/collision/RaycastResult.js

    */ this.body = null; + /** + * The index of the hit triangle, if the hit shape was a trimesh. + * @property {number} hitFaceIndex + * @default -1 + */ + this.hitFaceIndex = -1; + /** * Distance to the hit. Will be set to -1 if there was no hit. * @property {number} distance + * @default -1 */ this.distance = -1; + + /** + * If the ray should stop traversing the bodies. + * @private + * @property {Boolean} _shouldStop + * @default false + */ + this._shouldStop = false; } /** @@ -249,7 +216,16 @@

    File: src/collision/RaycastResult.js

    this.hasHit = false; this.shape = null; this.body = null; + this.hitFaceIndex = -1; this.distance = -1; + this._shouldStop = false; +}; + +/** + * @method abort + */ +RaycastResult.prototype.abort = function(){ + this._shouldStop = true; }; /** @@ -281,7 +257,6 @@

    File: src/collision/RaycastResult.js

    };
    -
    diff --git a/docs/files/src_collision_SAPBroadphase.js.html b/docs/files/src_collision_SAPBroadphase.js.html index cd13bb901..4179038bb 100644 --- a/docs/files/src_collision_SAPBroadphase.js.html +++ b/docs/files/src_collision_SAPBroadphase.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/collision/SAPBroadphase.js

    +

    File: src/collision/SAPBroadphase.js

    @@ -395,14 +346,21 @@ 

    File: src/collision/SAPBroadphase.js

    * @return {Boolean} */ SAPBroadphase.checkBounds = function(bi, bj, axisIndex){ - var axis; - if(axisIndex === 0){ axis = 'x'; } - if(axisIndex === 1){ axis = 'y'; } - if(axisIndex === 2){ axis = 'z'; } + var biPos; + var bjPos; - var biPos = bi.position[axis], - ri = bi.boundingRadius, - bjPos = bj.position[axis], + if(axisIndex === 0){ + biPos = bi.position.x; + bjPos = bj.position.x; + } else if(axisIndex === 1){ + biPos = bi.position.y; + bjPos = bj.position.y; + } else if(axisIndex === 2){ + biPos = bi.position.z; + bjPos = bj.position.z; + } + + var ri = bi.boundingRadius, rj = bj.boundingRadius, boundA1 = biPos - ri, boundA2 = biPos + ri, @@ -500,7 +458,6 @@

    File: src/collision/SAPBroadphase.js

    };
    -
    diff --git a/docs/files/src_constraints_ConeTwistConstraint.js.html b/docs/files/src_constraints_ConeTwistConstraint.js.html new file mode 100644 index 000000000..1f2199226 --- /dev/null +++ b/docs/files/src_constraints_ConeTwistConstraint.js.html @@ -0,0 +1,243 @@ + + + + + src/constraints/ConeTwistConstraint.js - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/constraints/ConeTwistConstraint.js

    + +
    +
    +module.exports = ConeTwistConstraint;
    +
    +var Constraint = require('./Constraint');
    +var PointToPointConstraint = require('./PointToPointConstraint');
    +var ConeEquation = require('../equations/ConeEquation');
    +var RotationalEquation = require('../equations/RotationalEquation');
    +var ContactEquation = require('../equations/ContactEquation');
    +var Vec3 = require('../math/Vec3');
    +
    +/**
    + * @class ConeTwistConstraint
    + * @constructor
    + * @author schteppe
    + * @param {Body} bodyA
    + * @param {Body} bodyB
    + * @param {object} [options]
    + * @param {Vec3} [options.pivotA]
    + * @param {Vec3} [options.pivotB]
    + * @param {Vec3} [options.axisA]
    + * @param {Vec3} [options.axisB]
    + * @param {Number} [options.maxForce=1e6]
    + * @extends PointToPointConstraint
    + */
    +function ConeTwistConstraint(bodyA, bodyB, options){
    +    options = options || {};
    +    var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6;
    +
    +    // Set pivot point in between
    +    var pivotA = options.pivotA ? options.pivotA.clone() : new Vec3();
    +    var pivotB = options.pivotB ? options.pivotB.clone() : new Vec3();
    +    this.axisA = options.axisA ? options.axisA.clone() : new Vec3();
    +    this.axisB = options.axisB ? options.axisB.clone() : new Vec3();
    +
    +    PointToPointConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce);
    +
    +    this.collideConnected = !!options.collideConnected;
    +
    +    this.angle = typeof(options.angle) !== 'undefined' ? options.angle : 0;
    +
    +    /**
    +     * @property {ConeEquation} coneEquation
    +     */
    +    var c = this.coneEquation = new ConeEquation(bodyA,bodyB,options);
    +
    +    /**
    +     * @property {RotationalEquation} twistEquation
    +     */
    +    var t = this.twistEquation = new RotationalEquation(bodyA,bodyB,options);
    +    this.twistAngle = typeof(options.twistAngle) !== 'undefined' ? options.twistAngle : 0;
    +
    +    // Make the cone equation push the bodies toward the cone axis, not outward
    +    c.maxForce = 0;
    +    c.minForce = -maxForce;
    +
    +    // Make the twist equation add torque toward the initial position
    +    t.maxForce = 0;
    +    t.minForce = -maxForce;
    +
    +    this.equations.push(c, t);
    +}
    +ConeTwistConstraint.prototype = new PointToPointConstraint();
    +ConeTwistConstraint.constructor = ConeTwistConstraint;
    +
    +var ConeTwistConstraint_update_tmpVec1 = new Vec3();
    +var ConeTwistConstraint_update_tmpVec2 = new Vec3();
    +
    +ConeTwistConstraint.prototype.update = function(){
    +    var bodyA = this.bodyA,
    +        bodyB = this.bodyB,
    +        cone = this.coneEquation,
    +        twist = this.twistEquation;
    +
    +    PointToPointConstraint.prototype.update.call(this);
    +
    +    // Update the axes to the cone constraint
    +    bodyA.vectorToWorldFrame(this.axisA, cone.axisA);
    +    bodyB.vectorToWorldFrame(this.axisB, cone.axisB);
    +
    +    // Update the world axes in the twist constraint
    +    this.axisA.tangents(twist.axisA, twist.axisA);
    +    bodyA.vectorToWorldFrame(twist.axisA, twist.axisA);
    +
    +    this.axisB.tangents(twist.axisB, twist.axisB);
    +    bodyB.vectorToWorldFrame(twist.axisB, twist.axisB);
    +
    +    cone.angle = this.angle;
    +    twist.maxAngle = this.twistAngle;
    +};
    +
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_constraints_Constraint.js.html b/docs/files/src_constraints_Constraint.js.html index 151a62778..1a1908e3a 100644 --- a/docs/files/src_constraints_Constraint.js.html +++ b/docs/files/src_constraints_Constraint.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/constraints/Constraint.js

    +

    File: src/constraints/Constraint.js

    @@ -243,17 +194,39 @@ 

    File: src/constraints/Constraint.js

    } /** + * Update all the equations with data. * @method update */ Constraint.prototype.update = function(){ throw new Error("method update() not implmemented in this Constraint subclass!"); }; +/** + * Enables all equations in the constraint. + * @method enable + */ +Constraint.prototype.enable = function(){ + var eqs = this.equations; + for(var i=0; i<eqs.length; i++){ + eqs[i].enabled = true; + } +}; + +/** + * Disables all equations in the constraint. + * @method disable + */ +Constraint.prototype.disable = function(){ + var eqs = this.equations; + for(var i=0; i<eqs.length; i++){ + eqs[i].enabled = false; + } +}; + Constraint.idCounter = 0;
    -
    diff --git a/docs/files/src_constraints_DistanceConstraint.js.html b/docs/files/src_constraints_DistanceConstraint.js.html index 4a4c5f765..3e2710a3e 100644 --- a/docs/files/src_constraints_DistanceConstraint.js.html +++ b/docs/files/src_constraints_DistanceConstraint.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/constraints/DistanceConstraint.js

    +

    File: src/constraints/DistanceConstraint.js

    @@ -188,48 +139,58 @@ 

    File: src/constraints/DistanceConstraint.js

    var ContactEquation = require('../equations/ContactEquation'); /** - * Constrains two bodies to be at a constant distance from each other. + * Constrains two bodies to be at a constant distance from each others center of mass. * @class DistanceConstraint * @constructor * @author schteppe * @param {Body} bodyA * @param {Body} bodyB - * @param {Number} distance - * @param {Number} maxForce + * @param {Number} [distance] The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB + * @param {Number} [maxForce=1e6] * @extends Constraint */ function DistanceConstraint(bodyA,bodyB,distance,maxForce){ Constraint.call(this,bodyA,bodyB); - if(typeof(maxForce)==="undefined" ) { - maxForce = 1e6; + if(typeof(distance)==="undefined") { + distance = bodyA.position.distanceTo(bodyB.position); } - // Equations to be fed to the solver - var eqs = this.equations = [ - new ContactEquation(bodyA,bodyB), // Just in the normal direction - ]; + if(typeof(maxForce)==="undefined") { + maxForce = 1e6; + } - var normal = eqs[0]; + /** + * @property {number} distance + */ + this.distance = distance; - normal.minForce = -maxForce; - normal.maxForce = maxForce; + /** + * @property {ContactEquation} distanceEquation + */ + var eq = this.distanceEquation = new ContactEquation(bodyA, bodyB); + this.equations.push(eq); - // Update - this.update = function(){ - bodyB.position.vsub(bodyA.position,normal.ni); - normal.ni.normalize(); - /*bodyA.quaternion.vmult(pivotA,normal.ri); - bodyB.quaternion.vmult(pivotB,normal.rj);*/ - normal.ni.mult( distance*0.5,normal.ri); - normal.ni.mult( -distance*0.5,normal.rj); - }; + // Make it bidirectional + eq.minForce = -maxForce; + eq.maxForce = maxForce; } DistanceConstraint.prototype = new Constraint(); +DistanceConstraint.prototype.update = function(){ + var bodyA = this.bodyA; + var bodyB = this.bodyB; + var eq = this.distanceEquation; + var halfDist = this.distance * 0.5; + var normal = eq.ni; + + bodyB.position.vsub(bodyA.position, normal); + normal.normalize(); + normal.mult(halfDist, eq.ri); + normal.mult(-halfDist, eq.rj); +};
    -
    diff --git a/docs/files/src_constraints_HingeConstraint.js.html b/docs/files/src_constraints_HingeConstraint.js.html index cd514dd1a..f2e89f72a 100644 --- a/docs/files/src_constraints_HingeConstraint.js.html +++ b/docs/files/src_constraints_HingeConstraint.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,336 +25,251 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/constraints/HingeConstraint.js

    +

    File: src/constraints/HingeConstraint.js

     module.exports = HingeConstraint;
     
     var Constraint = require('./Constraint');
    +var PointToPointConstraint = require('./PointToPointConstraint');
     var RotationalEquation = require('../equations/RotationalEquation');
     var RotationalMotorEquation = require('../equations/RotationalMotorEquation');
     var ContactEquation = require('../equations/ContactEquation');
     var Vec3 = require('../math/Vec3');
     
     /**
    - * Hinge constraint. Tries to keep the local body axes equal.
    + * Hinge constraint. Think of it as a door hinge. It tries to keep the door in the correct place and with the correct orientation.
      * @class HingeConstraint
      * @constructor
      * @author schteppe
    - * @param {RigidBody} bodyA
    - * @param {RigidBody} bodyB
    + * @param {Body} bodyA
    + * @param {Body} bodyB
      * @param {object} [options]
      * @param {Vec3} [options.pivotA] A point defined locally in bodyA. This defines the offset of axisA.
    - * @param {Vec3} [options.axisA] an axis that bodyA can rotate around.
    + * @param {Vec3} [options.axisA] An axis that bodyA can rotate around, defined locally in bodyA.
      * @param {Vec3} [options.pivotB]
      * @param {Vec3} [options.axisB]
      * @param {Number} [options.maxForce=1e6]
    - * @extends Constraint
    + * @extends PointToPointConstraint
      */
    -function HingeConstraint(bodyA, bodyB, options){ // bodyA, pivotA, axisA, bodyB, pivotB, axisB, maxForce
    -    Constraint.call(this, bodyA, bodyB, options);
    -
    +function HingeConstraint(bodyA, bodyB, options){
    +    options = options || {};
         var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6;
    -
    -    // TODO: use a clever default setup... how?
    -    var pivotA = this.pivotA = typeof(options.pivotA) !== 'undefined' ? options.pivotA.clone() : new Vec3();
    -    var pivotB = this.pivotB = typeof(options.pivotB) !== 'undefined' ? options.pivotB.clone() : new Vec3();
    -    var axisA = this.axisA = typeof(options.axisA) !== 'undefined' ? options.axisA.clone() : new Vec3(1,0,0);
    -    var axisB = this.axisB = typeof(options.axisB) !== 'undefined' ? options.axisB.clone() : new Vec3(1,0,0);
    -
    -    var that = this;
    +    var pivotA = options.pivotA ? options.pivotA.clone() : new Vec3();
    +    var pivotB = options.pivotB ? options.pivotB.clone() : new Vec3();
    +
    +    PointToPointConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce);
    +
    +    /**
    +     * Rotation axis, defined locally in bodyA.
    +     * @property {Vec3} axisA
    +     */
    +    var axisA = this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1,0,0);
    +    axisA.normalize();
    +
    +    /**
    +     * Rotation axis, defined locally in bodyB.
    +     * @property {Vec3} axisB
    +     */
    +    var axisB = this.axisB = options.axisB ? options.axisB.clone() : new Vec3(1,0,0);
    +    axisB.normalize();
    +
    +    /**
    +     * @property {RotationalEquation} rotationalEquation1
    +     */
    +    var r1 = this.rotationalEquation1 = new RotationalEquation(bodyA,bodyB,options);
    +
    +    /**
    +     * @property {RotationalEquation} rotationalEquation2
    +     */
    +    var r2 = this.rotationalEquation2 = new RotationalEquation(bodyA,bodyB,options);
    +
    +    /**
    +     * @property {RotationalMotorEquation} motorEquation
    +     */
    +    var motor = this.motorEquation = new RotationalMotorEquation(bodyA,bodyB,maxForce);
    +    motor.enabled = false; // Not enabled by default
     
         // Equations to be fed to the solver
    -    var eqs = this.equations = [
    -        new RotationalEquation(bodyA,bodyB), // rotational1
    -        new RotationalEquation(bodyA,bodyB), // rotational2
    -        new ContactEquation(bodyA,bodyB),    // p2pNormal
    -        new ContactEquation(bodyA,bodyB),    // p2pTangent1
    -        new ContactEquation(bodyA,bodyB),    // p2pTangent2
    -    ];
    -
    -    var r1 =        this.getRotationalEquation1();
    -    var r2 =        this.getRotationalEquation2();
    -    var normal =    this.getPointToPointEquation1();
    -    var t1 =        this.getPointToPointEquation2();
    -    var t2 =        this.getPointToPointEquation3();
    -    var motor; // not activated by default
    -
    -    t1.minForce = t2.minForce = normal.minForce = -maxForce;
    -    t1.maxForce = t2.maxForce = normal.maxForce =  maxForce;
    -
    -    var unitPivotA = pivotA.unit();
    -    var unitPivotB = pivotB.unit();
    -
    -    var axisA_x_pivotA = this.axisA_x_pivotA = new Vec3();
    -    var axisA_x_axisA_x_pivotA = this.axisA_x_axisA_x_pivotA = new Vec3();
    -    var axisB_x_pivotB = this.axisB_x_pivotB = new Vec3();
    -    axisA.cross(unitPivotA,axisA_x_pivotA);
    -    if(axisA_x_pivotA.norm2() < 0.001){ // pivotA is along the same line as axisA
    -        unitPivotA.tangents(axisA_x_pivotA,axisA_x_pivotA);
    -    }
    -    axisA.cross(axisA_x_pivotA,axisA_x_axisA_x_pivotA);
    -    axisB.cross(unitPivotB,axisB_x_pivotB);
    -    if(axisB_x_pivotB.norm2() < 0.001){ // pivotB is along the same line as axisB
    -        axisB.tangents(axisB_x_pivotB,axisB_x_pivotB);
    -    }
    -
    -    axisA_x_pivotA.normalize();
    -    axisB_x_pivotB.normalize();
    -
    -    // Motor stuff
    -    this.motorEnabled = false;
    -    this.motorTargetVelocity = 0;
    -    this.motorMinForce = -maxForce;
    -    this.motorMaxForce = maxForce;
    -    this.motorEquation = new RotationalMotorEquation(bodyA,bodyB,maxForce);
    +    this.equations.push(
    +        r1, // rotational1
    +        r2, // rotational2
    +        motor
    +    );
     }
    -HingeConstraint.prototype = new Constraint();
    +HingeConstraint.prototype = new PointToPointConstraint();
    +HingeConstraint.constructor = HingeConstraint;
     
     /**
      * @method enableMotor
      */
     HingeConstraint.prototype.enableMotor = function(){
    -    if(!this.motorEnabled){
    -        this.equations.push(this.motorEquation);
    -        this.motorEnabled = true;
    -    }
    +    this.motorEquation.enabled = true;
     };
     
     /**
      * @method disableMotor
      */
     HingeConstraint.prototype.disableMotor = function(){
    -    if(this.motorEnabled){
    -        this.motorEnabled = false;
    -        this.equations.pop();
    -    }
    +    this.motorEquation.enabled = false;
     };
     
    +/**
    + * @method setMotorSpeed
    + * @param {number} speed
    + */
    +HingeConstraint.prototype.setMotorSpeed = function(speed){
    +    this.motorEquation.targetVelocity = speed;
    +};
    +
    +/**
    + * @method setMotorMaxForce
    + * @param {number} maxForce
    + */
    +HingeConstraint.prototype.setMotorMaxForce = function(maxForce){
    +    this.motorEquation.maxForce = maxForce;
    +    this.motorEquation.minForce = -maxForce;
    +};
    +
    +var HingeConstraint_update_tmpVec1 = new Vec3();
    +var HingeConstraint_update_tmpVec2 = new Vec3();
    +
     HingeConstraint.prototype.update = function(){
         var bodyA = this.bodyA,
             bodyB = this.bodyB,
    -        eqs = this.equations,
             motor = this.motorEquation,
    -        r1 = eqs[0],
    -        r2 = eqs[1],
    -        normal = eqs[2],
    -        t1 = eqs[3],
    -        t2 = eqs[4];
    -    var axisA_x_pivotA = this.axisA_x_pivotA;
    +        r1 = this.rotationalEquation1,
    +        r2 = this.rotationalEquation2,
    +        worldAxisA = HingeConstraint_update_tmpVec1,
    +        worldAxisB = HingeConstraint_update_tmpVec2;
    +
         var axisA = this.axisA;
         var axisB = this.axisB;
    -    var pivotA = this.pivotA;
    -    var pivotB = this.pivotB;
    -    var axisA_x_axisA_x_pivotA = this.axisA_x_axisA_x_pivotA;
    -    var axisB_x_pivotB = this.axisB_x_pivotB;
    -
    -    // Update world positions of pivots
    -    /*
    -    bodyB.position.vsub(bodyA.position,normal.ni);
    -    normal.ni.normalize();
    -    */
    -    normal.ni.set(1,0,0);
    -    t1.ni.set(0,1,0);
    -    t2.ni.set(0,0,1);
    -    bodyA.quaternion.vmult(this.pivotA,normal.ri);
    -    bodyB.quaternion.vmult(this.pivotB,normal.rj);
    -
    -    //normal.ni.tangents(t1.ni,t2.ni);
    -    t1.ri.copy(normal.ri);
    -    t1.rj.copy(normal.rj);
    -    t2.ri.copy(normal.ri);
    -    t2.rj.copy(normal.rj);
     
    -    axisA.cross(pivotA, axisA_x_pivotA);
    -    if(axisA_x_pivotA.norm2() < 0.001){ // pivotA is along the same line as axisA
    -        pivotA.tangents(axisA_x_pivotA, axisA_x_pivotA);
    -    }
    -    axisA.cross(axisA_x_pivotA, axisA_x_axisA_x_pivotA);
    -    axisB.cross(pivotB, axisB_x_pivotB);
    -    if(axisB_x_pivotB.norm2() < 0.001){ // pivotB is along the same line as axisB
    -        axisB.tangents(axisB_x_pivotB,axisB_x_pivotB);
    -    }
    +    PointToPointConstraint.prototype.update.call(this);
     
    -    axisA_x_pivotA.normalize();
    -    axisB_x_pivotB.normalize();
    +    // Get world axes
    +    bodyA.quaternion.vmult(axisA, worldAxisA);
    +    bodyB.quaternion.vmult(axisB, worldAxisB);
     
    -    // update rotational constraints
    -    bodyA.quaternion.vmult(axisA_x_pivotA, r1.ni);
    -    bodyB.quaternion.vmult(axisB, r1.nj);
    -    bodyA.quaternion.vmult(axisA_x_axisA_x_pivotA, r2.ni);
    -    bodyB.quaternion.vmult(axisB, r2.nj);
    +    worldAxisA.tangents(r1.axisA, r2.axisA);
    +    r1.axisB.copy(worldAxisB);
    +    r2.axisB.copy(worldAxisB);
     
    -    if(this.motorEnabled){
    +    if(this.motorEquation.enabled){
             bodyA.quaternion.vmult(this.axisA, motor.axisA);
             bodyB.quaternion.vmult(this.axisB, motor.axisB);
    -        motor.targetVelocity = this.motorTargetVelocity;
    -        motor.maxForce = this.motorMaxForce;
    -        motor.minForce = this.motorMinForce;
         }
     };
     
    -HingeConstraint.prototype.getRotationalEquation1 =   function(){ return this.equations[0]; };
    -HingeConstraint.prototype.getRotationalEquation2 =   function(){ return this.equations[1]; };
    -HingeConstraint.prototype.getPointToPointEquation1 = function(){ return this.equations[2]; };
    -HingeConstraint.prototype.getPointToPointEquation2 = function(){ return this.equations[3]; };
    -HingeConstraint.prototype.getPointToPointEquation3 = function(){ return this.equations[4]; };
     
         
    -
    diff --git a/docs/files/src_constraints_LockConstraint.js.html b/docs/files/src_constraints_LockConstraint.js.html new file mode 100644 index 000000000..39eff6c47 --- /dev/null +++ b/docs/files/src_constraints_LockConstraint.js.html @@ -0,0 +1,233 @@ + + + + + src/constraints/LockConstraint.js - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/constraints/LockConstraint.js

    + +
    +
    +module.exports = LockConstraint;
    +
    +var Constraint = require('./Constraint');
    +var PointToPointConstraint = require('./PointToPointConstraint');
    +var RotationalEquation = require('../equations/RotationalEquation');
    +var RotationalMotorEquation = require('../equations/RotationalMotorEquation');
    +var ContactEquation = require('../equations/ContactEquation');
    +var Vec3 = require('../math/Vec3');
    +
    +/**
    + * Lock constraint. Will remove all degrees of freedom between the bodies.
    + * @class LockConstraint
    + * @constructor
    + * @author schteppe
    + * @param {Body} bodyA
    + * @param {Body} bodyB
    + * @param {object} [options]
    + * @param {Number} [options.maxForce=1e6]
    + * @extends PointToPointConstraint
    + */
    +function LockConstraint(bodyA, bodyB, options){
    +    options = options || {};
    +    var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6;
    +
    +    // Set pivot point in between
    +    var pivotA = new Vec3();
    +    var pivotB = new Vec3();
    +    var halfWay = new Vec3();
    +    bodyA.position.vadd(bodyB.position, halfWay);
    +    halfWay.scale(0.5, halfWay);
    +    bodyB.pointToLocalFrame(halfWay, pivotB);
    +    bodyA.pointToLocalFrame(halfWay, pivotA);
    +    PointToPointConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce);
    +
    +    /**
    +     * @property {RotationalEquation} rotationalEquation1
    +     */
    +    var r1 = this.rotationalEquation1 = new RotationalEquation(bodyA,bodyB,options);
    +
    +    /**
    +     * @property {RotationalEquation} rotationalEquation2
    +     */
    +    var r2 = this.rotationalEquation2 = new RotationalEquation(bodyA,bodyB,options);
    +
    +    /**
    +     * @property {RotationalEquation} rotationalEquation3
    +     */
    +    var r3 = this.rotationalEquation3 = new RotationalEquation(bodyA,bodyB,options);
    +
    +    this.equations.push(r1, r2, r3);
    +}
    +LockConstraint.prototype = new PointToPointConstraint();
    +LockConstraint.constructor = LockConstraint;
    +
    +var LockConstraint_update_tmpVec1 = new Vec3();
    +var LockConstraint_update_tmpVec2 = new Vec3();
    +
    +LockConstraint.prototype.update = function(){
    +    var bodyA = this.bodyA,
    +        bodyB = this.bodyB,
    +        motor = this.motorEquation,
    +        r1 = this.rotationalEquation1,
    +        r2 = this.rotationalEquation2,
    +        r3 = this.rotationalEquation3,
    +        worldAxisA = LockConstraint_update_tmpVec1,
    +        worldAxisB = LockConstraint_update_tmpVec2;
    +
    +    PointToPointConstraint.prototype.update.call(this);
    +
    +    bodyA.vectorToWorldFrame(Vec3.UNIT_X, r1.axisA);
    +    bodyB.vectorToWorldFrame(Vec3.UNIT_Y, r1.axisB);
    +
    +    bodyA.vectorToWorldFrame(Vec3.UNIT_Y, r2.axisA);
    +    bodyB.vectorToWorldFrame(Vec3.UNIT_Z, r2.axisB);
    +
    +    bodyA.vectorToWorldFrame(Vec3.UNIT_Z, r3.axisA);
    +    bodyB.vectorToWorldFrame(Vec3.UNIT_X, r3.axisB);
    +};
    +
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_constraints_PointToPointConstraint.js.html b/docs/files/src_constraints_PointToPointConstraint.js.html index 6ee59a11a..96d33c8fc 100644 --- a/docs/files/src_constraints_PointToPointConstraint.js.html +++ b/docs/files/src_constraints_PointToPointConstraint.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/constraints/PointToPointConstraint.js

    +

    File: src/constraints/PointToPointConstraint.js

    @@ -186,6 +137,7 @@ 

    File: src/constraints/PointToPointConstraint.js

    var Constraint = require('./Constraint'); var ContactEquation = require('../equations/ContactEquation'); +var Vec3 = require('../math/Vec3'); /** * Connects two bodies at given offset points. @@ -194,7 +146,7 @@

    File: src/constraints/PointToPointConstraint.js

    * @constructor * @param {Body} bodyA * @param {Vec3} pivotA The point relative to the center of mass of bodyA which bodyA is constrained to. - * @param {Body} bodyB Body that will be constrained in a similar way to the same point as bodyA. We will therefore get sort of a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point. + * @param {Body} bodyB Body that will be constrained in a similar way to the same point as bodyA. We will therefore get a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point. * @param {Vec3} pivotB See pivotA. * @param {Number} maxForce The maximum force that should be applied to constrain the bodies. * @@ -215,39 +167,66 @@

    File: src/constraints/PointToPointConstraint.js

    function PointToPointConstraint(bodyA,pivotA,bodyB,pivotB,maxForce){ Constraint.call(this,bodyA,bodyB); - // Equations to be fed to the solver - var eqs = this.equations = [ - new ContactEquation(bodyA,bodyB), // Normal - new ContactEquation(bodyA,bodyB), // Tangent2 - new ContactEquation(bodyA,bodyB), // Tangent2 - ]; + maxForce = typeof(maxForce) !== 'undefined' ? maxForce : 1e6; + + /** + * Pivot, defined locally in bodyA. + * @property {Vec3} pivotA + */ + this.pivotA = pivotA ? pivotA.clone() : new Vec3(); + + /** + * Pivot, defined locally in bodyB. + * @property {Vec3} pivotB + */ + this.pivotB = pivotB ? pivotB.clone() : new Vec3(); - var normal = eqs[0]; - var t1 = eqs[1]; - var t2 = eqs[2]; + /** + * @property {ContactEquation} equationX + */ + var x = this.equationX = new ContactEquation(bodyA,bodyB); - t1.minForce = t2.minForce = normal.minForce = -maxForce; - t1.maxForce = t2.maxForce = normal.maxForce = maxForce; + /** + * @property {ContactEquation} equationY + */ + var y = this.equationY = new ContactEquation(bodyA,bodyB); - // Update - this.update = function(){ - bodyB.position.vsub(bodyA.position,normal.ni); - normal.ni.normalize(); - bodyA.quaternion.vmult(pivotA,normal.ri); - bodyB.quaternion.vmult(pivotB,normal.rj); + /** + * @property {ContactEquation} equationZ + */ + var z = this.equationZ = new ContactEquation(bodyA,bodyB); - normal.ni.tangents(t1.ni,t2.ni); - t1.ri.copy(normal.ri); - t1.rj.copy(normal.rj); - t2.ri.copy(normal.ri); - t2.rj.copy(normal.rj); - }; + // Equations to be fed to the solver + this.equations.push(x, y, z); + + // Make the equations bidirectional + x.minForce = y.minForce = z.minForce = -maxForce; + x.maxForce = y.maxForce = z.maxForce = maxForce; + + x.ni.set(1, 0, 0); + y.ni.set(0, 1, 0); + z.ni.set(0, 0, 1); } PointToPointConstraint.prototype = new Constraint(); +PointToPointConstraint.prototype.update = function(){ + var bodyA = this.bodyA; + var bodyB = this.bodyB; + var x = this.equationX; + var y = this.equationY; + var z = this.equationZ; + + // Rotate the pivots to world space + bodyA.quaternion.vmult(this.pivotA,x.ri); + bodyB.quaternion.vmult(this.pivotB,x.rj); + + y.ri.copy(x.ri); + y.rj.copy(x.rj); + z.ri.copy(x.ri); + z.rj.copy(x.rj); +};
    -
    diff --git a/docs/files/src_demo_Demo.js.html b/docs/files/src_demo_Demo.js.html index e9cd9c671..7485915f7 100644 --- a/docs/files/src_demo_Demo.js.html +++ b/docs/files/src_demo_Demo.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    -
    -
    - -
    -
    -
    -
    - Show: - - - - - - - -
    - -
    -

    File: src/demo/Demo.js

    +

    File: src/demo/Demo.js

    @@ -394,7 +345,7 @@ 

    File: src/demo/Demo.js

    * Add a scene to the demo app * @method addScene * @param {String} title Title of the scene - * @param {Function} A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc. + * @param {Function} initfunc A function that takes one argument, app, and initializes a physics scene. The function runs app.setWorld(body), app.addVisual(body), app.removeVisual(body) etc. */ function addScene(title,initfunc){ if(typeof(title) !== "string"){ @@ -999,6 +950,7 @@

    File: src/demo/Demo.js

    function changeScene(n){ + that.dispatchEvent({ type: 'destroy' }); settings.paused = false; updategui(); buildScene(n); @@ -1064,6 +1016,8 @@

    File: src/demo/Demo.js

    }; } }; +CANNON.Demo.prototype = new CANNON.EventTarget(); +CANNON.Demo.constructor = CANNON.Demo; CANNON.Demo.prototype.setGlobalSpookParams = function(k,d,h){ var world = this.world; @@ -1254,6 +1208,27 @@

    File: src/demo/Demo.js

    mesh = new THREE.Mesh(geometry, this.currentMaterial); break; + case CANNON.Shape.types.TRIMESH: + var geometry = new THREE.Geometry(); + + var v0 = new CANNON.Vec3(); + var v1 = new CANNON.Vec3(); + var v2 = new CANNON.Vec3(); + for (var i = 0; i < shape.indices.length / 3; i++) { + shape.getTriangleVertices(i, v0, v1, v2); + geometry.vertices.push( + new THREE.Vector3(v0.x, v0.y, v0.z), + new THREE.Vector3(v1.x, v1.y, v1.z), + new THREE.Vector3(v2.x, v2.y, v2.z) + ); + var j = geometry.vertices.length - 3; + geometry.faces.push(new THREE.Face3(j, j+1, j+2)); + } + geometry.computeBoundingSphere(); + geometry.computeFaceNormals(); + mesh = new THREE.Mesh(geometry, this.currentMaterial); + break; + default: throw "Visual type not recognized: "+shape.type; } @@ -1286,7 +1261,6 @@

    File: src/demo/Demo.js

    -
    diff --git a/docs/files/src_equations_ConeEquation.js.html b/docs/files/src_equations_ConeEquation.js.html new file mode 100644 index 000000000..5006abcfc --- /dev/null +++ b/docs/files/src_equations_ConeEquation.js.html @@ -0,0 +1,231 @@ + + + + + src/equations/ConeEquation.js - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/equations/ConeEquation.js

    + +
    +
    +module.exports = ConeEquation;
    +
    +var Vec3 = require('../math/Vec3');
    +var Mat3 = require('../math/Mat3');
    +var Equation = require('./Equation');
    +
    +/**
    + * Cone equation. Works to keep the given body world vectors aligned, or tilted within a given angle from each other.
    + * @class ConeEquation
    + * @constructor
    + * @author schteppe
    + * @param {Body} bodyA
    + * @param {Body} bodyB
    + * @param {Vec3} [options.axisA] Local axis in A
    + * @param {Vec3} [options.axisB] Local axis in B
    + * @param {Vec3} [options.angle] The "cone angle" to keep
    + * @param {number} [options.maxForce=1e6]
    + * @extends Equation
    + */
    +function ConeEquation(bodyA, bodyB, options){
    +    options = options || {};
    +    var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6;
    +
    +    Equation.call(this,bodyA,bodyB,-maxForce, maxForce);
    +
    +    this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1, 0, 0);
    +    this.axisB = options.axisB ? options.axisB.clone() : new Vec3(0, 1, 0);
    +
    +    /**
    +     * The cone angle to keep
    +     * @property {number} angle
    +     */
    +    this.angle = typeof(options.angle) !== 'undefined' ? options.angle : 0;
    +}
    +
    +ConeEquation.prototype = new Equation();
    +ConeEquation.prototype.constructor = ConeEquation;
    +
    +var tmpVec1 = new Vec3();
    +var tmpVec2 = new Vec3();
    +
    +ConeEquation.prototype.computeB = function(h){
    +    var a = this.a,
    +        b = this.b,
    +
    +        ni = this.axisA,
    +        nj = this.axisB,
    +
    +        nixnj = tmpVec1,
    +        njxni = tmpVec2,
    +
    +        GA = this.jacobianElementA,
    +        GB = this.jacobianElementB;
    +
    +    // Caluclate cross products
    +    ni.cross(nj, nixnj);
    +    nj.cross(ni, njxni);
    +
    +    // The angle between two vector is:
    +    // cos(theta) = a * b / (length(a) * length(b) = { len(a) = len(b) = 1 } = a * b
    +
    +    // g = a * b
    +    // gdot = (b x a) * wi + (a x b) * wj
    +    // G = [0 bxa 0 axb]
    +    // W = [vi wi vj wj]
    +    GA.rotational.copy(njxni);
    +    GB.rotational.copy(nixnj);
    +
    +    var g = Math.cos(this.angle) - ni.dot(nj),
    +        GW = this.computeGW(),
    +        GiMf = this.computeGiMf();
    +
    +    var B = - g * a - GW * b - h * GiMf;
    +
    +    return B;
    +};
    +
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_equations_ContactEquation.js.html b/docs/files/src_equations_ContactEquation.js.html index 030160a9a..ffeac6af5 100644 --- a/docs/files/src_equations_ContactEquation.js.html +++ b/docs/files/src_equations_ContactEquation.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/equations/ContactEquation.js

    +

    File: src/equations/ContactEquation.js

    @@ -193,12 +144,13 @@ 

    File: src/equations/ContactEquation.js

    * @class ContactEquation * @constructor * @author schteppe - * @param {Body} bj - * @param {Body} bi + * @param {Body} bodyA + * @param {Body} bodyB * @extends Equation */ -function ContactEquation(bi,bj){ - Equation.call(this,bi,bj,0,1e6); +function ContactEquation(bodyA, bodyB, maxForce){ + maxForce = typeof(maxForce) !== 'undefined' ? maxForce : 1e6; + Equation.call(this, bodyA, bodyB, 0, maxForce); /** * @property restitution @@ -218,23 +170,11 @@

    File: src/equations/ContactEquation.js

    */ this.rj = new Vec3(); - this.penetrationVec = new Vec3(); - /** * Contact normal, pointing out of body i. * @property {Vec3} ni */ this.ni = new Vec3(); - - this.rixn = new Vec3(); - this.rjxn = new Vec3(); - - this.invIi = new Mat3(); - this.invIj = new Mat3(); - - // Cache - this.biInvInertiaTimesRixn = new Vec3(); - this.bjInvInertiaTimesRjxn = new Vec3(); } ContactEquation.prototype = new Equation(); @@ -242,7 +182,7 @@

    File: src/equations/ContactEquation.js

    var ContactEquation_computeB_temp1 = new Vec3(); // Temp vectors var ContactEquation_computeB_temp2 = new Vec3(); -var ContactEquation_computeB_zero = new Vec3(); +var ContactEquation_computeB_temp3 = new Vec3(); ContactEquation.prototype.computeB = function(h){ var a = this.a, b = this.b, @@ -250,27 +190,20 @@

    File: src/equations/ContactEquation.js

    bj = this.bj, ri = this.ri, rj = this.rj, - rixn = this.rixn, - rjxn = this.rjxn, - - zero = ContactEquation_computeB_zero, + rixn = ContactEquation_computeB_temp1, + rjxn = ContactEquation_computeB_temp2, vi = bi.velocity, - wi = bi.angularVelocity ? bi.angularVelocity : zero, + wi = bi.angularVelocity, fi = bi.force, - taui = bi.torque ? bi.torque : zero, + taui = bi.torque, vj = bj.velocity, - wj = bj.angularVelocity ? bj.angularVelocity : zero, + wj = bj.angularVelocity, fj = bj.force, - tauj = bj.torque ? bj.torque : zero, + tauj = bj.torque, - penetrationVec = this.penetrationVec, - invMassi = bi.invMass, - invMassj = bj.invMass, - - invIi = this.invIi, - invIj = this.invIj, + penetrationVec = ContactEquation_computeB_temp3, GA = this.jacobianElementA, GB = this.jacobianElementB, @@ -289,123 +222,55 @@

    File: src/equations/ContactEquation.js

    GB.rotational.copy(rjxn); // Calculate the penetration vector - var penetrationVec = this.penetrationVec; - penetrationVec.set(0,0,0); - penetrationVec.vadd(bj.position,penetrationVec); + penetrationVec.copy(bj.position); penetrationVec.vadd(rj,penetrationVec); penetrationVec.vsub(bi.position,penetrationVec); penetrationVec.vsub(ri,penetrationVec); var g = n.dot(penetrationVec); - var invIi_vmult_taui = ContactEquation_computeB_temp1; - var invIj_vmult_tauj = ContactEquation_computeB_temp2; - if(bi.invInertiaWorld){ - bi.invInertiaWorld.vmult(taui,invIi_vmult_taui); - } else { - invIi_vmult_taui.set(0,0,0); - } - if(bj.invInertiaWorld){ - bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj); - } else { - invIj_vmult_tauj.set(0,0,0); - } - // Compute iteration - var ePlusOne = this.restitution+1; - var GW = ePlusOne*vj.dot(n) - ePlusOne*vi.dot(n) + wj.dot(rjxn) - wi.dot(rixn); - var GiMf = this.computeGiMf();//fj.dot(n)*invMassj - fi.dot(n)*invMassi + rjxn.dot(invIj_vmult_tauj) - rixn.dot(invIi_vmult_taui); + var ePlusOne = this.restitution + 1; + var GW = ePlusOne * vj.dot(n) - ePlusOne * vi.dot(n) + wj.dot(rjxn) - wi.dot(rixn); + var GiMf = this.computeGiMf(); var B = - g * a - GW * b - h*GiMf; return B; }; -// Compute C = GMG+eps in the SPOOK equation -/* -var computeC_temp1 = new Vec3(); -var computeC_temp2 = new Vec3(); -ContactEquation.prototype.computeC = function(){ - var bi = this.bi; - var bj = this.bj; - var rixn = this.rixn; - var rjxn = this.rjxn; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - var C = invMassi + invMassj + this.eps; - - var invIi = this.invIi; - var invIj = this.invIj; - - // Compute rxn * I * rxn for each body - if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(rixn, this.biInvInertiaTimesRixn); - if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(rjxn, this.bjInvInertiaTimesRjxn); - - C += this.biInvInertiaTimesRixn.dot(rixn); - C += this.bjInvInertiaTimesRjxn.dot(rjxn); +var ContactEquation_getImpactVelocityAlongNormal_vi = new Vec3(); +var ContactEquation_getImpactVelocityAlongNormal_vj = new Vec3(); +var ContactEquation_getImpactVelocityAlongNormal_xi = new Vec3(); +var ContactEquation_getImpactVelocityAlongNormal_xj = new Vec3(); +var ContactEquation_getImpactVelocityAlongNormal_relVel = new Vec3(); - return C; -}; - -var computeGWlambda_ulambda = new Vec3(); -ContactEquation.prototype.computeGWlambda = function(){ - var bi = this.bi; - var bj = this.bj; - var ulambda = computeGWlambda_ulambda; +/** + * Get the current relative velocity in the contact point. + * @method getImpactVelocityAlongNormal + * @return {number} + */ +ContactEquation.prototype.getImpactVelocityAlongNormal = function(){ + var vi = ContactEquation_getImpactVelocityAlongNormal_vi; + var vj = ContactEquation_getImpactVelocityAlongNormal_vj; + var xi = ContactEquation_getImpactVelocityAlongNormal_xi; + var xj = ContactEquation_getImpactVelocityAlongNormal_xj; + var relVel = ContactEquation_getImpactVelocityAlongNormal_relVel; - var GWlambda = 0.0; + this.bi.position.vadd(this.ri, xi); + this.bj.position.vadd(this.rj, xj); - bj.vlambda.vsub(bi.vlambda, ulambda); - GWlambda += ulambda.dot(this.ni); + this.bi.getVelocityAtWorldPoint(xi, vi); + this.bj.getVelocityAtWorldPoint(xj, vj); - // Angular - if(bi.wlambda){ - GWlambda -= bi.wlambda.dot(this.rixn); - } - if(bj.wlambda){ - GWlambda += bj.wlambda.dot(this.rjxn); - } + vi.vsub(vj, relVel); - return GWlambda; + return this.ni.dot(relVel); }; -var ContactEquation_addToWlambda_temp1 = new Vec3(); -var ContactEquation_addToWlambda_temp2 = new Vec3(); -ContactEquation.prototype.addToWlambda = function(deltalambda){ - var bi = this.bi, - bj = this.bj, - rixn = this.rixn, - rjxn = this.rjxn, - invMassi = bi.invMass, - invMassj = bj.invMass, - n = this.ni, - temp1 = ContactEquation_addToWlambda_temp1, - temp2 = ContactEquation_addToWlambda_temp2; - - - // Add to linear velocity - n.mult(invMassi * deltalambda, temp2); - bi.vlambda.vsub(temp2,bi.vlambda); - n.mult(invMassj * deltalambda, temp2); - bj.vlambda.vadd(temp2,bj.vlambda); - - // Add to angular velocity - if(bi.wlambda !== undefined){ - this.biInvInertiaTimesRixn.mult(deltalambda,temp1); - - bi.wlambda.vsub(temp1,bi.wlambda); - } - if(bj.wlambda !== undefined){ - this.bjInvInertiaTimesRjxn.mult(deltalambda,temp1); - bj.wlambda.vadd(temp1,bj.wlambda); - } -}; -*/
    -
    diff --git a/docs/files/src_equations_Equation.js.html b/docs/files/src_equations_Equation.js.html index 0fda8e2d3..8022b1b8f 100644 --- a/docs/files/src_equations_Equation.js.html +++ b/docs/files/src_equations_Equation.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/equations/Equation.js

    +

    File: src/equations/Equation.js

    @@ -198,7 +149,7 @@ 

    File: src/equations/Equation.js

    * @param {Number} maxForce Maximum (read: positive max) force to be applied by the constraint. */ function Equation(bi,bj,minForce,maxForce){ - this.id = -1; + this.id = Equation.id++; /** * @property {number} minForce @@ -246,17 +197,23 @@

    File: src/equations/Equation.js

    this.jacobianElementA = new JacobianElement(); /** - * @property {JacobianElement} jacobianElementA + * @property {JacobianElement} jacobianElementB */ this.jacobianElementB = new JacobianElement(); + /** + * @property {boolean} enabled + * @default true + */ + this.enabled = true; + // Set typical spook params this.setSpookParams(1e7,4,1/60); - - this.enabled = true; } Equation.prototype.constructor = Equation; +Equation.id = 0; + /** * Recalculates a,b,eps. * @method setSpookParams @@ -449,7 +406,6 @@

    File: src/equations/Equation.js

    -
    diff --git a/docs/files/src_equations_FrictionEquation.js.html b/docs/files/src_equations_FrictionEquation.js.html index 79eb5721e..84eee1015 100644 --- a/docs/files/src_equations_FrictionEquation.js.html +++ b/docs/files/src_equations_FrictionEquation.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/equations/FrictionEquation.js

    +

    File: src/equations/FrictionEquation.js

    @@ -193,32 +144,16 @@ 

    File: src/equations/FrictionEquation.js

    * @class FrictionEquation * @constructor * @author schteppe - * @param {Body} bi - * @param {Body} bj + * @param {Body} bodyA + * @param {Body} bodyB * @param {Number} slipForce should be +-F_friction = +-mu * F_normal = +-mu * m * g * @extends Equation */ -function FrictionEquation(bi,bj,slipForce){ - Equation.call(this,bi,bj,-slipForce,slipForce); +function FrictionEquation(bodyA, bodyB, slipForce){ + Equation.call(this,bodyA, bodyB, -slipForce, slipForce); this.ri = new Vec3(); this.rj = new Vec3(); this.t = new Vec3(); // tangent - - - // The following is just cache - this.rixt = new Vec3(); - this.rjxt = new Vec3(); - this.wixri = new Vec3(); - this.wjxrj = new Vec3(); - - this.invIi = new Mat3(); - this.invIj = new Mat3(); - - this.relVel = new Vec3(); - this.relForce = new Vec3(); - - this.biInvInertiaTimesRixt = new Vec3(); - this.bjInvInertiaTimesRjxt = new Vec3(); } FrictionEquation.prototype = new Equation(); @@ -226,7 +161,6 @@

    File: src/equations/FrictionEquation.js

    var FrictionEquation_computeB_temp1 = new Vec3(); var FrictionEquation_computeB_temp2 = new Vec3(); -var FrictionEquation_computeB_zero = new Vec3(); FrictionEquation.prototype.computeB = function(h){ var a = this.a, b = this.b, @@ -234,42 +168,14 @@

    File: src/equations/FrictionEquation.js

    bj = this.bj, ri = this.ri, rj = this.rj, - rixt = this.rixt, - rjxt = this.rjxt, - wixri = this.wixri, - wjxrj = this.wjxrj, - zero = FrictionEquation_computeB_zero; - - var vi = bi.velocity, - wi = bi.angularVelocity ? bi.angularVelocity : zero, - fi = bi.force, - taui = bi.torque ? bi.torque : zero, - - vj = bj.velocity, - wj = bj.angularVelocity ? bj.angularVelocity : zero, - fj = bj.force, - tauj = bj.torque ? bj.torque : zero, - - relVel = this.relVel, - relForce = this.relForce, - invMassi = bi.invMass, - invMassj = bj.invMass, - - invIi = this.invIi, - invIj = this.invIj, - - t = this.t, - - invIi_vmult_taui = FrictionEquation_computeB_temp1, - invIj_vmult_tauj = FrictionEquation_computeB_temp2; + rixt = FrictionEquation_computeB_temp1, + rjxt = FrictionEquation_computeB_temp2, + t = this.t; // Caluclate cross products ri.cross(t,rixt); rj.cross(t,rjxt); - wi.cross(ri,wixri); - wj.cross(rj,wjxrj); - // G = [-t -rixt t rjxt] // And remember, this is a pure velocity constraint, g is always zero! var GA = this.jacobianElementA, @@ -279,100 +185,16 @@

    File: src/equations/FrictionEquation.js

    GB.spatial.copy(t); GB.rotational.copy(rjxt); - if(bi.invInertiaWorld){ bi.invInertiaWorld.vmult(taui,invIi_vmult_taui); } - else { invIi_vmult_taui.set(0,0,0); } - if(bj.invInertiaWorld){ bj.invInertiaWorld.vmult(tauj,invIj_vmult_tauj); } - else { invIj_vmult_tauj.set(0,0,0); } + var GW = this.computeGW(); + var GiMf = this.computeGiMf(); - var GW = this.computeGW();//vj.dot(t) - vi.dot(t) + wjxrj.dot(t) - wixri.dot(t), // eq. 40 - var GiMf = this.computeGiMf();//fj.dot(t)*invMassj - fi.dot(t)*invMassi + rjxt.dot(invIj_vmult_tauj) - rixt.dot(invIi_vmult_taui); - - // we do only want to constrain velocity, so g=0 - var B = - GW * b - h*GiMf; + var B = - GW * b - h * GiMf; return B; }; -/* -// Compute C = G * Minv * G + eps -//var FEcomputeC_temp1 = new Vec3(); -//var FEcomputeC_temp2 = new Vec3(); -FrictionEquation.prototype.computeC = function(){ - var bi = this.bi, - bj = this.bj, - rixt = this.rixt, - rjxt = this.rjxt, - invMassi = bi.invMass, - invMassj = bj.invMass, - C = invMassi + invMassj + this.eps, - invIi = this.invIi, - invIj = this.invIj; - - // Compute rxt * I * rxt for each body - if(bi.invInertiaWorld) bi.invInertiaWorld.vmult(rixt,this.biInvInertiaTimesRixt); - if(bj.invInertiaWorld) bj.invInertiaWorld.vmult(rjxt,this.bjInvInertiaTimesRjxt); - C += this.biInvInertiaTimesRixt.dot(rixt); - C += this.bjInvInertiaTimesRjxt.dot(rjxt); - - return C; -}; - -var FrictionEquation_computeGWlambda_ulambda = new Vec3(); -FrictionEquation.prototype.computeGWlambda = function(){ - var bi = this.bi; - var bj = this.bj; - - var GWlambda = 0.0; - var ulambda = FrictionEquation_computeGWlambda_ulambda; - bj.vlambda.vsub(bi.vlambda,ulambda); - GWlambda += ulambda.dot(this.t); - - // Angular - if(bi.wlambda){ - GWlambda -= bi.wlambda.dot(this.rixt); - } - if(bj.wlambda){ - GWlambda += bj.wlambda.dot(this.rjxt); - } - - return GWlambda; -}; - -var FrictionEquation_addToWlambda_tmp = new Vec3(); -FrictionEquation.prototype.addToWlambda = function(deltalambda){ - var bi = this.bi, - bj = this.bj, - rixt = this.rixt, - rjxt = this.rjxt, - invMassi = bi.invMass, - invMassj = bj.invMass, - t = this.t, - tmp = FrictionEquation_addToWlambda_tmp, - wi = bi.wlambda, - wj = bj.wlambda; - - // Add to linear velocity - t.mult(invMassi * deltalambda, tmp); - bi.vlambda.vsub(tmp,bi.vlambda); - - t.mult(invMassj * deltalambda, tmp); - bj.vlambda.vadd(tmp,bj.vlambda); - - // Add to angular velocity - if(wi){ - this.biInvInertiaTimesRixt.mult(deltalambda,tmp); - wi.vsub(tmp,wi); - } - if(wj){ - this.bjInvInertiaTimesRjxt.mult(deltalambda,tmp); - wj.vadd(tmp,wj); - } -}; -*/ -
    -
    diff --git a/docs/files/src_equations_RotationalEquation.js.html b/docs/files/src_equations_RotationalEquation.js.html index 84403e016..1a182a8a3 100644 --- a/docs/files/src_equations_RotationalEquation.js.html +++ b/docs/files/src_equations_RotationalEquation.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/equations/RotationalEquation.js

    +

    File: src/equations/RotationalEquation.js

    @@ -189,70 +140,51 @@ 

    File: src/equations/RotationalEquation.js

    var Equation = require('./Equation'); /** - * Rotational constraint. Works to keep the local vectors orthogonal to each other. + * Rotational constraint. Works to keep the local vectors orthogonal to each other in world space. * @class RotationalEquation * @constructor * @author schteppe - * @param {RigidBody} bj - * @param {Vec3} localVectorInBodyA - * @param {RigidBody} bi - * @param {Vec3} localVectorInBodyB + * @param {Body} bodyA + * @param {Body} bodyB + * @param {Vec3} [options.axisA] + * @param {Vec3} [options.axisB] + * @param {number} [options.maxForce] * @extends Equation */ -function RotationalEquation(bodyA, bodyB){ - Equation.call(this,bodyA,bodyB,-1e6,1e6); - this.ni = new Vec3(); // World oriented localVectorInBodyA - this.nj = new Vec3(); // ...and B +function RotationalEquation(bodyA, bodyB, options){ + options = options || {}; + var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6; - this.nixnj = new Vec3(); - this.njxni = new Vec3(); + Equation.call(this,bodyA,bodyB,-maxForce, maxForce); - this.invIi = new Mat3(); - this.invIj = new Mat3(); + this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1, 0, 0); + this.axisB = options.axisB ? options.axisB.clone() : new Vec3(0, 1, 0); - this.relVel = new Vec3(); - this.relForce = new Vec3(); + this.maxAngle = Math.PI / 2; } RotationalEquation.prototype = new Equation(); RotationalEquation.prototype.constructor = RotationalEquation; -var zero = new Vec3(); +var tmpVec1 = new Vec3(); +var tmpVec2 = new Vec3(); RotationalEquation.prototype.computeB = function(h){ var a = this.a, b = this.b, - bi = this.bi, - bj = this.bj, - - ni = this.ni, - nj = this.nj, - - nixnj = this.nixnj, - njxni = this.njxni, - - vi = bi.velocity, - wi = bi.angularVelocity ? bi.angularVelocity : zero, - fi = bi.force, - taui = bi.torque ? bi.torque : zero, - vj = bj.velocity, - wj = bj.angularVelocity ? bj.angularVelocity : zero, - fj = bj.force, - tauj = bj.torque ? bj.torque : zero, + ni = this.axisA, + nj = this.axisB, - invMassi = bi.invMass, - invMassj = bj.invMass, + nixnj = tmpVec1, + njxni = tmpVec2, GA = this.jacobianElementA, - GB = this.jacobianElementB, - - invIi = this.invIi, - invIj = this.invIj; + GB = this.jacobianElementB; // Caluclate cross products - ni.cross(nj,nixnj); - nj.cross(ni,njxni); + ni.cross(nj, nixnj); + nj.cross(ni, njxni); // g = ni * nj // gdot = (nj x ni) * wi + (ni x nj) * wj @@ -261,84 +193,18 @@

    File: src/equations/RotationalEquation.js

    GA.rotational.copy(njxni); GB.rotational.copy(nixnj); - var g = -ni.dot(nj), - GW = this.computeGW(),//njxni.dot(wi) + nixnj.dot(wj), - GiMf = this.computeGiMf();//njxni.dot(invIi.vmult(taui)) + nixnj.dot(invIj.vmult(tauj)); + var g = Math.cos(this.maxAngle) - ni.dot(nj), + GW = this.computeGW(), + GiMf = this.computeGiMf(); - var B = - g * a - GW * b - h*GiMf; + var B = - g * a - GW * b - h * GiMf; return B; }; -/* -// Compute C = GMG+eps -RotationalEquation.prototype.computeC = function(){ - var bi = this.bi; - var bj = this.bj; - var nixnj = this.nixnj; - var njxni = this.njxni; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - var C = this.eps; - - - C += bi.invInertiaWorld.vmult(njxni).dot(njxni); - C += bj.invInertiaWorld.vmult(nixnj).dot(nixnj); - - return C; -}; - -var computeGWlambda_ulambda = new Vec3(); -RotationalEquation.prototype.computeGWlambda = function(){ - var bi = this.bi; - var bj = this.bj; - var ulambda = computeGWlambda_ulambda; - - var GWlambda = 0.0; - //bj.vlambda.vsub(bi.vlambda, ulambda); - //GWlambda += ulambda.dot(this.ni); - - // Angular - if(bi.wlambda){ - GWlambda += bi.wlambda.dot(this.njxni); - } - if(bj.wlambda){ - GWlambda += bj.wlambda.dot(this.nixnj); - } - - //console.log("GWlambda:",GWlambda); - - return GWlambda; -}; - -RotationalEquation.prototype.addToWlambda = function(deltalambda){ - var bi = this.bi; - var bj = this.bj; - var nixnj = this.nixnj; - var njxni = this.njxni; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - // Add to linear velocity - //bi.vlambda.vsub(n.mult(invMassi * deltalambda),bi.vlambda); - //bj.vlambda.vadd(n.mult(invMassj * deltalambda),bj.vlambda); - - // Add to angular velocity - if(bi.wlambda){ - var I = bi.invInertiaWorld; - bi.wlambda.vsub(I.vmult(nixnj).mult(deltalambda),bi.wlambda); - } - if(bj.wlambda){ - var I = bj.invInertiaWorld; - bj.wlambda.vadd(I.vmult(nixnj).mult(deltalambda),bj.wlambda); - } -}; -*/
    -
    diff --git a/docs/files/src_equations_RotationalMotorEquation.js.html b/docs/files/src_equations_RotationalMotorEquation.js.html index 3c2417ed0..3161316ef 100644 --- a/docs/files/src_equations_RotationalMotorEquation.js.html +++ b/docs/files/src_equations_RotationalMotorEquation.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/equations/RotationalMotorEquation.js

    +

    File: src/equations/RotationalMotorEquation.js

    @@ -189,23 +140,30 @@ 

    File: src/equations/RotationalMotorEquation.js

    var Equation = require('./Equation'); /** - * Rotational motor constraint. Works to keep the relative angular velocity of the bodies to a given value + * Rotational motor constraint. Tries to keep the relative angular velocity of the bodies to a given value. * @class RotationalMotorEquation * @constructor * @author schteppe - * @param {RigidBody} bodyA - * @param {RigidBody} bodyB + * @param {Body} bodyA + * @param {Body} bodyB * @param {Number} maxForce * @extends Equation */ function RotationalMotorEquation(bodyA, bodyB, maxForce){ - maxForce = maxForce || 1e6; + maxForce = typeof(maxForce)!=='undefined' ? maxForce : 1e6; Equation.call(this,bodyA,bodyB,-maxForce,maxForce); - this.axisA = new Vec3(); // World oriented rotational axis - this.axisB = new Vec3(); // World oriented rotational axis - this.invIi = new Mat3(); - this.invIj = new Mat3(); + /** + * World oriented rotational axis + * @property {Vec3} axisA + */ + this.axisA = new Vec3(); + + /** + * World oriented rotational axis + * @property {Vec3} axisB + */ + this.axisB = new Vec3(); // World oriented rotational axis /** * Motor velocity @@ -217,8 +175,6 @@

    File: src/equations/RotationalMotorEquation.js

    RotationalMotorEquation.prototype = new Equation(); RotationalMotorEquation.prototype.constructor = RotationalMotorEquation; -var zero = new Vec3(); - RotationalMotorEquation.prototype.computeB = function(h){ var a = this.a, b = this.b, @@ -228,108 +184,28 @@

    File: src/equations/RotationalMotorEquation.js

    axisA = this.axisA, axisB = this.axisB, - vi = bi.velocity, - wi = bi.angularVelocity ? bi.angularVelocity : zero, - fi = bi.force, - taui = bi.torque ? bi.torque : zero, - - vj = bj.velocity, - wj = bj.angularVelocity ? bj.angularVelocity : zero, - fj = bj.force, - tauj = bj.torque ? bj.torque : zero, - GA = this.jacobianElementA, - GB = this.jacobianElementB, - - invMassi = bi.invMass, - invMassj = bj.invMass; + GB = this.jacobianElementB; // g = 0 // gdot = axisA * wi - axisB * wj + // gdot = G * W = G * [vi wi vj wj] + // => // G = [0 axisA 0 -axisB] - // W = [vi wi vj wj] GA.rotational.copy(axisA); axisB.negate(GB.rotational); var GW = this.computeGW() - this.targetVelocity, - GiMf = this.computeGiMf();//axis.dot(invIi.vmult(taui)) + axis.dot(invIj.vmult(tauj)); + GiMf = this.computeGiMf(); - var B = - GW * b - h*GiMf; + var B = - GW * b - h * GiMf; return B; }; -/* -// Compute C = GMG+eps -RotationalMotorEquation.prototype.computeC = function(){ - var bi = this.bi; - var bj = this.bj; - var axisA = this.axisA; - var axisB = this.axisB; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - var C = this.eps; - - C += bi.invInertiaWorld.vmult(axisA).dot(axisB); - C += bj.invInertiaWorld.vmult(axisB).dot(axisB); - - return C; -}; - -var computeGWlambda_ulambda = new Vec3(); -RotationalMotorEquation.prototype.computeGWlambda = function(){ - var bi = this.bi; - var bj = this.bj; - var ulambda = computeGWlambda_ulambda; - var axisA = this.axisA; - var axisB = this.axisB; - - var GWlambda = 0.0; - //bj.vlambda.vsub(bi.vlambda, ulambda); - //GWlambda += ulambda.dot(this.ni); - - // Angular - if(bi.wlambda){ - GWlambda += bi.wlambda.dot(axisA); - } - if(bj.wlambda){ - GWlambda += bj.wlambda.dot(axisB); - } - - //console.log("GWlambda:",GWlambda); - - return GWlambda; -}; - -RotationalMotorEquation.prototype.addToWlambda = function(deltalambda){ - var bi = this.bi; - var bj = this.bj; - var axisA = this.axisA; - var axisB = this.axisB; - var invMassi = bi.invMass; - var invMassj = bj.invMass; - - // Add to linear velocity - //bi.vlambda.vsub(n.mult(invMassi * deltalambda),bi.vlambda); - //bj.vlambda.vadd(n.mult(invMassj * deltalambda),bj.vlambda); - - // Add to angular velocity - if(bi.wlambda){ - var I = bi.invInertiaWorld; - bi.wlambda.vsub(I.vmult(axisA).mult(deltalambda),bi.wlambda); - } - if(bj.wlambda){ - var I = bj.invInertiaWorld; - bj.wlambda.vadd(I.vmult(axisB).mult(deltalambda),bj.wlambda); - } -}; -*/ -
    -
    diff --git a/docs/files/src_material_ContactMaterial.js.html b/docs/files/src_material_ContactMaterial.js.html index 18e57bfa4..2c6a1a277 100644 --- a/docs/files/src_material_ContactMaterial.js.html +++ b/docs/files/src_material_ContactMaterial.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/material/ContactMaterial.js

    +

    File: src/material/ContactMaterial.js

    @@ -264,7 +215,6 @@ 

    File: src/material/ContactMaterial.js

    -
    diff --git a/docs/files/src_material_Material.js.html b/docs/files/src_material_Material.js.html index f9c8ae077..6b6833915 100644 --- a/docs/files/src_material_Material.js.html +++ b/docs/files/src_material_Material.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/material/Material.js

    +

    File: src/material/Material.js

    @@ -188,28 +139,51 @@ 

    File: src/material/Material.js

    * Defines a physics material. * @class Material * @constructor - * @param {String} name + * @param {object} [options] * @author schteppe */ -function Material(name){ +function Material(options){ + var name = ''; + options = options || {}; + + // Backwards compatibility fix + if(typeof(options) === 'string'){ + name = options; + options = {}; + } else if(typeof(options) === 'object') { + name = ''; + } + /** * @property name * @type {String} */ this.name = name; - + /** * material id. * @property id + * @type {number} */ this.id = Material.idCounter++; + + /** + * Friction for this material. If non-negative, it will be used instead of the friction given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used. + * @property {number} friction + */ + this.friction = typeof(options.friction) !== 'undefined' ? options.friction : -1; + + /** + * Restitution for this material. If non-negative, it will be used instead of the restitution given by ContactMaterials. If there's no matching ContactMaterial, the value from .defaultContactMaterial in the World will be used. + * @property {number} restitution + */ + this.restitution = typeof(options.restitution) !== 'undefined' ? options.restitution : -1; } Material.idCounter = 0;
    -
    diff --git a/docs/files/src_math_JacobianElement.js.html b/docs/files/src_math_JacobianElement.js.html index 8d0d4dc08..ec838237b 100644 --- a/docs/files/src_math_JacobianElement.js.html +++ b/docs/files/src_math_JacobianElement.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/math/JacobianElement.js

    +

    File: src/math/JacobianElement.js

    @@ -227,7 +178,6 @@ 

    File: src/math/JacobianElement.js

    -
    diff --git a/docs/files/src_math_Mat3.js.html b/docs/files/src_math_Mat3.js.html index 7b9bc10cc..69493d144 100644 --- a/docs/files/src_math_Mat3.js.html +++ b/docs/files/src_math_Mat3.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/math/Mat3.js

    +

    File: src/math/Mat3.js

    @@ -212,17 +163,18 @@ 

    File: src/math/Mat3.js

    * @todo Create another function that immediately creates an identity matrix eg. eye() */ Mat3.prototype.identity = function(){ - this.elements[0] = 1; - this.elements[1] = 0; - this.elements[2] = 0; + var e = this.elements; + e[0] = 1; + e[1] = 0; + e[2] = 0; - this.elements[3] = 0; - this.elements[4] = 1; - this.elements[5] = 0; + e[3] = 0; + e[4] = 1; + e[5] = 0; - this.elements[6] = 0; - this.elements[7] = 0; - this.elements[8] = 1; + e[6] = 0; + e[7] = 0; + e[8] = 1; }; /** @@ -245,6 +197,7 @@

    File: src/math/Mat3.js

    /** * Sets the matrix diagonal elements from a Vec3 * @method setTrace + * @param {Vec3} vec3 */ Mat3.prototype.setTrace = function(vec3){ var e = this.elements; @@ -254,8 +207,9 @@

    File: src/math/Mat3.js

    }; /** - * Sets the matrix diagonal elements from a Vec3 - * @method setTrace + * Gets the matrix diagonal elements + * @method getTrace + * @return {Vec3} */ Mat3.prototype.getTrace = function(target){ var target = target || new Vec3(); @@ -604,7 +558,6 @@

    File: src/math/Mat3.js

    -
    diff --git a/docs/files/src_math_Quaternion.js.html b/docs/files/src_math_Quaternion.js.html index fa25a16ce..a773edac0 100644 --- a/docs/files/src_math_Quaternion.js.html +++ b/docs/files/src_math_Quaternion.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/math/Quaternion.js

    +

    File: src/math/Quaternion.js

    @@ -268,7 +219,7 @@ 

    File: src/math/Quaternion.js

    /** * Converts the quaternion to axis/angle representation. - * @method setFromAxisAngle + * @method toAxisAngle * @param {Vec3} targetAxis Optional. A vector object to reuse for storing the axis. * @return Array An array, first elemnt is the axis and the second is the angle in radians. */ @@ -583,7 +534,6 @@

    File: src/math/Quaternion.js

    };
    -
    diff --git a/docs/files/src_math_Transform.js.html b/docs/files/src_math_Transform.js.html index 69b42d683..be5e8c341 100644 --- a/docs/files/src_math_Transform.js.html +++ b/docs/files/src_math_Transform.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/math/Transform.js

    +

    File: src/math/Transform.js

    @@ -191,16 +142,24 @@ 

    File: src/math/Transform.js

    * @class Transform * @constructor */ -function Transform() { +function Transform(options) { + options = options || {}; + /** * @property {Vec3} position */ this.position = new Vec3(); - + if(options.position){ + this.position.copy(options.position); + } + /** * @property {Quaternion} quaternion */ this.quaternion = new Quaternion(); + if(options.quaternion){ + this.quaternion.copy(options.quaternion); + } } var tmpQuat = new Quaternion(); @@ -221,6 +180,17 @@

    File: src/math/Transform.js

    return result; }; +/** + * Get a global point in local transform coordinates. + * @method pointToLocal + * @param {Vec3} point + * @param {Vec3} result + * @return {Vec3} The "result" vector object + */ +Transform.prototype.pointToLocal = function(worldPoint, result){ + return Transform.pointToLocalFrame(this.position, this.quaternion, worldPoint, result); +}; + /** * @static * @method pointToWorldFrame @@ -236,12 +206,29 @@

    File: src/math/Transform.js

    return result; }; +/** + * Get a local point in global transform coordinates. + * @method pointToWorld + * @param {Vec3} point + * @param {Vec3} result + * @return {Vec3} The "result" vector object + */ +Transform.prototype.pointToWorld = function(localPoint, result){ + return Transform.pointToWorldFrame(this.position, this.quaternion, localPoint, result); +}; + + Transform.prototype.vectorToWorldFrame = function(localVector, result){ var result = result || new Vec3(); this.quaternion.vmult(localVector, result); return result; }; +Transform.vectorToWorldFrame = function(quaternion, localVector, result){ + quaternion.vmult(localVector, result); + return result; +}; + Transform.vectorToLocalFrame = function(position, quaternion, worldVector, result){ var result = result || new Vec3(); quaternion.w *= -1; @@ -252,7 +239,6 @@

    File: src/math/Transform.js

    -
    diff --git a/docs/files/src_math_Vec3.js.html b/docs/files/src_math_Vec3.js.html index bdbe1ed5b..51ea06064 100644 --- a/docs/files/src_math_Vec3.js.html +++ b/docs/files/src_math_Vec3.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/math/Vec3.js

    +

    File: src/math/Vec3.js

    @@ -218,8 +169,30 @@ 

    File: src/math/Vec3.js

    this.z = z||0.0; } +/** + * @static + * @property {Vec3} ZERO + */ Vec3.ZERO = new Vec3(0, 0, 0); +/** + * @static + * @property {Vec3} UNIT_X + */ +Vec3.UNIT_X = new Vec3(1, 0, 0); + +/** + * @static + * @property {Vec3} UNIT_Y + */ +Vec3.UNIT_Y = new Vec3(0, 1, 0); + +/** + * @static + * @property {Vec3} UNIT_Z + */ +Vec3.UNIT_Z = new Vec3(0, 0, 1); + /** * Vector cross product * @method cross @@ -357,24 +330,40 @@

    File: src/math/Vec3.js

    }; /** - * Get the 2-norm (length) of the vector + * Get the length of the vector * @method norm * @return {Number} + * @deprecated Use .length() instead */ Vec3.prototype.norm = function(){ var x=this.x, y=this.y, z=this.z; return Math.sqrt(x*x + y*y + z*z); }; +/** + * Get the length of the vector + * @method length + * @return {Number} + */ +Vec3.prototype.length = Vec3.prototype.norm; + /** * Get the squared length of the vector * @method norm2 * @return {Number} + * @deprecated Use .lengthSquared() instead. */ Vec3.prototype.norm2 = function(){ return this.dot(this); }; +/** + * Get the squared length of the vector. + * @method lengthSquared + * @return {Number} + */ +Vec3.prototype.lengthSquared = Vec3.prototype.norm2; + /** * Get distance from this point to another point * @method distanceTo @@ -390,12 +379,25 @@

    File: src/math/Vec3.js

    }; /** - * Multiply the vector with a scalar + * Get squared distance from this point to another point + * @method distanceSquared + * @param {Vec3} p + * @return {Number} + */ +Vec3.prototype.distanceSquared = function(p){ + var x=this.x, y=this.y, z=this.z; + var px=p.x, py=p.y, pz=p.z; + return (px-x)*(px-x) + (py-y)*(py-y) + (pz-z)*(pz-z); +}; + +/** + * Multiply all the components of the vector with a scalar. * @deprecated Use .scale instead * @method mult * @param {Number} scalar - * @param {Vec3} target + * @param {Vec3} target The vector to save the result in. * @return {Vec3} + * @deprecated Use .scale() instead */ Vec3.prototype.mult = function(scalar,target){ target = target || new Vec3(); @@ -474,8 +476,8 @@

    File: src/math/Vec3.js

    n.cross(t1,t2); } else { // The normal length is zero, make something up - t1.set(1,0,0).normalize(); - t2.set(0,1,0).normalize(); + t1.set(1, 0, 0); + t2.set(0, 1, 0); } }; @@ -585,7 +587,6 @@

    File: src/math/Vec3.js

    };
    -
    diff --git a/docs/files/src_objects_Body.js.html b/docs/files/src_objects_Body.js.html index dce2d64a2..0ca43c80a 100644 --- a/docs/files/src_objects_Body.js.html +++ b/docs/files/src_objects_Body.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/Body.js

    +

    File: src/objects/Body.js

    @@ -204,8 +155,17 @@ 

    File: src/objects/Body.js

    * @param {Vec3} [options.angularVelocity] * @param {Quaternion} [options.quaternion] * @param {number} [options.mass] + * @param {Material} [options.material] * @param {number} [options.type] - * @param {number} [options.linearDamping] + * @param {number} [options.linearDamping=0.01] + * @param {number} [options.angularDamping=0.01] + * @param {boolean} [options.allowSleep=true] + * @param {number} [options.sleepSpeedLimit=0.1] + * @param {number} [options.sleepTimeLimit=1] + * @param {number} [options.collisionFilterGroup=1] + * @param {number} [options.collisionFilterMask=1] + * @param {boolean} [options.fixedRotation=false] + * @param {Body} [options.shape] * @example * var body = new Body({ * mass: 1 @@ -249,12 +209,12 @@

    File: src/objects/Body.js

    /** * @property {Number} collisionFilterGroup */ - this.collisionFilterGroup = 1; + this.collisionFilterGroup = typeof(options.collisionFilterGroup) === 'number' ? options.collisionFilterGroup : 1; /** * @property {Number} collisionFilterMask */ - this.collisionFilterMask = 1; + this.collisionFilterMask = typeof(options.collisionFilterMask) === 'number' ? options.collisionFilterMask : 1; /** * Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled. @@ -312,6 +272,7 @@

    File: src/objects/Body.js

    /** * @property mass * @type {Number} + * @default 0 */ this.mass = mass; @@ -347,8 +308,9 @@

    File: src/objects/Body.js

    * If true, the body will automatically fall to sleep. * @property allowSleep * @type {Boolean} + * @default true */ - this.allowSleep = true; + this.allowSleep = typeof(options.allowSleep) !== 'undefined' ? options.allowSleep : true; /** * Current sleep state. @@ -361,15 +323,17 @@

    File: src/objects/Body.js

    * If the speed (the norm of the velocity) is smaller than this value, the body is considered sleepy. * @property sleepSpeedLimit * @type {Number} + * @default 0.1 */ - this.sleepSpeedLimit = 0.1; + this.sleepSpeedLimit = typeof(options.sleepSpeedLimit) !== 'undefined' ? options.sleepSpeedLimit : 0.1; /** * If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping. * @property sleepTimeLimit * @type {Number} + * @default 1 */ - this.sleepTimeLimit = 1; + this.sleepTimeLimit = typeof(options.sleepTimeLimit) !== 'undefined' ? options.sleepTimeLimit : 1; this.timeLastSleepy = 0; @@ -467,17 +431,18 @@

    File: src/objects/Body.js

    /** * Set to true if you don't want the body to rotate. Make sure to run .updateMassProperties() after changing this. * @property {Boolean} fixedRotation + * @default false */ - this.fixedRotation = false; + this.fixedRotation = typeof(options.fixedRotation) !== "undefined" ? options.fixedRotation : false; /** * @property {Number} angularDamping */ - this.angularDamping = 0.01; // Perhaps default should be zero here? + this.angularDamping = typeof(options.angularDamping) !== 'undefined' ? options.angularDamping : 0.01; /** * @property aabb - * @type {Vec3} + * @type {AABB} */ this.aabb = new AABB(); @@ -490,6 +455,10 @@

    File: src/objects/Body.js

    this.wlambda = new Vec3(); + if(options.shape){ + this.addShape(options.shape); + } + this.updateMassProperties(); } Body.prototype = new EventTarget(); @@ -627,6 +596,19 @@

    File: src/objects/Body.js

    return result; }; +/** + * Convert a world vector to local body frame. + * @method vectorToLocalFrame + * @param {Vec3} worldPoint + * @param {Vec3} result + * @return {Vec3} + */ +Body.prototype.vectorToLocalFrame = function(worldVector, result){ + var result = result || new Vec3(); + this.quaternion.conjugate().vmult(worldVector,result); + return result; +}; + /** * Convert a local body point to world frame. * @method pointToWorldFrame @@ -657,7 +639,14 @@

    File: src/objects/Body.js

    var tmpVec = new Vec3(); var tmpQuat = new Quaternion(); - +/** + * Add a shape to the body with a local offset and orientation. + * @method addShape + * @param {Shape} shape + * @param {Vec3} offset + * @param {Quaternion} quaternion + * @return {Body} The body object, for chainability. + */ Body.prototype.addShape = function(shape, _offset, _orientation){ var offset = new Vec3(); var orientation = new Quaternion(); @@ -676,6 +665,8 @@

    File: src/objects/Body.js

    this.updateBoundingRadius(); this.aabbNeedsUpdate = true; + + return this; }; /** @@ -806,6 +797,29 @@

    File: src/objects/Body.js

    this.torque.vadd(rotForce,this.torque); }; +/** + * Apply force to a local point in the body. + * @method applyLocalForce + * @param {Vec3} force The force vector to apply, defined locally in the body frame. + * @param {Vec3} localPoint A local point in the body to apply the force on. + */ +var Body_applyLocalForce_worldForce = new Vec3(); +var Body_applyLocalForce_worldPoint = new Vec3(); +Body.prototype.applyLocalForce = function(localForce, localPoint){ + if(this.type !== Body.DYNAMIC){ + return; + } + + var worldForce = Body_applyLocalForce_worldForce; + var worldPoint = Body_applyLocalForce_worldPoint; + + // Transform the force vector to world space + this.vectorToWorldFrame(localForce, worldForce); + this.pointToWorldFrame(localPoint, worldPoint); + + this.applyForce(worldForce, worldPoint); +}; + /** * Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity. * @method applyImpulse @@ -848,39 +862,49 @@

    File: src/objects/Body.js

    }; /** - * Should be called whenever you change the body mass. - * @method updateMassProperties + * Apply locally-defined impulse to a local point in the body. + * @method applyLocalImpulse + * @param {Vec3} force The force vector to apply, defined locally in the body frame. + * @param {Vec3} localPoint A local point in the body to apply the force on. */ -/*Body.prototype.updateMassProperties = function(){ - this.invMass = this.mass>0 ? 1.0/this.mass : 0; - this.shape.calculateLocalInertia(this.mass, this.inertia); - var I = this.inertia; - var fixed = this.fixedRotation; - this.invInertia.set( - I.x > 0 && !fixed ? 1.0 / I.x : 0, - I.y > 0 && !fixed ? 1.0 / I.y : 0, - I.z > 0 && !fixed ? 1.0 / I.z : 0 - ); - this.updateInertiaWorld(true); +var Body_applyLocalImpulse_worldImpulse = new Vec3(); +var Body_applyLocalImpulse_worldPoint = new Vec3(); +Body.prototype.applyLocalImpulse = function(localImpulse, localPoint){ + if(this.type !== Body.DYNAMIC){ + return; + } + + var worldImpulse = Body_applyLocalImpulse_worldImpulse; + var worldPoint = Body_applyLocalImpulse_worldPoint; + + // Transform the force vector to world space + this.vectorToWorldFrame(localImpulse, worldImpulse); + this.pointToWorldFrame(localPoint, worldPoint); + + this.applyImpulse(worldImpulse, worldPoint); }; -*/ -Body.prototype.updateMassProperties = function(){ - var target = new Vec3(); +var Body_updateMassProperties_halfExtents = new Vec3(); - // TODO: check if only 1 shape at origin, use shape inertia in that case +/** + * Should be called whenever you change the body shape or mass. + * @method updateMassProperties + */ +Body.prototype.updateMassProperties = function(){ + var halfExtents = Body_updateMassProperties_halfExtents; this.invMass = this.mass > 0 ? 1.0 / this.mass : 0; var I = this.inertia; var fixed = this.fixedRotation; - // Approximate with AABB + // Approximate with AABB box this.computeAABB(); - Box.calculateInertia(new Vec3( + halfExtents.set( (this.aabb.upperBound.x-this.aabb.lowerBound.x) / 2, (this.aabb.upperBound.y-this.aabb.lowerBound.y) / 2, (this.aabb.upperBound.z-this.aabb.lowerBound.z) / 2 - ), this.mass, I); + ); + Box.calculateInertia(halfExtents, this.mass, I); this.invInertia.set( I.x > 0 && !fixed ? 1.0 / I.x : 0, @@ -907,7 +931,6 @@

    File: src/objects/Body.js

    -
    diff --git a/docs/files/src_objects_RaycastVehicle.js.html b/docs/files/src_objects_RaycastVehicle.js.html index 0cde02328..f2bc31587 100644 --- a/docs/files/src_objects_RaycastVehicle.js.html +++ b/docs/files/src_objects_RaycastVehicle.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/RaycastVehicle.js

    +

    File: src/objects/RaycastVehicle.js

    @@ -312,9 +263,10 @@ 

    File: src/objects/RaycastVehicle.js

    var constraints = this.constraints; world.add(this.chassisBody); var that = this; - world.addEventListener('preStep', function(){ + this.preStepCallback = function(){ that.updateVehicle(world.dt); - }); + }; + world.addEventListener('preStep', this.preStepCallback); this.world = world; }; @@ -340,7 +292,7 @@

    File: src/objects/RaycastVehicle.js

    var chassisBody = this.chassisBody; for (var i = 0; i < numWheels; i++) { - this.updateWheelTransform(i, false); + this.updateWheelTransform(i); } this.currentVehicleSpeedKmHour = 3.6 * chassisBody.velocity.norm(); @@ -467,7 +419,7 @@

    File: src/objects/RaycastVehicle.js

    RaycastVehicle.prototype.removeFromWorld = function(world){ var constraints = this.constraints; world.remove(this.chassisBody); - world.removeEventListener('preStep', this.updateVehicle); + world.removeEventListener('preStep', this.preStepCallback); this.world = null; }; @@ -559,6 +511,13 @@

    File: src/objects/RaycastVehicle.js

    chassisBody.vectorToWorldFrame(wheel.axleLocal, wheel.axleWorld); }; + +/** + * Update one of the wheel transform. + * Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example. + * @method updateWheelTransform + * @param {integer} wheelIndex The wheel index to update. + */ RaycastVehicle.prototype.updateWheelTransform = function(wheelIndex){ var up = tmpVec4; var right = tmpVec5; @@ -879,7 +838,6 @@

    File: src/objects/RaycastVehicle.js

    }
    -
    diff --git a/docs/files/src_objects_RigidVehicle.js.html b/docs/files/src_objects_RigidVehicle.js.html index b04aed011..b2b5841ad 100644 --- a/docs/files/src_objects_RigidVehicle.js.html +++ b/docs/files/src_objects_RigidVehicle.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/RigidVehicle.js

    +

    File: src/objects/RigidVehicle.js

    @@ -194,7 +145,7 @@ 

    File: src/objects/RigidVehicle.js

    * Simple vehicle helper class with spherical rigid body wheels. * @class RigidVehicle * @constructor - * @param {object} [options.chassisBody] + * @param {Body} [options.chassisBody] */ function RigidVehicle(options){ this.wheelBodies = []; @@ -230,7 +181,7 @@

    File: src/objects/RigidVehicle.js

    * Add a wheel * @method addWheel * @param {object} options - * @param {object} [options.isFrontWheel] + * @param {boolean} [options.isFrontWheel] * @param {Vec3} [options.position] Position of the wheel, locally in the chassis body. * @param {Vec3} [options.direction] Slide direction of the wheel along the suspension. * @param {Vec3} [options.axis] Axis of rotation of the wheel, locally defined in the chassis. @@ -405,7 +356,6 @@

    File: src/objects/RigidVehicle.js

    -
    diff --git a/docs/files/src_objects_SPHSystem.js.html b/docs/files/src_objects_SPHSystem.js.html index 974df4fe2..8d73ead30 100644 --- a/docs/files/src_objects_SPHSystem.js.html +++ b/docs/files/src_objects_SPHSystem.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/SPHSystem.js

    +

    File: src/objects/SPHSystem.js

    @@ -198,9 +149,25 @@ 

    File: src/objects/SPHSystem.js

    */ function SPHSystem(){ this.particles = []; - this.density = 1; // kg/m3 - this.smoothingRadius = 1; // Adjust so there are about 15-20 neighbor particles within this radius + + /** + * Density of the system (kg/m3). + * @property {number} density + */ + this.density = 1; + + /** + * Distance below which two particles are considered to be neighbors. + * It should be adjusted so there are about 15-20 neighbor particles within this radius. + * @property {number} smoothingRadius + */ + this.smoothingRadius = 1; this.speedOfSound = 1; + + /** + * Viscosity of the system. + * @property {number} viscosity + */ this.viscosity = 0.01; this.eps = 0.000001; @@ -210,6 +177,11 @@

    File: src/objects/SPHSystem.js

    this.neighbors = []; } +/** + * Add a particle to the system. + * @method add + * @param {Body} particle + */ SPHSystem.prototype.add = function(particle){ this.particles.push(particle); if(this.neighbors.length < this.particles.length){ @@ -217,6 +189,11 @@

    File: src/objects/SPHSystem.js

    } }; +/** + * Remove a particle from the system. + * @method remove + * @param {Body} particle + */ SPHSystem.prototype.remove = function(particle){ var idx = this.particles.indexOf(particle); if(idx !== -1){ @@ -372,7 +349,6 @@

    File: src/objects/SPHSystem.js

    -
    diff --git a/docs/files/src_objects_Spring.js.html b/docs/files/src_objects_Spring.js.html index a1c46d18d..1a00bacfd 100644 --- a/docs/files/src_objects_Spring.js.html +++ b/docs/files/src_objects_Spring.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/Spring.js

    +

    File: src/objects/Spring.js

    @@ -378,7 +329,6 @@ 

    File: src/objects/Spring.js

    -
    diff --git a/docs/files/src_objects_WheelInfo.js.html b/docs/files/src_objects_WheelInfo.js.html index 577c0c8ba..ba8d53e8e 100644 --- a/docs/files/src_objects_WheelInfo.js.html +++ b/docs/files/src_objects_WheelInfo.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/objects/WheelInfo.js

    +

    File: src/objects/WheelInfo.js

    @@ -212,14 +163,14 @@ 

    File: src/objects/WheelInfo.js

    * @param {number} [options.deltaRotation=0] * @param {number} [options.rollInfluence=0.01] * @param {number} [options.maxSuspensionForce] - * @param {number} [options.isFrontWheel=true] + * @param {boolean} [options.isFrontWheel=true] * @param {number} [options.clippedInvContactDotSuspension=1] * @param {number} [options.suspensionRelativeVelocity=0] * @param {number} [options.suspensionForce=0] * @param {number} [options.skidInfo=0] * @param {number} [options.suspensionLength=0] * @param {number} [options.maxSuspensionTravel=1] - * @param {number} [options.useCustomSlidingRotationalSpeed=false] + * @param {boolean} [options.useCustomSlidingRotationalSpeed=false] * @param {number} [options.customSlidingRotationalSpeed=-0.1] */ function WheelInfo(options){ @@ -466,7 +417,6 @@

    File: src/objects/WheelInfo.js

    };
    -
    diff --git a/docs/files/src_shapes_Box.js.html b/docs/files/src_shapes_Box.js.html index 370f92068..9334d40b8 100644 --- a/docs/files/src_shapes_Box.js.html +++ b/docs/files/src_shapes_Box.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Box.js

    +

    File: src/shapes/Box.js

    @@ -230,28 +181,35 @@ 

    File: src/shapes/Box.js

    var sz = this.halfExtents.z; var V = Vec3; - var h = new ConvexPolyhedron([new V(-sx,-sy,-sz), - new V( sx,-sy,-sz), - new V( sx, sy,-sz), - new V(-sx, sy,-sz), - new V(-sx,-sy, sz), - new V( sx,-sy, sz), - new V( sx, sy, sz), - new V(-sx, sy, sz)], - [[3,2,1,0], // -z - [4,5,6,7], // +z - [5,4,0,1], // -y - [2,3,7,6], // +y - [0,4,7,3], // -x - [1,2,6,5], // +x - ], - [new V( 0, 0,-1), - new V( 0, 0, 1), - new V( 0,-1, 0), - new V( 0, 1, 0), - new V(-1, 0, 0), - new V( 1, 0, 0)]); + var vertices = [ + new V(-sx,-sy,-sz), + new V( sx,-sy,-sz), + new V( sx, sy,-sz), + new V(-sx, sy,-sz), + new V(-sx,-sy, sz), + new V( sx,-sy, sz), + new V( sx, sy, sz), + new V(-sx, sy, sz) + ]; + + var indices = [ + [3,2,1,0], // -z + [4,5,6,7], // +z + [5,4,0,1], // -y + [2,3,7,6], // +y + [0,4,7,3], // -x + [1,2,6,5], // +x + ]; + + var axes = [ + new V(0, 0, 1), + new V(0, 1, 0), + new V(1, 0, 0) + ]; + + var h = new ConvexPolyhedron(vertices, indices); this.convexPolyhedronRepresentation = h; + h.material = this.material; }; /** @@ -276,8 +234,8 @@

    File: src/shapes/Box.js

    /** * Get the box 6 side normals * @method getSideNormals - * @param {Boolean} includeNegative If true, this function returns 6 vectors. If false, it only returns 3 (but you get 6 by reversing those 3) - * @param {Quaternion} quat Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame. + * @param {array} sixTargetVectors An array of 6 vectors, to store the resulting side normals in. + * @param {Quaternion} quat Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame. * @return {array} */ Box.prototype.getSideNormals = function(sixTargetVectors,quat){ @@ -413,7 +371,6 @@

    File: src/shapes/Box.js

    -
    diff --git a/docs/files/src_shapes_ConvexPolyhedron.js.html b/docs/files/src_shapes_ConvexPolyhedron.js.html index be6a0b87e..178656435 100644 --- a/docs/files/src_shapes_ConvexPolyhedron.js.html +++ b/docs/files/src_shapes_ConvexPolyhedron.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    -
    -
    - -
    -
    -
    -
    - Show: - - - - - - - -
    - -
    -

    File: src/shapes/ConvexPolyhedron.js

    +

    File: src/shapes/ConvexPolyhedron.js

    @@ -208,7 +159,7 @@ 

    File: src/shapes/ConvexPolyhedron.js

    * @todo Move the clipping functions to ContactGenerator? * @todo Automatically merge coplanar polygons in constructor. */ -function ConvexPolyhedron(points, faces) { +function ConvexPolyhedron(points, faces, uniqueAxes) { var that = this; Shape.call(this); this.type = Shape.types.CONVEXPOLYHEDRON; @@ -248,12 +199,19 @@

    File: src/shapes/ConvexPolyhedron.js

    */ this.uniqueEdges = []; + /** + * If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check. + * @property {Array} uniqueAxes + */ + this.uniqueAxes = uniqueAxes ? uniqueAxes.slice() : null; + this.computeEdges(); this.updateBoundingSphereRadius(); } ConvexPolyhedron.prototype = new Shape(); ConvexPolyhedron.prototype.constructor = ConvexPolyhedron; +var computeEdges_tmpEdge = new Vec3(); /** * Computes uniqueEdges * @method computeEdges @@ -266,24 +224,17 @@

    File: src/shapes/ConvexPolyhedron.js

    edges.length = 0; - for(var pi=0; pi<nv; pi++){ - var p = vertices[pi]; - if(!(p instanceof Vec3)){ - throw "Argument 1 must be instance of Vec3"; - } - this.uniqueEdges.push(p); - } + var edge = computeEdges_tmpEdge; - for(var i=0; i<faces.length; i++){ + for(var i=0; i !== faces.length; i++){ var face = faces[i]; var numVertices = face.length; - for(var j = 0; j < numVertices; j++){ + for(var j = 0; j !== numVertices; j++){ var k = ( j+1 ) % numVertices; - var edge = new Vec3(); vertices[face[j]].vsub(vertices[face[k]], edge); edge.normalize(); var found = false; - for(var p=0; p < edges.length; p++){ + for(var p=0; p !== edges.length; p++){ if (edges[p].almostEquals(edge) || edges[p].almostEquals(edge)){ found = true; break; @@ -291,17 +242,7 @@

    File: src/shapes/ConvexPolyhedron.js

    } if (!found){ - edges.push(edge); - } - - if (edge) { - edge.face1 = i; - } else { - /* - var ed; - ed.m_face0 = i; - edges.insert(vp,ed); - */ + edges.push(edge.clone()); } } } @@ -388,16 +329,10 @@

    File: src/shapes/ConvexPolyhedron.js

    var cah_WorldNormal = new Vec3(); ConvexPolyhedron.prototype.clipAgainstHull = function(posA,quatA,hullB,posB,quatB,separatingNormal,minDist,maxDist,result){ var WorldNormal = cah_WorldNormal; - if(!(posA instanceof Vec3)){ - throw new Error("posA must be Vec3"); - } - if(!(quatA instanceof Quaternion)){ - throw new Error("quatA must be Quaternion"); - } var hullA = this; var curMaxDist = maxDist; var closestFaceB = -1; - var dmax = -Infinity; + var dmax = -Number.MAX_VALUE; for(var face=0; face < hullB.faces.length; face++){ WorldNormal.copy(hullB.faceNormals[face]); quatB.vmult(WorldNormal,WorldNormal); @@ -456,78 +391,112 @@

    File: src/shapes/ConvexPolyhedron.js

    worldEdge1 = fsa_worldEdge1, Cross = fsa_Cross; - var dmin = Infinity; + var dmin = Number.MAX_VALUE; var hullA = this; var curPlaneTests=0; - var numFacesA = faceListA ? faceListA.length : hullA.faces.length; - - // Test normals from hullA - for(var i=0; i<numFacesA; i++){ - var fi = faceListA ? faceListA[i] : i; - // Get world face normal - faceANormalWS3.copy(hullA.faceNormals[fi]); - quatA.vmult(faceANormalWS3,faceANormalWS3); - //posA.vadd(faceANormalWS3,faceANormalWS3); // Needed? - //console.log("face normal:",hullA.faceNormals[fi].toString(),"world face normal:",faceANormalWS3); - var d = hullA.testSepAxis(faceANormalWS3, hullB, posA, quatA, posB, quatB); - if(d===false){ - return false; + + if(!hullA.uniqueAxes){ + + var numFacesA = faceListA ? faceListA.length : hullA.faces.length; + + // Test face normals from hullA + for(var i=0; i<numFacesA; i++){ + var fi = faceListA ? faceListA[i] : i; + + // Get world face normal + faceANormalWS3.copy(hullA.faceNormals[fi]); + quatA.vmult(faceANormalWS3,faceANormalWS3); + + var d = hullA.testSepAxis(faceANormalWS3, hullB, posA, quatA, posB, quatB); + if(d===false){ + return false; + } + + if(d<dmin){ + dmin = d; + target.copy(faceANormalWS3); + } } - if(d<dmin){ - dmin = d; - target.copy(faceANormalWS3); + } else { + + // Test unique axes + for(var i = 0; i !== hullA.uniqueAxes.length; i++){ + + // Get world axis + quatA.vmult(hullA.uniqueAxes[i],faceANormalWS3); + + var d = hullA.testSepAxis(faceANormalWS3, hullB, posA, quatA, posB, quatB); + if(d===false){ + return false; + } + + if(d<dmin){ + dmin = d; + target.copy(faceANormalWS3); + } } } - // Test normals from hullB - var numFacesB = faceListB ? faceListB.length : hullB.faces.length; - for(var i=0;i<numFacesB;i++){ + if(!hullB.uniqueAxes){ - var fi = faceListB ? faceListB[i] : i; + // Test face normals from hullB + var numFacesB = faceListB ? faceListB.length : hullB.faces.length; + for(var i=0;i<numFacesB;i++){ - Worldnormal1.copy(hullB.faceNormals[fi]); - quatB.vmult(Worldnormal1,Worldnormal1); - //posB.vadd(Worldnormal1,Worldnormal1); - //console.log("facenormal",hullB.faceNormals[fi].toString(),"world:",Worldnormal1.toString()); - curPlaneTests++; - var d = hullA.testSepAxis(Worldnormal1, hullB,posA,quatA,posB,quatB); - if(d===false){ - return false; + var fi = faceListB ? faceListB[i] : i; + + Worldnormal1.copy(hullB.faceNormals[fi]); + quatB.vmult(Worldnormal1,Worldnormal1); + curPlaneTests++; + var d = hullA.testSepAxis(Worldnormal1, hullB,posA,quatA,posB,quatB); + if(d===false){ + return false; + } + + if(d<dmin){ + dmin = d; + target.copy(Worldnormal1); + } } + } else { - if(d<dmin){ - dmin = d; - target.copy(Worldnormal1); + // Test unique axes in B + for(var i = 0; i !== hullB.uniqueAxes.length; i++){ + quatB.vmult(hullB.uniqueAxes[i],Worldnormal1); + + curPlaneTests++; + var d = hullA.testSepAxis(Worldnormal1, hullB,posA,quatA,posB,quatB); + if(d===false){ + return false; + } + + if(d<dmin){ + dmin = d; + target.copy(Worldnormal1); + } } } - var edgeAstart,edgeAend,edgeBstart,edgeBend; - - var curEdgeEdge = 0; // Test edges - for(var e0=0; e0<hullA.uniqueEdges.length; e0++){ + for(var e0=0; e0 !== hullA.uniqueEdges.length; e0++){ + // Get world edge - worldEdge0.copy(hullA.uniqueEdges[e0]); - quatA.vmult(worldEdge0,worldEdge0); - //posA.vadd(worldEdge0,worldEdge0); // needed? + quatA.vmult(hullA.uniqueEdges[e0],worldEdge0); - //console.log("edge0:",worldEdge0.toString()); + for(var e1=0; e1 !== hullB.uniqueEdges.length; e1++){ - for(var e1=0; e1<hullB.uniqueEdges.length; e1++){ - worldEdge1.copy(hullB.uniqueEdges[e1]); - quatB.vmult(worldEdge1,worldEdge1); - //posB.vadd(worldEdge1,worldEdge1); // needed? - //console.log("edge1:",worldEdge1.toString()); + // Get world edge 2 + quatB.vmult(hullB.uniqueEdges[e1], worldEdge1); worldEdge0.cross(worldEdge1,Cross); - curEdgeEdge++; + if(!Cross.almostZero()){ Cross.normalize(); - var dist = hullA.testSepAxis( Cross, hullB, posA,quatA,posB,quatB); - if(dist===false){ + var dist = hullA.testSepAxis(Cross, hullB, posA, quatA, posB, quatB); + if(dist === false){ return false; } - if(dist<dmin){ + if(dist < dmin){ dmin = dist; target.copy(Cross); } @@ -539,9 +508,12 @@

    File: src/shapes/ConvexPolyhedron.js

    if((deltaC.dot(target))>0.0){ target.negate(target); } + return true; }; +var maxminA=[], maxminB=[]; + /** * Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one. * @method testSepAxis @@ -551,10 +523,10 @@

    File: src/shapes/ConvexPolyhedron.js

    * @param {Quaternion} quatA * @param {Vec3} posB * @param {Quaternion} quatB - * @return {float} The overlap depth, or FALSE if no penetration. + * @return {number} The overlap depth, or FALSE if no penetration. */ ConvexPolyhedron.prototype.testSepAxis = function(axis, hullB, posA, quatA, posB, quatB){ - var maxminA=[], maxminB=[], hullA=this; + var hullA=this; ConvexPolyhedron.project(hullA, axis, posA, quatA, maxminA); ConvexPolyhedron.project(hullB, axis, posB, quatB, maxminB); var maxA = maxminA[0]; @@ -562,7 +534,6 @@

    File: src/shapes/ConvexPolyhedron.js

    var maxB = maxminB[0]; var minB = maxminB[1]; if(maxA<minB || maxB<minA){ - //console.log(minA,maxA,minB,maxB); return false; // Separated } var d0 = maxA - minB; @@ -624,13 +595,6 @@

    File: src/shapes/ConvexPolyhedron.js

    cfah_localPlaneNormal = new Vec3(), cfah_planeNormalWS = new Vec3(); ConvexPolyhedron.prototype.clipFaceAgainstHull = function(separatingNormal, posA, quatA, worldVertsB1, minDist, maxDist,result){ - if(!(separatingNormal instanceof Vec3)){ - throw new Error("sep normal must be vector"); - } - if(!(worldVertsB1 instanceof Array)){ - throw new Error("world verts must be array"); - } - var faceANormalWS = cfah_faceANormalWS, edge0 = cfah_edge0, WorldEdge0 = cfah_WorldEdge0, @@ -640,15 +604,13 @@

    File: src/shapes/ConvexPolyhedron.js

    localPlaneNormal = cfah_localPlaneNormal, planeNormalWS = cfah_planeNormalWS; - minDist = Number(minDist); - maxDist = Number(maxDist); var hullA = this; var worldVertsB2 = []; var pVtxIn = worldVertsB1; var pVtxOut = worldVertsB2; // Find the face with normal closest to the separating axis var closestFaceA = -1; - var dmin = Infinity; + var dmin = Number.MAX_VALUE; for(var face=0; face<hullA.faces.length; face++){ faceANormalWS.copy(hullA.faceNormals[face]); quatA.vmult(faceANormalWS,faceANormalWS); @@ -659,8 +621,8 @@

    File: src/shapes/ConvexPolyhedron.js

    closestFaceA = face; } } - if (closestFaceA<0){ - console.log("--- did not find any closest face... ---"); + if (closestFaceA < 0){ + // console.log("--- did not find any closest face... ---"); return; } //console.log("closest A: ",closestFaceA); @@ -767,15 +729,6 @@

    File: src/shapes/ConvexPolyhedron.js

    * @param {Number} planeConstant The constant in the mathematical plane equation */ ConvexPolyhedron.prototype.clipFaceAgainstPlane = function(inVertices,outVertices, planeNormal, planeConstant){ - if(!(planeNormal instanceof Vec3)){ - throw new Error("planeNormal must be Vec3, "+planeNormal+" given"); - } - if(!(inVertices instanceof Array)) { - throw new Error("invertices must be Array, "+inVertices+" given"); - } - if(!(outVertices instanceof Array)){ - throw new Error("outvertices must be Array, "+outVertices+" given"); - } var n_dot_first, n_dot_last; var numVerts = inVertices.length; @@ -1109,7 +1062,6 @@

    File: src/shapes/ConvexPolyhedron.js

    -
    diff --git a/docs/files/src_shapes_Cylinder.js.html b/docs/files/src_shapes_Cylinder.js.html index 719a016e0..5cc7235fb 100644 --- a/docs/files/src_shapes_Cylinder.js.html +++ b/docs/files/src_shapes_Cylinder.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Cylinder.js

    +

    File: src/shapes/Cylinder.js

    @@ -202,7 +153,7 @@ 

    File: src/shapes/Cylinder.js

    function Cylinder( radiusTop, radiusBottom, height , numSegments ) { var N = numSegments, verts = [], - normals = [], + axes = [], faces = [], bottomface = [], topface = [], @@ -235,20 +186,20 @@

    File: src/shapes/Cylinder.js

    radiusTop*sin(theta), height*0.5)); topface.push(2*i+3); - // Normal - normals.push(new Vec3(cos(thetaN), - sin(thetaN), - 0)); + // Face faces.push([2*i+2, 2*i+3, 2*i+1,2*i]); } else { faces.push([0,1, 2*i+1, 2*i]); // Connect - // Normal - normals.push(new Vec3(cos(thetaN),sin(thetaN),0)); + } + + // Axis: we can cut off half of them if we have even number of segments + if(N % 2 === 1 || i < N / 2){ + axes.push(new Vec3(cos(thetaN), sin(thetaN), 0)); } } faces.push(topface); - normals.push(new Vec3(0,0,1)); + axes.push(new Vec3(0,0,1)); // Reorder bottom face var temp = []; @@ -256,17 +207,15 @@

    File: src/shapes/Cylinder.js

    temp.push(bottomface[bottomface.length - i - 1]); } faces.push(temp); - normals.push(new Vec3(0,0,-1)); this.type = Shape.types.CONVEXPOLYHEDRON; - ConvexPolyhedron.call( this, verts, faces, normals ); + ConvexPolyhedron.call( this, verts, faces, axes ); } Cylinder.prototype = new ConvexPolyhedron();
    -
    diff --git a/docs/files/src_shapes_Heightfield.js.html b/docs/files/src_shapes_Heightfield.js.html index e1307f5fc..f3829f6a7 100644 --- a/docs/files/src_shapes_Heightfield.js.html +++ b/docs/files/src_shapes_Heightfield.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Heightfield.js

    +

    File: src/shapes/Heightfield.js

    @@ -282,8 +233,8 @@ 

    File: src/shapes/Heightfield.js

    }; /** - * @method updateMinValue * Update the .minValue property + * @method updateMinValue */ Heightfield.prototype.updateMinValue = function(){ var data = this.data; @@ -359,8 +310,8 @@

    File: src/shapes/Heightfield.js

    // Get max and min of the data var data = this.data, max = this.minValue; // Set first value - for(var i = iMinX; i < iMaxX; i++){ - for(var j = iMinY; j < iMaxY; j++){ + for(var i = iMinX; i <= iMaxX; i++){ + for(var j = iMinY; j <= iMaxY; j++){ var height = data[i][j]; if(height > max){ max = height; @@ -412,7 +363,7 @@

    File: src/shapes/Heightfield.js

    var idx = []; this.getIndexOfPosition(x, y, idx, edgeClamp); - // TODO: do it better + // TODO: get upper or lower triangle, then use barycentric interpolation to get the height in the triangle. var minmax = []; this.getRectMinMax(idx[0], idx[1] + 1, idx[0], idx[1] + 1, minmax); @@ -666,9 +617,9 @@

    File: src/shapes/Heightfield.js

    s = this.elementSize; this.boundingSphereRadius = new Vec3(data.length * s, data[0].length * s, Math.max(Math.abs(this.maxValue), Math.abs(this.minValue))).norm(); }; +
    -
    diff --git a/docs/files/src_shapes_Particle.js.html b/docs/files/src_shapes_Particle.js.html index 0f7c99161..1cb4c384d 100644 --- a/docs/files/src_shapes_Particle.js.html +++ b/docs/files/src_shapes_Particle.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Particle.js

    +

    File: src/shapes/Particle.js

    @@ -230,7 +181,6 @@ 

    File: src/shapes/Particle.js

    -
    diff --git a/docs/files/src_shapes_Plane.js.html b/docs/files/src_shapes_Plane.js.html index 2d7defb30..df40e3818 100644 --- a/docs/files/src_shapes_Plane.js.html +++ b/docs/files/src_shapes_Plane.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Plane.js

    +

    File: src/shapes/Plane.js

    @@ -246,7 +197,6 @@ 

    File: src/shapes/Plane.js

    };
    -
    diff --git a/docs/files/src_shapes_Shape.js.html b/docs/files/src_shapes_Shape.js.html index c7b67462f..ae9229e94 100644 --- a/docs/files/src_shapes_Shape.js.html +++ b/docs/files/src_shapes_Shape.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Shape.js

    +

    File: src/shapes/Shape.js

    @@ -198,6 +149,12 @@ 

    File: src/shapes/Shape.js

    */ function Shape(){ + /** + * Identifyer of the Shape. + * @property {number} id + */ + this.id = Shape.idCounter++; + /** * The type of this shape. Must be set to an int > 0 by subclasses. * @property type @@ -217,6 +174,11 @@

    File: src/shapes/Shape.js

    * @property {boolean} collisionResponse */ this.collisionResponse = true; + + /** + * @property {Material} material + */ + this.material = null; } Shape.prototype.constructor = Shape; @@ -248,6 +210,8 @@

    File: src/shapes/Shape.js

    throw "calculateLocalInertia() not implemented for shape type "+this.type; }; +Shape.idCounter = 0; + /** * The available shape types. * @static @@ -262,13 +226,13 @@

    File: src/shapes/Shape.js

    CONVEXPOLYHEDRON:16, HEIGHTFIELD:32, PARTICLE:64, - CYLINDER:128 + CYLINDER:128, + TRIMESH:256 };
    -
    diff --git a/docs/files/src_shapes_Sphere.js.html b/docs/files/src_shapes_Sphere.js.html index aef83409f..f0edd3bdb 100644 --- a/docs/files/src_shapes_Sphere.js.html +++ b/docs/files/src_shapes_Sphere.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/shapes/Sphere.js

    +

    File: src/shapes/Sphere.js

    @@ -192,7 +143,7 @@ 

    File: src/shapes/Sphere.js

    * @class Sphere * @constructor * @extends Shape - * @param {Number} radius + * @param {Number} radius The radius of the sphere, a non-negative number. * @author schteppe / http://github.com/schteppe */ function Sphere(radius){ @@ -204,6 +155,10 @@

    File: src/shapes/Sphere.js

    this.radius = radius!==undefined ? Number(radius) : 1.0; this.type = Shape.types.SPHERE; + if(this.radius < 0){ + throw new Error('The sphere radius cannot be negative.'); + } + this.updateBoundingSphereRadius(); } Sphere.prototype = new Shape(); @@ -238,7 +193,6 @@

    File: src/shapes/Sphere.js

    -
    diff --git a/docs/files/src_shapes_Trimesh.js.html b/docs/files/src_shapes_Trimesh.js.html new file mode 100644 index 000000000..3a8ebbb14 --- /dev/null +++ b/docs/files/src_shapes_Trimesh.js.html @@ -0,0 +1,714 @@ + + + + + src/shapes/Trimesh.js - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/shapes/Trimesh.js

    + +
    +
    +module.exports = Trimesh;
    +
    +var Shape = require('./Shape');
    +var Vec3 = require('../math/Vec3');
    +var Quaternion = require('../math/Quaternion');
    +var Transform = require('../math/Transform');
    +var AABB = require('../collision/AABB');
    +var Octree = require('../utils/Octree');
    +
    +/**
    + * @class Trimesh
    + * @constructor
    + * @param {array} vertices
    + * @param {array} indices
    + * @extends Shape
    + * @example
    + *     // How to make a mesh with a single triangle
    + *     var vertices = [
    + *         0, 0, 0, // vertex 0
    + *         1, 0, 0, // vertex 1
    + *         0, 1, 0  // vertex 2
    + *     ];
    + *     var indices = [
    + *         0, 1, 2  // triangle 0
    + *     ];
    + *     var trimeshShape = new Trimesh(vertices, indices);
    + */
    +function Trimesh(vertices, indices) {
    +    Shape.call(this);
    +    this.type = Shape.types.TRIMESH;
    +
    +    /**
    +     * @property vertices
    +     * @type {Array}
    +     */
    +    this.vertices = new Float32Array(vertices);
    +
    +    /**
    +     * Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles.
    +     * @property indices
    +     * @type {Array}
    +     */
    +    this.indices = new Int16Array(indices);
    +
    +    /**
    +     * The normals data.
    +     * @property normals
    +     * @type {Array}
    +     */
    +    this.normals = new Float32Array(indices.length);
    +
    +    /**
    +     * The local AABB of the mesh.
    +     * @property aabb
    +     * @type {Array}
    +     */
    +    this.aabb = new AABB();
    +
    +    /**
    +     * References to vertex pairs, making up all unique edges in the trimesh.
    +     * @property {array} edges
    +     */
    +    this.edges = null;
    +
    +    /**
    +     * Local scaling of the mesh. Use .setScale() to set it.
    +     * @property {Vec3} scale
    +     */
    +    this.scale = new Vec3(1, 1, 1);
    +
    +    /**
    +     * The indexed triangles. Use .updateTree() to update it.
    +     * @property {Octree} tree
    +     */
    +    this.tree = new Octree();
    +
    +    this.updateEdges();
    +    this.updateNormals();
    +    this.updateAABB();
    +    this.updateBoundingSphereRadius();
    +    this.updateTree();
    +}
    +Trimesh.prototype = new Shape();
    +Trimesh.prototype.constructor = Trimesh;
    +
    +var computeNormals_n = new Vec3();
    +
    +/**
    + * @method updateTree
    + */
    +Trimesh.prototype.updateTree = function(){
    +    var tree = this.tree;
    +
    +    tree.reset();
    +    tree.aabb.copy(this.aabb);
    +    var scale = this.scale; // The local mesh AABB is scaled, but the octree AABB should be unscaled
    +    tree.aabb.lowerBound.x *= 1 / scale.x;
    +    tree.aabb.lowerBound.y *= 1 / scale.y;
    +    tree.aabb.lowerBound.z *= 1 / scale.z;
    +    tree.aabb.upperBound.x *= 1 / scale.x;
    +    tree.aabb.upperBound.y *= 1 / scale.y;
    +    tree.aabb.upperBound.z *= 1 / scale.z;
    +
    +    // Insert all triangles
    +    var triangleAABB = new AABB();
    +    var a = new Vec3();
    +    var b = new Vec3();
    +    var c = new Vec3();
    +    var points = [a, b, c];
    +    for (var i = 0; i < this.indices.length / 3; i++) {
    +        //this.getTriangleVertices(i, a, b, c);
    +
    +        // Get unscaled triangle verts
    +        var i3 = i * 3;
    +        this._getUnscaledVertex(this.indices[i3], a);
    +        this._getUnscaledVertex(this.indices[i3 + 1], b);
    +        this._getUnscaledVertex(this.indices[i3 + 2], c);
    +
    +        triangleAABB.setFromPoints(points);
    +        tree.insert(triangleAABB, i);
    +    }
    +    tree.removeEmptyNodes();
    +};
    +
    +var unscaledAABB = new AABB();
    +
    +/**
    + * Get triangles in a local AABB from the trimesh.
    + * @method getTrianglesInAABB
    + * @param  {AABB} aabb
    + * @param  {array} result An array of integers, referencing the queried triangles.
    + */
    +Trimesh.prototype.getTrianglesInAABB = function(aabb, result){
    +    unscaledAABB.copy(aabb);
    +
    +    // Scale it to local
    +    var scale = this.scale;
    +    var isx = scale.x;
    +    var isy = scale.y;
    +    var isz = scale.z;
    +    var l = unscaledAABB.lowerBound;
    +    var u = unscaledAABB.upperBound;
    +    l.x /= isx;
    +    l.y /= isy;
    +    l.z /= isz;
    +    u.x /= isx;
    +    u.y /= isy;
    +    u.z /= isz;
    +
    +    return this.tree.aabbQuery(unscaledAABB, result);
    +};
    +
    +/**
    + * @method setScale
    + * @param {Vec3} scale
    + */
    +Trimesh.prototype.setScale = function(scale){
    +    var wasUniform = this.scale.x === this.scale.y === this.scale.z;
    +    var isUniform = scale.x === scale.y === scale.z;
    +
    +    if(!(wasUniform && isUniform)){
    +        // Non-uniform scaling. Need to update normals.
    +        this.updateNormals();
    +    }
    +    this.scale.copy(scale);
    +    this.updateAABB();
    +    this.updateBoundingSphereRadius();
    +};
    +
    +/**
    + * Compute the normals of the faces. Will save in the .normals array.
    + * @method updateNormals
    + */
    +Trimesh.prototype.updateNormals = function(){
    +    var n = computeNormals_n;
    +
    +    // Generate normals
    +    var normals = this.normals;
    +    for(var i=0; i < this.indices.length / 3; i++){
    +        var i3 = i * 3;
    +
    +        var a = this.indices[i3],
    +            b = this.indices[i3 + 1],
    +            c = this.indices[i3 + 2];
    +
    +        this.getVertex(a, va);
    +        this.getVertex(b, vb);
    +        this.getVertex(c, vc);
    +
    +        Trimesh.computeNormal(vb, va, vc, n);
    +
    +        normals[i3] = n.x;
    +        normals[i3 + 1] = n.y;
    +        normals[i3 + 2] = n.z;
    +    }
    +};
    +
    +/**
    + * Update the .edges property
    + * @method updateEdges
    + */
    +Trimesh.prototype.updateEdges = function(){
    +    var edges = {};
    +    var add = function(indexA, indexB){
    +        var key = a < b ? a + '_' + b : b + '_' + a;
    +        edges[key] = true;
    +    };
    +    for(var i=0; i < this.indices.length / 3; i++){
    +        var i3 = i * 3;
    +        var a = this.indices[i3],
    +            b = this.indices[i3 + 1],
    +            c = this.indices[i3 + 2];
    +        add(a,b);
    +        add(b,c);
    +        add(c,a);
    +    }
    +    var keys = Object.keys(edges);
    +    this.edges = new Int16Array(keys.length * 2);
    +    for (var i = 0; i < keys.length; i++) {
    +        var indices = keys[i].split('_');
    +        this.edges[2 * i] = parseInt(indices[0], 10);
    +        this.edges[2 * i + 1] = parseInt(indices[1], 10);
    +    }
    +};
    +
    +/**
    + * Get an edge vertex
    + * @method getEdgeVertex
    + * @param  {number} edgeIndex
    + * @param  {number} firstOrSecond 0 or 1, depending on which one of the vertices you need.
    + * @param  {Vec3} vertexStore Where to store the result
    + */
    +Trimesh.prototype.getEdgeVertex = function(edgeIndex, firstOrSecond, vertexStore){
    +    var vertexIndex = this.edges[edgeIndex * 2 + (firstOrSecond ? 1 : 0)];
    +    this.getVertex(vertexIndex, vertexStore);
    +};
    +
    +var getEdgeVector_va = new Vec3();
    +var getEdgeVector_vb = new Vec3();
    +
    +/**
    + * Get a vector along an edge.
    + * @method getEdgeVector
    + * @param  {number} edgeIndex
    + * @param  {Vec3} vectorStore
    + */
    +Trimesh.prototype.getEdgeVector = function(edgeIndex, vectorStore){
    +    var va = getEdgeVector_va;
    +    var vb = getEdgeVector_vb;
    +    this.getEdgeVertex(edgeIndex, 0, va);
    +    this.getEdgeVertex(edgeIndex, 1, vb);
    +    vb.vsub(va, vectorStore);
    +};
    +
    +/**
    + * Get face normal given 3 vertices
    + * @static
    + * @method computeNormal
    + * @param {Vec3} va
    + * @param {Vec3} vb
    + * @param {Vec3} vc
    + * @param {Vec3} target
    + */
    +var cb = new Vec3();
    +var ab = new Vec3();
    +Trimesh.computeNormal = function ( va, vb, vc, target ) {
    +    vb.vsub(va,ab);
    +    vc.vsub(vb,cb);
    +    cb.cross(ab,target);
    +    if ( !target.isZero() ) {
    +        target.normalize();
    +    }
    +};
    +
    +var va = new Vec3();
    +var vb = new Vec3();
    +var vc = new Vec3();
    +
    +/**
    + * Get vertex i.
    + * @method getVertex
    + * @param  {number} i
    + * @param  {Vec3} out
    + * @return {Vec3} The "out" vector object
    + */
    +Trimesh.prototype.getVertex = function(i, out){
    +    var scale = this.scale;
    +    this._getUnscaledVertex(i, out);
    +    out.x *= scale.x;
    +    out.y *= scale.y;
    +    out.z *= scale.z;
    +    return out;
    +};
    +
    +/**
    + * Get raw vertex i
    + * @private
    + * @method _getUnscaledVertex
    + * @param  {number} i
    + * @param  {Vec3} out
    + * @return {Vec3} The "out" vector object
    + */
    +Trimesh.prototype._getUnscaledVertex = function(i, out){
    +    var i3 = i * 3;
    +    var vertices = this.vertices;
    +    return out.set(
    +        vertices[i3],
    +        vertices[i3 + 1],
    +        vertices[i3 + 2]
    +    );
    +};
    +
    +/**
    + * Get a vertex from the trimesh,transformed by the given position and quaternion.
    + * @method getWorldVertex
    + * @param  {number} i
    + * @param  {Vec3} pos
    + * @param  {Quaternion} quat
    + * @param  {Vec3} out
    + * @return {Vec3} The "out" vector object
    + */
    +Trimesh.prototype.getWorldVertex = function(i, pos, quat, out){
    +    this.getVertex(i, out);
    +    Transform.pointToWorldFrame(pos, quat, out, out);
    +    return out;
    +};
    +
    +/**
    + * Get the three vertices for triangle i.
    + * @method getTriangleVertices
    + * @param  {number} i
    + * @param  {Vec3} a
    + * @param  {Vec3} b
    + * @param  {Vec3} c
    + */
    +Trimesh.prototype.getTriangleVertices = function(i, a, b, c){
    +    var i3 = i * 3;
    +    this.getVertex(this.indices[i3], a);
    +    this.getVertex(this.indices[i3 + 1], b);
    +    this.getVertex(this.indices[i3 + 2], c);
    +};
    +
    +/**
    + * Compute the normal of triangle i.
    + * @method getNormal
    + * @param  {Number} i
    + * @param  {Vec3} target
    + * @return {Vec3} The "target" vector object
    + */
    +Trimesh.prototype.getNormal = function(i, target){
    +    var i3 = i * 3;
    +    return target.set(
    +        this.normals[i3],
    +        this.normals[i3 + 1],
    +        this.normals[i3 + 2]
    +    );
    +};
    +
    +var cli_aabb = new AABB();
    +
    +/**
    + * @method calculateLocalInertia
    + * @param  {Number} mass
    + * @param  {Vec3} target
    + * @return {Vec3} The "target" vector object
    + */
    +Trimesh.prototype.calculateLocalInertia = function(mass,target){
    +    // Approximate with box inertia
    +    // Exact inertia calculation is overkill, but see http://geometrictools.com/Documentation/PolyhedralMassProperties.pdf for the correct way to do it
    +    this.computeLocalAABB(cli_aabb);
    +    var x = cli_aabb.upperBound.x - cli_aabb.lowerBound.x,
    +        y = cli_aabb.upperBound.y - cli_aabb.lowerBound.y,
    +        z = cli_aabb.upperBound.z - cli_aabb.lowerBound.z;
    +    return target.set(
    +        1.0 / 12.0 * mass * ( 2*y*2*y + 2*z*2*z ),
    +        1.0 / 12.0 * mass * ( 2*x*2*x + 2*z*2*z ),
    +        1.0 / 12.0 * mass * ( 2*y*2*y + 2*x*2*x )
    +    );
    +};
    +
    +var computeLocalAABB_worldVert = new Vec3();
    +
    +/**
    + * Compute the local AABB for the trimesh
    + * @method computeLocalAABB
    + * @param  {AABB} aabb
    + */
    +Trimesh.prototype.computeLocalAABB = function(aabb){
    +    var l = aabb.lowerBound,
    +        u = aabb.upperBound,
    +        n = this.vertices.length,
    +        vertices = this.vertices,
    +        v = computeLocalAABB_worldVert;
    +
    +    this.getVertex(0, v);
    +    l.copy(v);
    +    u.copy(v);
    +
    +    for(var i=0; i !== n; i++){
    +        this.getVertex(i, v);
    +
    +        if(v.x < l.x){
    +            l.x = v.x;
    +        } else if(v.x > u.x){
    +            u.x = v.x;
    +        }
    +
    +        if(v.y < l.y){
    +            l.y = v.y;
    +        } else if(v.y > u.y){
    +            u.y = v.y;
    +        }
    +
    +        if(v.z < l.z){
    +            l.z = v.z;
    +        } else if(v.z > u.z){
    +            u.z = v.z;
    +        }
    +    }
    +};
    +
    +
    +/**
    + * Update the .aabb property
    + * @method updateAABB
    + */
    +Trimesh.prototype.updateAABB = function(){
    +    this.computeLocalAABB(this.aabb);
    +};
    +
    +/**
    + * Will update the .boundingSphereRadius property
    + * @method updateBoundingSphereRadius
    + */
    +Trimesh.prototype.updateBoundingSphereRadius = function(){
    +    // Assume points are distributed with local (0,0,0) as center
    +    var max2 = 0;
    +    var vertices = this.vertices;
    +    var v = new Vec3();
    +    for(var i=0, N=vertices.length / 3; i !== N; i++) {
    +        this.getVertex(i, v);
    +        var norm2 = v.norm2();
    +        if(norm2 > max2){
    +            max2 = norm2;
    +        }
    +    }
    +    this.boundingSphereRadius = Math.sqrt(max2);
    +};
    +
    +var tempWorldVertex = new Vec3();
    +var calculateWorldAABB_frame = new Transform();
    +var calculateWorldAABB_aabb = new AABB();
    +
    +/**
    + * @method calculateWorldAABB
    + * @param {Vec3}        pos
    + * @param {Quaternion}  quat
    + * @param {Vec3}        min
    + * @param {Vec3}        max
    + */
    +Trimesh.prototype.calculateWorldAABB = function(pos,quat,min,max){
    +    /*
    +    var n = this.vertices.length / 3,
    +        verts = this.vertices;
    +    var minx,miny,minz,maxx,maxy,maxz;
    +
    +    var v = tempWorldVertex;
    +    for(var i=0; i<n; i++){
    +        this.getVertex(i, v);
    +        quat.vmult(v, v);
    +        pos.vadd(v, v);
    +        if (v.x < minx || minx===undefined){
    +            minx = v.x;
    +        } else if(v.x > maxx || maxx===undefined){
    +            maxx = v.x;
    +        }
    +
    +        if (v.y < miny || miny===undefined){
    +            miny = v.y;
    +        } else if(v.y > maxy || maxy===undefined){
    +            maxy = v.y;
    +        }
    +
    +        if (v.z < minz || minz===undefined){
    +            minz = v.z;
    +        } else if(v.z > maxz || maxz===undefined){
    +            maxz = v.z;
    +        }
    +    }
    +    min.set(minx,miny,minz);
    +    max.set(maxx,maxy,maxz);
    +    */
    +
    +    // Faster approximation using local AABB
    +    var frame = calculateWorldAABB_frame;
    +    var result = calculateWorldAABB_aabb;
    +    frame.position = pos;
    +    frame.quaternion = quat;
    +    this.aabb.toWorldFrame(frame, result);
    +    min.copy(result.lowerBound);
    +    max.copy(result.upperBound);
    +};
    +
    +/**
    + * Get approximate volume
    + * @method volume
    + * @return {Number}
    + */
    +Trimesh.prototype.volume = function(){
    +    return 4.0 * Math.PI * this.boundingSphereRadius / 3.0;
    +};
    +
    +/**
    + * Create a Trimesh instance, shaped as a torus.
    + * @static
    + * @method createTorus
    + * @param  {number} [radius=1]
    + * @param  {number} [tube=0.5]
    + * @param  {number} [radialSegments=8]
    + * @param  {number} [tubularSegments=6]
    + * @param  {number} [arc=6.283185307179586]
    + * @return {Trimesh} A torus
    + */
    +Trimesh.createTorus = function (radius, tube, radialSegments, tubularSegments, arc) {
    +    radius = radius || 1;
    +    tube = tube || 0.5;
    +    radialSegments = radialSegments || 8;
    +    tubularSegments = tubularSegments || 6;
    +    arc = arc || Math.PI * 2;
    +
    +    var vertices = [];
    +    var indices = [];
    +
    +    for ( var j = 0; j <= radialSegments; j ++ ) {
    +        for ( var i = 0; i <= tubularSegments; i ++ ) {
    +            var u = i / tubularSegments * arc;
    +            var v = j / radialSegments * Math.PI * 2;
    +
    +            var x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
    +            var y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
    +            var z = tube * Math.sin( v );
    +
    +            vertices.push( x, y, z );
    +        }
    +    }
    +
    +    for ( var j = 1; j <= radialSegments; j ++ ) {
    +        for ( var i = 1; i <= tubularSegments; i ++ ) {
    +            var a = ( tubularSegments + 1 ) * j + i - 1;
    +            var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
    +            var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
    +            var d = ( tubularSegments + 1 ) * j + i;
    +
    +            indices.push(a, b, d);
    +            indices.push(b, c, d);
    +        }
    +    }
    +
    +    return new Trimesh(vertices, indices);
    +};
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_solver_GSSolver.js.html b/docs/files/src_solver_GSSolver.js.html index b6eb6bdff..c24b59c24 100644 --- a/docs/files/src_solver_GSSolver.js.html +++ b/docs/files/src_solver_GSSolver.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/solver/GSSolver.js

    +

    File: src/solver/GSSolver.js

    @@ -213,7 +164,7 @@ 

    File: src/solver/GSSolver.js

    * @property tolerance * @type {Number} */ - this.tolerance = 0; + this.tolerance = 1e-7; } GSSolver.prototype = new Solver(); @@ -318,7 +269,6 @@

    File: src/solver/GSSolver.js

    -
    diff --git a/docs/files/src_solver_Solver.js.html b/docs/files/src_solver_Solver.js.html index cb7cd794e..68413119e 100644 --- a/docs/files/src_solver_Solver.js.html +++ b/docs/files/src_solver_Solver.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/solver/Solver.js

    +

    File: src/solver/Solver.js

    @@ -244,7 +195,6 @@ 

    File: src/solver/Solver.js

    -
    diff --git a/docs/files/src_solver_SplitSolver.js.html b/docs/files/src_solver_SplitSolver.js.html index 6b66ba94a..5befd8b6c 100644 --- a/docs/files/src_solver_SplitSolver.js.html +++ b/docs/files/src_solver_SplitSolver.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/solver/SplitSolver.js

    +

    File: src/solver/SplitSolver.js

    @@ -198,15 +149,69 @@ 

    File: src/solver/SplitSolver.js

    */ function SplitSolver(subsolver){ Solver.call(this); + this.iterations = 10; + this.tolerance = 1e-7; this.subsolver = subsolver; + this.nodes = []; + this.nodePool = []; + + // Create needed nodes, reuse if possible + while(this.nodePool.length < 128){ + this.nodePool.push(this.createNode()); + } } SplitSolver.prototype = new Solver(); // Returns the number of subsystems var SplitSolver_solve_nodes = []; // All allocated node objects +var SplitSolver_solve_nodePool = []; // All allocated node objects var SplitSolver_solve_eqs = []; // Temp array var SplitSolver_solve_bds = []; // Temp array -var SplitSolver_solve_dummyWorld = {bodies:null}; // Temp object +var SplitSolver_solve_dummyWorld = {bodies:[]}; // Temp object + +var STATIC = Body.STATIC; +function getUnvisitedNode(nodes){ + var Nnodes = nodes.length; + for(var i=0; i!==Nnodes; i++){ + var node = nodes[i]; + if(!node.visited && !(node.body.type & STATIC)){ + return node; + } + } + return false; +} + +var queue = []; +function bfs(root,visitFunc,bds,eqs){ + queue.push(root); + root.visited = true; + visitFunc(root,bds,eqs); + while(queue.length) { + var node = queue.pop(); + // Loop over unvisited child nodes + var child; + while((child = getUnvisitedNode(node.children))) { + child.visited = true; + visitFunc(child,bds,eqs); + queue.push(child); + } + } +} + +function visitFunc(node,bds,eqs){ + bds.push(node.body); + var Neqs = node.eqs.length; + for(var i=0; i!==Neqs; i++){ + var eq = node.eqs[i]; + if(eqs.indexOf(eq) === -1){ + eqs.push(eq); + } + } +} + +SplitSolver.prototype.createNode = function(){ + return { body:null, children:[], eqs:[], visited:false }; +}; /** * Solve the subsystems @@ -216,17 +221,20 @@

    File: src/solver/SplitSolver.js

    */ SplitSolver.prototype.solve = function(dt,world){ var nodes=SplitSolver_solve_nodes, + nodePool=this.nodePool, bodies=world.bodies, equations=this.equations, Neq=equations.length, Nbodies=bodies.length, subsolver=this.subsolver; + // Create needed nodes, reuse if possible - if(nodes.length>Nbodies){ - nodes.length = Nbodies; + while(nodePool.length < Nbodies){ + nodePool.push(this.createNode()); } - while(nodes.length<Nbodies){ - nodes.push({ body:null, children:[], eqs:[], visited:false }); + nodes.length = Nbodies; + for (var i = 0; i < Nbodies; i++) { + nodes[i] = nodePool[i]; } // Reset node values @@ -249,58 +257,25 @@

    File: src/solver/SplitSolver.js

    nj.eqs.push(eq); } - var STATIC = Body.STATIC; - function getUnvisitedNode(nodes){ - var Nnodes = nodes.length; - for(var i=0; i!==Nnodes; i++){ - var node = nodes[i]; - if(!node.visited && !(node.body.type & STATIC)){ - return node; - } - } - return false; - } + var child, n=0, eqs=SplitSolver_solve_eqs; - function bfs(root,visitFunc){ - var queue = []; - queue.push(root); - root.visited = true; - visitFunc(root); - while(queue.length) { - var node = queue.pop(); - // Loop over unvisited child nodes - var child; - while((child = getUnvisitedNode(node.children))) { - child.visited = true; - visitFunc(child); - queue.push(child); - } - } - } + subsolver.tolerance = this.tolerance; + subsolver.iterations = this.iterations; - var child, n=0, eqs=SplitSolver_solve_eqs, bds=SplitSolver_solve_bds; - function visitFunc(node){ - bds.push(node.body); - var Neqs = node.eqs.length; - for(var i=0; i!==Neqs; i++){ - var eq = node.eqs[i]; - if(eqs.indexOf(eq) === -1){ - eqs.push(eq); - } - } - } var dummyWorld = SplitSolver_solve_dummyWorld; while((child = getUnvisitedNode(nodes))){ eqs.length = 0; - bds.length = 0; - bfs(child,visitFunc); + dummyWorld.bodies.length = 0; + bfs(child, visitFunc, dummyWorld.bodies, eqs); var Neqs = eqs.length; + + eqs = eqs.sort(sortById); + for(var i=0; i!==Neqs; i++){ subsolver.addEquation(eqs[i]); } - dummyWorld.bodies = bds; var iter = subsolver.solve(dt,dummyWorld); subsolver.removeAllEquations(); n++; @@ -309,9 +284,11 @@

    File: src/solver/SplitSolver.js

    return n; }; +function sortById(a, b){ + return b.id - a.id; +}
    -
    diff --git a/docs/files/src_utils_EventTarget.js.html b/docs/files/src_utils_EventTarget.js.html index 835054a42..b79aed4ea 100644 --- a/docs/files/src_utils_EventTarget.js.html +++ b/docs/files/src_utils_EventTarget.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/utils/EventTarget.js

    +

    File: src/utils/EventTarget.js

    @@ -272,7 +223,6 @@ 

    File: src/utils/EventTarget.js

    -
    diff --git a/docs/files/src_utils_Octree.js.html b/docs/files/src_utils_Octree.js.html new file mode 100644 index 000000000..e2feb5a57 --- /dev/null +++ b/docs/files/src_utils_Octree.js.html @@ -0,0 +1,387 @@ + + + + + src/utils/Octree.js - cannon + + + + + + + + +
    +
    +
    +

    +
    +
    + API Docs for: 0.6.1 +
    +
    +
    + + +
    +
    + Show: + + + + + + + +
    + +
    +
    +
    +

    File: src/utils/Octree.js

    + +
    +
    +var AABB = require('../collision/AABB');
    +var Vec3 = require('../math/Vec3');
    +
    +module.exports = Octree;
    +
    +/**
    + * @class OctreeNode
    + * @param {object} [options]
    + * @param {Octree} [options.root]
    + * @param {AABB} [options.aabb]
    + */
    +function OctreeNode(options){
    +    options = options || {};
    +
    +    /**
    +     * The root node
    +     * @property {OctreeNode} root
    +     */
    +    this.root = options.root || null;
    +
    +    /**
    +     * Boundary of this node
    +     * @property {AABB} aabb
    +     */
    +    this.aabb = options.aabb ? options.aabb.clone() : new AABB();
    +
    +    /**
    +     * Contained data at the current node level.
    +     * @property {Array} data
    +     */
    +    this.data = [];
    +
    +    /**
    +     * Children to this node
    +     * @property {Array} children
    +     */
    +    this.children = [];
    +}
    +
    +/**
    + * @class Octree
    + * @param {AABB} aabb The total AABB of the tree
    + * @param {object} [options]
    + * @param {number} [options.maxDepth=8]
    + * @extends OctreeNode
    + */
    +function Octree(aabb, options){
    +    options = options || {};
    +    options.root = null;
    +    options.aabb = aabb;
    +    OctreeNode.call(this, options);
    +
    +    /**
    +     * Maximum subdivision depth
    +     * @property {number} maxDepth
    +     */
    +    this.maxDepth = typeof(options.maxDepth) !== 'undefined' ? options.maxDepth : 8;
    +}
    +Octree.prototype = new OctreeNode();
    +
    +OctreeNode.prototype.reset = function(aabb, options){
    +    this.children.length = this.data.length = 0;
    +};
    +
    +/**
    + * Insert data into this node
    + * @method insert
    + * @param  {AABB} aabb
    + * @param  {object} elementData
    + * @return {boolean} True if successful, otherwise false
    + */
    +OctreeNode.prototype.insert = function(aabb, elementData, level){
    +    var nodeData = this.data;
    +    level = level || 0;
    +
    +    // Ignore objects that do not belong in this node
    +    if (!this.aabb.contains(aabb)){
    +        return false; // object cannot be added
    +    }
    +
    +    var children = this.children;
    +
    +    if(level < (this.maxDepth || this.root.maxDepth)){
    +        // Subdivide if there are no children yet
    +        var subdivided = false;
    +        if (!children.length){
    +            this.subdivide();
    +            subdivided = true;
    +        }
    +
    +        // add to whichever node will accept it
    +        for (var i = 0; i !== 8; i++) {
    +            if (children[i].insert(aabb, elementData, level + 1)){
    +                return true;
    +            }
    +        }
    +
    +        if(subdivided){
    +            // No children accepted! Might as well just remove em since they contain none
    +            children.length = 0;
    +        }
    +    }
    +
    +    // Too deep, or children didnt want it. add it in current node
    +    nodeData.push(elementData);
    +
    +    return true;
    +};
    +
    +var halfDiagonal = new Vec3();
    +
    +/**
    + * Create 8 equally sized children nodes and put them in the .children array.
    + * @method subdivide
    + */
    +OctreeNode.prototype.subdivide = function() {
    +    var aabb = this.aabb;
    +    var l = aabb.lowerBound;
    +    var u = aabb.upperBound;
    +
    +    var children = this.children;
    +
    +    children.push(
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(0,0,0) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(1,0,0) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(1,1,0) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(1,1,1) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(0,1,1) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(0,0,1) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(1,0,1) }) }),
    +        new OctreeNode({ aabb: new AABB({ lowerBound: new Vec3(0,1,0) }) })
    +    );
    +
    +    u.vsub(l, halfDiagonal);
    +    halfDiagonal.scale(0.5, halfDiagonal);
    +
    +    var root = this.root || this;
    +
    +    for (var i = 0; i !== 8; i++) {
    +        var child = children[i];
    +
    +        // Set current node as root
    +        child.root = root;
    +
    +        // Compute bounds
    +        var lowerBound = child.aabb.lowerBound;
    +        lowerBound.x *= halfDiagonal.x;
    +        lowerBound.y *= halfDiagonal.y;
    +        lowerBound.z *= halfDiagonal.z;
    +
    +        lowerBound.vadd(l, lowerBound);
    +
    +        // Upper bound is always lower bound + halfDiagonal
    +        lowerBound.vadd(halfDiagonal, child.aabb.upperBound);
    +    }
    +};
    +
    +/**
    + * Get all data, potentially within an AABB
    + * @method aabbQuery
    + * @param  {AABB} aabb
    + * @param  {array} result
    + * @return {array} The "result" object
    + */
    +OctreeNode.prototype.aabbQuery = function(aabb, result) {
    +
    +    var nodeData = this.data;
    +
    +    // abort if the range does not intersect this node
    +    // if (!this.aabb.overlaps(aabb)){
    +    //     return result;
    +    // }
    +
    +    // Add objects at this level
    +    // Array.prototype.push.apply(result, nodeData);
    +
    +    // Add child data
    +    // @todo unwrap recursion into a queue / loop, that's faster in JS
    +    var children = this.children;
    +
    +
    +    // for (var i = 0, N = this.children.length; i !== N; i++) {
    +    //     children[i].aabbQuery(aabb, result);
    +    // }
    +
    +    var queue = [this];
    +    while (queue.length) {
    +        var node = queue.pop();
    +        if (node.aabb.overlaps(aabb)){
    +            Array.prototype.push.apply(result, node.data);
    +        }
    +        Array.prototype.push.apply(queue, node.children);
    +    }
    +
    +    return result;
    +};
    +
    +var tmpAABB = new AABB();
    +
    +/**
    + * Get all data, potentially intersected by a ray.
    + * @method rayQuery
    + * @param  {Ray} ray
    + * @param  {Transform} treeTransform
    + * @param  {array} result
    + * @return {array} The "result" object
    + */
    +OctreeNode.prototype.rayQuery = function(ray, treeTransform, result) {
    +
    +    // Use aabb query for now.
    +    // @todo implement real ray query which needs less lookups
    +    ray.getAABB(tmpAABB);
    +    tmpAABB.toLocalFrame(treeTransform, tmpAABB);
    +    this.aabbQuery(tmpAABB, result);
    +
    +    return result;
    +};
    +
    +/**
    + * @method removeEmptyNodes
    + */
    +OctreeNode.prototype.removeEmptyNodes = function() {
    +    var queue = [this];
    +    while (queue.length) {
    +        var node = queue.pop();
    +        for (var i = node.children.length - 1; i >= 0; i--) {
    +            if(!node.children[i].data.length){
    +                node.children.splice(i, 1);
    +            }
    +        }
    +        Array.prototype.push.apply(queue, node.children);
    +    }
    +};
    +
    +    
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/docs/files/src_utils_Pool.js.html b/docs/files/src_utils_Pool.js.html index 727406ea3..11a40eb1d 100644 --- a/docs/files/src_utils_Pool.js.html +++ b/docs/files/src_utils_Pool.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/utils/Pool.js

    +

    File: src/utils/Pool.js

    @@ -239,7 +190,6 @@ 

    File: src/utils/Pool.js

    -
    diff --git a/docs/files/src_utils_TupleDictionary.js.html b/docs/files/src_utils_TupleDictionary.js.html index 0a7f1c3fc..877b433fb 100644 --- a/docs/files/src_utils_TupleDictionary.js.html +++ b/docs/files/src_utils_TupleDictionary.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/utils/TupleDictionary.js

    +

    File: src/utils/TupleDictionary.js

    @@ -250,7 +201,6 @@ 

    File: src/utils/TupleDictionary.js

    -
    diff --git a/docs/files/src_utils_Utils.js.html b/docs/files/src_utils_Utils.js.html index dd8d883ff..3f2349507 100644 --- a/docs/files/src_utils_Utils.js.html +++ b/docs/files/src_utils_Utils.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/utils/Utils.js

    +

    File: src/utils/Utils.js

    @@ -208,7 +159,6 @@ 

    File: src/utils/Utils.js

    -
    diff --git a/docs/files/src_utils_Vec3Pool.js.html b/docs/files/src_utils_Vec3Pool.js.html index c3b733b8a..71be0ff53 100644 --- a/docs/files/src_utils_Vec3Pool.js.html +++ b/docs/files/src_utils_Vec3Pool.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -

    File: src/utils/Vec3Pool.js

    +

    File: src/utils/Vec3Pool.js

    @@ -209,7 +160,6 @@ 

    File: src/utils/Vec3Pool.js

    -
    diff --git a/docs/files/src_world_Narrowphase.js.html b/docs/files/src_world_Narrowphase.js.html index 4da6629a4..07cd1bd0c 100644 --- a/docs/files/src_world_Narrowphase.js.html +++ b/docs/files/src_world_Narrowphase.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,164 +25,119 @@

    -
    -
    - -
    -
    -
    -
    - Show: - - - - - - - -
    - -
    -

    File: src/world/Narrowphase.js

    +

    File: src/world/Narrowphase.js

     module.exports = Narrowphase;
     
    +var AABB = require('../collision/AABB');
     var Shape = require('../shapes/Shape');
    +var Ray = require('../collision/Ray');
     var Vec3 = require('../math/Vec3');
     var Transform = require('../math/Transform');
     var ConvexPolyhedron = require('../shapes/ConvexPolyhedron');
    @@ -192,6 +145,7 @@ 

    File: src/world/Narrowphase.js

    var Solver = require('../solver/Solver'); var Vec3Pool = require('../utils/Vec3Pool'); var ContactEquation = require('../equations/ContactEquation'); +var FrictionEquation = require('../equations/FrictionEquation'); /** * Helper class for the World. Generates ContactEquations. @@ -201,7 +155,7 @@

    File: src/world/Narrowphase.js

    * @todo Contact reduction * @todo should move methods to prototype */ -function Narrowphase(){ +function Narrowphase(world){ /** * Internal storage of pooled contact points. @@ -209,19 +163,32 @@

    File: src/world/Narrowphase.js

    */ this.contactPointPool = []; + this.frictionEquationPool = []; + + this.result = []; + this.frictionResult = []; + /** * Pooled vectors. * @property {Vec3Pool} v3pool */ this.v3pool = new Vec3Pool(); + + this.world = world; + this.currentContactMaterial = null; + + /** + * @property {Boolean} enableFrictionReduction + */ + this.enableFrictionReduction = false; } /** * Make a contact object, by using the internal pool or creating a new one. - * @method makeResult + * @method createContactEquation * @return {ContactEquation} */ -Narrowphase.prototype.makeResult = function(bi, bj, si, sj, rsi, rsj){ +Narrowphase.prototype.createContactEquation = function(bi, bj, si, sj, rsi, rsj){ var c; if(this.contactPointPool.length){ c = this.contactPointPool.pop(); @@ -231,13 +198,134 @@

    File: src/world/Narrowphase.js

    c = new ContactEquation(bi, bj); } - c.enabled = true; + c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; + + var cm = this.currentContactMaterial; + + c.restitution = cm.restitution; + + c.setSpookParams( + cm.contactEquationStiffness, + cm.contactEquationRelaxation, + this.world.dt + ); + + var matA = si.material || bi.material; + var matB = sj.material || bj.material; + if(matA && matB && matA.restitution >= 0 && matB.restitution >= 0){ + c.restitution = matA.restitution * matB.restitution; + } + c.si = rsi || si; c.sj = rsj || sj; return c; }; +Narrowphase.prototype.createFrictionEquationsFromContact = function(contactEquation, outArray){ + var bodyA = contactEquation.bi; + var bodyB = contactEquation.bj; + var shapeA = contactEquation.si; + var shapeB = contactEquation.sj; + + var world = this.world; + var cm = this.currentContactMaterial; + + // If friction or restitution were specified in the material, use them + var friction = cm.friction; + var matA = shapeA.material || bodyA.material; + var matB = shapeB.material || bodyB.material; + if(matA && matB && matA.friction >= 0 && matB.friction >= 0){ + friction = matA.friction * matB.friction; + } + + if(friction > 0){ + + // Create 2 tangent equations + var mug = friction * world.gravity.length(); + var reducedMass = (bodyA.invMass + bodyB.invMass); + if(reducedMass > 0){ + reducedMass = 1/reducedMass; + } + var pool = this.frictionEquationPool; + var c1 = pool.length ? pool.pop() : new FrictionEquation(bodyA,bodyB,mug*reducedMass); + var c2 = pool.length ? pool.pop() : new FrictionEquation(bodyA,bodyB,mug*reducedMass); + + c1.bi = c2.bi = bodyA; + c1.bj = c2.bj = bodyB; + c1.minForce = c2.minForce = -mug*reducedMass; + c1.maxForce = c2.maxForce = mug*reducedMass; + + // Copy over the relative vectors + c1.ri.copy(contactEquation.ri); + c1.rj.copy(contactEquation.rj); + c2.ri.copy(contactEquation.ri); + c2.rj.copy(contactEquation.rj); + + // Construct tangents + contactEquation.ni.tangents(c1.t, c2.t); + + // Set spook params + c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt); + c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt); + + c1.enabled = c2.enabled = contactEquation.enabled; + + outArray.push(c1, c2); + + return true; + } + + return false; +}; + +var averageNormal = new Vec3(); +var averageContactPointA = new Vec3(); +var averageContactPointB = new Vec3(); + +// Take the average N latest contact point on the plane. +Narrowphase.prototype.createFrictionFromAverage = function(numContacts){ + // The last contactEquation + var c = this.result[this.result.length - 1]; + + // Create the result: two "average" friction equations + if (!this.createFrictionEquationsFromContact(c, this.frictionResult) || numContacts === 1) { + return; + } + + var f1 = this.frictionResult[this.frictionResult.length - 2]; + var f2 = this.frictionResult[this.frictionResult.length - 1]; + + averageNormal.setZero(); + averageContactPointA.setZero(); + averageContactPointB.setZero(); + + var bodyA = c.bi; + var bodyB = c.bj; + for(var i=0; i!==numContacts; i++){ + c = this.result[this.result.length - 1 - i]; + if(c.bodyA !== bodyA){ + averageNormal.vadd(c.ni, averageNormal); // vec2.add(eq.t, eq.t, c.normalA); + averageContactPointA.vadd(c.ri, averageContactPointA); // vec2.add(eq.contactPointA, eq.contactPointA, c.contactPointA); + averageContactPointB.vadd(c.rj, averageContactPointB); + } else { + averageNormal.vsub(c.ni, averageNormal); // vec2.sub(eq.t, eq.t, c.normalA); + averageContactPointA.vadd(c.rj, averageContactPointA); // vec2.add(eq.contactPointA, eq.contactPointA, c.contactPointA); + averageContactPointB.vadd(c.ri, averageContactPointB); + } + } + + var invNumContacts = 1 / numContacts; + averageContactPointA.scale(invNumContacts, f1.ri); // vec2.scale(eq.contactPointA, eq.contactPointA, invNumContacts); + averageContactPointB.scale(invNumContacts, f1.rj); // vec2.scale(eq.contactPointB, eq.contactPointB, invNumContacts); + f2.ri.copy(f1.ri); // Should be the same + f2.rj.copy(f1.rj); + averageNormal.normalize(); + averageNormal.tangents(f1.t, f2.t); + // return eq; +}; + + var tmpVec1 = new Vec3(); var tmpVec2 = new Vec3(); var tmpQuat1 = new Quaternion(); @@ -252,9 +340,12 @@

    File: src/world/Narrowphase.js

    * @param {array} result Array to store generated contacts * @param {array} oldcontacts Optional. Array of reusable contact objects */ -Narrowphase.prototype.getContacts = function(p1,p2,world,result,oldcontacts){ +Narrowphase.prototype.getContacts = function(p1, p2, world, result, oldcontacts, frictionResult, frictionPool){ // Save old contact objects this.contactPointPool = oldcontacts; + this.frictionEquationPool = frictionPool; + this.result = result; + this.frictionResult = frictionResult; var qi = tmpQuat1; var qj = tmpQuat2; @@ -267,6 +358,12 @@

    File: src/world/Narrowphase.js

    var bi = p1[k], bj = p2[k]; + // Get contact material + var bodyContactMaterial = null; + if(bi.material && bj.material){ + bodyContactMaterial = world.getContactMaterial(bi.material,bj.material) || null; + } + for (var i = 0; i < bi.shapes.length; i++) { bi.quaternion.mult(bi.shapeOrientations[i], qi); bi.quaternion.vmult(bi.shapeOffsets[i], xi); @@ -285,13 +382,21 @@

    File: src/world/Narrowphase.js

    continue; } + // Get collision material + var shapeContactMaterial = null; + if(si.material && sj.material){ + shapeContactMaterial = world.getContactMaterial(si.material,sj.material) || null; + } + + this.currentContactMaterial = shapeContactMaterial || bodyContactMaterial || world.defaultContactMaterial; + // Get contacts var resolver = this[si.type | sj.type]; if(resolver){ if (si.type < sj.type) { - resolver.call(this, result, si,sj,xi,xj,qi,qj,bi,bj,si,sj); + resolver.call(this, si, sj, xi, xj, qi, qj, bi, bj, si, sj); } else { - resolver.call(this, result, sj,si,xj,xi,qj,qi,bj,bi,si,sj); + resolver.call(this, sj, si, xj, xi, qj, qi, bj, bi, si, sj); } } } @@ -313,23 +418,30 @@

    File: src/world/Narrowphase.js

    } Narrowphase.prototype[Shape.types.BOX | Shape.types.BOX] = -Narrowphase.prototype.boxBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexConvex(result,si.convexPolyhedronRepresentation,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxBox = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + sj.convexPolyhedronRepresentation.material = sj.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + sj.convexPolyhedronRepresentation.collisionResponse = sj.collisionResponse; + this.convexConvex(si.convexPolyhedronRepresentation,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj,si,sj); }; Narrowphase.prototype[Shape.types.BOX | Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.boxConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexConvex(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxConvex = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexConvex(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); }; Narrowphase.prototype[Shape.types.BOX | Shape.types.PARTICLE] = -Narrowphase.prototype.boxParticle = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexParticle(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); +Narrowphase.prototype.boxParticle = function(si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexParticle(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj,si,sj); }; /** * @method sphereSphere - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -340,12 +452,12 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE] = -Narrowphase.prototype.sphereSphere = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.sphereSphere = function(si,sj,xi,xj,qi,qj,bi,bj){ // We will have only one contact in this case - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); // Contact normal - bj.position.vsub(xi, r.ni); + xj.vsub(xi, r.ni); r.ni.normalize(); // Contact point locations @@ -353,7 +465,280 @@

    File: src/world/Narrowphase.js

    r.rj.copy(r.ni); r.ri.mult(si.radius, r.ri); r.rj.mult(-sj.radius, r.rj); - result.push(r); + + r.ri.vadd(xi, r.ri); + r.ri.vsub(bi.position, r.ri); + + r.rj.vadd(xj, r.rj); + r.rj.vsub(bj.position, r.rj); + + this.result.push(r); + + this.createFrictionEquationsFromContact(r, this.frictionResult); +}; + +/** + * @method planeTrimesh + * @param {Shape} si + * @param {Shape} sj + * @param {Vec3} xi + * @param {Vec3} xj + * @param {Quaternion} qi + * @param {Quaternion} qj + * @param {Body} bi + * @param {Body} bj + */ +var planeTrimesh_normal = new Vec3(); +var planeTrimesh_relpos = new Vec3(); +var planeTrimesh_projected = new Vec3(); +Narrowphase.prototype[Shape.types.PLANE | Shape.types.TRIMESH] = +Narrowphase.prototype.planeTrimesh = function( + planeShape, + trimeshShape, + planePos, + trimeshPos, + planeQuat, + trimeshQuat, + planeBody, + trimeshBody +){ + // Make contacts! + var v = new Vec3(); + + var normal = planeTrimesh_normal; + normal.set(0,0,1); + planeQuat.vmult(normal,normal); // Turn normal according to plane + + for(var i=0; i<trimeshShape.vertices.length / 3; i++){ + + // Get world vertex from trimesh + trimeshShape.getVertex(i, v); + + // Safe up + var v2 = new Vec3(); + v2.copy(v); + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, v2, v); + + // Check plane side + var relpos = planeTrimesh_relpos; + v.vsub(planePos, relpos); + var dot = normal.dot(relpos); + + if(dot <= 0.0){ + var r = this.createContactEquation(planeBody,trimeshBody,planeShape,trimeshShape); + + r.ni.copy(normal); // Contact normal is the plane normal + + // Get vertex position projected on plane + var projected = planeTrimesh_projected; + normal.scale(relpos.dot(normal), projected); + v.vsub(projected,projected); + + // ri is the projected world position minus plane position + r.ri.copy(projected); + r.ri.vsub(planeBody.position, r.ri); + + r.rj.copy(v); + r.rj.vsub(trimeshBody.position, r.rj); + + // Store result + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } +}; + +/** + * @method sphereTrimesh + * @param {Shape} sphereShape + * @param {Shape} trimeshShape + * @param {Vec3} spherePos + * @param {Vec3} trimeshPos + * @param {Quaternion} sphereQuat + * @param {Quaternion} trimeshQuat + * @param {Body} sphereBody + * @param {Body} trimeshBody + */ +var sphereTrimesh_normal = new Vec3(); +var sphereTrimesh_relpos = new Vec3(); +var sphereTrimesh_projected = new Vec3(); +var sphereTrimesh_v = new Vec3(); +var sphereTrimesh_v2 = new Vec3(); +var sphereTrimesh_edgeVertexA = new Vec3(); +var sphereTrimesh_edgeVertexB = new Vec3(); +var sphereTrimesh_edgeVector = new Vec3(); +var sphereTrimesh_edgeVectorUnit = new Vec3(); +var sphereTrimesh_localSpherePos = new Vec3(); +var sphereTrimesh_tmp = new Vec3(); +var sphereTrimesh_va = new Vec3(); +var sphereTrimesh_vb = new Vec3(); +var sphereTrimesh_vc = new Vec3(); +var sphereTrimesh_localSphereAABB = new AABB(); +var sphereTrimesh_triangles = []; +Narrowphase.prototype[Shape.types.SPHERE | Shape.types.TRIMESH] = +Narrowphase.prototype.sphereTrimesh = function ( + sphereShape, + trimeshShape, + spherePos, + trimeshPos, + sphereQuat, + trimeshQuat, + sphereBody, + trimeshBody +) { + + var edgeVertexA = sphereTrimesh_edgeVertexA; + var edgeVertexB = sphereTrimesh_edgeVertexB; + var edgeVector = sphereTrimesh_edgeVector; + var edgeVectorUnit = sphereTrimesh_edgeVectorUnit; + var localSpherePos = sphereTrimesh_localSpherePos; + var tmp = sphereTrimesh_tmp; + var localSphereAABB = sphereTrimesh_localSphereAABB; + var v2 = sphereTrimesh_v2; + var relpos = sphereTrimesh_relpos; + var triangles = sphereTrimesh_triangles; + + // Convert sphere position to local in the trimesh + Transform.pointToLocalFrame(trimeshPos, trimeshQuat, spherePos, localSpherePos); + + // Get the aabb of the sphere locally in the trimesh + var sphereRadius = sphereShape.radius; + localSphereAABB.lowerBound.set( + localSpherePos.x - sphereRadius, + localSpherePos.y - sphereRadius, + localSpherePos.z - sphereRadius + ); + localSphereAABB.upperBound.set( + localSpherePos.x + sphereRadius, + localSpherePos.y + sphereRadius, + localSpherePos.z + sphereRadius + ); + + trimeshShape.getTrianglesInAABB(localSphereAABB, triangles); + //for (var i = 0; i < trimeshShape.indices.length / 3; i++) triangles.push(i); // All + + // Vertices + var v = sphereTrimesh_v; + var radiusSquared = sphereShape.radius * sphereShape.radius; + for(var i=0; i<triangles.length; i++){ + for (var j = 0; j < 3; j++) { + + trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + j], v); + + // Check vertex overlap in sphere + v.vsub(localSpherePos, relpos); + + if(relpos.norm2() <= radiusSquared){ + + // Safe up + v2.copy(v); + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, v2, v); + + v.vsub(spherePos, relpos); + + var r = this.createContactEquation(sphereBody,trimeshBody,sphereShape,trimeshShape); + r.ni.copy(relpos); + r.ni.normalize(); + + // ri is the vector from sphere center to the sphere surface + r.ri.copy(r.ni); + r.ri.scale(sphereShape.radius, r.ri); + r.ri.vadd(spherePos, r.ri); + r.ri.vsub(sphereBody.position, r.ri); + + r.rj.copy(v); + r.rj.vsub(trimeshBody.position, r.rj); + + // Store result + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + } + + // Check all edges + for(var i=0; i<triangles.length; i++){ + for (var j = 0; j < 3; j++) { + + trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + j], edgeVertexA); + trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + ((j+1)%3)], edgeVertexB); + edgeVertexB.vsub(edgeVertexA, edgeVector); + + // Project sphere position to the edge + localSpherePos.vsub(edgeVertexB, tmp); + var positionAlongEdgeB = tmp.dot(edgeVector); + + localSpherePos.vsub(edgeVertexA, tmp); + var positionAlongEdgeA = tmp.dot(edgeVector); + + if(positionAlongEdgeA > 0 && positionAlongEdgeB < 0){ + + // Now check the orthogonal distance from edge to sphere center + localSpherePos.vsub(edgeVertexA, tmp); + + edgeVectorUnit.copy(edgeVector); + edgeVectorUnit.normalize(); + positionAlongEdgeA = tmp.dot(edgeVectorUnit); + + edgeVectorUnit.scale(positionAlongEdgeA, tmp); + tmp.vadd(edgeVertexA, tmp); + + // tmp is now the sphere center position projected to the edge, defined locally in the trimesh frame + var dist = tmp.distanceTo(localSpherePos); + if(dist < sphereShape.radius){ + var r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape); + + tmp.vsub(localSpherePos, r.ni); + r.ni.normalize(); + r.ni.scale(sphereShape.radius, r.ri); + + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); + tmp.vsub(trimeshBody.position, r.rj); + + Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni); + Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + } + } + + // Triangle faces + var va = sphereTrimesh_va; + var vb = sphereTrimesh_vb; + var vc = sphereTrimesh_vc; + var normal = sphereTrimesh_normal; + for(var i=0, N = triangles.length; i !== N; i++){ + trimeshShape.getTriangleVertices(triangles[i], va, vb, vc); + trimeshShape.getNormal(triangles[i], normal); + localSpherePos.vsub(va, tmp); + var dist = tmp.dot(normal); + normal.scale(dist, tmp); + localSpherePos.vsub(tmp, tmp); + + // tmp is now the sphere position projected to the triangle plane + dist = tmp.distanceTo(localSpherePos); + if(Ray.pointInTriangle(tmp, va, vb, vc) && dist < sphereShape.radius){ + var r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape); + + tmp.vsub(localSpherePos, r.ni); + r.ni.normalize(); + r.ni.scale(sphereShape.radius, r.ri); + + Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp); + tmp.vsub(trimeshBody.position, r.rj); + + Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni); + Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + + triangles.length = 0; }; var point_on_plane_to_sphere = new Vec3(); @@ -361,7 +746,6 @@

    File: src/world/Narrowphase.js

    /** * @method spherePlane - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -372,9 +756,9 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.PLANE] = -Narrowphase.prototype.spherePlane = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.spherePlane = function(si,sj,xi,xj,qi,qj,bi,bj){ // We will have one contact in this case - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); // Contact normal r.ni.set(0,0,1); @@ -390,8 +774,7 @@

    File: src/world/Narrowphase.js

    r.ni.mult(r.ni.dot(point_on_plane_to_sphere), plane_to_sphere_ortho); point_on_plane_to_sphere.vsub(plane_to_sphere_ortho,r.rj); // The sphere position projected to plane - if(plane_to_sphere_ortho.norm2() <= si.radius * si.radius){ - result.push(r); + if(-point_on_plane_to_sphere.dot(r.ni) <= si.radius){ // Make it relative to the body var ri = r.ri; @@ -400,6 +783,9 @@

    File: src/world/Narrowphase.js

    ri.vsub(bi.position, ri); rj.vadd(xj, rj); rj.vsub(bj.position, rj); + + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -456,7 +842,6 @@

    File: src/world/Narrowphase.js

    /** * @method sphereBox - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -467,7 +852,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.BOX] = -Narrowphase.prototype.sphereBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.sphereBox = function(si,sj,xi,xj,qi,qj,bi,bj){ var v3pool = this.v3pool; // we refer to the box as body j @@ -529,7 +914,7 @@

    File: src/world/Narrowphase.js

    } if(side_penetrations){ found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); side_ns.mult(-R,r.ri); // Sphere r r.ni.copy(side_ns); r.ni.negate(r.ni); // Normal should be out of sphere @@ -545,7 +930,8 @@

    File: src/world/Narrowphase.js

    r.rj.vadd(xj, r.rj); r.rj.vsub(bj.position, r.rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } // Check corners @@ -577,7 +963,7 @@

    File: src/world/Narrowphase.js

    if(sphere_to_corner.norm2() < R*R){ found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); r.ri.copy(sphere_to_corner); r.ri.normalize(); r.ni.copy(r.ri); @@ -590,7 +976,8 @@

    File: src/world/Narrowphase.js

    r.rj.vadd(xj, r.rj); r.rj.vsub(bj.position, r.rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } } } @@ -636,7 +1023,7 @@

    File: src/world/Narrowphase.js

    if(tdist < sides[l].norm() && ndist<R){ found = true; - var res = this.makeResult(bi,bj,si,sj); + var res = this.createContactEquation(bi,bj,si,sj); edgeCenter.vadd(orthogonal,res.rj); // box rj res.rj.copy(res.rj); dist.negate(res.ni); @@ -654,7 +1041,8 @@

    File: src/world/Narrowphase.js

    res.rj.vadd(xj, res.rj); res.rj.vsub(bj.position, res.rj); - result.push(res); + this.result.push(res); + this.createFrictionEquationsFromContact(res, this.frictionResult); } } } @@ -675,7 +1063,6 @@

    File: src/world/Narrowphase.js

    /** * @method sphereConvex - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -686,7 +1073,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.sphereConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj){ +Narrowphase.prototype.sphereConvex = function(si,sj,xi,xj,qi,qj,bi,bj){ var v3pool = this.v3pool; xi.vsub(xj,convex_to_sphere); var normals = sj.faceNormals; @@ -711,7 +1098,7 @@

    File: src/world/Narrowphase.js

    worldCorner.vsub(xi, sphere_to_corner); if(sphere_to_corner.norm2() < R * R){ found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); r.ri.copy(sphere_to_corner); r.ri.normalize(); r.ni.copy(r.ri); @@ -726,7 +1113,8 @@

    File: src/world/Narrowphase.js

    r.rj.vadd(xj, r.rj); r.rj.vsub(bj.position, r.rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); return; } } @@ -773,7 +1161,7 @@

    File: src/world/Narrowphase.js

    if(pointInPolygon(faceVerts,worldNormal,xi)){ // Is the sphere center in the face polygon? found = true; - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); worldNormal.mult(-R, r.ri); // Contact offset, from sphere center to contact worldNormal.negate(r.ni); // Normal pointing out of sphere @@ -799,7 +1187,8 @@

    File: src/world/Narrowphase.js

    v3pool.release(penetrationVec2); v3pool.release(penetrationSpherePoint); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); // Release world vertices for(var j=0, Nfaceverts=faceVerts.length; j!==Nfaceverts; j++){ @@ -843,7 +1232,7 @@

    File: src/world/Narrowphase.js

    // AND if p is in between v1 and v2 if(dot > 0 && dot*dot<edge.norm2() && xi_to_p.norm2() < R*R){ // Collision if the edge-sphere distance is less than the radius // Edge contact! - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); p.vsub(xj,r.rj); p.vsub(xi,r.ni); @@ -859,7 +1248,8 @@

    File: src/world/Narrowphase.js

    r.ri.vadd(xi, r.ri); r.ri.vsub(bi.position, r.ri); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); // Release world vertices for(var j=0, Nfaceverts=faceVerts.length; j!==Nfaceverts; j++){ @@ -907,8 +1297,10 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.PLANE | Shape.types.BOX] = -Narrowphase.prototype.planeBox = function(result,si,sj,xi,xj,qi,qj,bi,bj){ - this.planeConvex(result,si,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj); +Narrowphase.prototype.planeBox = function(si,sj,xi,xj,qi,qj,bi,bj){ + sj.convexPolyhedronRepresentation.material = sj.material; + sj.convexPolyhedronRepresentation.collisionResponse = sj.collisionResponse; + this.planeConvex(si,sj.convexPolyhedronRepresentation,xi,xj,qi,qj,bi,bj); }; var planeConvex_v = new Vec3(); @@ -918,7 +1310,6 @@

    File: src/world/Narrowphase.js

    /** * @method planeConvex - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -930,7 +1321,6 @@

    File: src/world/Narrowphase.js

    */ Narrowphase.prototype[Shape.types.PLANE | Shape.types.CONVEXPOLYHEDRON] = Narrowphase.prototype.planeConvex = function( - result, planeShape, convexShape, planePosition, @@ -946,6 +1336,7 @@

    File: src/world/Narrowphase.js

    worldNormal.set(0,0,1); planeQuat.vmult(worldNormal,worldNormal); // Turn normal according to plane orientation + var numContacts = 0; var relpos = planeConvex_relpos; for(var i = 0; i !== convexShape.vertices.length; i++){ @@ -958,7 +1349,7 @@

    File: src/world/Narrowphase.js

    var dot = worldNormal.dot(relpos); if(dot <= 0.0){ - var r = this.makeResult(planeBody, convexBody, planeShape, convexShape); + var r = this.createContactEquation(planeBody, convexBody, planeShape, convexShape); // Get vertex position projected on plane var projected = planeConvex_projected; @@ -977,9 +1368,17 @@

    File: src/world/Narrowphase.js

    r.rj.vadd(convexPosition, r.rj); r.rj.vsub(convexBody.position, r.rj); - result.push(r); + this.result.push(r); + numContacts++; + if(!this.enableFrictionReduction){ + this.createFrictionEquationsFromContact(r, this.frictionResult); + } } } + + if(this.enableFrictionReduction && numContacts){ + this.createFrictionFromAverage(numContacts); + } }; var convexConvex_sepAxis = new Vec3(); @@ -987,7 +1386,6 @@

    File: src/world/Narrowphase.js

    /** * @method convexConvex - * @param {Array} result * @param {Shape} si * @param {Shape} sj * @param {Vec3} xi @@ -998,7 +1396,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.convexConvex = function(result,si,sj,xi,xj,qi,qj,bi,bj,rsi,rsj,faceListA,faceListB){ +Narrowphase.prototype.convexConvex = function(si,sj,xi,xj,qi,qj,bi,bj,rsi,rsj,faceListA,faceListB){ var sepAxis = convexConvex_sepAxis; if(xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius){ @@ -1009,8 +1407,9 @@

    File: src/world/Narrowphase.js

    var res = []; var q = convexConvex_q; si.clipAgainstHull(xi,qi,sj,xj,qj,sepAxis,-100,100,res); + var numContacts = 0; for(var j = 0; j !== res.length; j++){ - var r = this.makeResult(bi,bj,si,sj,rsi,rsj), + var r = this.createContactEquation(bi,bj,si,sj,rsi,rsj), ri = r.ri, rj = r.rj; sepAxis.negate(r.ni); @@ -1029,11 +1428,99 @@

    File: src/world/Narrowphase.js

    rj.vadd(xj, rj); rj.vsub(bj.position, rj); - result.push(r); + this.result.push(r); + numContacts++; + if(!this.enableFrictionReduction){ + this.createFrictionEquationsFromContact(r, this.frictionResult); + } + } + if(this.enableFrictionReduction && numContacts){ + this.createFrictionFromAverage(numContacts); } } }; + +/** + * @method convexTrimesh + * @param {Array} result + * @param {Shape} si + * @param {Shape} sj + * @param {Vec3} xi + * @param {Vec3} xj + * @param {Quaternion} qi + * @param {Quaternion} qj + * @param {Body} bi + * @param {Body} bj + */ +// Narrowphase.prototype[Shape.types.CONVEXPOLYHEDRON | Shape.types.TRIMESH] = +// Narrowphase.prototype.convexTrimesh = function(si,sj,xi,xj,qi,qj,bi,bj,rsi,rsj,faceListA,faceListB){ +// var sepAxis = convexConvex_sepAxis; + +// if(xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius){ +// return; +// } + +// // Construct a temp hull for each triangle +// var hullB = new ConvexPolyhedron(); + +// hullB.faces = [[0,1,2]]; +// var va = new Vec3(); +// var vb = new Vec3(); +// var vc = new Vec3(); +// hullB.vertices = [ +// va, +// vb, +// vc +// ]; + +// for (var i = 0; i < sj.indices.length / 3; i++) { + +// var triangleNormal = new Vec3(); +// sj.getNormal(i, triangleNormal); +// hullB.faceNormals = [triangleNormal]; + +// sj.getTriangleVertices(i, va, vb, vc); + +// var d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj); +// if(!d){ +// triangleNormal.scale(-1, triangleNormal); +// d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj); + +// if(!d){ +// continue; +// } +// } + +// var res = []; +// var q = convexConvex_q; +// si.clipAgainstHull(xi,qi,hullB,xj,qj,triangleNormal,-100,100,res); +// for(var j = 0; j !== res.length; j++){ +// var r = this.createContactEquation(bi,bj,si,sj,rsi,rsj), +// ri = r.ri, +// rj = r.rj; +// r.ni.copy(triangleNormal); +// r.ni.negate(r.ni); +// res[j].normal.negate(q); +// q.mult(res[j].depth, q); +// res[j].point.vadd(q, ri); +// rj.copy(res[j].point); + +// // Contact points are in world coordinates. Transform back to relative +// ri.vsub(xi,ri); +// rj.vsub(xj,rj); + +// // Make relative to bodies +// ri.vadd(xi, ri); +// ri.vsub(bi.position, ri); +// rj.vadd(xj, rj); +// rj.vsub(bj.position, rj); + +// result.push(r); +// } +// } +// }; + var particlePlane_normal = new Vec3(); var particlePlane_relpos = new Vec3(); var particlePlane_projected = new Vec3(); @@ -1051,7 +1538,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.PLANE | Shape.types.PARTICLE] = -Narrowphase.prototype.planeParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.planeParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ var normal = particlePlane_normal; normal.set(0,0,1); bj.quaternion.vmult(normal,normal); // Turn normal according to plane orientation @@ -1059,7 +1546,7 @@

    File: src/world/Narrowphase.js

    xi.vsub(bj.position,relpos); var dot = normal.dot(relpos); if(dot <= 0.0){ - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); r.ni.copy(normal); // Contact normal is the plane normal r.ni.negate(r.ni); r.ri.set(0,0,0); // Center of particle @@ -1072,7 +1559,8 @@

    File: src/world/Narrowphase.js

    // rj is now the projected world position minus plane position r.rj.copy(projected); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -1091,7 +1579,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.PARTICLE | Shape.types.SPHERE] = -Narrowphase.prototype.sphereParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.sphereParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ // The normal is the unit vector from sphere center to particle center var normal = particleSphere_normal; normal.set(0,0,1); @@ -1099,14 +1587,15 @@

    File: src/world/Narrowphase.js

    var lengthSquared = normal.norm2(); if(lengthSquared <= sj.radius * sj.radius){ - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); normal.normalize(); r.rj.copy(normal); r.rj.mult(sj.radius,r.rj); r.ni.copy(normal); // Contact normal r.ni.negate(r.ni); r.ri.set(0,0,0); // Center of particle - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } }; @@ -1131,7 +1620,7 @@

    File: src/world/Narrowphase.js

    * @param {Body} bj */ Narrowphase.prototype[Shape.types.PARTICLE | Shape.types.CONVEXPOLYHEDRON] = -Narrowphase.prototype.convexParticle = function(result,sj,si,xj,xi,qj,qi,bj,bi){ +Narrowphase.prototype.convexParticle = function(sj,si,xj,xi,qj,qi,bj,bi){ var penetratedFaceIndex = -1; var penetratedFaceNormal = convexParticle_penetratedFaceNormal; var worldPenetrationVec = convexParticle_worldPenetrationVec; @@ -1174,7 +1663,7 @@

    File: src/world/Narrowphase.js

    if(penetratedFaceIndex!==-1){ // Setup contact - var r = this.makeResult(bi,bj,si,sj); + var r = this.createContactEquation(bi,bj,si,sj); penetratedFaceNormal.mult(minPenetration, worldPenetrationVec); // rj is the particle position projected to the face @@ -1197,7 +1686,8 @@

    File: src/world/Narrowphase.js

    rj.vadd(xj, rj); rj.vsub(bj.position, rj); - result.push(r); + this.result.push(r); + this.createFrictionEquationsFromContact(r, this.frictionResult); } else { console.warn("Point found inside convex, but did not find penetrating face!"); } @@ -1205,8 +1695,10 @@

    File: src/world/Narrowphase.js

    }; Narrowphase.prototype[Shape.types.BOX | Shape.types.HEIGHTFIELD] = -Narrowphase.prototype.boxHeightfield = function (result,si,sj,xi,xj,qi,qj,bi,bj){ - this.convexHeightfield(result,si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj); +Narrowphase.prototype.boxHeightfield = function (si,sj,xi,xj,qi,qj,bi,bj){ + si.convexPolyhedronRepresentation.material = si.material; + si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse; + this.convexHeightfield(si.convexPolyhedronRepresentation,sj,xi,xj,qi,qj,bi,bj); }; var convexHeightfield_tmp1 = new Vec3(); @@ -1214,11 +1706,10 @@

    File: src/world/Narrowphase.js

    var convexHeightfield_faceList = [0]; /** - * @method sphereHeightfield + * @method convexHeightfield */ Narrowphase.prototype[Shape.types.CONVEXPOLYHEDRON | Shape.types.HEIGHTFIELD] = Narrowphase.prototype.convexHeightfield = function ( - result, convexShape, hfShape, convexPos, @@ -1245,7 +1736,7 @@

    File: src/world/Narrowphase.js

    iMaxY = Math.ceil((localConvexPos.y + radius) / w) + 1; // Bail out if we are out of the terrain - if(iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMaxY > data[0].length){ + if(iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMinY > data[0].length){ return; } @@ -1276,22 +1767,19 @@

    File: src/world/Narrowphase.js

    hfShape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) { - this.convexConvex(result, convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); + this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); } // Upper triangle hfShape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) { - this.convexConvex(result, convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); + this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, faceList, null); } } } }; - - - var sphereHeightfield_tmp1 = new Vec3(); var sphereHeightfield_tmp2 = new Vec3(); @@ -1300,7 +1788,6 @@

    File: src/world/Narrowphase.js

    */ Narrowphase.prototype[Shape.types.SPHERE | Shape.types.HEIGHTFIELD] = Narrowphase.prototype.sphereHeightfield = function ( - result, sphereShape, hfShape, spherePos, @@ -1350,6 +1837,7 @@

    File: src/world/Narrowphase.js

    return; } + var result = this.result; for(var i = iMinX; i < iMaxX; i++){ for(var j = iMinY; j < iMaxY; j++){ @@ -1359,14 +1847,14 @@

    File: src/world/Narrowphase.js

    hfShape.getConvexTrianglePillar(i, j, false); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) { - this.sphereConvex(result, sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); + this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); } // Upper triangle hfShape.getConvexTrianglePillar(i, j, true); Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset); if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) { - this.sphereConvex(result, sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); + this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody); } var numContacts = result.length - numContactsBefore; @@ -1383,9 +1871,9 @@

    File: src/world/Narrowphase.js

    } } }; +
    -
    diff --git a/docs/files/src_world_World.js.html b/docs/files/src_world_World.js.html index 491e39844..fc2b4bdc9 100644 --- a/docs/files/src_world_World.js.html +++ b/docs/files/src_world_World.js.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    -
    -
    - -
    -
    -
    -
    - Show: - - - - - - - -
    - -
    -

    File: src/world/World.js

    +

    File: src/world/World.js

    @@ -215,7 +166,7 @@ 

    File: src/world/World.js

    EventTarget.apply(this); /** - * Last used timestep. Is set to -1 if not available. + * Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks. * @property {Number} dt */ this.dt = -1; @@ -303,7 +254,7 @@

    File: src/world/World.js

    * @property narrowphase * @type {Narrowphase} */ - this.narrowphase = new Narrowphase(); + this.narrowphase = new Narrowphase(this); /** * @property {ArrayCollisionMatrix} collisionMatrix @@ -365,7 +316,7 @@

    File: src/world/World.js

    }; /** - * @property subystems + * @property subsystems * @type {Array} */ this.subsystems = []; @@ -392,7 +343,7 @@

    File: src/world/World.js

    * @method getContactMaterial * @param {Material} m1 * @param {Material} m2 - * @return {Contactmaterial} The contact material if it was found. + * @return {ContactMaterial} The contact material if it was found. */ World.prototype.getContactMaterial = function(m1,m2){ return this.contactMaterialTable.get(m1.id,m2.id); //this.contactmaterials[this.mats2cmat[i+j*this.materials.length]]; @@ -473,25 +424,90 @@

    File: src/world/World.js

    * @param {Vec3} from * @param {Vec3} to * @param {Function|RaycastResult} result + * @deprecated Use .raycastAll, .raycastClosest or .raycastAny instead. */ World.prototype.rayTest = function(from, to, result){ - // result = result || new RaycastResult(); + if(result instanceof RaycastResult){ + // Do raycastclosest + this.raycastClosest(from, to, { + skipBackfaces: true + }, result); + } else { + // Do raycastAll + this.raycastAll(from, to, { + skipBackfaces: true + }, result); + } +}; - tmpRay.from.copy(from); - tmpRay.to.copy(to); - tmpRay.getAABB(tmpAABB1); +/** + * Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument. + * @method raycastAll + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {Function} callback + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastAll = function(from, to, options, callback){ + options.mode = Ray.ALL; + options.from = from; + options.to = to; + options.callback = callback; + return tmpRay.intersectWorld(this, options); +}; - tmpArray1.length = 0; - this.broadphase.aabbQuery(this, tmpAABB1, tmpArray1); +/** + * Ray cast, and stop at the first result. Note that the order is random - but the method is fast. + * @method raycastAny + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {RaycastResult} result + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastAny = function(from, to, options, result){ + options.mode = Ray.ANY; + options.from = from; + options.to = to; + options.result = result; + return tmpRay.intersectWorld(this, options); +}; - tmpRay.intersectBodies(tmpArray1, result); +/** + * Ray cast, and return information of the closest hit. + * @method raycastClosest + * @param {Vec3} from + * @param {Vec3} to + * @param {Object} options + * @param {number} [options.collisionFilterMask=-1] + * @param {number} [options.collisionFilterGroup=-1] + * @param {boolean} [options.skipBackfaces=false] + * @param {boolean} [options.checkCollisionResponse=true] + * @param {RaycastResult} result + * @return {boolean} True if any body was hit. + */ +World.prototype.raycastClosest = function(from, to, options, result){ + options.mode = Ray.CLOSEST; + options.from = from; + options.to = to; + options.result = result; + return tmpRay.intersectWorld(this, options); }; /** * Remove a rigid body from the simulation. * @method remove * @param {Body} body - * @todo Rename to .removeBody + * @deprecated Use .removeBody instead */ World.prototype.remove = function(body){ body.world = null; @@ -512,6 +528,13 @@

    File: src/world/World.js

    } }; +/** + * Remove a rigid body from the simulation. + * @method removeBody + * @param {Body} body + */ +World.prototype.removeBody = World.prototype.remove; + /** * Adds a material to the World. * @method addMaterial @@ -729,11 +752,23 @@

    File: src/world/World.js

    } contacts.length = 0; - this.narrowphase.getContacts(p1,p2, - this, - contacts, - oldcontacts // To be reused - ); + // Transfer FrictionEquation from current list to the pool for reuse + var NoldFrictionEquations = this.frictionEquations.length; + for(i=0; i!==NoldFrictionEquations; i++){ + frictionEquationPool.push(this.frictionEquations[i]); + } + this.frictionEquations.length = 0; + + this.narrowphase.getContacts( + p1, + p2, + this, + contacts, + oldcontacts, // To be reused + this.frictionEquations, + frictionEquationPool + ); + if(doProfiling){ profile.narrowphase = performance.now() - profilingStart; } @@ -742,15 +777,13 @@

    File: src/world/World.js

    if(doProfiling){ profilingStart = performance.now(); } - var ncontacts = contacts.length; - // Transfer FrictionEquation from current list to the pool for reuse - var NoldFrictionEquations = this.frictionEquations.length; - for(i=0; i!==NoldFrictionEquations; i++){ - frictionEquationPool.push(this.frictionEquations[i]); + // Add all friction eqs + for (var i = 0; i < this.frictionEquations.length; i++) { + solver.addEquation(this.frictionEquations[i]); } - this.frictionEquations.length = 0; + var ncontacts = contacts.length; for(var k=0; k!==ncontacts; k++){ // Current contact @@ -762,9 +795,6 @@

    File: src/world/World.js

    si = c.si, sj = c.sj; - // Resolve indices - var i = bodies.indexOf(bi), j = bodies.indexOf(bj); - // Get collision properties var cm; if(bi.material && bj.material){ @@ -772,112 +802,108 @@

    File: src/world/World.js

    } else { cm = this.defaultContactMaterial; } + + // c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; + var mu = cm.friction; + // c.restitution = cm.restitution; - // g = ( xj + rj - xi - ri ) .dot ( ni ) - var gvec = World_step_gvec; - gvec.set(bj.position.x + c.rj.x - bi.position.x - c.ri.x, - bj.position.y + c.rj.y - bi.position.y - c.ri.y, - bj.position.z + c.rj.z - bi.position.z - c.ri.z); - var g = gvec.dot(c.ni); // Gap, negative if penetration - - // Action if penetration - if(g < 0.0){ - - c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse; - - c.restitution = cm.restitution; - c.penetration = g; - c.setSpookParams(cm.contactEquationStiffness, - cm.contactEquationRelaxation, - dt); - - solver.addEquation(c); - - // Add friction constraint equation - if(mu > 0){ - - // Create 2 tangent equations - var mug = mu*gnorm; - var reducedMass = (bi.invMass + bj.invMass); - if(reducedMass > 0){ - reducedMass = 1/reducedMass; - } - var pool = frictionEquationPool; - var c1 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); - var c2 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); - this.frictionEquations.push(c1); - this.frictionEquations.push(c2); - - c1.bi = c2.bi = bi; - c1.bj = c2.bj = bj; - c1.minForce = c2.minForce = -mug*reducedMass; - c1.maxForce = c2.maxForce = mug*reducedMass; - - // Copy over the relative vectors - c1.ri.copy(c.ri); - c1.rj.copy(c.rj); - c2.ri.copy(c.ri); - c2.rj.copy(c.rj); - - // Construct tangents - c.ni.tangents(c1.t, c2.t); - - // Set spook params - c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); - c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); - - c1.enabled = c2.enabled = c.enabled; - - // Add equations to solver - solver.addEquation(c1); - solver.addEquation(c2); - } - - if( bi.allowSleep && - bi.type === Body.DYNAMIC && - bi.sleepState === Body.SLEEPING && - bj.sleepState === Body.AWAKE && - bj.type !== Body.STATIC - ){ - var speedSquaredB = bj.velocity.norm2() + bj.angularVelocity.norm2(); - var speedLimitSquaredB = Math.pow(bj.sleepSpeedLimit,2); - if(speedSquaredB >= speedLimitSquaredB*2){ - bi._wakeUpAfterNarrowphase = true; - } + // If friction or restitution were specified in the material, use them + if(bi.material && bj.material){ + if(bi.material.friction >= 0 && bj.material.friction >= 0){ + mu = bi.material.friction * bj.material.friction; } - if( bj.allowSleep && - bj.type === Body.DYNAMIC && - bj.sleepState === Body.SLEEPING && - bi.sleepState === Body.AWAKE && - bi.type !== Body.STATIC - ){ - var speedSquaredA = bi.velocity.norm2() + bi.angularVelocity.norm2(); - var speedLimitSquaredA = Math.pow(bi.sleepSpeedLimit,2); - if(speedSquaredA >= speedLimitSquaredA*2){ - bj._wakeUpAfterNarrowphase = true; - } + if(bi.material.restitution >= 0 && bj.material.restitution >= 0){ + c.restitution = bi.material.restitution * bj.material.restitution; } + } + + // c.setSpookParams( + // cm.contactEquationStiffness, + // cm.contactEquationRelaxation, + // dt + // ); + + solver.addEquation(c); + + // // Add friction constraint equation + // if(mu > 0){ + + // // Create 2 tangent equations + // var mug = mu * gnorm; + // var reducedMass = (bi.invMass + bj.invMass); + // if(reducedMass > 0){ + // reducedMass = 1/reducedMass; + // } + // var pool = frictionEquationPool; + // var c1 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); + // var c2 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass); + // this.frictionEquations.push(c1, c2); + + // c1.bi = c2.bi = bi; + // c1.bj = c2.bj = bj; + // c1.minForce = c2.minForce = -mug*reducedMass; + // c1.maxForce = c2.maxForce = mug*reducedMass; + + // // Copy over the relative vectors + // c1.ri.copy(c.ri); + // c1.rj.copy(c.rj); + // c2.ri.copy(c.ri); + // c2.rj.copy(c.rj); + + // // Construct tangents + // c.ni.tangents(c1.t, c2.t); + + // // Set spook params + // c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); + // c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt); + + // c1.enabled = c2.enabled = c.enabled; + + // // Add equations to solver + // solver.addEquation(c1); + // solver.addEquation(c2); + // } + + if( bi.allowSleep && + bi.type === Body.DYNAMIC && + bi.sleepState === Body.SLEEPING && + bj.sleepState === Body.AWAKE && + bj.type !== Body.STATIC + ){ + var speedSquaredB = bj.velocity.norm2() + bj.angularVelocity.norm2(); + var speedLimitSquaredB = Math.pow(bj.sleepSpeedLimit,2); + if(speedSquaredB >= speedLimitSquaredB*2){ + bi._wakeUpAfterNarrowphase = true; + } + } - // Now we know that i and j are in contact. Set collision matrix state - this.collisionMatrix.set(bi, bj, true); + if( bj.allowSleep && + bj.type === Body.DYNAMIC && + bj.sleepState === Body.SLEEPING && + bi.sleepState === Body.AWAKE && + bi.type !== Body.STATIC + ){ + var speedSquaredA = bi.velocity.norm2() + bi.angularVelocity.norm2(); + var speedLimitSquaredA = Math.pow(bi.sleepSpeedLimit,2); + if(speedSquaredA >= speedLimitSquaredA*2){ + bj._wakeUpAfterNarrowphase = true; + } + } - if (this.collisionMatrix.get(bi, bj) !== this.collisionMatrixPrevious.get(bi, bj)) { - // First contact! - // We reuse the collideEvent object, otherwise we will end up creating new objects for each new contact, even if there's no event listener attached. - World_step_collideEvent.body = bj; - World_step_collideEvent.contact = c; - bi.dispatchEvent(World_step_collideEvent); + // Now we know that i and j are in contact. Set collision matrix state + this.collisionMatrix.set(bi, bj, true); - World_step_collideEvent.body = bi; - bj.dispatchEvent(World_step_collideEvent); + if (!this.collisionMatrixPrevious.get(bi, bj)) { + // First contact! + // We reuse the collideEvent object, otherwise we will end up creating new objects for each new contact, even if there's no event listener attached. + World_step_collideEvent.body = bj; + World_step_collideEvent.contact = c; + bi.dispatchEvent(World_step_collideEvent); - /* - bi.wakeUp(); - bj.wakeUp(); - */ - } + World_step_collideEvent.body = bi; + bj.dispatchEvent(World_step_collideEvent); } } if(doProfiling){ @@ -960,7 +986,6 @@

    File: src/world/World.js

    for(i=0; i!==N; i++){ var b = bodies[i], - s = b.shape, force = b.force, tau = b.torque; if((b.type & DYNAMIC_OR_KINEMATIC) && b.sleepState !== Body.SLEEPING){ // Only for dynamic @@ -979,12 +1004,6 @@

    File: src/world/World.js

    invInertia.vmult(tau,invI_tau_dt); invI_tau_dt.mult(dt,invI_tau_dt); invI_tau_dt.vadd(angularVelo,angularVelo); - //console.log(invI_tau_dt); - /* - angularVelo.x += tau.x * invInertia.x * dt; - angularVelo.y += tau.y * invInertia.y * dt; - angularVelo.z += tau.z * invInertia.z * dt; - */ } // Use new velocity - leap frog @@ -1012,29 +1031,13 @@

    File: src/world/World.js

    b.aabbNeedsUpdate = true; } - if(s){ - switch(s.type){ - case PLANE: - s.worldNormalNeedsUpdate = true; - break; - case CONVEX: - s.worldFaceNormalsNeedsUpdate = true; - s.worldVerticesNeedsUpdate = true; - break; - } - } - // Update world inertia if(b.updateInertiaWorld){ b.updateInertiaWorld(); } } - b.force.set(0,0,0); - if(b.torque){ - b.torque.set(0,0,0); - } - } + this.clearForces(); this.broadphase.dirty = true; @@ -1065,9 +1068,25 @@

    File: src/world/World.js

    } }; +/** + * Sets all body forces in the world to zero. + * @method clearForces + */ +World.prototype.clearForces = function(){ + var bodies = this.bodies; + var N = bodies.length; + for(var i=0; i !== N; i++){ + var b = bodies[i], + force = b.force, + tau = b.torque; + + b.force.set(0,0,0); + b.torque.set(0,0,0); + } +}; +
    -
    diff --git a/docs/index.html b/docs/index.html index 484880630..4d5af6ae3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,7 +6,7 @@ - + @@ -14,9 +14,7 @@
    - -

    - +

    API Docs for: 0.6.1 @@ -27,158 +25,111 @@

    - Show: - - - - - - - -
    - - + Show: + + + + + + + +
    +
    -
    +

    Browse to a module or class using the sidebar to view its API documentation. @@ -199,7 +150,6 @@

    Keyboard Shortcuts

    -
    diff --git a/package.json b/package.json index 4c3460dda..48de9eda9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cannon", - "version": "0.6.1", + "version": "0.6.2", "description": "A lightweight 3D physics engine written in JavaScript.", "homepage": "https://github.com/schteppe/cannon.js", "author": "Stefan Hedman (http://steffe.se)",