es6.js 126 KB

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