index.js 164 KB

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