es6.js 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import * as BABYLON from 'babylonjs/core/es6';
  12. import * as picking from 'babylonjs/picking/es6';
  13. __extends(BABYLON, picking);
  14. var BABYLON;
  15. (function (BABYLON) {
  16. /**
  17. * This is a holder class for the physics joint created by the physics plugin.
  18. * It holds a set of functions to control the underlying joint.
  19. */
  20. var PhysicsJoint = /** @class */ (function () {
  21. function PhysicsJoint(type, jointData) {
  22. this.type = type;
  23. this.jointData = jointData;
  24. jointData.nativeParams = jointData.nativeParams || {};
  25. }
  26. Object.defineProperty(PhysicsJoint.prototype, "physicsJoint", {
  27. get: function () {
  28. return this._physicsJoint;
  29. },
  30. set: function (newJoint) {
  31. if (this._physicsJoint) {
  32. //remove from the wolrd
  33. }
  34. this._physicsJoint = newJoint;
  35. },
  36. enumerable: true,
  37. configurable: true
  38. });
  39. Object.defineProperty(PhysicsJoint.prototype, "physicsPlugin", {
  40. set: function (physicsPlugin) {
  41. this._physicsPlugin = physicsPlugin;
  42. },
  43. enumerable: true,
  44. configurable: true
  45. });
  46. /**
  47. * Execute a function that is physics-plugin specific.
  48. * @param {Function} func the function that will be executed.
  49. * It accepts two parameters: the physics world and the physics joint.
  50. */
  51. PhysicsJoint.prototype.executeNativeFunction = function (func) {
  52. func(this._physicsPlugin.world, this._physicsJoint);
  53. };
  54. //TODO check if the native joints are the same
  55. //Joint Types
  56. PhysicsJoint.DistanceJoint = 0;
  57. PhysicsJoint.HingeJoint = 1;
  58. PhysicsJoint.BallAndSocketJoint = 2;
  59. PhysicsJoint.WheelJoint = 3;
  60. PhysicsJoint.SliderJoint = 4;
  61. //OIMO
  62. PhysicsJoint.PrismaticJoint = 5;
  63. //ENERGY FTW! (compare with this - http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions)
  64. PhysicsJoint.UniversalJoint = 6;
  65. PhysicsJoint.Hinge2Joint = PhysicsJoint.WheelJoint;
  66. //Cannon
  67. //Similar to a Ball-Joint. Different in params
  68. PhysicsJoint.PointToPointJoint = 8;
  69. //Cannon only at the moment
  70. PhysicsJoint.SpringJoint = 9;
  71. PhysicsJoint.LockJoint = 10;
  72. return PhysicsJoint;
  73. }());
  74. BABYLON.PhysicsJoint = PhysicsJoint;
  75. /**
  76. * A class representing a physics distance joint.
  77. */
  78. var DistanceJoint = /** @class */ (function (_super) {
  79. __extends(DistanceJoint, _super);
  80. function DistanceJoint(jointData) {
  81. return _super.call(this, PhysicsJoint.DistanceJoint, jointData) || this;
  82. }
  83. /**
  84. * Update the predefined distance.
  85. */
  86. DistanceJoint.prototype.updateDistance = function (maxDistance, minDistance) {
  87. this._physicsPlugin.updateDistanceJoint(this, maxDistance, minDistance);
  88. };
  89. return DistanceJoint;
  90. }(PhysicsJoint));
  91. BABYLON.DistanceJoint = DistanceJoint;
  92. var MotorEnabledJoint = /** @class */ (function (_super) {
  93. __extends(MotorEnabledJoint, _super);
  94. function MotorEnabledJoint(type, jointData) {
  95. return _super.call(this, type, jointData) || this;
  96. }
  97. /**
  98. * Set the motor values.
  99. * Attention, this function is plugin specific. Engines won't react 100% the same.
  100. * @param {number} force the force to apply
  101. * @param {number} maxForce max force for this motor.
  102. */
  103. MotorEnabledJoint.prototype.setMotor = function (force, maxForce) {
  104. this._physicsPlugin.setMotor(this, force || 0, maxForce);
  105. };
  106. /**
  107. * Set the motor's limits.
  108. * Attention, this function is plugin specific. Engines won't react 100% the same.
  109. */
  110. MotorEnabledJoint.prototype.setLimit = function (upperLimit, lowerLimit) {
  111. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
  112. };
  113. return MotorEnabledJoint;
  114. }(PhysicsJoint));
  115. BABYLON.MotorEnabledJoint = MotorEnabledJoint;
  116. /**
  117. * This class represents a single hinge physics joint
  118. */
  119. var HingeJoint = /** @class */ (function (_super) {
  120. __extends(HingeJoint, _super);
  121. function HingeJoint(jointData) {
  122. return _super.call(this, PhysicsJoint.HingeJoint, jointData) || this;
  123. }
  124. /**
  125. * Set the motor values.
  126. * Attention, this function is plugin specific. Engines won't react 100% the same.
  127. * @param {number} force the force to apply
  128. * @param {number} maxForce max force for this motor.
  129. */
  130. HingeJoint.prototype.setMotor = function (force, maxForce) {
  131. this._physicsPlugin.setMotor(this, force || 0, maxForce);
  132. };
  133. /**
  134. * Set the motor's limits.
  135. * Attention, this function is plugin specific. Engines won't react 100% the same.
  136. */
  137. HingeJoint.prototype.setLimit = function (upperLimit, lowerLimit) {
  138. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
  139. };
  140. return HingeJoint;
  141. }(MotorEnabledJoint));
  142. BABYLON.HingeJoint = HingeJoint;
  143. /**
  144. * This class represents a dual hinge physics joint (same as wheel joint)
  145. */
  146. var Hinge2Joint = /** @class */ (function (_super) {
  147. __extends(Hinge2Joint, _super);
  148. function Hinge2Joint(jointData) {
  149. return _super.call(this, PhysicsJoint.Hinge2Joint, jointData) || this;
  150. }
  151. /**
  152. * Set the motor values.
  153. * Attention, this function is plugin specific. Engines won't react 100% the same.
  154. * @param {number} force the force to apply
  155. * @param {number} maxForce max force for this motor.
  156. * @param {motorIndex} the motor's index, 0 or 1.
  157. */
  158. Hinge2Joint.prototype.setMotor = function (force, maxForce, motorIndex) {
  159. if (motorIndex === void 0) { motorIndex = 0; }
  160. this._physicsPlugin.setMotor(this, force || 0, maxForce, motorIndex);
  161. };
  162. /**
  163. * Set the motor limits.
  164. * Attention, this function is plugin specific. Engines won't react 100% the same.
  165. * @param {number} upperLimit the upper limit
  166. * @param {number} lowerLimit lower limit
  167. * @param {motorIndex} the motor's index, 0 or 1.
  168. */
  169. Hinge2Joint.prototype.setLimit = function (upperLimit, lowerLimit, motorIndex) {
  170. if (motorIndex === void 0) { motorIndex = 0; }
  171. this._physicsPlugin.setLimit(this, upperLimit, lowerLimit, motorIndex);
  172. };
  173. return Hinge2Joint;
  174. }(MotorEnabledJoint));
  175. BABYLON.Hinge2Joint = Hinge2Joint;
  176. })(BABYLON || (BABYLON = {}));
  177. //# sourceMappingURL=babylon.physicsJoint.js.map
  178. var BABYLON;
  179. (function (BABYLON) {
  180. var PhysicsImpostor = /** @class */ (function () {
  181. function PhysicsImpostor(object, type, _options, _scene) {
  182. if (_options === void 0) { _options = { mass: 0 }; }
  183. var _this = this;
  184. this.object = object;
  185. this.type = type;
  186. this._options = _options;
  187. this._scene = _scene;
  188. this._bodyUpdateRequired = false;
  189. this._onBeforePhysicsStepCallbacks = new Array();
  190. this._onAfterPhysicsStepCallbacks = new Array();
  191. this._onPhysicsCollideCallbacks = [];
  192. this._deltaPosition = BABYLON.Vector3.Zero();
  193. this._isDisposed = false;
  194. //temp variables for parent rotation calculations
  195. //private _mats: Array<Matrix> = [new Matrix(), new Matrix()];
  196. this._tmpQuat = new BABYLON.Quaternion();
  197. this._tmpQuat2 = new BABYLON.Quaternion();
  198. /**
  199. * this function is executed by the physics engine.
  200. */
  201. this.beforeStep = function () {
  202. if (!_this._physicsEngine) {
  203. return;
  204. }
  205. _this.object.translate(_this._deltaPosition, -1);
  206. _this._deltaRotationConjugated && _this.object.rotationQuaternion && _this.object.rotationQuaternion.multiplyToRef(_this._deltaRotationConjugated, _this.object.rotationQuaternion);
  207. _this.object.computeWorldMatrix(false);
  208. if (_this.object.parent && _this.object.rotationQuaternion) {
  209. _this.getParentsRotation();
  210. _this._tmpQuat.multiplyToRef(_this.object.rotationQuaternion, _this._tmpQuat);
  211. }
  212. else {
  213. _this._tmpQuat.copyFrom(_this.object.rotationQuaternion || new BABYLON.Quaternion());
  214. }
  215. if (!_this._options.disableBidirectionalTransformation) {
  216. _this.object.rotationQuaternion && _this._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(_this, /*bInfo.boundingBox.centerWorld*/ _this.object.getAbsolutePivotPoint(), _this._tmpQuat);
  217. }
  218. _this._onBeforePhysicsStepCallbacks.forEach(function (func) {
  219. func(_this);
  220. });
  221. };
  222. /**
  223. * this function is executed by the physics engine.
  224. */
  225. this.afterStep = function () {
  226. if (!_this._physicsEngine) {
  227. return;
  228. }
  229. _this._onAfterPhysicsStepCallbacks.forEach(function (func) {
  230. func(_this);
  231. });
  232. _this._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(_this);
  233. // object has now its world rotation. needs to be converted to local.
  234. if (_this.object.parent && _this.object.rotationQuaternion) {
  235. _this.getParentsRotation();
  236. _this._tmpQuat.conjugateInPlace();
  237. _this._tmpQuat.multiplyToRef(_this.object.rotationQuaternion, _this.object.rotationQuaternion);
  238. }
  239. // take the position set and make it the absolute position of this object.
  240. _this.object.setAbsolutePosition(_this.object.position);
  241. _this._deltaRotation && _this.object.rotationQuaternion && _this.object.rotationQuaternion.multiplyToRef(_this._deltaRotation, _this.object.rotationQuaternion);
  242. _this.object.translate(_this._deltaPosition, 1);
  243. };
  244. /**
  245. * Legacy collision detection event support
  246. */
  247. this.onCollideEvent = null;
  248. //event and body object due to cannon's event-based architecture.
  249. this.onCollide = function (e) {
  250. if (!_this._onPhysicsCollideCallbacks.length && !_this.onCollideEvent) {
  251. return;
  252. }
  253. if (!_this._physicsEngine) {
  254. return;
  255. }
  256. var otherImpostor = _this._physicsEngine.getImpostorWithPhysicsBody(e.body);
  257. if (otherImpostor) {
  258. // Legacy collision detection event support
  259. if (_this.onCollideEvent) {
  260. _this.onCollideEvent(_this, otherImpostor);
  261. }
  262. _this._onPhysicsCollideCallbacks.filter(function (obj) {
  263. return obj.otherImpostors.indexOf(otherImpostor) !== -1;
  264. }).forEach(function (obj) {
  265. obj.callback(_this, otherImpostor);
  266. });
  267. }
  268. };
  269. //sanity check!
  270. if (!this.object) {
  271. BABYLON.Tools.Error("No object was provided. A physics object is obligatory");
  272. return;
  273. }
  274. //legacy support for old syntax.
  275. if (!this._scene && object.getScene) {
  276. this._scene = object.getScene();
  277. }
  278. if (!this._scene) {
  279. return;
  280. }
  281. this._physicsEngine = this._scene.getPhysicsEngine();
  282. if (!this._physicsEngine) {
  283. BABYLON.Tools.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors.");
  284. }
  285. else {
  286. //set the object's quaternion, if not set
  287. if (!this.object.rotationQuaternion) {
  288. if (this.object.rotation) {
  289. this.object.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.object.rotation.y, this.object.rotation.x, this.object.rotation.z);
  290. }
  291. else {
  292. this.object.rotationQuaternion = new BABYLON.Quaternion();
  293. }
  294. }
  295. //default options params
  296. this._options.mass = (_options.mass === void 0) ? 0 : _options.mass;
  297. this._options.friction = (_options.friction === void 0) ? 0.2 : _options.friction;
  298. this._options.restitution = (_options.restitution === void 0) ? 0.2 : _options.restitution;
  299. this._joints = [];
  300. //If the mesh has a parent, don't initialize the physicsBody. Instead wait for the parent to do that.
  301. if (!this.object.parent || this._options.ignoreParent) {
  302. this._init();
  303. }
  304. else if (this.object.parent.physicsImpostor) {
  305. BABYLON.Tools.Warn("You must affect impostors to children before affecting impostor to parent.");
  306. }
  307. }
  308. }
  309. Object.defineProperty(PhysicsImpostor.prototype, "isDisposed", {
  310. get: function () {
  311. return this._isDisposed;
  312. },
  313. enumerable: true,
  314. configurable: true
  315. });
  316. Object.defineProperty(PhysicsImpostor.prototype, "mass", {
  317. get: function () {
  318. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyMass(this) : 0;
  319. },
  320. set: function (value) {
  321. this.setMass(value);
  322. },
  323. enumerable: true,
  324. configurable: true
  325. });
  326. Object.defineProperty(PhysicsImpostor.prototype, "friction", {
  327. get: function () {
  328. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyFriction(this) : 0;
  329. },
  330. set: function (value) {
  331. if (!this._physicsEngine) {
  332. return;
  333. }
  334. this._physicsEngine.getPhysicsPlugin().setBodyFriction(this, value);
  335. },
  336. enumerable: true,
  337. configurable: true
  338. });
  339. Object.defineProperty(PhysicsImpostor.prototype, "restitution", {
  340. get: function () {
  341. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyRestitution(this) : 0;
  342. },
  343. set: function (value) {
  344. if (!this._physicsEngine) {
  345. return;
  346. }
  347. this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this, value);
  348. },
  349. enumerable: true,
  350. configurable: true
  351. });
  352. /**
  353. * This function will completly initialize this impostor.
  354. * It will create a new body - but only if this mesh has no parent.
  355. * If it has, this impostor will not be used other than to define the impostor
  356. * of the child mesh.
  357. */
  358. PhysicsImpostor.prototype._init = function () {
  359. if (!this._physicsEngine) {
  360. return;
  361. }
  362. this._physicsEngine.removeImpostor(this);
  363. this.physicsBody = null;
  364. this._parent = this._parent || this._getPhysicsParent();
  365. if (!this._isDisposed && (!this.parent || this._options.ignoreParent)) {
  366. this._physicsEngine.addImpostor(this);
  367. }
  368. };
  369. PhysicsImpostor.prototype._getPhysicsParent = function () {
  370. if (this.object.parent instanceof BABYLON.AbstractMesh) {
  371. var parentMesh = this.object.parent;
  372. return parentMesh.physicsImpostor;
  373. }
  374. return null;
  375. };
  376. /**
  377. * Should a new body be generated.
  378. */
  379. PhysicsImpostor.prototype.isBodyInitRequired = function () {
  380. return this._bodyUpdateRequired || (!this._physicsBody && !this._parent);
  381. };
  382. PhysicsImpostor.prototype.setScalingUpdated = function (updated) {
  383. this.forceUpdate();
  384. };
  385. /**
  386. * Force a regeneration of this or the parent's impostor's body.
  387. * Use under cautious - This will remove all joints already implemented.
  388. */
  389. PhysicsImpostor.prototype.forceUpdate = function () {
  390. this._init();
  391. if (this.parent && !this._options.ignoreParent) {
  392. this.parent.forceUpdate();
  393. }
  394. };
  395. Object.defineProperty(PhysicsImpostor.prototype, "physicsBody", {
  396. /*public get mesh(): AbstractMesh {
  397. return this._mesh;
  398. }*/
  399. /**
  400. * Gets the body that holds this impostor. Either its own, or its parent.
  401. */
  402. get: function () {
  403. return (this._parent && !this._options.ignoreParent) ? this._parent.physicsBody : this._physicsBody;
  404. },
  405. /**
  406. * Set the physics body. Used mainly by the physics engine/plugin
  407. */
  408. set: function (physicsBody) {
  409. if (this._physicsBody && this._physicsEngine) {
  410. this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this);
  411. }
  412. this._physicsBody = physicsBody;
  413. this.resetUpdateFlags();
  414. },
  415. enumerable: true,
  416. configurable: true
  417. });
  418. Object.defineProperty(PhysicsImpostor.prototype, "parent", {
  419. get: function () {
  420. return !this._options.ignoreParent && this._parent ? this._parent : null;
  421. },
  422. set: function (value) {
  423. this._parent = value;
  424. },
  425. enumerable: true,
  426. configurable: true
  427. });
  428. PhysicsImpostor.prototype.resetUpdateFlags = function () {
  429. this._bodyUpdateRequired = false;
  430. };
  431. PhysicsImpostor.prototype.getObjectExtendSize = function () {
  432. if (this.object.getBoundingInfo) {
  433. var q = this.object.rotationQuaternion;
  434. //reset rotation
  435. this.object.rotationQuaternion = PhysicsImpostor.IDENTITY_QUATERNION;
  436. //calculate the world matrix with no rotation
  437. this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
  438. var boundingInfo = this.object.getBoundingInfo();
  439. var size = boundingInfo.boundingBox.extendSizeWorld.scale(2);
  440. //bring back the rotation
  441. this.object.rotationQuaternion = q;
  442. //calculate the world matrix with the new rotation
  443. this.object.computeWorldMatrix && this.object.computeWorldMatrix(true);
  444. return size;
  445. }
  446. else {
  447. return PhysicsImpostor.DEFAULT_OBJECT_SIZE;
  448. }
  449. };
  450. PhysicsImpostor.prototype.getObjectCenter = function () {
  451. if (this.object.getBoundingInfo) {
  452. var boundingInfo = this.object.getBoundingInfo();
  453. return boundingInfo.boundingBox.centerWorld;
  454. }
  455. else {
  456. return this.object.position;
  457. }
  458. };
  459. /**
  460. * Get a specific parametes from the options parameter.
  461. */
  462. PhysicsImpostor.prototype.getParam = function (paramName) {
  463. return this._options[paramName];
  464. };
  465. /**
  466. * Sets a specific parameter in the options given to the physics plugin
  467. */
  468. PhysicsImpostor.prototype.setParam = function (paramName, value) {
  469. this._options[paramName] = value;
  470. this._bodyUpdateRequired = true;
  471. };
  472. /**
  473. * Specifically change the body's mass option. Won't recreate the physics body object
  474. */
  475. PhysicsImpostor.prototype.setMass = function (mass) {
  476. if (this.getParam("mass") !== mass) {
  477. this.setParam("mass", mass);
  478. }
  479. if (this._physicsEngine) {
  480. this._physicsEngine.getPhysicsPlugin().setBodyMass(this, mass);
  481. }
  482. };
  483. PhysicsImpostor.prototype.getLinearVelocity = function () {
  484. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this) : BABYLON.Vector3.Zero();
  485. };
  486. PhysicsImpostor.prototype.setLinearVelocity = function (velocity) {
  487. if (this._physicsEngine) {
  488. this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this, velocity);
  489. }
  490. };
  491. PhysicsImpostor.prototype.getAngularVelocity = function () {
  492. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this) : BABYLON.Vector3.Zero();
  493. };
  494. PhysicsImpostor.prototype.setAngularVelocity = function (velocity) {
  495. if (this._physicsEngine) {
  496. this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this, velocity);
  497. }
  498. };
  499. /**
  500. * Execute a function with the physics plugin native code.
  501. * Provide a function the will have two variables - the world object and the physics body object.
  502. */
  503. PhysicsImpostor.prototype.executeNativeFunction = function (func) {
  504. if (this._physicsEngine) {
  505. func(this._physicsEngine.getPhysicsPlugin().world, this.physicsBody);
  506. }
  507. };
  508. /**
  509. * Register a function that will be executed before the physics world is stepping forward.
  510. */
  511. PhysicsImpostor.prototype.registerBeforePhysicsStep = function (func) {
  512. this._onBeforePhysicsStepCallbacks.push(func);
  513. };
  514. PhysicsImpostor.prototype.unregisterBeforePhysicsStep = function (func) {
  515. var index = this._onBeforePhysicsStepCallbacks.indexOf(func);
  516. if (index > -1) {
  517. this._onBeforePhysicsStepCallbacks.splice(index, 1);
  518. }
  519. else {
  520. BABYLON.Tools.Warn("Function to remove was not found");
  521. }
  522. };
  523. /**
  524. * Register a function that will be executed after the physics step
  525. */
  526. PhysicsImpostor.prototype.registerAfterPhysicsStep = function (func) {
  527. this._onAfterPhysicsStepCallbacks.push(func);
  528. };
  529. PhysicsImpostor.prototype.unregisterAfterPhysicsStep = function (func) {
  530. var index = this._onAfterPhysicsStepCallbacks.indexOf(func);
  531. if (index > -1) {
  532. this._onAfterPhysicsStepCallbacks.splice(index, 1);
  533. }
  534. else {
  535. BABYLON.Tools.Warn("Function to remove was not found");
  536. }
  537. };
  538. /**
  539. * register a function that will be executed when this impostor collides against a different body.
  540. */
  541. PhysicsImpostor.prototype.registerOnPhysicsCollide = function (collideAgainst, func) {
  542. var collidedAgainstList = collideAgainst instanceof Array ? collideAgainst : [collideAgainst];
  543. this._onPhysicsCollideCallbacks.push({ callback: func, otherImpostors: collidedAgainstList });
  544. };
  545. PhysicsImpostor.prototype.unregisterOnPhysicsCollide = function (collideAgainst, func) {
  546. var collidedAgainstList = collideAgainst instanceof Array ? collideAgainst : [collideAgainst];
  547. var index = this._onPhysicsCollideCallbacks.indexOf({ callback: func, otherImpostors: collidedAgainstList });
  548. if (index > -1) {
  549. this._onPhysicsCollideCallbacks.splice(index, 1);
  550. }
  551. else {
  552. BABYLON.Tools.Warn("Function to remove was not found");
  553. }
  554. };
  555. PhysicsImpostor.prototype.getParentsRotation = function () {
  556. var parent = this.object.parent;
  557. this._tmpQuat.copyFromFloats(0, 0, 0, 1);
  558. while (parent) {
  559. if (parent.rotationQuaternion) {
  560. this._tmpQuat2.copyFrom(parent.rotationQuaternion);
  561. }
  562. else {
  563. BABYLON.Quaternion.RotationYawPitchRollToRef(parent.rotation.y, parent.rotation.x, parent.rotation.z, this._tmpQuat2);
  564. }
  565. this._tmpQuat.multiplyToRef(this._tmpQuat2, this._tmpQuat);
  566. parent = parent.parent;
  567. }
  568. return this._tmpQuat;
  569. };
  570. /**
  571. * Apply a force
  572. */
  573. PhysicsImpostor.prototype.applyForce = function (force, contactPoint) {
  574. if (this._physicsEngine) {
  575. this._physicsEngine.getPhysicsPlugin().applyForce(this, force, contactPoint);
  576. }
  577. return this;
  578. };
  579. /**
  580. * Apply an impulse
  581. */
  582. PhysicsImpostor.prototype.applyImpulse = function (force, contactPoint) {
  583. if (this._physicsEngine) {
  584. this._physicsEngine.getPhysicsPlugin().applyImpulse(this, force, contactPoint);
  585. }
  586. return this;
  587. };
  588. /**
  589. * A help function to create a joint.
  590. */
  591. PhysicsImpostor.prototype.createJoint = function (otherImpostor, jointType, jointData) {
  592. var joint = new BABYLON.PhysicsJoint(jointType, jointData);
  593. this.addJoint(otherImpostor, joint);
  594. return this;
  595. };
  596. /**
  597. * Add a joint to this impostor with a different impostor.
  598. */
  599. PhysicsImpostor.prototype.addJoint = function (otherImpostor, joint) {
  600. this._joints.push({
  601. otherImpostor: otherImpostor,
  602. joint: joint
  603. });
  604. if (this._physicsEngine) {
  605. this._physicsEngine.addJoint(this, otherImpostor, joint);
  606. }
  607. return this;
  608. };
  609. /**
  610. * Will keep this body still, in a sleep mode.
  611. */
  612. PhysicsImpostor.prototype.sleep = function () {
  613. if (this._physicsEngine) {
  614. this._physicsEngine.getPhysicsPlugin().sleepBody(this);
  615. }
  616. return this;
  617. };
  618. /**
  619. * Wake the body up.
  620. */
  621. PhysicsImpostor.prototype.wakeUp = function () {
  622. if (this._physicsEngine) {
  623. this._physicsEngine.getPhysicsPlugin().wakeUpBody(this);
  624. }
  625. return this;
  626. };
  627. PhysicsImpostor.prototype.clone = function (newObject) {
  628. if (!newObject)
  629. return null;
  630. return new PhysicsImpostor(newObject, this.type, this._options, this._scene);
  631. };
  632. PhysicsImpostor.prototype.dispose = function () {
  633. var _this = this;
  634. //no dispose if no physics engine is available.
  635. if (!this._physicsEngine) {
  636. return;
  637. }
  638. this._joints.forEach(function (j) {
  639. if (_this._physicsEngine) {
  640. _this._physicsEngine.removeJoint(_this, j.otherImpostor, j.joint);
  641. }
  642. });
  643. //dispose the physics body
  644. this._physicsEngine.removeImpostor(this);
  645. if (this.parent) {
  646. this.parent.forceUpdate();
  647. }
  648. else {
  649. /*this._object.getChildMeshes().forEach(function(mesh) {
  650. if (mesh.physicsImpostor) {
  651. if (disposeChildren) {
  652. mesh.physicsImpostor.dispose();
  653. mesh.physicsImpostor = null;
  654. }
  655. }
  656. })*/
  657. }
  658. this._isDisposed = true;
  659. };
  660. PhysicsImpostor.prototype.setDeltaPosition = function (position) {
  661. this._deltaPosition.copyFrom(position);
  662. };
  663. PhysicsImpostor.prototype.setDeltaRotation = function (rotation) {
  664. if (!this._deltaRotation) {
  665. this._deltaRotation = new BABYLON.Quaternion();
  666. }
  667. this._deltaRotation.copyFrom(rotation);
  668. this._deltaRotationConjugated = this._deltaRotation.conjugate();
  669. };
  670. PhysicsImpostor.prototype.getBoxSizeToRef = function (result) {
  671. if (this._physicsEngine) {
  672. this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this, result);
  673. }
  674. return this;
  675. };
  676. PhysicsImpostor.prototype.getRadius = function () {
  677. return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getRadius(this) : 0;
  678. };
  679. /**
  680. * Sync a bone with this impostor
  681. * @param bone The bone to sync to the impostor.
  682. * @param boneMesh The mesh that the bone is influencing.
  683. * @param jointPivot The pivot of the joint / bone in local space.
  684. * @param distToJoint Optional distance from the impostor to the joint.
  685. * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
  686. */
  687. PhysicsImpostor.prototype.syncBoneWithImpostor = function (bone, boneMesh, jointPivot, distToJoint, adjustRotation) {
  688. var tempVec = PhysicsImpostor._tmpVecs[0];
  689. var mesh = this.object;
  690. if (mesh.rotationQuaternion) {
  691. if (adjustRotation) {
  692. var tempQuat = PhysicsImpostor._tmpQuat;
  693. mesh.rotationQuaternion.multiplyToRef(adjustRotation, tempQuat);
  694. bone.setRotationQuaternion(tempQuat, BABYLON.Space.WORLD, boneMesh);
  695. }
  696. else {
  697. bone.setRotationQuaternion(mesh.rotationQuaternion, BABYLON.Space.WORLD, boneMesh);
  698. }
  699. }
  700. tempVec.x = 0;
  701. tempVec.y = 0;
  702. tempVec.z = 0;
  703. if (jointPivot) {
  704. tempVec.x = jointPivot.x;
  705. tempVec.y = jointPivot.y;
  706. tempVec.z = jointPivot.z;
  707. bone.getDirectionToRef(tempVec, boneMesh, tempVec);
  708. if (distToJoint === undefined || distToJoint === null) {
  709. distToJoint = jointPivot.length();
  710. }
  711. tempVec.x *= distToJoint;
  712. tempVec.y *= distToJoint;
  713. tempVec.z *= distToJoint;
  714. }
  715. if (bone.getParent()) {
  716. tempVec.addInPlace(mesh.getAbsolutePosition());
  717. bone.setAbsolutePosition(tempVec, boneMesh);
  718. }
  719. else {
  720. boneMesh.setAbsolutePosition(mesh.getAbsolutePosition());
  721. boneMesh.position.x -= tempVec.x;
  722. boneMesh.position.y -= tempVec.y;
  723. boneMesh.position.z -= tempVec.z;
  724. }
  725. };
  726. /**
  727. * Sync impostor to a bone
  728. * @param bone The bone that the impostor will be synced to.
  729. * @param boneMesh The mesh that the bone is influencing.
  730. * @param jointPivot The pivot of the joint / bone in local space.
  731. * @param distToJoint Optional distance from the impostor to the joint.
  732. * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.
  733. * @param boneAxis Optional vector3 axis the bone is aligned with
  734. */
  735. PhysicsImpostor.prototype.syncImpostorWithBone = function (bone, boneMesh, jointPivot, distToJoint, adjustRotation, boneAxis) {
  736. var mesh = this.object;
  737. if (mesh.rotationQuaternion) {
  738. if (adjustRotation) {
  739. var tempQuat = PhysicsImpostor._tmpQuat;
  740. bone.getRotationQuaternionToRef(BABYLON.Space.WORLD, boneMesh, tempQuat);
  741. tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);
  742. }
  743. else {
  744. bone.getRotationQuaternionToRef(BABYLON.Space.WORLD, boneMesh, mesh.rotationQuaternion);
  745. }
  746. }
  747. var pos = PhysicsImpostor._tmpVecs[0];
  748. var boneDir = PhysicsImpostor._tmpVecs[1];
  749. if (!boneAxis) {
  750. boneAxis = PhysicsImpostor._tmpVecs[2];
  751. boneAxis.x = 0;
  752. boneAxis.y = 1;
  753. boneAxis.z = 0;
  754. }
  755. bone.getDirectionToRef(boneAxis, boneMesh, boneDir);
  756. bone.getAbsolutePositionToRef(boneMesh, pos);
  757. if ((distToJoint === undefined || distToJoint === null) && jointPivot) {
  758. distToJoint = jointPivot.length();
  759. }
  760. if (distToJoint !== undefined && distToJoint !== null) {
  761. pos.x += boneDir.x * distToJoint;
  762. pos.y += boneDir.y * distToJoint;
  763. pos.z += boneDir.z * distToJoint;
  764. }
  765. mesh.setAbsolutePosition(pos);
  766. };
  767. PhysicsImpostor.DEFAULT_OBJECT_SIZE = new BABYLON.Vector3(1, 1, 1);
  768. PhysicsImpostor.IDENTITY_QUATERNION = BABYLON.Quaternion.Identity();
  769. PhysicsImpostor._tmpVecs = [BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero(), BABYLON.Vector3.Zero()];
  770. PhysicsImpostor._tmpQuat = BABYLON.Quaternion.Identity();
  771. //Impostor types
  772. PhysicsImpostor.NoImpostor = 0;
  773. PhysicsImpostor.SphereImpostor = 1;
  774. PhysicsImpostor.BoxImpostor = 2;
  775. PhysicsImpostor.PlaneImpostor = 3;
  776. PhysicsImpostor.MeshImpostor = 4;
  777. PhysicsImpostor.CylinderImpostor = 7;
  778. PhysicsImpostor.ParticleImpostor = 8;
  779. PhysicsImpostor.HeightmapImpostor = 9;
  780. return PhysicsImpostor;
  781. }());
  782. BABYLON.PhysicsImpostor = PhysicsImpostor;
  783. })(BABYLON || (BABYLON = {}));
  784. //# sourceMappingURL=babylon.physicsImpostor.js.map
  785. BABYLON.Effect.ShadersStore['defaultVertexShader'] = "#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif\n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}";
  786. BABYLON.Effect.ShadersStore['defaultPixelShader'] = "#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}";
  787. var BABYLON;
  788. (function (BABYLON) {
  789. var PhysicsEngine = /** @class */ (function () {
  790. function PhysicsEngine(gravity, _physicsPlugin) {
  791. if (_physicsPlugin === void 0) { _physicsPlugin = new BABYLON.CannonJSPlugin(); }
  792. this._physicsPlugin = _physicsPlugin;
  793. //new methods and parameters
  794. this._impostors = [];
  795. this._joints = [];
  796. if (!this._physicsPlugin.isSupported()) {
  797. throw new Error("Physics Engine " + this._physicsPlugin.name + " cannot be found. "
  798. + "Please make sure it is included.");
  799. }
  800. gravity = gravity || new BABYLON.Vector3(0, -9.807, 0);
  801. this.setGravity(gravity);
  802. this.setTimeStep();
  803. }
  804. PhysicsEngine.prototype.setGravity = function (gravity) {
  805. this.gravity = gravity;
  806. this._physicsPlugin.setGravity(this.gravity);
  807. };
  808. /**
  809. * Set the time step of the physics engine.
  810. * default is 1/60.
  811. * To slow it down, enter 1/600 for example.
  812. * To speed it up, 1/30
  813. * @param {number} newTimeStep the new timestep to apply to this world.
  814. */
  815. PhysicsEngine.prototype.setTimeStep = function (newTimeStep) {
  816. if (newTimeStep === void 0) { newTimeStep = 1 / 60; }
  817. this._physicsPlugin.setTimeStep(newTimeStep);
  818. };
  819. /**
  820. * Get the time step of the physics engine.
  821. */
  822. PhysicsEngine.prototype.getTimeStep = function () {
  823. return this._physicsPlugin.getTimeStep();
  824. };
  825. PhysicsEngine.prototype.dispose = function () {
  826. this._impostors.forEach(function (impostor) {
  827. impostor.dispose();
  828. });
  829. this._physicsPlugin.dispose();
  830. };
  831. PhysicsEngine.prototype.getPhysicsPluginName = function () {
  832. return this._physicsPlugin.name;
  833. };
  834. /**
  835. * Adding a new impostor for the impostor tracking.
  836. * This will be done by the impostor itself.
  837. * @param {PhysicsImpostor} impostor the impostor to add
  838. */
  839. PhysicsEngine.prototype.addImpostor = function (impostor) {
  840. impostor.uniqueId = this._impostors.push(impostor);
  841. //if no parent, generate the body
  842. if (!impostor.parent) {
  843. this._physicsPlugin.generatePhysicsBody(impostor);
  844. }
  845. };
  846. /**
  847. * Remove an impostor from the engine.
  848. * This impostor and its mesh will not longer be updated by the physics engine.
  849. * @param {PhysicsImpostor} impostor the impostor to remove
  850. */
  851. PhysicsEngine.prototype.removeImpostor = function (impostor) {
  852. var index = this._impostors.indexOf(impostor);
  853. if (index > -1) {
  854. var removed = this._impostors.splice(index, 1);
  855. //Is it needed?
  856. if (removed.length) {
  857. //this will also remove it from the world.
  858. removed[0].physicsBody = null;
  859. }
  860. }
  861. };
  862. /**
  863. * Add a joint to the physics engine
  864. * @param {PhysicsImpostor} mainImpostor the main impostor to which the joint is added.
  865. * @param {PhysicsImpostor} connectedImpostor the impostor that is connected to the main impostor using this joint
  866. * @param {PhysicsJoint} the joint that will connect both impostors.
  867. */
  868. PhysicsEngine.prototype.addJoint = function (mainImpostor, connectedImpostor, joint) {
  869. var impostorJoint = {
  870. mainImpostor: mainImpostor,
  871. connectedImpostor: connectedImpostor,
  872. joint: joint
  873. };
  874. joint.physicsPlugin = this._physicsPlugin;
  875. this._joints.push(impostorJoint);
  876. this._physicsPlugin.generateJoint(impostorJoint);
  877. };
  878. PhysicsEngine.prototype.removeJoint = function (mainImpostor, connectedImpostor, joint) {
  879. var matchingJoints = this._joints.filter(function (impostorJoint) {
  880. return (impostorJoint.connectedImpostor === connectedImpostor
  881. && impostorJoint.joint === joint
  882. && impostorJoint.mainImpostor === mainImpostor);
  883. });
  884. if (matchingJoints.length) {
  885. this._physicsPlugin.removeJoint(matchingJoints[0]);
  886. //TODO remove it from the list as well
  887. }
  888. };
  889. /**
  890. * Called by the scene. no need to call it.
  891. */
  892. PhysicsEngine.prototype._step = function (delta) {
  893. var _this = this;
  894. //check if any mesh has no body / requires an update
  895. this._impostors.forEach(function (impostor) {
  896. if (impostor.isBodyInitRequired()) {
  897. _this._physicsPlugin.generatePhysicsBody(impostor);
  898. }
  899. });
  900. if (delta > 0.1) {
  901. delta = 0.1;
  902. }
  903. else if (delta <= 0) {
  904. delta = 1.0 / 60.0;
  905. }
  906. this._physicsPlugin.executeStep(delta, this._impostors);
  907. };
  908. PhysicsEngine.prototype.getPhysicsPlugin = function () {
  909. return this._physicsPlugin;
  910. };
  911. PhysicsEngine.prototype.getImpostors = function () {
  912. return this._impostors;
  913. };
  914. PhysicsEngine.prototype.getImpostorForPhysicsObject = function (object) {
  915. for (var i = 0; i < this._impostors.length; ++i) {
  916. if (this._impostors[i].object === object) {
  917. return this._impostors[i];
  918. }
  919. }
  920. return null;
  921. };
  922. PhysicsEngine.prototype.getImpostorWithPhysicsBody = function (body) {
  923. for (var i = 0; i < this._impostors.length; ++i) {
  924. if (this._impostors[i].physicsBody === body) {
  925. return this._impostors[i];
  926. }
  927. }
  928. return null;
  929. };
  930. // Statics
  931. PhysicsEngine.Epsilon = 0.001;
  932. return PhysicsEngine;
  933. }());
  934. BABYLON.PhysicsEngine = PhysicsEngine;
  935. })(BABYLON || (BABYLON = {}));
  936. //# sourceMappingURL=babylon.physicsEngine.js.map
  937. var BABYLON;
  938. (function (BABYLON) {
  939. var PhysicsHelper = /** @class */ (function () {
  940. function PhysicsHelper(scene) {
  941. this._scene = scene;
  942. this._physicsEngine = this._scene.getPhysicsEngine();
  943. if (!this._physicsEngine) {
  944. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you can use the methods.');
  945. }
  946. }
  947. /**
  948. * @param {Vector3} origin the origin of the explosion
  949. * @param {number} radius the explosion radius
  950. * @param {number} strength the explosion strength
  951. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  952. */
  953. PhysicsHelper.prototype.applyRadialExplosionImpulse = function (origin, radius, strength, falloff) {
  954. if (falloff === void 0) { falloff = PhysicsRadialImpulseFalloff.Constant; }
  955. if (!this._physicsEngine) {
  956. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call this method.');
  957. return null;
  958. }
  959. var impostors = this._physicsEngine.getImpostors();
  960. if (impostors.length === 0) {
  961. return null;
  962. }
  963. var event = new PhysicsRadialExplosionEvent(this._scene);
  964. impostors.forEach(function (impostor) {
  965. var impostorForceAndContactPoint = event.getImpostorForceAndContactPoint(impostor, origin, radius, strength, falloff);
  966. if (!impostorForceAndContactPoint) {
  967. return;
  968. }
  969. impostor.applyImpulse(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
  970. });
  971. event.dispose(false);
  972. return event;
  973. };
  974. /**
  975. * @param {Vector3} origin the origin of the explosion
  976. * @param {number} radius the explosion radius
  977. * @param {number} strength the explosion strength
  978. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  979. */
  980. PhysicsHelper.prototype.applyRadialExplosionForce = function (origin, radius, strength, falloff) {
  981. if (falloff === void 0) { falloff = PhysicsRadialImpulseFalloff.Constant; }
  982. if (!this._physicsEngine) {
  983. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
  984. return null;
  985. }
  986. var impostors = this._physicsEngine.getImpostors();
  987. if (impostors.length === 0) {
  988. return null;
  989. }
  990. var event = new PhysicsRadialExplosionEvent(this._scene);
  991. impostors.forEach(function (impostor) {
  992. var impostorForceAndContactPoint = event.getImpostorForceAndContactPoint(impostor, origin, radius, strength, falloff);
  993. if (!impostorForceAndContactPoint) {
  994. return;
  995. }
  996. impostor.applyForce(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
  997. });
  998. event.dispose(false);
  999. return event;
  1000. };
  1001. /**
  1002. * @param {Vector3} origin the origin of the explosion
  1003. * @param {number} radius the explosion radius
  1004. * @param {number} strength the explosion strength
  1005. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
  1006. */
  1007. PhysicsHelper.prototype.gravitationalField = function (origin, radius, strength, falloff) {
  1008. if (falloff === void 0) { falloff = PhysicsRadialImpulseFalloff.Constant; }
  1009. if (!this._physicsEngine) {
  1010. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
  1011. return null;
  1012. }
  1013. var impostors = this._physicsEngine.getImpostors();
  1014. if (impostors.length === 0) {
  1015. return null;
  1016. }
  1017. var event = new PhysicsGravitationalFieldEvent(this, this._scene, origin, radius, strength, falloff);
  1018. event.dispose(false);
  1019. return event;
  1020. };
  1021. /**
  1022. * @param {Vector3} origin the origin of the updraft
  1023. * @param {number} radius the radius of the updraft
  1024. * @param {number} strength the strength of the updraft
  1025. * @param {number} height the height of the updraft
  1026. * @param {PhysicsUpdraftMode} updraftMode possible options: Center & Perpendicular. Defaults to Center
  1027. */
  1028. PhysicsHelper.prototype.updraft = function (origin, radius, strength, height, updraftMode) {
  1029. if (updraftMode === void 0) { updraftMode = PhysicsUpdraftMode.Center; }
  1030. if (!this._physicsEngine) {
  1031. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
  1032. return null;
  1033. }
  1034. if (this._physicsEngine.getImpostors().length === 0) {
  1035. return null;
  1036. }
  1037. var event = new PhysicsUpdraftEvent(this._scene, origin, radius, strength, height, updraftMode);
  1038. event.dispose(false);
  1039. return event;
  1040. };
  1041. /**
  1042. * @param {Vector3} origin the of the vortex
  1043. * @param {number} radius the radius of the vortex
  1044. * @param {number} strength the strength of the vortex
  1045. * @param {number} height the height of the vortex
  1046. */
  1047. PhysicsHelper.prototype.vortex = function (origin, radius, strength, height) {
  1048. if (!this._physicsEngine) {
  1049. BABYLON.Tools.Warn('Physics engine not enabled. Please enable the physics before you call the PhysicsHelper.');
  1050. return null;
  1051. }
  1052. if (this._physicsEngine.getImpostors().length === 0) {
  1053. return null;
  1054. }
  1055. var event = new PhysicsVortexEvent(this._scene, origin, radius, strength, height);
  1056. event.dispose(false);
  1057. return event;
  1058. };
  1059. return PhysicsHelper;
  1060. }());
  1061. BABYLON.PhysicsHelper = PhysicsHelper;
  1062. /***** Radial explosion *****/
  1063. var PhysicsRadialExplosionEvent = /** @class */ (function () {
  1064. function PhysicsRadialExplosionEvent(scene) {
  1065. this._sphereOptions = { segments: 32, diameter: 1 }; // TODO: make configurable
  1066. this._rays = [];
  1067. this._dataFetched = false; // check if the data has been fetched. If not, do cleanup
  1068. this._scene = scene;
  1069. }
  1070. /**
  1071. * Returns the data related to the radial explosion event (sphere & rays).
  1072. * @returns {PhysicsRadialExplosionEventData}
  1073. */
  1074. PhysicsRadialExplosionEvent.prototype.getData = function () {
  1075. this._dataFetched = true;
  1076. return {
  1077. sphere: this._sphere,
  1078. rays: this._rays,
  1079. };
  1080. };
  1081. /**
  1082. * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
  1083. * @param impostor
  1084. * @param {Vector3} origin the origin of the explosion
  1085. * @param {number} radius the explosion radius
  1086. * @param {number} strength the explosion strength
  1087. * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear
  1088. * @returns {Nullable<PhysicsForceAndContactPoint>}
  1089. */
  1090. PhysicsRadialExplosionEvent.prototype.getImpostorForceAndContactPoint = function (impostor, origin, radius, strength, falloff) {
  1091. if (impostor.mass === 0) {
  1092. return null;
  1093. }
  1094. if (!this._intersectsWithSphere(impostor, origin, radius)) {
  1095. return null;
  1096. }
  1097. if (impostor.object.getClassName() !== 'Mesh') {
  1098. return null;
  1099. }
  1100. var impostorObject = impostor.object;
  1101. var impostorObjectCenter = impostor.getObjectCenter();
  1102. var direction = impostorObjectCenter.subtract(origin);
  1103. var ray = new BABYLON.Ray(origin, direction, radius);
  1104. this._rays.push(ray);
  1105. var hit = ray.intersectsMesh(impostorObject);
  1106. var contactPoint = hit.pickedPoint;
  1107. if (!contactPoint) {
  1108. return null;
  1109. }
  1110. var distanceFromOrigin = BABYLON.Vector3.Distance(origin, contactPoint);
  1111. if (distanceFromOrigin > radius) {
  1112. return null;
  1113. }
  1114. var multiplier = falloff === PhysicsRadialImpulseFalloff.Constant
  1115. ? strength
  1116. : strength * (1 - (distanceFromOrigin / radius));
  1117. var force = direction.multiplyByFloats(multiplier, multiplier, multiplier);
  1118. return { force: force, contactPoint: contactPoint };
  1119. };
  1120. /**
  1121. * Disposes the sphere.
  1122. * @param {bolean} force
  1123. */
  1124. PhysicsRadialExplosionEvent.prototype.dispose = function (force) {
  1125. var _this = this;
  1126. if (force === void 0) { force = true; }
  1127. if (force) {
  1128. this._sphere.dispose();
  1129. }
  1130. else {
  1131. setTimeout(function () {
  1132. if (!_this._dataFetched) {
  1133. _this._sphere.dispose();
  1134. }
  1135. }, 0);
  1136. }
  1137. };
  1138. /*** Helpers ***/
  1139. PhysicsRadialExplosionEvent.prototype._prepareSphere = function () {
  1140. if (!this._sphere) {
  1141. this._sphere = BABYLON.MeshBuilder.CreateSphere("radialExplosionEventSphere", this._sphereOptions, this._scene);
  1142. this._sphere.isVisible = false;
  1143. }
  1144. };
  1145. PhysicsRadialExplosionEvent.prototype._intersectsWithSphere = function (impostor, origin, radius) {
  1146. var impostorObject = impostor.object;
  1147. this._prepareSphere();
  1148. this._sphere.position = origin;
  1149. this._sphere.scaling = new BABYLON.Vector3(radius * 2, radius * 2, radius * 2);
  1150. this._sphere._updateBoundingInfo();
  1151. this._sphere.computeWorldMatrix(true);
  1152. return this._sphere.intersectsMesh(impostorObject, true);
  1153. };
  1154. return PhysicsRadialExplosionEvent;
  1155. }());
  1156. BABYLON.PhysicsRadialExplosionEvent = PhysicsRadialExplosionEvent;
  1157. /***** Gravitational Field *****/
  1158. var PhysicsGravitationalFieldEvent = /** @class */ (function () {
  1159. function PhysicsGravitationalFieldEvent(physicsHelper, scene, origin, radius, strength, falloff) {
  1160. if (falloff === void 0) { falloff = PhysicsRadialImpulseFalloff.Constant; }
  1161. this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
  1162. this._physicsHelper = physicsHelper;
  1163. this._scene = scene;
  1164. this._origin = origin;
  1165. this._radius = radius;
  1166. this._strength = strength;
  1167. this._falloff = falloff;
  1168. this._tickCallback = this._tick.bind(this);
  1169. }
  1170. /**
  1171. * Returns the data related to the gravitational field event (sphere).
  1172. * @returns {PhysicsGravitationalFieldEventData}
  1173. */
  1174. PhysicsGravitationalFieldEvent.prototype.getData = function () {
  1175. this._dataFetched = true;
  1176. return {
  1177. sphere: this._sphere,
  1178. };
  1179. };
  1180. /**
  1181. * Enables the gravitational field.
  1182. */
  1183. PhysicsGravitationalFieldEvent.prototype.enable = function () {
  1184. this._tickCallback.call(this);
  1185. this._scene.registerBeforeRender(this._tickCallback);
  1186. };
  1187. /**
  1188. * Disables the gravitational field.
  1189. */
  1190. PhysicsGravitationalFieldEvent.prototype.disable = function () {
  1191. this._scene.unregisterBeforeRender(this._tickCallback);
  1192. };
  1193. /**
  1194. * Disposes the sphere.
  1195. * @param {bolean} force
  1196. */
  1197. PhysicsGravitationalFieldEvent.prototype.dispose = function (force) {
  1198. var _this = this;
  1199. if (force === void 0) { force = true; }
  1200. if (force) {
  1201. this._sphere.dispose();
  1202. }
  1203. else {
  1204. setTimeout(function () {
  1205. if (!_this._dataFetched) {
  1206. _this._sphere.dispose();
  1207. }
  1208. }, 0);
  1209. }
  1210. };
  1211. PhysicsGravitationalFieldEvent.prototype._tick = function () {
  1212. // Since the params won't change, we fetch the event only once
  1213. if (this._sphere) {
  1214. this._physicsHelper.applyRadialExplosionForce(this._origin, this._radius, this._strength * -1, this._falloff);
  1215. }
  1216. else {
  1217. var radialExplosionEvent = this._physicsHelper.applyRadialExplosionForce(this._origin, this._radius, this._strength * -1, this._falloff);
  1218. if (radialExplosionEvent) {
  1219. this._sphere = radialExplosionEvent.getData().sphere.clone('radialExplosionEventSphereClone');
  1220. }
  1221. }
  1222. };
  1223. return PhysicsGravitationalFieldEvent;
  1224. }());
  1225. BABYLON.PhysicsGravitationalFieldEvent = PhysicsGravitationalFieldEvent;
  1226. /***** Updraft *****/
  1227. var PhysicsUpdraftEvent = /** @class */ (function () {
  1228. function PhysicsUpdraftEvent(_scene, _origin, _radius, _strength, _height, _updraftMode) {
  1229. this._scene = _scene;
  1230. this._origin = _origin;
  1231. this._radius = _radius;
  1232. this._strength = _strength;
  1233. this._height = _height;
  1234. this._updraftMode = _updraftMode;
  1235. this._originTop = BABYLON.Vector3.Zero(); // the most upper part of the cylinder
  1236. this._originDirection = BABYLON.Vector3.Zero(); // used if the updraftMode is perpendicular
  1237. this._cylinderPosition = BABYLON.Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
  1238. this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
  1239. this._physicsEngine = this._scene.getPhysicsEngine();
  1240. this._origin.addToRef(new BABYLON.Vector3(0, this._height / 2, 0), this._cylinderPosition);
  1241. this._origin.addToRef(new BABYLON.Vector3(0, this._height, 0), this._originTop);
  1242. if (this._updraftMode === PhysicsUpdraftMode.Perpendicular) {
  1243. this._originDirection = this._origin.subtract(this._originTop).normalize();
  1244. }
  1245. this._tickCallback = this._tick.bind(this);
  1246. }
  1247. /**
  1248. * Returns the data related to the updraft event (cylinder).
  1249. * @returns {PhysicsUpdraftEventData}
  1250. */
  1251. PhysicsUpdraftEvent.prototype.getData = function () {
  1252. this._dataFetched = true;
  1253. return {
  1254. cylinder: this._cylinder,
  1255. };
  1256. };
  1257. /**
  1258. * Enables the updraft.
  1259. */
  1260. PhysicsUpdraftEvent.prototype.enable = function () {
  1261. this._tickCallback.call(this);
  1262. this._scene.registerBeforeRender(this._tickCallback);
  1263. };
  1264. /**
  1265. * Disables the cortex.
  1266. */
  1267. PhysicsUpdraftEvent.prototype.disable = function () {
  1268. this._scene.unregisterBeforeRender(this._tickCallback);
  1269. };
  1270. /**
  1271. * Disposes the sphere.
  1272. * @param {bolean} force
  1273. */
  1274. PhysicsUpdraftEvent.prototype.dispose = function (force) {
  1275. var _this = this;
  1276. if (force === void 0) { force = true; }
  1277. if (force) {
  1278. this._cylinder.dispose();
  1279. }
  1280. else {
  1281. setTimeout(function () {
  1282. if (!_this._dataFetched) {
  1283. _this._cylinder.dispose();
  1284. }
  1285. }, 0);
  1286. }
  1287. };
  1288. PhysicsUpdraftEvent.prototype.getImpostorForceAndContactPoint = function (impostor) {
  1289. if (impostor.mass === 0) {
  1290. return null;
  1291. }
  1292. if (!this._intersectsWithCylinder(impostor)) {
  1293. return null;
  1294. }
  1295. var impostorObjectCenter = impostor.getObjectCenter();
  1296. if (this._updraftMode === PhysicsUpdraftMode.Perpendicular) {
  1297. var direction = this._originDirection;
  1298. }
  1299. else {
  1300. var direction = impostorObjectCenter.subtract(this._originTop);
  1301. }
  1302. var multiplier = this._strength * -1;
  1303. var force = direction.multiplyByFloats(multiplier, multiplier, multiplier);
  1304. return { force: force, contactPoint: impostorObjectCenter };
  1305. };
  1306. PhysicsUpdraftEvent.prototype._tick = function () {
  1307. var _this = this;
  1308. this._physicsEngine.getImpostors().forEach(function (impostor) {
  1309. var impostorForceAndContactPoint = _this.getImpostorForceAndContactPoint(impostor);
  1310. if (!impostorForceAndContactPoint) {
  1311. return;
  1312. }
  1313. impostor.applyForce(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
  1314. });
  1315. };
  1316. /*** Helpers ***/
  1317. PhysicsUpdraftEvent.prototype._prepareCylinder = function () {
  1318. if (!this._cylinder) {
  1319. this._cylinder = BABYLON.MeshBuilder.CreateCylinder("updraftEventCylinder", {
  1320. height: this._height,
  1321. diameter: this._radius * 2,
  1322. }, this._scene);
  1323. this._cylinder.isVisible = false;
  1324. }
  1325. };
  1326. PhysicsUpdraftEvent.prototype._intersectsWithCylinder = function (impostor) {
  1327. var impostorObject = impostor.object;
  1328. this._prepareCylinder();
  1329. this._cylinder.position = this._cylinderPosition;
  1330. return this._cylinder.intersectsMesh(impostorObject, true);
  1331. };
  1332. return PhysicsUpdraftEvent;
  1333. }());
  1334. BABYLON.PhysicsUpdraftEvent = PhysicsUpdraftEvent;
  1335. /***** Vortex *****/
  1336. var PhysicsVortexEvent = /** @class */ (function () {
  1337. function PhysicsVortexEvent(_scene, _origin, _radius, _strength, _height) {
  1338. this._scene = _scene;
  1339. this._origin = _origin;
  1340. this._radius = _radius;
  1341. this._strength = _strength;
  1342. this._height = _height;
  1343. this._originTop = BABYLON.Vector3.Zero(); // the most upper part of the cylinder
  1344. this._centripetalForceThreshold = 0.7; // at which distance, relative to the radius the centripetal forces should kick in
  1345. this._updraftMultiplier = 0.02;
  1346. this._cylinderPosition = BABYLON.Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
  1347. this._dataFetched = false; // check if the has been fetched the data. If not, do cleanup
  1348. this._physicsEngine = this._scene.getPhysicsEngine();
  1349. this._origin.addToRef(new BABYLON.Vector3(0, this._height / 2, 0), this._cylinderPosition);
  1350. this._origin.addToRef(new BABYLON.Vector3(0, this._height, 0), this._originTop);
  1351. this._tickCallback = this._tick.bind(this);
  1352. }
  1353. /**
  1354. * Returns the data related to the vortex event (cylinder).
  1355. * @returns {PhysicsVortexEventData}
  1356. */
  1357. PhysicsVortexEvent.prototype.getData = function () {
  1358. this._dataFetched = true;
  1359. return {
  1360. cylinder: this._cylinder,
  1361. };
  1362. };
  1363. /**
  1364. * Enables the vortex.
  1365. */
  1366. PhysicsVortexEvent.prototype.enable = function () {
  1367. this._tickCallback.call(this);
  1368. this._scene.registerBeforeRender(this._tickCallback);
  1369. };
  1370. /**
  1371. * Disables the cortex.
  1372. */
  1373. PhysicsVortexEvent.prototype.disable = function () {
  1374. this._scene.unregisterBeforeRender(this._tickCallback);
  1375. };
  1376. /**
  1377. * Disposes the sphere.
  1378. * @param {bolean} force
  1379. */
  1380. PhysicsVortexEvent.prototype.dispose = function (force) {
  1381. var _this = this;
  1382. if (force === void 0) { force = true; }
  1383. if (force) {
  1384. this._cylinder.dispose();
  1385. }
  1386. else {
  1387. setTimeout(function () {
  1388. if (!_this._dataFetched) {
  1389. _this._cylinder.dispose();
  1390. }
  1391. }, 0);
  1392. }
  1393. };
  1394. PhysicsVortexEvent.prototype.getImpostorForceAndContactPoint = function (impostor) {
  1395. if (impostor.mass === 0) {
  1396. return null;
  1397. }
  1398. if (!this._intersectsWithCylinder(impostor)) {
  1399. return null;
  1400. }
  1401. if (impostor.object.getClassName() !== 'Mesh') {
  1402. return null;
  1403. }
  1404. var impostorObject = impostor.object;
  1405. var impostorObjectCenter = impostor.getObjectCenter();
  1406. var originOnPlane = new BABYLON.Vector3(this._origin.x, impostorObjectCenter.y, this._origin.z); // the distance to the origin as if both objects were on a plane (Y-axis)
  1407. var originToImpostorDirection = impostorObjectCenter.subtract(originOnPlane);
  1408. var ray = new BABYLON.Ray(originOnPlane, originToImpostorDirection, this._radius);
  1409. var hit = ray.intersectsMesh(impostorObject);
  1410. var contactPoint = hit.pickedPoint;
  1411. if (!contactPoint) {
  1412. return null;
  1413. }
  1414. var absoluteDistanceFromOrigin = hit.distance / this._radius;
  1415. var perpendicularDirection = BABYLON.Vector3.Cross(originOnPlane, impostorObjectCenter).normalize();
  1416. var directionToOrigin = contactPoint.normalize();
  1417. if (absoluteDistanceFromOrigin > this._centripetalForceThreshold) {
  1418. directionToOrigin = directionToOrigin.negate();
  1419. }
  1420. // TODO: find a more physically based solution
  1421. if (absoluteDistanceFromOrigin > this._centripetalForceThreshold) {
  1422. var forceX = directionToOrigin.x * this._strength / 8;
  1423. var forceY = directionToOrigin.y * this._updraftMultiplier;
  1424. var forceZ = directionToOrigin.z * this._strength / 8;
  1425. }
  1426. else {
  1427. var forceX = (perpendicularDirection.x + directionToOrigin.x) / 2;
  1428. var forceY = this._originTop.y * this._updraftMultiplier;
  1429. var forceZ = (perpendicularDirection.z + directionToOrigin.z) / 2;
  1430. }
  1431. var force = new BABYLON.Vector3(forceX, forceY, forceZ);
  1432. force = force.multiplyByFloats(this._strength, this._strength, this._strength);
  1433. return { force: force, contactPoint: impostorObjectCenter };
  1434. };
  1435. PhysicsVortexEvent.prototype._tick = function () {
  1436. var _this = this;
  1437. this._physicsEngine.getImpostors().forEach(function (impostor) {
  1438. var impostorForceAndContactPoint = _this.getImpostorForceAndContactPoint(impostor);
  1439. if (!impostorForceAndContactPoint) {
  1440. return;
  1441. }
  1442. impostor.applyForce(impostorForceAndContactPoint.force, impostorForceAndContactPoint.contactPoint);
  1443. });
  1444. };
  1445. /*** Helpers ***/
  1446. PhysicsVortexEvent.prototype._prepareCylinder = function () {
  1447. if (!this._cylinder) {
  1448. this._cylinder = BABYLON.MeshBuilder.CreateCylinder("vortexEventCylinder", {
  1449. height: this._height,
  1450. diameter: this._radius * 2,
  1451. }, this._scene);
  1452. this._cylinder.isVisible = false;
  1453. }
  1454. };
  1455. PhysicsVortexEvent.prototype._intersectsWithCylinder = function (impostor) {
  1456. var impostorObject = impostor.object;
  1457. this._prepareCylinder();
  1458. this._cylinder.position = this._cylinderPosition;
  1459. return this._cylinder.intersectsMesh(impostorObject, true);
  1460. };
  1461. return PhysicsVortexEvent;
  1462. }());
  1463. BABYLON.PhysicsVortexEvent = PhysicsVortexEvent;
  1464. /***** Enums *****/
  1465. /**
  1466. * The strenght of the force in correspondence to the distance of the affected object
  1467. */
  1468. var PhysicsRadialImpulseFalloff;
  1469. (function (PhysicsRadialImpulseFalloff) {
  1470. PhysicsRadialImpulseFalloff[PhysicsRadialImpulseFalloff["Constant"] = 0] = "Constant";
  1471. PhysicsRadialImpulseFalloff[PhysicsRadialImpulseFalloff["Linear"] = 1] = "Linear"; // impulse gets weaker if it's further from the origin
  1472. })(PhysicsRadialImpulseFalloff = BABYLON.PhysicsRadialImpulseFalloff || (BABYLON.PhysicsRadialImpulseFalloff = {}));
  1473. /**
  1474. * The strenght of the force in correspondence to the distance of the affected object
  1475. */
  1476. var PhysicsUpdraftMode;
  1477. (function (PhysicsUpdraftMode) {
  1478. PhysicsUpdraftMode[PhysicsUpdraftMode["Center"] = 0] = "Center";
  1479. PhysicsUpdraftMode[PhysicsUpdraftMode["Perpendicular"] = 1] = "Perpendicular"; // once a impostor is inside the cylinder, it will shoot out perpendicular from the ground of the cylinder
  1480. })(PhysicsUpdraftMode = BABYLON.PhysicsUpdraftMode || (BABYLON.PhysicsUpdraftMode = {}));
  1481. })(BABYLON || (BABYLON = {}));
  1482. //# sourceMappingURL=babylon.physicsHelper.js.map
  1483. var BABYLON;
  1484. (function (BABYLON) {
  1485. var CannonJSPlugin = /** @class */ (function () {
  1486. function CannonJSPlugin(_useDeltaForWorldStep, iterations) {
  1487. if (_useDeltaForWorldStep === void 0) { _useDeltaForWorldStep = true; }
  1488. if (iterations === void 0) { iterations = 10; }
  1489. this._useDeltaForWorldStep = _useDeltaForWorldStep;
  1490. this.name = "CannonJSPlugin";
  1491. this._physicsMaterials = new Array();
  1492. this._fixedTimeStep = 1 / 60;
  1493. //See https://github.com/schteppe/CANNON.js/blob/gh-pages/demos/collisionFilter.html
  1494. this.BJSCANNON = typeof CANNON !== 'undefined' ? CANNON : (typeof require !== 'undefined' ? require('cannon') : undefined);
  1495. this._minus90X = new BABYLON.Quaternion(-0.7071067811865475, 0, 0, 0.7071067811865475);
  1496. this._plus90X = new BABYLON.Quaternion(0.7071067811865475, 0, 0, 0.7071067811865475);
  1497. this._tmpPosition = BABYLON.Vector3.Zero();
  1498. this._tmpDeltaPosition = BABYLON.Vector3.Zero();
  1499. this._tmpUnityRotation = new BABYLON.Quaternion();
  1500. if (!this.isSupported()) {
  1501. BABYLON.Tools.Error("CannonJS is not available. Please make sure you included the js file.");
  1502. return;
  1503. }
  1504. this._extendNamespace();
  1505. this.world = new this.BJSCANNON.World();
  1506. this.world.broadphase = new this.BJSCANNON.NaiveBroadphase();
  1507. this.world.solver.iterations = iterations;
  1508. }
  1509. CannonJSPlugin.prototype.setGravity = function (gravity) {
  1510. this.world.gravity.copy(gravity);
  1511. };
  1512. CannonJSPlugin.prototype.setTimeStep = function (timeStep) {
  1513. this._fixedTimeStep = timeStep;
  1514. };
  1515. CannonJSPlugin.prototype.getTimeStep = function () {
  1516. return this._fixedTimeStep;
  1517. };
  1518. CannonJSPlugin.prototype.executeStep = function (delta, impostors) {
  1519. this.world.step(this._fixedTimeStep, this._useDeltaForWorldStep ? delta : 0, 3);
  1520. };
  1521. CannonJSPlugin.prototype.applyImpulse = function (impostor, force, contactPoint) {
  1522. var worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
  1523. var impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
  1524. impostor.physicsBody.applyImpulse(impulse, worldPoint);
  1525. };
  1526. CannonJSPlugin.prototype.applyForce = function (impostor, force, contactPoint) {
  1527. var worldPoint = new this.BJSCANNON.Vec3(contactPoint.x, contactPoint.y, contactPoint.z);
  1528. var impulse = new this.BJSCANNON.Vec3(force.x, force.y, force.z);
  1529. impostor.physicsBody.applyForce(impulse, worldPoint);
  1530. };
  1531. CannonJSPlugin.prototype.generatePhysicsBody = function (impostor) {
  1532. //parent-child relationship. Does this impostor has a parent impostor?
  1533. if (impostor.parent) {
  1534. if (impostor.physicsBody) {
  1535. this.removePhysicsBody(impostor);
  1536. //TODO is that needed?
  1537. impostor.forceUpdate();
  1538. }
  1539. return;
  1540. }
  1541. //should a new body be created for this impostor?
  1542. if (impostor.isBodyInitRequired()) {
  1543. var shape = this._createShape(impostor);
  1544. //unregister events, if body is being changed
  1545. var oldBody = impostor.physicsBody;
  1546. if (oldBody) {
  1547. this.removePhysicsBody(impostor);
  1548. }
  1549. //create the body and material
  1550. var material = this._addMaterial("mat-" + impostor.uniqueId, impostor.getParam("friction"), impostor.getParam("restitution"));
  1551. var bodyCreationObject = {
  1552. mass: impostor.getParam("mass"),
  1553. material: material
  1554. };
  1555. // A simple extend, in case native options were used.
  1556. var nativeOptions = impostor.getParam("nativeOptions");
  1557. for (var key in nativeOptions) {
  1558. if (nativeOptions.hasOwnProperty(key)) {
  1559. bodyCreationObject[key] = nativeOptions[key];
  1560. }
  1561. }
  1562. impostor.physicsBody = new this.BJSCANNON.Body(bodyCreationObject);
  1563. impostor.physicsBody.addEventListener("collide", impostor.onCollide);
  1564. this.world.addEventListener("preStep", impostor.beforeStep);
  1565. this.world.addEventListener("postStep", impostor.afterStep);
  1566. impostor.physicsBody.addShape(shape);
  1567. this.world.add(impostor.physicsBody);
  1568. //try to keep the body moving in the right direction by taking old properties.
  1569. //Should be tested!
  1570. if (oldBody) {
  1571. ['force', 'torque', 'velocity', 'angularVelocity'].forEach(function (param) {
  1572. impostor.physicsBody[param].copy(oldBody[param]);
  1573. });
  1574. }
  1575. this._processChildMeshes(impostor);
  1576. }
  1577. //now update the body's transformation
  1578. this._updatePhysicsBodyTransformation(impostor);
  1579. };
  1580. CannonJSPlugin.prototype._processChildMeshes = function (mainImpostor) {
  1581. var _this = this;
  1582. var meshChildren = mainImpostor.object.getChildMeshes ? mainImpostor.object.getChildMeshes(true) : [];
  1583. var currentRotation = mainImpostor.object.rotationQuaternion;
  1584. if (meshChildren.length) {
  1585. var processMesh = function (localPosition, mesh) {
  1586. if (!currentRotation || !mesh.rotationQuaternion) {
  1587. return;
  1588. }
  1589. var childImpostor = mesh.getPhysicsImpostor();
  1590. if (childImpostor) {
  1591. var parent = childImpostor.parent;
  1592. if (parent !== mainImpostor) {
  1593. var pPosition = mesh.getAbsolutePosition().subtract(mainImpostor.object.getAbsolutePosition());
  1594. var localRotation = mesh.rotationQuaternion.multiply(BABYLON.Quaternion.Inverse(currentRotation));
  1595. if (childImpostor.physicsBody) {
  1596. _this.removePhysicsBody(childImpostor);
  1597. childImpostor.physicsBody = null;
  1598. }
  1599. childImpostor.parent = mainImpostor;
  1600. childImpostor.resetUpdateFlags();
  1601. mainImpostor.physicsBody.addShape(_this._createShape(childImpostor), new _this.BJSCANNON.Vec3(pPosition.x, pPosition.y, pPosition.z), new _this.BJSCANNON.Quaternion(localRotation.x, localRotation.y, localRotation.z, localRotation.w));
  1602. //Add the mass of the children.
  1603. mainImpostor.physicsBody.mass += childImpostor.getParam("mass");
  1604. }
  1605. }
  1606. currentRotation.multiplyInPlace(mesh.rotationQuaternion);
  1607. mesh.getChildMeshes(true).filter(function (m) { return !!m.physicsImpostor; }).forEach(processMesh.bind(_this, mesh.getAbsolutePosition()));
  1608. };
  1609. meshChildren.filter(function (m) { return !!m.physicsImpostor; }).forEach(processMesh.bind(this, mainImpostor.object.getAbsolutePosition()));
  1610. }
  1611. };
  1612. CannonJSPlugin.prototype.removePhysicsBody = function (impostor) {
  1613. impostor.physicsBody.removeEventListener("collide", impostor.onCollide);
  1614. this.world.removeEventListener("preStep", impostor.beforeStep);
  1615. this.world.removeEventListener("postStep", impostor.afterStep);
  1616. this.world.remove(impostor.physicsBody);
  1617. };
  1618. CannonJSPlugin.prototype.generateJoint = function (impostorJoint) {
  1619. var mainBody = impostorJoint.mainImpostor.physicsBody;
  1620. var connectedBody = impostorJoint.connectedImpostor.physicsBody;
  1621. if (!mainBody || !connectedBody) {
  1622. return;
  1623. }
  1624. var constraint;
  1625. var jointData = impostorJoint.joint.jointData;
  1626. //TODO - https://github.com/schteppe/this.BJSCANNON.js/blob/gh-pages/demos/collisionFilter.html
  1627. var constraintData = {
  1628. pivotA: jointData.mainPivot ? new this.BJSCANNON.Vec3().copy(jointData.mainPivot) : null,
  1629. pivotB: jointData.connectedPivot ? new this.BJSCANNON.Vec3().copy(jointData.connectedPivot) : null,
  1630. axisA: jointData.mainAxis ? new this.BJSCANNON.Vec3().copy(jointData.mainAxis) : null,
  1631. axisB: jointData.connectedAxis ? new this.BJSCANNON.Vec3().copy(jointData.connectedAxis) : null,
  1632. maxForce: jointData.nativeParams.maxForce,
  1633. collideConnected: !!jointData.collision
  1634. };
  1635. switch (impostorJoint.joint.type) {
  1636. case BABYLON.PhysicsJoint.HingeJoint:
  1637. case BABYLON.PhysicsJoint.Hinge2Joint:
  1638. constraint = new this.BJSCANNON.HingeConstraint(mainBody, connectedBody, constraintData);
  1639. break;
  1640. case BABYLON.PhysicsJoint.DistanceJoint:
  1641. constraint = new this.BJSCANNON.DistanceConstraint(mainBody, connectedBody, jointData.maxDistance || 2);
  1642. break;
  1643. case BABYLON.PhysicsJoint.SpringJoint:
  1644. var springData = jointData;
  1645. constraint = new this.BJSCANNON.Spring(mainBody, connectedBody, {
  1646. restLength: springData.length,
  1647. stiffness: springData.stiffness,
  1648. damping: springData.damping,
  1649. localAnchorA: constraintData.pivotA,
  1650. localAnchorB: constraintData.pivotB
  1651. });
  1652. break;
  1653. case BABYLON.PhysicsJoint.LockJoint:
  1654. constraint = new this.BJSCANNON.LockConstraint(mainBody, connectedBody, constraintData);
  1655. break;
  1656. case BABYLON.PhysicsJoint.PointToPointJoint:
  1657. case BABYLON.PhysicsJoint.BallAndSocketJoint:
  1658. default:
  1659. constraint = new this.BJSCANNON.PointToPointConstraint(mainBody, constraintData.pivotA, connectedBody, constraintData.pivotA, constraintData.maxForce);
  1660. break;
  1661. }
  1662. //set the collideConnected flag after the creation, since DistanceJoint ignores it.
  1663. constraint.collideConnected = !!jointData.collision;
  1664. impostorJoint.joint.physicsJoint = constraint;
  1665. //don't add spring as constraint, as it is not one.
  1666. if (impostorJoint.joint.type !== BABYLON.PhysicsJoint.SpringJoint) {
  1667. this.world.addConstraint(constraint);
  1668. }
  1669. else {
  1670. impostorJoint.mainImpostor.registerAfterPhysicsStep(function () {
  1671. constraint.applyForce();
  1672. });
  1673. }
  1674. };
  1675. CannonJSPlugin.prototype.removeJoint = function (impostorJoint) {
  1676. this.world.removeConstraint(impostorJoint.joint.physicsJoint);
  1677. };
  1678. CannonJSPlugin.prototype._addMaterial = function (name, friction, restitution) {
  1679. var index;
  1680. var mat;
  1681. for (index = 0; index < this._physicsMaterials.length; index++) {
  1682. mat = this._physicsMaterials[index];
  1683. if (mat.friction === friction && mat.restitution === restitution) {
  1684. return mat;
  1685. }
  1686. }
  1687. var currentMat = new this.BJSCANNON.Material(name);
  1688. currentMat.friction = friction;
  1689. currentMat.restitution = restitution;
  1690. this._physicsMaterials.push(currentMat);
  1691. return currentMat;
  1692. };
  1693. CannonJSPlugin.prototype._checkWithEpsilon = function (value) {
  1694. return value < BABYLON.PhysicsEngine.Epsilon ? BABYLON.PhysicsEngine.Epsilon : value;
  1695. };
  1696. CannonJSPlugin.prototype._createShape = function (impostor) {
  1697. var object = impostor.object;
  1698. var returnValue;
  1699. var extendSize = impostor.getObjectExtendSize();
  1700. switch (impostor.type) {
  1701. case BABYLON.PhysicsImpostor.SphereImpostor:
  1702. var radiusX = extendSize.x;
  1703. var radiusY = extendSize.y;
  1704. var radiusZ = extendSize.z;
  1705. returnValue = new this.BJSCANNON.Sphere(Math.max(this._checkWithEpsilon(radiusX), this._checkWithEpsilon(radiusY), this._checkWithEpsilon(radiusZ)) / 2);
  1706. break;
  1707. //TMP also for cylinder - TODO Cannon supports cylinder natively.
  1708. case BABYLON.PhysicsImpostor.CylinderImpostor:
  1709. returnValue = new this.BJSCANNON.Cylinder(this._checkWithEpsilon(extendSize.x) / 2, this._checkWithEpsilon(extendSize.x) / 2, this._checkWithEpsilon(extendSize.y), 16);
  1710. break;
  1711. case BABYLON.PhysicsImpostor.BoxImpostor:
  1712. var box = extendSize.scale(0.5);
  1713. returnValue = new this.BJSCANNON.Box(new this.BJSCANNON.Vec3(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z)));
  1714. break;
  1715. case BABYLON.PhysicsImpostor.PlaneImpostor:
  1716. BABYLON.Tools.Warn("Attention, PlaneImposter might not behave as you expect. Consider using BoxImposter instead");
  1717. returnValue = new this.BJSCANNON.Plane();
  1718. break;
  1719. case BABYLON.PhysicsImpostor.MeshImpostor:
  1720. // should transform the vertex data to world coordinates!!
  1721. var rawVerts = object.getVerticesData ? object.getVerticesData(BABYLON.VertexBuffer.PositionKind) : [];
  1722. var rawFaces = object.getIndices ? object.getIndices() : [];
  1723. if (!rawVerts)
  1724. return;
  1725. // get only scale! so the object could transform correctly.
  1726. var oldPosition = object.position.clone();
  1727. var oldRotation = object.rotation && object.rotation.clone();
  1728. var oldQuaternion = object.rotationQuaternion && object.rotationQuaternion.clone();
  1729. object.position.copyFromFloats(0, 0, 0);
  1730. object.rotation && object.rotation.copyFromFloats(0, 0, 0);
  1731. object.rotationQuaternion && object.rotationQuaternion.copyFrom(impostor.getParentsRotation());
  1732. object.rotationQuaternion && object.parent && object.rotationQuaternion.conjugateInPlace();
  1733. var transform = object.computeWorldMatrix(true);
  1734. // convert rawVerts to object space
  1735. var temp = new Array();
  1736. var index;
  1737. for (index = 0; index < rawVerts.length; index += 3) {
  1738. BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(rawVerts, index), transform).toArray(temp, index);
  1739. }
  1740. BABYLON.Tools.Warn("MeshImpostor only collides against spheres.");
  1741. returnValue = new this.BJSCANNON.Trimesh(temp, rawFaces);
  1742. //now set back the transformation!
  1743. object.position.copyFrom(oldPosition);
  1744. oldRotation && object.rotation && object.rotation.copyFrom(oldRotation);
  1745. oldQuaternion && object.rotationQuaternion && object.rotationQuaternion.copyFrom(oldQuaternion);
  1746. break;
  1747. case BABYLON.PhysicsImpostor.HeightmapImpostor:
  1748. var oldPosition2 = object.position.clone();
  1749. var oldRotation2 = object.rotation && object.rotation.clone();
  1750. var oldQuaternion2 = object.rotationQuaternion && object.rotationQuaternion.clone();
  1751. object.position.copyFromFloats(0, 0, 0);
  1752. object.rotation && object.rotation.copyFromFloats(0, 0, 0);
  1753. object.rotationQuaternion && object.rotationQuaternion.copyFrom(impostor.getParentsRotation());
  1754. object.rotationQuaternion && object.parent && object.rotationQuaternion.conjugateInPlace();
  1755. object.rotationQuaternion && object.rotationQuaternion.multiplyInPlace(this._minus90X);
  1756. returnValue = this._createHeightmap(object);
  1757. object.position.copyFrom(oldPosition2);
  1758. oldRotation2 && object.rotation && object.rotation.copyFrom(oldRotation2);
  1759. oldQuaternion2 && object.rotationQuaternion && object.rotationQuaternion.copyFrom(oldQuaternion2);
  1760. object.computeWorldMatrix(true);
  1761. break;
  1762. case BABYLON.PhysicsImpostor.ParticleImpostor:
  1763. returnValue = new this.BJSCANNON.Particle();
  1764. break;
  1765. }
  1766. return returnValue;
  1767. };
  1768. CannonJSPlugin.prototype._createHeightmap = function (object, pointDepth) {
  1769. var pos = (object.getVerticesData(BABYLON.VertexBuffer.PositionKind));
  1770. var transform = object.computeWorldMatrix(true);
  1771. // convert rawVerts to object space
  1772. var temp = new Array();
  1773. var index;
  1774. for (index = 0; index < pos.length; index += 3) {
  1775. BABYLON.Vector3.TransformCoordinates(BABYLON.Vector3.FromArray(pos, index), transform).toArray(temp, index);
  1776. }
  1777. pos = temp;
  1778. var matrix = new Array();
  1779. //For now pointDepth will not be used and will be automatically calculated.
  1780. //Future reference - try and find the best place to add a reference to the pointDepth variable.
  1781. var arraySize = pointDepth || ~~(Math.sqrt(pos.length / 3) - 1);
  1782. var boundingInfo = object.getBoundingInfo();
  1783. var dim = Math.min(boundingInfo.boundingBox.extendSizeWorld.x, boundingInfo.boundingBox.extendSizeWorld.y);
  1784. var minY = boundingInfo.boundingBox.extendSizeWorld.z;
  1785. var elementSize = dim * 2 / arraySize;
  1786. for (var i = 0; i < pos.length; i = i + 3) {
  1787. var x = Math.round((pos[i + 0]) / elementSize + arraySize / 2);
  1788. var z = Math.round(((pos[i + 1]) / elementSize - arraySize / 2) * -1);
  1789. var y = -pos[i + 2] + minY;
  1790. if (!matrix[x]) {
  1791. matrix[x] = [];
  1792. }
  1793. if (!matrix[x][z]) {
  1794. matrix[x][z] = y;
  1795. }
  1796. matrix[x][z] = Math.max(y, matrix[x][z]);
  1797. }
  1798. for (var x = 0; x <= arraySize; ++x) {
  1799. if (!matrix[x]) {
  1800. var loc = 1;
  1801. while (!matrix[(x + loc) % arraySize]) {
  1802. loc++;
  1803. }
  1804. matrix[x] = matrix[(x + loc) % arraySize].slice();
  1805. //console.log("missing x", x);
  1806. }
  1807. for (var z = 0; z <= arraySize; ++z) {
  1808. if (!matrix[x][z]) {
  1809. var loc = 1;
  1810. var newValue;
  1811. while (newValue === undefined) {
  1812. newValue = matrix[x][(z + loc++) % arraySize];
  1813. }
  1814. matrix[x][z] = newValue;
  1815. }
  1816. }
  1817. }
  1818. var shape = new this.BJSCANNON.Heightfield(matrix, {
  1819. elementSize: elementSize
  1820. });
  1821. //For future reference, needed for body transformation
  1822. shape.minY = minY;
  1823. return shape;
  1824. };
  1825. CannonJSPlugin.prototype._updatePhysicsBodyTransformation = function (impostor) {
  1826. var object = impostor.object;
  1827. //make sure it is updated...
  1828. object.computeWorldMatrix && object.computeWorldMatrix(true);
  1829. // The delta between the mesh position and the mesh bounding box center
  1830. var bInfo = object.getBoundingInfo();
  1831. if (!bInfo)
  1832. return;
  1833. var center = impostor.getObjectCenter();
  1834. //m.getAbsolutePosition().subtract(m.getBoundingInfo().boundingBox.centerWorld)
  1835. this._tmpDeltaPosition.copyFrom(object.getAbsolutePivotPoint().subtract(center));
  1836. this._tmpDeltaPosition.divideInPlace(impostor.object.scaling);
  1837. this._tmpPosition.copyFrom(center);
  1838. var quaternion = object.rotationQuaternion;
  1839. if (!quaternion) {
  1840. return;
  1841. }
  1842. //is shape is a plane or a heightmap, it must be rotated 90 degs in the X axis.
  1843. if (impostor.type === BABYLON.PhysicsImpostor.PlaneImpostor || impostor.type === BABYLON.PhysicsImpostor.HeightmapImpostor || impostor.type === BABYLON.PhysicsImpostor.CylinderImpostor) {
  1844. //-90 DEG in X, precalculated
  1845. quaternion = quaternion.multiply(this._minus90X);
  1846. //Invert! (Precalculated, 90 deg in X)
  1847. //No need to clone. this will never change.
  1848. impostor.setDeltaRotation(this._plus90X);
  1849. }
  1850. //If it is a heightfield, if should be centered.
  1851. if (impostor.type === BABYLON.PhysicsImpostor.HeightmapImpostor) {
  1852. var mesh = object;
  1853. var boundingInfo = mesh.getBoundingInfo();
  1854. //calculate the correct body position:
  1855. var rotationQuaternion = mesh.rotationQuaternion;
  1856. mesh.rotationQuaternion = this._tmpUnityRotation;
  1857. mesh.computeWorldMatrix(true);
  1858. //get original center with no rotation
  1859. var c = center.clone();
  1860. var oldPivot = mesh.getPivotMatrix() || BABYLON.Matrix.Translation(0, 0, 0);
  1861. //calculate the new center using a pivot (since this.BJSCANNON.js doesn't center height maps)
  1862. var p = BABYLON.Matrix.Translation(boundingInfo.boundingBox.extendSizeWorld.x, 0, -boundingInfo.boundingBox.extendSizeWorld.z);
  1863. mesh.setPivotMatrix(p);
  1864. mesh.computeWorldMatrix(true);
  1865. //calculate the translation
  1866. var translation = boundingInfo.boundingBox.centerWorld.subtract(center).subtract(mesh.position).negate();
  1867. this._tmpPosition.copyFromFloats(translation.x, translation.y - boundingInfo.boundingBox.extendSizeWorld.y, translation.z);
  1868. //add it inverted to the delta
  1869. this._tmpDeltaPosition.copyFrom(boundingInfo.boundingBox.centerWorld.subtract(c));
  1870. this._tmpDeltaPosition.y += boundingInfo.boundingBox.extendSizeWorld.y;
  1871. //rotation is back
  1872. mesh.rotationQuaternion = rotationQuaternion;
  1873. mesh.setPivotMatrix(oldPivot);
  1874. mesh.computeWorldMatrix(true);
  1875. }
  1876. else if (impostor.type === BABYLON.PhysicsImpostor.MeshImpostor) {
  1877. this._tmpDeltaPosition.copyFromFloats(0, 0, 0);
  1878. //this._tmpPosition.copyFrom(object.position);
  1879. }
  1880. impostor.setDeltaPosition(this._tmpDeltaPosition);
  1881. //Now update the impostor object
  1882. impostor.physicsBody.position.copy(this._tmpPosition);
  1883. impostor.physicsBody.quaternion.copy(quaternion);
  1884. };
  1885. CannonJSPlugin.prototype.setTransformationFromPhysicsBody = function (impostor) {
  1886. impostor.object.position.copyFrom(impostor.physicsBody.position);
  1887. if (impostor.object.rotationQuaternion) {
  1888. impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.quaternion);
  1889. }
  1890. };
  1891. CannonJSPlugin.prototype.setPhysicsBodyTransformation = function (impostor, newPosition, newRotation) {
  1892. impostor.physicsBody.position.copy(newPosition);
  1893. impostor.physicsBody.quaternion.copy(newRotation);
  1894. };
  1895. CannonJSPlugin.prototype.isSupported = function () {
  1896. return this.BJSCANNON !== undefined;
  1897. };
  1898. CannonJSPlugin.prototype.setLinearVelocity = function (impostor, velocity) {
  1899. impostor.physicsBody.velocity.copy(velocity);
  1900. };
  1901. CannonJSPlugin.prototype.setAngularVelocity = function (impostor, velocity) {
  1902. impostor.physicsBody.angularVelocity.copy(velocity);
  1903. };
  1904. CannonJSPlugin.prototype.getLinearVelocity = function (impostor) {
  1905. var v = impostor.physicsBody.velocity;
  1906. if (!v) {
  1907. return null;
  1908. }
  1909. return new BABYLON.Vector3(v.x, v.y, v.z);
  1910. };
  1911. CannonJSPlugin.prototype.getAngularVelocity = function (impostor) {
  1912. var v = impostor.physicsBody.angularVelocity;
  1913. if (!v) {
  1914. return null;
  1915. }
  1916. return new BABYLON.Vector3(v.x, v.y, v.z);
  1917. };
  1918. CannonJSPlugin.prototype.setBodyMass = function (impostor, mass) {
  1919. impostor.physicsBody.mass = mass;
  1920. impostor.physicsBody.updateMassProperties();
  1921. };
  1922. CannonJSPlugin.prototype.getBodyMass = function (impostor) {
  1923. return impostor.physicsBody.mass;
  1924. };
  1925. CannonJSPlugin.prototype.getBodyFriction = function (impostor) {
  1926. return impostor.physicsBody.material.friction;
  1927. };
  1928. CannonJSPlugin.prototype.setBodyFriction = function (impostor, friction) {
  1929. impostor.physicsBody.material.friction = friction;
  1930. };
  1931. CannonJSPlugin.prototype.getBodyRestitution = function (impostor) {
  1932. return impostor.physicsBody.material.restitution;
  1933. };
  1934. CannonJSPlugin.prototype.setBodyRestitution = function (impostor, restitution) {
  1935. impostor.physicsBody.material.restitution = restitution;
  1936. };
  1937. CannonJSPlugin.prototype.sleepBody = function (impostor) {
  1938. impostor.physicsBody.sleep();
  1939. };
  1940. CannonJSPlugin.prototype.wakeUpBody = function (impostor) {
  1941. impostor.physicsBody.wakeUp();
  1942. };
  1943. CannonJSPlugin.prototype.updateDistanceJoint = function (joint, maxDistance, minDistance) {
  1944. joint.physicsJoint.distance = maxDistance;
  1945. };
  1946. // private enableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
  1947. // if (!motorIndex) {
  1948. // joint.physicsJoint.enableMotor();
  1949. // }
  1950. // }
  1951. // private disableMotor(joint: IMotorEnabledJoint, motorIndex?: number) {
  1952. // if (!motorIndex) {
  1953. // joint.physicsJoint.disableMotor();
  1954. // }
  1955. // }
  1956. CannonJSPlugin.prototype.setMotor = function (joint, speed, maxForce, motorIndex) {
  1957. if (!motorIndex) {
  1958. joint.physicsJoint.enableMotor();
  1959. joint.physicsJoint.setMotorSpeed(speed);
  1960. if (maxForce) {
  1961. this.setLimit(joint, maxForce);
  1962. }
  1963. }
  1964. };
  1965. CannonJSPlugin.prototype.setLimit = function (joint, upperLimit, lowerLimit) {
  1966. joint.physicsJoint.motorEquation.maxForce = upperLimit;
  1967. joint.physicsJoint.motorEquation.minForce = lowerLimit === void 0 ? -upperLimit : lowerLimit;
  1968. };
  1969. CannonJSPlugin.prototype.syncMeshWithImpostor = function (mesh, impostor) {
  1970. var body = impostor.physicsBody;
  1971. mesh.position.x = body.position.x;
  1972. mesh.position.y = body.position.y;
  1973. mesh.position.z = body.position.z;
  1974. if (mesh.rotationQuaternion) {
  1975. mesh.rotationQuaternion.x = body.quaternion.x;
  1976. mesh.rotationQuaternion.y = body.quaternion.y;
  1977. mesh.rotationQuaternion.z = body.quaternion.z;
  1978. mesh.rotationQuaternion.w = body.quaternion.w;
  1979. }
  1980. };
  1981. CannonJSPlugin.prototype.getRadius = function (impostor) {
  1982. var shape = impostor.physicsBody.shapes[0];
  1983. return shape.boundingSphereRadius;
  1984. };
  1985. CannonJSPlugin.prototype.getBoxSizeToRef = function (impostor, result) {
  1986. var shape = impostor.physicsBody.shapes[0];
  1987. result.x = shape.halfExtents.x * 2;
  1988. result.y = shape.halfExtents.y * 2;
  1989. result.z = shape.halfExtents.z * 2;
  1990. };
  1991. CannonJSPlugin.prototype.dispose = function () {
  1992. };
  1993. CannonJSPlugin.prototype._extendNamespace = function () {
  1994. //this will force cannon to execute at least one step when using interpolation
  1995. var step_tmp1 = new this.BJSCANNON.Vec3();
  1996. var Engine = this.BJSCANNON;
  1997. this.BJSCANNON.World.prototype.step = function (dt, timeSinceLastCalled, maxSubSteps) {
  1998. maxSubSteps = maxSubSteps || 10;
  1999. timeSinceLastCalled = timeSinceLastCalled || 0;
  2000. if (timeSinceLastCalled === 0) {
  2001. this.internalStep(dt);
  2002. this.time += dt;
  2003. }
  2004. else {
  2005. var internalSteps = Math.floor((this.time + timeSinceLastCalled) / dt) - Math.floor(this.time / dt);
  2006. internalSteps = Math.min(internalSteps, maxSubSteps) || 1;
  2007. var t0 = performance.now();
  2008. for (var i = 0; i !== internalSteps; i++) {
  2009. this.internalStep(dt);
  2010. if (performance.now() - t0 > dt * 1000) {
  2011. break;
  2012. }
  2013. }
  2014. this.time += timeSinceLastCalled;
  2015. var h = this.time % dt;
  2016. var h_div_dt = h / dt;
  2017. var interpvelo = step_tmp1;
  2018. var bodies = this.bodies;
  2019. for (var j = 0; j !== bodies.length; j++) {
  2020. var b = bodies[j];
  2021. if (b.type !== Engine.Body.STATIC && b.sleepState !== Engine.Body.SLEEPING) {
  2022. b.position.vsub(b.previousPosition, interpvelo);
  2023. interpvelo.scale(h_div_dt, interpvelo);
  2024. b.position.vadd(interpvelo, b.interpolatedPosition);
  2025. }
  2026. else {
  2027. b.interpolatedPosition.copy(b.position);
  2028. b.interpolatedQuaternion.copy(b.quaternion);
  2029. }
  2030. }
  2031. }
  2032. };
  2033. };
  2034. return CannonJSPlugin;
  2035. }());
  2036. BABYLON.CannonJSPlugin = CannonJSPlugin;
  2037. })(BABYLON || (BABYLON = {}));
  2038. //# sourceMappingURL=babylon.cannonJSPlugin.js.map
  2039. var BABYLON;
  2040. (function (BABYLON) {
  2041. var OimoJSPlugin = /** @class */ (function () {
  2042. function OimoJSPlugin(iterations) {
  2043. this.name = "OimoJSPlugin";
  2044. this._tmpImpostorsArray = [];
  2045. this._tmpPositionVector = BABYLON.Vector3.Zero();
  2046. this.BJSOIMO = typeof OIMO !== 'undefined' ? OIMO : (typeof require !== 'undefined' ? require('./Oimo') : undefined);
  2047. this.world = new this.BJSOIMO.World(1 / 60, 2, iterations, true);
  2048. this.world.worldscale(1);
  2049. this.world.clear();
  2050. //making sure no stats are calculated
  2051. this.world.isNoStat = true;
  2052. }
  2053. OimoJSPlugin.prototype.setGravity = function (gravity) {
  2054. this.world.gravity.copy(gravity);
  2055. };
  2056. OimoJSPlugin.prototype.setTimeStep = function (timeStep) {
  2057. this.world.timeStep = timeStep;
  2058. };
  2059. OimoJSPlugin.prototype.getTimeStep = function () {
  2060. return this.world.timeStep;
  2061. };
  2062. OimoJSPlugin.prototype.executeStep = function (delta, impostors) {
  2063. var _this = this;
  2064. impostors.forEach(function (impostor) {
  2065. impostor.beforeStep();
  2066. });
  2067. this.world.step();
  2068. impostors.forEach(function (impostor) {
  2069. impostor.afterStep();
  2070. //update the ordered impostors array
  2071. _this._tmpImpostorsArray[impostor.uniqueId] = impostor;
  2072. });
  2073. //check for collisions
  2074. var contact = this.world.contacts;
  2075. while (contact !== null) {
  2076. if (contact.touching && !contact.body1.sleeping && !contact.body2.sleeping) {
  2077. contact = contact.next;
  2078. continue;
  2079. }
  2080. //is this body colliding with any other? get the impostor
  2081. var mainImpostor = this._tmpImpostorsArray[+contact.body1.name];
  2082. var collidingImpostor = this._tmpImpostorsArray[+contact.body2.name];
  2083. if (!mainImpostor || !collidingImpostor) {
  2084. contact = contact.next;
  2085. continue;
  2086. }
  2087. mainImpostor.onCollide({ body: collidingImpostor.physicsBody });
  2088. collidingImpostor.onCollide({ body: mainImpostor.physicsBody });
  2089. contact = contact.next;
  2090. }
  2091. };
  2092. OimoJSPlugin.prototype.applyImpulse = function (impostor, force, contactPoint) {
  2093. var mass = impostor.physicsBody.massInfo.mass;
  2094. impostor.physicsBody.applyImpulse(contactPoint.scale(this.BJSOIMO.INV_SCALE), force.scale(this.BJSOIMO.INV_SCALE * mass));
  2095. };
  2096. OimoJSPlugin.prototype.applyForce = function (impostor, force, contactPoint) {
  2097. BABYLON.Tools.Warn("Oimo doesn't support applying force. Using impule instead.");
  2098. this.applyImpulse(impostor, force, contactPoint);
  2099. };
  2100. OimoJSPlugin.prototype.generatePhysicsBody = function (impostor) {
  2101. var _this = this;
  2102. //parent-child relationship. Does this impostor has a parent impostor?
  2103. if (impostor.parent) {
  2104. if (impostor.physicsBody) {
  2105. this.removePhysicsBody(impostor);
  2106. //TODO is that needed?
  2107. impostor.forceUpdate();
  2108. }
  2109. return;
  2110. }
  2111. if (impostor.isBodyInitRequired()) {
  2112. var bodyConfig = {
  2113. name: impostor.uniqueId,
  2114. //Oimo must have mass, also for static objects.
  2115. config: [impostor.getParam("mass") || 1, impostor.getParam("friction"), impostor.getParam("restitution")],
  2116. size: [],
  2117. type: [],
  2118. pos: [],
  2119. rot: [],
  2120. move: impostor.getParam("mass") !== 0,
  2121. //Supporting older versions of Oimo
  2122. world: this.world
  2123. };
  2124. var impostors = [impostor];
  2125. var addToArray = function (parent) {
  2126. if (!parent.getChildMeshes)
  2127. return;
  2128. parent.getChildMeshes().forEach(function (m) {
  2129. if (m.physicsImpostor) {
  2130. impostors.push(m.physicsImpostor);
  2131. //m.physicsImpostor._init();
  2132. }
  2133. });
  2134. };
  2135. addToArray(impostor.object);
  2136. var checkWithEpsilon_1 = function (value) {
  2137. return Math.max(value, BABYLON.PhysicsEngine.Epsilon);
  2138. };
  2139. impostors.forEach(function (i) {
  2140. if (!impostor.object.rotationQuaternion) {
  2141. return;
  2142. }
  2143. //get the correct bounding box
  2144. var oldQuaternion = i.object.rotationQuaternion;
  2145. var rot = new _this.BJSOIMO.Euler().setFromQuaternion({
  2146. x: impostor.object.rotationQuaternion.x,
  2147. y: impostor.object.rotationQuaternion.y,
  2148. z: impostor.object.rotationQuaternion.z,
  2149. s: impostor.object.rotationQuaternion.w
  2150. });
  2151. var extendSize = i.getObjectExtendSize();
  2152. if (i === impostor) {
  2153. var center = impostor.getObjectCenter();
  2154. impostor.object.getAbsolutePivotPoint().subtractToRef(center, _this._tmpPositionVector);
  2155. _this._tmpPositionVector.divideInPlace(impostor.object.scaling);
  2156. //Can also use Array.prototype.push.apply
  2157. bodyConfig.pos.push(center.x);
  2158. bodyConfig.pos.push(center.y);
  2159. bodyConfig.pos.push(center.z);
  2160. //tmp solution
  2161. bodyConfig.rot.push(rot.x / (_this.BJSOIMO.degtorad || _this.BJSOIMO.TO_RAD));
  2162. bodyConfig.rot.push(rot.y / (_this.BJSOIMO.degtorad || _this.BJSOIMO.TO_RAD));
  2163. bodyConfig.rot.push(rot.z / (_this.BJSOIMO.degtorad || _this.BJSOIMO.TO_RAD));
  2164. }
  2165. else {
  2166. var localPosition = i.object.getAbsolutePosition().subtract(impostor.object.getAbsolutePosition());
  2167. bodyConfig.pos.push(localPosition.x);
  2168. bodyConfig.pos.push(localPosition.y);
  2169. bodyConfig.pos.push(localPosition.z);
  2170. //tmp solution until https://github.com/lo-th/OIMO.js/pull/37 is merged
  2171. bodyConfig.rot.push(0);
  2172. bodyConfig.rot.push(0);
  2173. bodyConfig.rot.push(0);
  2174. }
  2175. // register mesh
  2176. switch (i.type) {
  2177. case BABYLON.PhysicsImpostor.ParticleImpostor:
  2178. BABYLON.Tools.Warn("No Particle support in this.BJSOIMO.js. using SphereImpostor instead");
  2179. case BABYLON.PhysicsImpostor.SphereImpostor:
  2180. var radiusX = extendSize.x;
  2181. var radiusY = extendSize.y;
  2182. var radiusZ = extendSize.z;
  2183. var size = Math.max(checkWithEpsilon_1(radiusX), checkWithEpsilon_1(radiusY), checkWithEpsilon_1(radiusZ)) / 2;
  2184. bodyConfig.type.push('sphere');
  2185. //due to the way oimo works with compounds, add 3 times
  2186. bodyConfig.size.push(size);
  2187. bodyConfig.size.push(size);
  2188. bodyConfig.size.push(size);
  2189. break;
  2190. case BABYLON.PhysicsImpostor.CylinderImpostor:
  2191. var sizeX = checkWithEpsilon_1(extendSize.x) / 2;
  2192. var sizeY = checkWithEpsilon_1(extendSize.y);
  2193. bodyConfig.type.push('cylinder');
  2194. bodyConfig.size.push(sizeX);
  2195. bodyConfig.size.push(sizeY);
  2196. //due to the way oimo works with compounds, add one more value.
  2197. bodyConfig.size.push(sizeY);
  2198. break;
  2199. case BABYLON.PhysicsImpostor.PlaneImpostor:
  2200. case BABYLON.PhysicsImpostor.BoxImpostor:
  2201. default:
  2202. var sizeX = checkWithEpsilon_1(extendSize.x);
  2203. var sizeY = checkWithEpsilon_1(extendSize.y);
  2204. var sizeZ = checkWithEpsilon_1(extendSize.z);
  2205. bodyConfig.type.push('box');
  2206. bodyConfig.size.push(sizeX);
  2207. bodyConfig.size.push(sizeY);
  2208. bodyConfig.size.push(sizeZ);
  2209. break;
  2210. }
  2211. //actually not needed, but hey...
  2212. i.object.rotationQuaternion = oldQuaternion;
  2213. });
  2214. impostor.physicsBody = new this.BJSOIMO.Body(bodyConfig).body; //this.world.add(bodyConfig);
  2215. }
  2216. else {
  2217. this._tmpPositionVector.copyFromFloats(0, 0, 0);
  2218. }
  2219. impostor.setDeltaPosition(this._tmpPositionVector);
  2220. //this._tmpPositionVector.addInPlace(impostor.mesh.getBoundingInfo().boundingBox.center);
  2221. //this.setPhysicsBodyTransformation(impostor, this._tmpPositionVector, impostor.mesh.rotationQuaternion);
  2222. };
  2223. OimoJSPlugin.prototype.removePhysicsBody = function (impostor) {
  2224. //impostor.physicsBody.dispose();
  2225. //Same as : (older oimo versions)
  2226. this.world.removeRigidBody(impostor.physicsBody);
  2227. };
  2228. OimoJSPlugin.prototype.generateJoint = function (impostorJoint) {
  2229. var mainBody = impostorJoint.mainImpostor.physicsBody;
  2230. var connectedBody = impostorJoint.connectedImpostor.physicsBody;
  2231. if (!mainBody || !connectedBody) {
  2232. return;
  2233. }
  2234. var jointData = impostorJoint.joint.jointData;
  2235. var options = jointData.nativeParams || {};
  2236. var type;
  2237. var nativeJointData = {
  2238. body1: mainBody,
  2239. body2: connectedBody,
  2240. axe1: options.axe1 || (jointData.mainAxis ? jointData.mainAxis.asArray() : null),
  2241. axe2: options.axe2 || (jointData.connectedAxis ? jointData.connectedAxis.asArray() : null),
  2242. pos1: options.pos1 || (jointData.mainPivot ? jointData.mainPivot.asArray() : null),
  2243. pos2: options.pos2 || (jointData.connectedPivot ? jointData.connectedPivot.asArray() : null),
  2244. min: options.min,
  2245. max: options.max,
  2246. collision: options.collision || jointData.collision,
  2247. spring: options.spring,
  2248. //supporting older version of Oimo
  2249. world: this.world
  2250. };
  2251. switch (impostorJoint.joint.type) {
  2252. case BABYLON.PhysicsJoint.BallAndSocketJoint:
  2253. type = "jointBall";
  2254. break;
  2255. case BABYLON.PhysicsJoint.SpringJoint:
  2256. BABYLON.Tools.Warn("this.BJSOIMO.js doesn't support Spring Constraint. Simulating using DistanceJoint instead");
  2257. var springData = jointData;
  2258. nativeJointData.min = springData.length || nativeJointData.min;
  2259. //Max should also be set, just make sure it is at least min
  2260. nativeJointData.max = Math.max(nativeJointData.min, nativeJointData.max);
  2261. case BABYLON.PhysicsJoint.DistanceJoint:
  2262. type = "jointDistance";
  2263. nativeJointData.max = jointData.maxDistance;
  2264. break;
  2265. case BABYLON.PhysicsJoint.PrismaticJoint:
  2266. type = "jointPrisme";
  2267. break;
  2268. case BABYLON.PhysicsJoint.SliderJoint:
  2269. type = "jointSlide";
  2270. break;
  2271. case BABYLON.PhysicsJoint.WheelJoint:
  2272. type = "jointWheel";
  2273. break;
  2274. case BABYLON.PhysicsJoint.HingeJoint:
  2275. default:
  2276. type = "jointHinge";
  2277. break;
  2278. }
  2279. nativeJointData.type = type;
  2280. impostorJoint.joint.physicsJoint = new this.BJSOIMO.Link(nativeJointData).joint; //this.world.add(nativeJointData);
  2281. };
  2282. OimoJSPlugin.prototype.removeJoint = function (impostorJoint) {
  2283. //Bug in Oimo prevents us from disposing a joint in the playground
  2284. //joint.joint.physicsJoint.dispose();
  2285. //So we will bruteforce it!
  2286. try {
  2287. this.world.removeJoint(impostorJoint.joint.physicsJoint);
  2288. }
  2289. catch (e) {
  2290. BABYLON.Tools.Warn(e);
  2291. }
  2292. };
  2293. OimoJSPlugin.prototype.isSupported = function () {
  2294. return this.BJSOIMO !== undefined;
  2295. };
  2296. OimoJSPlugin.prototype.setTransformationFromPhysicsBody = function (impostor) {
  2297. if (!impostor.physicsBody.sleeping) {
  2298. //TODO check that
  2299. if (impostor.physicsBody.shapes.next) {
  2300. var parentShape = this._getLastShape(impostor.physicsBody);
  2301. impostor.object.position.x = parentShape.position.x * this.BJSOIMO.WORLD_SCALE;
  2302. impostor.object.position.y = parentShape.position.y * this.BJSOIMO.WORLD_SCALE;
  2303. impostor.object.position.z = parentShape.position.z * this.BJSOIMO.WORLD_SCALE;
  2304. }
  2305. else {
  2306. impostor.object.position.copyFrom(impostor.physicsBody.getPosition());
  2307. }
  2308. if (impostor.object.rotationQuaternion) {
  2309. impostor.object.rotationQuaternion.copyFrom(impostor.physicsBody.getQuaternion());
  2310. impostor.object.rotationQuaternion.normalize();
  2311. }
  2312. }
  2313. };
  2314. OimoJSPlugin.prototype.setPhysicsBodyTransformation = function (impostor, newPosition, newRotation) {
  2315. var body = impostor.physicsBody;
  2316. body.position.init(newPosition.x * this.BJSOIMO.INV_SCALE, newPosition.y * this.BJSOIMO.INV_SCALE, newPosition.z * this.BJSOIMO.INV_SCALE);
  2317. body.orientation.init(newRotation.w, newRotation.x, newRotation.y, newRotation.z);
  2318. body.syncShapes();
  2319. body.awake();
  2320. };
  2321. OimoJSPlugin.prototype._getLastShape = function (body) {
  2322. var lastShape = body.shapes;
  2323. while (lastShape.next) {
  2324. lastShape = lastShape.next;
  2325. }
  2326. return lastShape;
  2327. };
  2328. OimoJSPlugin.prototype.setLinearVelocity = function (impostor, velocity) {
  2329. impostor.physicsBody.linearVelocity.init(velocity.x, velocity.y, velocity.z);
  2330. };
  2331. OimoJSPlugin.prototype.setAngularVelocity = function (impostor, velocity) {
  2332. impostor.physicsBody.angularVelocity.init(velocity.x, velocity.y, velocity.z);
  2333. };
  2334. OimoJSPlugin.prototype.getLinearVelocity = function (impostor) {
  2335. var v = impostor.physicsBody.linearVelocity;
  2336. if (!v) {
  2337. return null;
  2338. }
  2339. return new BABYLON.Vector3(v.x, v.y, v.z);
  2340. };
  2341. OimoJSPlugin.prototype.getAngularVelocity = function (impostor) {
  2342. var v = impostor.physicsBody.angularVelocity;
  2343. if (!v) {
  2344. return null;
  2345. }
  2346. return new BABYLON.Vector3(v.x, v.y, v.z);
  2347. };
  2348. OimoJSPlugin.prototype.setBodyMass = function (impostor, mass) {
  2349. var staticBody = mass === 0;
  2350. //this will actually set the body's density and not its mass.
  2351. //But this is how oimo treats the mass variable.
  2352. impostor.physicsBody.shapes.density = staticBody ? 1 : mass;
  2353. impostor.physicsBody.setupMass(staticBody ? 0x2 : 0x1);
  2354. };
  2355. OimoJSPlugin.prototype.getBodyMass = function (impostor) {
  2356. return impostor.physicsBody.shapes.density;
  2357. };
  2358. OimoJSPlugin.prototype.getBodyFriction = function (impostor) {
  2359. return impostor.physicsBody.shapes.friction;
  2360. };
  2361. OimoJSPlugin.prototype.setBodyFriction = function (impostor, friction) {
  2362. impostor.physicsBody.shapes.friction = friction;
  2363. };
  2364. OimoJSPlugin.prototype.getBodyRestitution = function (impostor) {
  2365. return impostor.physicsBody.shapes.restitution;
  2366. };
  2367. OimoJSPlugin.prototype.setBodyRestitution = function (impostor, restitution) {
  2368. impostor.physicsBody.shapes.restitution = restitution;
  2369. };
  2370. OimoJSPlugin.prototype.sleepBody = function (impostor) {
  2371. impostor.physicsBody.sleep();
  2372. };
  2373. OimoJSPlugin.prototype.wakeUpBody = function (impostor) {
  2374. impostor.physicsBody.awake();
  2375. };
  2376. OimoJSPlugin.prototype.updateDistanceJoint = function (joint, maxDistance, minDistance) {
  2377. joint.physicsJoint.limitMotor.upperLimit = maxDistance;
  2378. if (minDistance !== void 0) {
  2379. joint.physicsJoint.limitMotor.lowerLimit = minDistance;
  2380. }
  2381. };
  2382. OimoJSPlugin.prototype.setMotor = function (joint, speed, maxForce, motorIndex) {
  2383. //TODO separate rotational and transational motors.
  2384. var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor1 || joint.physicsJoint.rotationalLimitMotor || joint.physicsJoint.limitMotor;
  2385. if (motor) {
  2386. motor.setMotor(speed, maxForce);
  2387. }
  2388. };
  2389. OimoJSPlugin.prototype.setLimit = function (joint, upperLimit, lowerLimit, motorIndex) {
  2390. //TODO separate rotational and transational motors.
  2391. var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor1 || joint.physicsJoint.rotationalLimitMotor || joint.physicsJoint.limitMotor;
  2392. if (motor) {
  2393. motor.setLimit(upperLimit, lowerLimit === void 0 ? -upperLimit : lowerLimit);
  2394. }
  2395. };
  2396. OimoJSPlugin.prototype.syncMeshWithImpostor = function (mesh, impostor) {
  2397. var body = impostor.physicsBody;
  2398. mesh.position.x = body.position.x;
  2399. mesh.position.y = body.position.y;
  2400. mesh.position.z = body.position.z;
  2401. if (mesh.rotationQuaternion) {
  2402. mesh.rotationQuaternion.x = body.orientation.x;
  2403. mesh.rotationQuaternion.y = body.orientation.y;
  2404. mesh.rotationQuaternion.z = body.orientation.z;
  2405. mesh.rotationQuaternion.w = body.orientation.s;
  2406. }
  2407. };
  2408. OimoJSPlugin.prototype.getRadius = function (impostor) {
  2409. return impostor.physicsBody.shapes.radius;
  2410. };
  2411. OimoJSPlugin.prototype.getBoxSizeToRef = function (impostor, result) {
  2412. var shape = impostor.physicsBody.shapes;
  2413. result.x = shape.halfWidth * 2;
  2414. result.y = shape.halfHeight * 2;
  2415. result.z = shape.halfDepth * 2;
  2416. };
  2417. OimoJSPlugin.prototype.dispose = function () {
  2418. this.world.clear();
  2419. };
  2420. return OimoJSPlugin;
  2421. }());
  2422. BABYLON.OimoJSPlugin = OimoJSPlugin;
  2423. })(BABYLON || (BABYLON = {}));
  2424. //# sourceMappingURL=babylon.oimoJSPlugin.js.map
  2425. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  2426. BABYLON.Effect.IncludesShadersStore['bonesDeclaration'] = "#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif";
  2427. BABYLON.Effect.IncludesShadersStore['instancesDeclaration'] = "#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif";
  2428. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  2429. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  2430. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  2431. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  2432. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  2433. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexDeclaration'] = "#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif";
  2434. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  2435. BABYLON.Effect.IncludesShadersStore['morphTargetsVertex'] = "#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif";
  2436. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  2437. BABYLON.Effect.IncludesShadersStore['bonesVertex'] = "#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif";
  2438. BABYLON.Effect.IncludesShadersStore['bumpVertex'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif";
  2439. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  2440. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  2441. BABYLON.Effect.IncludesShadersStore['shadowsVertex'] = "#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif";
  2442. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  2443. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  2444. BABYLON.Effect.IncludesShadersStore['helperFunctions'] = "const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nvec3 dither(vec2 seed,vec3 color) {\nfloat rand=getRand(seed);\ncolor+=mix(-0.5/255.0,0.5/255.0,rand);\ncolor=max(color,0.0);\nreturn color;\n}";
  2445. BABYLON.Effect.IncludesShadersStore['lightFragmentDeclaration'] = "#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif";
  2446. BABYLON.Effect.IncludesShadersStore['lightsFragmentFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n";
  2447. BABYLON.Effect.IncludesShadersStore['lightUboDeclaration'] = "#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif";
  2448. BABYLON.Effect.IncludesShadersStore['defaultVertexDeclaration'] = "\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  2449. BABYLON.Effect.IncludesShadersStore['defaultFragmentDeclaration'] = "uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif";
  2450. BABYLON.Effect.IncludesShadersStore['defaultUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  2451. BABYLON.Effect.IncludesShadersStore['shadowsFragmentFunctions'] = "#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n";
  2452. BABYLON.Effect.IncludesShadersStore['fresnelFunction'] = "#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif";
  2453. BABYLON.Effect.IncludesShadersStore['reflectionFunction'] = "vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}";
  2454. BABYLON.Effect.IncludesShadersStore['imageProcessingDeclaration'] = "#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif";
  2455. BABYLON.Effect.IncludesShadersStore['imageProcessingFunctions'] = "#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}";
  2456. BABYLON.Effect.IncludesShadersStore['bumpFragmentFunctions'] = "#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif";
  2457. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  2458. BABYLON.Effect.IncludesShadersStore['fogFragmentDeclaration'] = "#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif";
  2459. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  2460. BABYLON.Effect.IncludesShadersStore['bumpFragment'] = "vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif";
  2461. BABYLON.Effect.IncludesShadersStore['lightFragment'] = "#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif";
  2462. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  2463. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  2464. var PhysicsJoint = BABYLON.PhysicsJoint;
  2465. var DistanceJoint = BABYLON.DistanceJoint;
  2466. var MotorEnabledJoint = BABYLON.MotorEnabledJoint;
  2467. var HingeJoint = BABYLON.HingeJoint;
  2468. var Hinge2Joint = BABYLON.Hinge2Joint;
  2469. var PhysicsImpostor = BABYLON.PhysicsImpostor;
  2470. var PhysicsEngine = BABYLON.PhysicsEngine;
  2471. var PhysicsHelper = BABYLON.PhysicsHelper;
  2472. var PhysicsRadialExplosionEvent = BABYLON.PhysicsRadialExplosionEvent;
  2473. var PhysicsGravitationalFieldEvent = BABYLON.PhysicsGravitationalFieldEvent;
  2474. var PhysicsUpdraftEvent = BABYLON.PhysicsUpdraftEvent;
  2475. var PhysicsVortexEvent = BABYLON.PhysicsVortexEvent;
  2476. var PhysicsRadialImpulseFalloff = BABYLON.PhysicsRadialImpulseFalloff;
  2477. var PhysicsUpdraftMode = BABYLON.PhysicsUpdraftMode;
  2478. var CannonJSPlugin = BABYLON.CannonJSPlugin;
  2479. var OimoJSPlugin = BABYLON.OimoJSPlugin;
  2480. export { PhysicsJoint,DistanceJoint,MotorEnabledJoint,HingeJoint,Hinge2Joint,PhysicsImpostor,PhysicsEngine,PhysicsHelper,PhysicsRadialExplosionEvent,PhysicsGravitationalFieldEvent,PhysicsUpdraftEvent,PhysicsVortexEvent,PhysicsRadialImpulseFalloff,PhysicsUpdraftMode,CannonJSPlugin,OimoJSPlugin };