mxdraw 0.1.21 → 0.1.25

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 (120) hide show
  1. package/dist/lib/MxModule/McEdGetPointWorldDrawObject/McEdGetPointWorldDrawObjectClass.js +1 -128
  2. package/dist/lib/MxModule/McEdGetPointWorldDrawObject/index.js +1 -5
  3. package/dist/lib/MxModule/McGePoint3d/McGePoint3d.js +1 -0
  4. package/dist/lib/MxModule/McGePoint3d/index.js +1 -0
  5. package/dist/lib/MxModule/McGePoint3dArray/McGePoint3dArray.js +1 -0
  6. package/dist/lib/MxModule/McGePoint3dArray/index.js +1 -0
  7. package/dist/lib/MxModule/McGeTool/McGeTool.js +1 -0
  8. package/dist/lib/MxModule/McGeTool/index.js +1 -0
  9. package/dist/lib/MxModule/McGiWorldDraw/McGiWorldDraw.js +1 -3
  10. package/dist/lib/MxModule/McGiWorldDraw/index.js +1 -2
  11. package/dist/lib/MxModule/McGiWorldDrawType/McGiWorldDrawType.js +1 -19
  12. package/dist/lib/MxModule/McGiWorldDrawType/index.js +1 -4
  13. package/dist/lib/MxModule/MrxDbgUiPrBaseReturn/MrxDbgUiPrBaseReturn.js +1 -31
  14. package/dist/lib/MxModule/MrxDbgUiPrBaseReturn/index.js +1 -5
  15. package/dist/lib/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.js +1 -159
  16. package/dist/lib/MxModule/MrxDbgUiPrPoint/index.js +1 -5
  17. package/dist/lib/MxModule/Mx3PointArc/Mx3PointArc.js +1 -0
  18. package/dist/lib/MxModule/Mx3PointArc/index.js +1 -0
  19. package/dist/lib/MxModule/MxDb2LineAngularDimension/MxDb2LineAngularDimension.js +1 -0
  20. package/dist/lib/MxModule/MxDb2LineAngularDimension/index.js +1 -0
  21. package/dist/lib/MxModule/MxDbAlignedDimension/MxDbAlignedDimension.js +1 -213
  22. package/dist/lib/MxModule/MxDbAlignedDimension/index.js +1 -5
  23. package/dist/lib/MxModule/MxDbAnyLine/MxDbAnyLine.js +1 -0
  24. package/dist/lib/MxModule/MxDbAnyLine/index.js +1 -0
  25. package/dist/lib/MxModule/MxDbArea/MxDbArea.js +1 -0
  26. package/dist/lib/MxModule/MxDbArea/index.js +1 -0
  27. package/dist/lib/MxModule/MxDbCoord/MxDbCoord.js +1 -0
  28. package/dist/lib/MxModule/MxDbCoord/index.js +1 -0
  29. package/dist/lib/MxModule/MxDbEntity/MxDbEntity.js +1 -258
  30. package/dist/lib/MxModule/MxDbEntity/index.js +1 -5
  31. package/dist/lib/MxModule/MxDbImage/MxDbImage.js +1 -160
  32. package/dist/lib/MxModule/MxDbImage/index.js +1 -5
  33. package/dist/lib/MxModule/MxDbLine/MxDbLine.js +1 -94
  34. package/dist/lib/MxModule/MxDbLine/index.js +1 -5
  35. package/dist/lib/MxModule/MxDbPolyline/MxDbPolyline.js +1 -97
  36. package/dist/lib/MxModule/MxDbPolyline/index.js +1 -5
  37. package/dist/lib/MxModule/MxDbRect/MxDbRect.js +1 -273
  38. package/dist/lib/MxModule/MxDbRect/index.js +1 -4
  39. package/dist/lib/MxModule/MxDbSVG/MxDbSVG.js +1 -419
  40. package/dist/lib/MxModule/MxDbSVG/index.js +1 -5
  41. package/dist/lib/MxModule/MxDbSVGText/MxDbSVGText.js +1 -21
  42. package/dist/lib/MxModule/MxDbSVGText/index.js +1 -5
  43. package/dist/lib/MxModule/MxDrawObject/MxDrawObject.js +1 -782
  44. package/dist/lib/MxModule/MxDrawObject/index.js +1 -5
  45. package/dist/lib/MxModule/MxFilters/MxFilters.js +1 -201
  46. package/dist/lib/MxModule/MxFilters/index.js +1 -4
  47. package/dist/lib/MxModule/MxFun/MxFun.js +1 -676
  48. package/dist/lib/MxModule/MxFun/index.js +1 -4
  49. package/dist/lib/MxModule/MxThreeJS/MxThreeJS.js +1 -283
  50. package/dist/lib/MxModule/MxThreeJS/MxThreeJS.mixin.js +1 -146
  51. package/dist/lib/MxModule/MxThreeJS/index.js +1 -7
  52. package/dist/lib/MxModule/MxType/MxType.js +1 -27
  53. package/dist/lib/MxModule/MxType/index.js +1 -4
  54. package/dist/lib/MxModule/Mxassembly/Mxassembly.js +1 -20
  55. package/dist/lib/MxModule/Mxassembly/index.js +1 -9
  56. package/dist/lib/MxModule/loadCoreCode/index.js +1 -5
  57. package/dist/lib/MxModule/loadCoreCode/loadCoreCode.js +1 -125
  58. package/dist/lib/MxModule/loadCoreCode/mxUiData.js +1 -312
  59. package/dist/lib/MxModule/loadCoreCode/mxcadassembly_es5.js +1 -1519
  60. package/dist/lib/MxModule/loadCoreCode/mxfun.es5.js +1 -7363
  61. package/dist/lib/MxModule/store/PubsubClass.js +1 -40
  62. package/dist/lib/MxModule/store/StoreClass.js +1 -73
  63. package/dist/lib/MxModule/store/index.js +1 -19
  64. package/dist/lib/MxModule/store/store.js +1 -25
  65. package/dist/lib/MxModule/useCanvasResizeListener/index.js +1 -5
  66. package/dist/lib/MxModule/useCanvasResizeListener/useCanvasResizeListener.js +1 -95
  67. package/dist/lib/doc.js +1 -38
  68. package/dist/lib/mxdraw.js +1 -67
  69. package/dist/lib/tools/algorithm/math.js +1 -16
  70. package/dist/lib/tools/algorithm/random.js +1 -13
  71. package/dist/lib/tools/dom/create.js +1 -47
  72. package/dist/lib/tools/dynamicImport/index.js +1 -243
  73. package/dist/lib/tools/formatting/index.js +1 -20
  74. package/dist/lib/tools/proxy/index.js +1 -17
  75. package/dist/lib/tools/three/index.js +1 -124
  76. package/dist/mxdraw.es5.js +1 -0
  77. package/dist/mxdraw.umd.js +1 -0
  78. package/dist/types/MxModule/McEdGetPointWorldDrawObject/McEdGetPointWorldDrawObjectClass.d.ts +9 -0
  79. package/dist/types/MxModule/McGePoint3d/McGePoint3d.d.ts +11 -0
  80. package/dist/types/MxModule/McGePoint3d/index.d.ts +3 -0
  81. package/dist/types/MxModule/McGePoint3dArray/McGePoint3dArray.d.ts +14 -0
  82. package/dist/types/MxModule/McGePoint3dArray/index.d.ts +3 -0
  83. package/dist/types/MxModule/McGeTool/McGeTool.d.ts +38 -0
  84. package/dist/types/MxModule/McGeTool/index.d.ts +4 -0
  85. package/dist/types/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.d.ts +18 -1
  86. package/dist/types/MxModule/Mx3PointArc/Mx3PointArc.d.ts +19 -0
  87. package/dist/types/MxModule/Mx3PointArc/index.d.ts +3 -0
  88. package/dist/types/MxModule/MxDb2LineAngularDimension/MxDb2LineAngularDimension.d.ts +22 -0
  89. package/dist/types/MxModule/MxDb2LineAngularDimension/index.d.ts +3 -0
  90. package/dist/types/MxModule/MxDbAnyLine/MxDbAnyLine.d.ts +18 -0
  91. package/dist/types/MxModule/MxDbAnyLine/index.d.ts +3 -0
  92. package/dist/types/MxModule/MxDbArea/MxDbArea.d.ts +17 -0
  93. package/dist/types/MxModule/MxDbArea/index.d.ts +3 -0
  94. package/dist/types/MxModule/MxDbCoord/MxDbCoord.d.ts +19 -0
  95. package/dist/types/MxModule/MxDbCoord/index.d.ts +3 -0
  96. package/dist/types/MxModule/MxDrawObject/MxDrawObject.d.ts +70 -1
  97. package/dist/types/MxModule/MxFun/MxFun.d.ts +95 -30
  98. package/dist/types/MxModule/Mxassembly/Mxassembly.d.ts +11 -2
  99. package/dist/types/MxModule/store/store.d.ts +2 -2
  100. package/dist/types/mxdraw.d.ts +17 -4
  101. package/dist/types/tools/three/index.d.ts +28 -1
  102. package/package.json +3 -2
  103. package/dist/lib/MxModule/McGeVector3d/McGeVector3d.js +0 -2
  104. package/dist/lib/MxModule/McGeVector3d/index.js +0 -3
  105. package/dist/lib/MxModule/MxThreeJS/SVGLoader.js +0 -1862
  106. package/dist/lib/types/McEdGetPointWorldDrawObject.js +0 -2
  107. package/dist/lib/types/MrxDbgUiPrPoint.js +0 -2
  108. package/dist/lib/types/MxCADObject.js +0 -2
  109. package/dist/lib/types/MxDrawObject.js +0 -2
  110. package/dist/lib/types/MxFun.js +0 -2
  111. package/dist/lib/types/Mxassembly.js +0 -2
  112. package/dist/types/MxModule/McGeVector3d/McGeVector3d.d.ts +0 -17
  113. package/dist/types/MxModule/McGeVector3d/index.d.ts +0 -3
  114. package/dist/types/MxModule/MxThreeJS/SVGLoader.d.ts +0 -22
  115. package/dist/types/types/McEdGetPointWorldDrawObject.d.ts +0 -9
  116. package/dist/types/types/MrxDbgUiPrPoint.d.ts +0 -23
  117. package/dist/types/types/MxCADObject.d.ts +0 -40
  118. package/dist/types/types/MxDrawObject.d.ts +0 -60
  119. package/dist/types/types/MxFun.d.ts +0 -47
  120. package/dist/types/types/Mxassembly.d.ts +0 -3
@@ -1,1862 +0,0 @@
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
- exports.SVGLoader = void 0;
19
- var three_1 = require("three");
20
- var SVGLoader = /** @class */ (function (_super) {
21
- __extends(SVGLoader, _super);
22
- function SVGLoader(manager) {
23
- var _this = _super.call(this, manager) || this;
24
- // Default dots per inch
25
- _this.defaultDPI = 90;
26
- // Accepted units: 'mm', 'cm', 'in', 'pt', 'pc', 'px'
27
- _this.defaultUnit = 'px';
28
- return _this;
29
- }
30
- SVGLoader.prototype.load = function (url, onLoad, onProgress, onError) {
31
- var scope = this;
32
- var loader = new three_1.FileLoader(scope.manager);
33
- loader.setPath(scope.path);
34
- loader.setRequestHeader(scope.requestHeader);
35
- loader.setWithCredentials(scope.withCredentials);
36
- loader.load(url, function (text) {
37
- try {
38
- onLoad(scope.parse(text));
39
- }
40
- catch (e) {
41
- if (onError) {
42
- onError(e);
43
- }
44
- else {
45
- console.error(e);
46
- }
47
- scope.manager.itemError(url);
48
- }
49
- }, onProgress, onError);
50
- };
51
- SVGLoader.prototype.parse = function (text) {
52
- var scope = this;
53
- function parseNode(node, style) {
54
- if (node.nodeType !== 1)
55
- return;
56
- var transform = getNodeTransform(node);
57
- var traverseChildNodes = true;
58
- var path = null;
59
- switch (node.nodeName) {
60
- case 'svg':
61
- break;
62
- case 'style':
63
- parseCSSStylesheet(node);
64
- break;
65
- case 'g':
66
- style = parseStyle(node, style);
67
- break;
68
- case 'path':
69
- style = parseStyle(node, style);
70
- if (node.hasAttribute('d'))
71
- path = parsePathNode(node);
72
- break;
73
- case 'rect':
74
- style = parseStyle(node, style);
75
- path = parseRectNode(node);
76
- break;
77
- case 'polygon':
78
- style = parseStyle(node, style);
79
- path = parsePolygonNode(node);
80
- break;
81
- case 'polyline':
82
- style = parseStyle(node, style);
83
- path = parsePolylineNode(node);
84
- break;
85
- case 'circle':
86
- style = parseStyle(node, style);
87
- path = parseCircleNode(node);
88
- break;
89
- case 'ellipse':
90
- style = parseStyle(node, style);
91
- path = parseEllipseNode(node);
92
- break;
93
- case 'line':
94
- style = parseStyle(node, style);
95
- path = parseLineNode(node);
96
- break;
97
- case 'defs':
98
- traverseChildNodes = false;
99
- break;
100
- case 'use':
101
- style = parseStyle(node, style);
102
- var usedNodeId = node.href.baseVal.substring(1);
103
- var usedNode = node.viewportElement.getElementById(usedNodeId);
104
- if (usedNode) {
105
- parseNode(usedNode, style);
106
- }
107
- else {
108
- console.warn('SVGLoader: \'use node\' references non-existent node id: ' + usedNodeId);
109
- }
110
- break;
111
- default:
112
- // console.log( node );
113
- }
114
- if (path) {
115
- if (style.fill !== undefined && style.fill !== 'none') {
116
- path.color.setStyle(style.fill);
117
- }
118
- transformPath(path, currentTransform);
119
- paths.push(path);
120
- path.userData = { node: node, style: style };
121
- }
122
- if (traverseChildNodes) {
123
- var nodes = node.childNodes;
124
- for (var i = 0; i < nodes.length; i++) {
125
- parseNode(nodes[i], style);
126
- }
127
- }
128
- if (transform) {
129
- transformStack.pop();
130
- if (transformStack.length > 0) {
131
- currentTransform.copy(transformStack[transformStack.length - 1]);
132
- }
133
- else {
134
- currentTransform.identity();
135
- }
136
- }
137
- }
138
- function parsePathNode(node) {
139
- var path = new three_1.ShapePath();
140
- var point = new three_1.Vector2();
141
- var control = new three_1.Vector2();
142
- var firstPoint = new three_1.Vector2();
143
- var isFirstPoint = true;
144
- var doSetFirstPoint = false;
145
- var d = node.getAttribute('d');
146
- // console.log( d );
147
- var commands = d.match(/[a-df-z][^a-df-z]*/ig);
148
- for (var i = 0, l = commands.length; i < l; i++) {
149
- var command = commands[i];
150
- var type = command.charAt(0);
151
- var data_1 = command.substr(1).trim();
152
- if (isFirstPoint === true) {
153
- doSetFirstPoint = true;
154
- isFirstPoint = false;
155
- }
156
- var numbers = void 0;
157
- switch (type) {
158
- case 'M':
159
- numbers = parseFloats(data_1);
160
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
161
- point.x = numbers[j + 0];
162
- point.y = numbers[j + 1];
163
- control.x = point.x;
164
- control.y = point.y;
165
- if (j === 0) {
166
- path.moveTo(point.x, point.y);
167
- }
168
- else {
169
- path.lineTo(point.x, point.y);
170
- }
171
- if (j === 0)
172
- firstPoint.copy(point);
173
- }
174
- break;
175
- case 'H':
176
- numbers = parseFloats(data_1);
177
- for (var j = 0, jl = numbers.length; j < jl; j++) {
178
- point.x = numbers[j];
179
- control.x = point.x;
180
- control.y = point.y;
181
- path.lineTo(point.x, point.y);
182
- if (j === 0 && doSetFirstPoint === true)
183
- firstPoint.copy(point);
184
- }
185
- break;
186
- case 'V':
187
- numbers = parseFloats(data_1);
188
- for (var j = 0, jl = numbers.length; j < jl; j++) {
189
- point.y = numbers[j];
190
- control.x = point.x;
191
- control.y = point.y;
192
- path.lineTo(point.x, point.y);
193
- if (j === 0 && doSetFirstPoint === true)
194
- firstPoint.copy(point);
195
- }
196
- break;
197
- case 'L':
198
- numbers = parseFloats(data_1);
199
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
200
- point.x = numbers[j + 0];
201
- point.y = numbers[j + 1];
202
- control.x = point.x;
203
- control.y = point.y;
204
- path.lineTo(point.x, point.y);
205
- if (j === 0 && doSetFirstPoint === true)
206
- firstPoint.copy(point);
207
- }
208
- break;
209
- case 'C':
210
- numbers = parseFloats(data_1);
211
- for (var j = 0, jl = numbers.length; j < jl; j += 6) {
212
- path.bezierCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], numbers[j + 5]);
213
- control.x = numbers[j + 2];
214
- control.y = numbers[j + 3];
215
- point.x = numbers[j + 4];
216
- point.y = numbers[j + 5];
217
- if (j === 0 && doSetFirstPoint === true)
218
- firstPoint.copy(point);
219
- }
220
- break;
221
- case 'S':
222
- numbers = parseFloats(data_1);
223
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
224
- path.bezierCurveTo(getReflection(point.x, control.x), getReflection(point.y, control.y), numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
225
- control.x = numbers[j + 0];
226
- control.y = numbers[j + 1];
227
- point.x = numbers[j + 2];
228
- point.y = numbers[j + 3];
229
- if (j === 0 && doSetFirstPoint === true)
230
- firstPoint.copy(point);
231
- }
232
- break;
233
- case 'Q':
234
- numbers = parseFloats(data_1);
235
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
236
- path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
237
- control.x = numbers[j + 0];
238
- control.y = numbers[j + 1];
239
- point.x = numbers[j + 2];
240
- point.y = numbers[j + 3];
241
- if (j === 0 && doSetFirstPoint === true)
242
- firstPoint.copy(point);
243
- }
244
- break;
245
- case 'T':
246
- numbers = parseFloats(data_1);
247
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
248
- var rx = getReflection(point.x, control.x);
249
- var ry = getReflection(point.y, control.y);
250
- path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
251
- control.x = rx;
252
- control.y = ry;
253
- point.x = numbers[j + 0];
254
- point.y = numbers[j + 1];
255
- if (j === 0 && doSetFirstPoint === true)
256
- firstPoint.copy(point);
257
- }
258
- break;
259
- case 'A':
260
- numbers = parseFloats(data_1, [3, 4], 7);
261
- for (var j = 0, jl = numbers.length; j < jl; j += 7) {
262
- // skip command if start point == end point
263
- if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
264
- continue;
265
- var start = point.clone();
266
- point.x = numbers[j + 5];
267
- point.y = numbers[j + 6];
268
- control.x = point.x;
269
- control.y = point.y;
270
- parseArcCommand(path, numbers[j], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], start, point);
271
- if (j === 0 && doSetFirstPoint === true)
272
- firstPoint.copy(point);
273
- }
274
- break;
275
- case 'm':
276
- numbers = parseFloats(data_1);
277
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
278
- point.x += numbers[j + 0];
279
- point.y += numbers[j + 1];
280
- control.x = point.x;
281
- control.y = point.y;
282
- if (j === 0) {
283
- path.moveTo(point.x, point.y);
284
- }
285
- else {
286
- path.lineTo(point.x, point.y);
287
- }
288
- if (j === 0)
289
- firstPoint.copy(point);
290
- }
291
- break;
292
- case 'h':
293
- numbers = parseFloats(data_1);
294
- for (var j = 0, jl = numbers.length; j < jl; j++) {
295
- point.x += numbers[j];
296
- control.x = point.x;
297
- control.y = point.y;
298
- path.lineTo(point.x, point.y);
299
- if (j === 0 && doSetFirstPoint === true)
300
- firstPoint.copy(point);
301
- }
302
- break;
303
- case 'v':
304
- numbers = parseFloats(data_1);
305
- for (var j = 0, jl = numbers.length; j < jl; j++) {
306
- point.y += numbers[j];
307
- control.x = point.x;
308
- control.y = point.y;
309
- path.lineTo(point.x, point.y);
310
- if (j === 0 && doSetFirstPoint === true)
311
- firstPoint.copy(point);
312
- }
313
- break;
314
- case 'l':
315
- numbers = parseFloats(data_1);
316
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
317
- point.x += numbers[j + 0];
318
- point.y += numbers[j + 1];
319
- control.x = point.x;
320
- control.y = point.y;
321
- path.lineTo(point.x, point.y);
322
- if (j === 0 && doSetFirstPoint === true)
323
- firstPoint.copy(point);
324
- }
325
- break;
326
- case 'c':
327
- numbers = parseFloats(data_1);
328
- for (var j = 0, jl = numbers.length; j < jl; j += 6) {
329
- path.bezierCurveTo(point.x + numbers[j + 0], point.y + numbers[j + 1], point.x + numbers[j + 2], point.y + numbers[j + 3], point.x + numbers[j + 4], point.y + numbers[j + 5]);
330
- control.x = point.x + numbers[j + 2];
331
- control.y = point.y + numbers[j + 3];
332
- point.x += numbers[j + 4];
333
- point.y += numbers[j + 5];
334
- if (j === 0 && doSetFirstPoint === true)
335
- firstPoint.copy(point);
336
- }
337
- break;
338
- case 's':
339
- numbers = parseFloats(data_1);
340
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
341
- path.bezierCurveTo(getReflection(point.x, control.x), getReflection(point.y, control.y), point.x + numbers[j + 0], point.y + numbers[j + 1], point.x + numbers[j + 2], point.y + numbers[j + 3]);
342
- control.x = point.x + numbers[j + 0];
343
- control.y = point.y + numbers[j + 1];
344
- point.x += numbers[j + 2];
345
- point.y += numbers[j + 3];
346
- if (j === 0 && doSetFirstPoint === true)
347
- firstPoint.copy(point);
348
- }
349
- break;
350
- case 'q':
351
- numbers = parseFloats(data_1);
352
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
353
- path.quadraticCurveTo(point.x + numbers[j + 0], point.y + numbers[j + 1], point.x + numbers[j + 2], point.y + numbers[j + 3]);
354
- control.x = point.x + numbers[j + 0];
355
- control.y = point.y + numbers[j + 1];
356
- point.x += numbers[j + 2];
357
- point.y += numbers[j + 3];
358
- if (j === 0 && doSetFirstPoint === true)
359
- firstPoint.copy(point);
360
- }
361
- break;
362
- case 't':
363
- numbers = parseFloats(data_1);
364
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
365
- var rx = getReflection(point.x, control.x);
366
- var ry = getReflection(point.y, control.y);
367
- path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
368
- control.x = rx;
369
- control.y = ry;
370
- point.x = point.x + numbers[j + 0];
371
- point.y = point.y + numbers[j + 1];
372
- if (j === 0 && doSetFirstPoint === true)
373
- firstPoint.copy(point);
374
- }
375
- break;
376
- case 'a':
377
- numbers = parseFloats(data_1, [3, 4], 7);
378
- for (var j = 0, jl = numbers.length; j < jl; j += 7) {
379
- // skip command if no displacement
380
- if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
381
- continue;
382
- var start = point.clone();
383
- point.x += numbers[j + 5];
384
- point.y += numbers[j + 6];
385
- control.x = point.x;
386
- control.y = point.y;
387
- parseArcCommand(path, numbers[j], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], start, point);
388
- if (j === 0 && doSetFirstPoint === true)
389
- firstPoint.copy(point);
390
- }
391
- break;
392
- case 'Z':
393
- case 'z':
394
- path.currentPath.autoClose = true;
395
- if (path.currentPath.curves.length > 0) {
396
- // Reset point to beginning of Path
397
- point.copy(firstPoint);
398
- path.currentPath.currentPoint.copy(point);
399
- isFirstPoint = true;
400
- }
401
- break;
402
- default:
403
- console.warn(command);
404
- }
405
- // console.log( type, parseFloats( data ), parseFloats( data ).length )
406
- doSetFirstPoint = false;
407
- }
408
- return path;
409
- }
410
- function parseCSSStylesheet(node) {
411
- if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
412
- return;
413
- for (var i = 0; i < node.sheet.cssRules.length; i++) {
414
- var stylesheet = node.sheet.cssRules[i];
415
- if (stylesheet.type !== 1)
416
- continue;
417
- var selectorList = stylesheet.selectorText
418
- .split(/,/gm)
419
- .filter(Boolean)
420
- .map(function (i) { return i.trim(); });
421
- for (var j = 0; j < selectorList.length; j++) {
422
- stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, stylesheet.style);
423
- }
424
- }
425
- }
426
- /**
427
- * https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
428
- * https://mortoray.com/2017/02/16/rendering-an-svg-elliptical-arc-as-bezier-curves/ Appendix: Endpoint to center arc conversion
429
- * From
430
- * rx ry x-axis-rotation large-arc-flag sweep-flag x y
431
- * To
432
- * aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation
433
- */
434
- function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
435
- if (rx == 0 || ry == 0) {
436
- // draw a line if either of the radii == 0
437
- path.lineTo(end.x, end.y);
438
- return;
439
- }
440
- x_axis_rotation = x_axis_rotation * Math.PI / 180;
441
- // Ensure radii are positive
442
- rx = Math.abs(rx);
443
- ry = Math.abs(ry);
444
- // Compute (x1', y1')
445
- var dx2 = (start.x - end.x) / 2.0;
446
- var dy2 = (start.y - end.y) / 2.0;
447
- var x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
448
- var y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
449
- // Compute (cx', cy')
450
- var rxs = rx * rx;
451
- var rys = ry * ry;
452
- var x1ps = x1p * x1p;
453
- var y1ps = y1p * y1p;
454
- // Ensure radii are large enough
455
- var cr = x1ps / rxs + y1ps / rys;
456
- if (cr > 1) {
457
- // scale up rx,ry equally so cr == 1
458
- var s = Math.sqrt(cr);
459
- rx = s * rx;
460
- ry = s * ry;
461
- rxs = rx * rx;
462
- rys = ry * ry;
463
- }
464
- var dq = (rxs * y1ps + rys * x1ps);
465
- var pq = (rxs * rys - dq) / dq;
466
- var q = Math.sqrt(Math.max(0, pq));
467
- if (large_arc_flag === sweep_flag)
468
- q = -q;
469
- var cxp = q * rx * y1p / ry;
470
- var cyp = -q * ry * x1p / rx;
471
- // Step 3: Compute (cx, cy) from (cx', cy')
472
- var cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
473
- var cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
474
- // Step 4: Compute θ1 and Δθ
475
- var theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
476
- var delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
477
- path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
478
- }
479
- function svgAngle(ux, uy, vx, vy) {
480
- var dot = ux * vx + uy * vy;
481
- var len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
482
- var ang = Math.acos(Math.max(-1, Math.min(1, dot / len))); // floating point precision, slightly over values appear
483
- if ((ux * vy - uy * vx) < 0)
484
- ang = -ang;
485
- return ang;
486
- }
487
- /*
488
- * According to https://www.w3.org/TR/SVG/shapes.html#RectElementRXAttribute
489
- * rounded corner should be rendered to elliptical arc, but bezier curve does the job well enough
490
- */
491
- function parseRectNode(node) {
492
- var x = parseFloatWithUnits(node.getAttribute('x') || 0);
493
- var y = parseFloatWithUnits(node.getAttribute('y') || 0);
494
- var rx = parseFloatWithUnits(node.getAttribute('rx') || node.getAttribute('ry') || 0);
495
- var ry = parseFloatWithUnits(node.getAttribute('ry') || node.getAttribute('rx') || 0);
496
- var w = parseFloatWithUnits(node.getAttribute('width'));
497
- var h = parseFloatWithUnits(node.getAttribute('height'));
498
- // Ellipse arc to Bezier approximation Coefficient (Inversed). See:
499
- // https://spencermortensen.com/articles/bezier-circle/
500
- var bci = 1 - 0.551915024494;
501
- var path = new three_1.ShapePath();
502
- // top left
503
- path.moveTo(x + rx, y);
504
- // top right
505
- path.lineTo(x + w - rx, y);
506
- if (rx !== 0 || ry !== 0) {
507
- path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
508
- }
509
- // bottom right
510
- path.lineTo(x + w, y + h - ry);
511
- if (rx !== 0 || ry !== 0) {
512
- path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
513
- }
514
- // bottom left
515
- path.lineTo(x + rx, y + h);
516
- if (rx !== 0 || ry !== 0) {
517
- path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
518
- }
519
- // back to top left
520
- path.lineTo(x, y + ry);
521
- if (rx !== 0 || ry !== 0) {
522
- path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
523
- }
524
- return path;
525
- }
526
- function parsePolygonNode(node) {
527
- function iterator(match, a, b) {
528
- var x = parseFloatWithUnits(a);
529
- var y = parseFloatWithUnits(b);
530
- if (index === 0) {
531
- path.moveTo(x, y);
532
- }
533
- else {
534
- path.lineTo(x, y);
535
- }
536
- index++;
537
- }
538
- var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;
539
- var path = new three_1.ShapePath();
540
- var index = 0;
541
- node.getAttribute('points').replace(regex, iterator);
542
- path.currentPath.autoClose = true;
543
- return path;
544
- }
545
- function parsePolylineNode(node) {
546
- function iterator(match, a, b) {
547
- var x = parseFloatWithUnits(a);
548
- var y = parseFloatWithUnits(b);
549
- if (index === 0) {
550
- path.moveTo(x, y);
551
- }
552
- else {
553
- path.lineTo(x, y);
554
- }
555
- index++;
556
- }
557
- var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;
558
- var path = new three_1.ShapePath();
559
- var index = 0;
560
- node.getAttribute('points').replace(regex, iterator);
561
- path.currentPath.autoClose = false;
562
- return path;
563
- }
564
- function parseCircleNode(node) {
565
- var x = parseFloatWithUnits(node.getAttribute('cx') || 0);
566
- var y = parseFloatWithUnits(node.getAttribute('cy') || 0);
567
- var r = parseFloatWithUnits(node.getAttribute('r') || 0);
568
- var subpath = new three_1.Path();
569
- subpath.absarc(x, y, r, 0, Math.PI * 2);
570
- var path = new three_1.ShapePath();
571
- path.subPaths.push(subpath);
572
- return path;
573
- }
574
- function parseEllipseNode(node) {
575
- var x = parseFloatWithUnits(node.getAttribute('cx') || 0);
576
- var y = parseFloatWithUnits(node.getAttribute('cy') || 0);
577
- var rx = parseFloatWithUnits(node.getAttribute('rx') || 0);
578
- var ry = parseFloatWithUnits(node.getAttribute('ry') || 0);
579
- var subpath = new three_1.Path();
580
- subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
581
- var path = new three_1.ShapePath();
582
- path.subPaths.push(subpath);
583
- return path;
584
- }
585
- function parseLineNode(node) {
586
- var x1 = parseFloatWithUnits(node.getAttribute('x1') || 0);
587
- var y1 = parseFloatWithUnits(node.getAttribute('y1') || 0);
588
- var x2 = parseFloatWithUnits(node.getAttribute('x2') || 0);
589
- var y2 = parseFloatWithUnits(node.getAttribute('y2') || 0);
590
- var path = new three_1.ShapePath();
591
- path.moveTo(x1, y1);
592
- path.lineTo(x2, y2);
593
- path.currentPath.autoClose = false;
594
- return path;
595
- }
596
- //
597
- function parseStyle(node, style) {
598
- style = Object.assign({}, style); // clone style
599
- var stylesheetStyles = {};
600
- if (node.hasAttribute('class')) {
601
- var classSelectors = node.getAttribute('class')
602
- .split(/\s/)
603
- .filter(Boolean)
604
- .map(function (i) { return i.trim(); });
605
- for (var i = 0; i < classSelectors.length; i++) {
606
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets['.' + classSelectors[i]]);
607
- }
608
- }
609
- if (node.hasAttribute('id')) {
610
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets['#' + node.getAttribute('id')]);
611
- }
612
- function addStyle(svgName, jsName, adjustFunction) {
613
- if (adjustFunction === undefined)
614
- adjustFunction = function copy(v) {
615
- if (v.startsWith('url'))
616
- console.warn('SVGLoader: url access in attributes is not implemented.');
617
- return v;
618
- };
619
- if (node.hasAttribute(svgName))
620
- style[jsName] = adjustFunction(node.getAttribute(svgName));
621
- if (stylesheetStyles[svgName])
622
- style[jsName] = adjustFunction(stylesheetStyles[svgName]);
623
- if (node.style && node.style[svgName] !== '')
624
- style[jsName] = adjustFunction(node.style[svgName]);
625
- }
626
- function clamp(v) {
627
- return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
628
- }
629
- function positive(v) {
630
- return Math.max(0, parseFloatWithUnits(v));
631
- }
632
- addStyle('fill', 'fill');
633
- addStyle('fill-opacity', 'fillOpacity', clamp);
634
- addStyle('fill-rule', 'fillRule');
635
- addStyle('opacity', 'opacity', clamp);
636
- addStyle('stroke', 'stroke');
637
- addStyle('stroke-opacity', 'strokeOpacity', clamp);
638
- addStyle('stroke-width', 'strokeWidth', positive);
639
- addStyle('stroke-linejoin', 'strokeLineJoin');
640
- addStyle('stroke-linecap', 'strokeLineCap');
641
- addStyle('stroke-miterlimit', 'strokeMiterLimit', positive);
642
- addStyle('visibility', 'visibility');
643
- return style;
644
- }
645
- // http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
646
- function getReflection(a, b) {
647
- return a - (b - a);
648
- }
649
- // from https://github.com/ppvg/svg-numbers (MIT License)
650
- function parseFloats(input, flags, stride) {
651
- if (typeof input !== 'string') {
652
- throw new TypeError('Invalid input: ' + typeof input);
653
- }
654
- // Character groups
655
- var RE = {
656
- SEPARATOR: /[ \t\r\n\,.\-+]/,
657
- WHITESPACE: /[ \t\r\n]/,
658
- DIGIT: /[\d]/,
659
- SIGN: /[-+]/,
660
- POINT: /\./,
661
- COMMA: /,/,
662
- EXP: /e/i,
663
- FLAGS: /[01]/
664
- };
665
- // States
666
- var SEP = 0;
667
- var INT = 1;
668
- var FLOAT = 2;
669
- var EXP = 3;
670
- var state = SEP;
671
- var seenComma = true;
672
- var number = '', exponent = '';
673
- var result = [];
674
- function throwSyntaxError(current, i, partial) {
675
- var error = new SyntaxError('Unexpected character "' + current + '" at index ' + i + '.');
676
- error.partial = partial;
677
- throw error;
678
- }
679
- function newNumber() {
680
- if (number !== '') {
681
- if (exponent === '')
682
- result.push(Number(number));
683
- else
684
- result.push(Number(number) * Math.pow(10, Number(exponent)));
685
- }
686
- number = '';
687
- exponent = '';
688
- }
689
- var current;
690
- var length = input.length;
691
- for (var i = 0; i < length; i++) {
692
- current = input[i];
693
- // check for flags
694
- if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
695
- state = INT;
696
- number = current;
697
- newNumber();
698
- continue;
699
- }
700
- // parse until next number
701
- if (state === SEP) {
702
- // eat whitespace
703
- if (RE.WHITESPACE.test(current)) {
704
- continue;
705
- }
706
- // start new number
707
- if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
708
- state = INT;
709
- number = current;
710
- continue;
711
- }
712
- if (RE.POINT.test(current)) {
713
- state = FLOAT;
714
- number = current;
715
- continue;
716
- }
717
- // throw on double commas (e.g. "1, , 2")
718
- if (RE.COMMA.test(current)) {
719
- if (seenComma) {
720
- throwSyntaxError(current, i, result);
721
- }
722
- seenComma = true;
723
- }
724
- }
725
- // parse integer part
726
- if (state === INT) {
727
- if (RE.DIGIT.test(current)) {
728
- number += current;
729
- continue;
730
- }
731
- if (RE.POINT.test(current)) {
732
- number += current;
733
- state = FLOAT;
734
- continue;
735
- }
736
- if (RE.EXP.test(current)) {
737
- state = EXP;
738
- continue;
739
- }
740
- // throw on double signs ("-+1"), but not on sign as separator ("-1-2")
741
- if (RE.SIGN.test(current)
742
- && number.length === 1
743
- && RE.SIGN.test(number[0])) {
744
- throwSyntaxError(current, i, result);
745
- }
746
- }
747
- // parse decimal part
748
- if (state === FLOAT) {
749
- if (RE.DIGIT.test(current)) {
750
- number += current;
751
- continue;
752
- }
753
- if (RE.EXP.test(current)) {
754
- state = EXP;
755
- continue;
756
- }
757
- // throw on double decimal points (e.g. "1..2")
758
- if (RE.POINT.test(current) && number[number.length - 1] === '.') {
759
- throwSyntaxError(current, i, result);
760
- }
761
- }
762
- // parse exponent part
763
- if (state === EXP) {
764
- if (RE.DIGIT.test(current)) {
765
- exponent += current;
766
- continue;
767
- }
768
- if (RE.SIGN.test(current)) {
769
- if (exponent === '') {
770
- exponent += current;
771
- continue;
772
- }
773
- if (exponent.length === 1 && RE.SIGN.test(exponent)) {
774
- throwSyntaxError(current, i, result);
775
- }
776
- }
777
- }
778
- // end of number
779
- if (RE.WHITESPACE.test(current)) {
780
- newNumber();
781
- state = SEP;
782
- seenComma = false;
783
- }
784
- else if (RE.COMMA.test(current)) {
785
- newNumber();
786
- state = SEP;
787
- seenComma = true;
788
- }
789
- else if (RE.SIGN.test(current)) {
790
- newNumber();
791
- state = INT;
792
- number = current;
793
- }
794
- else if (RE.POINT.test(current)) {
795
- newNumber();
796
- state = FLOAT;
797
- number = current;
798
- }
799
- else {
800
- throwSyntaxError(current, i, result);
801
- }
802
- }
803
- // add the last number found (if any)
804
- newNumber();
805
- return result;
806
- }
807
- // Units
808
- var units = ['mm', 'cm', 'in', 'pt', 'pc', 'px'];
809
- // Conversion: [ fromUnit ][ toUnit ] (-1 means dpi dependent)
810
- var unitConversion = {
811
- 'mm': {
812
- 'mm': 1,
813
- 'cm': 0.1,
814
- 'in': 1 / 25.4,
815
- 'pt': 72 / 25.4,
816
- 'pc': 6 / 25.4,
817
- 'px': -1
818
- },
819
- 'cm': {
820
- 'mm': 10,
821
- 'cm': 1,
822
- 'in': 1 / 2.54,
823
- 'pt': 72 / 2.54,
824
- 'pc': 6 / 2.54,
825
- 'px': -1
826
- },
827
- 'in': {
828
- 'mm': 25.4,
829
- 'cm': 2.54,
830
- 'in': 1,
831
- 'pt': 72,
832
- 'pc': 6,
833
- 'px': -1
834
- },
835
- 'pt': {
836
- 'mm': 25.4 / 72,
837
- 'cm': 2.54 / 72,
838
- 'in': 1 / 72,
839
- 'pt': 1,
840
- 'pc': 6 / 72,
841
- 'px': -1
842
- },
843
- 'pc': {
844
- 'mm': 25.4 / 6,
845
- 'cm': 2.54 / 6,
846
- 'in': 1 / 6,
847
- 'pt': 72 / 6,
848
- 'pc': 1,
849
- 'px': -1
850
- },
851
- 'px': {
852
- 'px': 1
853
- }
854
- };
855
- function parseFloatWithUnits(string) {
856
- var theUnit = 'px';
857
- if (typeof string === 'string' || string instanceof String) {
858
- for (var i = 0, n = units.length; i < n; i++) {
859
- var u = units[i];
860
- if (string.endsWith(u)) {
861
- theUnit = u;
862
- string = string.substring(0, string.length - u.length);
863
- break;
864
- }
865
- }
866
- }
867
- var scale = undefined;
868
- if (theUnit === 'px' && scope.defaultUnit !== 'px') {
869
- // Conversion scale from pixels to inches, then to default units
870
- scale = unitConversion['in'][scope.defaultUnit] / scope.defaultDPI;
871
- }
872
- else {
873
- scale = unitConversion[theUnit][scope.defaultUnit];
874
- if (scale < 0) {
875
- // Conversion scale to pixels
876
- scale = unitConversion[theUnit]['in'] * scope.defaultDPI;
877
- }
878
- }
879
- return scale * parseFloat(string);
880
- }
881
- // Transforms
882
- function getNodeTransform(node) {
883
- if (!(node.hasAttribute('transform') || (node.nodeName === 'use' && (node.hasAttribute('x') || node.hasAttribute('y'))))) {
884
- return null;
885
- }
886
- var transform = parseNodeTransform(node);
887
- if (transformStack.length > 0) {
888
- transform.premultiply(transformStack[transformStack.length - 1]);
889
- }
890
- currentTransform.copy(transform);
891
- transformStack.push(transform);
892
- return transform;
893
- }
894
- function parseNodeTransform(node) {
895
- var transform = new three_1.Matrix3();
896
- var currentTransform = tempTransform0;
897
- if (node.nodeName === 'use' && (node.hasAttribute('x') || node.hasAttribute('y'))) {
898
- var tx = parseFloatWithUnits(node.getAttribute('x'));
899
- var ty = parseFloatWithUnits(node.getAttribute('y'));
900
- transform.translate(tx, ty);
901
- }
902
- if (node.hasAttribute('transform')) {
903
- var transformsTexts = node.getAttribute('transform').split(')');
904
- for (var tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
905
- var transformText = transformsTexts[tIndex].trim();
906
- if (transformText === '')
907
- continue;
908
- var openParPos = transformText.indexOf('(');
909
- var closeParPos = transformText.length;
910
- if (openParPos > 0 && openParPos < closeParPos) {
911
- var transformType = transformText.substr(0, openParPos);
912
- var array = parseFloats(transformText.substr(openParPos + 1, closeParPos - openParPos - 1));
913
- currentTransform.identity();
914
- switch (transformType) {
915
- case 'translate':
916
- if (array.length >= 1) {
917
- var tx = array[0];
918
- var ty = tx;
919
- if (array.length >= 2) {
920
- ty = array[1];
921
- }
922
- currentTransform.translate(tx, ty);
923
- }
924
- break;
925
- case 'rotate':
926
- if (array.length >= 1) {
927
- var angle = 0;
928
- var cx = 0;
929
- var cy = 0;
930
- // Angle
931
- angle = -array[0] * Math.PI / 180;
932
- if (array.length >= 3) {
933
- // Center x, y
934
- cx = array[1];
935
- cy = array[2];
936
- }
937
- // Rotate around center (cx, cy)
938
- tempTransform1.identity().translate(-cx, -cy);
939
- tempTransform2.identity().rotate(angle);
940
- tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
941
- tempTransform1.identity().translate(cx, cy);
942
- currentTransform.multiplyMatrices(tempTransform1, tempTransform3);
943
- }
944
- break;
945
- case 'scale':
946
- if (array.length >= 1) {
947
- var scaleX = array[0];
948
- var scaleY = scaleX;
949
- if (array.length >= 2) {
950
- scaleY = array[1];
951
- }
952
- currentTransform.scale(scaleX, scaleY);
953
- }
954
- break;
955
- case 'skewX':
956
- if (array.length === 1) {
957
- currentTransform.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
958
- }
959
- break;
960
- case 'skewY':
961
- if (array.length === 1) {
962
- currentTransform.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
963
- }
964
- break;
965
- case 'matrix':
966
- if (array.length === 6) {
967
- currentTransform.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
968
- }
969
- break;
970
- }
971
- }
972
- transform.premultiply(currentTransform);
973
- }
974
- }
975
- return transform;
976
- }
977
- function transformPath(path, m) {
978
- function transfVec2(v2) {
979
- tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
980
- v2.set(tempV3.x, tempV3.y);
981
- }
982
- var isRotated = isTransformRotated(m);
983
- var subPaths = path.subPaths;
984
- for (var i = 0, n = subPaths.length; i < n; i++) {
985
- var subPath = subPaths[i];
986
- var curves = subPath.curves;
987
- for (var j = 0; j < curves.length; j++) {
988
- var curve = curves[j];
989
- if (curve.isLineCurve) {
990
- transfVec2(curve.v1);
991
- transfVec2(curve.v2);
992
- }
993
- else if (curve.isCubicBezierCurve) {
994
- transfVec2(curve.v0);
995
- transfVec2(curve.v1);
996
- transfVec2(curve.v2);
997
- transfVec2(curve.v3);
998
- }
999
- else if (curve.isQuadraticBezierCurve) {
1000
- transfVec2(curve.v0);
1001
- transfVec2(curve.v1);
1002
- transfVec2(curve.v2);
1003
- }
1004
- else if (curve.isEllipseCurve) {
1005
- if (isRotated) {
1006
- console.warn('SVGLoader: Elliptic arc or ellipse rotation or skewing is not implemented.');
1007
- }
1008
- tempV2.set(curve.aX, curve.aY);
1009
- transfVec2(tempV2);
1010
- curve.aX = tempV2.x;
1011
- curve.aY = tempV2.y;
1012
- curve.xRadius *= getTransformScaleX(m);
1013
- curve.yRadius *= getTransformScaleY(m);
1014
- }
1015
- }
1016
- }
1017
- }
1018
- function isTransformRotated(m) {
1019
- return m.elements[1] !== 0 || m.elements[3] !== 0;
1020
- }
1021
- function getTransformScaleX(m) {
1022
- var te = m.elements;
1023
- return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
1024
- }
1025
- function getTransformScaleY(m) {
1026
- var te = m.elements;
1027
- return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
1028
- }
1029
- //
1030
- var paths = [];
1031
- var stylesheets = {};
1032
- var transformStack = [];
1033
- var tempTransform0 = new three_1.Matrix3();
1034
- var tempTransform1 = new three_1.Matrix3();
1035
- var tempTransform2 = new three_1.Matrix3();
1036
- var tempTransform3 = new three_1.Matrix3();
1037
- var tempV2 = new three_1.Vector2();
1038
- var tempV3 = new three_1.Vector3();
1039
- var currentTransform = new three_1.Matrix3();
1040
- var xml = new DOMParser().parseFromString(text, 'image/svg+xml'); // application/xml
1041
- parseNode(xml.documentElement, {
1042
- fill: '#000',
1043
- fillOpacity: 1,
1044
- strokeOpacity: 1,
1045
- strokeWidth: 1,
1046
- strokeLineJoin: 'miter',
1047
- strokeLineCap: 'butt',
1048
- strokeMiterLimit: 4
1049
- });
1050
- var data = { paths: paths, xml: xml.documentElement };
1051
- // console.log( paths );
1052
- return data;
1053
- };
1054
- SVGLoader.createShapes = function (shapePath) {
1055
- // Param shapePath: a shapepath as returned by the parse function of this class
1056
- // Returns Shape object
1057
- var BIGNUMBER = 999999999;
1058
- var IntersectionLocationType = {
1059
- ORIGIN: 0,
1060
- DESTINATION: 1,
1061
- BETWEEN: 2,
1062
- LEFT: 3,
1063
- RIGHT: 4,
1064
- BEHIND: 5,
1065
- BEYOND: 6
1066
- };
1067
- var classifyResult = {
1068
- loc: IntersectionLocationType.ORIGIN,
1069
- t: 0
1070
- };
1071
- function findEdgeIntersection(a0, a1, b0, b1) {
1072
- var x1 = a0.x;
1073
- var x2 = a1.x;
1074
- var x3 = b0.x;
1075
- var x4 = b1.x;
1076
- var y1 = a0.y;
1077
- var y2 = a1.y;
1078
- var y3 = b0.y;
1079
- var y4 = b1.y;
1080
- var nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
1081
- var nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
1082
- var denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
1083
- var t1 = nom1 / denom;
1084
- var t2 = nom2 / denom;
1085
- if (((denom === 0) && (nom1 !== 0)) || (t1 <= 0) || (t1 >= 1) || (t2 < 0) || (t2 > 1)) {
1086
- //1. lines are parallel or edges don't intersect
1087
- return null;
1088
- }
1089
- else if ((nom1 === 0) && (denom === 0)) {
1090
- //2. lines are colinear
1091
- //check if endpoints of edge2 (b0-b1) lies on edge1 (a0-a1)
1092
- for (var i = 0; i < 2; i++) {
1093
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1094
- //find position of this endpoints relatively to edge1
1095
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1096
- var point = (i === 0 ? b0 : b1);
1097
- return { x: point.x, y: point.y, t: classifyResult.t };
1098
- }
1099
- else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
1100
- var x = +((x1 + classifyResult.t * (x2 - x1)).toPrecision(10));
1101
- var y = +((y1 + classifyResult.t * (y2 - y1)).toPrecision(10));
1102
- return { x: x, y: y, t: classifyResult.t, };
1103
- }
1104
- }
1105
- return null;
1106
- }
1107
- else {
1108
- //3. edges intersect
1109
- for (var i = 0; i < 2; i++) {
1110
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1111
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1112
- var point = (i === 0 ? b0 : b1);
1113
- return { x: point.x, y: point.y, t: classifyResult.t };
1114
- }
1115
- }
1116
- var x = +((x1 + t1 * (x2 - x1)).toPrecision(10));
1117
- var y = +((y1 + t1 * (y2 - y1)).toPrecision(10));
1118
- return { x: x, y: y, t: t1 };
1119
- }
1120
- }
1121
- function classifyPoint(p, edgeStart, edgeEnd) {
1122
- var ax = edgeEnd.x - edgeStart.x;
1123
- var ay = edgeEnd.y - edgeStart.y;
1124
- var bx = p.x - edgeStart.x;
1125
- var by = p.y - edgeStart.y;
1126
- var sa = ax * by - bx * ay;
1127
- if ((p.x === edgeStart.x) && (p.y === edgeStart.y)) {
1128
- classifyResult.loc = IntersectionLocationType.ORIGIN;
1129
- classifyResult.t = 0;
1130
- return;
1131
- }
1132
- if ((p.x === edgeEnd.x) && (p.y === edgeEnd.y)) {
1133
- classifyResult.loc = IntersectionLocationType.DESTINATION;
1134
- classifyResult.t = 1;
1135
- return;
1136
- }
1137
- if (sa < -Number.EPSILON) {
1138
- classifyResult.loc = IntersectionLocationType.LEFT;
1139
- return;
1140
- }
1141
- if (sa > Number.EPSILON) {
1142
- classifyResult.loc = IntersectionLocationType.RIGHT;
1143
- return;
1144
- }
1145
- if (((ax * bx) < 0) || ((ay * by) < 0)) {
1146
- classifyResult.loc = IntersectionLocationType.BEHIND;
1147
- return;
1148
- }
1149
- if ((Math.sqrt(ax * ax + ay * ay)) < (Math.sqrt(bx * bx + by * by))) {
1150
- classifyResult.loc = IntersectionLocationType.BEYOND;
1151
- return;
1152
- }
1153
- var t;
1154
- if (ax !== 0) {
1155
- t = bx / ax;
1156
- }
1157
- else {
1158
- t = by / ay;
1159
- }
1160
- classifyResult.loc = IntersectionLocationType.BETWEEN;
1161
- classifyResult.t = t;
1162
- }
1163
- function getIntersections(path1, path2) {
1164
- var intersectionsRaw = [];
1165
- var intersections = [];
1166
- for (var index = 1; index < path1.length; index++) {
1167
- var path1EdgeStart = path1[index - 1];
1168
- var path1EdgeEnd = path1[index];
1169
- var _loop_1 = function (index2) {
1170
- var path2EdgeStart = path2[index2 - 1];
1171
- var path2EdgeEnd = path2[index2];
1172
- var intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
1173
- if (intersection !== null && intersectionsRaw.find(function (i) { return i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON; }) === undefined) {
1174
- intersectionsRaw.push(intersection);
1175
- intersections.push(new three_1.Vector2(intersection.x, intersection.y));
1176
- }
1177
- };
1178
- for (var index2 = 1; index2 < path2.length; index2++) {
1179
- _loop_1(index2);
1180
- }
1181
- }
1182
- return intersections;
1183
- }
1184
- function getScanlineIntersections(scanline, boundingBox, paths) {
1185
- var center = new three_1.Vector2();
1186
- boundingBox.getCenter(center);
1187
- var allIntersections = [];
1188
- paths.forEach(function (path) {
1189
- // check if the center of the bounding box is in the bounding box of the paths.
1190
- // this is a pruning method to limit the search of intersections in paths that can't envelop of the current path.
1191
- // if a path envelops another path. The center of that oter path, has to be inside the bounding box of the enveloping path.
1192
- if (path.boundingBox.containsPoint(center)) {
1193
- var intersections = getIntersections(scanline, path.points);
1194
- intersections.forEach(function (p) {
1195
- allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
1196
- });
1197
- }
1198
- });
1199
- allIntersections.sort(function (i1, i2) {
1200
- return i1.point.x - i2.point.x;
1201
- });
1202
- return allIntersections;
1203
- }
1204
- function isHoleTo(simplePath, allPaths, scanlineMinX, scanlineMaxX, _fillRule) {
1205
- if (_fillRule === null || _fillRule === undefined || _fillRule === '') {
1206
- _fillRule = 'nonzero';
1207
- }
1208
- var centerBoundingBox = new three_1.Vector2();
1209
- simplePath.boundingBox.getCenter(centerBoundingBox);
1210
- var scanline = [new three_1.Vector2(scanlineMinX, centerBoundingBox.y), new three_1.Vector2(scanlineMaxX, centerBoundingBox.y)];
1211
- var scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
1212
- scanlineIntersections.sort(function (i1, i2) {
1213
- return i1.point.x - i2.point.x;
1214
- });
1215
- var baseIntersections = [];
1216
- var otherIntersections = [];
1217
- scanlineIntersections.forEach(function (i) {
1218
- if (i.identifier === simplePath.identifier) {
1219
- baseIntersections.push(i);
1220
- }
1221
- else {
1222
- otherIntersections.push(i);
1223
- }
1224
- });
1225
- var firstXOfPath = baseIntersections[0].point.x;
1226
- // build up the path hierarchy
1227
- var stack = [];
1228
- var i = 0;
1229
- while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
1230
- if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
1231
- stack.pop();
1232
- }
1233
- else {
1234
- stack.push(otherIntersections[i].identifier);
1235
- }
1236
- i++;
1237
- }
1238
- stack.push(simplePath.identifier);
1239
- if (_fillRule === 'evenodd') {
1240
- var isHole = stack.length % 2 === 0 ? true : false;
1241
- var isHoleFor = stack[stack.length - 2];
1242
- return { identifier: simplePath.identifier, isHole: isHole, for: isHoleFor };
1243
- }
1244
- else if (_fillRule === 'nonzero') {
1245
- // check if path is a hole by counting the amount of paths with alternating rotations it has to cross.
1246
- var isHole = true;
1247
- var isHoleFor = null;
1248
- var lastCWValue = null;
1249
- for (var i_1 = 0; i_1 < stack.length; i_1++) {
1250
- var identifier_1 = stack[i_1];
1251
- if (isHole) {
1252
- lastCWValue = allPaths[identifier_1].isCW;
1253
- isHole = false;
1254
- isHoleFor = identifier_1;
1255
- }
1256
- else if (lastCWValue !== allPaths[identifier_1].isCW) {
1257
- lastCWValue = allPaths[identifier_1].isCW;
1258
- isHole = true;
1259
- }
1260
- }
1261
- return { identifier: simplePath.identifier, isHole: isHole, for: isHoleFor };
1262
- }
1263
- else {
1264
- console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
1265
- }
1266
- }
1267
- // check for self intersecting paths
1268
- // TODO
1269
- // check intersecting paths
1270
- // TODO
1271
- // prepare paths for hole detection
1272
- var identifier = 0;
1273
- var scanlineMinX = BIGNUMBER;
1274
- var scanlineMaxX = -BIGNUMBER;
1275
- var simplePaths = shapePath.subPaths.map(function (p) {
1276
- var points = p.getPoints();
1277
- var maxY = -BIGNUMBER;
1278
- var minY = BIGNUMBER;
1279
- var maxX = -BIGNUMBER;
1280
- var minX = BIGNUMBER;
1281
- //points.forEach(p => p.y *= -1);
1282
- for (var i = 0; i < points.length; i++) {
1283
- var p_1 = points[i];
1284
- if (p_1.y > maxY) {
1285
- maxY = p_1.y;
1286
- }
1287
- if (p_1.y < minY) {
1288
- minY = p_1.y;
1289
- }
1290
- if (p_1.x > maxX) {
1291
- maxX = p_1.x;
1292
- }
1293
- if (p_1.x < minX) {
1294
- minX = p_1.x;
1295
- }
1296
- }
1297
- //
1298
- if (scanlineMaxX <= maxX) {
1299
- scanlineMaxX = maxX + 1;
1300
- }
1301
- if (scanlineMinX >= minX) {
1302
- scanlineMinX = minX - 1;
1303
- }
1304
- return { curves: p.curves, points: points, isCW: three_1.ShapeUtils.isClockWise(points), identifier: identifier++, boundingBox: new three_1.Box2(new three_1.Vector2(minX, minY), new three_1.Vector2(maxX, maxY)) };
1305
- });
1306
- simplePaths = simplePaths.filter(function (sp) { return sp.points.length > 1; });
1307
- // check if path is solid or a hole
1308
- var isAHole = simplePaths.map(function (p) { return isHoleTo(p, simplePaths, scanlineMinX, scanlineMaxX, shapePath.userData.style.fillRule); });
1309
- var shapesToReturn = [];
1310
- simplePaths.forEach(function (p) {
1311
- var amIAHole = isAHole[p.identifier];
1312
- if (!amIAHole.isHole) {
1313
- var shape_1 = new three_1.Shape();
1314
- shape_1.curves = p.curves;
1315
- var holes = isAHole.filter(function (h) { return h.isHole && h.for === p.identifier; });
1316
- holes.forEach(function (h) {
1317
- var hole = simplePaths[h.identifier];
1318
- var path = new three_1.Path();
1319
- path.curves = hole.curves;
1320
- shape_1.holes.push(path);
1321
- });
1322
- shapesToReturn.push(shape_1);
1323
- }
1324
- });
1325
- return shapesToReturn;
1326
- };
1327
- SVGLoader.getStrokeStyle = function (width, color, lineJoin, lineCap, miterLimit) {
1328
- // Param width: Stroke width
1329
- // Param color: As returned by THREE.Color.getStyle()
1330
- // Param lineJoin: One of "round", "bevel", "miter" or "miter-limit"
1331
- // Param lineCap: One of "round", "square" or "butt"
1332
- // Param miterLimit: Maximum join length, in multiples of the "width" parameter (join is truncated if it exceeds that distance)
1333
- // Returns style object
1334
- width = width !== undefined ? width : 1;
1335
- color = color !== undefined ? color : '#000';
1336
- lineJoin = lineJoin !== undefined ? lineJoin : 'miter';
1337
- lineCap = lineCap !== undefined ? lineCap : 'butt';
1338
- miterLimit = miterLimit !== undefined ? miterLimit : 4;
1339
- return {
1340
- strokeColor: color,
1341
- strokeWidth: width,
1342
- strokeLineJoin: lineJoin,
1343
- strokeLineCap: lineCap,
1344
- strokeMiterLimit: miterLimit
1345
- };
1346
- };
1347
- SVGLoader.pointsToStroke = function (points, style, arcDivisions, minDistance) {
1348
- // Generates a stroke with some witdh around the given path.
1349
- // The path can be open or closed (last point equals to first point)
1350
- // Param points: Array of Vector2D (the path). Minimum 2 points.
1351
- // Param style: Object with SVG properties as returned by SVGLoader.getStrokeStyle(), or SVGLoader.parse() in the path.userData.style object
1352
- // Params arcDivisions: Arc divisions for round joins and endcaps. (Optional)
1353
- // Param minDistance: Points closer to this distance will be merged. (Optional)
1354
- // Returns BufferGeometry with stroke triangles (In plane z = 0). UV coordinates are generated ('u' along path. 'v' across it, from left to right)
1355
- var vertices = [];
1356
- var normals = [];
1357
- var uvs = [];
1358
- if (SVGLoader.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
1359
- return null;
1360
- }
1361
- var geometry = new three_1.BufferGeometry();
1362
- geometry.setAttribute('position', new three_1.Float32BufferAttribute(vertices, 3));
1363
- geometry.setAttribute('normal', new three_1.Float32BufferAttribute(normals, 3));
1364
- geometry.setAttribute('uv', new three_1.Float32BufferAttribute(uvs, 2));
1365
- return geometry;
1366
- };
1367
- SVGLoader.pointsToStrokeWithBuffers = function (points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
1368
- // This function can be called to update existing arrays or buffers.
1369
- // Accepts same parameters as pointsToStroke, plus the buffers and optional offset.
1370
- // Param vertexOffset: Offset vertices to start writing in the buffers (3 elements/vertex for vertices and normals, and 2 elements/vertex for uvs)
1371
- // Returns number of written vertices / normals / uvs pairs
1372
- // if 'vertices' parameter is undefined no triangles will be generated, but the returned vertices count will still be valid (useful to preallocate the buffers)
1373
- // 'normals' and 'uvs' buffers are optional
1374
- var tempV2_1 = new three_1.Vector2();
1375
- var tempV2_2 = new three_1.Vector2();
1376
- var tempV2_3 = new three_1.Vector2();
1377
- var tempV2_4 = new three_1.Vector2();
1378
- var tempV2_5 = new three_1.Vector2();
1379
- var tempV2_6 = new three_1.Vector2();
1380
- var tempV2_7 = new three_1.Vector2();
1381
- var lastPointL = new three_1.Vector2();
1382
- var lastPointR = new three_1.Vector2();
1383
- var point0L = new three_1.Vector2();
1384
- var point0R = new three_1.Vector2();
1385
- var currentPointL = new three_1.Vector2();
1386
- var currentPointR = new three_1.Vector2();
1387
- var nextPointL = new three_1.Vector2();
1388
- var nextPointR = new three_1.Vector2();
1389
- var innerPoint = new three_1.Vector2();
1390
- var outerPoint = new three_1.Vector2();
1391
- arcDivisions = arcDivisions !== undefined ? arcDivisions : 12;
1392
- minDistance = minDistance !== undefined ? minDistance : 0.001;
1393
- vertexOffset = vertexOffset !== undefined ? vertexOffset : 0;
1394
- // First ensure there are no duplicated points
1395
- points = removeDuplicatedPoints(points);
1396
- var numPoints = points.length;
1397
- if (numPoints < 2)
1398
- return 0;
1399
- var isClosed = points[0].equals(points[numPoints - 1]);
1400
- var currentPoint;
1401
- var previousPoint = points[0];
1402
- var nextPoint;
1403
- var strokeWidth2 = style.strokeWidth / 2;
1404
- var deltaU = 1 / (numPoints - 1);
1405
- var u0 = 0, u1;
1406
- var innerSideModified;
1407
- var joinIsOnLeftSide;
1408
- var isMiter;
1409
- var initialJoinIsOnLeftSide = false;
1410
- var numVertices = 0;
1411
- var currentCoordinate = vertexOffset * 3;
1412
- var currentCoordinateUV = vertexOffset * 2;
1413
- // Get initial left and right stroke points
1414
- getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
1415
- lastPointL.copy(points[0]).sub(tempV2_1);
1416
- lastPointR.copy(points[0]).add(tempV2_1);
1417
- point0L.copy(lastPointL);
1418
- point0R.copy(lastPointR);
1419
- for (var iPoint = 1; iPoint < numPoints; iPoint++) {
1420
- currentPoint = points[iPoint];
1421
- // Get next point
1422
- if (iPoint === numPoints - 1) {
1423
- if (isClosed) {
1424
- // Skip duplicated initial point
1425
- nextPoint = points[1];
1426
- }
1427
- else
1428
- nextPoint = undefined;
1429
- }
1430
- else {
1431
- nextPoint = points[iPoint + 1];
1432
- }
1433
- // Normal of previous segment in tempV2_1
1434
- var normal1 = tempV2_1;
1435
- getNormal(previousPoint, currentPoint, normal1);
1436
- tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
1437
- currentPointL.copy(currentPoint).sub(tempV2_3);
1438
- currentPointR.copy(currentPoint).add(tempV2_3);
1439
- u1 = u0 + deltaU;
1440
- innerSideModified = false;
1441
- if (nextPoint !== undefined) {
1442
- // Normal of next segment in tempV2_2
1443
- getNormal(currentPoint, nextPoint, tempV2_2);
1444
- tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
1445
- nextPointL.copy(currentPoint).sub(tempV2_3);
1446
- nextPointR.copy(currentPoint).add(tempV2_3);
1447
- joinIsOnLeftSide = true;
1448
- tempV2_3.subVectors(nextPoint, previousPoint);
1449
- if (normal1.dot(tempV2_3) < 0) {
1450
- joinIsOnLeftSide = false;
1451
- }
1452
- if (iPoint === 1)
1453
- initialJoinIsOnLeftSide = joinIsOnLeftSide;
1454
- tempV2_3.subVectors(nextPoint, currentPoint);
1455
- tempV2_3.normalize();
1456
- var dot = Math.abs(normal1.dot(tempV2_3));
1457
- // If path is straight, don't create join
1458
- if (dot !== 0) {
1459
- // Compute inner and outer segment intersections
1460
- var miterSide = strokeWidth2 / dot;
1461
- tempV2_3.multiplyScalar(-miterSide);
1462
- tempV2_4.subVectors(currentPoint, previousPoint);
1463
- tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1464
- innerPoint.copy(tempV2_5).negate();
1465
- var miterLength2 = tempV2_5.length();
1466
- var segmentLengthPrev = tempV2_4.length();
1467
- tempV2_4.divideScalar(segmentLengthPrev);
1468
- tempV2_6.subVectors(nextPoint, currentPoint);
1469
- var segmentLengthNext = tempV2_6.length();
1470
- tempV2_6.divideScalar(segmentLengthNext);
1471
- // Check that previous and next segments doesn't overlap with the innerPoint of intersection
1472
- if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1473
- innerSideModified = true;
1474
- }
1475
- outerPoint.copy(tempV2_5).add(currentPoint);
1476
- innerPoint.add(currentPoint);
1477
- isMiter = false;
1478
- if (innerSideModified) {
1479
- if (joinIsOnLeftSide) {
1480
- nextPointR.copy(innerPoint);
1481
- currentPointR.copy(innerPoint);
1482
- }
1483
- else {
1484
- nextPointL.copy(innerPoint);
1485
- currentPointL.copy(innerPoint);
1486
- }
1487
- }
1488
- else {
1489
- // The segment triangles are generated here if there was overlapping
1490
- makeSegmentTriangles();
1491
- }
1492
- switch (style.strokeLineJoin) {
1493
- case 'bevel':
1494
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1495
- break;
1496
- case 'round':
1497
- // Segment triangles
1498
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1499
- // Join triangles
1500
- if (joinIsOnLeftSide) {
1501
- makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1502
- }
1503
- else {
1504
- makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1505
- }
1506
- break;
1507
- case 'miter':
1508
- case 'miter-clip':
1509
- default:
1510
- var miterFraction = (strokeWidth2 * style.strokeMiterLimit) / miterLength2;
1511
- if (miterFraction < 1) {
1512
- // The join miter length exceeds the miter limit
1513
- if (style.strokeLineJoin !== 'miter-clip') {
1514
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1515
- break;
1516
- }
1517
- else {
1518
- // Segment triangles
1519
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1520
- // Miter-clip join triangles
1521
- if (joinIsOnLeftSide) {
1522
- tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1523
- tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1524
- addVertex(currentPointL, u1, 0);
1525
- addVertex(tempV2_6, u1, 0);
1526
- addVertex(currentPoint, u1, 0.5);
1527
- addVertex(currentPoint, u1, 0.5);
1528
- addVertex(tempV2_6, u1, 0);
1529
- addVertex(tempV2_7, u1, 0);
1530
- addVertex(currentPoint, u1, 0.5);
1531
- addVertex(tempV2_7, u1, 0);
1532
- addVertex(nextPointL, u1, 0);
1533
- }
1534
- else {
1535
- tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1536
- tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1537
- addVertex(currentPointR, u1, 1);
1538
- addVertex(tempV2_6, u1, 1);
1539
- addVertex(currentPoint, u1, 0.5);
1540
- addVertex(currentPoint, u1, 0.5);
1541
- addVertex(tempV2_6, u1, 1);
1542
- addVertex(tempV2_7, u1, 1);
1543
- addVertex(currentPoint, u1, 0.5);
1544
- addVertex(tempV2_7, u1, 1);
1545
- addVertex(nextPointR, u1, 1);
1546
- }
1547
- }
1548
- }
1549
- else {
1550
- // Miter join segment triangles
1551
- if (innerSideModified) {
1552
- // Optimized segment + join triangles
1553
- if (joinIsOnLeftSide) {
1554
- addVertex(lastPointR, u0, 1);
1555
- addVertex(lastPointL, u0, 0);
1556
- addVertex(outerPoint, u1, 0);
1557
- addVertex(lastPointR, u0, 1);
1558
- addVertex(outerPoint, u1, 0);
1559
- addVertex(innerPoint, u1, 1);
1560
- }
1561
- else {
1562
- addVertex(lastPointR, u0, 1);
1563
- addVertex(lastPointL, u0, 0);
1564
- addVertex(outerPoint, u1, 1);
1565
- addVertex(lastPointL, u0, 0);
1566
- addVertex(innerPoint, u1, 0);
1567
- addVertex(outerPoint, u1, 1);
1568
- }
1569
- if (joinIsOnLeftSide) {
1570
- nextPointL.copy(outerPoint);
1571
- }
1572
- else {
1573
- nextPointR.copy(outerPoint);
1574
- }
1575
- }
1576
- else {
1577
- // Add extra miter join triangles
1578
- if (joinIsOnLeftSide) {
1579
- addVertex(currentPointL, u1, 0);
1580
- addVertex(outerPoint, u1, 0);
1581
- addVertex(currentPoint, u1, 0.5);
1582
- addVertex(currentPoint, u1, 0.5);
1583
- addVertex(outerPoint, u1, 0);
1584
- addVertex(nextPointL, u1, 0);
1585
- }
1586
- else {
1587
- addVertex(currentPointR, u1, 1);
1588
- addVertex(outerPoint, u1, 1);
1589
- addVertex(currentPoint, u1, 0.5);
1590
- addVertex(currentPoint, u1, 0.5);
1591
- addVertex(outerPoint, u1, 1);
1592
- addVertex(nextPointR, u1, 1);
1593
- }
1594
- }
1595
- isMiter = true;
1596
- }
1597
- break;
1598
- }
1599
- }
1600
- else {
1601
- // The segment triangles are generated here when two consecutive points are collinear
1602
- makeSegmentTriangles();
1603
- }
1604
- }
1605
- else {
1606
- // The segment triangles are generated here if it is the ending segment
1607
- makeSegmentTriangles();
1608
- }
1609
- if (!isClosed && iPoint === numPoints - 1) {
1610
- // Start line endcap
1611
- addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1612
- }
1613
- // Increment loop variables
1614
- u0 = u1;
1615
- previousPoint = currentPoint;
1616
- lastPointL.copy(nextPointL);
1617
- lastPointR.copy(nextPointR);
1618
- }
1619
- if (!isClosed) {
1620
- // Ending line endcap
1621
- addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1622
- }
1623
- else if (innerSideModified && vertices) {
1624
- // Modify path first segment vertices to adjust to the segments inner and outer intersections
1625
- var lastOuter = outerPoint;
1626
- var lastInner = innerPoint;
1627
- if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1628
- lastOuter = innerPoint;
1629
- lastInner = outerPoint;
1630
- }
1631
- if (joinIsOnLeftSide) {
1632
- if (isMiter || initialJoinIsOnLeftSide) {
1633
- lastInner.toArray(vertices, 0 * 3);
1634
- lastInner.toArray(vertices, 3 * 3);
1635
- if (isMiter) {
1636
- lastOuter.toArray(vertices, 1 * 3);
1637
- }
1638
- }
1639
- }
1640
- else {
1641
- if (isMiter || !initialJoinIsOnLeftSide) {
1642
- lastInner.toArray(vertices, 1 * 3);
1643
- lastInner.toArray(vertices, 3 * 3);
1644
- if (isMiter) {
1645
- lastOuter.toArray(vertices, 0 * 3);
1646
- }
1647
- }
1648
- }
1649
- }
1650
- return numVertices;
1651
- // -- End of algorithm
1652
- // -- Functions
1653
- function getNormal(p1, p2, result) {
1654
- result.subVectors(p2, p1);
1655
- return result.set(-result.y, result.x).normalize();
1656
- }
1657
- function addVertex(position, u, v) {
1658
- if (vertices) {
1659
- vertices[currentCoordinate] = position.x;
1660
- vertices[currentCoordinate + 1] = position.y;
1661
- vertices[currentCoordinate + 2] = 0;
1662
- if (normals) {
1663
- normals[currentCoordinate] = 0;
1664
- normals[currentCoordinate + 1] = 0;
1665
- normals[currentCoordinate + 2] = 1;
1666
- }
1667
- currentCoordinate += 3;
1668
- if (uvs) {
1669
- uvs[currentCoordinateUV] = u;
1670
- uvs[currentCoordinateUV + 1] = v;
1671
- currentCoordinateUV += 2;
1672
- }
1673
- }
1674
- numVertices += 3;
1675
- }
1676
- function makeCircularSector(center, p1, p2, u, v) {
1677
- // param p1, p2: Points in the circle arc.
1678
- // p1 and p2 are in clockwise direction.
1679
- tempV2_1.copy(p1).sub(center).normalize();
1680
- tempV2_2.copy(p2).sub(center).normalize();
1681
- var angle = Math.PI;
1682
- var dot = tempV2_1.dot(tempV2_2);
1683
- if (Math.abs(dot) < 1)
1684
- angle = Math.abs(Math.acos(dot));
1685
- angle /= arcDivisions;
1686
- tempV2_3.copy(p1);
1687
- for (var i = 0, il = arcDivisions - 1; i < il; i++) {
1688
- tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1689
- addVertex(tempV2_3, u, v);
1690
- addVertex(tempV2_4, u, v);
1691
- addVertex(center, u, 0.5);
1692
- tempV2_3.copy(tempV2_4);
1693
- }
1694
- addVertex(tempV2_4, u, v);
1695
- addVertex(p2, u, v);
1696
- addVertex(center, u, 0.5);
1697
- }
1698
- function makeSegmentTriangles() {
1699
- addVertex(lastPointR, u0, 1);
1700
- addVertex(lastPointL, u0, 0);
1701
- addVertex(currentPointL, u1, 0);
1702
- addVertex(lastPointR, u0, 1);
1703
- addVertex(currentPointL, u1, 1);
1704
- addVertex(currentPointR, u1, 0);
1705
- }
1706
- function makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u) {
1707
- if (innerSideModified) {
1708
- // Optimized segment + bevel triangles
1709
- if (joinIsOnLeftSide) {
1710
- // Path segments triangles
1711
- addVertex(lastPointR, u0, 1);
1712
- addVertex(lastPointL, u0, 0);
1713
- addVertex(currentPointL, u1, 0);
1714
- addVertex(lastPointR, u0, 1);
1715
- addVertex(currentPointL, u1, 0);
1716
- addVertex(innerPoint, u1, 1);
1717
- // Bevel join triangle
1718
- addVertex(currentPointL, u, 0);
1719
- addVertex(nextPointL, u, 0);
1720
- addVertex(innerPoint, u, 0.5);
1721
- }
1722
- else {
1723
- // Path segments triangles
1724
- addVertex(lastPointR, u0, 1);
1725
- addVertex(lastPointL, u0, 0);
1726
- addVertex(currentPointR, u1, 1);
1727
- addVertex(lastPointL, u0, 0);
1728
- addVertex(innerPoint, u1, 0);
1729
- addVertex(currentPointR, u1, 1);
1730
- // Bevel join triangle
1731
- addVertex(currentPointR, u, 1);
1732
- addVertex(nextPointR, u, 0);
1733
- addVertex(innerPoint, u, 0.5);
1734
- }
1735
- }
1736
- else {
1737
- // Bevel join triangle. The segment triangles are done in the main loop
1738
- if (joinIsOnLeftSide) {
1739
- addVertex(currentPointL, u, 0);
1740
- addVertex(nextPointL, u, 0);
1741
- addVertex(currentPoint, u, 0.5);
1742
- }
1743
- else {
1744
- addVertex(currentPointR, u, 1);
1745
- addVertex(nextPointR, u, 0);
1746
- addVertex(currentPoint, u, 0.5);
1747
- }
1748
- }
1749
- }
1750
- function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified) {
1751
- if (innerSideModified) {
1752
- if (joinIsOnLeftSide) {
1753
- addVertex(lastPointR, u0, 1);
1754
- addVertex(lastPointL, u0, 0);
1755
- addVertex(currentPointL, u1, 0);
1756
- addVertex(lastPointR, u0, 1);
1757
- addVertex(currentPointL, u1, 0);
1758
- addVertex(innerPoint, u1, 1);
1759
- addVertex(currentPointL, u0, 0);
1760
- addVertex(currentPoint, u1, 0.5);
1761
- addVertex(innerPoint, u1, 1);
1762
- addVertex(currentPoint, u1, 0.5);
1763
- addVertex(nextPointL, u0, 0);
1764
- addVertex(innerPoint, u1, 1);
1765
- }
1766
- else {
1767
- addVertex(lastPointR, u0, 1);
1768
- addVertex(lastPointL, u0, 0);
1769
- addVertex(currentPointR, u1, 1);
1770
- addVertex(lastPointL, u0, 0);
1771
- addVertex(innerPoint, u1, 0);
1772
- addVertex(currentPointR, u1, 1);
1773
- addVertex(currentPointR, u0, 1);
1774
- addVertex(innerPoint, u1, 0);
1775
- addVertex(currentPoint, u1, 0.5);
1776
- addVertex(currentPoint, u1, 0.5);
1777
- addVertex(innerPoint, u1, 0);
1778
- addVertex(nextPointR, u0, 1);
1779
- }
1780
- }
1781
- }
1782
- function addCapGeometry(center, p1, p2, joinIsOnLeftSide, start, u) {
1783
- // param center: End point of the path
1784
- // param p1, p2: Left and right cap points
1785
- switch (style.strokeLineCap) {
1786
- case 'round':
1787
- if (start) {
1788
- makeCircularSector(center, p2, p1, u, 0.5);
1789
- }
1790
- else {
1791
- makeCircularSector(center, p1, p2, u, 0.5);
1792
- }
1793
- break;
1794
- case 'square':
1795
- if (start) {
1796
- tempV2_1.subVectors(p1, center);
1797
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1798
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1799
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1800
- // Modify already existing vertices
1801
- if (joinIsOnLeftSide) {
1802
- tempV2_3.toArray(vertices, 1 * 3);
1803
- tempV2_4.toArray(vertices, 0 * 3);
1804
- tempV2_4.toArray(vertices, 3 * 3);
1805
- }
1806
- else {
1807
- tempV2_3.toArray(vertices, 1 * 3);
1808
- tempV2_3.toArray(vertices, 3 * 3);
1809
- tempV2_4.toArray(vertices, 0 * 3);
1810
- }
1811
- }
1812
- else {
1813
- tempV2_1.subVectors(p2, center);
1814
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1815
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1816
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1817
- var vl = vertices.length;
1818
- // Modify already existing vertices
1819
- if (joinIsOnLeftSide) {
1820
- tempV2_3.toArray(vertices, vl - 1 * 3);
1821
- tempV2_4.toArray(vertices, vl - 2 * 3);
1822
- tempV2_4.toArray(vertices, vl - 4 * 3);
1823
- }
1824
- else {
1825
- tempV2_3.toArray(vertices, vl - 2 * 3);
1826
- tempV2_4.toArray(vertices, vl - 1 * 3);
1827
- tempV2_4.toArray(vertices, vl - 4 * 3);
1828
- }
1829
- }
1830
- break;
1831
- case 'butt':
1832
- default:
1833
- // Nothing to do here
1834
- break;
1835
- }
1836
- }
1837
- function removeDuplicatedPoints(points) {
1838
- // Creates a new array if necessary with duplicated points removed.
1839
- // This does not remove duplicated initial and ending points of a closed path.
1840
- var dupPoints = false;
1841
- for (var i = 1, n = points.length - 1; i < n; i++) {
1842
- if (points[i].distanceTo(points[i + 1]) < minDistance) {
1843
- dupPoints = true;
1844
- break;
1845
- }
1846
- }
1847
- if (!dupPoints)
1848
- return points;
1849
- var newPoints = [];
1850
- newPoints.push(points[0]);
1851
- for (var i = 1, n = points.length - 1; i < n; i++) {
1852
- if (points[i].distanceTo(points[i + 1]) >= minDistance) {
1853
- newPoints.push(points[i]);
1854
- }
1855
- }
1856
- newPoints.push(points[points.length - 1]);
1857
- return newPoints;
1858
- }
1859
- };
1860
- return SVGLoader;
1861
- }(three_1.Loader));
1862
- exports.SVGLoader = SVGLoader;