es6.js 170 KB

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