babylon.engine.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var _DepthCullingState = (function () {
  4. function _DepthCullingState() {
  5. this._isDepthTestDirty = false;
  6. this._isDepthMaskDirty = false;
  7. this._isDepthFuncDirty = false;
  8. this._isCullFaceDirty = false;
  9. this._isCullDirty = false;
  10. }
  11. Object.defineProperty(_DepthCullingState.prototype, "isDirty", {
  12. get: function () {
  13. return this._isDepthFuncDirty || this._isDepthTestDirty || this._isDepthMaskDirty || this._isCullFaceDirty || this._isCullDirty;
  14. },
  15. enumerable: true,
  16. configurable: true
  17. });
  18. Object.defineProperty(_DepthCullingState.prototype, "cullFace", {
  19. get: function () {
  20. return this._cullFace;
  21. },
  22. set: function (value) {
  23. if (this._cullFace === value) {
  24. return;
  25. }
  26. this._cullFace = value;
  27. this._isCullFaceDirty = true;
  28. },
  29. enumerable: true,
  30. configurable: true
  31. });
  32. Object.defineProperty(_DepthCullingState.prototype, "cull", {
  33. get: function () {
  34. return this._cull;
  35. },
  36. set: function (value) {
  37. if (this._cull === value) {
  38. return;
  39. }
  40. this._cull = value;
  41. this._isCullDirty = true;
  42. },
  43. enumerable: true,
  44. configurable: true
  45. });
  46. Object.defineProperty(_DepthCullingState.prototype, "depthFunc", {
  47. get: function () {
  48. return this._depthFunc;
  49. },
  50. set: function (value) {
  51. if (this._depthFunc === value) {
  52. return;
  53. }
  54. this._depthFunc = value;
  55. this._isDepthFuncDirty = true;
  56. },
  57. enumerable: true,
  58. configurable: true
  59. });
  60. Object.defineProperty(_DepthCullingState.prototype, "depthMask", {
  61. get: function () {
  62. return this._depthMask;
  63. },
  64. set: function (value) {
  65. if (this._depthMask === value) {
  66. return;
  67. }
  68. this._depthMask = value;
  69. this._isDepthMaskDirty = true;
  70. },
  71. enumerable: true,
  72. configurable: true
  73. });
  74. Object.defineProperty(_DepthCullingState.prototype, "depthTest", {
  75. get: function () {
  76. return this._depthTest;
  77. },
  78. set: function (value) {
  79. if (this._depthTest === value) {
  80. return;
  81. }
  82. this._depthTest = value;
  83. this._isDepthTestDirty = true;
  84. },
  85. enumerable: true,
  86. configurable: true
  87. });
  88. _DepthCullingState.prototype.reset = function () {
  89. this._depthMask = true;
  90. this._depthTest = true;
  91. this._depthFunc = null;
  92. this._cull = null;
  93. this._cullFace = null;
  94. this._isDepthTestDirty = true;
  95. this._isDepthMaskDirty = true;
  96. this._isDepthFuncDirty = false;
  97. this._isCullFaceDirty = false;
  98. this._isCullDirty = false;
  99. };
  100. _DepthCullingState.prototype.apply = function (gl) {
  101. if (!this.isDirty) {
  102. return;
  103. }
  104. // Cull
  105. if (this._isCullDirty) {
  106. if (this.cull) {
  107. gl.enable(gl.CULL_FACE);
  108. } else {
  109. gl.disable(gl.CULL_FACE);
  110. }
  111. this._isCullDirty = false;
  112. }
  113. // Cull face
  114. if (this._isCullFaceDirty) {
  115. gl.cullFace(this.cullFace);
  116. this._isCullFaceDirty = false;
  117. }
  118. // Depth mask
  119. if (this._isDepthMaskDirty) {
  120. gl.depthMask(this.depthMask);
  121. this._isDepthMaskDirty = false;
  122. }
  123. // Depth test
  124. if (this._isDepthTestDirty) {
  125. if (this.depthTest) {
  126. gl.enable(gl.DEPTH_TEST);
  127. } else {
  128. gl.disable(gl.DEPTH_TEST);
  129. }
  130. this._isDepthTestDirty = false;
  131. }
  132. // Depth func
  133. if (this._isDepthFuncDirty) {
  134. gl.depthFunc(this.depthFunc);
  135. this._isDepthFuncDirty = false;
  136. }
  137. };
  138. return _DepthCullingState;
  139. })();
  140. BABYLON._DepthCullingState = _DepthCullingState;
  141. var _AlphaState = (function () {
  142. function _AlphaState() {
  143. this._isAlphaBlendDirty = false;
  144. this._isBlendFunctionParametersDirty = false;
  145. this._alphaBlend = false;
  146. this._blendFunctionParameters = new Array(4);
  147. }
  148. Object.defineProperty(_AlphaState.prototype, "isDirty", {
  149. get: function () {
  150. return this._isAlphaBlendDirty || this._isBlendFunctionParametersDirty;
  151. },
  152. enumerable: true,
  153. configurable: true
  154. });
  155. Object.defineProperty(_AlphaState.prototype, "alphaBlend", {
  156. get: function () {
  157. return this._alphaBlend;
  158. },
  159. set: function (value) {
  160. if (this._alphaBlend === value) {
  161. return;
  162. }
  163. this._alphaBlend = value;
  164. this._isAlphaBlendDirty = true;
  165. },
  166. enumerable: true,
  167. configurable: true
  168. });
  169. _AlphaState.prototype.setAlphaBlendFunctionParameters = function (value0, value1, value2, value3) {
  170. if (this._blendFunctionParameters[0] === value0 && this._blendFunctionParameters[1] === value1 && this._blendFunctionParameters[2] === value2 && this._blendFunctionParameters[3] === value3) {
  171. return;
  172. }
  173. this._blendFunctionParameters[0] = value0;
  174. this._blendFunctionParameters[1] = value1;
  175. this._blendFunctionParameters[2] = value2;
  176. this._blendFunctionParameters[3] = value3;
  177. this._isBlendFunctionParametersDirty = true;
  178. };
  179. _AlphaState.prototype.reset = function () {
  180. this._alphaBlend = false;
  181. this._blendFunctionParameters[0] = null;
  182. this._blendFunctionParameters[1] = null;
  183. this._blendFunctionParameters[2] = null;
  184. this._blendFunctionParameters[3] = null;
  185. this._isAlphaBlendDirty = true;
  186. this._isBlendFunctionParametersDirty = false;
  187. };
  188. _AlphaState.prototype.apply = function (gl) {
  189. if (!this.isDirty) {
  190. return;
  191. }
  192. // Alpha blend
  193. if (this._isAlphaBlendDirty) {
  194. if (this._alphaBlend) {
  195. gl.enable(gl.BLEND);
  196. } else {
  197. gl.disable(gl.BLEND);
  198. }
  199. this._isAlphaBlendDirty = false;
  200. }
  201. // Alpha function
  202. if (this._isBlendFunctionParametersDirty) {
  203. gl.blendFuncSeparate(this._blendFunctionParameters[0], this._blendFunctionParameters[1], this._blendFunctionParameters[2], this._blendFunctionParameters[3]);
  204. this._isBlendFunctionParametersDirty = false;
  205. }
  206. };
  207. return _AlphaState;
  208. })();
  209. BABYLON._AlphaState = _AlphaState;
  210. var compileShader = function (gl, source, type, defines) {
  211. var shader = gl.createShader(type === "vertex" ? gl.VERTEX_SHADER : gl.FRAGMENT_SHADER);
  212. gl.shaderSource(shader, (defines ? defines + "\n" : "") + source);
  213. gl.compileShader(shader);
  214. if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
  215. throw new Error(gl.getShaderInfoLog(shader));
  216. }
  217. return shader;
  218. };
  219. var getSamplingParameters = function (samplingMode, generateMipMaps, gl) {
  220. var magFilter = gl.NEAREST;
  221. var minFilter = gl.NEAREST;
  222. if (samplingMode === BABYLON.Texture.BILINEAR_SAMPLINGMODE) {
  223. magFilter = gl.LINEAR;
  224. if (generateMipMaps) {
  225. minFilter = gl.LINEAR_MIPMAP_NEAREST;
  226. } else {
  227. minFilter = gl.LINEAR;
  228. }
  229. } else if (samplingMode === BABYLON.Texture.TRILINEAR_SAMPLINGMODE) {
  230. magFilter = gl.LINEAR;
  231. if (generateMipMaps) {
  232. minFilter = gl.LINEAR_MIPMAP_LINEAR;
  233. } else {
  234. minFilter = gl.LINEAR;
  235. }
  236. } else if (samplingMode === BABYLON.Texture.NEAREST_SAMPLINGMODE) {
  237. magFilter = gl.NEAREST;
  238. if (generateMipMaps) {
  239. minFilter = gl.NEAREST_MIPMAP_LINEAR;
  240. } else {
  241. minFilter = gl.NEAREST;
  242. }
  243. }
  244. return {
  245. min: minFilter,
  246. mag: magFilter
  247. };
  248. };
  249. var prepareWebGLTexture = function (texture, gl, scene, width, height, invertY, noMipmap, isCompressed, processFunction, samplingMode) {
  250. if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  251. var engine = scene.getEngine();
  252. var potWidth = BABYLON.Tools.GetExponantOfTwo(width, engine.getCaps().maxTextureSize);
  253. var potHeight = BABYLON.Tools.GetExponantOfTwo(height, engine.getCaps().maxTextureSize);
  254. gl.bindTexture(gl.TEXTURE_2D, texture);
  255. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  256. processFunction(potWidth, potHeight);
  257. var filters = getSamplingParameters(samplingMode, !noMipmap, gl);
  258. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
  259. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
  260. if (!noMipmap && !isCompressed) {
  261. gl.generateMipmap(gl.TEXTURE_2D);
  262. }
  263. gl.bindTexture(gl.TEXTURE_2D, null);
  264. engine._activeTexturesCache = [];
  265. texture._baseWidth = width;
  266. texture._baseHeight = height;
  267. texture._width = potWidth;
  268. texture._height = potHeight;
  269. texture.isReady = true;
  270. texture.samplingMode = samplingMode;
  271. scene._removePendingData(texture);
  272. };
  273. var partialLoad = function (url, index, loadedImages, scene, onfinish) {
  274. var onload = function () {
  275. loadedImages[index] = img;
  276. loadedImages._internalCount++;
  277. scene._removePendingData(img);
  278. if (loadedImages._internalCount === 6) {
  279. onfinish(loadedImages);
  280. }
  281. };
  282. var onerror = function () {
  283. scene._removePendingData(img);
  284. };
  285. var img = BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
  286. scene._addPendingData(img);
  287. };
  288. var cascadeLoad = function (rootUrl, scene, onfinish, extensions) {
  289. var loadedImages = [];
  290. loadedImages._internalCount = 0;
  291. for (var index = 0; index < 6; index++) {
  292. partialLoad(rootUrl + extensions[index], index, loadedImages, scene, onfinish);
  293. }
  294. };
  295. var EngineCapabilities = (function () {
  296. function EngineCapabilities() {
  297. }
  298. return EngineCapabilities;
  299. })();
  300. BABYLON.EngineCapabilities = EngineCapabilities;
  301. var Engine = (function () {
  302. function Engine(canvas, antialias, options) {
  303. var _this = this;
  304. // Public members
  305. this.isFullscreen = false;
  306. this.isPointerLock = false;
  307. this.cullBackFaces = true;
  308. this.renderEvenInBackground = true;
  309. this.scenes = new Array();
  310. this._windowIsBackground = false;
  311. this._loadingDivBackgroundColor = "black";
  312. this._drawCalls = 0;
  313. this._renderingQueueLaunched = false;
  314. this._activeRenderLoops = [];
  315. // FPS
  316. this.fpsRange = 60;
  317. this.previousFramesDuration = [];
  318. this.fps = 60;
  319. this.deltaTime = 0;
  320. // States
  321. this._depthCullingState = new _DepthCullingState();
  322. this._alphaState = new _AlphaState();
  323. this._alphaMode = Engine.ALPHA_DISABLE;
  324. // Cache
  325. this._loadedTexturesCache = new Array();
  326. this._activeTexturesCache = new Array();
  327. this._compiledEffects = {};
  328. this._uintIndicesCurrentlySet = false;
  329. this._renderingCanvas = canvas;
  330. this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
  331. options = options || {};
  332. options.antialias = antialias;
  333. try {
  334. this._gl = canvas.getContext("webgl", options) || canvas.getContext("experimental-webgl", options);
  335. } catch (e) {
  336. throw new Error("WebGL not supported");
  337. }
  338. if (!this._gl) {
  339. throw new Error("WebGL not supported");
  340. }
  341. this._onBlur = function () {
  342. _this._windowIsBackground = true;
  343. };
  344. this._onFocus = function () {
  345. _this._windowIsBackground = false;
  346. };
  347. window.addEventListener("blur", this._onBlur);
  348. window.addEventListener("focus", this._onFocus);
  349. // Textures
  350. this._workingCanvas = document.createElement("canvas");
  351. this._workingContext = this._workingCanvas.getContext("2d");
  352. // Viewport
  353. this._hardwareScalingLevel = 1.0 / (window.devicePixelRatio || 1.0);
  354. this.resize();
  355. // Caps
  356. this._caps = new EngineCapabilities();
  357. this._caps.maxTexturesImageUnits = this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS);
  358. this._caps.maxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
  359. this._caps.maxCubemapTextureSize = this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE);
  360. this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
  361. // Infos
  362. this._glVersion = this._gl.getParameter(this._gl.VERSION);
  363. var rendererInfo = this._gl.getExtension("WEBGL_debug_renderer_info");
  364. if (rendererInfo != null) {
  365. this._glRenderer = this._gl.getParameter(rendererInfo.UNMASKED_RENDERER_WEBGL);
  366. this._glVendor = this._gl.getParameter(rendererInfo.UNMASKED_VENDOR_WEBGL);
  367. }
  368. if (!this._glVendor) {
  369. this._glVendor = "Unknown vendor";
  370. }
  371. if (!this._glRenderer) {
  372. this._glRenderer = "Unknown renderer";
  373. }
  374. // Extensions
  375. this._caps.standardDerivatives = (this._gl.getExtension('OES_standard_derivatives') !== null);
  376. this._caps.s3tc = this._gl.getExtension('WEBGL_compressed_texture_s3tc');
  377. this._caps.textureFloat = (this._gl.getExtension('OES_texture_float') !== null);
  378. this._caps.textureAnisotropicFilterExtension = this._gl.getExtension('EXT_texture_filter_anisotropic') || this._gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic') || this._gl.getExtension('MOZ_EXT_texture_filter_anisotropic');
  379. this._caps.maxAnisotropy = this._caps.textureAnisotropicFilterExtension ? this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 0;
  380. this._caps.instancedArrays = this._gl.getExtension('ANGLE_instanced_arrays');
  381. this._caps.uintIndices = this._gl.getExtension('OES_element_index_uint') !== null;
  382. // Depth buffer
  383. this.setDepthBuffer(true);
  384. this.setDepthFunctionToLessOrEqual();
  385. this.setDepthWrite(true);
  386. // Fullscreen
  387. this._onFullscreenChange = function () {
  388. if (document.fullscreen !== undefined) {
  389. _this.isFullscreen = document.fullscreen;
  390. } else if (document.mozFullScreen !== undefined) {
  391. _this.isFullscreen = document.mozFullScreen;
  392. } else if (document.webkitIsFullScreen !== undefined) {
  393. _this.isFullscreen = document.webkitIsFullScreen;
  394. } else if (document.msIsFullScreen !== undefined) {
  395. _this.isFullscreen = document.msIsFullScreen;
  396. }
  397. // Pointer lock
  398. if (_this.isFullscreen && _this._pointerLockRequested) {
  399. canvas.requestPointerLock = canvas.requestPointerLock || canvas.msRequestPointerLock || canvas.mozRequestPointerLock || canvas.webkitRequestPointerLock;
  400. if (canvas.requestPointerLock) {
  401. canvas.requestPointerLock();
  402. }
  403. }
  404. };
  405. document.addEventListener("fullscreenchange", this._onFullscreenChange, false);
  406. document.addEventListener("mozfullscreenchange", this._onFullscreenChange, false);
  407. document.addEventListener("webkitfullscreenchange", this._onFullscreenChange, false);
  408. document.addEventListener("msfullscreenchange", this._onFullscreenChange, false);
  409. // Pointer lock
  410. this._onPointerLockChange = function () {
  411. _this.isPointerLock = (document.mozPointerLockElement === canvas || document.webkitPointerLockElement === canvas || document.msPointerLockElement === canvas || document.pointerLockElement === canvas);
  412. };
  413. document.addEventListener("pointerlockchange", this._onPointerLockChange, false);
  414. document.addEventListener("mspointerlockchange", this._onPointerLockChange, false);
  415. document.addEventListener("mozpointerlockchange", this._onPointerLockChange, false);
  416. document.addEventListener("webkitpointerlockchange", this._onPointerLockChange, false);
  417. this._audioEngine = new BABYLON.AudioEngine();
  418. BABYLON.Tools.Log("Babylon.js engine (v" + Engine.Version + ") launched");
  419. }
  420. Object.defineProperty(Engine, "ALPHA_DISABLE", {
  421. get: function () {
  422. return Engine._ALPHA_DISABLE;
  423. },
  424. enumerable: true,
  425. configurable: true
  426. });
  427. Object.defineProperty(Engine, "ALPHA_ADD", {
  428. get: function () {
  429. return Engine._ALPHA_ADD;
  430. },
  431. enumerable: true,
  432. configurable: true
  433. });
  434. Object.defineProperty(Engine, "ALPHA_COMBINE", {
  435. get: function () {
  436. return Engine._ALPHA_COMBINE;
  437. },
  438. enumerable: true,
  439. configurable: true
  440. });
  441. Object.defineProperty(Engine, "DELAYLOADSTATE_NONE", {
  442. get: function () {
  443. return Engine._DELAYLOADSTATE_NONE;
  444. },
  445. enumerable: true,
  446. configurable: true
  447. });
  448. Object.defineProperty(Engine, "DELAYLOADSTATE_LOADED", {
  449. get: function () {
  450. return Engine._DELAYLOADSTATE_LOADED;
  451. },
  452. enumerable: true,
  453. configurable: true
  454. });
  455. Object.defineProperty(Engine, "DELAYLOADSTATE_LOADING", {
  456. get: function () {
  457. return Engine._DELAYLOADSTATE_LOADING;
  458. },
  459. enumerable: true,
  460. configurable: true
  461. });
  462. Object.defineProperty(Engine, "DELAYLOADSTATE_NOTLOADED", {
  463. get: function () {
  464. return Engine._DELAYLOADSTATE_NOTLOADED;
  465. },
  466. enumerable: true,
  467. configurable: true
  468. });
  469. Object.defineProperty(Engine, "TEXTUREFORMAT_ALPHA", {
  470. get: function () {
  471. return Engine._TEXTUREFORMAT_ALPHA;
  472. },
  473. enumerable: true,
  474. configurable: true
  475. });
  476. Object.defineProperty(Engine, "TEXTUREFORMAT_LUMINANCE", {
  477. get: function () {
  478. return Engine._TEXTUREFORMAT_LUMINANCE;
  479. },
  480. enumerable: true,
  481. configurable: true
  482. });
  483. Object.defineProperty(Engine, "TEXTUREFORMAT_LUMINANCE_ALPHA", {
  484. get: function () {
  485. return Engine._TEXTUREFORMAT_LUMINANCE_ALPHA;
  486. },
  487. enumerable: true,
  488. configurable: true
  489. });
  490. Object.defineProperty(Engine, "TEXTUREFORMAT_RGB", {
  491. get: function () {
  492. return Engine._TEXTUREFORMAT_RGB;
  493. },
  494. enumerable: true,
  495. configurable: true
  496. });
  497. Object.defineProperty(Engine, "TEXTUREFORMAT_RGBA", {
  498. get: function () {
  499. return Engine._TEXTUREFORMAT_RGBA;
  500. },
  501. enumerable: true,
  502. configurable: true
  503. });
  504. Object.defineProperty(Engine, "Version", {
  505. get: function () {
  506. return "2.0.0";
  507. },
  508. enumerable: true,
  509. configurable: true
  510. });
  511. Engine.prototype.getGlInfo = function () {
  512. return {
  513. vendor: this._glVendor,
  514. renderer: this._glRenderer,
  515. version: this._glVersion
  516. };
  517. };
  518. Engine.prototype.getAudioEngine = function () {
  519. return this._audioEngine;
  520. };
  521. Engine.prototype.getAspectRatio = function (camera) {
  522. var viewport = camera.viewport;
  523. return (this.getRenderWidth() * viewport.width) / (this.getRenderHeight() * viewport.height);
  524. };
  525. Engine.prototype.getRenderWidth = function () {
  526. if (this._currentRenderTarget) {
  527. return this._currentRenderTarget._width;
  528. }
  529. return this._renderingCanvas.width;
  530. };
  531. Engine.prototype.getRenderHeight = function () {
  532. if (this._currentRenderTarget) {
  533. return this._currentRenderTarget._height;
  534. }
  535. return this._renderingCanvas.height;
  536. };
  537. Engine.prototype.getRenderingCanvas = function () {
  538. return this._renderingCanvas;
  539. };
  540. Engine.prototype.getRenderingCanvasClientRect = function () {
  541. return this._renderingCanvas.getBoundingClientRect();
  542. };
  543. Engine.prototype.setHardwareScalingLevel = function (level) {
  544. this._hardwareScalingLevel = level;
  545. this.resize();
  546. };
  547. Engine.prototype.getHardwareScalingLevel = function () {
  548. return this._hardwareScalingLevel;
  549. };
  550. Engine.prototype.getLoadedTexturesCache = function () {
  551. return this._loadedTexturesCache;
  552. };
  553. Engine.prototype.getCaps = function () {
  554. return this._caps;
  555. };
  556. Object.defineProperty(Engine.prototype, "drawCalls", {
  557. get: function () {
  558. return this._drawCalls;
  559. },
  560. enumerable: true,
  561. configurable: true
  562. });
  563. // Methods
  564. Engine.prototype.resetDrawCalls = function () {
  565. this._drawCalls = 0;
  566. };
  567. Engine.prototype.setDepthFunctionToGreater = function () {
  568. this._depthCullingState.depthFunc = this._gl.GREATER;
  569. };
  570. Engine.prototype.setDepthFunctionToGreaterOrEqual = function () {
  571. this._depthCullingState.depthFunc = this._gl.GEQUAL;
  572. };
  573. Engine.prototype.setDepthFunctionToLess = function () {
  574. this._depthCullingState.depthFunc = this._gl.LESS;
  575. };
  576. Engine.prototype.setDepthFunctionToLessOrEqual = function () {
  577. this._depthCullingState.depthFunc = this._gl.LEQUAL;
  578. };
  579. Engine.prototype.stopRenderLoop = function (renderFunction) {
  580. if (!renderFunction) {
  581. this._activeRenderLoops = [];
  582. return;
  583. }
  584. var index = this._activeRenderLoops.indexOf(renderFunction);
  585. if (index >= 0) {
  586. this._activeRenderLoops.splice(index, 1);
  587. }
  588. };
  589. Engine.prototype._renderLoop = function () {
  590. var _this = this;
  591. var shouldRender = true;
  592. if (!this.renderEvenInBackground && this._windowIsBackground) {
  593. shouldRender = false;
  594. }
  595. if (shouldRender) {
  596. // Start new frame
  597. this.beginFrame();
  598. for (var index = 0; index < this._activeRenderLoops.length; index++) {
  599. var renderFunction = this._activeRenderLoops[index];
  600. renderFunction();
  601. }
  602. // Present
  603. this.endFrame();
  604. }
  605. if (this._activeRenderLoops.length > 0) {
  606. // Register new frame
  607. BABYLON.Tools.QueueNewFrame(function () {
  608. _this._renderLoop();
  609. });
  610. } else {
  611. this._renderingQueueLaunched = false;
  612. }
  613. };
  614. Engine.prototype.runRenderLoop = function (renderFunction) {
  615. var _this = this;
  616. if (this._activeRenderLoops.indexOf(renderFunction) !== -1) {
  617. return;
  618. }
  619. this._activeRenderLoops.push(renderFunction);
  620. if (!this._renderingQueueLaunched) {
  621. this._renderingQueueLaunched = true;
  622. BABYLON.Tools.QueueNewFrame(function () {
  623. _this._renderLoop();
  624. });
  625. }
  626. };
  627. Engine.prototype.switchFullscreen = function (requestPointerLock) {
  628. if (this.isFullscreen) {
  629. BABYLON.Tools.ExitFullscreen();
  630. } else {
  631. this._pointerLockRequested = requestPointerLock;
  632. BABYLON.Tools.RequestFullscreen(this._renderingCanvas);
  633. }
  634. };
  635. Engine.prototype.clear = function (color, backBuffer, depthStencil) {
  636. this.applyStates();
  637. this._gl.clearColor(color.r, color.g, color.b, color.a !== undefined ? color.a : 1.0);
  638. if (this._depthCullingState.depthMask) {
  639. this._gl.clearDepth(1.0);
  640. }
  641. var mode = 0;
  642. if (backBuffer)
  643. mode |= this._gl.COLOR_BUFFER_BIT;
  644. if (depthStencil && this._depthCullingState.depthMask)
  645. mode |= this._gl.DEPTH_BUFFER_BIT;
  646. this._gl.clear(mode);
  647. };
  648. Engine.prototype.setViewport = function (viewport, requiredWidth, requiredHeight) {
  649. var width = requiredWidth || this._renderingCanvas.width;
  650. var height = requiredHeight || this._renderingCanvas.height;
  651. var x = viewport.x || 0;
  652. var y = viewport.y || 0;
  653. this._cachedViewport = viewport;
  654. this._gl.viewport(x * width, y * height, width * viewport.width, height * viewport.height);
  655. };
  656. Engine.prototype.setDirectViewport = function (x, y, width, height) {
  657. this._cachedViewport = null;
  658. this._gl.viewport(x, y, width, height);
  659. };
  660. Engine.prototype.beginFrame = function () {
  661. this._measureFps();
  662. };
  663. Engine.prototype.endFrame = function () {
  664. this.flushFramebuffer();
  665. };
  666. Engine.prototype.resize = function () {
  667. this.setSize(this._renderingCanvas.clientWidth / this._hardwareScalingLevel, this._renderingCanvas.clientHeight / this._hardwareScalingLevel);
  668. };
  669. Engine.prototype.setSize = function (width, height) {
  670. this._renderingCanvas.width = width;
  671. this._renderingCanvas.height = height;
  672. this._canvasClientRect = this._renderingCanvas.getBoundingClientRect();
  673. };
  674. Engine.prototype.bindFramebuffer = function (texture) {
  675. this._currentRenderTarget = texture;
  676. var gl = this._gl;
  677. gl.bindFramebuffer(gl.FRAMEBUFFER, texture._framebuffer);
  678. this._gl.viewport(0, 0, texture._width, texture._height);
  679. this.wipeCaches();
  680. };
  681. Engine.prototype.unBindFramebuffer = function (texture) {
  682. this._currentRenderTarget = null;
  683. if (texture.generateMipMaps) {
  684. var gl = this._gl;
  685. gl.bindTexture(gl.TEXTURE_2D, texture);
  686. gl.generateMipmap(gl.TEXTURE_2D);
  687. gl.bindTexture(gl.TEXTURE_2D, null);
  688. }
  689. this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
  690. };
  691. Engine.prototype.flushFramebuffer = function () {
  692. // this._gl.flush();
  693. };
  694. Engine.prototype.restoreDefaultFramebuffer = function () {
  695. this._currentRenderTarget = null;
  696. this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
  697. this.setViewport(this._cachedViewport);
  698. this.wipeCaches();
  699. };
  700. // VBOs
  701. Engine.prototype._resetVertexBufferBinding = function () {
  702. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, null);
  703. this._cachedVertexBuffers = null;
  704. };
  705. Engine.prototype.createVertexBuffer = function (vertices) {
  706. var vbo = this._gl.createBuffer();
  707. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vbo);
  708. this._gl.bufferData(this._gl.ARRAY_BUFFER, new Float32Array(vertices), this._gl.STATIC_DRAW);
  709. this._resetVertexBufferBinding();
  710. vbo.references = 1;
  711. return vbo;
  712. };
  713. Engine.prototype.createDynamicVertexBuffer = function (capacity) {
  714. var vbo = this._gl.createBuffer();
  715. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vbo);
  716. this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);
  717. this._resetVertexBufferBinding();
  718. vbo.references = 1;
  719. return vbo;
  720. };
  721. Engine.prototype.updateDynamicVertexBuffer = function (vertexBuffer, vertices, offset) {
  722. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer);
  723. if (offset === undefined) {
  724. offset = 0;
  725. }
  726. if (vertices instanceof Float32Array) {
  727. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, vertices);
  728. } else {
  729. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, offset, new Float32Array(vertices));
  730. }
  731. this._resetVertexBufferBinding();
  732. };
  733. Engine.prototype._resetIndexBufferBinding = function () {
  734. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, null);
  735. this._cachedIndexBuffer = null;
  736. };
  737. Engine.prototype.createIndexBuffer = function (indices) {
  738. var vbo = this._gl.createBuffer();
  739. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, vbo);
  740. // Check for 32 bits indices
  741. var arrayBuffer;
  742. var need32Bits = false;
  743. if (this._caps.uintIndices) {
  744. for (var index = 0; index < indices.length; index++) {
  745. if (indices[index] > 65535) {
  746. need32Bits = true;
  747. break;
  748. }
  749. }
  750. arrayBuffer = need32Bits ? new Uint32Array(indices) : new Uint16Array(indices);
  751. } else {
  752. arrayBuffer = new Uint16Array(indices);
  753. }
  754. this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.STATIC_DRAW);
  755. this._resetIndexBufferBinding();
  756. vbo.references = 1;
  757. vbo.is32Bits = need32Bits;
  758. return vbo;
  759. };
  760. Engine.prototype.bindBuffers = function (vertexBuffer, indexBuffer, vertexDeclaration, vertexStrideSize, effect) {
  761. if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
  762. this._cachedVertexBuffers = vertexBuffer;
  763. this._cachedEffectForVertexBuffers = effect;
  764. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer);
  765. var offset = 0;
  766. for (var index = 0; index < vertexDeclaration.length; index++) {
  767. var order = effect.getAttributeLocation(index);
  768. if (order >= 0) {
  769. this._gl.vertexAttribPointer(order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
  770. }
  771. offset += vertexDeclaration[index] * 4;
  772. }
  773. }
  774. if (this._cachedIndexBuffer !== indexBuffer) {
  775. this._cachedIndexBuffer = indexBuffer;
  776. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
  777. this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
  778. }
  779. };
  780. Engine.prototype.bindMultiBuffers = function (vertexBuffers, indexBuffer, effect) {
  781. if (this._cachedVertexBuffers !== vertexBuffers || this._cachedEffectForVertexBuffers !== effect) {
  782. this._cachedVertexBuffers = vertexBuffers;
  783. this._cachedEffectForVertexBuffers = effect;
  784. var attributes = effect.getAttributesNames();
  785. for (var index = 0; index < attributes.length; index++) {
  786. var order = effect.getAttributeLocation(index);
  787. if (order >= 0) {
  788. var vertexBuffer = vertexBuffers[attributes[index]];
  789. if (!vertexBuffer) {
  790. continue;
  791. }
  792. var stride = vertexBuffer.getStrideSize();
  793. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, vertexBuffer.getBuffer());
  794. this._gl.vertexAttribPointer(order, stride, this._gl.FLOAT, false, stride * 4, 0);
  795. }
  796. }
  797. }
  798. if (indexBuffer != null && this._cachedIndexBuffer !== indexBuffer) {
  799. this._cachedIndexBuffer = indexBuffer;
  800. this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
  801. this._uintIndicesCurrentlySet = indexBuffer.is32Bits;
  802. }
  803. };
  804. Engine.prototype._releaseBuffer = function (buffer) {
  805. buffer.references--;
  806. if (buffer.references === 0) {
  807. this._gl.deleteBuffer(buffer);
  808. return true;
  809. }
  810. return false;
  811. };
  812. Engine.prototype.createInstancesBuffer = function (capacity) {
  813. var buffer = this._gl.createBuffer();
  814. buffer.capacity = capacity;
  815. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, buffer);
  816. this._gl.bufferData(this._gl.ARRAY_BUFFER, capacity, this._gl.DYNAMIC_DRAW);
  817. return buffer;
  818. };
  819. Engine.prototype.deleteInstancesBuffer = function (buffer) {
  820. this._gl.deleteBuffer(buffer);
  821. };
  822. Engine.prototype.updateAndBindInstancesBuffer = function (instancesBuffer, data, offsetLocations) {
  823. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, instancesBuffer);
  824. this._gl.bufferSubData(this._gl.ARRAY_BUFFER, 0, data);
  825. for (var index = 0; index < 4; index++) {
  826. var offsetLocation = offsetLocations[index];
  827. this._gl.enableVertexAttribArray(offsetLocation);
  828. this._gl.vertexAttribPointer(offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
  829. this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 1);
  830. }
  831. };
  832. Engine.prototype.unBindInstancesBuffer = function (instancesBuffer, offsetLocations) {
  833. this._gl.bindBuffer(this._gl.ARRAY_BUFFER, instancesBuffer);
  834. for (var index = 0; index < 4; index++) {
  835. var offsetLocation = offsetLocations[index];
  836. this._gl.disableVertexAttribArray(offsetLocation);
  837. this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 0);
  838. }
  839. };
  840. Engine.prototype.applyStates = function () {
  841. this._depthCullingState.apply(this._gl);
  842. this._alphaState.apply(this._gl);
  843. };
  844. Engine.prototype.draw = function (useTriangles, indexStart, indexCount, instancesCount) {
  845. // Apply states
  846. this.applyStates();
  847. this._drawCalls++;
  848. // Render
  849. var indexFormat = this._uintIndicesCurrentlySet ? this._gl.UNSIGNED_INT : this._gl.UNSIGNED_SHORT;
  850. if (instancesCount) {
  851. this._caps.instancedArrays.drawElementsInstancedANGLE(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2, instancesCount);
  852. return;
  853. }
  854. this._gl.drawElements(useTriangles ? this._gl.TRIANGLES : this._gl.LINES, indexCount, indexFormat, indexStart * 2);
  855. };
  856. Engine.prototype.drawPointClouds = function (verticesStart, verticesCount, instancesCount) {
  857. // Apply states
  858. this.applyStates();
  859. this._drawCalls++;
  860. if (instancesCount) {
  861. this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS, verticesStart, verticesCount, instancesCount);
  862. return;
  863. }
  864. this._gl.drawArrays(this._gl.POINTS, verticesStart, verticesCount);
  865. };
  866. // Shaders
  867. Engine.prototype._releaseEffect = function (effect) {
  868. if (this._compiledEffects[effect._key]) {
  869. delete this._compiledEffects[effect._key];
  870. if (effect.getProgram()) {
  871. this._gl.deleteProgram(effect.getProgram());
  872. }
  873. }
  874. };
  875. Engine.prototype.createEffect = function (baseName, attributesNames, uniformsNames, samplers, defines, fallbacks, onCompiled, onError) {
  876. var vertex = baseName.vertexElement || baseName.vertex || baseName;
  877. var fragment = baseName.fragmentElement || baseName.fragment || baseName;
  878. var name = vertex + "+" + fragment + "@" + defines;
  879. if (this._compiledEffects[name]) {
  880. return this._compiledEffects[name];
  881. }
  882. var effect = new BABYLON.Effect(baseName, attributesNames, uniformsNames, samplers, this, defines, fallbacks, onCompiled, onError);
  883. effect._key = name;
  884. this._compiledEffects[name] = effect;
  885. return effect;
  886. };
  887. Engine.prototype.createEffectForParticles = function (fragmentName, uniformsNames, samplers, defines, fallbacks, onCompiled, onError) {
  888. if (typeof uniformsNames === "undefined") { uniformsNames = []; }
  889. if (typeof samplers === "undefined") { samplers = []; }
  890. if (typeof defines === "undefined") { defines = ""; }
  891. return this.createEffect({
  892. vertex: "particles",
  893. fragmentElement: fragmentName
  894. }, ["position", "color", "options"], ["view", "projection"].concat(uniformsNames), ["diffuseSampler"].concat(samplers), defines, fallbacks, onCompiled, onError);
  895. };
  896. Engine.prototype.createShaderProgram = function (vertexCode, fragmentCode, defines) {
  897. var vertexShader = compileShader(this._gl, vertexCode, "vertex", defines);
  898. var fragmentShader = compileShader(this._gl, fragmentCode, "fragment", defines);
  899. var shaderProgram = this._gl.createProgram();
  900. this._gl.attachShader(shaderProgram, vertexShader);
  901. this._gl.attachShader(shaderProgram, fragmentShader);
  902. this._gl.linkProgram(shaderProgram);
  903. var linked = this._gl.getProgramParameter(shaderProgram, this._gl.LINK_STATUS);
  904. if (!linked) {
  905. var error = this._gl.getProgramInfoLog(shaderProgram);
  906. if (error) {
  907. throw new Error(error);
  908. }
  909. }
  910. this._gl.deleteShader(vertexShader);
  911. this._gl.deleteShader(fragmentShader);
  912. return shaderProgram;
  913. };
  914. Engine.prototype.getUniforms = function (shaderProgram, uniformsNames) {
  915. var results = [];
  916. for (var index = 0; index < uniformsNames.length; index++) {
  917. results.push(this._gl.getUniformLocation(shaderProgram, uniformsNames[index]));
  918. }
  919. return results;
  920. };
  921. Engine.prototype.getAttributes = function (shaderProgram, attributesNames) {
  922. var results = [];
  923. for (var index = 0; index < attributesNames.length; index++) {
  924. try {
  925. results.push(this._gl.getAttribLocation(shaderProgram, attributesNames[index]));
  926. } catch (e) {
  927. results.push(-1);
  928. }
  929. }
  930. return results;
  931. };
  932. Engine.prototype.enableEffect = function (effect) {
  933. if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
  934. if (effect && effect.onBind) {
  935. effect.onBind(effect);
  936. }
  937. return;
  938. }
  939. this._vertexAttribArrays = this._vertexAttribArrays || [];
  940. // Use program
  941. this._gl.useProgram(effect.getProgram());
  942. for (var i in this._vertexAttribArrays) {
  943. if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArrays[i]) {
  944. continue;
  945. }
  946. this._vertexAttribArrays[i] = false;
  947. this._gl.disableVertexAttribArray(i);
  948. }
  949. var attributesCount = effect.getAttributesCount();
  950. for (var index = 0; index < attributesCount; index++) {
  951. // Attributes
  952. var order = effect.getAttributeLocation(index);
  953. if (order >= 0) {
  954. this._vertexAttribArrays[order] = true;
  955. this._gl.enableVertexAttribArray(order);
  956. }
  957. }
  958. this._currentEffect = effect;
  959. if (effect.onBind) {
  960. effect.onBind(effect);
  961. }
  962. };
  963. Engine.prototype.setArray = function (uniform, array) {
  964. if (!uniform)
  965. return;
  966. this._gl.uniform1fv(uniform, array);
  967. };
  968. Engine.prototype.setMatrices = function (uniform, matrices) {
  969. if (!uniform)
  970. return;
  971. this._gl.uniformMatrix4fv(uniform, false, matrices);
  972. };
  973. Engine.prototype.setMatrix = function (uniform, matrix) {
  974. if (!uniform)
  975. return;
  976. this._gl.uniformMatrix4fv(uniform, false, matrix.toArray());
  977. };
  978. Engine.prototype.setFloat = function (uniform, value) {
  979. if (!uniform)
  980. return;
  981. this._gl.uniform1f(uniform, value);
  982. };
  983. Engine.prototype.setFloat2 = function (uniform, x, y) {
  984. if (!uniform)
  985. return;
  986. this._gl.uniform2f(uniform, x, y);
  987. };
  988. Engine.prototype.setFloat3 = function (uniform, x, y, z) {
  989. if (!uniform)
  990. return;
  991. this._gl.uniform3f(uniform, x, y, z);
  992. };
  993. Engine.prototype.setBool = function (uniform, bool) {
  994. if (!uniform)
  995. return;
  996. this._gl.uniform1i(uniform, bool);
  997. };
  998. Engine.prototype.setFloat4 = function (uniform, x, y, z, w) {
  999. if (!uniform)
  1000. return;
  1001. this._gl.uniform4f(uniform, x, y, z, w);
  1002. };
  1003. Engine.prototype.setColor3 = function (uniform, color3) {
  1004. if (!uniform)
  1005. return;
  1006. this._gl.uniform3f(uniform, color3.r, color3.g, color3.b);
  1007. };
  1008. Engine.prototype.setColor4 = function (uniform, color3, alpha) {
  1009. if (!uniform)
  1010. return;
  1011. this._gl.uniform4f(uniform, color3.r, color3.g, color3.b, alpha);
  1012. };
  1013. // States
  1014. Engine.prototype.setState = function (culling, force) {
  1015. // Culling
  1016. if (this._depthCullingState.cull !== culling || force) {
  1017. if (culling) {
  1018. this._depthCullingState.cullFace = this.cullBackFaces ? this._gl.BACK : this._gl.FRONT;
  1019. this._depthCullingState.cull = true;
  1020. } else {
  1021. this._depthCullingState.cull = false;
  1022. }
  1023. }
  1024. };
  1025. Engine.prototype.setDepthBuffer = function (enable) {
  1026. this._depthCullingState.depthTest = enable;
  1027. };
  1028. Engine.prototype.getDepthWrite = function () {
  1029. return this._depthCullingState.depthMask;
  1030. };
  1031. Engine.prototype.setDepthWrite = function (enable) {
  1032. this._depthCullingState.depthMask = enable;
  1033. };
  1034. Engine.prototype.setColorWrite = function (enable) {
  1035. this._gl.colorMask(enable, enable, enable, enable);
  1036. };
  1037. Engine.prototype.setAlphaMode = function (mode) {
  1038. switch (mode) {
  1039. case Engine.ALPHA_DISABLE:
  1040. this.setDepthWrite(true);
  1041. this._alphaState.alphaBlend = false;
  1042. break;
  1043. case Engine.ALPHA_COMBINE:
  1044. this.setDepthWrite(false);
  1045. this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA, this._gl.ONE_MINUS_SRC_ALPHA, this._gl.ONE, this._gl.ONE);
  1046. this._alphaState.alphaBlend = true;
  1047. break;
  1048. case Engine.ALPHA_ADD:
  1049. this.setDepthWrite(false);
  1050. this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE, this._gl.ONE, this._gl.ZERO, this._gl.ONE);
  1051. this._alphaState.alphaBlend = true;
  1052. break;
  1053. }
  1054. this._alphaMode = mode;
  1055. };
  1056. Engine.prototype.getAlphaMode = function () {
  1057. return this._alphaMode;
  1058. };
  1059. Engine.prototype.setAlphaTesting = function (enable) {
  1060. this._alphaTest = enable;
  1061. };
  1062. Engine.prototype.getAlphaTesting = function () {
  1063. return this._alphaTest;
  1064. };
  1065. // Textures
  1066. Engine.prototype.wipeCaches = function () {
  1067. this._activeTexturesCache = [];
  1068. this._currentEffect = null;
  1069. this._depthCullingState.reset();
  1070. this._alphaState.reset();
  1071. this._cachedVertexBuffers = null;
  1072. this._cachedIndexBuffer = null;
  1073. this._cachedEffectForVertexBuffers = null;
  1074. };
  1075. Engine.prototype.setSamplingMode = function (texture, samplingMode) {
  1076. var gl = this._gl;
  1077. gl.bindTexture(gl.TEXTURE_2D, texture);
  1078. var magFilter = gl.NEAREST;
  1079. var minFilter = gl.NEAREST;
  1080. if (samplingMode === BABYLON.Texture.BILINEAR_SAMPLINGMODE) {
  1081. magFilter = gl.LINEAR;
  1082. minFilter = gl.LINEAR;
  1083. } else if (samplingMode === BABYLON.Texture.TRILINEAR_SAMPLINGMODE) {
  1084. magFilter = gl.LINEAR;
  1085. minFilter = gl.LINEAR_MIPMAP_LINEAR;
  1086. }
  1087. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter);
  1088. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter);
  1089. gl.bindTexture(gl.TEXTURE_2D, null);
  1090. texture.samplingMode = samplingMode;
  1091. };
  1092. Engine.prototype.createTexture = function (url, noMipmap, invertY, scene, samplingMode, onLoad, onError, buffer) {
  1093. var _this = this;
  1094. if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  1095. if (typeof onLoad === "undefined") { onLoad = null; }
  1096. if (typeof onError === "undefined") { onError = null; }
  1097. if (typeof buffer === "undefined") { buffer = null; }
  1098. var texture = this._gl.createTexture();
  1099. var extension;
  1100. var fromData = false;
  1101. if (url.substr(0, 5) === "data:") {
  1102. fromData = true;
  1103. }
  1104. if (!fromData)
  1105. extension = url.substr(url.length - 4, 4).toLowerCase();
  1106. else {
  1107. var oldUrl = url;
  1108. fromData = oldUrl.split(':');
  1109. url = oldUrl;
  1110. extension = fromData[1].substr(fromData[1].length - 4, 4).toLowerCase();
  1111. }
  1112. var isDDS = this.getCaps().s3tc && (extension === ".dds");
  1113. var isTGA = (extension === ".tga");
  1114. scene._addPendingData(texture);
  1115. texture.url = url;
  1116. texture.noMipmap = noMipmap;
  1117. texture.references = 1;
  1118. this._loadedTexturesCache.push(texture);
  1119. var onerror = function () {
  1120. scene._removePendingData(texture);
  1121. if (onError) {
  1122. onError();
  1123. }
  1124. };
  1125. if (isTGA) {
  1126. var callback = function (arrayBuffer) {
  1127. var data = new Uint8Array(arrayBuffer);
  1128. var header = BABYLON.Internals.TGATools.GetTGAHeader(data);
  1129. prepareWebGLTexture(texture, _this._gl, scene, header.width, header.height, invertY, noMipmap, false, function () {
  1130. BABYLON.Internals.TGATools.UploadContent(_this._gl, data);
  1131. if (onLoad) {
  1132. onLoad();
  1133. }
  1134. }, samplingMode);
  1135. };
  1136. if (!(fromData instanceof Array))
  1137. BABYLON.Tools.LoadFile(url, function (arrayBuffer) {
  1138. callback(arrayBuffer);
  1139. }, onerror, scene.database, true);
  1140. else
  1141. callback(buffer);
  1142. } else if (isDDS) {
  1143. callback = function (data) {
  1144. var info = BABYLON.Internals.DDSTools.GetDDSInfo(data);
  1145. var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap && ((info.width >> (info.mipmapCount - 1)) === 1);
  1146. prepareWebGLTexture(texture, _this._gl, scene, info.width, info.height, invertY, !loadMipmap, info.isFourCC, function () {
  1147. BABYLON.Internals.DDSTools.UploadDDSLevels(_this._gl, _this.getCaps().s3tc, data, info, loadMipmap, 1);
  1148. if (onLoad) {
  1149. onLoad();
  1150. }
  1151. }, samplingMode);
  1152. };
  1153. if (!(fromData instanceof Array))
  1154. BABYLON.Tools.LoadFile(url, function (data) {
  1155. callback(data);
  1156. }, onerror, scene.database, true);
  1157. else
  1158. callback(buffer);
  1159. } else {
  1160. var onload = function (img) {
  1161. prepareWebGLTexture(texture, _this._gl, scene, img.width, img.height, invertY, noMipmap, false, function (potWidth, potHeight) {
  1162. var isPot = (img.width === potWidth && img.height === potHeight);
  1163. if (!isPot) {
  1164. _this._workingCanvas.width = potWidth;
  1165. _this._workingCanvas.height = potHeight;
  1166. _this._workingContext.drawImage(img, 0, 0, img.width, img.height, 0, 0, potWidth, potHeight);
  1167. }
  1168. _this._gl.texImage2D(_this._gl.TEXTURE_2D, 0, _this._gl.RGBA, _this._gl.RGBA, _this._gl.UNSIGNED_BYTE, isPot ? img : _this._workingCanvas);
  1169. if (onLoad) {
  1170. onLoad();
  1171. }
  1172. }, samplingMode);
  1173. };
  1174. if (!(fromData instanceof Array))
  1175. BABYLON.Tools.LoadImage(url, onload, onerror, scene.database);
  1176. else
  1177. BABYLON.Tools.LoadImage(buffer, onload, onerror, scene.database);
  1178. }
  1179. return texture;
  1180. };
  1181. Engine.prototype.createRawTexture = function (data, width, height, format, generateMipMaps, invertY, samplingMode) {
  1182. var texture = this._gl.createTexture();
  1183. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  1184. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY === undefined ? 1 : (invertY ? 1 : 0));
  1185. // Format
  1186. var internalFormat = this._gl.RGBA;
  1187. switch (format) {
  1188. case Engine.TEXTUREFORMAT_ALPHA:
  1189. internalFormat = this._gl.ALPHA;
  1190. break;
  1191. case Engine.TEXTUREFORMAT_LUMINANCE:
  1192. internalFormat = this._gl.LUMINANCE;
  1193. break;
  1194. case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
  1195. internalFormat = this._gl.LUMINANCE_ALPHA;
  1196. break;
  1197. case Engine.TEXTUREFORMAT_RGB:
  1198. internalFormat = this._gl.RGB;
  1199. break;
  1200. case Engine.TEXTUREFORMAT_RGBA:
  1201. internalFormat = this._gl.RGBA;
  1202. break;
  1203. }
  1204. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, internalFormat, width, height, 0, internalFormat, this._gl.UNSIGNED_BYTE, data);
  1205. if (generateMipMaps) {
  1206. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  1207. }
  1208. // Filters
  1209. var filters = getSamplingParameters(samplingMode, generateMipMaps, this._gl);
  1210. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
  1211. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  1212. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1213. this._activeTexturesCache = [];
  1214. texture._baseWidth = width;
  1215. texture._baseHeight = height;
  1216. texture._width = width;
  1217. texture._height = height;
  1218. texture.isReady = true;
  1219. texture.references = 1;
  1220. texture.samplingMode = samplingMode;
  1221. this._loadedTexturesCache.push(texture);
  1222. return texture;
  1223. };
  1224. Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
  1225. var texture = this._gl.createTexture();
  1226. width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
  1227. height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
  1228. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  1229. var filters = getSamplingParameters(samplingMode, generateMipMaps, this._gl);
  1230. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MAG_FILTER, filters.mag);
  1231. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_MIN_FILTER, filters.min);
  1232. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1233. this._activeTexturesCache = [];
  1234. texture._baseWidth = width;
  1235. texture._baseHeight = height;
  1236. texture._width = width;
  1237. texture._height = height;
  1238. texture.isReady = false;
  1239. texture.generateMipMaps = generateMipMaps;
  1240. texture.references = 1;
  1241. texture.samplingMode = samplingMode;
  1242. this._loadedTexturesCache.push(texture);
  1243. return texture;
  1244. };
  1245. Engine.prototype.updateDynamicTexture = function (texture, canvas, invertY) {
  1246. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  1247. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 1 : 0);
  1248. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, canvas);
  1249. if (texture.generateMipMaps) {
  1250. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  1251. }
  1252. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1253. this._activeTexturesCache = [];
  1254. texture.isReady = true;
  1255. };
  1256. Engine.prototype.updateVideoTexture = function (texture, video, invertY) {
  1257. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  1258. this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL, invertY ? 0 : 1); // Video are upside down by default
  1259. // Scale the video if it is a NPOT using the current working canvas
  1260. if (video.videoWidth !== texture._width || video.videoHeight !== texture._height) {
  1261. if (!texture._workingCanvas) {
  1262. texture._workingCanvas = document.createElement("canvas");
  1263. texture._workingContext = texture._workingCanvas.getContext("2d");
  1264. texture._workingCanvas.width = texture._width;
  1265. texture._workingCanvas.height = texture._height;
  1266. }
  1267. texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture._width, texture._height);
  1268. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
  1269. } else {
  1270. this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, video);
  1271. }
  1272. if (texture.generateMipMaps) {
  1273. this._gl.generateMipmap(this._gl.TEXTURE_2D);
  1274. }
  1275. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1276. this._activeTexturesCache = [];
  1277. texture.isReady = true;
  1278. };
  1279. Engine.prototype.createRenderTargetTexture = function (size, options) {
  1280. // old version had a "generateMipMaps" arg instead of options.
  1281. // if options.generateMipMaps is undefined, consider that options itself if the generateMipmaps value
  1282. // in the same way, generateDepthBuffer is defaulted to true
  1283. var generateMipMaps = false;
  1284. var generateDepthBuffer = true;
  1285. var samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
  1286. if (options !== undefined) {
  1287. generateMipMaps = options.generateMipMaps === undefined ? options : options.generateMipmaps;
  1288. generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;
  1289. if (options.samplingMode !== undefined) {
  1290. samplingMode = options.samplingMode;
  1291. }
  1292. }
  1293. var gl = this._gl;
  1294. var texture = gl.createTexture();
  1295. gl.bindTexture(gl.TEXTURE_2D, texture);
  1296. var width = size.width || size;
  1297. var height = size.height || size;
  1298. var filters = getSamplingParameters(samplingMode, generateMipMaps, gl);
  1299. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filters.mag);
  1300. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
  1301. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  1302. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  1303. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  1304. var depthBuffer;
  1305. // Create the depth buffer
  1306. if (generateDepthBuffer) {
  1307. depthBuffer = gl.createRenderbuffer();
  1308. gl.bindRenderbuffer(gl.RENDERBUFFER, depthBuffer);
  1309. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, width, height);
  1310. }
  1311. // Create the framebuffer
  1312. var framebuffer = gl.createFramebuffer();
  1313. gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
  1314. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
  1315. if (generateDepthBuffer) {
  1316. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuffer);
  1317. }
  1318. // Unbind
  1319. gl.bindTexture(gl.TEXTURE_2D, null);
  1320. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  1321. gl.bindFramebuffer(gl.FRAMEBUFFER, null);
  1322. texture._framebuffer = framebuffer;
  1323. if (generateDepthBuffer) {
  1324. texture._depthBuffer = depthBuffer;
  1325. }
  1326. texture._width = width;
  1327. texture._height = height;
  1328. texture.isReady = true;
  1329. texture.generateMipMaps = generateMipMaps;
  1330. texture.references = 1;
  1331. texture.samplingMode = samplingMode;
  1332. this._activeTexturesCache = [];
  1333. this._loadedTexturesCache.push(texture);
  1334. return texture;
  1335. };
  1336. Engine.prototype.createCubeTexture = function (rootUrl, scene, extensions, noMipmap) {
  1337. var _this = this;
  1338. var gl = this._gl;
  1339. var texture = gl.createTexture();
  1340. texture.isCube = true;
  1341. texture.url = rootUrl;
  1342. texture.references = 1;
  1343. this._loadedTexturesCache.push(texture);
  1344. var extension = rootUrl.substr(rootUrl.length - 4, 4).toLowerCase();
  1345. var isDDS = this.getCaps().s3tc && (extension === ".dds");
  1346. if (isDDS) {
  1347. BABYLON.Tools.LoadFile(rootUrl, function (data) {
  1348. var info = BABYLON.Internals.DDSTools.GetDDSInfo(data);
  1349. var loadMipmap = (info.isRGB || info.isLuminance || info.mipmapCount > 1) && !noMipmap;
  1350. gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
  1351. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 1);
  1352. BABYLON.Internals.DDSTools.UploadDDSLevels(_this._gl, _this.getCaps().s3tc, data, info, loadMipmap, 6);
  1353. if (!noMipmap && !info.isFourCC && info.mipmapCount === 1) {
  1354. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  1355. }
  1356. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1357. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, loadMipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
  1358. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  1359. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  1360. gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
  1361. _this._activeTexturesCache = [];
  1362. texture._width = info.width;
  1363. texture._height = info.height;
  1364. texture.isReady = true;
  1365. }, null, null, true);
  1366. } else {
  1367. cascadeLoad(rootUrl, scene, function (imgs) {
  1368. var width = BABYLON.Tools.GetExponantOfTwo(imgs[0].width, _this._caps.maxCubemapTextureSize);
  1369. var height = width;
  1370. _this._workingCanvas.width = width;
  1371. _this._workingCanvas.height = height;
  1372. var faces = [
  1373. gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
  1374. gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
  1375. ];
  1376. gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
  1377. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
  1378. for (var index = 0; index < faces.length; index++) {
  1379. _this._workingContext.drawImage(imgs[index], 0, 0, imgs[index].width, imgs[index].height, 0, 0, width, height);
  1380. gl.texImage2D(faces[index], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, _this._workingCanvas);
  1381. }
  1382. if (!noMipmap) {
  1383. gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
  1384. }
  1385. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
  1386. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, noMipmap ? gl.LINEAR : gl.LINEAR_MIPMAP_LINEAR);
  1387. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  1388. gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  1389. gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
  1390. _this._activeTexturesCache = [];
  1391. texture._width = width;
  1392. texture._height = height;
  1393. texture.isReady = true;
  1394. }, extensions);
  1395. }
  1396. return texture;
  1397. };
  1398. Engine.prototype._releaseTexture = function (texture) {
  1399. var gl = this._gl;
  1400. if (texture._framebuffer) {
  1401. gl.deleteFramebuffer(texture._framebuffer);
  1402. }
  1403. if (texture._depthBuffer) {
  1404. gl.deleteRenderbuffer(texture._depthBuffer);
  1405. }
  1406. gl.deleteTexture(texture);
  1407. for (var channel = 0; channel < this._caps.maxTexturesImageUnits; channel++) {
  1408. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  1409. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1410. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
  1411. this._activeTexturesCache[channel] = null;
  1412. }
  1413. var index = this._loadedTexturesCache.indexOf(texture);
  1414. if (index !== -1) {
  1415. this._loadedTexturesCache.splice(index, 1);
  1416. }
  1417. };
  1418. Engine.prototype.bindSamplers = function (effect) {
  1419. this._gl.useProgram(effect.getProgram());
  1420. var samplers = effect.getSamplers();
  1421. for (var index = 0; index < samplers.length; index++) {
  1422. var uniform = effect.getUniform(samplers[index]);
  1423. this._gl.uniform1i(uniform, index);
  1424. }
  1425. this._currentEffect = null;
  1426. };
  1427. Engine.prototype._bindTexture = function (channel, texture) {
  1428. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  1429. this._gl.bindTexture(this._gl.TEXTURE_2D, texture);
  1430. this._activeTexturesCache[channel] = null;
  1431. };
  1432. Engine.prototype.setTextureFromPostProcess = function (channel, postProcess) {
  1433. this._bindTexture(channel, postProcess._textures.data[postProcess._currentRenderTextureInd]);
  1434. };
  1435. Engine.prototype.setTexture = function (channel, texture) {
  1436. if (channel < 0) {
  1437. return;
  1438. }
  1439. // Not ready?
  1440. if (!texture || !texture.isReady()) {
  1441. if (this._activeTexturesCache[channel] != null) {
  1442. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  1443. this._gl.bindTexture(this._gl.TEXTURE_2D, null);
  1444. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, null);
  1445. this._activeTexturesCache[channel] = null;
  1446. }
  1447. return;
  1448. }
  1449. // Video
  1450. if (texture instanceof BABYLON.VideoTexture) {
  1451. if (texture.update()) {
  1452. this._activeTexturesCache[channel] = null;
  1453. }
  1454. } else if (texture.delayLoadState === Engine.DELAYLOADSTATE_NOTLOADED) {
  1455. texture.delayLoad();
  1456. return;
  1457. }
  1458. if (this._activeTexturesCache[channel] === texture) {
  1459. return;
  1460. }
  1461. this._activeTexturesCache[channel] = texture;
  1462. var internalTexture = texture.getInternalTexture();
  1463. this._gl.activeTexture(this._gl["TEXTURE" + channel]);
  1464. if (internalTexture.isCube) {
  1465. this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP, internalTexture);
  1466. if (internalTexture._cachedCoordinatesMode !== texture.coordinatesMode) {
  1467. internalTexture._cachedCoordinatesMode = texture.coordinatesMode;
  1468. // CUBIC_MODE and SKYBOX_MODE both require CLAMP_TO_EDGE. All other modes use REPEAT.
  1469. var textureWrapMode = (texture.coordinatesMode !== BABYLON.Texture.CUBIC_MODE && texture.coordinatesMode !== BABYLON.Texture.SKYBOX_MODE) ? this._gl.REPEAT : this._gl.CLAMP_TO_EDGE;
  1470. this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_S, textureWrapMode);
  1471. this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP, this._gl.TEXTURE_WRAP_T, textureWrapMode);
  1472. }
  1473. this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP, texture);
  1474. } else {
  1475. this._gl.bindTexture(this._gl.TEXTURE_2D, internalTexture);
  1476. if (internalTexture._cachedWrapU !== texture.wrapU) {
  1477. internalTexture._cachedWrapU = texture.wrapU;
  1478. switch (texture.wrapU) {
  1479. case BABYLON.Texture.WRAP_ADDRESSMODE:
  1480. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.REPEAT);
  1481. break;
  1482. case BABYLON.Texture.CLAMP_ADDRESSMODE:
  1483. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.CLAMP_TO_EDGE);
  1484. break;
  1485. case BABYLON.Texture.MIRROR_ADDRESSMODE:
  1486. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_S, this._gl.MIRRORED_REPEAT);
  1487. break;
  1488. }
  1489. }
  1490. if (internalTexture._cachedWrapV !== texture.wrapV) {
  1491. internalTexture._cachedWrapV = texture.wrapV;
  1492. switch (texture.wrapV) {
  1493. case BABYLON.Texture.WRAP_ADDRESSMODE:
  1494. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.REPEAT);
  1495. break;
  1496. case BABYLON.Texture.CLAMP_ADDRESSMODE:
  1497. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.CLAMP_TO_EDGE);
  1498. break;
  1499. case BABYLON.Texture.MIRROR_ADDRESSMODE:
  1500. this._gl.texParameteri(this._gl.TEXTURE_2D, this._gl.TEXTURE_WRAP_T, this._gl.MIRRORED_REPEAT);
  1501. break;
  1502. }
  1503. }
  1504. this._setAnisotropicLevel(this._gl.TEXTURE_2D, texture);
  1505. }
  1506. };
  1507. Engine.prototype._setAnisotropicLevel = function (key, texture) {
  1508. var anisotropicFilterExtension = this._caps.textureAnisotropicFilterExtension;
  1509. if (anisotropicFilterExtension && texture._cachedAnisotropicFilteringLevel !== texture.anisotropicFilteringLevel) {
  1510. this._gl.texParameterf(key, anisotropicFilterExtension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropicFilteringLevel, this._caps.maxAnisotropy));
  1511. texture._cachedAnisotropicFilteringLevel = texture.anisotropicFilteringLevel;
  1512. }
  1513. };
  1514. Engine.prototype.readPixels = function (x, y, width, height) {
  1515. var data = new Uint8Array(height * width * 4);
  1516. this._gl.readPixels(0, 0, width, height, this._gl.RGBA, this._gl.UNSIGNED_BYTE, data);
  1517. return data;
  1518. };
  1519. // Dispose
  1520. Engine.prototype.dispose = function () {
  1521. this.hideLoadingUI();
  1522. this.stopRenderLoop();
  1523. while (this.scenes.length) {
  1524. this.scenes[0].dispose();
  1525. }
  1526. for (var name in this._compiledEffects) {
  1527. this._gl.deleteProgram(this._compiledEffects[name]._program);
  1528. }
  1529. for (var i in this._vertexAttribArrays) {
  1530. if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArrays[i]) {
  1531. continue;
  1532. }
  1533. this._gl.disableVertexAttribArray(i);
  1534. }
  1535. // Events
  1536. window.removeEventListener("blur", this._onBlur);
  1537. window.removeEventListener("focus", this._onFocus);
  1538. document.removeEventListener("fullscreenchange", this._onFullscreenChange);
  1539. document.removeEventListener("mozfullscreenchange", this._onFullscreenChange);
  1540. document.removeEventListener("webkitfullscreenchange", this._onFullscreenChange);
  1541. document.removeEventListener("msfullscreenchange", this._onFullscreenChange);
  1542. document.removeEventListener("pointerlockchange", this._onPointerLockChange);
  1543. document.removeEventListener("mspointerlockchange", this._onPointerLockChange);
  1544. document.removeEventListener("mozpointerlockchange", this._onPointerLockChange);
  1545. document.removeEventListener("webkitpointerlockchange", this._onPointerLockChange);
  1546. };
  1547. // Loading screen
  1548. Engine.prototype.displayLoadingUI = function () {
  1549. var _this = this;
  1550. this._loadingDiv = document.createElement("div");
  1551. this._loadingDiv.style.opacity = "0";
  1552. this._loadingDiv.style.transition = "opacity 1.5s ease";
  1553. // Loading text
  1554. this._loadingTextDiv = document.createElement("div");
  1555. this._loadingTextDiv.style.position = "absolute";
  1556. this._loadingTextDiv.style.left = "0";
  1557. this._loadingTextDiv.style.top = "50%";
  1558. this._loadingTextDiv.style.marginTop = "80px";
  1559. this._loadingTextDiv.style.width = "100%";
  1560. this._loadingTextDiv.style.height = "20px";
  1561. this._loadingTextDiv.style.fontFamily = "Arial";
  1562. this._loadingTextDiv.style.fontSize = "14px";
  1563. this._loadingTextDiv.style.color = "white";
  1564. this._loadingTextDiv.style.textAlign = "center";
  1565. this._loadingTextDiv.innerHTML = "Loading";
  1566. this._loadingDiv.appendChild(this._loadingTextDiv);
  1567. // Loading img
  1568. var imgBack = new Image();
  1569. imgBack.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAARbSURBVHhe7Z09aFNRFMc716kuLrq4FdyLq4Wi4CAoRQcR0UJBUBdRiuLSIYMo6CA4FF2sgw6CFAdFUOpSQYcWO4hD26UQCfXrIQrx/JJzw1OSWq3NPeL/B4Fy+0jg/HO+7j3vpUcI8b/Q39+/49ihfWdPHT94Yf/e3Se3bd263f8lus218TPn6vV6Ya8Wi/MzNRNmj18iusX9W1evmP1/EKNEIVG6CMbG6E3bt+fT++pHha8NoHdT72bLE8NDg7tGU64gLLndV4Wc4m8j/pS+vr4tGB/DT16v3Fyr8dvBe/jbit8BL0AES9LX1iPAz+BR/hFiLVCynj95dPzNy6fv3IZ/k4L3948Sq7FzYGBg4vLFGxitabuOFCbWNKGrMnbiUuo18KaV6tIHv6YtvL9/nOgE31jCktmrY7k6+/zhE4yP4Vf7hiNqh/BWWEl8mzDol4p22Lf7cIdvdUMEvv0Y2S9fE5S1hLzpqTsPkiep//gFGPnR3Yl7GL5p/xYFBrTwM+iXio3GqpwDGL5p/xYNIX7XG8Q6IJRgdIzf1KBBgafII7oMidhyQtVFaMA2Bt7il4huQRhaXphbcR2g4RXqBzKAGHiCCwGFVUAj/m/RTRDj29cvn10I0PZ3LghH5f4CL1EFlQmqqXK3jDDKFxmhQ3Yt6oQseUZGKmMnTpsOqc8o1F9kBOMjQlOLeqEeIyOc6JV6jYLJD/+XyIFvnzdgl9aXRQ5I2qZDK1SpospMqaoqON/wZZGDciLnMMiXRS7IF4hhqMTNTdk7CFu+LHLhR7BQqBvPDJUUQqCGvCMATHUgBmhWNgApmdOda9YpM+VwRYfuyyIXDK8hBlilNerLIheMZCKGwlUAyru6GlwOgPUbRxADdJ9FAChxXY864viyyEXqPxhc0M2TAfAbatSdRyHtXymhByEdRnE3ky+JnHAIhSA0h74kckETmHoQbSgGwJrCIRMEPSRIBCRIMAhZaYhaggQhJXUJEoRU9mofKwh+F22dLRRfEjlJM7w6KQwCoQpBOKTyJZETjmwRxKqtGV8SOSkNOGjKPQppBEgDDkFgpxdBVGkFgaYQQXRIFQSObk0P5ZFIpAZRHXsQ0r0hCluBWKkuvVbYCkQaCdL5ehBScudJP4yY+rLISdps1NBDEJKXMMmoSfggWC4ZQRR17oFYXph7hSiquIKQ+hJGTX1J5MYSPD/GVdNzsgLBwZVCVyAQAkF0ohiI/c1fS6tNXq9UfEnkhudmIQolsS+J3Hh/UtNDzQLhj42VKJFInqLwFYiUU5ToA+HdfI0JevUpQUAIn+vSz2lHIuUV/dJOIHhOY/IWVWGBIHQtzs88s9zyWBuTgcBLzGOmeNnfF/QslSDgMeQW85i3DOQxuipxAkCyZ8SIm4Omp+7MMlCB59j6sKZcMoM4iIEoeI2J9AKxrFobZx0v4vYInuHFS4J1GQRCAGaLEYQXfyMML5XSQgghhBBCCCH+cXp6vgNhKpSKX/XdOAAAAABJRU5ErkJggg==";
  1570. imgBack.style.position = "absolute";
  1571. imgBack.style.left = "50%";
  1572. imgBack.style.top = "50%";
  1573. imgBack.style.marginLeft = "-50px";
  1574. imgBack.style.marginTop = "-50px";
  1575. imgBack.style.transition = "transform 1.0s ease";
  1576. imgBack.style.webkitTransition = "-webkit-transform 1.0s ease";
  1577. var deg = 360;
  1578. var onTransitionEnd = function () {
  1579. deg += 360;
  1580. imgBack.style.transform = "rotateZ(" + deg + "deg)";
  1581. imgBack.style.webkitTransform = "rotateZ(" + deg + "deg)";
  1582. };
  1583. imgBack.addEventListener("transitionend", onTransitionEnd);
  1584. imgBack.addEventListener("webkitTransitionEnd", onTransitionEnd);
  1585. this._loadingDiv.appendChild(imgBack);
  1586. // front image
  1587. var imgFront = new Image();
  1588. imgFront.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuM4zml1AAAAYJSURBVHhe7Zy/qx1FFMff/2Av2Nvbi4WFiiAEY/OQ2IgQsbCJQoqkCAgpFLXyoZURLfwBIiIpgqZJoYQYlWelNsIrNOxDJcrzfHe+G97dnTl75u7euzv7zgcWHrlnZmfOmXPmzI/NjuM4juM4juM4juM4juM4juM4juM4juM45fPic08/uHf5/CvffH7lnT8PfrtxdHS0n3p+/fHGl5+89/prr5599iEWd8bg0rkXHoFyqehKnlxQpjYSDHTm9JMPsGrHylOPPXofvICKXMcIGtXdf/76AYbm6xyNW9e/eAtKC7rbKLXnvHHx5Sf4auc4Ek7OQkFU1Dap/vv37k/wSjblZANFiFIGzw98hhizwqBgs04mCBdQRNCHidoAEtY+lLIvtSdoGFeyql2ZH57HBH4sE7O+o/r9l+8/ZXUni68+2jsHBQQ9qNRGeP/tSxdSYQX/roUcpL4/f3vtM9TD+jTq92n1LQ7jxF1hhGPtwWL3gGccy8JuS1r8sVWBGXNVdSKMYjBGPUJjCzooiGuSpnwlnnOGP2dhHRSLNgpHp2oMKIriK8TmG4Qh/rwW8D6pps9b9im+LDDipXOqMVJrAngBfg9i98gevWKA+/nnCod3Dr5GfaHaDgidVym6HKRjGIkpqthcAVKGxNqBImbEo66kjCih8AOpNmkUmbMuUrR8kEqiU6FvHZLGAPJ71JCYSyhiBqmwFE2GoD6jLGIfDHtG6EzoU4dK21PCqIRMEF0FGRjFzGDtIkXVAdATvsqfT9CJ0JcOFdYiFIsiMlqYy1YOFpQo2OddqBtyEaq9y+efoVh5oPHoROjLKn0j3JIE5Ka8UqZRtGrMnneX6yVofOhDh94MSbznTcpqmDOt1vyQzOgaJAF4F3JBfIXesrNEGWWmjIX7UBZ6jRJbBMLg/DmJiKUGVHleIpnVNTa+jakzkAviJqLhi4MC9XQGBrZeKJZESSrKy7ik0VGFWhQBRDTHIACKQ5l9nAjy75gya4a2w+Jhs0FJdc0xX/GwUbAqFBkZi7QpJ2w16WUbjFyK9MJF3KaoEM74KhVtLrQOrsmRxkbdHEqmSC/c+EuGnIFkjW7Ih2Kr4CCMIvNG2hrrgLpCjiFloooYCjyYrzCRyvhyBthkIPuQtsZGdnbMTezyDiU71KTC5zr7aVsHbsz2tllrEkS5UHwU1tq1HbtPW4UbeB0O7xx8R5EsMJql+BheUmHjkNVmIRP7LutoM3+D4O4tG7vCkNO9ESZ4lL3J6rKRMPx4qKbD/A0icf8CG7tC7kTahnMTwleuYSrsS7GatRAvfZh1tTm5BmmQCdZ8a0Sefe28xUrRBkmFLKy8KTIKUDRX0Y1xagPgwbaIdeFnQULmKak3xvwNMkVGgok/N5XNoehJvejRlCDl9escI28dJU0tZ++nBTJE9mEF647x5Ehbo4s5hDOKFIU0PdofeA5F5k1q63zIWmQqNI/P3ZubjFTqKxQ3jyjHAOX0RdlgVO9hzRFpczRcjZ3Gbxxpc7Qj6+5pTYF2OFXawNI+yDGf1k2NcvOlzBQeDQ/t7zD7DsEDpJ2xATXaNtDWUS4IzP4DS2ljajAVu57SUkYw245ptxZxA5JiZaJ0DswudGn3kYUy54426EjoT4dZfYbccxC2nI92cDkZHQr96jD4AGkMDKeSy/COBsRe6VTSKFN6irLeaCh3IteQjt1E5+oudsG/b/2DfZ5AqsYo8vMDK9LB1HzSsLWvlGThdxXvC6+NsqyPPWP0pMINtbdsajfVeC6f/GZ+cdAofQoB1d+Hf9waY98I7+RXWab3Lt4zYkjHtTnlOLXHYMsCh1zWeQYehu1zfNPOOiys/d91LAKEBSgh6MJMbSA82AaHofDgAIwbgvVvlLNS11nModMm4UZergLHZBZrodmBuA3lBB1thdorSjkOmATMDwg/UBQVtglqQyx6fbEJ+H3IWIapjYAjAfeIgeCMHldueJvFaqDaAHhwf8qNsEEQ1iQbOoUUGIbCLRc8+Bvfp4jyd2FEijuO4ziO4ziO4ziO4ziO4ziO4ziO4ziOUzw7O/8D0P7rcZ/GEboAAAAASUVORK5CYII=";
  1589. imgFront.style.position = "absolute";
  1590. imgFront.style.left = "50%";
  1591. imgFront.style.top = "50%";
  1592. imgFront.style.marginLeft = "-50px";
  1593. imgFront.style.marginTop = "-50px";
  1594. this._loadingDiv.appendChild(imgFront);
  1595. // Resize
  1596. this._resizeLoadingUI = function () {
  1597. var canvasRect = _this.getRenderingCanvasClientRect();
  1598. _this._loadingDiv.style.position = "absolute";
  1599. _this._loadingDiv.style.left = canvasRect.left + "px";
  1600. _this._loadingDiv.style.top = canvasRect.top + "px";
  1601. _this._loadingDiv.style.width = canvasRect.width + "px";
  1602. _this._loadingDiv.style.height = canvasRect.height + "px";
  1603. };
  1604. this._resizeLoadingUI();
  1605. window.addEventListener("resize", this._resizeLoadingUI);
  1606. this._loadingDiv.style.backgroundColor = this._loadingDivBackgroundColor;
  1607. document.body.appendChild(this._loadingDiv);
  1608. setTimeout(function () {
  1609. _this._loadingDiv.style.opacity = "1";
  1610. imgBack.style.transform = "rotateZ(360deg)";
  1611. imgBack.style.webkitTransform = "rotateZ(360deg)";
  1612. }, 0);
  1613. };
  1614. Object.defineProperty(Engine.prototype, "loadingUIText", {
  1615. set: function (text) {
  1616. if (!this._loadingDiv) {
  1617. return;
  1618. }
  1619. this._loadingTextDiv.innerHTML = text;
  1620. },
  1621. enumerable: true,
  1622. configurable: true
  1623. });
  1624. Object.defineProperty(Engine.prototype, "loadingUIBackgroundColor", {
  1625. get: function () {
  1626. return this._loadingDivBackgroundColor;
  1627. },
  1628. set: function (color) {
  1629. this._loadingDivBackgroundColor = color;
  1630. if (!this._loadingDiv) {
  1631. return;
  1632. }
  1633. this._loadingDiv.style.backgroundColor = this._loadingDivBackgroundColor;
  1634. },
  1635. enumerable: true,
  1636. configurable: true
  1637. });
  1638. Engine.prototype.hideLoadingUI = function () {
  1639. var _this = this;
  1640. if (!this._loadingDiv) {
  1641. return;
  1642. }
  1643. var onTransitionEnd = function () {
  1644. if (!_this._loadingDiv) {
  1645. return;
  1646. }
  1647. document.body.removeChild(_this._loadingDiv);
  1648. window.removeEventListener("resize", _this._resizeLoadingUI);
  1649. _this._loadingDiv = null;
  1650. };
  1651. this._loadingDiv.style.opacity = "0";
  1652. this._loadingDiv.addEventListener("transitionend", onTransitionEnd);
  1653. };
  1654. // FPS
  1655. Engine.prototype.getFps = function () {
  1656. return this.fps;
  1657. };
  1658. Engine.prototype.getDeltaTime = function () {
  1659. return this.deltaTime;
  1660. };
  1661. Engine.prototype._measureFps = function () {
  1662. this.previousFramesDuration.push(BABYLON.Tools.Now);
  1663. var length = this.previousFramesDuration.length;
  1664. if (length >= 2) {
  1665. this.deltaTime = this.previousFramesDuration[length - 1] - this.previousFramesDuration[length - 2];
  1666. }
  1667. if (length >= this.fpsRange) {
  1668. if (length > this.fpsRange) {
  1669. this.previousFramesDuration.splice(0, 1);
  1670. length = this.previousFramesDuration.length;
  1671. }
  1672. var sum = 0;
  1673. for (var id = 0; id < length - 1; id++) {
  1674. sum += this.previousFramesDuration[id + 1] - this.previousFramesDuration[id];
  1675. }
  1676. this.fps = 1000.0 / (sum / (length - 1));
  1677. }
  1678. };
  1679. // Statics
  1680. Engine.isSupported = function () {
  1681. try {
  1682. // Avoid creating an unsized context for CocoonJS, since size determined on first creation. Is not resizable
  1683. if (navigator.isCocoonJS) {
  1684. return true;
  1685. }
  1686. var tempcanvas = document.createElement("canvas");
  1687. var gl = tempcanvas.getContext("webgl") || tempcanvas.getContext("experimental-webgl");
  1688. return gl != null && !!window.WebGLRenderingContext;
  1689. } catch (e) {
  1690. return false;
  1691. }
  1692. };
  1693. Engine._ALPHA_DISABLE = 0;
  1694. Engine._ALPHA_ADD = 1;
  1695. Engine._ALPHA_COMBINE = 2;
  1696. Engine._DELAYLOADSTATE_NONE = 0;
  1697. Engine._DELAYLOADSTATE_LOADED = 1;
  1698. Engine._DELAYLOADSTATE_LOADING = 2;
  1699. Engine._DELAYLOADSTATE_NOTLOADED = 4;
  1700. Engine._TEXTUREFORMAT_ALPHA = 0;
  1701. Engine._TEXTUREFORMAT_LUMINANCE = 1;
  1702. Engine._TEXTUREFORMAT_LUMINANCE_ALPHA = 2;
  1703. Engine._TEXTUREFORMAT_RGB = 4;
  1704. Engine._TEXTUREFORMAT_RGBA = 4;
  1705. Engine.Epsilon = 0.001;
  1706. Engine.CollisionsEpsilon = 0.001;
  1707. Engine.ShadersRepository = "Babylon/Shaders/";
  1708. return Engine;
  1709. })();
  1710. BABYLON.Engine = Engine;
  1711. })(BABYLON || (BABYLON = {}));
  1712. //# sourceMappingURL=babylon.engine.js.map