index.js 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  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. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  12. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  13. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  14. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  15. return c > 3 && r && Object.defineProperty(target, key, r), r;
  16. };
  17. if(typeof require !== 'undefined'){
  18. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  19. var BABYLON = globalObject["BABYLON"] || {};
  20. var BABYLON0 = require('babylonjs/core');
  21. if(BABYLON !== BABYLON0) __extends(BABYLON, BABYLON0);
  22. var BABYLON;
  23. (function (BABYLON) {
  24. var FreeCameraGamepadInput = /** @class */ (function () {
  25. function FreeCameraGamepadInput() {
  26. this.gamepadAngularSensibility = 200;
  27. this.gamepadMoveSensibility = 40;
  28. // private members
  29. this._cameraTransform = BABYLON.Matrix.Identity();
  30. this._deltaTransform = BABYLON.Vector3.Zero();
  31. this._vector3 = BABYLON.Vector3.Zero();
  32. this._vector2 = BABYLON.Vector2.Zero();
  33. }
  34. FreeCameraGamepadInput.prototype.attachControl = function (element, noPreventDefault) {
  35. var _this = this;
  36. var manager = this.camera.getScene().gamepadManager;
  37. this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
  38. if (gamepad.type !== BABYLON.Gamepad.POSE_ENABLED) {
  39. // prioritize XBOX gamepads.
  40. if (!_this.gamepad || gamepad.type === BABYLON.Gamepad.XBOX) {
  41. _this.gamepad = gamepad;
  42. }
  43. }
  44. });
  45. this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add(function (gamepad) {
  46. if (_this.gamepad === gamepad) {
  47. _this.gamepad = null;
  48. }
  49. });
  50. this.gamepad = manager.getGamepadByType(BABYLON.Gamepad.XBOX);
  51. };
  52. FreeCameraGamepadInput.prototype.detachControl = function (element) {
  53. this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
  54. this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
  55. this.gamepad = null;
  56. };
  57. FreeCameraGamepadInput.prototype.checkInputs = function () {
  58. if (this.gamepad && this.gamepad.leftStick) {
  59. var camera = this.camera;
  60. var LSValues = this.gamepad.leftStick;
  61. var normalizedLX = LSValues.x / this.gamepadMoveSensibility;
  62. var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
  63. LSValues.x = Math.abs(normalizedLX) > 0.005 ? 0 + normalizedLX : 0;
  64. LSValues.y = Math.abs(normalizedLY) > 0.005 ? 0 + normalizedLY : 0;
  65. var RSValues = this.gamepad.rightStick;
  66. if (RSValues) {
  67. var normalizedRX = RSValues.x / this.gamepadAngularSensibility;
  68. var normalizedRY = RSValues.y / this.gamepadAngularSensibility;
  69. RSValues.x = Math.abs(normalizedRX) > 0.001 ? 0 + normalizedRX : 0;
  70. RSValues.y = Math.abs(normalizedRY) > 0.001 ? 0 + normalizedRY : 0;
  71. }
  72. else {
  73. RSValues = { x: 0, y: 0 };
  74. }
  75. if (!camera.rotationQuaternion) {
  76. BABYLON.Matrix.RotationYawPitchRollToRef(camera.rotation.y, camera.rotation.x, 0, this._cameraTransform);
  77. }
  78. else {
  79. camera.rotationQuaternion.toRotationMatrix(this._cameraTransform);
  80. }
  81. var speed = camera._computeLocalCameraSpeed() * 50.0;
  82. this._vector3.copyFromFloats(LSValues.x * speed, 0, -LSValues.y * speed);
  83. BABYLON.Vector3.TransformCoordinatesToRef(this._vector3, this._cameraTransform, this._deltaTransform);
  84. camera.cameraDirection.addInPlace(this._deltaTransform);
  85. this._vector2.copyFromFloats(RSValues.y, RSValues.x);
  86. camera.cameraRotation.addInPlace(this._vector2);
  87. }
  88. };
  89. FreeCameraGamepadInput.prototype.getClassName = function () {
  90. return "FreeCameraGamepadInput";
  91. };
  92. FreeCameraGamepadInput.prototype.getSimpleName = function () {
  93. return "gamepad";
  94. };
  95. __decorate([
  96. BABYLON.serialize()
  97. ], FreeCameraGamepadInput.prototype, "gamepadAngularSensibility", void 0);
  98. __decorate([
  99. BABYLON.serialize()
  100. ], FreeCameraGamepadInput.prototype, "gamepadMoveSensibility", void 0);
  101. return FreeCameraGamepadInput;
  102. }());
  103. BABYLON.FreeCameraGamepadInput = FreeCameraGamepadInput;
  104. BABYLON.CameraInputTypes["FreeCameraGamepadInput"] = FreeCameraGamepadInput;
  105. })(BABYLON || (BABYLON = {}));
  106. //# sourceMappingURL=babylon.freeCameraGamepadInput.js.map
  107. var BABYLON;
  108. (function (BABYLON) {
  109. var ArcRotateCameraGamepadInput = /** @class */ (function () {
  110. function ArcRotateCameraGamepadInput() {
  111. this.gamepadRotationSensibility = 80;
  112. this.gamepadMoveSensibility = 40;
  113. }
  114. ArcRotateCameraGamepadInput.prototype.attachControl = function (element, noPreventDefault) {
  115. var _this = this;
  116. var manager = this.camera.getScene().gamepadManager;
  117. this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
  118. if (gamepad.type !== BABYLON.Gamepad.POSE_ENABLED) {
  119. // prioritize XBOX gamepads.
  120. if (!_this.gamepad || gamepad.type === BABYLON.Gamepad.XBOX) {
  121. _this.gamepad = gamepad;
  122. }
  123. }
  124. });
  125. this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add(function (gamepad) {
  126. if (_this.gamepad === gamepad) {
  127. _this.gamepad = null;
  128. }
  129. });
  130. this.gamepad = manager.getGamepadByType(BABYLON.Gamepad.XBOX);
  131. };
  132. ArcRotateCameraGamepadInput.prototype.detachControl = function (element) {
  133. this.camera.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
  134. this.camera.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
  135. this.gamepad = null;
  136. };
  137. ArcRotateCameraGamepadInput.prototype.checkInputs = function () {
  138. if (this.gamepad) {
  139. var camera = this.camera;
  140. var RSValues = this.gamepad.rightStick;
  141. if (RSValues) {
  142. if (RSValues.x != 0) {
  143. var normalizedRX = RSValues.x / this.gamepadRotationSensibility;
  144. if (normalizedRX != 0 && Math.abs(normalizedRX) > 0.005) {
  145. camera.inertialAlphaOffset += normalizedRX;
  146. }
  147. }
  148. if (RSValues.y != 0) {
  149. var normalizedRY = RSValues.y / this.gamepadRotationSensibility;
  150. if (normalizedRY != 0 && Math.abs(normalizedRY) > 0.005) {
  151. camera.inertialBetaOffset += normalizedRY;
  152. }
  153. }
  154. }
  155. var LSValues = this.gamepad.leftStick;
  156. if (LSValues && LSValues.y != 0) {
  157. var normalizedLY = LSValues.y / this.gamepadMoveSensibility;
  158. if (normalizedLY != 0 && Math.abs(normalizedLY) > 0.005) {
  159. this.camera.inertialRadiusOffset -= normalizedLY;
  160. }
  161. }
  162. }
  163. };
  164. ArcRotateCameraGamepadInput.prototype.getClassName = function () {
  165. return "ArcRotateCameraGamepadInput";
  166. };
  167. ArcRotateCameraGamepadInput.prototype.getSimpleName = function () {
  168. return "gamepad";
  169. };
  170. __decorate([
  171. BABYLON.serialize()
  172. ], ArcRotateCameraGamepadInput.prototype, "gamepadRotationSensibility", void 0);
  173. __decorate([
  174. BABYLON.serialize()
  175. ], ArcRotateCameraGamepadInput.prototype, "gamepadMoveSensibility", void 0);
  176. return ArcRotateCameraGamepadInput;
  177. }());
  178. BABYLON.ArcRotateCameraGamepadInput = ArcRotateCameraGamepadInput;
  179. BABYLON.CameraInputTypes["ArcRotateCameraGamepadInput"] = ArcRotateCameraGamepadInput;
  180. })(BABYLON || (BABYLON = {}));
  181. //# sourceMappingURL=babylon.arcRotateCameraGamepadInput.js.map
  182. 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}";
  183. 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}";
  184. var BABYLON;
  185. (function (BABYLON) {
  186. var GamepadManager = /** @class */ (function () {
  187. function GamepadManager(_scene) {
  188. var _this = this;
  189. this._scene = _scene;
  190. this._babylonGamepads = [];
  191. this._oneGamepadConnected = false;
  192. this._isMonitoring = false;
  193. this.onGamepadDisconnectedObservable = new BABYLON.Observable();
  194. if (!BABYLON.Tools.IsWindowObjectExist()) {
  195. this._gamepadEventSupported = false;
  196. }
  197. else {
  198. this._gamepadEventSupported = 'GamepadEvent' in window;
  199. this._gamepadSupport = (navigator.getGamepads ||
  200. navigator.webkitGetGamepads || navigator.msGetGamepads || navigator.webkitGamepads);
  201. }
  202. this.onGamepadConnectedObservable = new BABYLON.Observable(function (observer) {
  203. // This will be used to raise the onGamepadConnected for all gamepads ALREADY connected
  204. for (var i in _this._babylonGamepads) {
  205. var gamepad = _this._babylonGamepads[i];
  206. if (gamepad && gamepad._isConnected) {
  207. _this.onGamepadConnectedObservable.notifyObserver(observer, gamepad);
  208. }
  209. }
  210. });
  211. this._onGamepadConnectedEvent = function (evt) {
  212. var gamepad = evt.gamepad;
  213. if (gamepad.index in _this._babylonGamepads) {
  214. if (_this._babylonGamepads[gamepad.index].isConnected) {
  215. return;
  216. }
  217. }
  218. var newGamepad;
  219. if (_this._babylonGamepads[gamepad.index]) {
  220. newGamepad = _this._babylonGamepads[gamepad.index];
  221. newGamepad.browserGamepad = gamepad;
  222. newGamepad._isConnected = true;
  223. }
  224. else {
  225. newGamepad = _this._addNewGamepad(gamepad);
  226. }
  227. _this.onGamepadConnectedObservable.notifyObservers(newGamepad);
  228. _this._startMonitoringGamepads();
  229. };
  230. this._onGamepadDisconnectedEvent = function (evt) {
  231. var gamepad = evt.gamepad;
  232. // Remove the gamepad from the list of gamepads to monitor.
  233. for (var i in _this._babylonGamepads) {
  234. if (_this._babylonGamepads[i].index === gamepad.index) {
  235. var disconnectedGamepad = _this._babylonGamepads[i];
  236. disconnectedGamepad._isConnected = false;
  237. _this.onGamepadDisconnectedObservable.notifyObservers(disconnectedGamepad);
  238. break;
  239. }
  240. }
  241. };
  242. if (this._gamepadSupport) {
  243. //first add already-connected gamepads
  244. this._updateGamepadObjects();
  245. if (this._babylonGamepads.length) {
  246. this._startMonitoringGamepads();
  247. }
  248. // Checking if the gamepad connected event is supported (like in Firefox)
  249. if (this._gamepadEventSupported) {
  250. window.addEventListener('gamepadconnected', this._onGamepadConnectedEvent, false);
  251. window.addEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent, false);
  252. }
  253. else {
  254. this._startMonitoringGamepads();
  255. }
  256. }
  257. }
  258. Object.defineProperty(GamepadManager.prototype, "gamepads", {
  259. get: function () {
  260. return this._babylonGamepads;
  261. },
  262. enumerable: true,
  263. configurable: true
  264. });
  265. GamepadManager.prototype.getGamepadByType = function (type) {
  266. if (type === void 0) { type = BABYLON.Gamepad.XBOX; }
  267. for (var _i = 0, _a = this._babylonGamepads; _i < _a.length; _i++) {
  268. var gamepad = _a[_i];
  269. if (gamepad && gamepad.type === type) {
  270. return gamepad;
  271. }
  272. }
  273. return null;
  274. };
  275. GamepadManager.prototype.dispose = function () {
  276. if (this._gamepadEventSupported) {
  277. if (this._onGamepadConnectedEvent) {
  278. window.removeEventListener('gamepadconnected', this._onGamepadConnectedEvent);
  279. }
  280. if (this._onGamepadDisconnectedEvent) {
  281. window.removeEventListener('gamepaddisconnected', this._onGamepadDisconnectedEvent);
  282. }
  283. this._onGamepadConnectedEvent = null;
  284. this._onGamepadDisconnectedEvent = null;
  285. }
  286. this._babylonGamepads.forEach(function (gamepad) {
  287. gamepad.dispose();
  288. });
  289. this.onGamepadConnectedObservable.clear();
  290. this.onGamepadDisconnectedObservable.clear();
  291. this._oneGamepadConnected = false;
  292. this._stopMonitoringGamepads();
  293. this._babylonGamepads = [];
  294. };
  295. GamepadManager.prototype._addNewGamepad = function (gamepad) {
  296. if (!this._oneGamepadConnected) {
  297. this._oneGamepadConnected = true;
  298. }
  299. var newGamepad;
  300. var xboxOne = (gamepad.id.search("Xbox One") !== -1);
  301. if (xboxOne || gamepad.id.search("Xbox 360") !== -1 || gamepad.id.search("xinput") !== -1) {
  302. newGamepad = new BABYLON.Xbox360Pad(gamepad.id, gamepad.index, gamepad, xboxOne);
  303. }
  304. else if (gamepad.pose) {
  305. newGamepad = BABYLON.PoseEnabledControllerHelper.InitiateController(gamepad);
  306. }
  307. else {
  308. newGamepad = new BABYLON.GenericPad(gamepad.id, gamepad.index, gamepad);
  309. }
  310. this._babylonGamepads[newGamepad.index] = newGamepad;
  311. return newGamepad;
  312. };
  313. GamepadManager.prototype._startMonitoringGamepads = function () {
  314. if (!this._isMonitoring) {
  315. this._isMonitoring = true;
  316. //back-comp
  317. if (!this._scene) {
  318. this._checkGamepadsStatus();
  319. }
  320. }
  321. };
  322. GamepadManager.prototype._stopMonitoringGamepads = function () {
  323. this._isMonitoring = false;
  324. };
  325. GamepadManager.prototype._checkGamepadsStatus = function () {
  326. var _this = this;
  327. // Hack to be compatible Chrome
  328. this._updateGamepadObjects();
  329. for (var i in this._babylonGamepads) {
  330. var gamepad = this._babylonGamepads[i];
  331. if (!gamepad || !gamepad.isConnected) {
  332. continue;
  333. }
  334. gamepad.update();
  335. }
  336. if (this._isMonitoring && !this._scene) {
  337. BABYLON.Tools.QueueNewFrame(function () { _this._checkGamepadsStatus(); });
  338. }
  339. };
  340. // This function is called only on Chrome, which does not properly support
  341. // connection/disconnection events and forces you to recopy again the gamepad object
  342. GamepadManager.prototype._updateGamepadObjects = function () {
  343. var gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
  344. for (var i = 0; i < gamepads.length; i++) {
  345. if (gamepads[i]) {
  346. if (!this._babylonGamepads[gamepads[i].index]) {
  347. var newGamepad = this._addNewGamepad(gamepads[i]);
  348. this.onGamepadConnectedObservable.notifyObservers(newGamepad);
  349. }
  350. else {
  351. // Forced to copy again this object for Chrome for unknown reason
  352. this._babylonGamepads[i].browserGamepad = gamepads[i];
  353. if (!this._babylonGamepads[i].isConnected) {
  354. this._babylonGamepads[i]._isConnected = true;
  355. this.onGamepadConnectedObservable.notifyObservers(this._babylonGamepads[i]);
  356. }
  357. }
  358. }
  359. }
  360. };
  361. return GamepadManager;
  362. }());
  363. BABYLON.GamepadManager = GamepadManager;
  364. })(BABYLON || (BABYLON = {}));
  365. //# sourceMappingURL=babylon.gamepadManager.js.map
  366. var BABYLON;
  367. (function (BABYLON) {
  368. var StickValues = /** @class */ (function () {
  369. function StickValues(x, y) {
  370. this.x = x;
  371. this.y = y;
  372. }
  373. return StickValues;
  374. }());
  375. BABYLON.StickValues = StickValues;
  376. var Gamepad = /** @class */ (function () {
  377. function Gamepad(id, index, browserGamepad, leftStickX, leftStickY, rightStickX, rightStickY) {
  378. if (leftStickX === void 0) { leftStickX = 0; }
  379. if (leftStickY === void 0) { leftStickY = 1; }
  380. if (rightStickX === void 0) { rightStickX = 2; }
  381. if (rightStickY === void 0) { rightStickY = 3; }
  382. this.id = id;
  383. this.index = index;
  384. this.browserGamepad = browserGamepad;
  385. this._isConnected = true;
  386. this._invertLeftStickY = false;
  387. this.type = Gamepad.GAMEPAD;
  388. this._leftStickAxisX = leftStickX;
  389. this._leftStickAxisY = leftStickY;
  390. this._rightStickAxisX = rightStickX;
  391. this._rightStickAxisY = rightStickY;
  392. if (this.browserGamepad.axes.length >= 2) {
  393. this._leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };
  394. }
  395. if (this.browserGamepad.axes.length >= 4) {
  396. this._rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };
  397. }
  398. }
  399. Object.defineProperty(Gamepad.prototype, "isConnected", {
  400. get: function () {
  401. return this._isConnected;
  402. },
  403. enumerable: true,
  404. configurable: true
  405. });
  406. Gamepad.prototype.onleftstickchanged = function (callback) {
  407. this._onleftstickchanged = callback;
  408. };
  409. Gamepad.prototype.onrightstickchanged = function (callback) {
  410. this._onrightstickchanged = callback;
  411. };
  412. Object.defineProperty(Gamepad.prototype, "leftStick", {
  413. get: function () {
  414. return this._leftStick;
  415. },
  416. set: function (newValues) {
  417. if (this._onleftstickchanged && (this._leftStick.x !== newValues.x || this._leftStick.y !== newValues.y)) {
  418. this._onleftstickchanged(newValues);
  419. }
  420. this._leftStick = newValues;
  421. },
  422. enumerable: true,
  423. configurable: true
  424. });
  425. Object.defineProperty(Gamepad.prototype, "rightStick", {
  426. get: function () {
  427. return this._rightStick;
  428. },
  429. set: function (newValues) {
  430. if (this._onrightstickchanged && (this._rightStick.x !== newValues.x || this._rightStick.y !== newValues.y)) {
  431. this._onrightstickchanged(newValues);
  432. }
  433. this._rightStick = newValues;
  434. },
  435. enumerable: true,
  436. configurable: true
  437. });
  438. Gamepad.prototype.update = function () {
  439. if (this._leftStick) {
  440. this.leftStick = { x: this.browserGamepad.axes[this._leftStickAxisX], y: this.browserGamepad.axes[this._leftStickAxisY] };
  441. if (this._invertLeftStickY) {
  442. this.leftStick.y *= -1;
  443. }
  444. }
  445. if (this._rightStick) {
  446. this.rightStick = { x: this.browserGamepad.axes[this._rightStickAxisX], y: this.browserGamepad.axes[this._rightStickAxisY] };
  447. }
  448. };
  449. Gamepad.prototype.dispose = function () {
  450. };
  451. Gamepad.GAMEPAD = 0;
  452. Gamepad.GENERIC = 1;
  453. Gamepad.XBOX = 2;
  454. Gamepad.POSE_ENABLED = 3;
  455. return Gamepad;
  456. }());
  457. BABYLON.Gamepad = Gamepad;
  458. var GenericPad = /** @class */ (function (_super) {
  459. __extends(GenericPad, _super);
  460. function GenericPad(id, index, browserGamepad) {
  461. var _this = _super.call(this, id, index, browserGamepad) || this;
  462. _this.onButtonDownObservable = new BABYLON.Observable();
  463. _this.onButtonUpObservable = new BABYLON.Observable();
  464. _this.type = Gamepad.GENERIC;
  465. _this._buttons = new Array(browserGamepad.buttons.length);
  466. return _this;
  467. }
  468. GenericPad.prototype.onbuttondown = function (callback) {
  469. this._onbuttondown = callback;
  470. };
  471. GenericPad.prototype.onbuttonup = function (callback) {
  472. this._onbuttonup = callback;
  473. };
  474. GenericPad.prototype._setButtonValue = function (newValue, currentValue, buttonIndex) {
  475. if (newValue !== currentValue) {
  476. if (newValue === 1) {
  477. if (this._onbuttondown) {
  478. this._onbuttondown(buttonIndex);
  479. }
  480. this.onButtonDownObservable.notifyObservers(buttonIndex);
  481. }
  482. if (newValue === 0) {
  483. if (this._onbuttonup) {
  484. this._onbuttonup(buttonIndex);
  485. }
  486. this.onButtonUpObservable.notifyObservers(buttonIndex);
  487. }
  488. }
  489. return newValue;
  490. };
  491. GenericPad.prototype.update = function () {
  492. _super.prototype.update.call(this);
  493. for (var index = 0; index < this._buttons.length; index++) {
  494. this._buttons[index] = this._setButtonValue(this.browserGamepad.buttons[index].value, this._buttons[index], index);
  495. }
  496. };
  497. GenericPad.prototype.dispose = function () {
  498. _super.prototype.dispose.call(this);
  499. this.onButtonDownObservable.clear();
  500. this.onButtonUpObservable.clear();
  501. };
  502. return GenericPad;
  503. }(Gamepad));
  504. BABYLON.GenericPad = GenericPad;
  505. })(BABYLON || (BABYLON = {}));
  506. //# sourceMappingURL=babylon.gamepad.js.map
  507. var BABYLON;
  508. (function (BABYLON) {
  509. var Xbox360Button;
  510. (function (Xbox360Button) {
  511. Xbox360Button[Xbox360Button["A"] = 0] = "A";
  512. Xbox360Button[Xbox360Button["B"] = 1] = "B";
  513. Xbox360Button[Xbox360Button["X"] = 2] = "X";
  514. Xbox360Button[Xbox360Button["Y"] = 3] = "Y";
  515. Xbox360Button[Xbox360Button["Start"] = 4] = "Start";
  516. Xbox360Button[Xbox360Button["Back"] = 5] = "Back";
  517. Xbox360Button[Xbox360Button["LB"] = 6] = "LB";
  518. Xbox360Button[Xbox360Button["RB"] = 7] = "RB";
  519. Xbox360Button[Xbox360Button["LeftStick"] = 8] = "LeftStick";
  520. Xbox360Button[Xbox360Button["RightStick"] = 9] = "RightStick";
  521. })(Xbox360Button = BABYLON.Xbox360Button || (BABYLON.Xbox360Button = {}));
  522. var Xbox360Dpad;
  523. (function (Xbox360Dpad) {
  524. Xbox360Dpad[Xbox360Dpad["Up"] = 0] = "Up";
  525. Xbox360Dpad[Xbox360Dpad["Down"] = 1] = "Down";
  526. Xbox360Dpad[Xbox360Dpad["Left"] = 2] = "Left";
  527. Xbox360Dpad[Xbox360Dpad["Right"] = 3] = "Right";
  528. })(Xbox360Dpad = BABYLON.Xbox360Dpad || (BABYLON.Xbox360Dpad = {}));
  529. var Xbox360Pad = /** @class */ (function (_super) {
  530. __extends(Xbox360Pad, _super);
  531. function Xbox360Pad(id, index, gamepad, xboxOne) {
  532. if (xboxOne === void 0) { xboxOne = false; }
  533. var _this = _super.call(this, id, index, gamepad, 0, 1, 2, 3) || this;
  534. _this._leftTrigger = 0;
  535. _this._rightTrigger = 0;
  536. _this.onButtonDownObservable = new BABYLON.Observable();
  537. _this.onButtonUpObservable = new BABYLON.Observable();
  538. _this.onPadDownObservable = new BABYLON.Observable();
  539. _this.onPadUpObservable = new BABYLON.Observable();
  540. _this._buttonA = 0;
  541. _this._buttonB = 0;
  542. _this._buttonX = 0;
  543. _this._buttonY = 0;
  544. _this._buttonBack = 0;
  545. _this._buttonStart = 0;
  546. _this._buttonLB = 0;
  547. _this._buttonRB = 0;
  548. _this._buttonLeftStick = 0;
  549. _this._buttonRightStick = 0;
  550. _this._dPadUp = 0;
  551. _this._dPadDown = 0;
  552. _this._dPadLeft = 0;
  553. _this._dPadRight = 0;
  554. _this._isXboxOnePad = false;
  555. _this.type = BABYLON.Gamepad.XBOX;
  556. _this._isXboxOnePad = xboxOne;
  557. return _this;
  558. }
  559. Xbox360Pad.prototype.onlefttriggerchanged = function (callback) {
  560. this._onlefttriggerchanged = callback;
  561. };
  562. Xbox360Pad.prototype.onrighttriggerchanged = function (callback) {
  563. this._onrighttriggerchanged = callback;
  564. };
  565. Object.defineProperty(Xbox360Pad.prototype, "leftTrigger", {
  566. get: function () {
  567. return this._leftTrigger;
  568. },
  569. set: function (newValue) {
  570. if (this._onlefttriggerchanged && this._leftTrigger !== newValue) {
  571. this._onlefttriggerchanged(newValue);
  572. }
  573. this._leftTrigger = newValue;
  574. },
  575. enumerable: true,
  576. configurable: true
  577. });
  578. Object.defineProperty(Xbox360Pad.prototype, "rightTrigger", {
  579. get: function () {
  580. return this._rightTrigger;
  581. },
  582. set: function (newValue) {
  583. if (this._onrighttriggerchanged && this._rightTrigger !== newValue) {
  584. this._onrighttriggerchanged(newValue);
  585. }
  586. this._rightTrigger = newValue;
  587. },
  588. enumerable: true,
  589. configurable: true
  590. });
  591. Xbox360Pad.prototype.onbuttondown = function (callback) {
  592. this._onbuttondown = callback;
  593. };
  594. Xbox360Pad.prototype.onbuttonup = function (callback) {
  595. this._onbuttonup = callback;
  596. };
  597. Xbox360Pad.prototype.ondpaddown = function (callback) {
  598. this._ondpaddown = callback;
  599. };
  600. Xbox360Pad.prototype.ondpadup = function (callback) {
  601. this._ondpadup = callback;
  602. };
  603. Xbox360Pad.prototype._setButtonValue = function (newValue, currentValue, buttonType) {
  604. if (newValue !== currentValue) {
  605. if (newValue === 1) {
  606. if (this._onbuttondown) {
  607. this._onbuttondown(buttonType);
  608. }
  609. this.onButtonDownObservable.notifyObservers(buttonType);
  610. }
  611. if (newValue === 0) {
  612. if (this._onbuttonup) {
  613. this._onbuttonup(buttonType);
  614. }
  615. this.onButtonUpObservable.notifyObservers(buttonType);
  616. }
  617. }
  618. return newValue;
  619. };
  620. Xbox360Pad.prototype._setDPadValue = function (newValue, currentValue, buttonType) {
  621. if (newValue !== currentValue) {
  622. if (newValue === 1) {
  623. if (this._ondpaddown) {
  624. this._ondpaddown(buttonType);
  625. }
  626. this.onPadDownObservable.notifyObservers(buttonType);
  627. }
  628. if (newValue === 0) {
  629. if (this._ondpadup) {
  630. this._ondpadup(buttonType);
  631. }
  632. this.onPadUpObservable.notifyObservers(buttonType);
  633. }
  634. }
  635. return newValue;
  636. };
  637. Object.defineProperty(Xbox360Pad.prototype, "buttonA", {
  638. get: function () {
  639. return this._buttonA;
  640. },
  641. set: function (value) {
  642. this._buttonA = this._setButtonValue(value, this._buttonA, Xbox360Button.A);
  643. },
  644. enumerable: true,
  645. configurable: true
  646. });
  647. Object.defineProperty(Xbox360Pad.prototype, "buttonB", {
  648. get: function () {
  649. return this._buttonB;
  650. },
  651. set: function (value) {
  652. this._buttonB = this._setButtonValue(value, this._buttonB, Xbox360Button.B);
  653. },
  654. enumerable: true,
  655. configurable: true
  656. });
  657. Object.defineProperty(Xbox360Pad.prototype, "buttonX", {
  658. get: function () {
  659. return this._buttonX;
  660. },
  661. set: function (value) {
  662. this._buttonX = this._setButtonValue(value, this._buttonX, Xbox360Button.X);
  663. },
  664. enumerable: true,
  665. configurable: true
  666. });
  667. Object.defineProperty(Xbox360Pad.prototype, "buttonY", {
  668. get: function () {
  669. return this._buttonY;
  670. },
  671. set: function (value) {
  672. this._buttonY = this._setButtonValue(value, this._buttonY, Xbox360Button.Y);
  673. },
  674. enumerable: true,
  675. configurable: true
  676. });
  677. Object.defineProperty(Xbox360Pad.prototype, "buttonStart", {
  678. get: function () {
  679. return this._buttonStart;
  680. },
  681. set: function (value) {
  682. this._buttonStart = this._setButtonValue(value, this._buttonStart, Xbox360Button.Start);
  683. },
  684. enumerable: true,
  685. configurable: true
  686. });
  687. Object.defineProperty(Xbox360Pad.prototype, "buttonBack", {
  688. get: function () {
  689. return this._buttonBack;
  690. },
  691. set: function (value) {
  692. this._buttonBack = this._setButtonValue(value, this._buttonBack, Xbox360Button.Back);
  693. },
  694. enumerable: true,
  695. configurable: true
  696. });
  697. Object.defineProperty(Xbox360Pad.prototype, "buttonLB", {
  698. get: function () {
  699. return this._buttonLB;
  700. },
  701. set: function (value) {
  702. this._buttonLB = this._setButtonValue(value, this._buttonLB, Xbox360Button.LB);
  703. },
  704. enumerable: true,
  705. configurable: true
  706. });
  707. Object.defineProperty(Xbox360Pad.prototype, "buttonRB", {
  708. get: function () {
  709. return this._buttonRB;
  710. },
  711. set: function (value) {
  712. this._buttonRB = this._setButtonValue(value, this._buttonRB, Xbox360Button.RB);
  713. },
  714. enumerable: true,
  715. configurable: true
  716. });
  717. Object.defineProperty(Xbox360Pad.prototype, "buttonLeftStick", {
  718. get: function () {
  719. return this._buttonLeftStick;
  720. },
  721. set: function (value) {
  722. this._buttonLeftStick = this._setButtonValue(value, this._buttonLeftStick, Xbox360Button.LeftStick);
  723. },
  724. enumerable: true,
  725. configurable: true
  726. });
  727. Object.defineProperty(Xbox360Pad.prototype, "buttonRightStick", {
  728. get: function () {
  729. return this._buttonRightStick;
  730. },
  731. set: function (value) {
  732. this._buttonRightStick = this._setButtonValue(value, this._buttonRightStick, Xbox360Button.RightStick);
  733. },
  734. enumerable: true,
  735. configurable: true
  736. });
  737. Object.defineProperty(Xbox360Pad.prototype, "dPadUp", {
  738. get: function () {
  739. return this._dPadUp;
  740. },
  741. set: function (value) {
  742. this._dPadUp = this._setDPadValue(value, this._dPadUp, Xbox360Dpad.Up);
  743. },
  744. enumerable: true,
  745. configurable: true
  746. });
  747. Object.defineProperty(Xbox360Pad.prototype, "dPadDown", {
  748. get: function () {
  749. return this._dPadDown;
  750. },
  751. set: function (value) {
  752. this._dPadDown = this._setDPadValue(value, this._dPadDown, Xbox360Dpad.Down);
  753. },
  754. enumerable: true,
  755. configurable: true
  756. });
  757. Object.defineProperty(Xbox360Pad.prototype, "dPadLeft", {
  758. get: function () {
  759. return this._dPadLeft;
  760. },
  761. set: function (value) {
  762. this._dPadLeft = this._setDPadValue(value, this._dPadLeft, Xbox360Dpad.Left);
  763. },
  764. enumerable: true,
  765. configurable: true
  766. });
  767. Object.defineProperty(Xbox360Pad.prototype, "dPadRight", {
  768. get: function () {
  769. return this._dPadRight;
  770. },
  771. set: function (value) {
  772. this._dPadRight = this._setDPadValue(value, this._dPadRight, Xbox360Dpad.Right);
  773. },
  774. enumerable: true,
  775. configurable: true
  776. });
  777. Xbox360Pad.prototype.update = function () {
  778. _super.prototype.update.call(this);
  779. if (this._isXboxOnePad) {
  780. this.buttonA = this.browserGamepad.buttons[0].value;
  781. this.buttonB = this.browserGamepad.buttons[1].value;
  782. this.buttonX = this.browserGamepad.buttons[2].value;
  783. this.buttonY = this.browserGamepad.buttons[3].value;
  784. this.buttonLB = this.browserGamepad.buttons[4].value;
  785. this.buttonRB = this.browserGamepad.buttons[5].value;
  786. this.leftTrigger = this.browserGamepad.axes[2];
  787. this.rightTrigger = this.browserGamepad.axes[5];
  788. this.buttonBack = this.browserGamepad.buttons[9].value;
  789. this.buttonStart = this.browserGamepad.buttons[8].value;
  790. this.buttonLeftStick = this.browserGamepad.buttons[6].value;
  791. this.buttonRightStick = this.browserGamepad.buttons[7].value;
  792. this.dPadUp = this.browserGamepad.buttons[11].value;
  793. this.dPadDown = this.browserGamepad.buttons[12].value;
  794. this.dPadLeft = this.browserGamepad.buttons[13].value;
  795. this.dPadRight = this.browserGamepad.buttons[14].value;
  796. }
  797. else {
  798. this.buttonA = this.browserGamepad.buttons[0].value;
  799. this.buttonB = this.browserGamepad.buttons[1].value;
  800. this.buttonX = this.browserGamepad.buttons[2].value;
  801. this.buttonY = this.browserGamepad.buttons[3].value;
  802. this.buttonLB = this.browserGamepad.buttons[4].value;
  803. this.buttonRB = this.browserGamepad.buttons[5].value;
  804. this.leftTrigger = this.browserGamepad.buttons[6].value;
  805. this.rightTrigger = this.browserGamepad.buttons[7].value;
  806. this.buttonBack = this.browserGamepad.buttons[8].value;
  807. this.buttonStart = this.browserGamepad.buttons[9].value;
  808. this.buttonLeftStick = this.browserGamepad.buttons[10].value;
  809. this.buttonRightStick = this.browserGamepad.buttons[11].value;
  810. this.dPadUp = this.browserGamepad.buttons[12].value;
  811. this.dPadDown = this.browserGamepad.buttons[13].value;
  812. this.dPadLeft = this.browserGamepad.buttons[14].value;
  813. this.dPadRight = this.browserGamepad.buttons[15].value;
  814. }
  815. };
  816. Xbox360Pad.prototype.dispose = function () {
  817. _super.prototype.dispose.call(this);
  818. this.onButtonDownObservable.clear();
  819. this.onButtonUpObservable.clear();
  820. this.onPadDownObservable.clear();
  821. this.onPadUpObservable.clear();
  822. };
  823. return Xbox360Pad;
  824. }(BABYLON.Gamepad));
  825. BABYLON.Xbox360Pad = Xbox360Pad;
  826. })(BABYLON || (BABYLON = {}));
  827. //# sourceMappingURL=babylon.xboxGamepad.js.map
  828. var BABYLON;
  829. (function (BABYLON) {
  830. var PoseEnabledControllerType;
  831. (function (PoseEnabledControllerType) {
  832. PoseEnabledControllerType[PoseEnabledControllerType["VIVE"] = 0] = "VIVE";
  833. PoseEnabledControllerType[PoseEnabledControllerType["OCULUS"] = 1] = "OCULUS";
  834. PoseEnabledControllerType[PoseEnabledControllerType["WINDOWS"] = 2] = "WINDOWS";
  835. PoseEnabledControllerType[PoseEnabledControllerType["GENERIC"] = 3] = "GENERIC";
  836. })(PoseEnabledControllerType = BABYLON.PoseEnabledControllerType || (BABYLON.PoseEnabledControllerType = {}));
  837. var PoseEnabledControllerHelper = /** @class */ (function () {
  838. function PoseEnabledControllerHelper() {
  839. }
  840. PoseEnabledControllerHelper.InitiateController = function (vrGamepad) {
  841. // Oculus Touch
  842. if (vrGamepad.id.indexOf('Oculus Touch') !== -1) {
  843. return new BABYLON.OculusTouchController(vrGamepad);
  844. }
  845. else if (vrGamepad.id.indexOf(BABYLON.WindowsMotionController.GAMEPAD_ID_PREFIX) === 0) {
  846. return new BABYLON.WindowsMotionController(vrGamepad);
  847. }
  848. else if (vrGamepad.id.toLowerCase().indexOf('openvr') !== -1) {
  849. return new BABYLON.ViveController(vrGamepad);
  850. }
  851. else {
  852. return new BABYLON.GenericController(vrGamepad);
  853. }
  854. };
  855. return PoseEnabledControllerHelper;
  856. }());
  857. BABYLON.PoseEnabledControllerHelper = PoseEnabledControllerHelper;
  858. var PoseEnabledController = /** @class */ (function (_super) {
  859. __extends(PoseEnabledController, _super);
  860. function PoseEnabledController(browserGamepad) {
  861. var _this = _super.call(this, browserGamepad.id, browserGamepad.index, browserGamepad) || this;
  862. // Represents device position and rotation in room space. Should only be used to help calculate babylon space values
  863. _this._deviceRoomPosition = BABYLON.Vector3.Zero();
  864. _this._deviceRoomRotationQuaternion = new BABYLON.Quaternion();
  865. // Represents device position and rotation in babylon space
  866. _this.devicePosition = BABYLON.Vector3.Zero();
  867. _this.deviceRotationQuaternion = new BABYLON.Quaternion();
  868. _this.deviceScaleFactor = 1;
  869. _this._leftHandSystemQuaternion = new BABYLON.Quaternion();
  870. _this._deviceToWorld = BABYLON.Matrix.Identity();
  871. _this._workingMatrix = BABYLON.Matrix.Identity();
  872. _this.type = BABYLON.Gamepad.POSE_ENABLED;
  873. _this.controllerType = PoseEnabledControllerType.GENERIC;
  874. _this.position = BABYLON.Vector3.Zero();
  875. _this.rotationQuaternion = new BABYLON.Quaternion();
  876. _this._calculatedPosition = BABYLON.Vector3.Zero();
  877. _this._calculatedRotation = new BABYLON.Quaternion();
  878. BABYLON.Quaternion.RotationYawPitchRollToRef(Math.PI, 0, 0, _this._leftHandSystemQuaternion);
  879. return _this;
  880. }
  881. PoseEnabledController.prototype.update = function () {
  882. _super.prototype.update.call(this);
  883. var pose = this.browserGamepad.pose;
  884. this.updateFromDevice(pose);
  885. BABYLON.Vector3.TransformCoordinatesToRef(this._calculatedPosition, this._deviceToWorld, this.devicePosition);
  886. this._deviceToWorld.getRotationMatrixToRef(this._workingMatrix);
  887. BABYLON.Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);
  888. this.deviceRotationQuaternion.multiplyInPlace(this._calculatedRotation);
  889. if (this._mesh) {
  890. this._mesh.position.copyFrom(this.devicePosition);
  891. if (this._mesh.rotationQuaternion) {
  892. this._mesh.rotationQuaternion.copyFrom(this.deviceRotationQuaternion);
  893. }
  894. }
  895. };
  896. PoseEnabledController.prototype.updateFromDevice = function (poseData) {
  897. if (poseData) {
  898. this.rawPose = poseData;
  899. if (poseData.position) {
  900. this._deviceRoomPosition.copyFromFloats(poseData.position[0], poseData.position[1], -poseData.position[2]);
  901. if (this._mesh && this._mesh.getScene().useRightHandedSystem) {
  902. this._deviceRoomPosition.z *= -1;
  903. }
  904. this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);
  905. this._calculatedPosition.addInPlace(this.position);
  906. }
  907. var pose = this.rawPose;
  908. if (poseData.orientation && pose.orientation) {
  909. this._deviceRoomRotationQuaternion.copyFromFloats(pose.orientation[0], pose.orientation[1], -pose.orientation[2], -pose.orientation[3]);
  910. if (this._mesh) {
  911. if (this._mesh.getScene().useRightHandedSystem) {
  912. this._deviceRoomRotationQuaternion.z *= -1;
  913. this._deviceRoomRotationQuaternion.w *= -1;
  914. }
  915. else {
  916. this._deviceRoomRotationQuaternion.multiplyToRef(this._leftHandSystemQuaternion, this._deviceRoomRotationQuaternion);
  917. }
  918. }
  919. // if the camera is set, rotate to the camera's rotation
  920. this._deviceRoomRotationQuaternion.multiplyToRef(this.rotationQuaternion, this._calculatedRotation);
  921. }
  922. }
  923. };
  924. PoseEnabledController.prototype.attachToMesh = function (mesh) {
  925. if (this._mesh) {
  926. this._mesh.parent = null;
  927. }
  928. this._mesh = mesh;
  929. if (this._poseControlledCamera) {
  930. this._mesh.parent = this._poseControlledCamera;
  931. }
  932. if (!this._mesh.rotationQuaternion) {
  933. this._mesh.rotationQuaternion = new BABYLON.Quaternion();
  934. }
  935. };
  936. PoseEnabledController.prototype.attachToPoseControlledCamera = function (camera) {
  937. this._poseControlledCamera = camera;
  938. if (this._mesh) {
  939. this._mesh.parent = this._poseControlledCamera;
  940. }
  941. };
  942. PoseEnabledController.prototype.dispose = function () {
  943. if (this._mesh) {
  944. this._mesh.dispose();
  945. }
  946. this._mesh = null;
  947. _super.prototype.dispose.call(this);
  948. };
  949. Object.defineProperty(PoseEnabledController.prototype, "mesh", {
  950. get: function () {
  951. return this._mesh;
  952. },
  953. enumerable: true,
  954. configurable: true
  955. });
  956. PoseEnabledController.prototype.getForwardRay = function (length) {
  957. if (length === void 0) { length = 100; }
  958. if (!this.mesh) {
  959. return new BABYLON.Ray(BABYLON.Vector3.Zero(), new BABYLON.Vector3(0, 0, 1), length);
  960. }
  961. var m = this.mesh.getWorldMatrix();
  962. var origin = m.getTranslation();
  963. var forward = new BABYLON.Vector3(0, 0, -1);
  964. var forwardWorld = BABYLON.Vector3.TransformNormal(forward, m);
  965. var direction = BABYLON.Vector3.Normalize(forwardWorld);
  966. return new BABYLON.Ray(origin, direction, length);
  967. };
  968. return PoseEnabledController;
  969. }(BABYLON.Gamepad));
  970. BABYLON.PoseEnabledController = PoseEnabledController;
  971. })(BABYLON || (BABYLON = {}));
  972. //# sourceMappingURL=babylon.poseEnabledController.js.map
  973. var BABYLON;
  974. (function (BABYLON) {
  975. var WebVRController = /** @class */ (function (_super) {
  976. __extends(WebVRController, _super);
  977. function WebVRController(vrGamepad) {
  978. var _this = _super.call(this, vrGamepad) || this;
  979. // Observables
  980. _this.onTriggerStateChangedObservable = new BABYLON.Observable();
  981. _this.onMainButtonStateChangedObservable = new BABYLON.Observable();
  982. _this.onSecondaryButtonStateChangedObservable = new BABYLON.Observable();
  983. _this.onPadStateChangedObservable = new BABYLON.Observable();
  984. _this.onPadValuesChangedObservable = new BABYLON.Observable();
  985. _this.pad = { x: 0, y: 0 };
  986. // avoid GC, store state in a tmp object
  987. _this._changes = {
  988. pressChanged: false,
  989. touchChanged: false,
  990. valueChanged: false,
  991. changed: false
  992. };
  993. _this._buttons = new Array(vrGamepad.buttons.length);
  994. _this.hand = vrGamepad.hand;
  995. return _this;
  996. }
  997. WebVRController.prototype.onButtonStateChange = function (callback) {
  998. this._onButtonStateChange = callback;
  999. };
  1000. Object.defineProperty(WebVRController.prototype, "defaultModel", {
  1001. get: function () {
  1002. return this._defaultModel;
  1003. },
  1004. enumerable: true,
  1005. configurable: true
  1006. });
  1007. WebVRController.prototype.update = function () {
  1008. _super.prototype.update.call(this);
  1009. for (var index = 0; index < this._buttons.length; index++) {
  1010. this._setButtonValue(this.browserGamepad.buttons[index], this._buttons[index], index);
  1011. }
  1012. ;
  1013. if (this.leftStick.x !== this.pad.x || this.leftStick.y !== this.pad.y) {
  1014. this.pad.x = this.leftStick.x;
  1015. this.pad.y = this.leftStick.y;
  1016. this.onPadValuesChangedObservable.notifyObservers(this.pad);
  1017. }
  1018. };
  1019. WebVRController.prototype._setButtonValue = function (newState, currentState, buttonIndex) {
  1020. if (!newState) {
  1021. newState = {
  1022. pressed: false,
  1023. touched: false,
  1024. value: 0
  1025. };
  1026. }
  1027. if (!currentState) {
  1028. this._buttons[buttonIndex] = {
  1029. pressed: newState.pressed,
  1030. touched: newState.touched,
  1031. value: newState.value
  1032. };
  1033. return;
  1034. }
  1035. this._checkChanges(newState, currentState);
  1036. if (this._changes.changed) {
  1037. this._onButtonStateChange && this._onButtonStateChange(this.index, buttonIndex, newState);
  1038. this.handleButtonChange(buttonIndex, newState, this._changes);
  1039. }
  1040. this._buttons[buttonIndex].pressed = newState.pressed;
  1041. this._buttons[buttonIndex].touched = newState.touched;
  1042. // oculus triggers are never 0, thou not touched.
  1043. this._buttons[buttonIndex].value = newState.value < 0.00000001 ? 0 : newState.value;
  1044. };
  1045. WebVRController.prototype._checkChanges = function (newState, currentState) {
  1046. this._changes.pressChanged = newState.pressed !== currentState.pressed;
  1047. this._changes.touchChanged = newState.touched !== currentState.touched;
  1048. this._changes.valueChanged = newState.value !== currentState.value;
  1049. this._changes.changed = this._changes.pressChanged || this._changes.touchChanged || this._changes.valueChanged;
  1050. return this._changes;
  1051. };
  1052. WebVRController.prototype.dispose = function () {
  1053. _super.prototype.dispose.call(this);
  1054. this.onTriggerStateChangedObservable.clear();
  1055. this.onMainButtonStateChangedObservable.clear();
  1056. this.onSecondaryButtonStateChangedObservable.clear();
  1057. this.onPadStateChangedObservable.clear();
  1058. this.onPadValuesChangedObservable.clear();
  1059. };
  1060. return WebVRController;
  1061. }(BABYLON.PoseEnabledController));
  1062. BABYLON.WebVRController = WebVRController;
  1063. })(BABYLON || (BABYLON = {}));
  1064. //# sourceMappingURL=babylon.webVRController.js.map
  1065. var BABYLON;
  1066. (function (BABYLON) {
  1067. var OculusTouchController = /** @class */ (function (_super) {
  1068. __extends(OculusTouchController, _super);
  1069. function OculusTouchController(vrGamepad) {
  1070. var _this = _super.call(this, vrGamepad) || this;
  1071. _this.onSecondaryTriggerStateChangedObservable = new BABYLON.Observable();
  1072. _this.onThumbRestChangedObservable = new BABYLON.Observable();
  1073. _this.controllerType = BABYLON.PoseEnabledControllerType.OCULUS;
  1074. return _this;
  1075. }
  1076. OculusTouchController.prototype.initControllerMesh = function (scene, meshLoaded) {
  1077. var _this = this;
  1078. var meshName;
  1079. // Hand
  1080. if (this.hand === 'left') {
  1081. meshName = OculusTouchController.MODEL_LEFT_FILENAME;
  1082. }
  1083. else {
  1084. meshName = OculusTouchController.MODEL_RIGHT_FILENAME;
  1085. }
  1086. BABYLON.SceneLoader.ImportMesh("", OculusTouchController.MODEL_BASE_URL, meshName, scene, function (newMeshes) {
  1087. /*
  1088. Parent Mesh name: oculus_touch_left
  1089. - body
  1090. - trigger
  1091. - thumbstick
  1092. - grip
  1093. - button_y
  1094. - button_x
  1095. - button_enter
  1096. */
  1097. _this._defaultModel = newMeshes[1];
  1098. _this.attachToMesh(_this._defaultModel);
  1099. if (meshLoaded) {
  1100. meshLoaded(_this._defaultModel);
  1101. }
  1102. });
  1103. };
  1104. Object.defineProperty(OculusTouchController.prototype, "onAButtonStateChangedObservable", {
  1105. // helper getters for left and right hand.
  1106. get: function () {
  1107. if (this.hand === 'right') {
  1108. return this.onMainButtonStateChangedObservable;
  1109. }
  1110. else {
  1111. throw new Error('No A button on left hand');
  1112. }
  1113. },
  1114. enumerable: true,
  1115. configurable: true
  1116. });
  1117. Object.defineProperty(OculusTouchController.prototype, "onBButtonStateChangedObservable", {
  1118. get: function () {
  1119. if (this.hand === 'right') {
  1120. return this.onSecondaryButtonStateChangedObservable;
  1121. }
  1122. else {
  1123. throw new Error('No B button on left hand');
  1124. }
  1125. },
  1126. enumerable: true,
  1127. configurable: true
  1128. });
  1129. Object.defineProperty(OculusTouchController.prototype, "onXButtonStateChangedObservable", {
  1130. get: function () {
  1131. if (this.hand === 'left') {
  1132. return this.onMainButtonStateChangedObservable;
  1133. }
  1134. else {
  1135. throw new Error('No X button on right hand');
  1136. }
  1137. },
  1138. enumerable: true,
  1139. configurable: true
  1140. });
  1141. Object.defineProperty(OculusTouchController.prototype, "onYButtonStateChangedObservable", {
  1142. get: function () {
  1143. if (this.hand === 'left') {
  1144. return this.onSecondaryButtonStateChangedObservable;
  1145. }
  1146. else {
  1147. throw new Error('No Y button on right hand');
  1148. }
  1149. },
  1150. enumerable: true,
  1151. configurable: true
  1152. });
  1153. /*
  1154. 0) thumb stick (touch, press, value = pressed (0,1)). value is in this.leftStick
  1155. 1) index trigger (touch (?), press (only when value > 0.1), value 0 to 1)
  1156. 2) secondary trigger (same)
  1157. 3) A (right) X (left), touch, pressed = value
  1158. 4) B / Y
  1159. 5) thumb rest
  1160. */
  1161. OculusTouchController.prototype.handleButtonChange = function (buttonIdx, state, changes) {
  1162. var notifyObject = state; //{ state: state, changes: changes };
  1163. var triggerDirection = this.hand === 'right' ? -1 : 1;
  1164. switch (buttonIdx) {
  1165. case 0:
  1166. this.onPadStateChangedObservable.notifyObservers(notifyObject);
  1167. return;
  1168. case 1:// index trigger
  1169. if (this._defaultModel) {
  1170. (this._defaultModel.getChildren()[3]).rotation.x = -notifyObject.value * 0.20;
  1171. (this._defaultModel.getChildren()[3]).position.y = -notifyObject.value * 0.005;
  1172. (this._defaultModel.getChildren()[3]).position.z = -notifyObject.value * 0.005;
  1173. }
  1174. this.onTriggerStateChangedObservable.notifyObservers(notifyObject);
  1175. return;
  1176. case 2:// secondary trigger
  1177. if (this._defaultModel) {
  1178. (this._defaultModel.getChildren()[4]).position.x = triggerDirection * notifyObject.value * 0.0035;
  1179. }
  1180. this.onSecondaryTriggerStateChangedObservable.notifyObservers(notifyObject);
  1181. return;
  1182. case 3:
  1183. if (this._defaultModel) {
  1184. if (notifyObject.pressed) {
  1185. (this._defaultModel.getChildren()[1]).position.y = -0.001;
  1186. }
  1187. else {
  1188. (this._defaultModel.getChildren()[1]).position.y = 0;
  1189. }
  1190. }
  1191. this.onMainButtonStateChangedObservable.notifyObservers(notifyObject);
  1192. return;
  1193. case 4:
  1194. if (this._defaultModel) {
  1195. if (notifyObject.pressed) {
  1196. (this._defaultModel.getChildren()[2]).position.y = -0.001;
  1197. }
  1198. else {
  1199. (this._defaultModel.getChildren()[2]).position.y = 0;
  1200. }
  1201. }
  1202. this.onSecondaryButtonStateChangedObservable.notifyObservers(notifyObject);
  1203. return;
  1204. case 5:
  1205. this.onThumbRestChangedObservable.notifyObservers(notifyObject);
  1206. return;
  1207. }
  1208. };
  1209. OculusTouchController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/oculus/';
  1210. OculusTouchController.MODEL_LEFT_FILENAME = 'left.babylon';
  1211. OculusTouchController.MODEL_RIGHT_FILENAME = 'right.babylon';
  1212. return OculusTouchController;
  1213. }(BABYLON.WebVRController));
  1214. BABYLON.OculusTouchController = OculusTouchController;
  1215. })(BABYLON || (BABYLON = {}));
  1216. //# sourceMappingURL=babylon.oculusTouchController.js.map
  1217. var BABYLON;
  1218. (function (BABYLON) {
  1219. var ViveController = /** @class */ (function (_super) {
  1220. __extends(ViveController, _super);
  1221. function ViveController(vrGamepad) {
  1222. var _this = _super.call(this, vrGamepad) || this;
  1223. _this.controllerType = BABYLON.PoseEnabledControllerType.VIVE;
  1224. _this._invertLeftStickY = true;
  1225. return _this;
  1226. }
  1227. ViveController.prototype.initControllerMesh = function (scene, meshLoaded) {
  1228. var _this = this;
  1229. BABYLON.SceneLoader.ImportMesh("", ViveController.MODEL_BASE_URL, ViveController.MODEL_FILENAME, scene, function (newMeshes) {
  1230. /*
  1231. Parent Mesh name: ViveWand
  1232. - body
  1233. - r_gripper
  1234. - l_gripper
  1235. - menu_button
  1236. - system_button
  1237. - trackpad
  1238. - trigger
  1239. - LED
  1240. */
  1241. _this._defaultModel = newMeshes[1];
  1242. _this.attachToMesh(_this._defaultModel);
  1243. if (meshLoaded) {
  1244. meshLoaded(_this._defaultModel);
  1245. }
  1246. });
  1247. };
  1248. Object.defineProperty(ViveController.prototype, "onLeftButtonStateChangedObservable", {
  1249. get: function () {
  1250. return this.onMainButtonStateChangedObservable;
  1251. },
  1252. enumerable: true,
  1253. configurable: true
  1254. });
  1255. Object.defineProperty(ViveController.prototype, "onRightButtonStateChangedObservable", {
  1256. get: function () {
  1257. return this.onMainButtonStateChangedObservable;
  1258. },
  1259. enumerable: true,
  1260. configurable: true
  1261. });
  1262. Object.defineProperty(ViveController.prototype, "onMenuButtonStateChangedObservable", {
  1263. get: function () {
  1264. return this.onSecondaryButtonStateChangedObservable;
  1265. },
  1266. enumerable: true,
  1267. configurable: true
  1268. });
  1269. /**
  1270. * Vive mapping:
  1271. * 0: touchpad
  1272. * 1: trigger
  1273. * 2: left AND right buttons
  1274. * 3: menu button
  1275. */
  1276. ViveController.prototype.handleButtonChange = function (buttonIdx, state, changes) {
  1277. var notifyObject = state; //{ state: state, changes: changes };
  1278. switch (buttonIdx) {
  1279. case 0:
  1280. this.onPadStateChangedObservable.notifyObservers(notifyObject);
  1281. return;
  1282. case 1:// index trigger
  1283. if (this._defaultModel) {
  1284. (this._defaultModel.getChildren()[6]).rotation.x = -notifyObject.value * 0.15;
  1285. }
  1286. this.onTriggerStateChangedObservable.notifyObservers(notifyObject);
  1287. return;
  1288. case 2:// left AND right button
  1289. this.onMainButtonStateChangedObservable.notifyObservers(notifyObject);
  1290. return;
  1291. case 3:
  1292. if (this._defaultModel) {
  1293. if (notifyObject.pressed) {
  1294. (this._defaultModel.getChildren()[2]).position.y = -0.001;
  1295. }
  1296. else {
  1297. (this._defaultModel.getChildren()[2]).position.y = 0;
  1298. }
  1299. }
  1300. this.onSecondaryButtonStateChangedObservable.notifyObservers(notifyObject);
  1301. return;
  1302. }
  1303. };
  1304. ViveController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/vive/';
  1305. ViveController.MODEL_FILENAME = 'wand.babylon';
  1306. return ViveController;
  1307. }(BABYLON.WebVRController));
  1308. BABYLON.ViveController = ViveController;
  1309. })(BABYLON || (BABYLON = {}));
  1310. //# sourceMappingURL=babylon.viveController.js.map
  1311. var BABYLON;
  1312. (function (BABYLON) {
  1313. var GenericController = /** @class */ (function (_super) {
  1314. __extends(GenericController, _super);
  1315. function GenericController(vrGamepad) {
  1316. return _super.call(this, vrGamepad) || this;
  1317. }
  1318. GenericController.prototype.initControllerMesh = function (scene, meshLoaded) {
  1319. var _this = this;
  1320. BABYLON.SceneLoader.ImportMesh("", GenericController.MODEL_BASE_URL, GenericController.MODEL_FILENAME, scene, function (newMeshes) {
  1321. _this._defaultModel = newMeshes[1];
  1322. _this.attachToMesh(_this._defaultModel);
  1323. if (meshLoaded) {
  1324. meshLoaded(_this._defaultModel);
  1325. }
  1326. });
  1327. };
  1328. GenericController.prototype.handleButtonChange = function (buttonIdx, state, changes) {
  1329. console.log("Button id: " + buttonIdx + "state: ");
  1330. console.dir(state);
  1331. };
  1332. GenericController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/generic/';
  1333. GenericController.MODEL_FILENAME = 'generic.babylon';
  1334. return GenericController;
  1335. }(BABYLON.WebVRController));
  1336. BABYLON.GenericController = GenericController;
  1337. })(BABYLON || (BABYLON = {}));
  1338. //# sourceMappingURL=babylon.genericController.js.map
  1339. var BABYLON;
  1340. (function (BABYLON) {
  1341. var LoadedMeshInfo = /** @class */ (function () {
  1342. function LoadedMeshInfo() {
  1343. this.buttonMeshes = {};
  1344. this.axisMeshes = {};
  1345. }
  1346. return LoadedMeshInfo;
  1347. }());
  1348. var WindowsMotionController = /** @class */ (function (_super) {
  1349. __extends(WindowsMotionController, _super);
  1350. function WindowsMotionController(vrGamepad) {
  1351. var _this = _super.call(this, vrGamepad) || this;
  1352. _this._mapping = {
  1353. // Semantic button names
  1354. buttons: ['thumbstick', 'trigger', 'grip', 'menu', 'trackpad'],
  1355. // A mapping of the button name to glTF model node name
  1356. // that should be transformed by button value.
  1357. buttonMeshNames: {
  1358. 'trigger': 'SELECT',
  1359. 'menu': 'MENU',
  1360. 'grip': 'GRASP',
  1361. 'thumbstick': 'THUMBSTICK_PRESS',
  1362. 'trackpad': 'TOUCHPAD_PRESS'
  1363. },
  1364. // This mapping is used to translate from the Motion Controller to Babylon semantics
  1365. buttonObservableNames: {
  1366. 'trigger': 'onTriggerStateChangedObservable',
  1367. 'menu': 'onSecondaryButtonStateChangedObservable',
  1368. 'grip': 'onMainButtonStateChangedObservable',
  1369. 'thumbstick': 'onPadStateChangedObservable',
  1370. 'trackpad': 'onTrackpadChangedObservable'
  1371. },
  1372. // A mapping of the axis name to glTF model node name
  1373. // that should be transformed by axis value.
  1374. // This array mirrors the browserGamepad.axes array, such that
  1375. // the mesh corresponding to axis 0 is in this array index 0.
  1376. axisMeshNames: [
  1377. 'THUMBSTICK_X',
  1378. 'THUMBSTICK_Y',
  1379. 'TOUCHPAD_TOUCH_X',
  1380. 'TOUCHPAD_TOUCH_Y'
  1381. ],
  1382. pointingPoseMeshName: 'POINTING_POSE'
  1383. };
  1384. _this.onTrackpadChangedObservable = new BABYLON.Observable();
  1385. _this.onTrackpadValuesChangedObservable = new BABYLON.Observable();
  1386. _this.trackpad = { x: 0, y: 0 };
  1387. _this.controllerType = BABYLON.PoseEnabledControllerType.WINDOWS;
  1388. _this._loadedMeshInfo = null;
  1389. return _this;
  1390. }
  1391. Object.defineProperty(WindowsMotionController.prototype, "onTriggerButtonStateChangedObservable", {
  1392. get: function () {
  1393. return this.onTriggerStateChangedObservable;
  1394. },
  1395. enumerable: true,
  1396. configurable: true
  1397. });
  1398. Object.defineProperty(WindowsMotionController.prototype, "onMenuButtonStateChangedObservable", {
  1399. get: function () {
  1400. return this.onSecondaryButtonStateChangedObservable;
  1401. },
  1402. enumerable: true,
  1403. configurable: true
  1404. });
  1405. Object.defineProperty(WindowsMotionController.prototype, "onGripButtonStateChangedObservable", {
  1406. get: function () {
  1407. return this.onMainButtonStateChangedObservable;
  1408. },
  1409. enumerable: true,
  1410. configurable: true
  1411. });
  1412. Object.defineProperty(WindowsMotionController.prototype, "onThumbstickButtonStateChangedObservable", {
  1413. get: function () {
  1414. return this.onPadStateChangedObservable;
  1415. },
  1416. enumerable: true,
  1417. configurable: true
  1418. });
  1419. Object.defineProperty(WindowsMotionController.prototype, "onTouchpadButtonStateChangedObservable", {
  1420. get: function () {
  1421. return this.onTrackpadChangedObservable;
  1422. },
  1423. enumerable: true,
  1424. configurable: true
  1425. });
  1426. Object.defineProperty(WindowsMotionController.prototype, "onTouchpadValuesChangedObservable", {
  1427. get: function () {
  1428. return this.onTrackpadValuesChangedObservable;
  1429. },
  1430. enumerable: true,
  1431. configurable: true
  1432. });
  1433. /**
  1434. * Called once per frame by the engine.
  1435. */
  1436. WindowsMotionController.prototype.update = function () {
  1437. _super.prototype.update.call(this);
  1438. // Only need to animate axes if there is a loaded mesh
  1439. if (this._loadedMeshInfo) {
  1440. if (this.browserGamepad.axes) {
  1441. if (this.browserGamepad.axes[2] != this.trackpad.x || this.browserGamepad.axes[3] != this.trackpad.y) {
  1442. this.trackpad.x = this.browserGamepad["axes"][2];
  1443. this.trackpad.y = this.browserGamepad["axes"][3];
  1444. this.onTrackpadValuesChangedObservable.notifyObservers(this.trackpad);
  1445. }
  1446. for (var axis = 0; axis < this._mapping.axisMeshNames.length; axis++) {
  1447. this.lerpAxisTransform(axis, this.browserGamepad.axes[axis]);
  1448. }
  1449. }
  1450. }
  1451. };
  1452. /**
  1453. * Called once for each button that changed state since the last frame
  1454. * @param buttonIdx Which button index changed
  1455. * @param state New state of the button
  1456. * @param changes Which properties on the state changed since last frame
  1457. */
  1458. WindowsMotionController.prototype.handleButtonChange = function (buttonIdx, state, changes) {
  1459. var buttonName = this._mapping.buttons[buttonIdx];
  1460. if (!buttonName) {
  1461. return;
  1462. }
  1463. // Only emit events for buttons that we know how to map from index to name
  1464. var observable = this[(this._mapping.buttonObservableNames)[buttonName]];
  1465. if (observable) {
  1466. observable.notifyObservers(state);
  1467. }
  1468. this.lerpButtonTransform(buttonName, state.value);
  1469. };
  1470. WindowsMotionController.prototype.lerpButtonTransform = function (buttonName, buttonValue) {
  1471. // If there is no loaded mesh, there is nothing to transform.
  1472. if (!this._loadedMeshInfo) {
  1473. return;
  1474. }
  1475. var meshInfo = this._loadedMeshInfo.buttonMeshes[buttonName];
  1476. if (!meshInfo.unpressed.rotationQuaternion || !meshInfo.pressed.rotationQuaternion || !meshInfo.value.rotationQuaternion) {
  1477. return;
  1478. }
  1479. BABYLON.Quaternion.SlerpToRef(meshInfo.unpressed.rotationQuaternion, meshInfo.pressed.rotationQuaternion, buttonValue, meshInfo.value.rotationQuaternion);
  1480. BABYLON.Vector3.LerpToRef(meshInfo.unpressed.position, meshInfo.pressed.position, buttonValue, meshInfo.value.position);
  1481. };
  1482. WindowsMotionController.prototype.lerpAxisTransform = function (axis, axisValue) {
  1483. if (!this._loadedMeshInfo) {
  1484. return;
  1485. }
  1486. var meshInfo = this._loadedMeshInfo.axisMeshes[axis];
  1487. if (!meshInfo) {
  1488. return;
  1489. }
  1490. if (!meshInfo.min.rotationQuaternion || !meshInfo.max.rotationQuaternion || !meshInfo.value.rotationQuaternion) {
  1491. return;
  1492. }
  1493. // Convert from gamepad value range (-1 to +1) to lerp range (0 to 1)
  1494. var lerpValue = axisValue * 0.5 + 0.5;
  1495. BABYLON.Quaternion.SlerpToRef(meshInfo.min.rotationQuaternion, meshInfo.max.rotationQuaternion, lerpValue, meshInfo.value.rotationQuaternion);
  1496. BABYLON.Vector3.LerpToRef(meshInfo.min.position, meshInfo.max.position, lerpValue, meshInfo.value.position);
  1497. };
  1498. /**
  1499. * Implements abstract method on WebVRController class, loading controller meshes and calling this.attachToMesh if successful.
  1500. * @param scene scene in which to add meshes
  1501. * @param meshLoaded optional callback function that will be called if the mesh loads successfully.
  1502. */
  1503. WindowsMotionController.prototype.initControllerMesh = function (scene, meshLoaded, forceDefault) {
  1504. var _this = this;
  1505. if (forceDefault === void 0) { forceDefault = false; }
  1506. var path;
  1507. var filename;
  1508. // Checking if GLB loader is present
  1509. if (BABYLON.SceneLoader.IsPluginForExtensionAvailable(".glb")) {
  1510. // Determine the device specific folder based on the ID suffix
  1511. var device = 'default';
  1512. if (this.id && !forceDefault) {
  1513. var match = this.id.match(WindowsMotionController.GAMEPAD_ID_PATTERN);
  1514. device = ((match && match[0]) || device);
  1515. }
  1516. // Hand
  1517. if (this.hand === 'left') {
  1518. filename = WindowsMotionController.MODEL_LEFT_FILENAME;
  1519. }
  1520. else {
  1521. filename = WindowsMotionController.MODEL_RIGHT_FILENAME;
  1522. }
  1523. path = WindowsMotionController.MODEL_BASE_URL + device + '/';
  1524. }
  1525. else {
  1526. BABYLON.Tools.Warn("You need to reference GLTF loader to load Windows Motion Controllers model. Falling back to generic models");
  1527. path = BABYLON.GenericController.MODEL_BASE_URL;
  1528. filename = BABYLON.GenericController.MODEL_FILENAME;
  1529. }
  1530. BABYLON.SceneLoader.ImportMesh("", path, filename, scene, function (meshes) {
  1531. // glTF files successfully loaded from the remote server, now process them to ensure they are in the right format.
  1532. _this._loadedMeshInfo = _this.processModel(scene, meshes);
  1533. if (!_this._loadedMeshInfo) {
  1534. return;
  1535. }
  1536. _this._defaultModel = _this._loadedMeshInfo.rootNode;
  1537. _this.attachToMesh(_this._defaultModel);
  1538. if (meshLoaded) {
  1539. meshLoaded(_this._defaultModel);
  1540. }
  1541. }, null, function (scene, message) {
  1542. BABYLON.Tools.Log(message);
  1543. BABYLON.Tools.Warn('Failed to retrieve controller model from the remote server: ' + path + filename);
  1544. if (!forceDefault) {
  1545. _this.initControllerMesh(scene, meshLoaded, true);
  1546. }
  1547. });
  1548. };
  1549. /**
  1550. * Takes a list of meshes (as loaded from the glTF file) and finds the root node, as well as nodes that
  1551. * can be transformed by button presses and axes values, based on this._mapping.
  1552. *
  1553. * @param scene scene in which the meshes exist
  1554. * @param meshes list of meshes that make up the controller model to process
  1555. * @return structured view of the given meshes, with mapping of buttons and axes to meshes that can be transformed.
  1556. */
  1557. WindowsMotionController.prototype.processModel = function (scene, meshes) {
  1558. var loadedMeshInfo = null;
  1559. // Create a new mesh to contain the glTF hierarchy
  1560. var parentMesh = new BABYLON.Mesh(this.id + " " + this.hand, scene);
  1561. // Find the root node in the loaded glTF scene, and attach it as a child of 'parentMesh'
  1562. var childMesh = null;
  1563. for (var i = 0; i < meshes.length; i++) {
  1564. var mesh = meshes[i];
  1565. if (!mesh.parent) {
  1566. // Exclude controller meshes from picking results
  1567. mesh.isPickable = false;
  1568. // Handle root node, attach to the new parentMesh
  1569. childMesh = mesh;
  1570. break;
  1571. }
  1572. }
  1573. if (childMesh) {
  1574. childMesh.setParent(parentMesh);
  1575. // Create our mesh info. Note that this method will always return non-null.
  1576. loadedMeshInfo = this.createMeshInfo(parentMesh);
  1577. }
  1578. else {
  1579. BABYLON.Tools.Warn('Could not find root node in model file.');
  1580. }
  1581. return loadedMeshInfo;
  1582. };
  1583. WindowsMotionController.prototype.createMeshInfo = function (rootNode) {
  1584. var loadedMeshInfo = new LoadedMeshInfo();
  1585. var i;
  1586. loadedMeshInfo.rootNode = rootNode;
  1587. // Reset the caches
  1588. loadedMeshInfo.buttonMeshes = {};
  1589. loadedMeshInfo.axisMeshes = {};
  1590. // Button Meshes
  1591. for (i = 0; i < this._mapping.buttons.length; i++) {
  1592. var buttonMeshName = this._mapping.buttonMeshNames[this._mapping.buttons[i]];
  1593. if (!buttonMeshName) {
  1594. BABYLON.Tools.Log('Skipping unknown button at index: ' + i + ' with mapped name: ' + this._mapping.buttons[i]);
  1595. continue;
  1596. }
  1597. var buttonMesh = getChildByName(rootNode, buttonMeshName);
  1598. if (!buttonMesh) {
  1599. BABYLON.Tools.Warn('Missing button mesh with name: ' + buttonMeshName);
  1600. continue;
  1601. }
  1602. var buttonMeshInfo = {
  1603. index: i,
  1604. value: getImmediateChildByName(buttonMesh, 'VALUE'),
  1605. pressed: getImmediateChildByName(buttonMesh, 'PRESSED'),
  1606. unpressed: getImmediateChildByName(buttonMesh, 'UNPRESSED')
  1607. };
  1608. if (buttonMeshInfo.value && buttonMeshInfo.pressed && buttonMeshInfo.unpressed) {
  1609. loadedMeshInfo.buttonMeshes[this._mapping.buttons[i]] = buttonMeshInfo;
  1610. }
  1611. else {
  1612. // If we didn't find the mesh, it simply means this button won't have transforms applied as mapped button value changes.
  1613. BABYLON.Tools.Warn('Missing button submesh under mesh with name: ' + buttonMeshName +
  1614. '(VALUE: ' + !!buttonMeshInfo.value +
  1615. ', PRESSED: ' + !!buttonMeshInfo.pressed +
  1616. ', UNPRESSED:' + !!buttonMeshInfo.unpressed +
  1617. ')');
  1618. }
  1619. }
  1620. // Axis Meshes
  1621. for (i = 0; i < this._mapping.axisMeshNames.length; i++) {
  1622. var axisMeshName = this._mapping.axisMeshNames[i];
  1623. if (!axisMeshName) {
  1624. BABYLON.Tools.Log('Skipping unknown axis at index: ' + i);
  1625. continue;
  1626. }
  1627. var axisMesh = getChildByName(rootNode, axisMeshName);
  1628. if (!axisMesh) {
  1629. BABYLON.Tools.Warn('Missing axis mesh with name: ' + axisMeshName);
  1630. continue;
  1631. }
  1632. var axisMeshInfo = {
  1633. index: i,
  1634. value: getImmediateChildByName(axisMesh, 'VALUE'),
  1635. min: getImmediateChildByName(axisMesh, 'MIN'),
  1636. max: getImmediateChildByName(axisMesh, 'MAX')
  1637. };
  1638. if (axisMeshInfo.value && axisMeshInfo.min && axisMeshInfo.max) {
  1639. loadedMeshInfo.axisMeshes[i] = axisMeshInfo;
  1640. }
  1641. else {
  1642. // If we didn't find the mesh, it simply means thit axis won't have transforms applied as mapped axis values change.
  1643. BABYLON.Tools.Warn('Missing axis submesh under mesh with name: ' + axisMeshName +
  1644. '(VALUE: ' + !!axisMeshInfo.value +
  1645. ', MIN: ' + !!axisMeshInfo.min +
  1646. ', MAX:' + !!axisMeshInfo.max +
  1647. ')');
  1648. }
  1649. }
  1650. // Pointing Ray
  1651. loadedMeshInfo.pointingPoseNode = getChildByName(rootNode, this._mapping.pointingPoseMeshName);
  1652. if (!loadedMeshInfo.pointingPoseNode) {
  1653. BABYLON.Tools.Warn('Missing pointing pose mesh with name: ' + this._mapping.pointingPoseMeshName);
  1654. }
  1655. return loadedMeshInfo;
  1656. // Look through all children recursively. This will return null if no mesh exists with the given name.
  1657. function getChildByName(node, name) {
  1658. return node.getChildMeshes(false, function (n) { return n.name === name; })[0];
  1659. }
  1660. // Look through only immediate children. This will return null if no mesh exists with the given name.
  1661. function getImmediateChildByName(node, name) {
  1662. return node.getChildMeshes(true, function (n) { return n.name == name; })[0];
  1663. }
  1664. };
  1665. WindowsMotionController.prototype.getForwardRay = function (length) {
  1666. if (length === void 0) { length = 100; }
  1667. if (!(this._loadedMeshInfo && this._loadedMeshInfo.pointingPoseNode)) {
  1668. return _super.prototype.getForwardRay.call(this, length);
  1669. }
  1670. var m = this._loadedMeshInfo.pointingPoseNode.getWorldMatrix();
  1671. var origin = m.getTranslation();
  1672. var forward = new BABYLON.Vector3(0, 0, -1);
  1673. var forwardWorld = BABYLON.Vector3.TransformNormal(forward, m);
  1674. var direction = BABYLON.Vector3.Normalize(forwardWorld);
  1675. return new BABYLON.Ray(origin, direction, length);
  1676. };
  1677. WindowsMotionController.prototype.dispose = function () {
  1678. _super.prototype.dispose.call(this);
  1679. this.onTrackpadChangedObservable.clear();
  1680. };
  1681. WindowsMotionController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/microsoft/';
  1682. WindowsMotionController.MODEL_LEFT_FILENAME = 'left.glb';
  1683. WindowsMotionController.MODEL_RIGHT_FILENAME = 'right.glb';
  1684. WindowsMotionController.GAMEPAD_ID_PREFIX = 'Spatial Controller (Spatial Interaction Source) ';
  1685. WindowsMotionController.GAMEPAD_ID_PATTERN = /([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/;
  1686. return WindowsMotionController;
  1687. }(BABYLON.WebVRController));
  1688. BABYLON.WindowsMotionController = WindowsMotionController;
  1689. })(BABYLON || (BABYLON = {}));
  1690. //# sourceMappingURL=babylon.windowsMotionController.js.map
  1691. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1692. 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";
  1693. 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";
  1694. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1695. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1696. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1697. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1698. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1699. 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";
  1700. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1701. 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";
  1702. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1703. 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";
  1704. 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";
  1705. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1706. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1707. 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";
  1708. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1709. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1710. 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}";
  1711. 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";
  1712. 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";
  1713. 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";
  1714. 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";
  1715. 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";
  1716. 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};";
  1717. 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";
  1718. 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";
  1719. 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}";
  1720. 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";
  1721. 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}";
  1722. 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";
  1723. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1724. 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";
  1725. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1726. 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";
  1727. 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";
  1728. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1729. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1730. (function() {
  1731. var EXPORTS = {};EXPORTS['FreeCameraGamepadInput'] = BABYLON['FreeCameraGamepadInput'];EXPORTS['ArcRotateCameraGamepadInput'] = BABYLON['ArcRotateCameraGamepadInput'];EXPORTS['GamepadManager'] = BABYLON['GamepadManager'];EXPORTS['StickValues'] = BABYLON['StickValues'];EXPORTS['Gamepad'] = BABYLON['Gamepad'];EXPORTS['GenericPad'] = BABYLON['GenericPad'];EXPORTS['Xbox360Button'] = BABYLON['Xbox360Button'];EXPORTS['Xbox360Dpad'] = BABYLON['Xbox360Dpad'];EXPORTS['Xbox360Pad'] = BABYLON['Xbox360Pad'];EXPORTS['PoseEnabledControllerType'] = BABYLON['PoseEnabledControllerType'];EXPORTS['PoseEnabledControllerHelper'] = BABYLON['PoseEnabledControllerHelper'];EXPORTS['PoseEnabledController'] = BABYLON['PoseEnabledController'];EXPORTS['WebVRController'] = BABYLON['WebVRController'];EXPORTS['OculusTouchController'] = BABYLON['OculusTouchController'];EXPORTS['ViveController'] = BABYLON['ViveController'];EXPORTS['GenericController'] = BABYLON['GenericController'];EXPORTS['WindowsMotionController'] = BABYLON['WindowsMotionController'];
  1732. globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
  1733. module.exports = EXPORTS;
  1734. })();
  1735. }