"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _CesiumTilesLayer2 = _interopRequireDefault(require("../cesium-tiles-layer/CesiumTilesLayer"));
var _cesium = require("cesium");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var PipeTilesLayer = exports["default"] = /*#__PURE__*/function (_CesiumTilesLayer) {
  function PipeTilesLayer(opt_options) {
    _classCallCheck(this, PipeTilesLayer);
    var _ref = opt_options || {},
      defaultOpt = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
    return _callSuper(this, PipeTilesLayer, [_objectSpread(_objectSpread({}, defaultOpt), {}, {
      customShader: new _cesium.CustomShader({
        // lightingModel: LightingModel.UNLIT,
        lightingModel: _cesium.LightingModel.PBR,
        //设置变量，由顶点着色器传递给片元着色器
        varyings: {
          v_normalMC: _cesium.VaryingType.VEC3,
          v_st: _cesium.VaryingType.VEC3
        },
        //外部传给顶点着色器或者片元着色器
        uniforms: {
          u_texture: {
            value: new _cesium.TextureUniform({
              url: '/colors.png'
            }),
            type: _cesium.UniformType.SAMPLER_2D
          }
        },
        //贴纹理
        //顶点着色器
        //将法向量从顶点着色器设置变量传给片元着色器
        vertexShaderText: "\n            void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {\n                  v_normalMC = vsInput.attributes.normalMC;\n                  v_st=vsInput.attributes.positionMC ;\n            }",
        //片元着色器
        fragmentShaderText: "\n           void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {\n              vec3 positionMC = fsInput.attributes.positionMC;\n              //\u8FD9\u91CC\u662F\u8BBE\u7F6E\u8981\u8D34\u56FE\u7684\u56FE\u7247\u7684\u5C3A\u5BF8\uFF0C\u8BBE\u7F6E\u5C0F\u4E86\u4F1A\u91CD\u590D\n              float width = 100.0;\n              float height = 32.0;\n              vec3 rgb;\n              //\u8FD9\u662F\u662F\u8BBE\u7F6E\u4E86\u5C4B\u9876\u7684\u989C\u8272\uFF0C\u5F53\u548C\u6CD5\u5411\u91CF\u5E73\u884C\u65F6\uFF0C\u5C31\u662F\u5C4B\u9876\uFF0C\u8FD9\u91CC\u8BBE\u7F6E0.95\uFF0C\u76F8\u5F53\u4E8E\u5782\u76F4\uFF0C\u5EFA\u7B51\u7269\u56DB\u5468\u5F00\u59CB\u8D34\u56FE\n              float textureX = 0.0;\n                float dotYAxis = dot(vec3(0.0, 0.0, 1.0), v_normalMC);\n                // cos(45deg) \u7EA6\u7B49\u4E8E 0.71\uFF0C\u8FD9\u91CC\u662F\u5EFA\u7B51\u7269\u56DB\u5468\u7684\u5411\u91CF\u4E0E\u6CD5\u5411\u91CF\u4F1A\u5927\u4E8E\u56DB\u5341\u4E94\u5EA6\u5939\u89D2\n                if (dotYAxis > 0.71 || dotYAxis < -0.71) {\n                //x\u4EE3\u8868\u7684\u662F\u524D\u540E\u9762\n                  textureX = mod(positionMC.x, width) / width;\n                } else {\n                //z\u4EE3\u8868\u7684\u662F\u5DE6\u53F3\u9762\n                  textureX = mod(positionMC.z, width) / width;\n                }\n                float textureY = mod(positionMC.y, height) / height;\n\n                rgb = texture2D(u_texture, vec2(textureX, textureY)).rgb;\n                material.diffuse = rgb;\n          }"
      })
    })]);
  }
  _inherits(PipeTilesLayer, _CesiumTilesLayer);
  return _createClass(PipeTilesLayer);
}(_CesiumTilesLayer2["default"]);
//# sourceMappingURL=PipeTilesLayer.js.map
