babylon.asciiArtPostProcess.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-post-process", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-post-process"] = factory(require("babylonjs"));
  8. else
  9. root["POSTPROCESSES"] = factory(root["BABYLON"]);
  10. })((typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : this), function(__WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_decorators__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-asciiArt.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** D:/Repos/Babylon.js/node_modules/tslib/tslib.es6.js ***!
  101. \***********************************************************/
  102. /*! exports provided: __extends, __assign, __rest, __decorate, __param, __metadata, __awaiter, __generator, __exportStar, __values, __read, __spread, __spreadArrays, __await, __asyncGenerator, __asyncDelegator, __asyncValues, __makeTemplateObject, __importStar, __importDefault */
  103. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  104. "use strict";
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
  107. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
  108. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
  109. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
  110. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
  112. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
  113. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
  114. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
  115. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
  116. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
  117. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
  118. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  125. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  126. /*! *****************************************************************************
  127. Copyright (c) Microsoft Corporation. All rights reserved.
  128. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  129. this file except in compliance with the License. You may obtain a copy of the
  130. License at http://www.apache.org/licenses/LICENSE-2.0
  131. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  132. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  133. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  134. MERCHANTABLITY OR NON-INFRINGEMENT.
  135. See the Apache Version 2.0 License for specific language governing permissions
  136. and limitations under the License.
  137. ***************************************************************************** */
  138. /* global Reflect, Promise */
  139. var extendStatics = function(d, b) {
  140. extendStatics = Object.setPrototypeOf ||
  141. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  142. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  143. return extendStatics(d, b);
  144. };
  145. function __extends(d, b) {
  146. extendStatics(d, b);
  147. function __() { this.constructor = d; }
  148. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  149. }
  150. var __assign = function() {
  151. __assign = Object.assign || function __assign(t) {
  152. for (var s, i = 1, n = arguments.length; i < n; i++) {
  153. s = arguments[i];
  154. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  155. }
  156. return t;
  157. }
  158. return __assign.apply(this, arguments);
  159. }
  160. function __rest(s, e) {
  161. var t = {};
  162. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  163. t[p] = s[p];
  164. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  165. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  166. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  167. t[p[i]] = s[p[i]];
  168. }
  169. return t;
  170. }
  171. function __decorate(decorators, target, key, desc) {
  172. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  173. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  174. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  175. return c > 3 && r && Object.defineProperty(target, key, r), r;
  176. }
  177. function __param(paramIndex, decorator) {
  178. return function (target, key) { decorator(target, key, paramIndex); }
  179. }
  180. function __metadata(metadataKey, metadataValue) {
  181. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  182. }
  183. function __awaiter(thisArg, _arguments, P, generator) {
  184. return new (P || (P = Promise))(function (resolve, reject) {
  185. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  186. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  187. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  188. step((generator = generator.apply(thisArg, _arguments || [])).next());
  189. });
  190. }
  191. function __generator(thisArg, body) {
  192. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  193. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  194. function verb(n) { return function (v) { return step([n, v]); }; }
  195. function step(op) {
  196. if (f) throw new TypeError("Generator is already executing.");
  197. while (_) try {
  198. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  199. if (y = 0, t) op = [op[0] & 2, t.value];
  200. switch (op[0]) {
  201. case 0: case 1: t = op; break;
  202. case 4: _.label++; return { value: op[1], done: false };
  203. case 5: _.label++; y = op[1]; op = [0]; continue;
  204. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  205. default:
  206. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  207. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  208. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  209. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  210. if (t[2]) _.ops.pop();
  211. _.trys.pop(); continue;
  212. }
  213. op = body.call(thisArg, _);
  214. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  215. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  216. }
  217. }
  218. function __exportStar(m, exports) {
  219. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  220. }
  221. function __values(o) {
  222. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  223. if (m) return m.call(o);
  224. return {
  225. next: function () {
  226. if (o && i >= o.length) o = void 0;
  227. return { value: o && o[i++], done: !o };
  228. }
  229. };
  230. }
  231. function __read(o, n) {
  232. var m = typeof Symbol === "function" && o[Symbol.iterator];
  233. if (!m) return o;
  234. var i = m.call(o), r, ar = [], e;
  235. try {
  236. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  237. }
  238. catch (error) { e = { error: error }; }
  239. finally {
  240. try {
  241. if (r && !r.done && (m = i["return"])) m.call(i);
  242. }
  243. finally { if (e) throw e.error; }
  244. }
  245. return ar;
  246. }
  247. function __spread() {
  248. for (var ar = [], i = 0; i < arguments.length; i++)
  249. ar = ar.concat(__read(arguments[i]));
  250. return ar;
  251. }
  252. function __spreadArrays() {
  253. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  254. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  255. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  256. r[k] = a[j];
  257. return r;
  258. };
  259. function __await(v) {
  260. return this instanceof __await ? (this.v = v, this) : new __await(v);
  261. }
  262. function __asyncGenerator(thisArg, _arguments, generator) {
  263. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  264. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  265. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  266. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  267. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  268. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  269. function fulfill(value) { resume("next", value); }
  270. function reject(value) { resume("throw", value); }
  271. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  272. }
  273. function __asyncDelegator(o) {
  274. var i, p;
  275. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  276. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  277. }
  278. function __asyncValues(o) {
  279. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  280. var m = o[Symbol.asyncIterator], i;
  281. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  282. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  283. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  284. }
  285. function __makeTemplateObject(cooked, raw) {
  286. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  287. return cooked;
  288. };
  289. function __importStar(mod) {
  290. if (mod && mod.__esModule) return mod;
  291. var result = {};
  292. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  293. result.default = mod;
  294. return result;
  295. }
  296. function __importDefault(mod) {
  297. return (mod && mod.__esModule) ? mod : { default: mod };
  298. }
  299. /***/ }),
  300. /***/ "../../node_modules/webpack/buildin/global.js":
  301. /*!***********************************!*\
  302. !*** (webpack)/buildin/global.js ***!
  303. \***********************************/
  304. /*! no static exports found */
  305. /***/ (function(module, exports) {
  306. var g;
  307. // This works in non-strict mode
  308. g = (function() {
  309. return this;
  310. })();
  311. try {
  312. // This works if eval is allowed (see CSP)
  313. g = g || new Function("return this")();
  314. } catch (e) {
  315. // This works if the window reference is available
  316. if (typeof window === "object") g = window;
  317. }
  318. // g can still be undefined, but nothing to do about it...
  319. // We return undefined, instead of nothing here, so it's
  320. // easier to handle this case. if(!global) { ...}
  321. module.exports = g;
  322. /***/ }),
  323. /***/ "./asciiArt/asciiArtPostProcess.ts":
  324. /*!*****************************************!*\
  325. !*** ./asciiArt/asciiArtPostProcess.ts ***!
  326. \*****************************************/
  327. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess */
  328. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  329. "use strict";
  330. __webpack_require__.r(__webpack_exports__);
  331. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return AsciiArtFontTexture; });
  332. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return AsciiArtPostProcess; });
  333. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  334. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Misc/decorators */ "babylonjs/Misc/decorators");
  335. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__);
  336. /* harmony import */ var _asciiart_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./asciiart.fragment */ "./asciiArt/asciiart.fragment.ts");
  337. /**
  338. * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
  339. *
  340. * It basically takes care rendering the font front the given font size to a texture.
  341. * This is used later on in the postprocess.
  342. */
  343. var AsciiArtFontTexture = /** @class */ (function (_super) {
  344. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(AsciiArtFontTexture, _super);
  345. /**
  346. * Create a new instance of the Ascii Art FontTexture class
  347. * @param name the name of the texture
  348. * @param font the font to use, use the W3C CSS notation
  349. * @param text the caracter set to use in the rendering.
  350. * @param scene the scene that owns the texture
  351. */
  352. function AsciiArtFontTexture(name, font, text, scene) {
  353. if (scene === void 0) { scene = null; }
  354. var _this = _super.call(this, scene) || this;
  355. scene = _this.getScene();
  356. if (!scene) {
  357. return _this;
  358. }
  359. _this.name = name;
  360. _this._text == text;
  361. _this._font == font;
  362. _this.wrapU = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  363. _this.wrapV = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].CLAMP_ADDRESSMODE;
  364. //this.anisotropicFilteringLevel = 1;
  365. // Get the font specific info.
  366. var maxCharHeight = _this.getFontHeight(font);
  367. var maxCharWidth = _this.getFontWidth(font);
  368. _this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
  369. // This is an approximate size, but should always be able to fit at least the maxCharCount.
  370. var textureWidth = Math.ceil(_this._charSize * text.length);
  371. var textureHeight = _this._charSize;
  372. // Create the texture that will store the font characters.
  373. _this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].NEAREST_SAMPLINGMODE);
  374. //scene.getEngine().setclamp
  375. var textureSize = _this.getSize();
  376. // Create a canvas with the final size: the one matching the texture.
  377. var canvas = document.createElement("canvas");
  378. canvas.width = textureSize.width;
  379. canvas.height = textureSize.height;
  380. var context = canvas.getContext("2d");
  381. context.textBaseline = "top";
  382. context.font = font;
  383. context.fillStyle = "white";
  384. context.imageSmoothingEnabled = false;
  385. // Sets the text in the texture.
  386. for (var i = 0; i < text.length; i++) {
  387. context.fillText(text[i], i * _this._charSize, -maxCharHeight.offset);
  388. }
  389. // Flush the text in the dynamic texture.
  390. scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
  391. return _this;
  392. }
  393. Object.defineProperty(AsciiArtFontTexture.prototype, "charSize", {
  394. /**
  395. * Gets the size of one char in the texture (each char fits in size * size space in the texture).
  396. */
  397. get: function () {
  398. return this._charSize;
  399. },
  400. enumerable: true,
  401. configurable: true
  402. });
  403. /**
  404. * Gets the max char width of a font.
  405. * @param font the font to use, use the W3C CSS notation
  406. * @return the max char width
  407. */
  408. AsciiArtFontTexture.prototype.getFontWidth = function (font) {
  409. var fontDraw = document.createElement("canvas");
  410. var ctx = fontDraw.getContext('2d');
  411. ctx.fillStyle = 'white';
  412. ctx.font = font;
  413. return ctx.measureText("W").width;
  414. };
  415. // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
  416. /**
  417. * Gets the max char height of a font.
  418. * @param font the font to use, use the W3C CSS notation
  419. * @return the max char height
  420. */
  421. AsciiArtFontTexture.prototype.getFontHeight = function (font) {
  422. var fontDraw = document.createElement("canvas");
  423. var ctx = fontDraw.getContext('2d');
  424. ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
  425. ctx.textBaseline = 'top';
  426. ctx.fillStyle = 'white';
  427. ctx.font = font;
  428. ctx.fillText('jH|', 0, 0);
  429. var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
  430. var start = -1;
  431. var end = -1;
  432. for (var row = 0; row < fontDraw.height; row++) {
  433. for (var column = 0; column < fontDraw.width; column++) {
  434. var index = (row * fontDraw.width + column) * 4;
  435. if (pixels[index] === 0) {
  436. if (column === fontDraw.width - 1 && start !== -1) {
  437. end = row;
  438. row = fontDraw.height;
  439. break;
  440. }
  441. continue;
  442. }
  443. else {
  444. if (start === -1) {
  445. start = row;
  446. }
  447. break;
  448. }
  449. }
  450. }
  451. return { height: (end - start) + 1, offset: start - 1 };
  452. };
  453. /**
  454. * Clones the current AsciiArtTexture.
  455. * @return the clone of the texture.
  456. */
  457. AsciiArtFontTexture.prototype.clone = function () {
  458. return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());
  459. };
  460. /**
  461. * Parses a json object representing the texture and returns an instance of it.
  462. * @param source the source JSON representation
  463. * @param scene the scene to create the texture for
  464. * @return the parsed texture
  465. */
  466. AsciiArtFontTexture.Parse = function (source, scene) {
  467. var texture = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Parse(function () { return new AsciiArtFontTexture(source.name, source.font, source.text, scene); }, source, scene, null);
  468. return texture;
  469. };
  470. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  471. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("font")
  472. ], AsciiArtFontTexture.prototype, "_font", void 0);
  473. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
  474. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("text")
  475. ], AsciiArtFontTexture.prototype, "_text", void 0);
  476. return AsciiArtFontTexture;
  477. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["BaseTexture"]));
  478. /**
  479. * AsciiArtPostProcess helps rendering everithing in Ascii Art.
  480. *
  481. * Simmply add it to your scene and let the nerd that lives in you have fun.
  482. * Example usage: var pp = new AsciiArtPostProcess("myAscii", "20px Monospace", camera);
  483. */
  484. var AsciiArtPostProcess = /** @class */ (function (_super) {
  485. Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"])(AsciiArtPostProcess, _super);
  486. /**
  487. * Instantiates a new Ascii Art Post Process.
  488. * @param name the name to give to the postprocess
  489. * @camera the camera to apply the post process to.
  490. * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format
  491. */
  492. function AsciiArtPostProcess(name, camera, options) {
  493. var _this = _super.call(this, name, 'asciiart', ['asciiArtFontInfos', 'asciiArtOptions'], ['asciiArtFont'], {
  494. width: camera.getEngine().getRenderWidth(),
  495. height: camera.getEngine().getRenderHeight()
  496. }, camera, babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
  497. /**
  498. * This defines the amount you want to mix the "tile" or caracter space colored in the ascii art.
  499. * This number is defined between 0 and 1;
  500. */
  501. _this.mixToTile = 0;
  502. /**
  503. * This defines the amount you want to mix the normal rendering pass in the ascii art.
  504. * This number is defined between 0 and 1;
  505. */
  506. _this.mixToNormal = 0;
  507. // Default values.
  508. var font = "40px Monospace";
  509. var characterSet = " `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";
  510. // Use options.
  511. if (options) {
  512. if (typeof (options) === "string") {
  513. font = options;
  514. }
  515. else {
  516. font = options.font || font;
  517. characterSet = options.characterSet || characterSet;
  518. _this.mixToTile = options.mixToTile || _this.mixToTile;
  519. _this.mixToNormal = options.mixToNormal || _this.mixToNormal;
  520. }
  521. }
  522. _this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());
  523. var textureSize = _this._asciiArtFontTexture.getSize();
  524. _this.onApply = function (effect) {
  525. effect.setTexture("asciiArtFont", _this._asciiArtFontTexture);
  526. effect.setFloat4("asciiArtFontInfos", _this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
  527. effect.setFloat4("asciiArtOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
  528. };
  529. return _this;
  530. }
  531. return AsciiArtPostProcess;
  532. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["PostProcess"]));
  533. /***/ }),
  534. /***/ "./asciiArt/asciiart.fragment.ts":
  535. /*!***************************************!*\
  536. !*** ./asciiArt/asciiart.fragment.ts ***!
  537. \***************************************/
  538. /*! exports provided: asciiartPixelShader */
  539. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  540. "use strict";
  541. __webpack_require__.r(__webpack_exports__);
  542. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "asciiartPixelShader", function() { return asciiartPixelShader; });
  543. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Misc/decorators");
  544. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  545. var name = 'asciiartPixelShader';
  546. var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void)\n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}";
  547. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  548. /** @hidden */
  549. var asciiartPixelShader = { name: name, shader: shader };
  550. /***/ }),
  551. /***/ "./asciiArt/index.ts":
  552. /*!***************************!*\
  553. !*** ./asciiArt/index.ts ***!
  554. \***************************/
  555. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess */
  556. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  557. "use strict";
  558. __webpack_require__.r(__webpack_exports__);
  559. /* harmony import */ var _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./asciiArtPostProcess */ "./asciiArt/asciiArtPostProcess.ts");
  560. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__["AsciiArtFontTexture"]; });
  561. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return _asciiArtPostProcess__WEBPACK_IMPORTED_MODULE_0__["AsciiArtPostProcess"]; });
  562. /***/ }),
  563. /***/ "./legacy/legacy-asciiArt.ts":
  564. /*!***********************************!*\
  565. !*** ./legacy/legacy-asciiArt.ts ***!
  566. \***********************************/
  567. /*! exports provided: AsciiArtFontTexture, AsciiArtPostProcess */
  568. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  569. "use strict";
  570. __webpack_require__.r(__webpack_exports__);
  571. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _asciiArt_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../asciiArt/index */ "./asciiArt/index.ts");
  572. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtFontTexture", function() { return _asciiArt_index__WEBPACK_IMPORTED_MODULE_0__["AsciiArtFontTexture"]; });
  573. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AsciiArtPostProcess", function() { return _asciiArt_index__WEBPACK_IMPORTED_MODULE_0__["AsciiArtPostProcess"]; });
  574. /**
  575. * This is the entry point for the UMD module.
  576. * The entry point for a future ESM package should be index.ts
  577. */
  578. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  579. if (typeof globalObject !== "undefined") {
  580. for (var key in _asciiArt_index__WEBPACK_IMPORTED_MODULE_0__) {
  581. globalObject.BABYLON[key] = _asciiArt_index__WEBPACK_IMPORTED_MODULE_0__[key];
  582. }
  583. }
  584. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  585. /***/ }),
  586. /***/ "babylonjs/Misc/decorators":
  587. /*!****************************************************************************************************!*\
  588. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  589. \****************************************************************************************************/
  590. /*! no static exports found */
  591. /***/ (function(module, exports) {
  592. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_decorators__;
  593. /***/ })
  594. /******/ });
  595. });
  596. //# sourceMappingURL=babylon.asciiArtPostProcess.js.map