(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("babylonjs")); else if(typeof define === 'function' && define.amd) define("babylonjs-materials", ["babylonjs"], factory); else if(typeof exports === 'object') exports["babylonjs-materials"] = factory(require("babylonjs")); else root["MATLIB"] = factory(root["BABYLON"]); })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-grid.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "../Tools/Gulp/node_modules/webpack/buildin/global.js": /*!************************************************************!*\ !*** ../Tools/Gulp/node_modules/webpack/buildin/global.js ***! \************************************************************/ /*! no static exports found */ /***/ (function(module, exports) { var g; // This works in non-strict mode g = (function() { return this; })(); try { // This works if eval is allowed (see CSP) g = g || Function("return this")() || (1, eval)("this"); } catch (e) { // This works if the window reference is available if (typeof window === "object") g = window; } // g can still be undefined, but nothing to do about it... // We return undefined, instead of nothing here, so it's // easier to handle this case. if(!global) { ...} module.exports = g; /***/ }), /***/ "./legacy/legacy-grid.ts": /*!*******************************!*\ !*** ./legacy/legacy-grid.ts ***! \*******************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) { function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); var MatLib = __webpack_require__(/*! ../src/grid/index */ "./src/grid/index.ts"); /** * This is the entry point for the UMD module. * The entry point for a future ESM package should be index.ts */ var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined); if (typeof globalObject !== "undefined") { for (var key in MatLib) { globalObject.BABYLON[key] = MatLib[key]; } } __export(__webpack_require__(/*! ../src/grid/index */ "./src/grid/index.ts")); /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../Tools/Gulp/node_modules/webpack/buildin/global.js"))) /***/ }), /***/ "./src/grid/grid.fragment.fx": /*!***********************************!*\ !*** ./src/grid/grid.fragment.fx ***! \***********************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = "#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include\n#endif\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nfloat opacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else\n\ngl_FragColor=vec4(color.rgb,1.0);\n#endif\n}" /***/ }), /***/ "./src/grid/grid.vertex.fx": /*!*********************************!*\ !*** ./src/grid/grid.vertex.fx ***! \*********************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\nvPosition=position;\nvNormal=normal;\n}" /***/ }), /***/ "./src/grid/gridMaterial.ts": /*!**********************************!*\ !*** ./src/grid/gridMaterial.ts ***! \**********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs"); babylonjs_1.Effect.ShadersStore["gridPixelShader"] = __webpack_require__(/*! ./grid.fragment.fx */ "./src/grid/grid.fragment.fx"); babylonjs_1.Effect.ShadersStore["gridVertexShader"] = __webpack_require__(/*! ./grid.vertex.fx */ "./src/grid/grid.vertex.fx"); var GridMaterialDefines = /** @class */ (function (_super) { __extends(GridMaterialDefines, _super); function GridMaterialDefines() { var _this = _super.call(this) || this; _this.TRANSPARENT = false; _this.FOG = false; _this.PREMULTIPLYALPHA = false; _this.rebuild(); return _this; } return GridMaterialDefines; }(babylonjs_1.MaterialDefines)); /** * The grid materials allows you to wrap any shape with a grid. * Colors are customizable. */ var GridMaterial = /** @class */ (function (_super) { __extends(GridMaterial, _super); /** * constructor * @param name The name given to the material in order to identify it afterwards. * @param scene The scene the material is used in. */ function GridMaterial(name, scene) { var _this = _super.call(this, name, scene) || this; /** * Main color of the grid (e.g. between lines) */ _this.mainColor = babylonjs_1.Color3.Black(); /** * Color of the grid lines. */ _this.lineColor = babylonjs_1.Color3.Teal(); /** * The scale of the grid compared to unit. */ _this.gridRatio = 1.0; /** * Allows setting an offset for the grid lines. */ _this.gridOffset = babylonjs_1.Vector3.Zero(); /** * The frequency of thicker lines. */ _this.majorUnitFrequency = 10; /** * The visibility of minor units in the grid. */ _this.minorUnitVisibility = 0.33; /** * The grid opacity outside of the lines. */ _this.opacity = 1.0; /** * Determine RBG output is premultiplied by alpha value. */ _this.preMultiplyAlpha = false; _this._gridControl = new babylonjs_1.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity); return _this; } /** * Returns wehter or not the grid requires alpha blending. */ GridMaterial.prototype.needAlphaBlending = function () { return this.opacity < 1.0; }; GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) { return this.needAlphaBlending(); }; GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) { if (this.isFrozen) { if (this._wasPreviouslyReady && subMesh.effect) { return true; } } if (!subMesh._materialDefines) { subMesh._materialDefines = new GridMaterialDefines(); } var defines = subMesh._materialDefines; var scene = this.getScene(); if (!this.checkReadyOnEveryCall && subMesh.effect) { if (this._renderId === scene.getRenderId()) { return true; } } if (defines.TRANSPARENT !== (this.opacity < 1.0)) { defines.TRANSPARENT = !defines.TRANSPARENT; defines.markAsUnprocessed(); } if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) { defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA; defines.markAsUnprocessed(); } babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, false, defines); // Get correct effect if (defines.isDirty) { defines.markAsProcessed(); scene.resetCachedMaterial(); // Attributes var attribs = [babylonjs_1.VertexBuffer.PositionKind, babylonjs_1.VertexBuffer.NormalKind]; // Defines var join = defines.toString(); subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines); } if (!subMesh.effect || !subMesh.effect.isReady()) { return false; } this._renderId = scene.getRenderId(); this._wasPreviouslyReady = true; return true; }; GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) { var scene = this.getScene(); var defines = subMesh._materialDefines; if (!defines) { return; } var effect = subMesh.effect; if (!effect) { return; } this._activeEffect = effect; // Matrices this.bindOnlyWorldMatrix(world); this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix())); this._activeEffect.setMatrix("view", scene.getViewMatrix()); this._activeEffect.setMatrix("projection", scene.getProjectionMatrix()); // Uniforms if (this._mustRebind(scene, effect)) { this._activeEffect.setColor3("mainColor", this.mainColor); this._activeEffect.setColor3("lineColor", this.lineColor); this._activeEffect.setVector3("gridOffset", this.gridOffset); this._gridControl.x = this.gridRatio; this._gridControl.y = Math.round(this.majorUnitFrequency); this._gridControl.z = this.minorUnitVisibility; this._gridControl.w = this.opacity; this._activeEffect.setVector4("gridControl", this._gridControl); } // Fog babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect); this._afterBind(mesh, this._activeEffect); }; /** * Dispose the material and its associated resources. * @param forceDisposeEffect will also dispose the used effect when true */ GridMaterial.prototype.dispose = function (forceDisposeEffect) { _super.prototype.dispose.call(this, forceDisposeEffect); }; GridMaterial.prototype.clone = function (name) { var _this = this; return babylonjs_1.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this); }; GridMaterial.prototype.serialize = function () { var serializationObject = babylonjs_1.SerializationHelper.Serialize(this); serializationObject.customType = "BABYLON.GridMaterial"; return serializationObject; }; GridMaterial.prototype.getClassName = function () { return "GridMaterial"; }; GridMaterial.Parse = function (source, scene, rootUrl) { return babylonjs_1.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl); }; __decorate([ babylonjs_1.serializeAsColor3() ], GridMaterial.prototype, "mainColor", void 0); __decorate([ babylonjs_1.serializeAsColor3() ], GridMaterial.prototype, "lineColor", void 0); __decorate([ babylonjs_1.serialize() ], GridMaterial.prototype, "gridRatio", void 0); __decorate([ babylonjs_1.serializeAsColor3() ], GridMaterial.prototype, "gridOffset", void 0); __decorate([ babylonjs_1.serialize() ], GridMaterial.prototype, "majorUnitFrequency", void 0); __decorate([ babylonjs_1.serialize() ], GridMaterial.prototype, "minorUnitVisibility", void 0); __decorate([ babylonjs_1.serialize() ], GridMaterial.prototype, "opacity", void 0); __decorate([ babylonjs_1.serialize() ], GridMaterial.prototype, "preMultiplyAlpha", void 0); return GridMaterial; }(BABYLON.PushMaterial)); exports.GridMaterial = GridMaterial; /***/ }), /***/ "./src/grid/index.ts": /*!***************************!*\ !*** ./src/grid/index.ts ***! \***************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); __export(__webpack_require__(/*! ./gridMaterial */ "./src/grid/gridMaterial.ts")); /***/ }), /***/ "babylonjs": /*!****************************************************************************************************!*\ !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***! \****************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__; /***/ }) /******/ }); }); //# sourceMappingURL=babylon.gridMaterial.js.map