index.js 170 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. if(typeof require !== 'undefined'){
  12. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  13. var BABYLON = globalObject["BABYLON"] || {};
  14. var BABYLON0 = require('babylonjs/core');
  15. if(BABYLON !== BABYLON0) __extends(BABYLON, BABYLON0);
  16. var BABYLON;
  17. (function (BABYLON) {
  18. var VRDistortionCorrectionPostProcess = /** @class */ (function (_super) {
  19. __extends(VRDistortionCorrectionPostProcess, _super);
  20. function VRDistortionCorrectionPostProcess(name, camera, isRightEye, vrMetrics) {
  21. var _this = _super.call(this, name, "vrDistortionCorrection", [
  22. 'LensCenter',
  23. 'Scale',
  24. 'ScaleIn',
  25. 'HmdWarpParam'
  26. ], null, vrMetrics.postProcessScaleFactor, camera, BABYLON.Texture.BILINEAR_SAMPLINGMODE) || this;
  27. _this._isRightEye = isRightEye;
  28. _this._distortionFactors = vrMetrics.distortionK;
  29. _this._postProcessScaleFactor = vrMetrics.postProcessScaleFactor;
  30. _this._lensCenterOffset = vrMetrics.lensCenterOffset;
  31. _this.adaptScaleToCurrentViewport = true;
  32. _this.onSizeChangedObservable.add(function () {
  33. _this.aspectRatio = _this.width * .5 / _this.height;
  34. _this._scaleIn = new BABYLON.Vector2(2, 2 / _this.aspectRatio);
  35. _this._scaleFactor = new BABYLON.Vector2(.5 * (1 / _this._postProcessScaleFactor), .5 * (1 / _this._postProcessScaleFactor) * _this.aspectRatio);
  36. _this._lensCenter = new BABYLON.Vector2(_this._isRightEye ? 0.5 - _this._lensCenterOffset * 0.5 : 0.5 + _this._lensCenterOffset * 0.5, 0.5);
  37. });
  38. _this.onApplyObservable.add(function (effect) {
  39. effect.setFloat2("LensCenter", _this._lensCenter.x, _this._lensCenter.y);
  40. effect.setFloat2("Scale", _this._scaleFactor.x, _this._scaleFactor.y);
  41. effect.setFloat2("ScaleIn", _this._scaleIn.x, _this._scaleIn.y);
  42. effect.setFloat4("HmdWarpParam", _this._distortionFactors[0], _this._distortionFactors[1], _this._distortionFactors[2], _this._distortionFactors[3]);
  43. });
  44. return _this;
  45. }
  46. return VRDistortionCorrectionPostProcess;
  47. }(BABYLON.PostProcess));
  48. BABYLON.VRDistortionCorrectionPostProcess = VRDistortionCorrectionPostProcess;
  49. })(BABYLON || (BABYLON = {}));
  50. //# sourceMappingURL=babylon.vrDistortionCorrectionPostProcess.js.map
  51. var BABYLON;
  52. (function (BABYLON) {
  53. var AnaglyphPostProcess = /** @class */ (function (_super) {
  54. __extends(AnaglyphPostProcess, _super);
  55. function AnaglyphPostProcess(name, options, rigCameras, samplingMode, engine, reusable) {
  56. var _this = _super.call(this, name, "anaglyph", null, ["leftSampler"], options, rigCameras[1], samplingMode, engine, reusable) || this;
  57. _this._passedProcess = rigCameras[0]._rigPostProcess;
  58. _this.onApplyObservable.add(function (effect) {
  59. effect.setTextureFromPostProcess("leftSampler", _this._passedProcess);
  60. });
  61. return _this;
  62. }
  63. return AnaglyphPostProcess;
  64. }(BABYLON.PostProcess));
  65. BABYLON.AnaglyphPostProcess = AnaglyphPostProcess;
  66. })(BABYLON || (BABYLON = {}));
  67. //# sourceMappingURL=babylon.anaglyphPostProcess.js.map
  68. var BABYLON;
  69. (function (BABYLON) {
  70. var StereoscopicInterlacePostProcess = /** @class */ (function (_super) {
  71. __extends(StereoscopicInterlacePostProcess, _super);
  72. function StereoscopicInterlacePostProcess(name, rigCameras, isStereoscopicHoriz, samplingMode, engine, reusable) {
  73. var _this = _super.call(this, name, "stereoscopicInterlace", ['stepSize'], ['camASampler'], 1, rigCameras[1], samplingMode, engine, reusable, isStereoscopicHoriz ? "#define IS_STEREOSCOPIC_HORIZ 1" : undefined) || this;
  74. _this._passedProcess = rigCameras[0]._rigPostProcess;
  75. _this._stepSize = new BABYLON.Vector2(1 / _this.width, 1 / _this.height);
  76. _this.onSizeChangedObservable.add(function () {
  77. _this._stepSize = new BABYLON.Vector2(1 / _this.width, 1 / _this.height);
  78. });
  79. _this.onApplyObservable.add(function (effect) {
  80. effect.setTextureFromPostProcess("camASampler", _this._passedProcess);
  81. effect.setFloat2("stepSize", _this._stepSize.x, _this._stepSize.y);
  82. });
  83. return _this;
  84. }
  85. return StereoscopicInterlacePostProcess;
  86. }(BABYLON.PostProcess));
  87. BABYLON.StereoscopicInterlacePostProcess = StereoscopicInterlacePostProcess;
  88. })(BABYLON || (BABYLON = {}));
  89. //# sourceMappingURL=babylon.stereoscopicInterlacePostProcess.js.map
  90. var BABYLON;
  91. (function (BABYLON) {
  92. var FreeCameraDeviceOrientationInput = /** @class */ (function () {
  93. function FreeCameraDeviceOrientationInput() {
  94. var _this = this;
  95. this._screenOrientationAngle = 0;
  96. this._screenQuaternion = new BABYLON.Quaternion();
  97. this._alpha = 0;
  98. this._beta = 0;
  99. this._gamma = 0;
  100. this._orientationChanged = function () {
  101. _this._screenOrientationAngle = (window.orientation !== undefined ? +window.orientation : (window.screen.orientation && window.screen.orientation['angle'] ? window.screen.orientation.angle : 0));
  102. _this._screenOrientationAngle = -BABYLON.Tools.ToRadians(_this._screenOrientationAngle / 2);
  103. _this._screenQuaternion.copyFromFloats(0, Math.sin(_this._screenOrientationAngle), 0, Math.cos(_this._screenOrientationAngle));
  104. };
  105. this._deviceOrientation = function (evt) {
  106. _this._alpha = evt.alpha !== null ? evt.alpha : 0;
  107. _this._beta = evt.beta !== null ? evt.beta : 0;
  108. _this._gamma = evt.gamma !== null ? evt.gamma : 0;
  109. };
  110. this._constantTranform = new BABYLON.Quaternion(-Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));
  111. this._orientationChanged();
  112. }
  113. Object.defineProperty(FreeCameraDeviceOrientationInput.prototype, "camera", {
  114. get: function () {
  115. return this._camera;
  116. },
  117. set: function (camera) {
  118. this._camera = camera;
  119. if (this._camera != null && !this._camera.rotationQuaternion) {
  120. this._camera.rotationQuaternion = new BABYLON.Quaternion();
  121. }
  122. },
  123. enumerable: true,
  124. configurable: true
  125. });
  126. FreeCameraDeviceOrientationInput.prototype.attachControl = function (element, noPreventDefault) {
  127. window.addEventListener("orientationchange", this._orientationChanged);
  128. window.addEventListener("deviceorientation", this._deviceOrientation);
  129. //In certain cases, the attach control is called AFTER orientation was changed,
  130. //So this is needed.
  131. this._orientationChanged();
  132. };
  133. FreeCameraDeviceOrientationInput.prototype.detachControl = function (element) {
  134. window.removeEventListener("orientationchange", this._orientationChanged);
  135. window.removeEventListener("deviceorientation", this._deviceOrientation);
  136. };
  137. FreeCameraDeviceOrientationInput.prototype.checkInputs = function () {
  138. //if no device orientation provided, don't update the rotation.
  139. //Only testing against alpha under the assumption thatnorientation will never be so exact when set.
  140. if (!this._alpha)
  141. return;
  142. BABYLON.Quaternion.RotationYawPitchRollToRef(BABYLON.Tools.ToRadians(this._alpha), BABYLON.Tools.ToRadians(this._beta), -BABYLON.Tools.ToRadians(this._gamma), this.camera.rotationQuaternion);
  143. this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion);
  144. this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform);
  145. //Mirror on XY Plane
  146. this._camera.rotationQuaternion.z *= -1;
  147. this._camera.rotationQuaternion.w *= -1;
  148. };
  149. FreeCameraDeviceOrientationInput.prototype.getClassName = function () {
  150. return "FreeCameraDeviceOrientationInput";
  151. };
  152. FreeCameraDeviceOrientationInput.prototype.getSimpleName = function () {
  153. return "deviceOrientation";
  154. };
  155. return FreeCameraDeviceOrientationInput;
  156. }());
  157. BABYLON.FreeCameraDeviceOrientationInput = FreeCameraDeviceOrientationInput;
  158. BABYLON.CameraInputTypes["FreeCameraDeviceOrientationInput"] = FreeCameraDeviceOrientationInput;
  159. })(BABYLON || (BABYLON = {}));
  160. //# sourceMappingURL=babylon.freeCameraDeviceOrientationInput.js.map
  161. var BABYLON;
  162. (function (BABYLON) {
  163. var ArcRotateCameraVRDeviceOrientationInput = /** @class */ (function () {
  164. function ArcRotateCameraVRDeviceOrientationInput() {
  165. this.alphaCorrection = 1;
  166. this.betaCorrection = 1;
  167. this.gammaCorrection = 1;
  168. this._alpha = 0;
  169. this._gamma = 0;
  170. this._dirty = false;
  171. this._deviceOrientationHandler = this._onOrientationEvent.bind(this);
  172. }
  173. ArcRotateCameraVRDeviceOrientationInput.prototype.attachControl = function (element, noPreventDefault) {
  174. this.camera.attachControl(element, noPreventDefault);
  175. window.addEventListener("deviceorientation", this._deviceOrientationHandler);
  176. };
  177. ArcRotateCameraVRDeviceOrientationInput.prototype._onOrientationEvent = function (evt) {
  178. if (evt.alpha !== null) {
  179. this._alpha = +evt.alpha | 0;
  180. }
  181. if (evt.gamma !== null) {
  182. this._gamma = +evt.gamma | 0;
  183. }
  184. this._dirty = true;
  185. };
  186. ArcRotateCameraVRDeviceOrientationInput.prototype.checkInputs = function () {
  187. if (this._dirty) {
  188. this._dirty = false;
  189. if (this._gamma < 0) {
  190. this._gamma = 180 + this._gamma;
  191. }
  192. this.camera.alpha = (-this._alpha / 180.0 * Math.PI) % Math.PI * 2;
  193. this.camera.beta = (this._gamma / 180.0 * Math.PI);
  194. }
  195. };
  196. ArcRotateCameraVRDeviceOrientationInput.prototype.detachControl = function (element) {
  197. window.removeEventListener("deviceorientation", this._deviceOrientationHandler);
  198. };
  199. ArcRotateCameraVRDeviceOrientationInput.prototype.getClassName = function () {
  200. return "ArcRotateCameraVRDeviceOrientationInput";
  201. };
  202. ArcRotateCameraVRDeviceOrientationInput.prototype.getSimpleName = function () {
  203. return "VRDeviceOrientation";
  204. };
  205. return ArcRotateCameraVRDeviceOrientationInput;
  206. }());
  207. BABYLON.ArcRotateCameraVRDeviceOrientationInput = ArcRotateCameraVRDeviceOrientationInput;
  208. BABYLON.CameraInputTypes["ArcRotateCameraVRDeviceOrientationInput"] = ArcRotateCameraVRDeviceOrientationInput;
  209. })(BABYLON || (BABYLON = {}));
  210. //# sourceMappingURL=babylon.arcRotateCameraVRDeviceOrientationInput.js.map
  211. 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}";
  212. 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}";
  213. BABYLON.Effect.ShadersStore['anaglyphPixelShader'] = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D leftSampler;\nvoid main(void)\n{\nvec4 leftFrag=texture2D(leftSampler,vUV);\nleftFrag=vec4(1.0,leftFrag.g,leftFrag.b,1.0);\nvec4 rightFrag=texture2D(textureSampler,vUV);\nrightFrag=vec4(rightFrag.r,1.0,1.0,1.0);\ngl_FragColor=vec4(rightFrag.rgb*leftFrag.rgb,1.0);\n}";
  214. BABYLON.Effect.ShadersStore['stereoscopicInterlacePixelShader'] = "const vec3 TWO=vec3(2.0,2.0,2.0);\nvarying vec2 vUV;\nuniform sampler2D camASampler;\nuniform sampler2D textureSampler;\nuniform vec2 stepSize;\nvoid main(void)\n{\nbool useCamB;\nvec2 texCoord1;\nvec2 texCoord2;\nvec3 frag1;\nvec3 frag2;\n#ifdef IS_STEREOSCOPIC_HORIZ\nuseCamB=vUV.x>0.5;\ntexCoord1=vec2(useCamB ? (vUV.x-0.5)*2.0 : vUV.x*2.0,vUV.y);\ntexCoord2=vec2(texCoord1.x+stepSize.x,vUV.y);\n#else\nuseCamB=vUV.y>0.5;\ntexCoord1=vec2(vUV.x,useCamB ? (vUV.y-0.5)*2.0 : vUV.y*2.0);\ntexCoord2=vec2(vUV.x,texCoord1.y+stepSize.y);\n#endif\n\nif (useCamB){\nfrag1=texture2D(textureSampler,texCoord1).rgb;\nfrag2=texture2D(textureSampler,texCoord2).rgb;\n}else{\nfrag1=texture2D(camASampler ,texCoord1).rgb;\nfrag2=texture2D(camASampler ,texCoord2).rgb;\n}\ngl_FragColor=vec4((frag1+frag2)/TWO,1.0);\n}";
  215. BABYLON.Effect.ShadersStore['vrDistortionCorrectionPixelShader'] = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 LensCenter;\nuniform vec2 Scale;\nuniform vec2 ScaleIn;\nuniform vec4 HmdWarpParam;\nvec2 HmdWarp(vec2 in01) {\nvec2 theta=(in01-LensCenter)*ScaleIn; \nfloat rSq=theta.x*theta.x+theta.y*theta.y;\nvec2 rvector=theta*(HmdWarpParam.x+HmdWarpParam.y*rSq+HmdWarpParam.z*rSq*rSq+HmdWarpParam.w*rSq*rSq*rSq);\nreturn LensCenter+Scale*rvector;\n}\nvoid main(void)\n{\nvec2 tc=HmdWarp(vUV);\nif (tc.x <0.0 || tc.x>1.0 || tc.y<0.0 || tc.y>1.0)\ngl_FragColor=vec4(0.0,0.0,0.0,0.0);\nelse{\ngl_FragColor=texture2D(textureSampler,tc);\n}\n}";
  216. var BABYLON;
  217. (function (BABYLON) {
  218. var VRCameraMetrics = /** @class */ (function () {
  219. function VRCameraMetrics() {
  220. this.compensateDistortion = true;
  221. }
  222. Object.defineProperty(VRCameraMetrics.prototype, "aspectRatio", {
  223. get: function () {
  224. return this.hResolution / (2 * this.vResolution);
  225. },
  226. enumerable: true,
  227. configurable: true
  228. });
  229. Object.defineProperty(VRCameraMetrics.prototype, "aspectRatioFov", {
  230. get: function () {
  231. return (2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance)));
  232. },
  233. enumerable: true,
  234. configurable: true
  235. });
  236. Object.defineProperty(VRCameraMetrics.prototype, "leftHMatrix", {
  237. get: function () {
  238. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  239. var h = (4 * meters) / this.hScreenSize;
  240. return BABYLON.Matrix.Translation(h, 0, 0);
  241. },
  242. enumerable: true,
  243. configurable: true
  244. });
  245. Object.defineProperty(VRCameraMetrics.prototype, "rightHMatrix", {
  246. get: function () {
  247. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  248. var h = (4 * meters) / this.hScreenSize;
  249. return BABYLON.Matrix.Translation(-h, 0, 0);
  250. },
  251. enumerable: true,
  252. configurable: true
  253. });
  254. Object.defineProperty(VRCameraMetrics.prototype, "leftPreViewMatrix", {
  255. get: function () {
  256. return BABYLON.Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
  257. },
  258. enumerable: true,
  259. configurable: true
  260. });
  261. Object.defineProperty(VRCameraMetrics.prototype, "rightPreViewMatrix", {
  262. get: function () {
  263. return BABYLON.Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
  264. },
  265. enumerable: true,
  266. configurable: true
  267. });
  268. VRCameraMetrics.GetDefault = function () {
  269. var result = new VRCameraMetrics();
  270. result.hResolution = 1280;
  271. result.vResolution = 800;
  272. result.hScreenSize = 0.149759993;
  273. result.vScreenSize = 0.0935999975;
  274. result.vScreenCenter = 0.0467999987;
  275. result.eyeToScreenDistance = 0.0410000011;
  276. result.lensSeparationDistance = 0.0635000020;
  277. result.interpupillaryDistance = 0.0640000030;
  278. result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
  279. result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
  280. result.postProcessScaleFactor = 1.714605507808412;
  281. result.lensCenterOffset = 0.151976421;
  282. return result;
  283. };
  284. return VRCameraMetrics;
  285. }());
  286. BABYLON.VRCameraMetrics = VRCameraMetrics;
  287. })(BABYLON || (BABYLON = {}));
  288. //# sourceMappingURL=babylon.vrCameraMetrics.js.map
  289. var BABYLON;
  290. (function (BABYLON) {
  291. var WebVRFreeCamera = /** @class */ (function (_super) {
  292. __extends(WebVRFreeCamera, _super);
  293. function WebVRFreeCamera(name, position, scene, webVROptions) {
  294. if (webVROptions === void 0) { webVROptions = {}; }
  295. var _this = _super.call(this, name, position, scene) || this;
  296. _this.webVROptions = webVROptions;
  297. _this._vrDevice = null;
  298. _this.rawPose = null;
  299. _this._specsVersion = "1.1";
  300. _this._attached = false;
  301. _this._descendants = [];
  302. // Represents device position and rotation in room space. Should only be used to help calculate babylon space values
  303. _this._deviceRoomPosition = BABYLON.Vector3.Zero();
  304. _this._deviceRoomRotationQuaternion = BABYLON.Quaternion.Identity();
  305. _this._standingMatrix = null;
  306. // Represents device position and rotation in babylon space
  307. _this.devicePosition = BABYLON.Vector3.Zero();
  308. _this.deviceRotationQuaternion = BABYLON.Quaternion.Identity();
  309. _this.deviceScaleFactor = 1;
  310. _this._deviceToWorld = BABYLON.Matrix.Identity();
  311. _this._worldToDevice = BABYLON.Matrix.Identity();
  312. _this.controllers = [];
  313. _this.onControllersAttachedObservable = new BABYLON.Observable();
  314. _this.onControllerMeshLoadedObservable = new BABYLON.Observable();
  315. _this.rigParenting = true; // should the rig cameras be used as parent instead of this camera.
  316. _this._defaultHeight = 0;
  317. _this.deviceDistanceToRoomGround = function () {
  318. if (_this._standingMatrix) {
  319. // Add standing matrix offset to get real offset from ground in room
  320. _this._standingMatrix.getTranslationToRef(_this._workingVector);
  321. return _this._deviceRoomPosition.y + _this._workingVector.y;
  322. }
  323. else {
  324. return _this._defaultHeight;
  325. }
  326. };
  327. _this.useStandingMatrix = function (callback) {
  328. if (callback === void 0) { callback = function (bool) { }; }
  329. // Use standing matrix if availible
  330. if (!navigator || !navigator.getVRDisplays) {
  331. callback(false);
  332. }
  333. else {
  334. navigator.getVRDisplays().then(function (displays) {
  335. if (!displays || !displays[0] || !displays[0].stageParameters || !displays[0].stageParameters.sittingToStandingTransform) {
  336. callback(false);
  337. }
  338. else {
  339. _this._standingMatrix = new BABYLON.Matrix();
  340. BABYLON.Matrix.FromFloat32ArrayToRefScaled(displays[0].stageParameters.sittingToStandingTransform, 0, 1, _this._standingMatrix);
  341. if (!_this.getScene().useRightHandedSystem) {
  342. [2, 6, 8, 9, 14].forEach(function (num) {
  343. if (_this._standingMatrix) {
  344. _this._standingMatrix.m[num] *= -1;
  345. }
  346. });
  347. }
  348. callback(true);
  349. }
  350. });
  351. }
  352. };
  353. _this._workingVector = BABYLON.Vector3.Zero();
  354. _this._oneVector = BABYLON.Vector3.One();
  355. _this._workingMatrix = BABYLON.Matrix.Identity();
  356. _this._cache.position = BABYLON.Vector3.Zero();
  357. if (webVROptions.defaultHeight) {
  358. _this._defaultHeight = webVROptions.defaultHeight;
  359. _this.position.y = _this._defaultHeight;
  360. }
  361. _this.minZ = 0.1;
  362. //legacy support - the compensation boolean was removed.
  363. if (arguments.length === 5) {
  364. _this.webVROptions = arguments[4];
  365. }
  366. // default webVR options
  367. if (_this.webVROptions.trackPosition == undefined) {
  368. _this.webVROptions.trackPosition = true;
  369. }
  370. if (_this.webVROptions.controllerMeshes == undefined) {
  371. _this.webVROptions.controllerMeshes = true;
  372. }
  373. if (_this.webVROptions.defaultLightingOnControllers == undefined) {
  374. _this.webVROptions.defaultLightingOnControllers = true;
  375. }
  376. _this.rotationQuaternion = new BABYLON.Quaternion();
  377. if (_this.webVROptions && _this.webVROptions.positionScale) {
  378. _this.deviceScaleFactor = _this.webVROptions.positionScale;
  379. }
  380. //enable VR
  381. var engine = _this.getEngine();
  382. _this._onVREnabled = function (success) { if (success) {
  383. _this.initControllers();
  384. } };
  385. engine.onVRRequestPresentComplete.add(_this._onVREnabled);
  386. engine.initWebVR().add(function (event) {
  387. if (!event.vrDisplay || _this._vrDevice === event.vrDisplay) {
  388. return;
  389. }
  390. _this._vrDevice = event.vrDisplay;
  391. //reset the rig parameters.
  392. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_WEBVR, { parentCamera: _this, vrDisplay: _this._vrDevice, frameData: _this._frameData, specs: _this._specsVersion });
  393. if (_this._attached) {
  394. _this.getEngine().enableVR();
  395. }
  396. });
  397. if (typeof (VRFrameData) !== "undefined")
  398. _this._frameData = new VRFrameData();
  399. /**
  400. * The idea behind the following lines:
  401. * objects that have the camera as parent should actually have the rig cameras as a parent.
  402. * BUT, each of those cameras has a different view matrix, which means that if we set the parent to the first rig camera,
  403. * the second will not show it correctly.
  404. *
  405. * To solve this - each object that has the camera as parent will be added to a protected array.
  406. * When the rig camera renders, it will take this array and set all of those to be its children.
  407. * This way, the right camera will be used as a parent, and the mesh will be rendered correctly.
  408. * Amazing!
  409. */
  410. scene.onBeforeCameraRenderObservable.add(function (camera) {
  411. if (camera.parent === _this && _this.rigParenting) {
  412. _this._descendants = _this.getDescendants(true, function (n) {
  413. // don't take the cameras or the controllers!
  414. var isController = _this.controllers.some(function (controller) { return controller._mesh === n; });
  415. var isRigCamera = _this._rigCameras.indexOf(n) !== -1;
  416. return !isController && !isRigCamera;
  417. });
  418. _this._descendants.forEach(function (node) {
  419. node.parent = camera;
  420. });
  421. }
  422. });
  423. scene.onAfterCameraRenderObservable.add(function (camera) {
  424. if (camera.parent === _this && _this.rigParenting) {
  425. _this._descendants.forEach(function (node) {
  426. node.parent = _this;
  427. });
  428. }
  429. });
  430. return _this;
  431. }
  432. WebVRFreeCamera.prototype.dispose = function () {
  433. this.getEngine().onVRRequestPresentComplete.removeCallback(this._onVREnabled);
  434. _super.prototype.dispose.call(this);
  435. };
  436. WebVRFreeCamera.prototype.getControllerByName = function (name) {
  437. for (var _i = 0, _a = this.controllers; _i < _a.length; _i++) {
  438. var gp = _a[_i];
  439. if (gp.hand === name) {
  440. return gp;
  441. }
  442. }
  443. return null;
  444. };
  445. Object.defineProperty(WebVRFreeCamera.prototype, "leftController", {
  446. get: function () {
  447. if (!this._leftController) {
  448. this._leftController = this.getControllerByName("left");
  449. }
  450. return this._leftController;
  451. },
  452. enumerable: true,
  453. configurable: true
  454. });
  455. ;
  456. Object.defineProperty(WebVRFreeCamera.prototype, "rightController", {
  457. get: function () {
  458. if (!this._rightController) {
  459. this._rightController = this.getControllerByName("right");
  460. }
  461. return this._rightController;
  462. },
  463. enumerable: true,
  464. configurable: true
  465. });
  466. ;
  467. WebVRFreeCamera.prototype.getForwardRay = function (length) {
  468. if (length === void 0) { length = 100; }
  469. if (this.leftCamera) {
  470. // Use left eye to avoid computation to compute center on every call
  471. return _super.prototype.getForwardRay.call(this, length, this.leftCamera.getWorldMatrix(), this.leftCamera.globalPosition); // Need the actual rendered camera
  472. }
  473. else {
  474. return _super.prototype.getForwardRay.call(this, length);
  475. }
  476. };
  477. WebVRFreeCamera.prototype._checkInputs = function () {
  478. if (this._vrDevice && this._vrDevice.isPresenting) {
  479. this._vrDevice.getFrameData(this._frameData);
  480. this.updateFromDevice(this._frameData.pose);
  481. }
  482. _super.prototype._checkInputs.call(this);
  483. };
  484. WebVRFreeCamera.prototype.updateFromDevice = function (poseData) {
  485. if (poseData && poseData.orientation) {
  486. this.rawPose = poseData;
  487. this._deviceRoomRotationQuaternion.copyFromFloats(poseData.orientation[0], poseData.orientation[1], -poseData.orientation[2], -poseData.orientation[3]);
  488. if (this.getScene().useRightHandedSystem) {
  489. this._deviceRoomRotationQuaternion.z *= -1;
  490. this._deviceRoomRotationQuaternion.w *= -1;
  491. }
  492. if (this.webVROptions.trackPosition && this.rawPose.position) {
  493. this._deviceRoomPosition.copyFromFloats(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2]);
  494. if (this.getScene().useRightHandedSystem) {
  495. this._deviceRoomPosition.z *= -1;
  496. }
  497. }
  498. }
  499. };
  500. /**
  501. * WebVR's attach control will start broadcasting frames to the device.
  502. * Note that in certain browsers (chrome for example) this function must be called
  503. * within a user-interaction callback. Example:
  504. * <pre> scene.onPointerDown = function() { camera.attachControl(canvas); }</pre>
  505. *
  506. * @param {HTMLElement} element
  507. * @param {boolean} [noPreventDefault]
  508. *
  509. * @memberOf WebVRFreeCamera
  510. */
  511. WebVRFreeCamera.prototype.attachControl = function (element, noPreventDefault) {
  512. _super.prototype.attachControl.call(this, element, noPreventDefault);
  513. this._attached = true;
  514. noPreventDefault = BABYLON.Camera.ForceAttachControlToAlwaysPreventDefault ? false : noPreventDefault;
  515. if (this._vrDevice) {
  516. this.getEngine().enableVR();
  517. }
  518. };
  519. WebVRFreeCamera.prototype.detachControl = function (element) {
  520. this.getScene().gamepadManager.onGamepadConnectedObservable.remove(this._onGamepadConnectedObserver);
  521. this.getScene().gamepadManager.onGamepadDisconnectedObservable.remove(this._onGamepadDisconnectedObserver);
  522. _super.prototype.detachControl.call(this, element);
  523. this._attached = false;
  524. this.getEngine().disableVR();
  525. };
  526. WebVRFreeCamera.prototype.getClassName = function () {
  527. return "WebVRFreeCamera";
  528. };
  529. WebVRFreeCamera.prototype.resetToCurrentRotation = function () {
  530. //uses the vrDisplay's "resetPose()".
  531. //pitch and roll won't be affected.
  532. this._vrDevice.resetPose();
  533. };
  534. WebVRFreeCamera.prototype._updateRigCameras = function () {
  535. var camLeft = this._rigCameras[0];
  536. var camRight = this._rigCameras[1];
  537. camLeft.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);
  538. camRight.rotationQuaternion.copyFrom(this._deviceRoomRotationQuaternion);
  539. camLeft.position.copyFrom(this._deviceRoomPosition);
  540. camRight.position.copyFrom(this._deviceRoomPosition);
  541. };
  542. WebVRFreeCamera.prototype._updateCache = function (ignoreParentClass) {
  543. var _this = this;
  544. if (!this.rotationQuaternion.equals(this._cache.rotationQuaternion) || !this.position.equals(this._cache.position)) {
  545. // Update to ensure devicePosition is up to date with most recent _deviceRoomPosition
  546. if (!this.updateCacheCalled) {
  547. // make sure it is only called once per loop. this.update() might cause an infinite loop.
  548. this.updateCacheCalled = true;
  549. this.update();
  550. }
  551. // Set working vector to the device position in room space rotated by the new rotation
  552. this.rotationQuaternion.toRotationMatrix(this._workingMatrix);
  553. BABYLON.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._workingMatrix, this._workingVector);
  554. // Subtract this vector from the current device position in world to get the translation for the device world matrix
  555. this.devicePosition.subtractToRef(this._workingVector, this._workingVector);
  556. BABYLON.Matrix.ComposeToRef(this._oneVector, this.rotationQuaternion, this._workingVector, this._deviceToWorld);
  557. // Add translation from anchor position
  558. this._deviceToWorld.getTranslationToRef(this._workingVector);
  559. this._workingVector.addInPlace(this.position);
  560. this._workingVector.subtractInPlace(this._cache.position);
  561. this._deviceToWorld.setTranslation(this._workingVector);
  562. // Set an inverted matrix to be used when updating the camera
  563. this._deviceToWorld.invertToRef(this._worldToDevice);
  564. // Update the gamepad to ensure the mesh is updated on the same frame as camera
  565. this.controllers.forEach(function (controller) {
  566. controller._deviceToWorld = _this._deviceToWorld;
  567. controller.update();
  568. });
  569. }
  570. if (!ignoreParentClass) {
  571. _super.prototype._updateCache.call(this);
  572. }
  573. this.updateCacheCalled = false;
  574. };
  575. WebVRFreeCamera.prototype.update = function () {
  576. // Get current device position in babylon world
  577. BABYLON.Vector3.TransformCoordinatesToRef(this._deviceRoomPosition, this._deviceToWorld, this.devicePosition);
  578. // Get current device rotation in babylon world
  579. BABYLON.Matrix.FromQuaternionToRef(this._deviceRoomRotationQuaternion, this._workingMatrix);
  580. this._workingMatrix.multiplyToRef(this._deviceToWorld, this._workingMatrix);
  581. BABYLON.Quaternion.FromRotationMatrixToRef(this._workingMatrix, this.deviceRotationQuaternion);
  582. _super.prototype.update.call(this);
  583. };
  584. WebVRFreeCamera.prototype._getViewMatrix = function () {
  585. return BABYLON.Matrix.Identity();
  586. };
  587. /**
  588. * This function is called by the two RIG cameras.
  589. * 'this' is the left or right camera (and NOT (!!!) the WebVRFreeCamera instance)
  590. */
  591. WebVRFreeCamera.prototype._getWebVRViewMatrix = function () {
  592. var _this = this;
  593. //WebVR 1.1
  594. var viewArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftViewMatrix : this._cameraRigParams["frameData"].rightViewMatrix;
  595. BABYLON.Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);
  596. if (!this.getScene().useRightHandedSystem) {
  597. [2, 6, 8, 9, 14].forEach(function (num) {
  598. _this._webvrViewMatrix.m[num] *= -1;
  599. });
  600. }
  601. // update the camera rotation matrix
  602. this._webvrViewMatrix.getRotationMatrixToRef(this._cameraRotationMatrix);
  603. BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint, this._cameraRotationMatrix, this._transformedReferencePoint);
  604. // Computing target and final matrix
  605. this.position.addToRef(this._transformedReferencePoint, this._currentTarget);
  606. var parentCamera = this._cameraRigParams["parentCamera"];
  607. // should the view matrix be updated with scale and position offset?
  608. if (parentCamera.deviceScaleFactor !== 1) {
  609. this._webvrViewMatrix.invert();
  610. // scale the position, if set
  611. if (parentCamera.deviceScaleFactor) {
  612. this._webvrViewMatrix.m[12] *= parentCamera.deviceScaleFactor;
  613. this._webvrViewMatrix.m[13] *= parentCamera.deviceScaleFactor;
  614. this._webvrViewMatrix.m[14] *= parentCamera.deviceScaleFactor;
  615. }
  616. this._webvrViewMatrix.invert();
  617. }
  618. parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
  619. return this._webvrViewMatrix;
  620. };
  621. WebVRFreeCamera.prototype._getWebVRProjectionMatrix = function () {
  622. var _this = this;
  623. var parentCamera = this.parent;
  624. parentCamera._vrDevice.depthNear = parentCamera.minZ;
  625. parentCamera._vrDevice.depthFar = parentCamera.maxZ;
  626. var projectionArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftProjectionMatrix : this._cameraRigParams["frameData"].rightProjectionMatrix;
  627. BABYLON.Matrix.FromArrayToRef(projectionArray, 0, this._projectionMatrix);
  628. //babylon compatible matrix
  629. if (!this.getScene().useRightHandedSystem) {
  630. [8, 9, 10, 11].forEach(function (num) {
  631. _this._projectionMatrix.m[num] *= -1;
  632. });
  633. }
  634. return this._projectionMatrix;
  635. };
  636. WebVRFreeCamera.prototype.initControllers = function () {
  637. var _this = this;
  638. this.controllers = [];
  639. var manager = this.getScene().gamepadManager;
  640. this._onGamepadDisconnectedObserver = manager.onGamepadDisconnectedObservable.add(function (gamepad) {
  641. if (gamepad.type === BABYLON.Gamepad.POSE_ENABLED) {
  642. var webVrController = gamepad;
  643. if (webVrController.defaultModel) {
  644. webVrController.defaultModel.setEnabled(false);
  645. }
  646. if (webVrController.hand === "right") {
  647. _this._rightController = null;
  648. }
  649. if (webVrController.hand === "left") {
  650. _this._rightController = null;
  651. }
  652. var controllerIndex = _this.controllers.indexOf(webVrController);
  653. if (controllerIndex !== -1) {
  654. _this.controllers.splice(controllerIndex, 1);
  655. }
  656. }
  657. });
  658. this._onGamepadConnectedObserver = manager.onGamepadConnectedObservable.add(function (gamepad) {
  659. if (gamepad.type === BABYLON.Gamepad.POSE_ENABLED) {
  660. var webVrController_1 = gamepad;
  661. webVrController_1._deviceToWorld = _this._deviceToWorld;
  662. if (_this.webVROptions.controllerMeshes) {
  663. if (webVrController_1.defaultModel) {
  664. webVrController_1.defaultModel.setEnabled(true);
  665. }
  666. else {
  667. // Load the meshes
  668. webVrController_1.initControllerMesh(_this.getScene(), function (loadedMesh) {
  669. _this.onControllerMeshLoadedObservable.notifyObservers(webVrController_1);
  670. if (_this.webVROptions.defaultLightingOnControllers) {
  671. if (!_this._lightOnControllers) {
  672. _this._lightOnControllers = new BABYLON.HemisphericLight("vrControllersLight", new BABYLON.Vector3(0, 1, 0), _this.getScene());
  673. }
  674. var activateLightOnSubMeshes_1 = function (mesh, light) {
  675. var children = mesh.getChildren();
  676. if (children.length !== 0) {
  677. children.forEach(function (mesh) {
  678. light.includedOnlyMeshes.push(mesh);
  679. activateLightOnSubMeshes_1(mesh, light);
  680. });
  681. }
  682. };
  683. _this._lightOnControllers.includedOnlyMeshes.push(loadedMesh);
  684. activateLightOnSubMeshes_1(loadedMesh, _this._lightOnControllers);
  685. }
  686. });
  687. }
  688. }
  689. webVrController_1.attachToPoseControlledCamera(_this);
  690. // since this is async - sanity check. Is the controller already stored?
  691. if (_this.controllers.indexOf(webVrController_1) === -1) {
  692. //add to the controllers array
  693. _this.controllers.push(webVrController_1);
  694. // Forced to add some control code for Vive as it doesn't always fill properly the "hand" property
  695. // Sometimes, both controllers are set correctly (left and right), sometimes none, sometimes only one of them...
  696. // So we're overriding setting left & right manually to be sure
  697. var firstViveWandDetected = false;
  698. for (var i = 0; i < _this.controllers.length; i++) {
  699. if (_this.controllers[i].controllerType === BABYLON.PoseEnabledControllerType.VIVE) {
  700. if (!firstViveWandDetected) {
  701. firstViveWandDetected = true;
  702. _this.controllers[i].hand = "left";
  703. }
  704. else {
  705. _this.controllers[i].hand = "right";
  706. }
  707. }
  708. }
  709. //did we find enough controllers? Great! let the developer know.
  710. if (_this.controllers.length >= 2) {
  711. _this.onControllersAttachedObservable.notifyObservers(_this.controllers);
  712. }
  713. }
  714. }
  715. });
  716. };
  717. return WebVRFreeCamera;
  718. }(BABYLON.FreeCamera));
  719. BABYLON.WebVRFreeCamera = WebVRFreeCamera;
  720. })(BABYLON || (BABYLON = {}));
  721. //# sourceMappingURL=babylon.webVRCamera.js.map
  722. var BABYLON;
  723. (function (BABYLON) {
  724. // We're mainly based on the logic defined into the FreeCamera code
  725. var DeviceOrientationCamera = /** @class */ (function (_super) {
  726. __extends(DeviceOrientationCamera, _super);
  727. function DeviceOrientationCamera(name, position, scene) {
  728. var _this = _super.call(this, name, position, scene) || this;
  729. _this._quaternionCache = new BABYLON.Quaternion();
  730. _this.inputs.addDeviceOrientation();
  731. return _this;
  732. }
  733. DeviceOrientationCamera.prototype.getClassName = function () {
  734. return "DeviceOrientationCamera";
  735. };
  736. DeviceOrientationCamera.prototype._checkInputs = function () {
  737. _super.prototype._checkInputs.call(this);
  738. this._quaternionCache.copyFrom(this.rotationQuaternion);
  739. if (this._initialQuaternion) {
  740. this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
  741. }
  742. };
  743. DeviceOrientationCamera.prototype.resetToCurrentRotation = function (axis) {
  744. var _this = this;
  745. if (axis === void 0) { axis = BABYLON.Axis.Y; }
  746. //can only work if this camera has a rotation quaternion already.
  747. if (!this.rotationQuaternion)
  748. return;
  749. if (!this._initialQuaternion) {
  750. this._initialQuaternion = new BABYLON.Quaternion();
  751. }
  752. this._initialQuaternion.copyFrom(this._quaternionCache || this.rotationQuaternion);
  753. ['x', 'y', 'z'].forEach(function (axisName) {
  754. if (!axis[axisName]) {
  755. _this._initialQuaternion[axisName] = 0;
  756. }
  757. else {
  758. _this._initialQuaternion[axisName] *= -1;
  759. }
  760. });
  761. this._initialQuaternion.normalize();
  762. //force rotation update
  763. this._initialQuaternion.multiplyToRef(this.rotationQuaternion, this.rotationQuaternion);
  764. };
  765. return DeviceOrientationCamera;
  766. }(BABYLON.FreeCamera));
  767. BABYLON.DeviceOrientationCamera = DeviceOrientationCamera;
  768. })(BABYLON || (BABYLON = {}));
  769. //# sourceMappingURL=babylon.deviceOrientationCamera.js.map
  770. var BABYLON;
  771. (function (BABYLON) {
  772. var VRDeviceOrientationFreeCamera = /** @class */ (function (_super) {
  773. __extends(VRDeviceOrientationFreeCamera, _super);
  774. function VRDeviceOrientationFreeCamera(name, position, scene, compensateDistortion, vrCameraMetrics) {
  775. if (compensateDistortion === void 0) { compensateDistortion = true; }
  776. if (vrCameraMetrics === void 0) { vrCameraMetrics = BABYLON.VRCameraMetrics.GetDefault(); }
  777. var _this = _super.call(this, name, position, scene) || this;
  778. vrCameraMetrics.compensateDistortion = compensateDistortion;
  779. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
  780. return _this;
  781. }
  782. VRDeviceOrientationFreeCamera.prototype.getClassName = function () {
  783. return "VRDeviceOrientationFreeCamera";
  784. };
  785. return VRDeviceOrientationFreeCamera;
  786. }(BABYLON.DeviceOrientationCamera));
  787. BABYLON.VRDeviceOrientationFreeCamera = VRDeviceOrientationFreeCamera;
  788. var VRDeviceOrientationGamepadCamera = /** @class */ (function (_super) {
  789. __extends(VRDeviceOrientationGamepadCamera, _super);
  790. function VRDeviceOrientationGamepadCamera(name, position, scene, compensateDistortion, vrCameraMetrics) {
  791. if (compensateDistortion === void 0) { compensateDistortion = true; }
  792. if (vrCameraMetrics === void 0) { vrCameraMetrics = BABYLON.VRCameraMetrics.GetDefault(); }
  793. var _this = _super.call(this, name, position, scene, compensateDistortion, vrCameraMetrics) || this;
  794. _this.inputs.addGamepad();
  795. return _this;
  796. }
  797. VRDeviceOrientationGamepadCamera.prototype.getClassName = function () {
  798. return "VRDeviceOrientationGamepadCamera";
  799. };
  800. return VRDeviceOrientationGamepadCamera;
  801. }(VRDeviceOrientationFreeCamera));
  802. BABYLON.VRDeviceOrientationGamepadCamera = VRDeviceOrientationGamepadCamera;
  803. var VRDeviceOrientationArcRotateCamera = /** @class */ (function (_super) {
  804. __extends(VRDeviceOrientationArcRotateCamera, _super);
  805. function VRDeviceOrientationArcRotateCamera(name, alpha, beta, radius, target, scene, compensateDistortion, vrCameraMetrics) {
  806. if (compensateDistortion === void 0) { compensateDistortion = true; }
  807. if (vrCameraMetrics === void 0) { vrCameraMetrics = BABYLON.VRCameraMetrics.GetDefault(); }
  808. var _this = _super.call(this, name, alpha, beta, radius, target, scene) || this;
  809. vrCameraMetrics.compensateDistortion = compensateDistortion;
  810. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_VR, { vrCameraMetrics: vrCameraMetrics });
  811. _this.inputs.addVRDeviceOrientation();
  812. return _this;
  813. }
  814. VRDeviceOrientationArcRotateCamera.prototype.getClassName = function () {
  815. return "VRDeviceOrientationArcRotateCamera";
  816. };
  817. return VRDeviceOrientationArcRotateCamera;
  818. }(BABYLON.ArcRotateCamera));
  819. BABYLON.VRDeviceOrientationArcRotateCamera = VRDeviceOrientationArcRotateCamera;
  820. })(BABYLON || (BABYLON = {}));
  821. //# sourceMappingURL=babylon.vrDeviceOrientationCamera.js.map
  822. var BABYLON;
  823. (function (BABYLON) {
  824. var AnaglyphFreeCamera = /** @class */ (function (_super) {
  825. __extends(AnaglyphFreeCamera, _super);
  826. function AnaglyphFreeCamera(name, position, interaxialDistance, scene) {
  827. var _this = _super.call(this, name, position, scene) || this;
  828. _this.interaxialDistance = interaxialDistance;
  829. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH, { interaxialDistance: interaxialDistance });
  830. return _this;
  831. }
  832. AnaglyphFreeCamera.prototype.getClassName = function () {
  833. return "AnaglyphFreeCamera";
  834. };
  835. return AnaglyphFreeCamera;
  836. }(BABYLON.FreeCamera));
  837. BABYLON.AnaglyphFreeCamera = AnaglyphFreeCamera;
  838. var AnaglyphArcRotateCamera = /** @class */ (function (_super) {
  839. __extends(AnaglyphArcRotateCamera, _super);
  840. function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, interaxialDistance, scene) {
  841. var _this = _super.call(this, name, alpha, beta, radius, target, scene) || this;
  842. _this.interaxialDistance = interaxialDistance;
  843. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH, { interaxialDistance: interaxialDistance });
  844. return _this;
  845. }
  846. AnaglyphArcRotateCamera.prototype.getClassName = function () {
  847. return "AnaglyphArcRotateCamera";
  848. };
  849. return AnaglyphArcRotateCamera;
  850. }(BABYLON.ArcRotateCamera));
  851. BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
  852. var AnaglyphGamepadCamera = /** @class */ (function (_super) {
  853. __extends(AnaglyphGamepadCamera, _super);
  854. function AnaglyphGamepadCamera(name, position, interaxialDistance, scene) {
  855. var _this = _super.call(this, name, position, scene) || this;
  856. _this.interaxialDistance = interaxialDistance;
  857. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH, { interaxialDistance: interaxialDistance });
  858. return _this;
  859. }
  860. AnaglyphGamepadCamera.prototype.getClassName = function () {
  861. return "AnaglyphGamepadCamera";
  862. };
  863. return AnaglyphGamepadCamera;
  864. }(BABYLON.GamepadCamera));
  865. BABYLON.AnaglyphGamepadCamera = AnaglyphGamepadCamera;
  866. var AnaglyphUniversalCamera = /** @class */ (function (_super) {
  867. __extends(AnaglyphUniversalCamera, _super);
  868. function AnaglyphUniversalCamera(name, position, interaxialDistance, scene) {
  869. var _this = _super.call(this, name, position, scene) || this;
  870. _this.interaxialDistance = interaxialDistance;
  871. _this.setCameraRigMode(BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH, { interaxialDistance: interaxialDistance });
  872. return _this;
  873. }
  874. AnaglyphUniversalCamera.prototype.getClassName = function () {
  875. return "AnaglyphUniversalCamera";
  876. };
  877. return AnaglyphUniversalCamera;
  878. }(BABYLON.UniversalCamera));
  879. BABYLON.AnaglyphUniversalCamera = AnaglyphUniversalCamera;
  880. var StereoscopicFreeCamera = /** @class */ (function (_super) {
  881. __extends(StereoscopicFreeCamera, _super);
  882. function StereoscopicFreeCamera(name, position, interaxialDistance, isStereoscopicSideBySide, scene) {
  883. var _this = _super.call(this, name, position, scene) || this;
  884. _this.interaxialDistance = interaxialDistance;
  885. _this.isStereoscopicSideBySide = isStereoscopicSideBySide;
  886. _this.setCameraRigMode(isStereoscopicSideBySide ? BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL : BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER, { interaxialDistance: interaxialDistance });
  887. return _this;
  888. }
  889. StereoscopicFreeCamera.prototype.getClassName = function () {
  890. return "StereoscopicFreeCamera";
  891. };
  892. return StereoscopicFreeCamera;
  893. }(BABYLON.FreeCamera));
  894. BABYLON.StereoscopicFreeCamera = StereoscopicFreeCamera;
  895. var StereoscopicArcRotateCamera = /** @class */ (function (_super) {
  896. __extends(StereoscopicArcRotateCamera, _super);
  897. function StereoscopicArcRotateCamera(name, alpha, beta, radius, target, interaxialDistance, isStereoscopicSideBySide, scene) {
  898. var _this = _super.call(this, name, alpha, beta, radius, target, scene) || this;
  899. _this.interaxialDistance = interaxialDistance;
  900. _this.isStereoscopicSideBySide = isStereoscopicSideBySide;
  901. _this.setCameraRigMode(isStereoscopicSideBySide ? BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL : BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER, { interaxialDistance: interaxialDistance });
  902. return _this;
  903. }
  904. StereoscopicArcRotateCamera.prototype.getClassName = function () {
  905. return "StereoscopicArcRotateCamera";
  906. };
  907. return StereoscopicArcRotateCamera;
  908. }(BABYLON.ArcRotateCamera));
  909. BABYLON.StereoscopicArcRotateCamera = StereoscopicArcRotateCamera;
  910. var StereoscopicGamepadCamera = /** @class */ (function (_super) {
  911. __extends(StereoscopicGamepadCamera, _super);
  912. function StereoscopicGamepadCamera(name, position, interaxialDistance, isStereoscopicSideBySide, scene) {
  913. var _this = _super.call(this, name, position, scene) || this;
  914. _this.interaxialDistance = interaxialDistance;
  915. _this.isStereoscopicSideBySide = isStereoscopicSideBySide;
  916. _this.setCameraRigMode(isStereoscopicSideBySide ? BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL : BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER, { interaxialDistance: interaxialDistance });
  917. return _this;
  918. }
  919. StereoscopicGamepadCamera.prototype.getClassName = function () {
  920. return "StereoscopicGamepadCamera";
  921. };
  922. return StereoscopicGamepadCamera;
  923. }(BABYLON.GamepadCamera));
  924. BABYLON.StereoscopicGamepadCamera = StereoscopicGamepadCamera;
  925. var StereoscopicUniversalCamera = /** @class */ (function (_super) {
  926. __extends(StereoscopicUniversalCamera, _super);
  927. function StereoscopicUniversalCamera(name, position, interaxialDistance, isStereoscopicSideBySide, scene) {
  928. var _this = _super.call(this, name, position, scene) || this;
  929. _this.interaxialDistance = interaxialDistance;
  930. _this.isStereoscopicSideBySide = isStereoscopicSideBySide;
  931. _this.setCameraRigMode(isStereoscopicSideBySide ? BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL : BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER, { interaxialDistance: interaxialDistance });
  932. return _this;
  933. }
  934. StereoscopicUniversalCamera.prototype.getClassName = function () {
  935. return "StereoscopicUniversalCamera";
  936. };
  937. return StereoscopicUniversalCamera;
  938. }(BABYLON.UniversalCamera));
  939. BABYLON.StereoscopicUniversalCamera = StereoscopicUniversalCamera;
  940. })(BABYLON || (BABYLON = {}));
  941. //# sourceMappingURL=babylon.stereoscopicCameras.js.map
  942. var BABYLON;
  943. (function (BABYLON) {
  944. var VRExperienceHelper = /** @class */ (function () {
  945. function VRExperienceHelper(scene, webVROptions) {
  946. if (webVROptions === void 0) { webVROptions = {}; }
  947. var _this = this;
  948. this.webVROptions = webVROptions;
  949. // Can the system support WebVR, even if a headset isn't plugged in?
  950. this._webVRsupported = false;
  951. // If WebVR is supported, is a headset plugged in and are we ready to present?
  952. this._webVRready = false;
  953. // Are we waiting for the requestPresent callback to complete?
  954. this._webVRrequesting = false;
  955. // Are we presenting to the headset right now?
  956. this._webVRpresenting = false;
  957. // Are we presenting in the fullscreen fallback?
  958. this._fullscreenVRpresenting = false;
  959. /**
  960. * Observable raised when entering VR.
  961. */
  962. this.onEnteringVRObservable = new BABYLON.Observable();
  963. /**
  964. * Observable raised when exiting VR.
  965. */
  966. this.onExitingVRObservable = new BABYLON.Observable();
  967. /**
  968. * Observable raised when controller mesh is loaded.
  969. */
  970. this.onControllerMeshLoadedObservable = new BABYLON.Observable();
  971. this._useCustomVRButton = false;
  972. this._teleportationRequested = false;
  973. this._teleportationEnabledOnLeftController = false;
  974. this._teleportationEnabledOnRightController = false;
  975. this._interactionsEnabledOnLeftController = false;
  976. this._interactionsEnabledOnRightController = false;
  977. this._leftControllerReady = false;
  978. this._rightControllerReady = false;
  979. this._floorMeshesCollection = [];
  980. this._teleportationAllowed = false;
  981. this._rotationAllowed = true;
  982. this._teleportationRequestInitiated = false;
  983. this._teleportationBackRequestInitiated = false;
  984. this.teleportBackwardsVector = new BABYLON.Vector3(0, -1, -1);
  985. this._rotationRightAsked = false;
  986. this._rotationLeftAsked = false;
  987. this._isDefaultTeleportationTarget = true;
  988. this._teleportationFillColor = "#444444";
  989. this._teleportationBorderColor = "#FFFFFF";
  990. this._rotationAngle = 0;
  991. this._haloCenter = new BABYLON.Vector3(0, 0, 0);
  992. this._padSensibilityUp = 0.65;
  993. this._padSensibilityDown = 0.35;
  994. /**
  995. * Observable raised when a new mesh is selected based on meshSelectionPredicate
  996. */
  997. this.onNewMeshSelected = new BABYLON.Observable();
  998. /**
  999. * Observable raised when a new mesh is picked based on meshSelectionPredicate
  1000. */
  1001. this.onNewMeshPicked = new BABYLON.Observable();
  1002. /**
  1003. * Observable raised before camera teleportation
  1004. */
  1005. this.onBeforeCameraTeleport = new BABYLON.Observable();
  1006. /**
  1007. * Observable raised after camera teleportation
  1008. */
  1009. this.onAfterCameraTeleport = new BABYLON.Observable();
  1010. /**
  1011. * Observable raised when current selected mesh gets unselected
  1012. */
  1013. this.onSelectedMeshUnselected = new BABYLON.Observable();
  1014. /**
  1015. * Set teleportation enabled. If set to false camera teleportation will be disabled but camera rotation will be kept.
  1016. */
  1017. this.teleportationEnabled = true;
  1018. this._pointerDownOnMeshAsked = false;
  1019. this._isActionableMesh = false;
  1020. this._teleportationInitialized = false;
  1021. this._interactionsEnabled = false;
  1022. this._interactionsRequested = false;
  1023. this._displayGaze = true;
  1024. this._displayLaserPointer = true;
  1025. this._dpadPressed = true;
  1026. this._onResize = function () {
  1027. _this.moveButtonToBottomRight();
  1028. if (_this._fullscreenVRpresenting && _this._webVRready) {
  1029. _this.exitVR();
  1030. }
  1031. };
  1032. this._onFullscreenChange = function () {
  1033. if (document.fullscreen !== undefined) {
  1034. _this._fullscreenVRpresenting = document.fullscreen;
  1035. }
  1036. else if (document.mozFullScreen !== undefined) {
  1037. _this._fullscreenVRpresenting = document.mozFullScreen;
  1038. }
  1039. else if (document.webkitIsFullScreen !== undefined) {
  1040. _this._fullscreenVRpresenting = document.webkitIsFullScreen;
  1041. }
  1042. else if (document.msIsFullScreen !== undefined) {
  1043. _this._fullscreenVRpresenting = document.msIsFullScreen;
  1044. }
  1045. if (!_this._fullscreenVRpresenting && _this._canvas) {
  1046. _this.exitVR();
  1047. if (!_this._useCustomVRButton) {
  1048. _this._btnVR.style.top = _this._canvas.offsetTop + _this._canvas.offsetHeight - 70 + "px";
  1049. _this._btnVR.style.left = _this._canvas.offsetLeft + _this._canvas.offsetWidth - 100 + "px";
  1050. }
  1051. }
  1052. };
  1053. this.beforeRender = function () {
  1054. _this._castRayAndSelectObject();
  1055. };
  1056. this._onNewGamepadConnected = function (gamepad) {
  1057. if (gamepad.type !== BABYLON.Gamepad.POSE_ENABLED) {
  1058. if (gamepad.leftStick) {
  1059. gamepad.onleftstickchanged(function (stickValues) {
  1060. if (_this._teleportationInitialized && _this.teleportationEnabled) {
  1061. // Listening to classic/xbox gamepad only if no VR controller is active
  1062. if ((!_this._leftLaserPointer && !_this._rightLaserPointer) ||
  1063. ((_this._leftLaserPointer && !_this._leftLaserPointer.isVisible) &&
  1064. (_this._rightLaserPointer && !_this._rightLaserPointer.isVisible))) {
  1065. _this._checkTeleportWithRay(stickValues);
  1066. _this._checkTeleportBackwards(stickValues);
  1067. }
  1068. }
  1069. });
  1070. }
  1071. if (gamepad.rightStick) {
  1072. gamepad.onrightstickchanged(function (stickValues) {
  1073. if (_this._teleportationInitialized) {
  1074. _this._checkRotate(stickValues);
  1075. }
  1076. });
  1077. }
  1078. if (gamepad.type === BABYLON.Gamepad.XBOX) {
  1079. gamepad.onbuttondown(function (buttonPressed) {
  1080. if (_this._interactionsEnabled && buttonPressed === BABYLON.Xbox360Button.A) {
  1081. _this._selectionPointerDown();
  1082. }
  1083. });
  1084. gamepad.onbuttonup(function (buttonPressed) {
  1085. if (_this._interactionsEnabled && buttonPressed === BABYLON.Xbox360Button.A) {
  1086. _this._selectionPointerUp();
  1087. }
  1088. });
  1089. }
  1090. }
  1091. else {
  1092. var webVRController = gamepad;
  1093. _this._tryEnableInteractionOnController(webVRController);
  1094. }
  1095. };
  1096. // This only succeeds if the controller's mesh exists for the controller so this must be called whenever new controller is connected or when mesh is loaded
  1097. this._tryEnableInteractionOnController = function (webVRController) {
  1098. if (webVRController.hand === "left") {
  1099. _this._leftControllerReady = true;
  1100. if (_this._interactionsRequested && !_this._interactionsEnabledOnLeftController) {
  1101. _this._enableInteractionOnController(webVRController);
  1102. }
  1103. if (_this._teleportationRequested && !_this._teleportationEnabledOnLeftController) {
  1104. _this._enableTeleportationOnController(webVRController);
  1105. }
  1106. }
  1107. if (webVRController.hand === "right") {
  1108. _this._rightControllerReady = true;
  1109. if (_this._interactionsRequested && !_this._interactionsEnabledOnRightController) {
  1110. _this._enableInteractionOnController(webVRController);
  1111. }
  1112. if (_this._teleportationRequested && !_this._teleportationEnabledOnRightController) {
  1113. _this._enableTeleportationOnController(webVRController);
  1114. }
  1115. }
  1116. };
  1117. this._onNewGamepadDisconnected = function (gamepad) {
  1118. if (gamepad instanceof BABYLON.WebVRController) {
  1119. if (gamepad.hand === "left") {
  1120. _this._interactionsEnabledOnLeftController = false;
  1121. _this._teleportationEnabledOnLeftController = false;
  1122. _this._leftControllerReady = false;
  1123. if (_this._leftLaserPointer) {
  1124. _this._leftLaserPointer.dispose();
  1125. }
  1126. }
  1127. if (gamepad.hand === "right") {
  1128. _this._interactionsEnabledOnRightController = false;
  1129. _this._teleportationEnabledOnRightController = false;
  1130. _this._rightControllerReady = false;
  1131. if (_this._rightLaserPointer) {
  1132. _this._rightLaserPointer.dispose();
  1133. }
  1134. }
  1135. }
  1136. };
  1137. this._workingVector = BABYLON.Vector3.Zero();
  1138. this._workingQuaternion = BABYLON.Quaternion.Identity();
  1139. this._workingMatrix = BABYLON.Matrix.Identity();
  1140. this._scene = scene;
  1141. this._canvas = scene.getEngine().getRenderingCanvas();
  1142. // Parse options
  1143. if (webVROptions.createFallbackVRDeviceOrientationFreeCamera === undefined) {
  1144. webVROptions.createFallbackVRDeviceOrientationFreeCamera = true;
  1145. }
  1146. if (webVROptions.createDeviceOrientationCamera === undefined) {
  1147. webVROptions.createDeviceOrientationCamera = true;
  1148. }
  1149. if (webVROptions.defaultHeight === undefined) {
  1150. webVROptions.defaultHeight = 1.7;
  1151. }
  1152. if (webVROptions.useCustomVRButton) {
  1153. this._useCustomVRButton = true;
  1154. if (webVROptions.customVRButton) {
  1155. this._btnVR = webVROptions.customVRButton;
  1156. }
  1157. }
  1158. if (webVROptions.rayLength) {
  1159. this._rayLength = webVROptions.rayLength;
  1160. }
  1161. this._defaultHeight = webVROptions.defaultHeight;
  1162. // Set position
  1163. if (this._scene.activeCamera) {
  1164. this._position = this._scene.activeCamera.position.clone();
  1165. }
  1166. else {
  1167. this._position = new BABYLON.Vector3(0, this._defaultHeight, 0);
  1168. }
  1169. // Set non-vr camera
  1170. if (webVROptions.createDeviceOrientationCamera || !this._scene.activeCamera) {
  1171. this._deviceOrientationCamera = new BABYLON.DeviceOrientationCamera("deviceOrientationVRHelper", this._position.clone(), scene);
  1172. // Copy data from existing camera
  1173. if (this._scene.activeCamera) {
  1174. this._deviceOrientationCamera.minZ = this._scene.activeCamera.minZ;
  1175. this._deviceOrientationCamera.maxZ = this._scene.activeCamera.maxZ;
  1176. // Set rotation from previous camera
  1177. if (this._scene.activeCamera instanceof BABYLON.TargetCamera && this._scene.activeCamera.rotation) {
  1178. var targetCamera = this._scene.activeCamera;
  1179. if (targetCamera.rotationQuaternion) {
  1180. this._deviceOrientationCamera.rotationQuaternion.copyFrom(targetCamera.rotationQuaternion);
  1181. }
  1182. else {
  1183. this._deviceOrientationCamera.rotationQuaternion.copyFrom(BABYLON.Quaternion.RotationYawPitchRoll(targetCamera.rotation.y, targetCamera.rotation.x, targetCamera.rotation.z));
  1184. }
  1185. this._deviceOrientationCamera.rotation = targetCamera.rotation.clone();
  1186. }
  1187. }
  1188. this._scene.activeCamera = this._deviceOrientationCamera;
  1189. if (this._canvas) {
  1190. this._scene.activeCamera.attachControl(this._canvas);
  1191. }
  1192. }
  1193. else {
  1194. this._existingCamera = this._scene.activeCamera;
  1195. }
  1196. // Create VR cameras
  1197. if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
  1198. this._vrDeviceOrientationCamera = new BABYLON.VRDeviceOrientationFreeCamera("VRDeviceOrientationVRHelper", this._position, this._scene);
  1199. }
  1200. this._webVRCamera = new BABYLON.WebVRFreeCamera("WebVRHelper", this._position, this._scene, webVROptions);
  1201. this._webVRCamera.useStandingMatrix();
  1202. // Create default button
  1203. if (!this._useCustomVRButton) {
  1204. this._btnVR = document.createElement("BUTTON");
  1205. this._btnVR.className = "babylonVRicon";
  1206. this._btnVR.id = "babylonVRiconbtn";
  1207. this._btnVR.title = "Click to switch to VR";
  1208. var css = ".babylonVRicon { position: absolute; right: 20px; height: 50px; width: 80px; background-color: rgba(51,51,51,0.7); background-image: url(data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%222048%22%20height%3D%221152%22%20viewBox%3D%220%200%202048%201152%22%20version%3D%221.1%22%3E%3Cpath%20transform%3D%22rotate%28180%201024%2C576.0000000000001%29%22%20d%3D%22m1109%2C896q17%2C0%2030%2C-12t13%2C-30t-12.5%2C-30.5t-30.5%2C-12.5l-170%2C0q-18%2C0%20-30.5%2C12.5t-12.5%2C30.5t13%2C30t30%2C12l170%2C0zm-85%2C256q59%2C0%20132.5%2C-1.5t154.5%2C-5.5t164.5%2C-11.5t163%2C-20t150%2C-30t124.5%2C-41.5q23%2C-11%2042%2C-24t38%2C-30q27%2C-25%2041%2C-61.5t14%2C-72.5l0%2C-257q0%2C-123%20-47%2C-232t-128%2C-190t-190%2C-128t-232%2C-47l-81%2C0q-37%2C0%20-68.5%2C14t-60.5%2C34.5t-55.5%2C45t-53%2C45t-53%2C34.5t-55.5%2C14t-55.5%2C-14t-53%2C-34.5t-53%2C-45t-55.5%2C-45t-60.5%2C-34.5t-68.5%2C-14l-81%2C0q-123%2C0%20-232%2C47t-190%2C128t-128%2C190t-47%2C232l0%2C257q0%2C68%2038%2C115t97%2C73q54%2C24%20124.5%2C41.5t150%2C30t163%2C20t164.5%2C11.5t154.5%2C5.5t132.5%2C1.5zm939%2C-298q0%2C39%20-24.5%2C67t-58.5%2C42q-54%2C23%20-122%2C39.5t-143.5%2C28t-155.5%2C19t-157%2C11t-148.5%2C5t-129.5%2C1.5q-59%2C0%20-130%2C-1.5t-148%2C-5t-157%2C-11t-155.5%2C-19t-143.5%2C-28t-122%2C-39.5q-34%2C-14%20-58.5%2C-42t-24.5%2C-67l0%2C-257q0%2C-106%2040.5%2C-199t110%2C-162.5t162.5%2C-109.5t199%2C-40l81%2C0q27%2C0%2052%2C14t50%2C34.5t51%2C44.5t55.5%2C44.5t63.5%2C34.5t74%2C14t74%2C-14t63.5%2C-34.5t55.5%2C-44.5t51%2C-44.5t50%2C-34.5t52%2C-14l14%2C0q37%2C0%2070%2C0.5t64.5%2C4.5t63.5%2C12t68%2C23q71%2C30%20128.5%2C78.5t98.5%2C110t63.5%2C133.5t22.5%2C149l0%2C257z%22%20fill%3D%22white%22%20/%3E%3C/svg%3E%0A); background-size: 80%; background-repeat:no-repeat; background-position: center; border: none; outline: none; transition: transform 0.125s ease-out } .babylonVRicon:hover { transform: scale(1.05) } .babylonVRicon:active {background-color: rgba(51,51,51,1) } .babylonVRicon:focus {background-color: rgba(51,51,51,1) }";
  1209. css += ".babylonVRicon.vrdisplaypresenting { display: none; }";
  1210. // TODO: Add user feedback so that they know what state the VRDisplay is in (disconnected, connected, entering-VR)
  1211. // css += ".babylonVRicon.vrdisplaysupported { }";
  1212. // css += ".babylonVRicon.vrdisplayready { }";
  1213. // css += ".babylonVRicon.vrdisplayrequesting { }";
  1214. var style = document.createElement('style');
  1215. style.appendChild(document.createTextNode(css));
  1216. document.getElementsByTagName('head')[0].appendChild(style);
  1217. this.moveButtonToBottomRight();
  1218. }
  1219. // VR button click event
  1220. if (this._btnVR) {
  1221. this._btnVR.addEventListener("click", function () {
  1222. if (!_this.isInVRMode) {
  1223. _this.enterVR();
  1224. }
  1225. else {
  1226. _this.exitVR();
  1227. }
  1228. });
  1229. }
  1230. // Window events
  1231. window.addEventListener("resize", this._onResize);
  1232. document.addEventListener("fullscreenchange", this._onFullscreenChange, false);
  1233. document.addEventListener("mozfullscreenchange", this._onFullscreenChange, false);
  1234. document.addEventListener("webkitfullscreenchange", this._onFullscreenChange, false);
  1235. document.addEventListener("msfullscreenchange", this._onFullscreenChange, false);
  1236. // Display vr button when headset is connected
  1237. if (webVROptions.createFallbackVRDeviceOrientationFreeCamera) {
  1238. this.displayVRButton();
  1239. }
  1240. else {
  1241. this._scene.getEngine().onVRDisplayChangedObservable.add(function (e) {
  1242. if (e.vrDisplay) {
  1243. _this.displayVRButton();
  1244. }
  1245. });
  1246. }
  1247. // Exiting VR mode using 'ESC' key on desktop
  1248. this._onKeyDown = function (event) {
  1249. if (event.keyCode === 27 && _this.isInVRMode) {
  1250. _this.exitVR();
  1251. }
  1252. };
  1253. document.addEventListener("keydown", this._onKeyDown);
  1254. // Exiting VR mode double tapping the touch screen
  1255. this._scene.onPrePointerObservable.add(function (pointerInfo, eventState) {
  1256. if (_this.isInVRMode) {
  1257. _this.exitVR();
  1258. if (_this._fullscreenVRpresenting) {
  1259. _this._scene.getEngine().switchFullscreen(true);
  1260. }
  1261. }
  1262. }, BABYLON.PointerEventTypes.POINTERDOUBLETAP, false);
  1263. // Listen for WebVR display changes
  1264. this._onVRDisplayChanged = function (eventArgs) { return _this.onVRDisplayChanged(eventArgs); };
  1265. this._onVrDisplayPresentChange = function () { return _this.onVrDisplayPresentChange(); };
  1266. this._onVRRequestPresentStart = function () {
  1267. _this._webVRrequesting = true;
  1268. _this.updateButtonVisibility();
  1269. };
  1270. this._onVRRequestPresentComplete = function (success) {
  1271. _this._webVRrequesting = false;
  1272. _this.updateButtonVisibility();
  1273. };
  1274. scene.getEngine().onVRDisplayChangedObservable.add(this._onVRDisplayChanged);
  1275. scene.getEngine().onVRRequestPresentStart.add(this._onVRRequestPresentStart);
  1276. scene.getEngine().onVRRequestPresentComplete.add(this._onVRRequestPresentComplete);
  1277. window.addEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
  1278. scene.onDisposeObservable.add(function () {
  1279. _this.dispose();
  1280. });
  1281. // Gamepad connection events
  1282. this._webVRCamera.onControllerMeshLoadedObservable.add(function (webVRController) { return _this._onDefaultMeshLoaded(webVRController); });
  1283. this._scene.gamepadManager.onGamepadConnectedObservable.add(this._onNewGamepadConnected);
  1284. this._scene.gamepadManager.onGamepadDisconnectedObservable.add(this._onNewGamepadDisconnected);
  1285. this.updateButtonVisibility();
  1286. //create easing functions
  1287. this._circleEase = new BABYLON.CircleEase();
  1288. this._circleEase.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
  1289. }
  1290. Object.defineProperty(VRExperienceHelper.prototype, "onEnteringVR", {
  1291. /** Return this.onEnteringVRObservable
  1292. * Note: This one is for backward compatibility. Please use onEnteringVRObservable directly
  1293. */
  1294. get: function () {
  1295. return this.onEnteringVRObservable;
  1296. },
  1297. enumerable: true,
  1298. configurable: true
  1299. });
  1300. Object.defineProperty(VRExperienceHelper.prototype, "onExitingVR", {
  1301. /** Return this.onExitingVRObservable
  1302. * Note: This one is for backward compatibility. Please use onExitingVRObservable directly
  1303. */
  1304. get: function () {
  1305. return this.onExitingVRObservable;
  1306. },
  1307. enumerable: true,
  1308. configurable: true
  1309. });
  1310. Object.defineProperty(VRExperienceHelper.prototype, "onControllerMeshLoaded", {
  1311. /** Return this.onControllerMeshLoadedObservable
  1312. * Note: This one is for backward compatibility. Please use onControllerMeshLoadedObservable directly
  1313. */
  1314. get: function () {
  1315. return this.onControllerMeshLoadedObservable;
  1316. },
  1317. enumerable: true,
  1318. configurable: true
  1319. });
  1320. Object.defineProperty(VRExperienceHelper.prototype, "teleportationTarget", {
  1321. get: function () {
  1322. return this._teleportationTarget;
  1323. },
  1324. set: function (value) {
  1325. if (value) {
  1326. value.name = "teleportationTarget";
  1327. this._isDefaultTeleportationTarget = false;
  1328. this._teleportationTarget = value;
  1329. }
  1330. },
  1331. enumerable: true,
  1332. configurable: true
  1333. });
  1334. Object.defineProperty(VRExperienceHelper.prototype, "displayGaze", {
  1335. get: function () {
  1336. return this._displayGaze;
  1337. },
  1338. set: function (value) {
  1339. this._displayGaze = value;
  1340. if (!value) {
  1341. this._gazeTracker.isVisible = false;
  1342. }
  1343. },
  1344. enumerable: true,
  1345. configurable: true
  1346. });
  1347. Object.defineProperty(VRExperienceHelper.prototype, "displayLaserPointer", {
  1348. get: function () {
  1349. return this._displayLaserPointer;
  1350. },
  1351. set: function (value) {
  1352. this._displayLaserPointer = value;
  1353. if (!value) {
  1354. if (this._rightLaserPointer) {
  1355. this._rightLaserPointer.isVisible = false;
  1356. }
  1357. if (this._leftLaserPointer) {
  1358. this._leftLaserPointer.isVisible = false;
  1359. }
  1360. }
  1361. else {
  1362. if (this._rightLaserPointer) {
  1363. this._rightLaserPointer.isVisible = true;
  1364. }
  1365. else if (this._leftLaserPointer) {
  1366. this._leftLaserPointer.isVisible = true;
  1367. }
  1368. }
  1369. },
  1370. enumerable: true,
  1371. configurable: true
  1372. });
  1373. Object.defineProperty(VRExperienceHelper.prototype, "deviceOrientationCamera", {
  1374. get: function () {
  1375. return this._deviceOrientationCamera;
  1376. },
  1377. enumerable: true,
  1378. configurable: true
  1379. });
  1380. Object.defineProperty(VRExperienceHelper.prototype, "currentVRCamera", {
  1381. // Based on the current WebVR support, returns the current VR camera used
  1382. get: function () {
  1383. if (this._webVRready) {
  1384. return this._webVRCamera;
  1385. }
  1386. else {
  1387. return this._scene.activeCamera;
  1388. }
  1389. },
  1390. enumerable: true,
  1391. configurable: true
  1392. });
  1393. Object.defineProperty(VRExperienceHelper.prototype, "webVRCamera", {
  1394. get: function () {
  1395. return this._webVRCamera;
  1396. },
  1397. enumerable: true,
  1398. configurable: true
  1399. });
  1400. Object.defineProperty(VRExperienceHelper.prototype, "vrDeviceOrientationCamera", {
  1401. get: function () {
  1402. return this._vrDeviceOrientationCamera;
  1403. },
  1404. enumerable: true,
  1405. configurable: true
  1406. });
  1407. // Raised when one of the controller has loaded successfully its associated default mesh
  1408. VRExperienceHelper.prototype._onDefaultMeshLoaded = function (webVRController) {
  1409. this._tryEnableInteractionOnController(webVRController);
  1410. try {
  1411. this.onControllerMeshLoadedObservable.notifyObservers(webVRController);
  1412. }
  1413. catch (err) {
  1414. BABYLON.Tools.Warn("Error in your custom logic onControllerMeshLoaded: " + err);
  1415. }
  1416. };
  1417. Object.defineProperty(VRExperienceHelper.prototype, "isInVRMode", {
  1418. /**
  1419. * Gets a value indicating if we are currently in VR mode.
  1420. */
  1421. get: function () {
  1422. return this._webVRpresenting || this._fullscreenVRpresenting;
  1423. },
  1424. enumerable: true,
  1425. configurable: true
  1426. });
  1427. VRExperienceHelper.prototype.onVrDisplayPresentChange = function () {
  1428. var vrDisplay = this._scene.getEngine().getVRDevice();
  1429. if (vrDisplay) {
  1430. var wasPresenting = this._webVRpresenting;
  1431. // A VR display is connected
  1432. this._webVRpresenting = vrDisplay.isPresenting;
  1433. if (wasPresenting && !this._webVRpresenting)
  1434. this.exitVR();
  1435. }
  1436. else {
  1437. BABYLON.Tools.Warn('Detected VRDisplayPresentChange on an unknown VRDisplay. Did you can enterVR on the vrExperienceHelper?');
  1438. }
  1439. this.updateButtonVisibility();
  1440. };
  1441. VRExperienceHelper.prototype.onVRDisplayChanged = function (eventArgs) {
  1442. this._webVRsupported = eventArgs.vrSupported;
  1443. this._webVRready = !!eventArgs.vrDisplay;
  1444. this._webVRpresenting = eventArgs.vrDisplay && eventArgs.vrDisplay.isPresenting;
  1445. this.updateButtonVisibility();
  1446. };
  1447. VRExperienceHelper.prototype.moveButtonToBottomRight = function () {
  1448. if (this._canvas && !this._useCustomVRButton) {
  1449. this._btnVR.style.top = this._canvas.offsetTop + this._canvas.offsetHeight - 70 + "px";
  1450. this._btnVR.style.left = this._canvas.offsetLeft + this._canvas.offsetWidth - 100 + "px";
  1451. }
  1452. };
  1453. VRExperienceHelper.prototype.displayVRButton = function () {
  1454. if (!this._useCustomVRButton && !this._btnVRDisplayed) {
  1455. document.body.appendChild(this._btnVR);
  1456. this._btnVRDisplayed = true;
  1457. }
  1458. };
  1459. VRExperienceHelper.prototype.updateButtonVisibility = function () {
  1460. if (!this._btnVR || this._useCustomVRButton) {
  1461. return;
  1462. }
  1463. this._btnVR.className = "babylonVRicon";
  1464. if (this.isInVRMode) {
  1465. this._btnVR.className += " vrdisplaypresenting";
  1466. }
  1467. else {
  1468. if (this._webVRready)
  1469. this._btnVR.className += " vrdisplayready";
  1470. if (this._webVRsupported)
  1471. this._btnVR.className += " vrdisplaysupported";
  1472. if (this._webVRrequesting)
  1473. this._btnVR.className += " vrdisplayrequesting";
  1474. }
  1475. };
  1476. /**
  1477. * Attempt to enter VR. If a headset is connected and ready, will request present on that.
  1478. * Otherwise, will use the fullscreen API.
  1479. */
  1480. VRExperienceHelper.prototype.enterVR = function () {
  1481. if (this.onEnteringVRObservable) {
  1482. try {
  1483. this.onEnteringVRObservable.notifyObservers(this);
  1484. }
  1485. catch (err) {
  1486. BABYLON.Tools.Warn("Error in your custom logic onEnteringVR: " + err);
  1487. }
  1488. }
  1489. if (this._scene.activeCamera) {
  1490. this._position = this._scene.activeCamera.position.clone();
  1491. // make sure that we return to the last active camera
  1492. this._existingCamera = this._scene.activeCamera;
  1493. }
  1494. if (this._webVRrequesting)
  1495. return;
  1496. // If WebVR is supported and a headset is connected
  1497. if (this._webVRready) {
  1498. if (!this._webVRpresenting) {
  1499. this._webVRCamera.position = this._position;
  1500. this._scene.activeCamera = this._webVRCamera;
  1501. }
  1502. }
  1503. else if (this._vrDeviceOrientationCamera) {
  1504. this._vrDeviceOrientationCamera.position = this._position;
  1505. this._scene.activeCamera = this._vrDeviceOrientationCamera;
  1506. this._scene.getEngine().switchFullscreen(true);
  1507. this.updateButtonVisibility();
  1508. }
  1509. if (this._scene.activeCamera && this._canvas) {
  1510. this._scene.activeCamera.attachControl(this._canvas);
  1511. }
  1512. if (this._interactionsEnabled) {
  1513. this._scene.registerBeforeRender(this.beforeRender);
  1514. }
  1515. };
  1516. /**
  1517. * Attempt to exit VR, or fullscreen.
  1518. */
  1519. VRExperienceHelper.prototype.exitVR = function () {
  1520. if (this.onExitingVRObservable) {
  1521. try {
  1522. this.onExitingVRObservable.notifyObservers(this);
  1523. }
  1524. catch (err) {
  1525. BABYLON.Tools.Warn("Error in your custom logic onExitingVR: " + err);
  1526. }
  1527. }
  1528. if (this._webVRpresenting) {
  1529. this._scene.getEngine().disableVR();
  1530. }
  1531. if (this._scene.activeCamera) {
  1532. this._position = this._scene.activeCamera.position.clone();
  1533. }
  1534. if (this._deviceOrientationCamera) {
  1535. this._deviceOrientationCamera.position = this._position;
  1536. this._scene.activeCamera = this._deviceOrientationCamera;
  1537. if (this._canvas) {
  1538. this._scene.activeCamera.attachControl(this._canvas);
  1539. }
  1540. }
  1541. else if (this._existingCamera) {
  1542. this._existingCamera.position = this._position;
  1543. this._scene.activeCamera = this._existingCamera;
  1544. }
  1545. this.updateButtonVisibility();
  1546. if (this._interactionsEnabled) {
  1547. this._scene.unregisterBeforeRender(this.beforeRender);
  1548. }
  1549. };
  1550. Object.defineProperty(VRExperienceHelper.prototype, "position", {
  1551. get: function () {
  1552. return this._position;
  1553. },
  1554. set: function (value) {
  1555. this._position = value;
  1556. if (this._scene.activeCamera) {
  1557. this._scene.activeCamera.position = value;
  1558. }
  1559. },
  1560. enumerable: true,
  1561. configurable: true
  1562. });
  1563. VRExperienceHelper.prototype.enableInteractions = function () {
  1564. var _this = this;
  1565. if (!this._interactionsEnabled) {
  1566. this._interactionsRequested = true;
  1567. if (this._leftControllerReady && this._webVRCamera.leftController) {
  1568. this._enableInteractionOnController(this._webVRCamera.leftController);
  1569. }
  1570. if (this._rightControllerReady && this._webVRCamera.rightController) {
  1571. this._enableInteractionOnController(this._webVRCamera.rightController);
  1572. }
  1573. this._createGazeTracker();
  1574. this.raySelectionPredicate = function (mesh) {
  1575. return mesh.isVisible;
  1576. };
  1577. this.meshSelectionPredicate = function (mesh) {
  1578. return true;
  1579. };
  1580. this._raySelectionPredicate = function (mesh) {
  1581. if (_this._isTeleportationFloor(mesh) || (mesh.name.indexOf("gazeTracker") === -1
  1582. && mesh.name.indexOf("teleportationTarget") === -1
  1583. && mesh.name.indexOf("torusTeleportation") === -1
  1584. && mesh.name.indexOf("laserPointer") === -1)) {
  1585. return _this.raySelectionPredicate(mesh);
  1586. }
  1587. return false;
  1588. };
  1589. this._interactionsEnabled = true;
  1590. }
  1591. };
  1592. VRExperienceHelper.prototype._isTeleportationFloor = function (mesh) {
  1593. for (var i = 0; i < this._floorMeshesCollection.length; i++) {
  1594. if (this._floorMeshesCollection[i].id === mesh.id) {
  1595. return true;
  1596. }
  1597. }
  1598. if (this._floorMeshName && mesh.name === this._floorMeshName) {
  1599. return true;
  1600. }
  1601. return false;
  1602. };
  1603. VRExperienceHelper.prototype.addFloorMesh = function (floorMesh) {
  1604. if (!this._floorMeshesCollection) {
  1605. return;
  1606. }
  1607. if (this._floorMeshesCollection.indexOf(floorMesh) > -1) {
  1608. return;
  1609. }
  1610. this._floorMeshesCollection.push(floorMesh);
  1611. };
  1612. VRExperienceHelper.prototype.removeFloorMesh = function (floorMesh) {
  1613. if (!this._floorMeshesCollection) {
  1614. return;
  1615. }
  1616. var meshIndex = this._floorMeshesCollection.indexOf(floorMesh);
  1617. if (meshIndex !== -1) {
  1618. this._floorMeshesCollection.splice(meshIndex, 1);
  1619. }
  1620. };
  1621. VRExperienceHelper.prototype.enableTeleportation = function (vrTeleportationOptions) {
  1622. if (vrTeleportationOptions === void 0) { vrTeleportationOptions = {}; }
  1623. if (!this._teleportationInitialized) {
  1624. this._teleportationRequested = true;
  1625. this.enableInteractions();
  1626. if (vrTeleportationOptions.floorMeshName) {
  1627. this._floorMeshName = vrTeleportationOptions.floorMeshName;
  1628. }
  1629. if (vrTeleportationOptions.floorMeshes) {
  1630. this._floorMeshesCollection = vrTeleportationOptions.floorMeshes;
  1631. }
  1632. if (this._leftControllerReady && this._webVRCamera.leftController) {
  1633. this._enableTeleportationOnController(this._webVRCamera.leftController);
  1634. }
  1635. if (this._rightControllerReady && this._webVRCamera.rightController) {
  1636. this._enableTeleportationOnController(this._webVRCamera.rightController);
  1637. }
  1638. // Creates an image processing post process for the vignette not relying
  1639. // on the main scene configuration for image processing to reduce setup and spaces
  1640. // (gamma/linear) conflicts.
  1641. var imageProcessingConfiguration = new BABYLON.ImageProcessingConfiguration();
  1642. imageProcessingConfiguration.vignetteColor = new BABYLON.Color4(0, 0, 0, 0);
  1643. imageProcessingConfiguration.vignetteEnabled = true;
  1644. this._postProcessMove = new BABYLON.ImageProcessingPostProcess("postProcessMove", 1.0, this._webVRCamera, undefined, undefined, undefined, undefined, imageProcessingConfiguration);
  1645. this._webVRCamera.detachPostProcess(this._postProcessMove);
  1646. this._passProcessMove = new BABYLON.PassPostProcess("pass", 1.0, this._webVRCamera);
  1647. this._teleportationInitialized = true;
  1648. if (this._isDefaultTeleportationTarget) {
  1649. this._createTeleportationCircles();
  1650. }
  1651. }
  1652. };
  1653. VRExperienceHelper.prototype._enableInteractionOnController = function (webVRController) {
  1654. var _this = this;
  1655. var controllerMesh = webVRController.mesh;
  1656. if (controllerMesh) {
  1657. var makeNotPick = function (root) {
  1658. root.name += " laserPointer";
  1659. root.getChildMeshes().forEach(function (c) {
  1660. makeNotPick(c);
  1661. });
  1662. };
  1663. makeNotPick(controllerMesh);
  1664. var childMeshes = controllerMesh.getChildMeshes();
  1665. for (var i = 0; i < childMeshes.length; i++) {
  1666. if (childMeshes[i].name && childMeshes[i].name.indexOf("POINTING_POSE") >= 0) {
  1667. controllerMesh = childMeshes[i];
  1668. break;
  1669. }
  1670. }
  1671. var laserPointer = BABYLON.Mesh.CreateCylinder("laserPointer", 1, 0.004, 0.0002, 20, 1, this._scene, false);
  1672. var laserPointerMaterial = new BABYLON.StandardMaterial("laserPointerMat", this._scene);
  1673. laserPointerMaterial.emissiveColor = new BABYLON.Color3(0.7, 0.7, 0.7);
  1674. laserPointerMaterial.alpha = 0.6;
  1675. laserPointer.material = laserPointerMaterial;
  1676. laserPointer.rotation.x = Math.PI / 2;
  1677. laserPointer.parent = controllerMesh;
  1678. laserPointer.position.z = -0.5;
  1679. laserPointer.isVisible = false;
  1680. if (webVRController.hand === "left") {
  1681. this._leftLaserPointer = laserPointer;
  1682. this._interactionsEnabledOnLeftController = true;
  1683. if (!this._rightLaserPointer) {
  1684. this._leftLaserPointer.isVisible = true;
  1685. }
  1686. }
  1687. else {
  1688. this._rightLaserPointer = laserPointer;
  1689. this._interactionsEnabledOnRightController = true;
  1690. if (!this._leftLaserPointer) {
  1691. this._rightLaserPointer.isVisible = true;
  1692. }
  1693. }
  1694. webVRController.onMainButtonStateChangedObservable.add(function (stateObject) {
  1695. // Enabling / disabling laserPointer
  1696. if (_this._displayLaserPointer && stateObject.value === 1) {
  1697. laserPointer.isVisible = !laserPointer.isVisible;
  1698. // Laser pointer can only be active on left or right, not both at the same time
  1699. if (webVRController.hand === "left" && _this._rightLaserPointer) {
  1700. _this._rightLaserPointer.isVisible = false;
  1701. }
  1702. else if (_this._leftLaserPointer) {
  1703. _this._leftLaserPointer.isVisible = false;
  1704. }
  1705. }
  1706. });
  1707. webVRController.onTriggerStateChangedObservable.add(function (stateObject) {
  1708. if (!_this._pointerDownOnMeshAsked) {
  1709. if (stateObject.value > _this._padSensibilityUp) {
  1710. _this._selectionPointerDown();
  1711. }
  1712. }
  1713. else if (stateObject.value < _this._padSensibilityDown) {
  1714. _this._selectionPointerUp();
  1715. }
  1716. });
  1717. }
  1718. };
  1719. VRExperienceHelper.prototype._checkTeleportWithRay = function (stateObject, webVRController) {
  1720. if (webVRController === void 0) { webVRController = null; }
  1721. if (!this._teleportationRequestInitiated) {
  1722. if (stateObject.y < -this._padSensibilityUp && this._dpadPressed) {
  1723. if (webVRController) {
  1724. // If laser pointer wasn't enabled yet
  1725. if (this._displayLaserPointer && webVRController.hand === "left" && this._leftLaserPointer) {
  1726. this._leftLaserPointer.isVisible = true;
  1727. if (this._rightLaserPointer) {
  1728. this._rightLaserPointer.isVisible = false;
  1729. }
  1730. }
  1731. else if (this._displayLaserPointer && this._rightLaserPointer) {
  1732. this._rightLaserPointer.isVisible = true;
  1733. if (this._leftLaserPointer) {
  1734. this._leftLaserPointer.isVisible = false;
  1735. }
  1736. }
  1737. }
  1738. this._teleportationRequestInitiated = true;
  1739. }
  1740. }
  1741. else {
  1742. // Listening to the proper controller values changes to confirm teleportation
  1743. if (webVRController == null
  1744. || (webVRController.hand === "left" && this._leftLaserPointer && this._leftLaserPointer.isVisible)
  1745. || (webVRController.hand === "right" && this._rightLaserPointer && this._rightLaserPointer.isVisible)) {
  1746. if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
  1747. if (this._teleportationAllowed) {
  1748. this._teleportationAllowed = false;
  1749. this._teleportCamera();
  1750. }
  1751. this._teleportationRequestInitiated = false;
  1752. }
  1753. }
  1754. }
  1755. };
  1756. VRExperienceHelper.prototype._selectionPointerDown = function () {
  1757. this._pointerDownOnMeshAsked = true;
  1758. if (this._currentMeshSelected && this._currentHit) {
  1759. this._scene.simulatePointerDown(this._currentHit);
  1760. }
  1761. };
  1762. VRExperienceHelper.prototype._selectionPointerUp = function () {
  1763. if (this._currentMeshSelected && this._currentHit) {
  1764. this._scene.simulatePointerUp(this._currentHit);
  1765. }
  1766. this._pointerDownOnMeshAsked = false;
  1767. };
  1768. VRExperienceHelper.prototype._checkRotate = function (stateObject) {
  1769. // Only rotate when user is not currently selecting a teleportation location
  1770. if (this._teleportationRequestInitiated) {
  1771. return;
  1772. }
  1773. if (!this._rotationLeftAsked) {
  1774. if (stateObject.x < -this._padSensibilityUp && this._dpadPressed) {
  1775. this._rotationLeftAsked = true;
  1776. if (this._rotationAllowed) {
  1777. this._rotateCamera(false);
  1778. }
  1779. }
  1780. }
  1781. else {
  1782. if (stateObject.x > -this._padSensibilityDown) {
  1783. this._rotationLeftAsked = false;
  1784. }
  1785. }
  1786. if (!this._rotationRightAsked) {
  1787. if (stateObject.x > this._padSensibilityUp && this._dpadPressed) {
  1788. this._rotationRightAsked = true;
  1789. if (this._rotationAllowed) {
  1790. this._rotateCamera(true);
  1791. }
  1792. }
  1793. }
  1794. else {
  1795. if (stateObject.x < this._padSensibilityDown) {
  1796. this._rotationRightAsked = false;
  1797. }
  1798. }
  1799. };
  1800. VRExperienceHelper.prototype._checkTeleportBackwards = function (stateObject) {
  1801. // Only teleport backwards when user is not currently selecting a teleportation location
  1802. if (this._teleportationRequestInitiated) {
  1803. return;
  1804. }
  1805. // Teleport backwards
  1806. if (stateObject.y > this._padSensibilityUp && this._dpadPressed) {
  1807. if (!this._teleportationBackRequestInitiated) {
  1808. if (!this.currentVRCamera) {
  1809. return;
  1810. }
  1811. // Get rotation and position of the current camera
  1812. var rotation = BABYLON.Quaternion.FromRotationMatrix(this.currentVRCamera.getWorldMatrix().getRotationMatrix());
  1813. var position = this.currentVRCamera.position;
  1814. // If the camera has device position, use that instead
  1815. if (this.currentVRCamera.devicePosition && this.currentVRCamera.deviceRotationQuaternion) {
  1816. rotation = this.currentVRCamera.deviceRotationQuaternion;
  1817. position = this.currentVRCamera.devicePosition;
  1818. }
  1819. // Get matrix with only the y rotation of the device rotation
  1820. rotation.toEulerAnglesToRef(this._workingVector);
  1821. this._workingVector.z = 0;
  1822. this._workingVector.x = 0;
  1823. BABYLON.Quaternion.RotationYawPitchRollToRef(this._workingVector.y, this._workingVector.x, this._workingVector.z, this._workingQuaternion);
  1824. this._workingQuaternion.toRotationMatrix(this._workingMatrix);
  1825. // Rotate backwards ray by device rotation to cast at the ground behind the user
  1826. BABYLON.Vector3.TransformCoordinatesToRef(this.teleportBackwardsVector, this._workingMatrix, this._workingVector);
  1827. // Teleport if ray hit the ground and is not to far away eg. backwards off a cliff
  1828. var ray = new BABYLON.Ray(position, this._workingVector);
  1829. var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
  1830. if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {
  1831. this._teleportCamera(hit.pickedPoint);
  1832. }
  1833. this._teleportationBackRequestInitiated = true;
  1834. }
  1835. }
  1836. else {
  1837. this._teleportationBackRequestInitiated = false;
  1838. }
  1839. };
  1840. VRExperienceHelper.prototype._enableTeleportationOnController = function (webVRController) {
  1841. var _this = this;
  1842. var controllerMesh = webVRController.mesh;
  1843. if (controllerMesh) {
  1844. if (webVRController.hand === "left") {
  1845. if (!this._interactionsEnabledOnLeftController) {
  1846. this._enableInteractionOnController(webVRController);
  1847. }
  1848. this._teleportationEnabledOnLeftController = true;
  1849. }
  1850. else {
  1851. if (!this._interactionsEnabledOnRightController) {
  1852. this._enableInteractionOnController(webVRController);
  1853. }
  1854. this._teleportationEnabledOnRightController = true;
  1855. }
  1856. if (webVRController.controllerType === BABYLON.PoseEnabledControllerType.VIVE) {
  1857. this._dpadPressed = false;
  1858. webVRController.onPadStateChangedObservable.add(function (stateObject) {
  1859. _this._dpadPressed = stateObject.pressed;
  1860. if (!_this._dpadPressed) {
  1861. _this._rotationLeftAsked = false;
  1862. _this._rotationRightAsked = false;
  1863. _this._teleportationBackRequestInitiated = false;
  1864. }
  1865. });
  1866. }
  1867. webVRController.onPadValuesChangedObservable.add(function (stateObject) {
  1868. if (_this.teleportationEnabled) {
  1869. _this._checkTeleportBackwards(stateObject);
  1870. _this._checkTeleportWithRay(stateObject, webVRController);
  1871. }
  1872. _this._checkRotate(stateObject);
  1873. });
  1874. }
  1875. };
  1876. // Gaze support used to point to teleport or to interact with an object
  1877. VRExperienceHelper.prototype._createGazeTracker = function () {
  1878. this._gazeTracker = BABYLON.Mesh.CreateTorus("gazeTracker", 0.0035, 0.0025, 20, this._scene, false);
  1879. this._gazeTracker.bakeCurrentTransformIntoVertices();
  1880. this._gazeTracker.isPickable = false;
  1881. this._gazeTracker.isVisible = false;
  1882. var targetMat = new BABYLON.StandardMaterial("targetMat", this._scene);
  1883. targetMat.specularColor = BABYLON.Color3.Black();
  1884. targetMat.emissiveColor = new BABYLON.Color3(0.7, 0.7, 0.7);
  1885. targetMat.backFaceCulling = false;
  1886. this._gazeTracker.material = targetMat;
  1887. };
  1888. VRExperienceHelper.prototype._createTeleportationCircles = function () {
  1889. this._teleportationTarget = BABYLON.Mesh.CreateGround("teleportationTarget", 2, 2, 2, this._scene);
  1890. this._teleportationTarget.isPickable = false;
  1891. var length = 512;
  1892. var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", length, this._scene, true);
  1893. dynamicTexture.hasAlpha = true;
  1894. var context = dynamicTexture.getContext();
  1895. var centerX = length / 2;
  1896. var centerY = length / 2;
  1897. var radius = 200;
  1898. context.beginPath();
  1899. context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
  1900. context.fillStyle = this._teleportationFillColor;
  1901. context.fill();
  1902. context.lineWidth = 10;
  1903. context.strokeStyle = this._teleportationBorderColor;
  1904. context.stroke();
  1905. context.closePath();
  1906. dynamicTexture.update();
  1907. var teleportationCircleMaterial = new BABYLON.StandardMaterial("TextPlaneMaterial", this._scene);
  1908. teleportationCircleMaterial.diffuseTexture = dynamicTexture;
  1909. this._teleportationTarget.material = teleportationCircleMaterial;
  1910. var torus = BABYLON.Mesh.CreateTorus("torusTeleportation", 0.75, 0.1, 25, this._scene, false);
  1911. torus.isPickable = false;
  1912. torus.parent = this._teleportationTarget;
  1913. var animationInnerCircle = new BABYLON.Animation("animationInnerCircle", "position.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
  1914. var keys = [];
  1915. keys.push({
  1916. frame: 0,
  1917. value: 0
  1918. });
  1919. keys.push({
  1920. frame: 30,
  1921. value: 0.4
  1922. });
  1923. keys.push({
  1924. frame: 60,
  1925. value: 0
  1926. });
  1927. animationInnerCircle.setKeys(keys);
  1928. var easingFunction = new BABYLON.SineEase();
  1929. easingFunction.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
  1930. animationInnerCircle.setEasingFunction(easingFunction);
  1931. torus.animations = [];
  1932. torus.animations.push(animationInnerCircle);
  1933. this._scene.beginAnimation(torus, 0, 60, true);
  1934. this._hideTeleportationTarget();
  1935. };
  1936. VRExperienceHelper.prototype._displayTeleportationTarget = function () {
  1937. if (this._teleportationInitialized) {
  1938. this._teleportationTarget.isVisible = true;
  1939. if (this._isDefaultTeleportationTarget) {
  1940. this._teleportationTarget.getChildren()[0].isVisible = true;
  1941. }
  1942. }
  1943. };
  1944. VRExperienceHelper.prototype._hideTeleportationTarget = function () {
  1945. if (this._teleportationInitialized) {
  1946. this._teleportationTarget.isVisible = false;
  1947. if (this._isDefaultTeleportationTarget) {
  1948. this._teleportationTarget.getChildren()[0].isVisible = false;
  1949. }
  1950. }
  1951. };
  1952. VRExperienceHelper.prototype._rotateCamera = function (right) {
  1953. var _this = this;
  1954. if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
  1955. return;
  1956. }
  1957. if (right) {
  1958. this._rotationAngle++;
  1959. }
  1960. else {
  1961. this._rotationAngle--;
  1962. }
  1963. this.currentVRCamera.animations = [];
  1964. var target = BABYLON.Quaternion.FromRotationMatrix(BABYLON.Matrix.RotationY(Math.PI / 4 * this._rotationAngle));
  1965. var animationRotation = new BABYLON.Animation("animationRotation", "rotationQuaternion", 90, BABYLON.Animation.ANIMATIONTYPE_QUATERNION, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  1966. var animationRotationKeys = [];
  1967. animationRotationKeys.push({
  1968. frame: 0,
  1969. value: this.currentVRCamera.rotationQuaternion
  1970. });
  1971. animationRotationKeys.push({
  1972. frame: 6,
  1973. value: target
  1974. });
  1975. animationRotation.setKeys(animationRotationKeys);
  1976. animationRotation.setEasingFunction(this._circleEase);
  1977. this.currentVRCamera.animations.push(animationRotation);
  1978. this._postProcessMove.animations = [];
  1979. var animationPP = new BABYLON.Animation("animationPP", "vignetteWeight", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  1980. var vignetteWeightKeys = [];
  1981. vignetteWeightKeys.push({
  1982. frame: 0,
  1983. value: 0
  1984. });
  1985. vignetteWeightKeys.push({
  1986. frame: 3,
  1987. value: 4
  1988. });
  1989. vignetteWeightKeys.push({
  1990. frame: 6,
  1991. value: 0
  1992. });
  1993. animationPP.setKeys(vignetteWeightKeys);
  1994. animationPP.setEasingFunction(this._circleEase);
  1995. this._postProcessMove.animations.push(animationPP);
  1996. var animationPP2 = new BABYLON.Animation("animationPP2", "vignetteStretch", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  1997. var vignetteStretchKeys = [];
  1998. vignetteStretchKeys.push({
  1999. frame: 0,
  2000. value: 0
  2001. });
  2002. vignetteStretchKeys.push({
  2003. frame: 3,
  2004. value: 10
  2005. });
  2006. vignetteStretchKeys.push({
  2007. frame: 6,
  2008. value: 0
  2009. });
  2010. animationPP2.setKeys(vignetteStretchKeys);
  2011. animationPP2.setEasingFunction(this._circleEase);
  2012. this._postProcessMove.animations.push(animationPP2);
  2013. this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;
  2014. this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;
  2015. this._webVRCamera.attachPostProcess(this._postProcessMove);
  2016. this._scene.beginAnimation(this._postProcessMove, 0, 6, false, 1, function () {
  2017. _this._webVRCamera.detachPostProcess(_this._postProcessMove);
  2018. });
  2019. this._scene.beginAnimation(this.currentVRCamera, 0, 6, false, 1);
  2020. };
  2021. VRExperienceHelper.prototype._moveTeleportationSelectorTo = function (hit) {
  2022. if (hit.pickedPoint) {
  2023. this._teleportationAllowed = true;
  2024. if (this._teleportationRequestInitiated) {
  2025. this._displayTeleportationTarget();
  2026. }
  2027. else {
  2028. this._hideTeleportationTarget();
  2029. }
  2030. this._haloCenter.copyFrom(hit.pickedPoint);
  2031. this._teleportationTarget.position.copyFrom(hit.pickedPoint);
  2032. var pickNormal = hit.getNormal(true, false);
  2033. if (pickNormal) {
  2034. var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
  2035. var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
  2036. BABYLON.Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, this._teleportationTarget.rotation);
  2037. }
  2038. this._teleportationTarget.position.y += 0.1;
  2039. }
  2040. };
  2041. VRExperienceHelper.prototype._teleportCamera = function (location) {
  2042. var _this = this;
  2043. if (location === void 0) { location = null; }
  2044. if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
  2045. return;
  2046. }
  2047. if (!location) {
  2048. location = this._haloCenter;
  2049. }
  2050. // Teleport the hmd to where the user is looking by moving the anchor to where they are looking minus the
  2051. // offset of the headset from the anchor.
  2052. if (this.webVRCamera.leftCamera) {
  2053. this._workingVector.copyFrom(this.webVRCamera.leftCamera.globalPosition);
  2054. this._workingVector.subtractInPlace(this.webVRCamera.position);
  2055. location.subtractToRef(this._workingVector, this._workingVector);
  2056. }
  2057. else {
  2058. this._workingVector.copyFrom(location);
  2059. }
  2060. // Add height to account for user's height offset
  2061. if (this.isInVRMode) {
  2062. this._workingVector.y += this.webVRCamera.deviceDistanceToRoomGround();
  2063. }
  2064. else {
  2065. this._workingVector.y += this._defaultHeight;
  2066. }
  2067. this.onBeforeCameraTeleport.notifyObservers(this._workingVector);
  2068. // Create animation from the camera's position to the new location
  2069. this.currentVRCamera.animations = [];
  2070. var animationCameraTeleportation = new BABYLON.Animation("animationCameraTeleportation", "position", 90, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  2071. var animationCameraTeleportationKeys = [{
  2072. frame: 0,
  2073. value: this.currentVRCamera.position
  2074. },
  2075. {
  2076. frame: 11,
  2077. value: this._workingVector
  2078. }
  2079. ];
  2080. animationCameraTeleportation.setKeys(animationCameraTeleportationKeys);
  2081. animationCameraTeleportation.setEasingFunction(this._circleEase);
  2082. this.currentVRCamera.animations.push(animationCameraTeleportation);
  2083. this._postProcessMove.animations = [];
  2084. var animationPP = new BABYLON.Animation("animationPP", "vignetteWeight", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  2085. var vignetteWeightKeys = [];
  2086. vignetteWeightKeys.push({
  2087. frame: 0,
  2088. value: 0
  2089. });
  2090. vignetteWeightKeys.push({
  2091. frame: 5,
  2092. value: 8
  2093. });
  2094. vignetteWeightKeys.push({
  2095. frame: 11,
  2096. value: 0
  2097. });
  2098. animationPP.setKeys(vignetteWeightKeys);
  2099. this._postProcessMove.animations.push(animationPP);
  2100. var animationPP2 = new BABYLON.Animation("animationPP2", "vignetteStretch", 90, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
  2101. var vignetteStretchKeys = [];
  2102. vignetteStretchKeys.push({
  2103. frame: 0,
  2104. value: 0
  2105. });
  2106. vignetteStretchKeys.push({
  2107. frame: 5,
  2108. value: 10
  2109. });
  2110. vignetteStretchKeys.push({
  2111. frame: 11,
  2112. value: 0
  2113. });
  2114. animationPP2.setKeys(vignetteStretchKeys);
  2115. this._postProcessMove.animations.push(animationPP2);
  2116. this._postProcessMove.imageProcessingConfiguration.vignetteWeight = 0;
  2117. this._postProcessMove.imageProcessingConfiguration.vignetteStretch = 0;
  2118. this._webVRCamera.attachPostProcess(this._postProcessMove);
  2119. this._scene.beginAnimation(this._postProcessMove, 0, 11, false, 1, function () {
  2120. _this._webVRCamera.detachPostProcess(_this._postProcessMove);
  2121. });
  2122. this._scene.beginAnimation(this.currentVRCamera, 0, 11, false, 1, function () {
  2123. _this.onAfterCameraTeleport.notifyObservers(_this._workingVector);
  2124. });
  2125. };
  2126. VRExperienceHelper.prototype._castRayAndSelectObject = function () {
  2127. if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
  2128. return;
  2129. }
  2130. var ray;
  2131. if (this._leftLaserPointer && this._leftLaserPointer.isVisible && this.currentVRCamera.leftController) {
  2132. ray = this.currentVRCamera.leftController.getForwardRay(this._rayLength);
  2133. }
  2134. else if (this._rightLaserPointer && this._rightLaserPointer.isVisible && this.currentVRCamera.rightController) {
  2135. ray = this.currentVRCamera.rightController.getForwardRay(this._rayLength);
  2136. }
  2137. else {
  2138. ray = this.currentVRCamera.getForwardRay(this._rayLength);
  2139. }
  2140. var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
  2141. // Moving the gazeTracker on the mesh face targetted
  2142. if (hit && hit.pickedPoint) {
  2143. if (this._displayGaze) {
  2144. var multiplier = 1;
  2145. this._gazeTracker.isVisible = true;
  2146. if (this._isActionableMesh) {
  2147. multiplier = 3;
  2148. }
  2149. this._gazeTracker.scaling.x = hit.distance * multiplier;
  2150. this._gazeTracker.scaling.y = hit.distance * multiplier;
  2151. this._gazeTracker.scaling.z = hit.distance * multiplier;
  2152. var pickNormal = hit.getNormal();
  2153. // To avoid z-fighting
  2154. var deltaFighting = 0.002;
  2155. if (pickNormal) {
  2156. var axis1 = BABYLON.Vector3.Cross(BABYLON.Axis.Y, pickNormal);
  2157. var axis2 = BABYLON.Vector3.Cross(pickNormal, axis1);
  2158. BABYLON.Vector3.RotationFromAxisToRef(axis2, pickNormal, axis1, this._gazeTracker.rotation);
  2159. }
  2160. this._gazeTracker.position.copyFrom(hit.pickedPoint);
  2161. if (this._gazeTracker.position.x < 0) {
  2162. this._gazeTracker.position.x += deltaFighting;
  2163. }
  2164. else {
  2165. this._gazeTracker.position.x -= deltaFighting;
  2166. }
  2167. if (this._gazeTracker.position.y < 0) {
  2168. this._gazeTracker.position.y += deltaFighting;
  2169. }
  2170. else {
  2171. this._gazeTracker.position.y -= deltaFighting;
  2172. }
  2173. if (this._gazeTracker.position.z < 0) {
  2174. this._gazeTracker.position.z += deltaFighting;
  2175. }
  2176. else {
  2177. this._gazeTracker.position.z -= deltaFighting;
  2178. }
  2179. }
  2180. // Changing the size of the laser pointer based on the distance from the targetted point
  2181. if (this._rightLaserPointer && this._rightLaserPointer.isVisible) {
  2182. this._rightLaserPointer.scaling.y = hit.distance;
  2183. this._rightLaserPointer.position.z = -hit.distance / 2;
  2184. }
  2185. if (this._leftLaserPointer && this._leftLaserPointer.isVisible) {
  2186. this._leftLaserPointer.scaling.y = hit.distance;
  2187. this._leftLaserPointer.position.z = -hit.distance / 2;
  2188. }
  2189. }
  2190. else {
  2191. this._gazeTracker.isVisible = false;
  2192. }
  2193. if (hit && hit.pickedMesh) {
  2194. this._currentHit = hit;
  2195. if (this._pointerDownOnMeshAsked) {
  2196. this._scene.simulatePointerMove(this._currentHit);
  2197. }
  2198. // The object selected is the floor, we're in a teleportation scenario
  2199. if (this._teleportationInitialized && this._isTeleportationFloor(hit.pickedMesh) && hit.pickedPoint) {
  2200. // Moving the teleportation area to this targetted point
  2201. this._moveTeleportationSelectorTo(hit);
  2202. return;
  2203. }
  2204. // If not, we're in a selection scenario
  2205. this._hideTeleportationTarget();
  2206. this._teleportationAllowed = false;
  2207. if (hit.pickedMesh !== this._currentMeshSelected) {
  2208. if (this.meshSelectionPredicate(hit.pickedMesh)) {
  2209. this.onNewMeshPicked.notifyObservers(hit);
  2210. this._currentMeshSelected = hit.pickedMesh;
  2211. if (hit.pickedMesh.isPickable && hit.pickedMesh.actionManager) {
  2212. this.changeGazeColor(new BABYLON.Color3(0, 0, 1));
  2213. this.changeLaserColor(new BABYLON.Color3(0.2, 0.2, 1));
  2214. this._isActionableMesh = true;
  2215. }
  2216. else {
  2217. this.changeGazeColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2218. this.changeLaserColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2219. this._isActionableMesh = false;
  2220. }
  2221. try {
  2222. this.onNewMeshSelected.notifyObservers(this._currentMeshSelected);
  2223. }
  2224. catch (err) {
  2225. BABYLON.Tools.Warn("Error in your custom logic onNewMeshSelected: " + err);
  2226. }
  2227. }
  2228. else {
  2229. if (this._currentMeshSelected) {
  2230. this.onSelectedMeshUnselected.notifyObservers(this._currentMeshSelected);
  2231. }
  2232. this._currentMeshSelected = null;
  2233. this.changeGazeColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2234. this.changeLaserColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2235. }
  2236. }
  2237. }
  2238. else {
  2239. this._currentHit = null;
  2240. this._currentMeshSelected = null;
  2241. this._teleportationAllowed = false;
  2242. this._hideTeleportationTarget();
  2243. this.changeGazeColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2244. this.changeLaserColor(new BABYLON.Color3(0.7, 0.7, 0.7));
  2245. }
  2246. };
  2247. VRExperienceHelper.prototype.changeLaserColor = function (color) {
  2248. if (this._leftLaserPointer && this._leftLaserPointer.material) {
  2249. this._leftLaserPointer.material.emissiveColor = color;
  2250. }
  2251. if (this._rightLaserPointer && this._rightLaserPointer.material) {
  2252. this._rightLaserPointer.material.emissiveColor = color;
  2253. }
  2254. };
  2255. VRExperienceHelper.prototype.changeGazeColor = function (color) {
  2256. if (this._gazeTracker.material) {
  2257. this._gazeTracker.material.emissiveColor = color;
  2258. }
  2259. };
  2260. VRExperienceHelper.prototype.dispose = function () {
  2261. if (this.isInVRMode) {
  2262. this.exitVR();
  2263. }
  2264. if (this._passProcessMove) {
  2265. this._passProcessMove.dispose();
  2266. }
  2267. if (this._postProcessMove) {
  2268. this._postProcessMove.dispose();
  2269. }
  2270. if (this._webVRCamera) {
  2271. this._webVRCamera.dispose();
  2272. }
  2273. if (this._vrDeviceOrientationCamera) {
  2274. this._vrDeviceOrientationCamera.dispose();
  2275. }
  2276. if (!this._useCustomVRButton && this._btnVR.parentNode) {
  2277. document.body.removeChild(this._btnVR);
  2278. }
  2279. if (this._deviceOrientationCamera && (this._scene.activeCamera != this._deviceOrientationCamera)) {
  2280. this._deviceOrientationCamera.dispose();
  2281. }
  2282. if (this._gazeTracker) {
  2283. this._gazeTracker.dispose();
  2284. }
  2285. if (this._teleportationTarget) {
  2286. this._teleportationTarget.dispose();
  2287. }
  2288. this._floorMeshesCollection = [];
  2289. document.removeEventListener("keydown", this._onKeyDown);
  2290. window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
  2291. window.removeEventListener("resize", this._onResize);
  2292. document.removeEventListener("fullscreenchange", this._onFullscreenChange);
  2293. document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
  2294. document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
  2295. document.removeEventListener("msfullscreenchange", this._onFullscreenChange);
  2296. this._scene.getEngine().onVRDisplayChangedObservable.removeCallback(this._onVRDisplayChanged);
  2297. this._scene.getEngine().onVRRequestPresentStart.removeCallback(this._onVRRequestPresentStart);
  2298. this._scene.getEngine().onVRRequestPresentComplete.removeCallback(this._onVRRequestPresentComplete);
  2299. window.removeEventListener('vrdisplaypresentchange', this._onVrDisplayPresentChange);
  2300. this._scene.gamepadManager.onGamepadConnectedObservable.removeCallback(this._onNewGamepadConnected);
  2301. this._scene.gamepadManager.onGamepadDisconnectedObservable.removeCallback(this._onNewGamepadDisconnected);
  2302. this._scene.unregisterBeforeRender(this.beforeRender);
  2303. };
  2304. VRExperienceHelper.prototype.getClassName = function () {
  2305. return "VRExperienceHelper";
  2306. };
  2307. return VRExperienceHelper;
  2308. }());
  2309. BABYLON.VRExperienceHelper = VRExperienceHelper;
  2310. })(BABYLON || (BABYLON = {}));
  2311. //# sourceMappingURL=babylon.vrExperienceHelper.js.map
  2312. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  2313. 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";
  2314. 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";
  2315. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  2316. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  2317. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  2318. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  2319. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  2320. 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";
  2321. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  2322. 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";
  2323. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  2324. 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";
  2325. 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";
  2326. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  2327. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  2328. 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";
  2329. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  2330. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  2331. 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}";
  2332. 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";
  2333. 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";
  2334. 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";
  2335. 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";
  2336. 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";
  2337. 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};";
  2338. 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";
  2339. 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";
  2340. 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}";
  2341. 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";
  2342. 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}";
  2343. 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";
  2344. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  2345. 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";
  2346. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  2347. 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";
  2348. 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";
  2349. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  2350. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  2351. (function() {
  2352. var EXPORTS = {};EXPORTS['VRDistortionCorrectionPostProcess'] = BABYLON['VRDistortionCorrectionPostProcess'];EXPORTS['AnaglyphPostProcess'] = BABYLON['AnaglyphPostProcess'];EXPORTS['StereoscopicInterlacePostProcess'] = BABYLON['StereoscopicInterlacePostProcess'];EXPORTS['FreeCameraDeviceOrientationInput'] = BABYLON['FreeCameraDeviceOrientationInput'];EXPORTS['ArcRotateCameraVRDeviceOrientationInput'] = BABYLON['ArcRotateCameraVRDeviceOrientationInput'];EXPORTS['VRCameraMetrics'] = BABYLON['VRCameraMetrics'];EXPORTS['WebVRFreeCamera'] = BABYLON['WebVRFreeCamera'];EXPORTS['DeviceOrientationCamera'] = BABYLON['DeviceOrientationCamera'];EXPORTS['VRDeviceOrientationFreeCamera'] = BABYLON['VRDeviceOrientationFreeCamera'];EXPORTS['VRDeviceOrientationGamepadCamera'] = BABYLON['VRDeviceOrientationGamepadCamera'];EXPORTS['VRDeviceOrientationArcRotateCamera'] = BABYLON['VRDeviceOrientationArcRotateCamera'];EXPORTS['AnaglyphFreeCamera'] = BABYLON['AnaglyphFreeCamera'];EXPORTS['AnaglyphArcRotateCamera'] = BABYLON['AnaglyphArcRotateCamera'];EXPORTS['AnaglyphGamepadCamera'] = BABYLON['AnaglyphGamepadCamera'];EXPORTS['AnaglyphUniversalCamera'] = BABYLON['AnaglyphUniversalCamera'];EXPORTS['StereoscopicFreeCamera'] = BABYLON['StereoscopicFreeCamera'];EXPORTS['StereoscopicArcRotateCamera'] = BABYLON['StereoscopicArcRotateCamera'];EXPORTS['StereoscopicGamepadCamera'] = BABYLON['StereoscopicGamepadCamera'];EXPORTS['StereoscopicUniversalCamera'] = BABYLON['StereoscopicUniversalCamera'];EXPORTS['VRExperienceHelper'] = BABYLON['VRExperienceHelper'];
  2353. globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
  2354. module.exports = EXPORTS;
  2355. })();
  2356. }