mxdraw 0.1.3 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/lib/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.js +18 -1
  2. package/dist/lib/MxModule/MxDbImage/MxDbImage.js +20 -11
  3. package/dist/lib/MxModule/MxDbLine/MxDbLine.js +94 -0
  4. package/dist/lib/MxModule/MxDbLine/index.js +5 -0
  5. package/dist/lib/MxModule/MxDbRect/MxDbRect.js +249 -0
  6. package/dist/lib/MxModule/MxDbRect/index.js +4 -0
  7. package/dist/lib/MxModule/MxFilters/MxFilters.js +201 -0
  8. package/dist/lib/MxModule/MxFilters/index.js +4 -0
  9. package/dist/lib/MxModule/MxFun/MxFun.js +6 -2
  10. package/dist/lib/MxModule/MxThreeJS/MxThreeJS.mixin.js +1 -1
  11. package/dist/lib/MxModule/loadCoreCode/loadCoreCode.js +2 -0
  12. package/dist/lib/MxModule/loadCoreCode/mxfun.es5.js +20 -14
  13. package/dist/lib/MxModule/store/store.js +1 -3
  14. package/dist/lib/MxModule/useCanvasResizeListener/useCanvasResizeListener.js +16 -9
  15. package/dist/lib/doc.js +11 -1
  16. package/dist/lib/mxdraw.js +16 -9
  17. package/dist/lib/tools/three/index.js +106 -3
  18. package/dist/mxdraw.es5.js +3 -3
  19. package/dist/mxdraw.es5.js.map +1 -1
  20. package/dist/mxdraw.umd.js +3 -3
  21. package/dist/mxdraw.umd.js.map +1 -1
  22. package/dist/types/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.d.ts +1 -1
  23. package/dist/types/MxModule/MxDbEntity/MxDbEntity.d.ts +1 -1
  24. package/dist/types/MxModule/MxDbLine/MxDbLine.d.ts +22 -0
  25. package/dist/types/MxModule/MxDbLine/index.d.ts +3 -0
  26. package/dist/types/MxModule/MxDbRect/MxDbRect.d.ts +72 -0
  27. package/dist/types/MxModule/MxDbRect/index.d.ts +2 -0
  28. package/dist/types/MxModule/MxFilters/MxFilters.d.ts +94 -0
  29. package/dist/types/MxModule/MxFilters/index.d.ts +2 -0
  30. package/dist/types/MxModule/MxFun/MxFun.d.ts +3 -1
  31. package/dist/types/MxModule/store/store.d.ts +0 -1
  32. package/dist/types/doc.d.ts +6 -1
  33. package/dist/types/mxdraw.d.ts +11 -7
  34. package/dist/types/tools/three/index.d.ts +20 -1
  35. package/dist/types/types/MxFun.d.ts +1 -1
  36. package/package.json +1 -1
@@ -109,7 +109,24 @@ var MrxDbgUiPrPoint = /** @class */ (function () {
109
109
  * @returns void
110
110
  */
111
111
  MrxDbgUiPrPoint.prototype.go = function (retcall) {
112
- return _MrxDbgUiPrPoint.go(retcall);
112
+ if (retcall) {
113
+ _MrxDbgUiPrPoint.go(retcall);
114
+ return new Promise(function (resolve, reject) {
115
+ resolve(null);
116
+ });
117
+ }
118
+ else {
119
+ return new Promise(function (resolve, reject) {
120
+ _MrxDbgUiPrPoint.go(function (status) {
121
+ if (status != 0) {
122
+ resolve(null);
123
+ }
124
+ else {
125
+ resolve(_MrxDbgUiPrPoint.value());
126
+ }
127
+ });
128
+ });
129
+ }
113
130
  };
114
131
  /**
115
132
  * 动态拖动,连续取点,直到ESC退出。
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
  ///////////////////////////////////////////////////////////////////////////////
3
3
  //版权所有(C)2002-2022,成都梦想凯德科技有限公司。
4
- //本软件代码及其文档和相关资料归成都梦想凯德科技有限公司
5
- //应用包含本软件的程序必须包括以下声明
6
- //在版权声明中:
7
- //此应用程序与成都梦想凯德科技有限公司成协议。
8
- //通过使用本软件、其文档或相关材料
4
+ //本软件代码及其文档和相关资料归成都梦想凯德科技有限公司,应用包含本软件的程序必须包括以下版权声明
5
+ //此应用程序与成都梦想凯德科技有限公司成协议。通过使用本软件、其文档或相关材料
9
6
  ///////////////////////////////////////////////////////////////////////////////
10
7
  /** @module MxDbImage*/
11
8
  var __extends = (this && this.__extends) || (function () {
@@ -50,11 +47,11 @@ var MxDbImage = /** @class */ (function (_super) {
50
47
  var _this = this;
51
48
  var pt3 = new THREE.Vector3(this.pt1.x, this.pt2.y);
52
49
  var pt4 = new THREE.Vector3(this.pt2.x, this.pt1.y);
53
- pWorldDraw.drawLine(this.pt1, pt3);
54
- pWorldDraw.drawLine(pt3, this.pt2);
55
- pWorldDraw.drawLine(this.pt2, pt4);
56
- pWorldDraw.drawLine(pt4, this.pt1);
57
50
  if (pWorldDraw.getType() == 1) {
51
+ pWorldDraw.drawSelectLine(this.pt1, pt3);
52
+ pWorldDraw.drawSelectLine(pt3, this.pt2);
53
+ pWorldDraw.drawSelectLine(this.pt2, pt4);
54
+ pWorldDraw.drawSelectLine(pt4, this.pt1);
58
55
  // 图片正常的显示绘制.
59
56
  if (this.material) {
60
57
  var w = Math.abs(this.pt1.x - this.pt2.x);
@@ -73,7 +70,7 @@ var MxDbImage = /** @class */ (function (_super) {
73
70
  }
74
71
  else if (this.imagePath.length > 0 && this.isLoadMaterialFromPath) {
75
72
  var myThis_1 = this;
76
- MxFun_1.default.loadImageMaterial('./models/img/mxcad.jpg', function (material) {
73
+ MxFun_1.default.loadImageMaterial(this.imagePath, function (material) {
77
74
  _this.isLoadMaterialFromPath = false;
78
75
  if (!material) {
79
76
  return;
@@ -84,6 +81,12 @@ var MxDbImage = /** @class */ (function (_super) {
84
81
  });
85
82
  }
86
83
  }
84
+ else {
85
+ pWorldDraw.drawLine(this.pt1, pt3);
86
+ pWorldDraw.drawLine(pt3, this.pt2);
87
+ pWorldDraw.drawLine(this.pt2, pt4);
88
+ pWorldDraw.drawLine(pt4, this.pt1);
89
+ }
87
90
  };
88
91
  MxDbImage.prototype.setImagePath = function (sPath) {
89
92
  this.imagePath = sPath;
@@ -113,6 +116,8 @@ var MxDbImage = /** @class */ (function (_super) {
113
116
  var ret = [];
114
117
  ret.push(this.pt1);
115
118
  ret.push(this.pt2);
119
+ var midPt = new THREE.Vector3(this.pt1.x + (this.pt2.x - this.pt1.x) * 0.5, this.pt1.y + (this.pt2.y - this.pt1.y) * 0.5);
120
+ ret.push(midPt);
116
121
  return ret;
117
122
  };
118
123
  // 图片的夹点拖动编辑.
@@ -120,7 +125,11 @@ var MxDbImage = /** @class */ (function (_super) {
120
125
  if (index == 0) {
121
126
  this.pt1.add(offset);
122
127
  }
123
- else if ((index = 1)) {
128
+ else if (index == 1) {
129
+ this.pt2.add(offset);
130
+ }
131
+ else if (index == 2) {
132
+ this.pt1.add(offset);
124
133
  this.pt2.add(offset);
125
134
  }
126
135
  return true;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ ///////////////////////////////////////////////////////////////////////////////
19
+ //版权所有(C)2002-2022,成都梦想凯德科技有限公司。
20
+ //本软件代码及其文档和相关资料归成都梦想凯德科技有限公司,应用包含本软件的程序必须包括以下版权声明
21
+ //此应用程序与成都梦想凯德科技有限公司成协议。通过使用本软件、其文档或相关材料
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+ /** @module MxDbLine*/
24
+ var THREE = require("three");
25
+ var MxDbEntity_1 = require("../MxDbEntity");
26
+ /**
27
+ * MxDbLine 直线对象.
28
+ */
29
+ var MxDbLine = /** @class */ (function (_super) {
30
+ __extends(MxDbLine, _super);
31
+ function MxDbLine() {
32
+ var _this = _super !== null && _super.apply(this, arguments) || this;
33
+ // pt1,pt2
34
+ _this.pt1 = new THREE.Vector3();
35
+ _this.pt2 = new THREE.Vector3();
36
+ return _this;
37
+ }
38
+ MxDbLine.prototype.getTypeName = function () {
39
+ return 'MxDbLine';
40
+ };
41
+ MxDbLine.prototype.worldDraw = function (pWorldDraw) {
42
+ pWorldDraw.drawLine(this.pt1, this.pt2);
43
+ };
44
+ MxDbLine.prototype.setPoint1 = function (pt1) {
45
+ this.pt1 = pt1;
46
+ };
47
+ MxDbLine.prototype.getPoint1 = function () {
48
+ return this.pt1;
49
+ };
50
+ MxDbLine.prototype.setPoint2 = function (pt2) {
51
+ this.pt2 = pt2;
52
+ };
53
+ MxDbLine.prototype.getPoint2 = function () {
54
+ return this.pt2;
55
+ };
56
+ MxDbLine.prototype.getGripPoints = function () {
57
+ var ret = [];
58
+ ret.push(this.pt1);
59
+ ret.push(this.pt2);
60
+ var midPoint = new THREE.Vector3(this.pt1.x + (this.pt2.x - this.pt1.x) * 0.5, this.pt1.y + (this.pt2.y - this.pt1.y) * 0.5, 0);
61
+ ret.push(midPoint);
62
+ return ret;
63
+ };
64
+ MxDbLine.prototype.moveGripPointsAt = function (index, offset) {
65
+ if (index == 0) {
66
+ this.pt1.add(offset);
67
+ }
68
+ else if (index == 1) {
69
+ this.pt2.add(offset);
70
+ }
71
+ else if (index == 2) {
72
+ this.pt1.add(offset);
73
+ this.pt2.add(offset);
74
+ }
75
+ return true;
76
+ };
77
+ MxDbLine.prototype.dwgIn = function (obj) {
78
+ this.onDwgIn(obj);
79
+ this.pt1.copy(obj['pt1']);
80
+ this.pt2.copy(obj['pt2']);
81
+ return true;
82
+ };
83
+ MxDbLine.prototype.dwgOut = function (obj) {
84
+ this.onDwgOut(obj);
85
+ obj['pt1'] = this.pt1;
86
+ obj['pt2'] = this.pt2;
87
+ return obj;
88
+ };
89
+ MxDbLine.prototype.create = function () {
90
+ return new MxDbLine();
91
+ };
92
+ return MxDbLine;
93
+ }(MxDbEntity_1.default));
94
+ exports.default = MxDbLine;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /** @module McEdGetPointWorldDrawObject*/
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ var MxDbLine_1 = require("./MxDbLine");
5
+ exports.default = MxDbLine_1.default;
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ var MxDbEntity_1 = require("../MxDbEntity");
30
+ var three_1 = require("three");
31
+ var index_1 = require("../../tools/three/index");
32
+ var _ = require("lodash");
33
+ var MxFun_1 = require("../MxFun");
34
+ /**
35
+ * MxRectEntity 矩形对象.
36
+ */
37
+ var MxDbRect = /** @class */ (function (_super) {
38
+ __extends(MxDbRect, _super);
39
+ function MxDbRect() {
40
+ var _this = _super !== null && _super.apply(this, arguments) || this;
41
+ // 圆角半径
42
+ _this.cornerRadius = [];
43
+ /**
44
+ * pt1: 构成矩形的第一个点
45
+ * */
46
+ _this.pt1 = new three_1.Vector3();
47
+ /**
48
+ * pt1: 构成矩形的第二个点(对角点)
49
+ * */
50
+ _this.pt2 = new three_1.Vector3();
51
+ /**
52
+ * width: 在绘制时自动计算矩形像素宽度 单位px
53
+ * */
54
+ _this.width = 0;
55
+ /**
56
+ * height: 在绘制时自动计算矩形像素高度 单位px
57
+ * */
58
+ _this.height = 0;
59
+ /**
60
+ * transparent 开启透明度
61
+ * */
62
+ _this.transparent = true;
63
+ /**
64
+ * opacity 设置透明度 0 ~ 1
65
+ * */
66
+ _this.opacity = 1;
67
+ /**
68
+ * visible 该矩形对象是否可见
69
+ * */
70
+ _this.visible = true;
71
+ return _this;
72
+ }
73
+ MxDbRect.prototype.worldDraw = function (pWorldDraw) {
74
+ var _this = this;
75
+ // 根据第一个点和对角点 计算矩形的四个点位
76
+ var points = (0, index_1.computeRectPoints)(this.pt1, this.pt2);
77
+ if (this.cornerRadius.length > 0) {
78
+ points = (0, index_1.getToGenerateRoundedCorners)(points, this.cornerRadius);
79
+ }
80
+ var geometry;
81
+ var material;
82
+ var line = new three_1.Object3D();
83
+ // 公共的material参数
84
+ var materialParam = {
85
+ transparent: this.transparent,
86
+ opacity: this.opacity,
87
+ visible: this.visible
88
+ };
89
+ // 如果是填充模式
90
+ if (this.fillColor || this.fillImageSrc) {
91
+ // 三维坐标转二位坐标
92
+ points = points.map(function (_a) {
93
+ var x = _a.x, y = _a.y;
94
+ return new three_1.Vector2(x, y);
95
+ });
96
+ // 计算矩形宽高
97
+ geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
98
+ geometry.computeBoundingBox();
99
+ var size_1 = new three_1.Vector3();
100
+ geometry.boundingBox.getSize(size_1);
101
+ this.width = MxFun_1.default.docCoord2Screen(size_1.x).x;
102
+ this.height = MxFun_1.default.docCoord2Screen(size_1.y).x;
103
+ // 如果是图片填充
104
+ if (this.fillImageSrc) {
105
+ var imgSrc = this.fillImageSrc;
106
+ MxFun_1.default.loadImageMaterial(imgSrc, function (mate) {
107
+ if (!mate)
108
+ return;
109
+ material = mate;
110
+ geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
111
+ // 修复集合体的uv坐标
112
+ geometry = (0, index_1.repairGeometryFaceVertexUvs)(geometry);
113
+ // 纹理属性设置
114
+ var map = mate.map;
115
+ if (_this.fillImageParam) {
116
+ if (_this.fillImageParam.center)
117
+ map.center = _this.fillImageParam.center;
118
+ if (_this.fillImageParam.offset)
119
+ map.offset = _this.fillImageParam.offset;
120
+ if (_this.fillImageParam.repeat)
121
+ map.repeat = _this.fillImageParam.repeat;
122
+ if (_this.fillImageParam.rotation)
123
+ map.rotation = _this.fillImageParam.rotation;
124
+ }
125
+ // 有滤镜对象使用自定义着色器
126
+ if (_this.filter) {
127
+ var data = _this.filter._getFilterShaderData(map);
128
+ material = new three_1.ShaderMaterial(__assign(__assign({}, data), materialParam));
129
+ }
130
+ // 设置材质属性
131
+ material.depthTest = false;
132
+ material.transparent = _this.transparent;
133
+ material.opacity = _this.opacity;
134
+ material.visible = _this.visible;
135
+ line = new three_1.Mesh(geometry, material);
136
+ pWorldDraw.drawEntity(line);
137
+ });
138
+ return;
139
+ }
140
+ else {
141
+ // 颜色填充
142
+ material = new three_1.MeshBasicMaterial(__assign({ color: this.filter
143
+ ? this.filter._getFilterColor(this.fillColor, this.opacity)
144
+ : new three_1.Color(this.fillColor) }, materialParam));
145
+ line = new three_1.Mesh(geometry, material);
146
+ }
147
+ }
148
+ else {
149
+ // 线框模式
150
+ geometry = new three_1.BufferGeometry().setFromPoints(points);
151
+ material = new three_1.LineBasicMaterial(__assign({ color: this.getColor() }, materialParam));
152
+ line = new three_1.LineLoop(geometry, material);
153
+ }
154
+ // 计算矩形宽高
155
+ geometry.computeBoundingBox();
156
+ var size = new three_1.Vector3();
157
+ geometry.boundingBox.getSize(size);
158
+ this.width = MxFun_1.default.docCoord2Screen(size.x).x;
159
+ this.height = MxFun_1.default.docCoord2Screen(size.y).x;
160
+ pWorldDraw.drawEntity(line);
161
+ };
162
+ MxDbRect.prototype.getGripPoints = function () {
163
+ var ret = [];
164
+ ret.push(this.pt1);
165
+ var lineMath = new three_1.Line3(this.pt1, this.pt2);
166
+ var corePt = new three_1.Vector3();
167
+ lineMath.getCenter(corePt);
168
+ ret.push(corePt);
169
+ ret.push(this.pt2);
170
+ return ret;
171
+ };
172
+ MxDbRect.prototype.moveGripPointsAt = function (index, offset) {
173
+ if (index == 0) {
174
+ this.pt1.add(offset);
175
+ }
176
+ else if (index == 1) {
177
+ this.pt1.add(offset);
178
+ this.pt2.add(offset);
179
+ }
180
+ else if (index == 2) {
181
+ this.pt2.add(offset);
182
+ }
183
+ return true;
184
+ };
185
+ MxDbRect.prototype.dwgIn = function (obj) {
186
+ this.onDwgIn(obj);
187
+ this.pt1.copy(obj['pt1']);
188
+ this.pt2.copy(obj['pt2']);
189
+ this.fillColor = obj['fillColor'];
190
+ this.fillImageSrc = obj['fillImageSrc'];
191
+ this.fillImageSrc = obj['fillImageParam'];
192
+ this.cornerRadius = obj['cornerRadius'];
193
+ this.filter = obj['filter'];
194
+ this.transparent = obj['transparent'];
195
+ this.opacity = obj['opacity'];
196
+ this.visible = obj['visible'];
197
+ return true;
198
+ };
199
+ MxDbRect.prototype.dwgOut = function (obj) {
200
+ this.onDwgOut(obj);
201
+ obj['pt1'] = this.pt1;
202
+ obj['pt2'] = this.pt2;
203
+ obj['fillColor'] = this.fillColor;
204
+ obj['fillImageSrc'] = this.fillImageSrc;
205
+ obj['fillImageParam'] = this.fillImageParam;
206
+ obj['cornerRadius'] = this.cornerRadius;
207
+ obj['filter'] = this.filter;
208
+ obj['transparent'] = this.transparent;
209
+ obj['opacity'] = this.opacity;
210
+ obj['visible'] = this.visible;
211
+ return obj;
212
+ };
213
+ MxDbRect.prototype.create = function () {
214
+ return new MxDbRect();
215
+ };
216
+ MxDbRect.prototype.transformBy = function (mat) {
217
+ this.pt1.applyMatrix4(mat);
218
+ this.pt2.applyMatrix4(mat);
219
+ };
220
+ /**
221
+ * setRadius 设置圆角 圆角的半径 如[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4
222
+ * @param { number | number[] } radius 圆角半径 为数组时[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4; 或者直接设置半径值 则四个角统一半径
223
+ * */
224
+ MxDbRect.prototype.setRadius = function (radius) {
225
+ if (_.isArray(radius)) {
226
+ this.cornerRadius = radius.map(function (r) {
227
+ return MxFun_1.default.screenCoordLong2Doc(r);
228
+ });
229
+ }
230
+ else if (_.isNumber(radius)) {
231
+ if (radius > 0) {
232
+ this.cornerRadius = [
233
+ MxFun_1.default.screenCoordLong2Doc(radius),
234
+ MxFun_1.default.screenCoordLong2Doc(radius),
235
+ MxFun_1.default.screenCoordLong2Doc(radius),
236
+ MxFun_1.default.screenCoordLong2Doc(radius)
237
+ ];
238
+ }
239
+ else {
240
+ this.cornerRadius = [];
241
+ }
242
+ }
243
+ };
244
+ MxDbRect.prototype.getTypeName = function () {
245
+ return 'MxDbRect';
246
+ };
247
+ return MxDbRect;
248
+ }(MxDbEntity_1.default));
249
+ exports.default = MxDbRect;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var MxDbRect_1 = require("./MxDbRect");
4
+ exports.default = MxDbRect_1.default;
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ /** 简单颜色滤镜矩阵 */
15
+ var three_1 = require("three");
16
+ var MxFilters = /** @class */ (function () {
17
+ function MxFilters() {
18
+ this.uniformObj = {};
19
+ this.filtersStr = '';
20
+ this.filtersTypes = '';
21
+ //顶点着色器代码片段
22
+ this.VSHADER_SOURCE = "\n varying vec2 v_Uv; \n void main () {\n v_Uv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ";
23
+ //片元着色器代码片段
24
+ this.FSHADER_SOURCE = "\n varying vec2 v_Uv;\n uniform sampler2D e_Texture;\n uniform mat4 colorMatrix;\n ".concat(this.filtersStr, "\n void main () {\n vec4 color = texture2D( e_Texture, v_Uv );\n color = color * colorMatrix;\n ").concat(this.filtersTypes, "\n gl_FragColor = color;\n }");
25
+ this._matrix = new three_1.Matrix4();
26
+ }
27
+ /**
28
+ * 过滤或增强某个颜色通道
29
+ * @param {ChannelParamTypes}
30
+ * */
31
+ MxFilters.prototype.channel = function (_a) {
32
+ var _b = _a.r, r = _b === void 0 ? 1 : _b, _c = _a.g, g = _c === void 0 ? 1 : _c, _d = _a.b, b = _d === void 0 ? 1 : _d;
33
+ this._matrix = new three_1.Matrix4()
34
+ .set(r, 0, 0, 0, 0, g, 0, 0, 0, 0, b, 0, 0, 0, 0, 1)
35
+ .multiply(this._matrix);
36
+ return this;
37
+ };
38
+ /**
39
+ * 改变亮度
40
+ * @param {number} p
41
+ * p = 0 全暗,p > 0 且 p < 1 调暗,p = 1 原色, p > 1 调亮
42
+ * */
43
+ MxFilters.prototype.brightness = function (p) {
44
+ this._matrix = new three_1.Matrix4()
45
+ .set(p, 0, 0, 0, 0, p, 0, 0, 0, 0, p, 0, 0, 0, 0, 1)
46
+ .multiply(this._matrix);
47
+ return this;
48
+ };
49
+ /**
50
+ * 饱和度
51
+ * @param {number} p
52
+ * p = 0 完全灰度化,p = 1 原色,p > 1 增强饱和度
53
+ * */
54
+ MxFilters.prototype.saturate = function (p) {
55
+ var r = 0.2126 * (1 - p);
56
+ var g = 0.7152 * (1 - p);
57
+ var b = 0.0722 * (1 - p);
58
+ this._matrix = new three_1.Matrix4()
59
+ .set(r + p, g, b, 0, r, g + p, b, 0, r, g, b + p, 0, 0, 0, 0, 1)
60
+ .multiply(this._matrix);
61
+ return this;
62
+ };
63
+ /**
64
+ * 对比度
65
+ * @param {number} p
66
+ * p = 1 原色, p < 1 减弱对比度,p > 1 增强对比度
67
+ * */
68
+ MxFilters.prototype.contrast = function (p) {
69
+ var d = 0.5 * (1 - p);
70
+ this._matrix = new three_1.Matrix4()
71
+ .set(p, 0, 0, 0, 0, p, 0, 0, 0, 0, p, 0, d, d, d, 1)
72
+ .multiply(this._matrix);
73
+ return this;
74
+ };
75
+ /**
76
+ * 透明度
77
+ * @param {number} p
78
+ * p = 0 全透明,p = 1 原色
79
+ * */
80
+ MxFilters.prototype.opacity = function (p) {
81
+ this._matrix = new three_1.Matrix4()
82
+ .set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, p)
83
+ .multiply(this._matrix);
84
+ return this;
85
+ };
86
+ /**
87
+ * 反色
88
+ * @param {number} p
89
+ * p = 0 原色, p = 1 完全反色
90
+ * */
91
+ MxFilters.prototype.invert = function (p) {
92
+ var d = 1 - 2 * p;
93
+ this._matrix = new three_1.Matrix4()
94
+ .set(d, 0, 0, 0, 0, d, 0, 0, 0, 0, d, 0, p, p, p, 1)
95
+ .multiply(this._matrix);
96
+ return this;
97
+ };
98
+ /**
99
+ * 灰度
100
+ * @param {number} p 0~1
101
+ * */
102
+ MxFilters.prototype.grayscale = function (p) {
103
+ if (p === void 0) { p = 1; }
104
+ var r = 0.2126 * p;
105
+ var g = 0.7152 * p;
106
+ var b = 0.0722 * p;
107
+ this._matrix = new three_1.Matrix4()
108
+ .set(r + 1 - p, g, b, 0, r, g + 1 - p, b, 0, r, g, b + 1 - p, 0, 0, 0, 0, 1)
109
+ .multiply(this._matrix);
110
+ return this;
111
+ };
112
+ /**
113
+ * 深褐色
114
+ * @param {number} p 0~1
115
+ * */
116
+ MxFilters.prototype.sepia = function (p) {
117
+ if (p === void 0) { p = 1; }
118
+ this._matrix = new three_1.Matrix4()
119
+ .set(1 - 0.607 * p, 0.769 * p, 0.189 * p, 0, 0.349 * p, 1 - 0.314 * p, 0.168 * p, 0, 0.272 * p, 0.534 * p, 1 - 0.869 * p, 0, 0, 0, 0, 1)
120
+ .multiply(this._matrix);
121
+ return this;
122
+ };
123
+ /**
124
+ * 色相旋转,将色调沿极坐标转过deg角度
125
+ * @param {number} deg 0~360
126
+ * */
127
+ MxFilters.prototype.hueRotate = function (deg) {
128
+ var rotation = (deg / 180) * Math.PI;
129
+ var cos = Math.cos(rotation), sin = Math.sin(rotation), lumR = 0.2126, lumG = 0.7152, lumB = 0.0722;
130
+ this._matrix = new three_1.Matrix4()
131
+ .set(lumR + cos * (1 - lumR) + sin * -lumR, lumG + cos * -lumG + sin * -lumG, lumB + cos * -lumB + sin * (1 - lumB), 0, lumR + cos * -lumR + sin * 0.143, lumG + cos * (1 - lumG) + sin * 0.14, lumB + cos * -lumB + sin * -0.283, 0, lumR + cos * -lumR + sin * -(1 - lumR), lumG + cos * -lumG + sin * lumG, lumB + cos * (1 - lumB) + sin * lumB, 0, 0, 0, 0, 1)
132
+ .multiply(this._matrix);
133
+ return this;
134
+ };
135
+ /**
136
+ * 色相旋转,将色调沿极坐标转过deg角度
137
+ * @param {number} deg 0~360
138
+ * */
139
+ /**
140
+ * 卷积
141
+ * @param {Matrix3} cKernel 3*3的矩阵
142
+ * @param {number} stStep 1 / 9
143
+ * @param {number} scaleFactor 521
144
+ * */
145
+ MxFilters.prototype.convolution = function (cKernel, stStep, scaleFactor) {
146
+ if (stStep === void 0) { stStep = 1 / 9; }
147
+ if (scaleFactor === void 0) { scaleFactor = 521; }
148
+ this.uniformObj = __assign(__assign({}, this.uniformObj), { cKernel: {
149
+ value: cKernel.toArray()
150
+ }, stStep: {
151
+ value: stStep
152
+ }, scaleFactor: {
153
+ value: scaleFactor
154
+ } });
155
+ if (this.filtersTypes.indexOf('convolutionTextureColor') < 0) {
156
+ this.filtersStr += "\n uniform float cKernel[9];\n uniform float stStep;\n uniform float scaleFactor;\n vec4 convolutionTextureColor(vec4 color) {\n vec2 offsets[9];\n offsets[0] = vec2(-1.0,-1.0);\n offsets[1] = vec2(0.0,-1.0);\n offsets[2] = vec2(1.0,-1.0);\n offsets[3] = vec2(-1.0,0.0);\n offsets[4] = vec2(0.0,0.0);\n offsets[5] = vec2(1.0,0.0);\n offsets[6] = vec2(-1.0,1.0);\n offsets[7] = vec2(0.0,1.0);\n offsets[8] = vec2(1.0,1.0);\n \n vec4 sum = color;\n for(int i = 0; i < 9; i++) {\n sum = sum + cKernel[i] * scaleFactor * texture2D(e_Texture, v_Uv + offsets[i] / stStep);\n };\n return sum;\n }";
157
+ this.filtersTypes += 'color = convolutionTextureColor(color);\n';
158
+ }
159
+ return this;
160
+ };
161
+ /**
162
+ * 重置所有滤镜效果
163
+ * */
164
+ MxFilters.prototype.reset = function () {
165
+ this.uniformObj = {};
166
+ this.filtersStr = '';
167
+ this.filtersTypes = '';
168
+ this._matrix = new three_1.Matrix4();
169
+ return this;
170
+ };
171
+ // 获取滤镜自定义着色器数据
172
+ MxFilters.prototype._getFilterShaderData = function (texture) {
173
+ return {
174
+ uniforms: __assign({ e_Texture: {
175
+ value: texture
176
+ }, colorMatrix: {
177
+ value: this._matrix
178
+ } }, this.uniformObj),
179
+ // 顶点着色器
180
+ vertexShader: this.VSHADER_SOURCE,
181
+ // 片元着色器
182
+ fragmentShader: this.FSHADER_SOURCE
183
+ };
184
+ };
185
+ // 获取转换后的颜色
186
+ MxFilters.prototype._getFilterColor = function (color, opacity) {
187
+ if (color === void 0) { color = '#000000'; }
188
+ if (opacity === void 0) { opacity = 1; }
189
+ color = new three_1.Color(color);
190
+ var r = color.r, g = color.g, b = color.b;
191
+ var arr = this._matrix.toArray();
192
+ var A = arr[12] * opacity + arr[13] * opacity + arr[14] * opacity + arr[15] * opacity + 0;
193
+ var R = arr[0] * r + arr[1] * r + arr[2] * r + arr[3] * opacity;
194
+ var G = arr[4] * g + arr[5] * g + arr[6] * g + arr[7] * opacity;
195
+ var B = arr[8] * b + arr[9] * b + arr[10] * b + arr[11] * opacity;
196
+ color.setRGB(R, G, B);
197
+ return color;
198
+ };
199
+ return MxFilters;
200
+ }());
201
+ exports.default = MxFilters;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var MxFilters_1 = require("./MxFilters");
4
+ exports.default = MxFilters_1.default;