es6.js 163 KB

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