kitchen-simulator 1.1.1-test.48 → 1.1.1-test.49

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