kitchen-simulator 3.1.1 → 4.0.0-react-18

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 (138) hide show
  1. package/README.md +0 -3
  2. package/es/AppContext.js +1 -1
  3. package/es/LiteKitchenConfigurator.js +15 -25
  4. package/es/LiteRenderer.js +2 -5
  5. package/es/actions/export.js +12 -25
  6. package/es/catalog/catalog.js +5 -21
  7. package/es/components/content.js +2 -5
  8. package/es/components/export.js +6 -4
  9. package/es/components/style/export.js +2 -28
  10. package/es/components/style/form-number-input.js +22 -11
  11. package/es/components/viewer2d/group.js +4 -5
  12. package/es/components/viewer2d/item.js +4 -5
  13. package/es/components/viewer2d/layer.js +1 -1
  14. package/es/components/viewer2d/line.js +47 -17
  15. package/es/components/viewer2d/rulerX.js +0 -3
  16. package/es/components/viewer2d/rulerY.js +0 -3
  17. package/es/components/viewer2d/scene.js +1 -4
  18. package/es/components/viewer2d/state.js +1 -1
  19. package/es/components/viewer2d/viewer2d.js +43 -28
  20. package/es/components/viewer3d/viewer3d-first-person.js +0 -8
  21. package/es/components/viewer3d/viewer3d.js +0 -9
  22. package/es/devLiteRenderer.js +148 -317
  23. package/es/index.js +12 -4
  24. package/es/mocks/appliancePayload.json +27 -0
  25. package/es/mocks/cabinetPayload.json +1914 -0
  26. package/es/mocks/cabinetPayload2.json +76 -0
  27. package/es/mocks/dataBundle2.json +4 -0
  28. package/es/mocks/distancePayload.json +6 -0
  29. package/es/mocks/doorStylePayload2.json +84 -0
  30. package/es/mocks/furnishingPayload.json +23 -0
  31. package/es/mocks/itemCDSPayload.json +27 -0
  32. package/es/mocks/lightingPayload.json +23 -0
  33. package/es/mocks/mockProps.json +43 -0
  34. package/es/mocks/mockProps2.json +9 -0
  35. package/es/mocks/moldingPayload.json +19 -0
  36. package/es/mocks/projectItemsCatalog.json +133 -0
  37. package/es/mocks/rectangleShape.json +238 -0
  38. package/es/mocks/replaceCabinetPayload.json +81 -0
  39. package/es/mocks/roomShapePayload.json +5 -0
  40. package/es/useAppContext.js +8 -0
  41. package/lib/AppContext.js +1 -1
  42. package/lib/LiteKitchenConfigurator.js +15 -25
  43. package/lib/LiteRenderer.js +2 -5
  44. package/lib/actions/export.js +39 -35
  45. package/lib/catalog/catalog.js +4 -20
  46. package/lib/components/content.js +2 -5
  47. package/lib/components/export.js +26 -6
  48. package/lib/components/style/export.js +1 -105
  49. package/lib/components/style/form-number-input.js +22 -11
  50. package/lib/components/viewer2d/group.js +4 -5
  51. package/lib/components/viewer2d/item.js +4 -5
  52. package/lib/components/viewer2d/layer.js +1 -1
  53. package/lib/components/viewer2d/line.js +47 -17
  54. package/lib/components/viewer2d/rulerX.js +0 -3
  55. package/lib/components/viewer2d/rulerY.js +0 -3
  56. package/lib/components/viewer2d/scene.js +1 -4
  57. package/lib/components/viewer2d/state.js +1 -1
  58. package/lib/components/viewer2d/viewer2d.js +42 -27
  59. package/lib/components/viewer3d/viewer3d-first-person.js +0 -8
  60. package/lib/components/viewer3d/viewer3d.js +0 -9
  61. package/lib/devLiteRenderer.js +147 -316
  62. package/lib/index.js +12 -4
  63. package/lib/mocks/appliancePayload.json +27 -0
  64. package/lib/mocks/cabinetPayload.json +1914 -0
  65. package/lib/mocks/cabinetPayload2.json +76 -0
  66. package/lib/mocks/dataBundle2.json +4 -0
  67. package/lib/mocks/distancePayload.json +6 -0
  68. package/lib/mocks/doorStylePayload2.json +84 -0
  69. package/lib/mocks/furnishingPayload.json +23 -0
  70. package/lib/mocks/itemCDSPayload.json +27 -0
  71. package/lib/mocks/lightingPayload.json +23 -0
  72. package/lib/mocks/mockProps.json +43 -0
  73. package/lib/mocks/mockProps2.json +9 -0
  74. package/lib/mocks/moldingPayload.json +19 -0
  75. package/lib/mocks/projectItemsCatalog.json +133 -0
  76. package/lib/mocks/rectangleShape.json +238 -0
  77. package/lib/mocks/replaceCabinetPayload.json +81 -0
  78. package/lib/mocks/roomShapePayload.json +5 -0
  79. package/lib/useAppContext.js +16 -0
  80. package/package.json +16 -21
  81. package/es/catalog/properties/export.js +0 -21
  82. package/es/catalog/properties/property-checkbox.js +0 -68
  83. package/es/catalog/properties/property-color.js +0 -39
  84. package/es/catalog/properties/property-enum.js +0 -50
  85. package/es/catalog/properties/property-hidden.js +0 -19
  86. package/es/catalog/properties/property-lenght-measure.js +0 -100
  87. package/es/catalog/properties/property-length-measure.js +0 -84
  88. package/es/catalog/properties/property-length-measure_hole.js +0 -100
  89. package/es/catalog/properties/property-number.js +0 -48
  90. package/es/catalog/properties/property-read-only.js +0 -26
  91. package/es/catalog/properties/property-string.js +0 -48
  92. package/es/catalog/properties/property-toggle.js +0 -39
  93. package/es/catalog/properties/shared-property-style.js +0 -14
  94. package/es/components/style/button.js +0 -106
  95. package/es/components/style/cancel-button.js +0 -21
  96. package/es/components/style/content-container.js +0 -30
  97. package/es/components/style/content-title.js +0 -25
  98. package/es/components/style/delete-button.js +0 -24
  99. package/es/components/style/form-block.js +0 -20
  100. package/es/components/style/form-color-input.js +0 -26
  101. package/es/components/style/form-label.js +0 -22
  102. package/es/components/style/form-number-input_2.js +0 -200
  103. package/es/components/style/form-select.js +0 -19
  104. package/es/components/style/form-slider.js +0 -60
  105. package/es/components/style/form-submit-button.js +0 -25
  106. package/es/components/style/form-text-input.js +0 -69
  107. package/es/plugins/SVGLoader.js +0 -1414
  108. package/es/styles/export.js +0 -5
  109. package/es/styles/tabs.css +0 -40
  110. package/lib/catalog/properties/export.js +0 -81
  111. package/lib/catalog/properties/property-checkbox.js +0 -76
  112. package/lib/catalog/properties/property-color.js +0 -47
  113. package/lib/catalog/properties/property-enum.js +0 -58
  114. package/lib/catalog/properties/property-hidden.js +0 -27
  115. package/lib/catalog/properties/property-lenght-measure.js +0 -108
  116. package/lib/catalog/properties/property-length-measure.js +0 -92
  117. package/lib/catalog/properties/property-length-measure_hole.js +0 -108
  118. package/lib/catalog/properties/property-number.js +0 -56
  119. package/lib/catalog/properties/property-read-only.js +0 -34
  120. package/lib/catalog/properties/property-string.js +0 -56
  121. package/lib/catalog/properties/property-toggle.js +0 -47
  122. package/lib/catalog/properties/shared-property-style.js +0 -21
  123. package/lib/components/style/button.js +0 -115
  124. package/lib/components/style/cancel-button.js +0 -29
  125. package/lib/components/style/content-container.js +0 -38
  126. package/lib/components/style/content-title.js +0 -35
  127. package/lib/components/style/delete-button.js +0 -34
  128. package/lib/components/style/form-block.js +0 -28
  129. package/lib/components/style/form-color-input.js +0 -34
  130. package/lib/components/style/form-label.js +0 -30
  131. package/lib/components/style/form-number-input_2.js +0 -209
  132. package/lib/components/style/form-select.js +0 -29
  133. package/lib/components/style/form-slider.js +0 -68
  134. package/lib/components/style/form-submit-button.js +0 -35
  135. package/lib/components/style/form-text-input.js +0 -78
  136. package/lib/plugins/SVGLoader.js +0 -1419
  137. package/lib/styles/export.js +0 -13
  138. package/lib/styles/tabs.css +0 -40
@@ -1,1414 +0,0 @@
1
- import { BufferGeometry, FileLoader, Float32BufferAttribute, Loader, Matrix3, Path, ShapePath, Vector2, Vector3 } from 'three';
2
- var SVGLoader = function SVGLoader(manager) {
3
- Loader.call(this, manager);
4
-
5
- // Default dots per inch
6
- this.defaultDPI = 90;
7
-
8
- // Accepted units: 'mm', 'cm', 'in', 'pt', 'pc', 'px'
9
- this.defaultUnit = 'px';
10
- };
11
- SVGLoader.prototype = Object.assign(Object.create(Loader.prototype), {
12
- constructor: SVGLoader,
13
- load: function load(url, onLoad, onProgress, onError) {
14
- var scope = this;
15
- var loader = new FileLoader(scope.manager);
16
- loader.setPath(scope.path);
17
- loader.setRequestHeader(scope.requestHeader);
18
- loader.setWithCredentials(scope.withCredentials);
19
- loader.load(url, function (text) {
20
- try {
21
- onLoad(scope.parse(text));
22
- } catch (e) {
23
- if (onError) {
24
- onError(e);
25
- } else {
26
- console.error(e);
27
- }
28
- scope.manager.itemError(url);
29
- }
30
- }, onProgress, onError);
31
- },
32
- parse: function parse(text) {
33
- var scope = this;
34
- function parseNode(node, style) {
35
- if (node.nodeType !== 1) return;
36
- var transform = getNodeTransform(node);
37
- var traverseChildNodes = true;
38
- var path = null;
39
- switch (node.nodeName) {
40
- case 'svg':
41
- break;
42
- case 'style':
43
- parseCSSStylesheet(node);
44
- break;
45
- case 'g':
46
- style = parseStyle(node, style);
47
- break;
48
- case 'path':
49
- style = parseStyle(node, style);
50
- if (node.hasAttribute('d')) path = parsePathNode(node);
51
- break;
52
- case 'rect':
53
- style = parseStyle(node, style);
54
- path = parseRectNode(node);
55
- break;
56
- case 'polygon':
57
- style = parseStyle(node, style);
58
- path = parsePolygonNode(node);
59
- break;
60
- case 'polyline':
61
- style = parseStyle(node, style);
62
- path = parsePolylineNode(node);
63
- break;
64
- case 'circle':
65
- style = parseStyle(node, style);
66
- path = parseCircleNode(node);
67
- break;
68
- case 'ellipse':
69
- style = parseStyle(node, style);
70
- path = parseEllipseNode(node);
71
- break;
72
- case 'line':
73
- style = parseStyle(node, style);
74
- path = parseLineNode(node);
75
- break;
76
- case 'defs':
77
- traverseChildNodes = false;
78
- break;
79
- case 'use':
80
- style = parseStyle(node, style);
81
- var usedNodeId = node.href.baseVal.substring(1);
82
- if (node.viewportElement.getElementById(usedNodeId)) {
83
- var usedNode = node.viewportElement.getElementById(usedNodeId);
84
- if (usedNode) {
85
- parseNode(usedNode, style);
86
- } else {
87
- console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
88
- }
89
- }
90
- break;
91
- default:
92
- // console.log( node );
93
- }
94
- if (path) {
95
- if (style.fill !== undefined && style.fill !== 'none') {
96
- path.color.setStyle(style.fill);
97
- }
98
- transformPath(path, currentTransform);
99
- paths.push(path);
100
- path.userData = {
101
- node: node,
102
- style: style
103
- };
104
- }
105
- if (traverseChildNodes) {
106
- var nodes = node.childNodes;
107
- for (var i = 0; i < nodes.length; i++) {
108
- parseNode(nodes[i], style);
109
- }
110
- }
111
- if (transform) {
112
- transformStack.pop();
113
- if (transformStack.length > 0) {
114
- currentTransform.copy(transformStack[transformStack.length - 1]);
115
- } else {
116
- currentTransform.identity();
117
- }
118
- }
119
- }
120
- function parsePathNode(node) {
121
- var path = new ShapePath();
122
- var point = new Vector2();
123
- var control = new Vector2();
124
- var firstPoint = new Vector2();
125
- var isFirstPoint = true;
126
- var doSetFirstPoint = false;
127
- var d = node.getAttribute('d');
128
-
129
- // console.log( d );
130
-
131
- var commands = d.match(/[a-df-z][^a-df-z]*/gi);
132
- for (var i = 0, l = commands.length; i < l; i++) {
133
- var command = commands[i];
134
- var type = command.charAt(0);
135
- var data = command.substr(1).trim();
136
- if (isFirstPoint === true) {
137
- doSetFirstPoint = true;
138
- isFirstPoint = false;
139
- }
140
- switch (type) {
141
- case 'M':
142
- var numbers = parseFloats(data);
143
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
144
- point.x = numbers[j + 0];
145
- point.y = numbers[j + 1];
146
- control.x = point.x;
147
- control.y = point.y;
148
- if (j === 0) {
149
- path.moveTo(point.x, point.y);
150
- } else {
151
- path.lineTo(point.x, point.y);
152
- }
153
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
154
- }
155
- break;
156
- case 'H':
157
- var numbers = parseFloats(data);
158
- for (var j = 0, jl = numbers.length; j < jl; j++) {
159
- point.x = numbers[j];
160
- control.x = point.x;
161
- control.y = point.y;
162
- path.lineTo(point.x, point.y);
163
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
164
- }
165
- break;
166
- case 'V':
167
- var numbers = parseFloats(data);
168
- for (var j = 0, jl = numbers.length; j < jl; j++) {
169
- point.y = numbers[j];
170
- control.x = point.x;
171
- control.y = point.y;
172
- path.lineTo(point.x, point.y);
173
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
174
- }
175
- break;
176
- case 'L':
177
- var numbers = parseFloats(data);
178
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
179
- point.x = numbers[j + 0];
180
- point.y = numbers[j + 1];
181
- control.x = point.x;
182
- control.y = point.y;
183
- path.lineTo(point.x, point.y);
184
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
185
- }
186
- break;
187
- case 'C':
188
- var numbers = parseFloats(data);
189
- for (var j = 0, jl = numbers.length; j < jl; j += 6) {
190
- path.bezierCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], numbers[j + 5]);
191
- control.x = numbers[j + 2];
192
- control.y = numbers[j + 3];
193
- point.x = numbers[j + 4];
194
- point.y = numbers[j + 5];
195
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
196
- }
197
- break;
198
- case 'S':
199
- var numbers = parseFloats(data);
200
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
201
- path.bezierCurveTo(getReflection(point.x, control.x), getReflection(point.y, control.y), numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
202
- control.x = numbers[j + 0];
203
- control.y = numbers[j + 1];
204
- point.x = numbers[j + 2];
205
- point.y = numbers[j + 3];
206
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
207
- }
208
- break;
209
- case 'Q':
210
- var numbers = parseFloats(data);
211
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
212
- path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
213
- control.x = numbers[j + 0];
214
- control.y = numbers[j + 1];
215
- point.x = numbers[j + 2];
216
- point.y = numbers[j + 3];
217
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
218
- }
219
- break;
220
- case 'T':
221
- var numbers = parseFloats(data);
222
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
223
- var rx = getReflection(point.x, control.x);
224
- var ry = getReflection(point.y, control.y);
225
- path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
226
- control.x = rx;
227
- control.y = ry;
228
- point.x = numbers[j + 0];
229
- point.y = numbers[j + 1];
230
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
231
- }
232
- break;
233
- case 'A':
234
- var numbers = parseFloats(data);
235
- for (var j = 0, jl = numbers.length; j < jl; j += 7) {
236
- var start = point.clone();
237
- point.x = numbers[j + 5];
238
- point.y = numbers[j + 6];
239
- control.x = point.x;
240
- control.y = point.y;
241
- parseArcCommand(path, numbers[j], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], start, point);
242
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
243
- }
244
- break;
245
- case 'm':
246
- var numbers = parseFloats(data);
247
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
248
- point.x += numbers[j + 0];
249
- point.y += numbers[j + 1];
250
- control.x = point.x;
251
- control.y = point.y;
252
- if (j === 0) {
253
- path.moveTo(point.x, point.y);
254
- } else {
255
- path.lineTo(point.x, point.y);
256
- }
257
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
258
- }
259
- break;
260
- case 'h':
261
- var numbers = parseFloats(data);
262
- for (var j = 0, jl = numbers.length; j < jl; j++) {
263
- point.x += numbers[j];
264
- control.x = point.x;
265
- control.y = point.y;
266
- path.lineTo(point.x, point.y);
267
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
268
- }
269
- break;
270
- case 'v':
271
- var numbers = parseFloats(data);
272
- for (var j = 0, jl = numbers.length; j < jl; j++) {
273
- point.y += numbers[j];
274
- control.x = point.x;
275
- control.y = point.y;
276
- path.lineTo(point.x, point.y);
277
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
278
- }
279
- break;
280
- case 'l':
281
- var numbers = parseFloats(data);
282
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
283
- point.x += numbers[j + 0];
284
- point.y += numbers[j + 1];
285
- control.x = point.x;
286
- control.y = point.y;
287
- path.lineTo(point.x, point.y);
288
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
289
- }
290
- break;
291
- case 'c':
292
- var numbers = parseFloats(data);
293
- for (var j = 0, jl = numbers.length; j < jl; j += 6) {
294
- 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]);
295
- control.x = point.x + numbers[j + 2];
296
- control.y = point.y + numbers[j + 3];
297
- point.x += numbers[j + 4];
298
- point.y += numbers[j + 5];
299
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
300
- }
301
- break;
302
- case 's':
303
- var numbers = parseFloats(data);
304
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
305
- 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]);
306
- control.x = point.x + numbers[j + 0];
307
- control.y = point.y + numbers[j + 1];
308
- point.x += numbers[j + 2];
309
- point.y += numbers[j + 3];
310
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
311
- }
312
- break;
313
- case 'q':
314
- var numbers = parseFloats(data);
315
- for (var j = 0, jl = numbers.length; j < jl; j += 4) {
316
- path.quadraticCurveTo(point.x + numbers[j + 0], point.y + numbers[j + 1], point.x + numbers[j + 2], point.y + numbers[j + 3]);
317
- control.x = point.x + numbers[j + 0];
318
- control.y = point.y + numbers[j + 1];
319
- point.x += numbers[j + 2];
320
- point.y += numbers[j + 3];
321
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
322
- }
323
- break;
324
- case 't':
325
- var numbers = parseFloats(data);
326
- for (var j = 0, jl = numbers.length; j < jl; j += 2) {
327
- var rx = getReflection(point.x, control.x);
328
- var ry = getReflection(point.y, control.y);
329
- path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
330
- control.x = rx;
331
- control.y = ry;
332
- point.x = point.x + numbers[j + 0];
333
- point.y = point.y + numbers[j + 1];
334
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
335
- }
336
- break;
337
- case 'a':
338
- var numbers = parseFloats(data);
339
- for (var j = 0, jl = numbers.length; j < jl; j += 7) {
340
- var start = point.clone();
341
- point.x += numbers[j + 5];
342
- point.y += numbers[j + 6];
343
- control.x = point.x;
344
- control.y = point.y;
345
- parseArcCommand(path, numbers[j], numbers[j + 1], numbers[j + 2], numbers[j + 3], numbers[j + 4], start, point);
346
- if (j === 0 && doSetFirstPoint === true) firstPoint.copy(point);
347
- }
348
- break;
349
- case 'Z':
350
- case 'z':
351
- path.currentPath.autoClose = true;
352
- if (path.currentPath.curves.length > 0) {
353
- // Reset point to beginning of Path
354
- point.copy(firstPoint);
355
- path.currentPath.currentPoint.copy(point);
356
- isFirstPoint = true;
357
- }
358
- break;
359
- default:
360
- console.warn(command);
361
- }
362
-
363
- // console.log( type, parseFloats( data ), parseFloats( data ).length )
364
-
365
- doSetFirstPoint = false;
366
- }
367
- return path;
368
- }
369
- function parseCSSStylesheet(node) {
370
- if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length) return;
371
- for (var i = 0; i < node.sheet.cssRules.length; i++) {
372
- var stylesheet = node.sheet.cssRules[i];
373
- if (stylesheet.type !== 1) continue;
374
- var selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map(function (i) {
375
- return i.trim();
376
- });
377
- for (var j = 0; j < selectorList.length; j++) {
378
- stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, stylesheet.style);
379
- }
380
- }
381
- }
382
-
383
- /**
384
- * https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
385
- * https://mortoray.com/2017/02/16/rendering-an-svg-elliptical-arc-as-bezier-curves/ Appendix: Endpoint to center arc conversion
386
- * From
387
- * rx ry x-axis-rotation large-arc-flag sweep-flag x y
388
- * To
389
- * aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation
390
- */
391
-
392
- function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
393
- x_axis_rotation = x_axis_rotation * Math.PI / 180;
394
-
395
- // Ensure radii are positive
396
- rx = Math.abs(rx);
397
- ry = Math.abs(ry);
398
-
399
- // Compute (x1', y1')
400
- var dx2 = (start.x - end.x) / 2.0;
401
- var dy2 = (start.y - end.y) / 2.0;
402
- var x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
403
- var y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
404
-
405
- // Compute (cx', cy')
406
- var rxs = rx * rx;
407
- var rys = ry * ry;
408
- var x1ps = x1p * x1p;
409
- var y1ps = y1p * y1p;
410
-
411
- // Ensure radii are large enough
412
- var cr = x1ps / rxs + y1ps / rys;
413
- if (cr > 1) {
414
- // scale up rx,ry equally so cr == 1
415
- var s = Math.sqrt(cr);
416
- rx = s * rx;
417
- ry = s * ry;
418
- rxs = rx * rx;
419
- rys = ry * ry;
420
- }
421
- var dq = rxs * y1ps + rys * x1ps;
422
- var pq = (rxs * rys - dq) / dq;
423
- var q = Math.sqrt(Math.max(0, pq));
424
- if (large_arc_flag === sweep_flag) q = -q;
425
- var cxp = q * rx * y1p / ry;
426
- var cyp = -q * ry * x1p / rx;
427
-
428
- // Step 3: Compute (cx, cy) from (cx', cy')
429
- var cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
430
- var cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
431
-
432
- // Step 4: Compute ��1 and ����
433
- var theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
434
- var delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
435
- path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
436
- }
437
- function svgAngle(ux, uy, vx, vy) {
438
- var dot = ux * vx + uy * vy;
439
- var len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
440
- var ang = Math.acos(Math.max(-1, Math.min(1, dot / len))); // floating point precision, slightly over values appear
441
- if (ux * vy - uy * vx < 0) ang = -ang;
442
- return ang;
443
- }
444
-
445
- /*
446
- * According to https://www.w3.org/TR/SVG/shapes.html#RectElementRXAttribute
447
- * rounded corner should be rendered to elliptical arc, but bezier curve does the job well enough
448
- */
449
- function parseRectNode(node) {
450
- var x = parseFloatWithUnits(node.getAttribute('x') || 0);
451
- var y = parseFloatWithUnits(node.getAttribute('y') || 0);
452
- var rx = parseFloatWithUnits(node.getAttribute('rx') || 0);
453
- var ry = parseFloatWithUnits(node.getAttribute('ry') || 0);
454
- var w = parseFloatWithUnits(node.getAttribute('width'));
455
- var h = parseFloatWithUnits(node.getAttribute('height'));
456
- var path = new ShapePath();
457
- path.moveTo(x + 2 * rx, y);
458
- path.lineTo(x + w - 2 * rx, y);
459
- if (rx !== 0 || ry !== 0) path.bezierCurveTo(x + w, y, x + w, y, x + w, y + 2 * ry);
460
- path.lineTo(x + w, y + h - 2 * ry);
461
- if (rx !== 0 || ry !== 0) path.bezierCurveTo(x + w, y + h, x + w, y + h, x + w - 2 * rx, y + h);
462
- path.lineTo(x + 2 * rx, y + h);
463
- if (rx !== 0 || ry !== 0) {
464
- path.bezierCurveTo(x, y + h, x, y + h, x, y + h - 2 * ry);
465
- }
466
- path.lineTo(x, y + 2 * ry);
467
- if (rx !== 0 || ry !== 0) {
468
- path.bezierCurveTo(x, y, x, y, x + 2 * rx, y);
469
- }
470
- return path;
471
- }
472
- function parsePolygonNode(node) {
473
- function iterator(match, a, b) {
474
- var x = parseFloatWithUnits(a);
475
- var y = parseFloatWithUnits(b);
476
- if (index === 0) {
477
- path.moveTo(x, y);
478
- } else {
479
- path.lineTo(x, y);
480
- }
481
- index++;
482
- }
483
- var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;
484
- var path = new ShapePath();
485
- var index = 0;
486
- node.getAttribute('points').replace(regex, iterator);
487
- path.currentPath.autoClose = true;
488
- return path;
489
- }
490
- function parsePolylineNode(node) {
491
- function iterator(match, a, b) {
492
- var x = parseFloatWithUnits(a);
493
- var y = parseFloatWithUnits(b);
494
- if (index === 0) {
495
- path.moveTo(x, y);
496
- } else {
497
- path.lineTo(x, y);
498
- }
499
- index++;
500
- }
501
- var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;
502
- var path = new ShapePath();
503
- var index = 0;
504
- node.getAttribute('points').replace(regex, iterator);
505
- path.currentPath.autoClose = false;
506
- return path;
507
- }
508
- function parseCircleNode(node) {
509
- var x = parseFloatWithUnits(node.getAttribute('cx'));
510
- var y = parseFloatWithUnits(node.getAttribute('cy'));
511
- var r = parseFloatWithUnits(node.getAttribute('r'));
512
- var subpath = new Path();
513
- subpath.absarc(x, y, r, 0, Math.PI * 2);
514
- var path = new ShapePath();
515
- path.subPaths.push(subpath);
516
- return path;
517
- }
518
- function parseEllipseNode(node) {
519
- var x = parseFloatWithUnits(node.getAttribute('cx'));
520
- var y = parseFloatWithUnits(node.getAttribute('cy'));
521
- var rx = parseFloatWithUnits(node.getAttribute('rx'));
522
- var ry = parseFloatWithUnits(node.getAttribute('ry'));
523
- var subpath = new Path();
524
- subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
525
- var path = new ShapePath();
526
- path.subPaths.push(subpath);
527
- return path;
528
- }
529
- function parseLineNode(node) {
530
- var x1 = parseFloatWithUnits(node.getAttribute('x1'));
531
- var y1 = parseFloatWithUnits(node.getAttribute('y1'));
532
- var x2 = parseFloatWithUnits(node.getAttribute('x2'));
533
- var y2 = parseFloatWithUnits(node.getAttribute('y2'));
534
- var path = new ShapePath();
535
- path.moveTo(x1, y1);
536
- path.lineTo(x2, y2);
537
- path.currentPath.autoClose = false;
538
- return path;
539
- }
540
-
541
- //
542
-
543
- function parseStyle(node, style) {
544
- style = Object.assign({}, style); // clone style
545
-
546
- var stylesheetStyles = {};
547
- if (node.hasAttribute('class')) {
548
- var classSelectors = node.getAttribute('class').split(/\s/).filter(Boolean).map(function (i) {
549
- return i.trim();
550
- });
551
- for (var i = 0; i < classSelectors.length; i++) {
552
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets['.' + classSelectors[i]]);
553
- }
554
- }
555
- if (node.hasAttribute('id')) {
556
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets['#' + node.getAttribute('id')]);
557
- }
558
- function addStyle(svgName, jsName, adjustFunction) {
559
- if (adjustFunction === undefined) adjustFunction = function copy(v) {
560
- if (v.startsWith('url')) console.warn('SVGLoader: url access in attributes is not implemented.');
561
- return v;
562
- };
563
- if (node.hasAttribute(svgName)) style[jsName] = adjustFunction(node.getAttribute(svgName));
564
- if (stylesheetStyles[svgName]) style[jsName] = adjustFunction(stylesheetStyles[svgName]);
565
- if (node.style && node.style[svgName] !== '') style[jsName] = adjustFunction(node.style[svgName]);
566
- }
567
- function clamp(v) {
568
- return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
569
- }
570
- function positive(v) {
571
- return Math.max(0, parseFloatWithUnits(v));
572
- }
573
- addStyle('fill', 'fill');
574
- addStyle('fill-opacity', 'fillOpacity', clamp);
575
- addStyle('opacity', 'opacity', clamp);
576
- addStyle('stroke', 'stroke');
577
- addStyle('stroke-opacity', 'strokeOpacity', clamp);
578
- addStyle('stroke-width', 'strokeWidth', positive);
579
- addStyle('stroke-linejoin', 'strokeLineJoin');
580
- addStyle('stroke-linecap', 'strokeLineCap');
581
- addStyle('stroke-miterlimit', 'strokeMiterLimit', positive);
582
- addStyle('visibility', 'visibility');
583
- return style;
584
- }
585
-
586
- // http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
587
-
588
- function getReflection(a, b) {
589
- return a - (b - a);
590
- }
591
- function parseFloats(string) {
592
- var array = string.split(/[\s,]+|(?=\s?[+\-])/);
593
- for (var i = 0; i < array.length; i++) {
594
- var number = array[i];
595
-
596
- // Handle values like 48.6037.7.8
597
- // TODO Find a regex for this
598
-
599
- if (number.indexOf('.') !== number.lastIndexOf('.')) {
600
- var split = number.split('.');
601
- for (var s = 2; s < split.length; s++) {
602
- array.splice(i + s - 1, 0, '0.' + split[s]);
603
- }
604
- }
605
- array[i] = parseFloatWithUnits(number);
606
- }
607
- return array;
608
- }
609
-
610
- // Units
611
-
612
- var units = ['mm', 'cm', 'in', 'pt', 'pc', 'px'];
613
-
614
- // Conversion: [ fromUnit ][ toUnit ] (-1 means dpi dependent)
615
- var unitConversion = {
616
- mm: {
617
- mm: 1,
618
- cm: 0.1,
619
- "in": 1 / 25.4,
620
- pt: 72 / 25.4,
621
- pc: 6 / 25.4,
622
- px: -1
623
- },
624
- cm: {
625
- mm: 10,
626
- cm: 1,
627
- "in": 1 / 2.54,
628
- pt: 72 / 2.54,
629
- pc: 6 / 2.54,
630
- px: -1
631
- },
632
- "in": {
633
- mm: 25.4,
634
- cm: 2.54,
635
- "in": 1,
636
- pt: 72,
637
- pc: 6,
638
- px: -1
639
- },
640
- pt: {
641
- mm: 25.4 / 72,
642
- cm: 2.54 / 72,
643
- "in": 1 / 72,
644
- pt: 1,
645
- pc: 6 / 72,
646
- px: -1
647
- },
648
- pc: {
649
- mm: 25.4 / 6,
650
- cm: 2.54 / 6,
651
- "in": 1 / 6,
652
- pt: 72 / 6,
653
- pc: 1,
654
- px: -1
655
- },
656
- px: {
657
- px: 1
658
- }
659
- };
660
- function parseFloatWithUnits(string) {
661
- var theUnit = 'px';
662
- if (typeof string === 'string' || string instanceof String) {
663
- for (var i = 0, n = units.length; i < n; i++) {
664
- var u = units[i];
665
- if (string.endsWith(u)) {
666
- theUnit = u;
667
- string = string.substring(0, string.length - u.length);
668
- break;
669
- }
670
- }
671
- }
672
- var scale = undefined;
673
- if (theUnit === 'px' && scope.defaultUnit !== 'px') {
674
- // Conversion scale from pixels to inches, then to default units
675
-
676
- scale = unitConversion['in'][scope.defaultUnit] / scope.defaultDPI;
677
- } else {
678
- scale = unitConversion[theUnit][scope.defaultUnit];
679
- if (scale < 0) {
680
- // Conversion scale to pixels
681
-
682
- scale = unitConversion[theUnit]['in'] * scope.defaultDPI;
683
- }
684
- }
685
- return scale * parseFloat(string);
686
- }
687
-
688
- // Transforms
689
-
690
- function getNodeTransform(node) {
691
- if (!(node.hasAttribute('transform') || node.nodeName === 'use' && (node.hasAttribute('x') || node.hasAttribute('y')))) {
692
- return null;
693
- }
694
- var transform = parseNodeTransform(node);
695
- if (transformStack.length > 0) {
696
- transform.premultiply(transformStack[transformStack.length - 1]);
697
- }
698
- currentTransform.copy(transform);
699
- transformStack.push(transform);
700
- return transform;
701
- }
702
- function parseNodeTransform(node) {
703
- var transform = new Matrix3();
704
- var currentTransform = tempTransform0;
705
- if (node.nodeName === 'use' && (node.hasAttribute('x') || node.hasAttribute('y'))) {
706
- var tx = parseFloatWithUnits(node.getAttribute('x'));
707
- var ty = parseFloatWithUnits(node.getAttribute('y'));
708
- transform.translate(tx, ty);
709
- }
710
- if (node.hasAttribute('transform')) {
711
- var transformsTexts = node.getAttribute('transform').split(')');
712
- for (var tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
713
- var transformText = transformsTexts[tIndex].trim();
714
- if (transformText === '') continue;
715
- var openParPos = transformText.indexOf('(');
716
- var closeParPos = transformText.length;
717
- if (openParPos > 0 && openParPos < closeParPos) {
718
- var transformType = transformText.substr(0, openParPos);
719
- var array = parseFloats(transformText.substr(openParPos + 1, closeParPos - openParPos - 1));
720
- currentTransform.identity();
721
- switch (transformType) {
722
- case 'translate':
723
- if (array.length >= 1) {
724
- var tx = array[0];
725
- var ty = tx;
726
- if (array.length >= 2) {
727
- ty = array[1];
728
- }
729
- currentTransform.translate(tx, ty);
730
- }
731
- break;
732
- case 'rotate':
733
- if (array.length >= 1) {
734
- var angle = 0;
735
- var cx = 0;
736
- var cy = 0;
737
-
738
- // Angle
739
- angle = -array[0] * Math.PI / 180;
740
- if (array.length >= 3) {
741
- // Center x, y
742
- cx = array[1];
743
- cy = array[2];
744
- }
745
-
746
- // Rotate around center (cx, cy)
747
- tempTransform1.identity().translate(-cx, -cy);
748
- tempTransform2.identity().rotate(angle);
749
- tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
750
- tempTransform1.identity().translate(cx, cy);
751
- currentTransform.multiplyMatrices(tempTransform1, tempTransform3);
752
- }
753
- break;
754
- case 'scale':
755
- if (array.length >= 1) {
756
- var scaleX = array[0];
757
- var scaleY = scaleX;
758
- if (array.length >= 2) {
759
- scaleY = array[1];
760
- }
761
- currentTransform.scale(scaleX, scaleY);
762
- }
763
- break;
764
- case 'skewX':
765
- if (array.length === 1) {
766
- currentTransform.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
767
- }
768
- break;
769
- case 'skewY':
770
- if (array.length === 1) {
771
- currentTransform.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
772
- }
773
- break;
774
- case 'matrix':
775
- if (array.length === 6) {
776
- currentTransform.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
777
- }
778
- break;
779
- }
780
- }
781
- transform.premultiply(currentTransform);
782
- }
783
- }
784
- return transform;
785
- }
786
- function transformPath(path, m) {
787
- function transfVec2(v2) {
788
- tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
789
- v2.set(tempV3.x, tempV3.y);
790
- }
791
- var isRotated = isTransformRotated(m);
792
- var subPaths = path.subPaths;
793
- for (var i = 0, n = subPaths.length; i < n; i++) {
794
- var subPath = subPaths[i];
795
- var curves = subPath.curves;
796
- for (var j = 0; j < curves.length; j++) {
797
- var curve = curves[j];
798
- if (curve.isLineCurve) {
799
- transfVec2(curve.v1);
800
- transfVec2(curve.v2);
801
- } else if (curve.isCubicBezierCurve) {
802
- transfVec2(curve.v0);
803
- transfVec2(curve.v1);
804
- transfVec2(curve.v2);
805
- transfVec2(curve.v3);
806
- } else if (curve.isQuadraticBezierCurve) {
807
- transfVec2(curve.v0);
808
- transfVec2(curve.v1);
809
- transfVec2(curve.v2);
810
- } else if (curve.isEllipseCurve) {
811
- if (isRotated) {
812
- console.warn('SVGLoader: Elliptic arc or ellipse rotation or skewing is not implemented.');
813
- }
814
- tempV2.set(curve.aX, curve.aY);
815
- transfVec2(tempV2);
816
- curve.aX = tempV2.x;
817
- curve.aY = tempV2.y;
818
- curve.xRadius *= getTransformScaleX(m);
819
- curve.yRadius *= getTransformScaleY(m);
820
- }
821
- }
822
- }
823
- }
824
- function isTransformRotated(m) {
825
- return m.elements[1] !== 0 || m.elements[3] !== 0;
826
- }
827
- function getTransformScaleX(m) {
828
- var te = m.elements;
829
- return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
830
- }
831
- function getTransformScaleY(m) {
832
- var te = m.elements;
833
- return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
834
- }
835
-
836
- //
837
-
838
- var paths = [];
839
- var stylesheets = {};
840
- var transformStack = [];
841
- var tempTransform0 = new Matrix3();
842
- var tempTransform1 = new Matrix3();
843
- var tempTransform2 = new Matrix3();
844
- var tempTransform3 = new Matrix3();
845
- var tempV2 = new Vector2();
846
- var tempV3 = new Vector3();
847
- var currentTransform = new Matrix3();
848
- var xml = new DOMParser().parseFromString(text, 'image/svg+xml'); // application/xml
849
-
850
- parseNode(xml.documentElement, {
851
- fill: '#000',
852
- fillOpacity: 1,
853
- strokeOpacity: 1,
854
- strokeWidth: 1,
855
- strokeLineJoin: 'miter',
856
- strokeLineCap: 'butt',
857
- strokeMiterLimit: 4
858
- });
859
- var data = {
860
- paths: paths,
861
- xml: xml.documentElement
862
- };
863
-
864
- // console.log( paths );
865
- return data;
866
- }
867
- });
868
- SVGLoader.getStrokeStyle = function (width, color, lineJoin, lineCap, miterLimit) {
869
- // Param width: Stroke width
870
- // Param color: As returned by THREE.Color.getStyle()
871
- // Param lineJoin: One of "round", "bevel", "miter" or "miter-limit"
872
- // Param lineCap: One of "round", "square" or "butt"
873
- // Param miterLimit: Maximum join length, in multiples of the "width" parameter (join is truncated if it exceeds that distance)
874
- // Returns style object
875
-
876
- width = width !== undefined ? width : 1;
877
- color = color !== undefined ? color : '#000';
878
- lineJoin = lineJoin !== undefined ? lineJoin : 'miter';
879
- lineCap = lineCap !== undefined ? lineCap : 'butt';
880
- miterLimit = miterLimit !== undefined ? miterLimit : 4;
881
- return {
882
- strokeColor: color,
883
- strokeWidth: width,
884
- strokeLineJoin: lineJoin,
885
- strokeLineCap: lineCap,
886
- strokeMiterLimit: miterLimit
887
- };
888
- };
889
- SVGLoader.pointsToStroke = function (points, style, arcDivisions, minDistance) {
890
- // Generates a stroke with some witdh around the given path.
891
- // The path can be open or closed (last point equals to first point)
892
- // Param points: Array of Vector2D (the path). Minimum 2 points.
893
- // Param style: Object with SVG properties as returned by SVGLoader.getStrokeStyle(), or SVGLoader.parse() in the path.userData.style object
894
- // Params arcDivisions: Arc divisions for round joins and endcaps. (Optional)
895
- // Param minDistance: Points closer to this distance will be merged. (Optional)
896
- // Returns BufferGeometry with stroke triangles (In plane z = 0). UV coordinates are generated ('u' along path. 'v' across it, from left to right)
897
-
898
- var vertices = [];
899
- var normals = [];
900
- var uvs = [];
901
- if (SVGLoader.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
902
- return null;
903
- }
904
- var geometry = new BufferGeometry();
905
- geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
906
- geometry.setAttribute('normal', new Float32BufferAttribute(normals, 3));
907
- geometry.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
908
- return geometry;
909
- };
910
- SVGLoader.pointsToStrokeWithBuffers = function () {
911
- var tempV2_1 = new Vector2();
912
- var tempV2_2 = new Vector2();
913
- var tempV2_3 = new Vector2();
914
- var tempV2_4 = new Vector2();
915
- var tempV2_5 = new Vector2();
916
- var tempV2_6 = new Vector2();
917
- var tempV2_7 = new Vector2();
918
- var lastPointL = new Vector2();
919
- var lastPointR = new Vector2();
920
- var point0L = new Vector2();
921
- var point0R = new Vector2();
922
- var currentPointL = new Vector2();
923
- var currentPointR = new Vector2();
924
- var nextPointL = new Vector2();
925
- var nextPointR = new Vector2();
926
- var innerPoint = new Vector2();
927
- var outerPoint = new Vector2();
928
- return function (points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
929
- // This function can be called to update existing arrays or buffers.
930
- // Accepts same parameters as pointsToStroke, plus the buffers and optional offset.
931
- // Param vertexOffset: Offset vertices to start writing in the buffers (3 elements/vertex for vertices and normals, and 2 elements/vertex for uvs)
932
- // Returns number of written vertices / normals / uvs pairs
933
- // if 'vertices' parameter is undefined no triangles will be generated, but the returned vertices count will still be valid (useful to preallocate the buffers)
934
- // 'normals' and 'uvs' buffers are optional
935
-
936
- arcDivisions = arcDivisions !== undefined ? arcDivisions : 12;
937
- minDistance = minDistance !== undefined ? minDistance : 0.001;
938
- vertexOffset = vertexOffset !== undefined ? vertexOffset : 0;
939
-
940
- // First ensure there are no duplicated points
941
- points = removeDuplicatedPoints(points);
942
- var numPoints = points.length;
943
- if (numPoints < 2) return 0;
944
- var isClosed = points[0].equals(points[numPoints - 1]);
945
- var currentPoint;
946
- var previousPoint = points[0];
947
- var nextPoint;
948
- var strokeWidth2 = style.strokeWidth / 2;
949
- var deltaU = 1 / (numPoints - 1);
950
- var u0 = 0;
951
- var innerSideModified;
952
- var joinIsOnLeftSide;
953
- var isMiter;
954
- var initialJoinIsOnLeftSide = false;
955
- var numVertices = 0;
956
- var currentCoordinate = vertexOffset * 3;
957
- var currentCoordinateUV = vertexOffset * 2;
958
-
959
- // Get initial left and right stroke points
960
- getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
961
- lastPointL.copy(points[0]).sub(tempV2_1);
962
- lastPointR.copy(points[0]).add(tempV2_1);
963
- point0L.copy(lastPointL);
964
- point0R.copy(lastPointR);
965
- for (var iPoint = 1; iPoint < numPoints; iPoint++) {
966
- currentPoint = points[iPoint];
967
-
968
- // Get next point
969
- if (iPoint === numPoints - 1) {
970
- if (isClosed) {
971
- // Skip duplicated initial point
972
- nextPoint = points[1];
973
- } else nextPoint = undefined;
974
- } else {
975
- nextPoint = points[iPoint + 1];
976
- }
977
-
978
- // Normal of previous segment in tempV2_1
979
- var normal1 = tempV2_1;
980
- getNormal(previousPoint, currentPoint, normal1);
981
- tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
982
- currentPointL.copy(currentPoint).sub(tempV2_3);
983
- currentPointR.copy(currentPoint).add(tempV2_3);
984
- var u1 = u0 + deltaU;
985
- innerSideModified = false;
986
- if (nextPoint !== undefined) {
987
- // Normal of next segment in tempV2_2
988
- getNormal(currentPoint, nextPoint, tempV2_2);
989
- tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
990
- nextPointL.copy(currentPoint).sub(tempV2_3);
991
- nextPointR.copy(currentPoint).add(tempV2_3);
992
- joinIsOnLeftSide = true;
993
- tempV2_3.subVectors(nextPoint, previousPoint);
994
- if (normal1.dot(tempV2_3) < 0) {
995
- joinIsOnLeftSide = false;
996
- }
997
- if (iPoint === 1) initialJoinIsOnLeftSide = joinIsOnLeftSide;
998
- tempV2_3.subVectors(nextPoint, currentPoint);
999
- tempV2_3.normalize();
1000
- var dot = Math.abs(normal1.dot(tempV2_3));
1001
-
1002
- // If path is straight, don't create join
1003
- if (dot !== 0) {
1004
- // Compute inner and outer segment intersections
1005
- var miterSide = strokeWidth2 / dot;
1006
- tempV2_3.multiplyScalar(-miterSide);
1007
- tempV2_4.subVectors(currentPoint, previousPoint);
1008
- tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1009
- innerPoint.copy(tempV2_5).negate();
1010
- var miterLength2 = tempV2_5.length();
1011
- var segmentLengthPrev = tempV2_4.length();
1012
- tempV2_4.divideScalar(segmentLengthPrev);
1013
- tempV2_6.subVectors(nextPoint, currentPoint);
1014
- var segmentLengthNext = tempV2_6.length();
1015
- tempV2_6.divideScalar(segmentLengthNext);
1016
- // Check that previous and next segments doesn't overlap with the innerPoint of intersection
1017
- if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1018
- innerSideModified = true;
1019
- }
1020
- outerPoint.copy(tempV2_5).add(currentPoint);
1021
- innerPoint.add(currentPoint);
1022
- isMiter = false;
1023
- if (innerSideModified) {
1024
- if (joinIsOnLeftSide) {
1025
- nextPointR.copy(innerPoint);
1026
- currentPointR.copy(innerPoint);
1027
- } else {
1028
- nextPointL.copy(innerPoint);
1029
- currentPointL.copy(innerPoint);
1030
- }
1031
- } else {
1032
- // The segment triangles are generated here if there was overlapping
1033
-
1034
- makeSegmentTriangles();
1035
- }
1036
- switch (style.strokeLineJoin) {
1037
- case 'bevel':
1038
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1039
- break;
1040
- case 'round':
1041
- // Segment triangles
1042
-
1043
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1044
-
1045
- // Join triangles
1046
-
1047
- if (joinIsOnLeftSide) {
1048
- makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1049
- } else {
1050
- makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1051
- }
1052
- break;
1053
- case 'miter':
1054
- case 'miter-clip':
1055
- default:
1056
- var miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
1057
- if (miterFraction < 1) {
1058
- // The join miter length exceeds the miter limit
1059
-
1060
- if (style.strokeLineJoin !== 'miter-clip') {
1061
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1062
- break;
1063
- } else {
1064
- // Segment triangles
1065
-
1066
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1067
-
1068
- // Miter-clip join triangles
1069
-
1070
- if (joinIsOnLeftSide) {
1071
- tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1072
- tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1073
- addVertex(currentPointL, u1, 0);
1074
- addVertex(tempV2_6, u1, 0);
1075
- addVertex(currentPoint, u1, 0.5);
1076
- addVertex(currentPoint, u1, 0.5);
1077
- addVertex(tempV2_6, u1, 0);
1078
- addVertex(tempV2_7, u1, 0);
1079
- addVertex(currentPoint, u1, 0.5);
1080
- addVertex(tempV2_7, u1, 0);
1081
- addVertex(nextPointL, u1, 0);
1082
- } else {
1083
- tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1084
- tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1085
- addVertex(currentPointR, u1, 1);
1086
- addVertex(tempV2_6, u1, 1);
1087
- addVertex(currentPoint, u1, 0.5);
1088
- addVertex(currentPoint, u1, 0.5);
1089
- addVertex(tempV2_6, u1, 1);
1090
- addVertex(tempV2_7, u1, 1);
1091
- addVertex(currentPoint, u1, 0.5);
1092
- addVertex(tempV2_7, u1, 1);
1093
- addVertex(nextPointR, u1, 1);
1094
- }
1095
- }
1096
- } else {
1097
- // Miter join segment triangles
1098
-
1099
- if (innerSideModified) {
1100
- // Optimized segment + join triangles
1101
-
1102
- if (joinIsOnLeftSide) {
1103
- addVertex(lastPointR, u0, 1);
1104
- addVertex(lastPointL, u0, 0);
1105
- addVertex(outerPoint, u1, 0);
1106
- addVertex(lastPointR, u0, 1);
1107
- addVertex(outerPoint, u1, 0);
1108
- addVertex(innerPoint, u1, 1);
1109
- } else {
1110
- addVertex(lastPointR, u0, 1);
1111
- addVertex(lastPointL, u0, 0);
1112
- addVertex(outerPoint, u1, 1);
1113
- addVertex(lastPointL, u0, 0);
1114
- addVertex(innerPoint, u1, 0);
1115
- addVertex(outerPoint, u1, 1);
1116
- }
1117
- if (joinIsOnLeftSide) {
1118
- nextPointL.copy(outerPoint);
1119
- } else {
1120
- nextPointR.copy(outerPoint);
1121
- }
1122
- } else {
1123
- // Add extra miter join triangles
1124
-
1125
- if (joinIsOnLeftSide) {
1126
- addVertex(currentPointL, u1, 0);
1127
- addVertex(outerPoint, u1, 0);
1128
- addVertex(currentPoint, u1, 0.5);
1129
- addVertex(currentPoint, u1, 0.5);
1130
- addVertex(outerPoint, u1, 0);
1131
- addVertex(nextPointL, u1, 0);
1132
- } else {
1133
- addVertex(currentPointR, u1, 1);
1134
- addVertex(outerPoint, u1, 1);
1135
- addVertex(currentPoint, u1, 0.5);
1136
- addVertex(currentPoint, u1, 0.5);
1137
- addVertex(outerPoint, u1, 1);
1138
- addVertex(nextPointR, u1, 1);
1139
- }
1140
- }
1141
- isMiter = true;
1142
- }
1143
- break;
1144
- }
1145
- } else {
1146
- // The segment triangles are generated here when two consecutive points are collinear
1147
-
1148
- makeSegmentTriangles();
1149
- }
1150
- } else {
1151
- // The segment triangles are generated here if it is the ending segment
1152
-
1153
- makeSegmentTriangles();
1154
- }
1155
- if (!isClosed && iPoint === numPoints - 1) {
1156
- // Start line endcap
1157
- addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1158
- }
1159
-
1160
- // Increment loop variables
1161
-
1162
- u0 = u1;
1163
- previousPoint = currentPoint;
1164
- lastPointL.copy(nextPointL);
1165
- lastPointR.copy(nextPointR);
1166
- }
1167
- if (!isClosed) {
1168
- // Ending line endcap
1169
- addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1170
- } else if (innerSideModified && vertices) {
1171
- // Modify path first segment vertices to adjust to the segments inner and outer intersections
1172
-
1173
- var lastOuter = outerPoint;
1174
- var lastInner = innerPoint;
1175
- if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1176
- lastOuter = innerPoint;
1177
- lastInner = outerPoint;
1178
- }
1179
- if (joinIsOnLeftSide) {
1180
- if (isMiter || initialJoinIsOnLeftSide) {
1181
- lastInner.toArray(vertices, 0 * 3);
1182
- lastInner.toArray(vertices, 3 * 3);
1183
- if (isMiter) {
1184
- lastOuter.toArray(vertices, 1 * 3);
1185
- }
1186
- }
1187
- } else {
1188
- if (isMiter || !initialJoinIsOnLeftSide) {
1189
- lastInner.toArray(vertices, 1 * 3);
1190
- lastInner.toArray(vertices, 3 * 3);
1191
- if (isMiter) {
1192
- lastOuter.toArray(vertices, 0 * 3);
1193
- }
1194
- }
1195
- }
1196
- }
1197
- return numVertices;
1198
-
1199
- // -- End of algorithm
1200
-
1201
- // -- Functions
1202
-
1203
- function getNormal(p1, p2, result) {
1204
- result.subVectors(p2, p1);
1205
- return result.set(-result.y, result.x).normalize();
1206
- }
1207
- function addVertex(position, u, v) {
1208
- if (vertices) {
1209
- vertices[currentCoordinate] = position.x;
1210
- vertices[currentCoordinate + 1] = position.y;
1211
- vertices[currentCoordinate + 2] = 0;
1212
- if (normals) {
1213
- normals[currentCoordinate] = 0;
1214
- normals[currentCoordinate + 1] = 0;
1215
- normals[currentCoordinate + 2] = 1;
1216
- }
1217
- currentCoordinate += 3;
1218
- if (uvs) {
1219
- uvs[currentCoordinateUV] = u;
1220
- uvs[currentCoordinateUV + 1] = v;
1221
- currentCoordinateUV += 2;
1222
- }
1223
- }
1224
- numVertices += 3;
1225
- }
1226
- function makeCircularSector(center, p1, p2, u, v) {
1227
- // param p1, p2: Points in the circle arc.
1228
- // p1 and p2 are in clockwise direction.
1229
-
1230
- tempV2_1.copy(p1).sub(center).normalize();
1231
- tempV2_2.copy(p2).sub(center).normalize();
1232
- var angle = Math.PI;
1233
- var dot = tempV2_1.dot(tempV2_2);
1234
- if (Math.abs(dot) < 1) angle = Math.abs(Math.acos(dot));
1235
- angle /= arcDivisions;
1236
- tempV2_3.copy(p1);
1237
- for (var i = 0, il = arcDivisions - 1; i < il; i++) {
1238
- tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1239
- addVertex(tempV2_3, u, v);
1240
- addVertex(tempV2_4, u, v);
1241
- addVertex(center, u, 0.5);
1242
- tempV2_3.copy(tempV2_4);
1243
- }
1244
- addVertex(tempV2_4, u, v);
1245
- addVertex(p2, u, v);
1246
- addVertex(center, u, 0.5);
1247
- }
1248
- function makeSegmentTriangles() {
1249
- addVertex(lastPointR, u0, 1);
1250
- addVertex(lastPointL, u0, 0);
1251
- addVertex(currentPointL, u1, 0);
1252
- addVertex(lastPointR, u0, 1);
1253
- addVertex(currentPointL, u1, 1);
1254
- addVertex(currentPointR, u1, 0);
1255
- }
1256
- function makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u) {
1257
- if (innerSideModified) {
1258
- // Optimized segment + bevel triangles
1259
-
1260
- if (joinIsOnLeftSide) {
1261
- // Path segments triangles
1262
-
1263
- addVertex(lastPointR, u0, 1);
1264
- addVertex(lastPointL, u0, 0);
1265
- addVertex(currentPointL, u1, 0);
1266
- addVertex(lastPointR, u0, 1);
1267
- addVertex(currentPointL, u1, 0);
1268
- addVertex(innerPoint, u1, 1);
1269
-
1270
- // Bevel join triangle
1271
-
1272
- addVertex(currentPointL, u, 0);
1273
- addVertex(nextPointL, u, 0);
1274
- addVertex(innerPoint, u, 0.5);
1275
- } else {
1276
- // Path segments triangles
1277
-
1278
- addVertex(lastPointR, u0, 1);
1279
- addVertex(lastPointL, u0, 0);
1280
- addVertex(currentPointR, u1, 1);
1281
- addVertex(lastPointL, u0, 0);
1282
- addVertex(innerPoint, u1, 0);
1283
- addVertex(currentPointR, u1, 1);
1284
-
1285
- // Bevel join triangle
1286
-
1287
- addVertex(currentPointR, u, 1);
1288
- addVertex(nextPointR, u, 0);
1289
- addVertex(innerPoint, u, 0.5);
1290
- }
1291
- } else {
1292
- // Bevel join triangle. The segment triangles are done in the main loop
1293
-
1294
- if (joinIsOnLeftSide) {
1295
- addVertex(currentPointL, u, 0);
1296
- addVertex(nextPointL, u, 0);
1297
- addVertex(currentPoint, u, 0.5);
1298
- } else {
1299
- addVertex(currentPointR, u, 1);
1300
- addVertex(nextPointR, u, 0);
1301
- addVertex(currentPoint, u, 0.5);
1302
- }
1303
- }
1304
- }
1305
- function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified) {
1306
- if (innerSideModified) {
1307
- if (joinIsOnLeftSide) {
1308
- addVertex(lastPointR, u0, 1);
1309
- addVertex(lastPointL, u0, 0);
1310
- addVertex(currentPointL, u1, 0);
1311
- addVertex(lastPointR, u0, 1);
1312
- addVertex(currentPointL, u1, 0);
1313
- addVertex(innerPoint, u1, 1);
1314
- addVertex(currentPointL, u0, 0);
1315
- addVertex(currentPoint, u1, 0.5);
1316
- addVertex(innerPoint, u1, 1);
1317
- addVertex(currentPoint, u1, 0.5);
1318
- addVertex(nextPointL, u0, 0);
1319
- addVertex(innerPoint, u1, 1);
1320
- } else {
1321
- addVertex(lastPointR, u0, 1);
1322
- addVertex(lastPointL, u0, 0);
1323
- addVertex(currentPointR, u1, 1);
1324
- addVertex(lastPointL, u0, 0);
1325
- addVertex(innerPoint, u1, 0);
1326
- addVertex(currentPointR, u1, 1);
1327
- addVertex(currentPointR, u0, 1);
1328
- addVertex(innerPoint, u1, 0);
1329
- addVertex(currentPoint, u1, 0.5);
1330
- addVertex(currentPoint, u1, 0.5);
1331
- addVertex(innerPoint, u1, 0);
1332
- addVertex(nextPointR, u0, 1);
1333
- }
1334
- }
1335
- }
1336
- function addCapGeometry(center, p1, p2, joinIsOnLeftSide, start, u) {
1337
- // param center: End point of the path
1338
- // param p1, p2: Left and right cap points
1339
-
1340
- switch (style.strokeLineCap) {
1341
- case 'round':
1342
- if (start) {
1343
- makeCircularSector(center, p2, p1, u, 0.5);
1344
- } else {
1345
- makeCircularSector(center, p1, p2, u, 0.5);
1346
- }
1347
- break;
1348
- case 'square':
1349
- if (start) {
1350
- tempV2_1.subVectors(p1, center);
1351
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1352
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1353
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1354
-
1355
- // Modify already existing vertices
1356
- if (joinIsOnLeftSide) {
1357
- tempV2_3.toArray(vertices, 1 * 3);
1358
- tempV2_4.toArray(vertices, 0 * 3);
1359
- tempV2_4.toArray(vertices, 3 * 3);
1360
- } else {
1361
- tempV2_3.toArray(vertices, 1 * 3);
1362
- tempV2_3.toArray(vertices, 3 * 3);
1363
- tempV2_4.toArray(vertices, 0 * 3);
1364
- }
1365
- } else {
1366
- tempV2_1.subVectors(p2, center);
1367
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1368
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1369
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1370
- var vl = vertices.length;
1371
-
1372
- // Modify already existing vertices
1373
- if (joinIsOnLeftSide) {
1374
- tempV2_3.toArray(vertices, vl - 1 * 3);
1375
- tempV2_4.toArray(vertices, vl - 2 * 3);
1376
- tempV2_4.toArray(vertices, vl - 4 * 3);
1377
- } else {
1378
- tempV2_3.toArray(vertices, vl - 2 * 3);
1379
- tempV2_4.toArray(vertices, vl - 1 * 3);
1380
- tempV2_4.toArray(vertices, vl - 4 * 3);
1381
- }
1382
- }
1383
- break;
1384
- case 'butt':
1385
- default:
1386
- // Nothing to do here
1387
- break;
1388
- }
1389
- }
1390
- function removeDuplicatedPoints(points) {
1391
- // Creates a new array if necessary with duplicated points removed.
1392
- // This does not remove duplicated initial and ending points of a closed path.
1393
-
1394
- var dupPoints = false;
1395
- for (var i = 1, n = points.length - 1; i < n; i++) {
1396
- if (points[i].distanceTo(points[i + 1]) < minDistance) {
1397
- dupPoints = true;
1398
- break;
1399
- }
1400
- }
1401
- if (!dupPoints) return points;
1402
- var newPoints = [];
1403
- newPoints.push(points[0]);
1404
- for (var i = 1, n = points.length - 1; i < n; i++) {
1405
- if (points[i].distanceTo(points[i + 1]) >= minDistance) {
1406
- newPoints.push(points[i]);
1407
- }
1408
- }
1409
- newPoints.push(points[points.length - 1]);
1410
- return newPoints;
1411
- }
1412
- };
1413
- }();
1414
- export { SVGLoader };