babylon.furMaterial.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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-materials", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-materials"] = factory(require("babylonjs"));
  8. else
  9. root["MATERIALS"] = 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-fur.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../../node_modules/tslib/tslib.es6.js":
  99. /*!***********************************************************!*\
  100. !*** E:/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, __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__, "__await", function() { return __await; });
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
  120. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
  121. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
  122. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
  123. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
  124. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
  125. /*! *****************************************************************************
  126. Copyright (c) Microsoft Corporation. All rights reserved.
  127. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  128. this file except in compliance with the License. You may obtain a copy of the
  129. License at http://www.apache.org/licenses/LICENSE-2.0
  130. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  131. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  132. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  133. MERCHANTABLITY OR NON-INFRINGEMENT.
  134. See the Apache Version 2.0 License for specific language governing permissions
  135. and limitations under the License.
  136. ***************************************************************************** */
  137. /* global Reflect, Promise */
  138. var extendStatics = function(d, b) {
  139. extendStatics = Object.setPrototypeOf ||
  140. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  141. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  142. return extendStatics(d, b);
  143. };
  144. function __extends(d, b) {
  145. extendStatics(d, b);
  146. function __() { this.constructor = d; }
  147. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  148. }
  149. var __assign = function() {
  150. __assign = Object.assign || function __assign(t) {
  151. for (var s, i = 1, n = arguments.length; i < n; i++) {
  152. s = arguments[i];
  153. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  154. }
  155. return t;
  156. }
  157. return __assign.apply(this, arguments);
  158. }
  159. function __rest(s, e) {
  160. var t = {};
  161. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  162. t[p] = s[p];
  163. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  164. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
  165. t[p[i]] = s[p[i]];
  166. return t;
  167. }
  168. function __decorate(decorators, target, key, desc) {
  169. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  170. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  171. 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;
  172. return c > 3 && r && Object.defineProperty(target, key, r), r;
  173. }
  174. function __param(paramIndex, decorator) {
  175. return function (target, key) { decorator(target, key, paramIndex); }
  176. }
  177. function __metadata(metadataKey, metadataValue) {
  178. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  179. }
  180. function __awaiter(thisArg, _arguments, P, generator) {
  181. return new (P || (P = Promise))(function (resolve, reject) {
  182. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  183. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  184. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  185. step((generator = generator.apply(thisArg, _arguments || [])).next());
  186. });
  187. }
  188. function __generator(thisArg, body) {
  189. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  190. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  191. function verb(n) { return function (v) { return step([n, v]); }; }
  192. function step(op) {
  193. if (f) throw new TypeError("Generator is already executing.");
  194. while (_) try {
  195. 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;
  196. if (y = 0, t) op = [op[0] & 2, t.value];
  197. switch (op[0]) {
  198. case 0: case 1: t = op; break;
  199. case 4: _.label++; return { value: op[1], done: false };
  200. case 5: _.label++; y = op[1]; op = [0]; continue;
  201. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  202. default:
  203. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  204. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  205. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  206. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  207. if (t[2]) _.ops.pop();
  208. _.trys.pop(); continue;
  209. }
  210. op = body.call(thisArg, _);
  211. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  212. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  213. }
  214. }
  215. function __exportStar(m, exports) {
  216. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  217. }
  218. function __values(o) {
  219. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  220. if (m) return m.call(o);
  221. return {
  222. next: function () {
  223. if (o && i >= o.length) o = void 0;
  224. return { value: o && o[i++], done: !o };
  225. }
  226. };
  227. }
  228. function __read(o, n) {
  229. var m = typeof Symbol === "function" && o[Symbol.iterator];
  230. if (!m) return o;
  231. var i = m.call(o), r, ar = [], e;
  232. try {
  233. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  234. }
  235. catch (error) { e = { error: error }; }
  236. finally {
  237. try {
  238. if (r && !r.done && (m = i["return"])) m.call(i);
  239. }
  240. finally { if (e) throw e.error; }
  241. }
  242. return ar;
  243. }
  244. function __spread() {
  245. for (var ar = [], i = 0; i < arguments.length; i++)
  246. ar = ar.concat(__read(arguments[i]));
  247. return ar;
  248. }
  249. function __await(v) {
  250. return this instanceof __await ? (this.v = v, this) : new __await(v);
  251. }
  252. function __asyncGenerator(thisArg, _arguments, generator) {
  253. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  254. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  255. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  256. 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); }); }; }
  257. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  258. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  259. function fulfill(value) { resume("next", value); }
  260. function reject(value) { resume("throw", value); }
  261. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  262. }
  263. function __asyncDelegator(o) {
  264. var i, p;
  265. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  266. 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; }
  267. }
  268. function __asyncValues(o) {
  269. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  270. var m = o[Symbol.asyncIterator], i;
  271. 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);
  272. 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); }); }; }
  273. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  274. }
  275. function __makeTemplateObject(cooked, raw) {
  276. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  277. return cooked;
  278. };
  279. function __importStar(mod) {
  280. if (mod && mod.__esModule) return mod;
  281. var result = {};
  282. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  283. result.default = mod;
  284. return result;
  285. }
  286. function __importDefault(mod) {
  287. return (mod && mod.__esModule) ? mod : { default: mod };
  288. }
  289. /***/ }),
  290. /***/ "../../node_modules/webpack/buildin/global.js":
  291. /*!***********************************!*\
  292. !*** (webpack)/buildin/global.js ***!
  293. \***********************************/
  294. /*! no static exports found */
  295. /***/ (function(module, exports) {
  296. var g;
  297. // This works in non-strict mode
  298. g = (function() {
  299. return this;
  300. })();
  301. try {
  302. // This works if eval is allowed (see CSP)
  303. g = g || new Function("return this")();
  304. } catch (e) {
  305. // This works if the window reference is available
  306. if (typeof window === "object") g = window;
  307. }
  308. // g can still be undefined, but nothing to do about it...
  309. // We return undefined, instead of nothing here, so it's
  310. // easier to handle this case. if(!global) { ...}
  311. module.exports = g;
  312. /***/ }),
  313. /***/ "./fur/fur.fragment.ts":
  314. /*!*****************************!*\
  315. !*** ./fur/fur.fragment.ts ***!
  316. \*****************************/
  317. /*! exports provided: furPixelShader */
  318. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  319. "use strict";
  320. __webpack_require__.r(__webpack_exports__);
  321. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "furPixelShader", function() { return furPixelShader; });
  322. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Misc/decorators");
  323. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  324. var name = 'furPixelShader';
  325. var shader = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform float furOcclusion;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*max(occlusion,furOcclusion),1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";
  326. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  327. /** @hidden */
  328. var furPixelShader = { name: name, shader: shader };
  329. /***/ }),
  330. /***/ "./fur/fur.vertex.ts":
  331. /*!***************************!*\
  332. !*** ./fur/fur.vertex.ts ***!
  333. \***************************/
  334. /*! exports provided: furVertexShader */
  335. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  336. "use strict";
  337. __webpack_require__.r(__webpack_exports__);
  338. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "furVertexShader", function() { return furVertexShader; });
  339. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Materials/effect */ "babylonjs/Misc/decorators");
  340. /* harmony import */ var babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__);
  341. var name = 'furVertexShader';
  342. var shader = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else\nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  343. babylonjs_Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
  344. /** @hidden */
  345. var furVertexShader = { name: name, shader: shader };
  346. /***/ }),
  347. /***/ "./fur/furMaterial.ts":
  348. /*!****************************!*\
  349. !*** ./fur/furMaterial.ts ***!
  350. \****************************/
  351. /*! exports provided: FurMaterial */
  352. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  353. "use strict";
  354. __webpack_require__.r(__webpack_exports__);
  355. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FurMaterial", function() { return FurMaterial; });
  356. /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! tslib */ "../../node_modules/tslib/tslib.es6.js");
  357. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! babylonjs/Misc/decorators */ "babylonjs/Misc/decorators");
  358. /* harmony import */ var babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__);
  359. /* harmony import */ var _fur_fragment__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./fur.fragment */ "./fur/fur.fragment.ts");
  360. /* harmony import */ var _fur_vertex__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./fur.vertex */ "./fur/fur.vertex.ts");
  361. var FurMaterialDefines = /** @class */ (function (_super) {
  362. tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"](FurMaterialDefines, _super);
  363. function FurMaterialDefines() {
  364. var _this = _super.call(this) || this;
  365. _this.DIFFUSE = false;
  366. _this.HEIGHTMAP = false;
  367. _this.CLIPPLANE = false;
  368. _this.CLIPPLANE2 = false;
  369. _this.CLIPPLANE3 = false;
  370. _this.CLIPPLANE4 = false;
  371. _this.ALPHATEST = false;
  372. _this.DEPTHPREPASS = false;
  373. _this.POINTSIZE = false;
  374. _this.FOG = false;
  375. _this.NORMAL = false;
  376. _this.UV1 = false;
  377. _this.UV2 = false;
  378. _this.VERTEXCOLOR = false;
  379. _this.VERTEXALPHA = false;
  380. _this.NUM_BONE_INFLUENCERS = 0;
  381. _this.BonesPerMesh = 0;
  382. _this.INSTANCES = false;
  383. _this.HIGHLEVEL = false;
  384. _this.rebuild();
  385. return _this;
  386. }
  387. return FurMaterialDefines;
  388. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialDefines"]));
  389. var FurMaterial = /** @class */ (function (_super) {
  390. tslib__WEBPACK_IMPORTED_MODULE_0__["__extends"](FurMaterial, _super);
  391. function FurMaterial(name, scene) {
  392. var _this = _super.call(this, name, scene) || this;
  393. _this.diffuseColor = new babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Color3"](1, 1, 1);
  394. _this.furLength = 1;
  395. _this.furAngle = 0;
  396. _this.furColor = new babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Color3"](0.44, 0.21, 0.02);
  397. _this.furOffset = 0.0;
  398. _this.furSpacing = 12;
  399. _this.furGravity = new babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Vector3"](0, 0, 0);
  400. _this.furSpeed = 100;
  401. _this.furDensity = 20;
  402. _this.furOcclusion = 0.0;
  403. _this._disableLighting = false;
  404. _this._maxSimultaneousLights = 4;
  405. _this.highLevelFur = true;
  406. _this._furTime = 0;
  407. return _this;
  408. }
  409. Object.defineProperty(FurMaterial.prototype, "furTime", {
  410. get: function () {
  411. return this._furTime;
  412. },
  413. set: function (furTime) {
  414. this._furTime = furTime;
  415. },
  416. enumerable: true,
  417. configurable: true
  418. });
  419. FurMaterial.prototype.needAlphaBlending = function () {
  420. return (this.alpha < 1.0);
  421. };
  422. FurMaterial.prototype.needAlphaTesting = function () {
  423. return false;
  424. };
  425. FurMaterial.prototype.getAlphaTestTexture = function () {
  426. return null;
  427. };
  428. FurMaterial.prototype.updateFur = function () {
  429. for (var i = 1; i < this._meshes.length; i++) {
  430. var offsetFur = this._meshes[i].material;
  431. offsetFur.furLength = this.furLength;
  432. offsetFur.furAngle = this.furAngle;
  433. offsetFur.furGravity = this.furGravity;
  434. offsetFur.furSpacing = this.furSpacing;
  435. offsetFur.furSpeed = this.furSpeed;
  436. offsetFur.furColor = this.furColor;
  437. offsetFur.diffuseTexture = this.diffuseTexture;
  438. offsetFur.furTexture = this.furTexture;
  439. offsetFur.highLevelFur = this.highLevelFur;
  440. offsetFur.furTime = this.furTime;
  441. offsetFur.furDensity = this.furDensity;
  442. }
  443. };
  444. // Methods
  445. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  446. if (this.isFrozen) {
  447. if (this._wasPreviouslyReady && subMesh.effect) {
  448. return true;
  449. }
  450. }
  451. if (!subMesh._materialDefines) {
  452. subMesh._materialDefines = new FurMaterialDefines();
  453. }
  454. var defines = subMesh._materialDefines;
  455. var scene = this.getScene();
  456. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  457. if (this._renderId === scene.getRenderId()) {
  458. return true;
  459. }
  460. }
  461. var engine = scene.getEngine();
  462. // Textures
  463. if (defines._areTexturesDirty) {
  464. if (scene.texturesEnabled) {
  465. if (this.diffuseTexture && babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialFlags"].DiffuseTextureEnabled) {
  466. if (!this.diffuseTexture.isReady()) {
  467. return false;
  468. }
  469. else {
  470. defines._needUVs = true;
  471. defines.DIFFUSE = true;
  472. }
  473. }
  474. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  475. if (!this.heightTexture.isReady()) {
  476. return false;
  477. }
  478. else {
  479. defines._needUVs = true;
  480. defines.HEIGHTMAP = true;
  481. }
  482. }
  483. }
  484. }
  485. // High level
  486. if (this.highLevelFur !== defines.HIGHLEVEL) {
  487. defines.HIGHLEVEL = true;
  488. defines.markAsUnprocessed();
  489. }
  490. // Misc.
  491. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  492. // Lights
  493. defines._needNormals = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  494. // Values that need to be evaluated on every frame
  495. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  496. // Attribs
  497. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareDefinesForAttributes(mesh, defines, true, true);
  498. // Get correct effect
  499. if (defines.isDirty) {
  500. defines.markAsProcessed();
  501. scene.resetCachedMaterial();
  502. // Fallbacks
  503. var fallbacks = new babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["EffectFallbacks"]();
  504. if (defines.FOG) {
  505. fallbacks.addFallback(1, "FOG");
  506. }
  507. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  508. if (defines.NUM_BONE_INFLUENCERS > 0) {
  509. fallbacks.addCPUSkinningFallback(0, mesh);
  510. }
  511. //Attributes
  512. var attribs = [babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].PositionKind];
  513. if (defines.NORMAL) {
  514. attribs.push(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].NormalKind);
  515. }
  516. if (defines.UV1) {
  517. attribs.push(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UVKind);
  518. }
  519. if (defines.UV2) {
  520. attribs.push(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].UV2Kind);
  521. }
  522. if (defines.VERTEXCOLOR) {
  523. attribs.push(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["VertexBuffer"].ColorKind);
  524. }
  525. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  526. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareAttributesForInstances(attribs, defines);
  527. // Legacy browser patch
  528. var shaderName = "fur";
  529. var join = defines.toString();
  530. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  531. "vFogInfos", "vFogColor", "pointSize",
  532. "vDiffuseInfos",
  533. "mBones",
  534. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  535. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity", "furOcclusion"
  536. ];
  537. var samplers = ["diffuseSampler",
  538. "heightTexture", "furTexture"
  539. ];
  540. var uniformBuffers = new Array();
  541. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].PrepareUniformsAndSamplersList({
  542. uniformsNames: uniforms,
  543. uniformBuffersNames: uniformBuffers,
  544. samplers: samplers,
  545. defines: defines,
  546. maxSimultaneousLights: this.maxSimultaneousLights
  547. });
  548. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  549. attributes: attribs,
  550. uniformsNames: uniforms,
  551. uniformBuffersNames: uniformBuffers,
  552. samplers: samplers,
  553. defines: join,
  554. fallbacks: fallbacks,
  555. onCompiled: this.onCompiled,
  556. onError: this.onError,
  557. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  558. }, engine), defines);
  559. }
  560. if (!subMesh.effect || !subMesh.effect.isReady()) {
  561. return false;
  562. }
  563. this._renderId = scene.getRenderId();
  564. this._wasPreviouslyReady = true;
  565. return true;
  566. };
  567. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  568. var scene = this.getScene();
  569. var defines = subMesh._materialDefines;
  570. if (!defines) {
  571. return;
  572. }
  573. var effect = subMesh.effect;
  574. if (!effect) {
  575. return;
  576. }
  577. this._activeEffect = effect;
  578. // Matrices
  579. this.bindOnlyWorldMatrix(world);
  580. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  581. // Bones
  582. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].BindBonesParameters(mesh, this._activeEffect);
  583. if (scene.getCachedMaterial() !== this) {
  584. // Textures
  585. if (this._diffuseTexture && babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialFlags"].DiffuseTextureEnabled) {
  586. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  587. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  588. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  589. }
  590. if (this._heightTexture) {
  591. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  592. }
  593. // Clip plane
  594. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].BindClipPlane(this._activeEffect, scene);
  595. // Point size
  596. if (this.pointsCloud) {
  597. this._activeEffect.setFloat("pointSize", this.pointSize);
  598. }
  599. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].BindEyePosition(effect, scene);
  600. }
  601. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  602. if (scene.lightsEnabled && !this.disableLighting) {
  603. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  604. }
  605. // View
  606. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Scene"].FOGMODE_NONE) {
  607. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  608. }
  609. // Fog
  610. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["MaterialHelper"].BindFogParameters(scene, mesh, this._activeEffect);
  611. this._activeEffect.setFloat("furLength", this.furLength);
  612. this._activeEffect.setFloat("furAngle", this.furAngle);
  613. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  614. if (this.highLevelFur) {
  615. this._activeEffect.setVector3("furGravity", this.furGravity);
  616. this._activeEffect.setFloat("furOffset", this.furOffset);
  617. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  618. this._activeEffect.setFloat("furDensity", this.furDensity);
  619. this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
  620. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  621. this._activeEffect.setFloat("furTime", this._furTime);
  622. this._activeEffect.setTexture("furTexture", this.furTexture);
  623. }
  624. this._afterBind(mesh, this._activeEffect);
  625. };
  626. FurMaterial.prototype.getAnimatables = function () {
  627. var results = [];
  628. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  629. results.push(this.diffuseTexture);
  630. }
  631. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  632. results.push(this.heightTexture);
  633. }
  634. return results;
  635. };
  636. FurMaterial.prototype.getActiveTextures = function () {
  637. var activeTextures = _super.prototype.getActiveTextures.call(this);
  638. if (this._diffuseTexture) {
  639. activeTextures.push(this._diffuseTexture);
  640. }
  641. if (this._heightTexture) {
  642. activeTextures.push(this._heightTexture);
  643. }
  644. return activeTextures;
  645. };
  646. FurMaterial.prototype.hasTexture = function (texture) {
  647. if (_super.prototype.hasTexture.call(this, texture)) {
  648. return true;
  649. }
  650. if (this.diffuseTexture === texture) {
  651. return true;
  652. }
  653. if (this._heightTexture === texture) {
  654. return true;
  655. }
  656. return false;
  657. };
  658. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  659. if (this.diffuseTexture) {
  660. this.diffuseTexture.dispose();
  661. }
  662. if (this._meshes) {
  663. for (var i = 1; i < this._meshes.length; i++) {
  664. var mat = this._meshes[i].material;
  665. if (mat) {
  666. mat.dispose(forceDisposeEffect);
  667. }
  668. this._meshes[i].dispose();
  669. }
  670. }
  671. _super.prototype.dispose.call(this, forceDisposeEffect);
  672. };
  673. FurMaterial.prototype.clone = function (name) {
  674. var _this = this;
  675. return babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  676. };
  677. FurMaterial.prototype.serialize = function () {
  678. var serializationObject = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Serialize(this);
  679. serializationObject.customType = "BABYLON.FurMaterial";
  680. if (this._meshes) {
  681. serializationObject.sourceMeshName = this._meshes[0].name;
  682. serializationObject.quality = this._meshes.length;
  683. }
  684. return serializationObject;
  685. };
  686. FurMaterial.prototype.getClassName = function () {
  687. return "FurMaterial";
  688. };
  689. // Statics
  690. FurMaterial.Parse = function (source, scene, rootUrl) {
  691. var material = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["SerializationHelper"].Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  692. if (source.sourceMeshName && material.highLevelFur) {
  693. scene.executeWhenReady(function () {
  694. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  695. if (sourceMesh) {
  696. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  697. material.furTexture = furTexture;
  698. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  699. }
  700. });
  701. }
  702. return material;
  703. };
  704. FurMaterial.GenerateTexture = function (name, scene) {
  705. // Generate fur textures
  706. var texture = new babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["DynamicTexture"]("FurTexture " + name, 256, scene, true);
  707. var context = texture.getContext();
  708. for (var i = 0; i < 20000; ++i) {
  709. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  710. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  711. }
  712. texture.update(false);
  713. texture.wrapU = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  714. texture.wrapV = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Texture"].WRAP_ADDRESSMODE;
  715. return texture;
  716. };
  717. // Creates and returns an array of meshes used as shells for the Fur Material
  718. // that can be disposed later in your code
  719. // The quality is in interval [0, 100]
  720. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  721. var meshes = [sourceMesh];
  722. var mat = sourceMesh.material;
  723. var i;
  724. if (!(mat instanceof FurMaterial)) {
  725. throw "The material of the source mesh must be a Fur Material";
  726. }
  727. for (i = 1; i < quality; i++) {
  728. var offsetFur = new FurMaterial(mat.name + i, sourceMesh.getScene());
  729. sourceMesh.getScene().materials.pop();
  730. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Tags"].EnableFor(offsetFur);
  731. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Tags"].AddTagsTo(offsetFur, "furShellMaterial");
  732. offsetFur.furLength = mat.furLength;
  733. offsetFur.furAngle = mat.furAngle;
  734. offsetFur.furGravity = mat.furGravity;
  735. offsetFur.furSpacing = mat.furSpacing;
  736. offsetFur.furSpeed = mat.furSpeed;
  737. offsetFur.furColor = mat.furColor;
  738. offsetFur.diffuseTexture = mat.diffuseTexture;
  739. offsetFur.furOffset = i / quality;
  740. offsetFur.furTexture = mat.furTexture;
  741. offsetFur.highLevelFur = mat.highLevelFur;
  742. offsetFur.furTime = mat.furTime;
  743. offsetFur.furDensity = mat.furDensity;
  744. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  745. offsetMesh.material = offsetFur;
  746. offsetMesh.skeleton = sourceMesh.skeleton;
  747. offsetMesh.position = babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero();
  748. meshes.push(offsetMesh);
  749. }
  750. for (i = 1; i < meshes.length; i++) {
  751. meshes[i].parent = sourceMesh;
  752. }
  753. sourceMesh.material._meshes = meshes;
  754. return meshes;
  755. };
  756. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  757. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serializeAsTexture"])("diffuseTexture")
  758. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  759. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  760. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["expandToProperty"])("_markAllSubMeshesAsTexturesDirty")
  761. ], FurMaterial.prototype, "diffuseTexture", void 0);
  762. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  763. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serializeAsTexture"])("heightTexture")
  764. ], FurMaterial.prototype, "_heightTexture", void 0);
  765. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  766. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["expandToProperty"])("_markAllSubMeshesAsTexturesDirty")
  767. ], FurMaterial.prototype, "heightTexture", void 0);
  768. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  769. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serializeAsColor3"])()
  770. ], FurMaterial.prototype, "diffuseColor", void 0);
  771. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  772. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  773. ], FurMaterial.prototype, "furLength", void 0);
  774. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  775. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  776. ], FurMaterial.prototype, "furAngle", void 0);
  777. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  778. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serializeAsColor3"])()
  779. ], FurMaterial.prototype, "furColor", void 0);
  780. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  781. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  782. ], FurMaterial.prototype, "furOffset", void 0);
  783. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  784. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  785. ], FurMaterial.prototype, "furSpacing", void 0);
  786. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  787. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serializeAsVector3"])()
  788. ], FurMaterial.prototype, "furGravity", void 0);
  789. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  790. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  791. ], FurMaterial.prototype, "furSpeed", void 0);
  792. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  793. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  794. ], FurMaterial.prototype, "furDensity", void 0);
  795. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  796. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  797. ], FurMaterial.prototype, "furOcclusion", void 0);
  798. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  799. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("disableLighting")
  800. ], FurMaterial.prototype, "_disableLighting", void 0);
  801. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  802. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["expandToProperty"])("_markAllSubMeshesAsLightsDirty")
  803. ], FurMaterial.prototype, "disableLighting", void 0);
  804. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  805. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])("maxSimultaneousLights")
  806. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  807. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  808. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["expandToProperty"])("_markAllSubMeshesAsLightsDirty")
  809. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  810. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  811. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  812. ], FurMaterial.prototype, "highLevelFur", void 0);
  813. tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
  814. Object(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
  815. ], FurMaterial.prototype, "furTime", null);
  816. return FurMaterial;
  817. }(babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["PushMaterial"]));
  818. babylonjs_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["_TypeStore"].RegisteredTypes["BABYLON.FurMaterial"] = FurMaterial;
  819. /***/ }),
  820. /***/ "./fur/index.ts":
  821. /*!**********************!*\
  822. !*** ./fur/index.ts ***!
  823. \**********************/
  824. /*! exports provided: FurMaterial */
  825. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  826. "use strict";
  827. __webpack_require__.r(__webpack_exports__);
  828. /* harmony import */ var _furMaterial__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./furMaterial */ "./fur/furMaterial.ts");
  829. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FurMaterial", function() { return _furMaterial__WEBPACK_IMPORTED_MODULE_0__["FurMaterial"]; });
  830. /***/ }),
  831. /***/ "./legacy/legacy-fur.ts":
  832. /*!******************************!*\
  833. !*** ./legacy/legacy-fur.ts ***!
  834. \******************************/
  835. /*! exports provided: FurMaterial */
  836. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  837. "use strict";
  838. __webpack_require__.r(__webpack_exports__);
  839. /* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var _fur_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../fur/index */ "./fur/index.ts");
  840. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FurMaterial", function() { return _fur_index__WEBPACK_IMPORTED_MODULE_0__["FurMaterial"]; });
  841. /**
  842. * This is the entry point for the UMD module.
  843. * The entry point for a future ESM package should be index.ts
  844. */
  845. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  846. if (typeof globalObject !== "undefined") {
  847. for (var key in _fur_index__WEBPACK_IMPORTED_MODULE_0__) {
  848. globalObject.BABYLON[key] = _fur_index__WEBPACK_IMPORTED_MODULE_0__[key];
  849. }
  850. }
  851. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../node_modules/webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js")))
  852. /***/ }),
  853. /***/ "babylonjs/Misc/decorators":
  854. /*!****************************************************************************************************!*\
  855. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  856. \****************************************************************************************************/
  857. /*! no static exports found */
  858. /***/ (function(module, exports) {
  859. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs_Misc_decorators__;
  860. /***/ })
  861. /******/ });
  862. });
  863. //# sourceMappingURL=babylon.furMaterial.js.map