diff --git a/examples/spark/.babelrc b/examples/spark/.babelrc index b55ce67..410d04d 100644 --- a/examples/spark/.babelrc +++ b/examples/spark/.babelrc @@ -1,3 +1,12 @@ { + "presets": [ + [ + "@babel/preset-env", + { + "useBuiltIns": "entry", + "corejs": 3 + } + ] + ], "plugins": ["@babel/plugin-transform-object-assign"] } \ No newline at end of file diff --git a/examples/spark/package-lock.json b/examples/spark/package-lock.json index bed047b..8698087 100644 --- a/examples/spark/package-lock.json +++ b/examples/spark/package-lock.json @@ -1471,6 +1471,12 @@ "regenerator-runtime": "^0.11.0" }, "dependencies": { + "core-js": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", + "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", + "dev": true + }, "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", @@ -2018,10 +2024,9 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, "core-js": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", - "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", - "dev": true + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.4.tgz", + "integrity": "sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw==" }, "core-js-compat": { "version": "3.6.4", diff --git a/examples/spark/package.json b/examples/spark/package.json index c52d777..cf78c9d 100644 --- a/examples/spark/package.json +++ b/examples/spark/package.json @@ -10,6 +10,7 @@ "start": "npm run dev" }, "dependencies": { + "core-js": "^3.6.4", "physar": "file:../..", "short-uuid": "^3.1.1", "webpack": "^4.41.6" @@ -23,7 +24,6 @@ "babel-core": "^7.0.0-bridge.0", "babel-loader": "^8.0.0-beta.6", "babel-plugin-transform-class-properties": "^6.24.1", - "core-js": "^2.5.2", "regenerator-runtime": "^0.13.3", "webpack-cli": "^3.3.11" } diff --git a/examples/spark/physar_examples/scripts/script.js b/examples/spark/physar_examples/scripts/script.js index 42c1a65..97a6e98 100644 --- a/examples/spark/physar_examples/scripts/script.js +++ b/examples/spark/physar_examples/scripts/script.js @@ -1 +1,8 @@ -!function(t){var e={};function s(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,s),i.l=!0,i.exports}s.m=t,s.c=e,s.d=function(t,e,r){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)s.d(r,i,function(e){return t[e]}.bind(null,i));return r},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=4)}([function(t,e){t.exports=require("Time")},function(t,e){t.exports=require("cannon")},function(t,e){t.exports=require("Diagnostics")},function(t,e){t.exports=require("Scene")},function(t,e,s){"use strict";s.r(e);const r=s(3),i=r.root.find("SphereObject"),n=r.root.find("Cube01"),o=r.root.find("plane0"),a=new class{constructor(t){this.Diagnostics=void 0,this.Time=void 0,this.currentInterval=void 0,this.lastInterval=void 0,this.lastTime=void 0,this.fixedTimeStep=1/60,this.maxSubSteps=3,this.timeInterval=5,this.C=void 0,this.worldObjects=[],this.worldConstraints=[],this.defaults={body:{mass:0,radius:1,transform:{rotation:{x:0,y:0,z:0,w:.5},position:{x:0,y:0,z:0},scale:{x:1,y:1,z:1}}},sync:{properties:["position","rotation"],axes:["x","y","z"],rotation:{enabled:!0,allAxis:!0,x:!0,y:!0,z:!0},position:{enabled:!0,allAxis:!0,x:!0,y:!0,z:!0}}},this.initRequiredSparkModules(),this.createCWorld(t)}initRequiredSparkModules(){this.Time=s(0),this.C=s(1),this.Diagnostics=s(2)}createCWorld(t){this.world=new this.C.World,this.world.broadphase=new this.C.NaiveBroadphase,this.world.gravity.set(t.x,t.y,t.z)}beginSync(){this.initialWorldState=this.worldObjects,this.currentInterval=this.Time.setInterval(t=>{if(void 0!==this.lastTime){let e=(t-this.lastTime)/1e3;this.world.step(this.fixedTimeStep,e,this.maxSubSteps),this.objectSync()}this.lastTime=t},this.timeInterval)}objectSync(){this.worldObjects.forEach(t=>{if(t.spark){const e=t.sync,s=e.properties,r=e.axes,i={};t.body.quaternion.toEuler(i),s.forEach(e=>{t.sync[e].enabled&&r.forEach(s=>{if(t.sync[e].allAxis||t.sync[e][s]){const r=`rotation${s.toUpperCase()}`;"position"==e&&(t.spark.transform[s]=t.body[e][s]),"rotation"==e&&(t.spark.transform[r]=i[s])}})})}})}stopSync(){this.currentInterval&&(this.Time.clearInterval(this.currentInterval),this.lastInterval=currentInterval,this.currentInterval=void 0),this.resetWorldState()}getDefaults(t){return t?this.defaults[t]:this.defaults}fillWithDefaults(t){const e=this.getDefaults();return Object.keys(e).forEach(s=>{t.hasOwnProperty(s)||(t[s]=e[s]),Object.keys(e[s]).forEach(r=>{Array.isArray(t[s][r])?e[s][r].forEach(i=>{t[s][r].indexOf(i)<0&&t[s][r].push(e[s][r][i])}):(t[s].hasOwnProperty(r)||(t[s][r]=e[s][r]),"object"!=typeof e[s][r]||Array.isArray(e[s][r])||Object.keys(e[s][r]).forEach(i=>{t[s][r].hasOwnProperty(i)||(t[s][r][i]=e[s][r][i])}))})}),t}resetWorldState(){this.initialWorldState&&this.worldObjects.forEach((t,e)=>{const s=this.initialWorldState[e],r=s.body,i=t.body;if(i.velocity.setZero(),i.initVelocity.setZero(),i.angularVelocity.setZero(),i.initAngularVelocity.setZero(),i.force.setZero(),i.torque.setZero(),i.quaternion=r.quaternion,i.position=r.position,t.spark){const e=t.sync,r=e.properties,i=e.axes,n={};t.body.quaternion.toEuler(n),r.forEach(e=>{t.sync[e].enabled&&i.forEach(r=>{if(t.sync[e].allAxis||t.sync[e][r]){const i=`rotation${r.toUpperCase()}`;"position"==e&&(t.spark.transform[r]=s.spark.transform[r]),"rotation"==e&&(t.spark.transform[i]=s.spark.transform[i])}})})}})}createObject(t,e,s){const{sync:r,body:i}=this.fillWithDefaults(s),{mass:n,radius:o,transform:a}=i,c=a.rotation,d=a.scale,l=a.position,h=new this.C.Vec3(l.x,l.y,l.z),u=new this.C.Quaternion(c.x,c.y,c.z,c.w),f=t=>{switch(t){case"box":return new this.C.Box(new this.C.Vec3(d.x,d.y,d.z));case"sphere":return new this.C.Sphere(o);case"ground":return new this.C.Plane}},p=t=>{const s={mass:n,shape:t,position:h,quaternion:u,angularDamping:.8};return"sphere"==e&&(s.radius=o),"ground"==e&&(s.mass=0),s},y=(t=>{const e=new this.C.Body(p(f(t)));if("ground"==t){const t=-Math.PI/2,s=new this.C.Vec3(1,0,0);e.quaternion.setFromAxisAngle(s,t)}return e})(e);return this.addObjectToPhysicsWorld(y,t,r,"ground"==e)}find(t=0,e){return"object"==t?this.worldObjects.find(t=>t.id==e):"constraint"==t?this.worldConstraints.find(t=>t.id==e):void 0}createConstraint(t,e={}){if(!e.bodyA||!e.bodyB)return;let[s,r,i,n,o,a]=e;const c={pivotA:i,pivotB:n,axisA:o,axisB:a},d=this.find("object",s),l=this.find("object",r);if(!d||!l)return;let h;switch(t){case"point":h=new this.C.PointToPointConstraint(s,i,r,n);break;case"hinge":h=new this.C.HingeConstraint(s,r,c);break;case"conetwist":h=new this.C.ConeTwistConstraint(s,r,c);break;case"lock":h=new this.C.LockConstraint(i,n,{});break;default:return}return this.addConstraint(h,d,l)}addConstraint(t,e,s){if(!e.body||!s.body)return;const r=e.body,i=s.body;this.world.addConstraint(t);const n=btoa(`${r.id}.${i.id}`);return this.worldConstraints.push({id:n,constraint:t,isActive:!0}),n}removeConstraint(t,e=!1){const s=this.find("constraint",t);if(s&&this.world.removeConstraint(s.constraint),e){const t=this.worldConstraints.indexOf(s);this.worldConstraints.splice(t,1)}}pauseConstraint(t){const e=this.find("constraint",t);e&&this.removeConstraint(t,!1);const s=this.worldConstraints.indexOf(e);this.worldConstraints[s].isActive=!1}resumeConstraint(t){const e=this.find("constraint",t),s=e.constraint;if(e&&0==e.isActive){this.world.addConstraint(s);const t=this.worldConstraints.indexOf(e);this.worldConstraints[t].isActive=!0}}log(t){this.Diagnostics.log(t)}addObjectToPhysicsWorld(t,e,s,r){this.world.addBody(t);const i={...this.getDefaults("sync"),...s},n=((t,e)=>{for(e=t="";t++<36;e+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return e})(),o={id:n,body:t,spark:e,sync:i,isGround:r};return this.worldObjects.push(o),n}createCMaterial(t){let e=void 0;return null==t&&(e=new this.C.Material),e}start(){this.beginSync()}}({x:0,y:-9.82,z:0});a.createObject(o,"ground",{body:{mass:0,transform:{position:{x:0,y:0,z:0}}}});const c=a.createObject(i,"sphere",{body:{mass:1,radius:.01,transform:{position:{x:0,y:2,z:0}}}}),d=a.createObject(n,"box",{body:{mass:5,transform:{scale:{x:.01,y:.01,z:.01},position:{x:0,y:10,z:0},rotation:{x:.2,y:.8,z:.3,w:0}}}});a.addConstraint("point",c,d);a.start()}]); \ No newline at end of file +!function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=2)}({0:function(t,r,e){"use strict";(function(t){e.d(r,"a",(function(){return i}));var n=e(1);class i{constructor(t){this.Diagnostics=void 0,this.Time=void 0,this.currentInterval=void 0,this.lastInterval=void 0,this.lastTime=void 0,this.fixedTimeStep=1/60,this.maxSubSteps=3,this.timeInterval=5,this.C=void 0,this.worldObjects=[],this.worldConstraints=[],this.defaults={body:{mass:0,radius:1,transform:{rotation:{x:0,y:0,z:0,w:.5},position:{x:0,y:0,z:0},scale:{x:1,y:1,z:1}}},sync:{properties:["position","rotation"],axes:["x","y","z"],rotation:{enabled:!0,allAxis:!0,x:!0,y:!0,z:!0},position:{enabled:!0,allAxis:!0,x:!0,y:!0,z:!0}}},this.initRequiredSparkModules(),this.createCWorld(t)}initRequiredSparkModules(){this.Time=e(366),this.C=e(367),this.Diagnostics=e(368)}createCWorld(t){this.world=new this.C.World,this.world.broadphase=new this.C.NaiveBroadphase,this.world.gravity.set(t.x,t.y,t.z)}beginSync(){this.initialWorldState=this.worldObjects,this.currentInterval=this.Time.setInterval(t=>{if(void 0!==this.lastTime){let r=(t-this.lastTime)/1e3;this.world.step(this.fixedTimeStep,r,this.maxSubSteps),this.objectSync()}this.lastTime=t},this.timeInterval)}objectSync(){this.worldObjects.forEach(t=>{if(t.spark){const r=t.sync,e=r.properties,n=r.axes,i={};t.body.quaternion.toEuler(i),e.forEach(r=>{t.sync[r].enabled&&n.forEach(e=>{if(t.sync[r].allAxis||t.sync[r][e]){const n=`rotation${e.toUpperCase()}`;"position"==r&&(t.spark.transform[e]=t.body[r][e]),"rotation"==r&&(t.spark.transform[n]=i[e])}})})}})}stopSync(){this.currentInterval&&(this.Time.clearInterval(this.currentInterval),this.lastInterval=currentInterval,this.currentInterval=void 0),this.resetWorldState()}getDefaults(t){return t?this.defaults[t]:this.defaults}fillWithDefaults(t){const r=this.getDefaults();return Object.keys(r).forEach(e=>{t.hasOwnProperty(e)||(t[e]=r[e]),Object.keys(r[e]).forEach(n=>{Array.isArray(t[e][n])?r[e][n].forEach(i=>{t[e][n].indexOf(i)<0&&t[e][n].push(r[e][n][i])}):(t[e].hasOwnProperty(n)||(t[e][n]=r[e][n]),"object"!=typeof r[e][n]||Array.isArray(r[e][n])||Object.keys(r[e][n]).forEach(i=>{t[e][n].hasOwnProperty(i)||(t[e][n][i]=r[e][n][i])}))})}),t}resetWorldState(){this.initialWorldState&&this.worldObjects.forEach((t,r)=>{const e=this.initialWorldState[r],n=e.body,i=t.body;if(i.velocity.setZero(),i.initVelocity.setZero(),i.angularVelocity.setZero(),i.initAngularVelocity.setZero(),i.force.setZero(),i.torque.setZero(),i.quaternion=n.quaternion,i.position=n.position,t.spark){const r=t.sync,n=r.properties,i=r.axes,o={};t.body.quaternion.toEuler(o),n.forEach(r=>{t.sync[r].enabled&&i.forEach(n=>{if(t.sync[r].allAxis||t.sync[r][n]){const i=`rotation${n.toUpperCase()}`;"position"==r&&(t.spark.transform[n]=e.spark.transform[n]),"rotation"==r&&(t.spark.transform[i]=e.spark.transform[i])}})})}})}createObject(t,r,e){const{sync:n,body:i}=this.fillWithDefaults(e),{mass:o,radius:s,transform:a}=i,u=a.rotation,f=a.scale,h=a.position,c=new this.C.Vec3(h.x,h.y,h.z),l=new this.C.Quaternion(u.x,u.y,u.z,u.w),p=t=>{switch(t){case"box":return new this.C.Box(new this.C.Vec3(f.x,f.y,f.z));case"sphere":return new this.C.Sphere(s);case"ground":return new this.C.Plane}},d=t=>{const e={mass:o,shape:t,position:c,quaternion:l,angularDamping:.8};return"sphere"==r&&(e.radius=s),"ground"==r&&(e.mass=0),e},y=(t=>{const r=new this.C.Body(d(p(t)));if("ground"==t){const t=-Math.PI/2,e=new this.C.Vec3(1,0,0);r.quaternion.setFromAxisAngle(e,t)}return r})(r);return this.addObjectToPhysicsWorld(y,t,n,"ground"==r)}find(t,r){if("object"==t)for(var e=0;e{for(r=t="";t++<36;r+=51*t&52?(15^t?8^Math.random()*(20^t?16:4):4).toString(16):"-");return r}},150:function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},2:function(t,r,e){"use strict";e.r(r);var n=e(0),i=e(369),o=i.root.find("SphereObject"),s=i.root.find("Cube01"),a=i.root.find("plane0"),u=new n.a({x:0,y:-9.82,z:0});u.createObject(a,"ground",{body:{mass:0,transform:{position:{x:0,y:0,z:0}}}});var f={bodyA:u.createObject(o,"sphere",{body:{mass:1,radius:.01,transform:{position:{x:0,y:2,z:0}}}}),bodyB:u.createObject(s,"box",{body:{mass:5,transform:{scale:{x:.01,y:.01,z:.01},position:{x:0,y:10,z:0},rotation:{x:.2,y:.8,z:.3,w:0}}}})};u.createConstraint("point",f);u.start()},3:function(t,r,e){"use strict";(function(t){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +var n=e(4),i=e(5),o=e(6);function s(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,r){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function d(t,r){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return z(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return N(t).length;default:if(n)return z(t).length;r=(""+r).toLowerCase(),n=!0}}function y(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,r,e);case"utf8":case"utf-8":return C(this,r,e);case"ascii":return P(this,r,e);case"latin1":case"binary":return S(this,r,e);case"base64":return T(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function g(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function w(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=u.from(r,n)),u.isBuffer(r))return 0===r.length?-1:b(t,r,e,n,i);if("number"==typeof r)return r&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):b(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function b(t,r,e,n,i){var o,s=1,a=t.length,u=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;s=2,a/=2,u/=2,e/=2}function f(t,r){return 1===s?t[r]:t.readUInt16BE(r*s)}if(i){var h=-1;for(o=e;oa&&(e=a-u),o=e;o>=0;o--){for(var c=!0,l=0;li&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function T(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function C(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:f>223?3:f>191?2:1;if(i+c<=e)switch(c){case 1:f<128&&(h=f);break;case 2:128==(192&(o=t[i+1]))&&(u=(31&f)<<6|63&o)>127&&(h=u);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(u=(15&f)<<12|(63&o)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(u=(15&f)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,c=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=c}return function(t){var r=t.length;if(r<=4096)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},u.prototype.compare=function(t,r,e,n,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(e>>>=0)-(r>>>=0),a=Math.min(o,s),f=this.slice(n,i),h=t.slice(r,e),c=0;ci)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return A(this,t,r,e);case"ascii":return m(this,t,r,e);case"latin1":case"binary":return E(this,t,r,e);case"base64":return _(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function P(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function U(t,r,e,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function I(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i>>8*(n?i:1-i)}function Y(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i>>8*(n?i:3-i)&255}function M(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function j(t,r,e,n,o){return o||M(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function D(t,r,e,n,o){return o||M(t,0,e,8),i.write(t,r,e,n,52,8),e+8}u.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(i*=256);)n+=this[t+--r]*i;return n},u.prototype.readUInt8=function(t,r){return r||O(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,r){return r||O(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,r){return r||O(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,r){return r||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,r){return r||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||O(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},u.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||O(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},u.prototype.readInt8=function(t,r){return r||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,r){r||O(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},u.prototype.readInt16BE=function(t,r){r||O(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},u.prototype.readInt32LE=function(t,r){return r||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,r){return r||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,r){return r||O(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,r){return r||O(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,r){return r||O(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,r){return r||O(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||U(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o=0&&(o*=256);)this[r+i]=t/o&255;return r+e},u.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},u.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):I(this,t,r,!0),r+2},u.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):I(this,t,r,!1),r+2},u.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Y(this,t,r,!0),r+4},u.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},u.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);U(this,t,r,e,i-1,-i)}var o=0,s=1,a=0;for(this[r]=255&t;++o>0)-a&255;return r+e},u.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);U(this,t,r,e,i-1,-i)}var o=e-1,s=1,a=0;for(this[r+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[r+o+1]&&(a=1),this[r+o]=(t/s>>0)-a&255;return r+e},u.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},u.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):I(this,t,r,!0),r+2},u.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):I(this,t,r,!1),r+2},u.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Y(this,t,r,!0),r+4},u.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||U(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},u.prototype.writeFloatLE=function(t,r,e){return j(this,t,r,!0,e)},u.prototype.writeFloatBE=function(t,r,e){return j(this,t,r,!1,e)},u.prototype.writeDoubleLE=function(t,r,e){return D(this,t,r,!0,e)},u.prototype.writeDoubleBE=function(t,r,e){return D(this,t,r,!1,e)},u.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--i)t[i+r]=this[i+e];else if(o<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function N(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(k,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function q(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(this,e(150))},366:function(t,r){t.exports=require("Time")},367:function(t,r){t.exports=require("cannon")},368:function(t,r){t.exports=require("Diagnostics")},369:function(t,r){t.exports=require("Scene")},4:function(t,r,e){"use strict";r.byteLength=function(t){var r=f(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){var r,e,n=f(t),s=n[0],a=n[1],u=new o(function(t,r,e){return 3*(r+e)/4-e}(0,s,a)),h=0,c=a>0?s-4:s;for(e=0;e>16&255,u[h++]=r>>8&255,u[h++]=255&r;2===a&&(r=i[t.charCodeAt(e)]<<2|i[t.charCodeAt(e+1)]>>4,u[h++]=255&r);1===a&&(r=i[t.charCodeAt(e)]<<10|i[t.charCodeAt(e+1)]<<4|i[t.charCodeAt(e+2)]>>2,u[h++]=r>>8&255,u[h++]=255&r);return u},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],s=0,a=e-i;sa?a:s+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function h(t,r,e){for(var i,o,s=[],a=r;a>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},5:function(t,r){r.read=function(t,r,e,n,i){var o,s,a=8*i-n-1,u=(1<>1,h=-7,c=e?i-1:0,l=e?-1:1,p=t[r+c];for(c+=l,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[r+c],c+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[r+c],c+=l,h-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=f}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var s,a,u,f=8*o-i-1,h=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,y=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,s=h):(s=Math.floor(Math.log(r)/Math.LN2),r*(u=Math.pow(2,-s))<1&&(s--,u*=2),(r+=s+c>=1?l/u:l*Math.pow(2,1-c))*u>=2&&(s++,u/=2),s+c>=h?(a=0,s=h):s+c>=1?(a=(r*u-1)*Math.pow(2,i),s+=c):(a=r*Math.pow(2,c-1)*Math.pow(2,i),s=0));i>=8;t[e+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[e+p]=255&s,p+=d,s/=256,f-=8);t[e+p-d]|=128*y}},6:function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}}}); \ No newline at end of file diff --git a/examples/spark/src/index.js b/examples/spark/src/index.js index abaf55d..8aae8a8 100644 --- a/examples/spark/src/index.js +++ b/examples/spark/src/index.js @@ -1,4 +1,3 @@ - import Physar from 'physar' const Scene = require('Scene'); @@ -62,5 +61,10 @@ physar.createObject(plane, 'ground', groundProps) const sphereID = physar.createObject(sphere, 'sphere', sphereProps) const boxID = physar.createObject(cube, 'box', cubeProps) -const constraint = physar.addConstraint('point', sphereID, boxID) +const constraintProps = { + bodyA: sphereID, + bodyB: boxID +} + +const constraint = physar.createConstraint('point', constraintProps) physar.start()