@anov/3d 0.0.4-alpha.1 → 0.0.4-alpha13

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 (588) hide show
  1. package/README.md +1 -144
  2. package/dist/applicationApi.d.ts +34 -0
  3. package/dist/{core/cssRenderer.js → applicationApi.js} +53 -21
  4. package/dist/environment/index.d.ts +27 -0
  5. package/dist/environment/index.js +84 -0
  6. package/dist/environment/time/index.d.ts +12 -0
  7. package/dist/environment/time/index.js +27 -0
  8. package/dist/environment/weather/type.d.ts +15 -0
  9. package/dist/environment/weather/type.js +27 -0
  10. package/dist/hooksManager.d.ts +2 -0
  11. package/dist/hooksManager.js +15 -0
  12. package/dist/index.d.ts +15 -3
  13. package/dist/index.js +38 -5
  14. package/dist/messageStatus.d.ts +49 -0
  15. package/dist/messageStatus.js +50 -0
  16. package/dist/utils/index.d.ts +11 -50
  17. package/dist/utils/index.js +29 -92
  18. package/dist/utils/messageFn.d.ts +12 -0
  19. package/dist/utils/messageFn.js +33 -0
  20. package/package.json +8 -24
  21. package/dist/commonEnu.d.ts +0 -5
  22. package/dist/commonEnu.js +0 -6
  23. package/dist/core/camera.d.ts +0 -32
  24. package/dist/core/camera.js +0 -74
  25. package/dist/core/control/transformControls.d.ts +0 -12
  26. package/dist/core/control/transformControls.js +0 -72
  27. package/dist/core/cssRenderer.d.ts +0 -17
  28. package/dist/core/events.d.ts +0 -16
  29. package/dist/core/events.js +0 -38
  30. package/dist/core/global/global.d.ts +0 -27
  31. package/dist/core/global/global.js +0 -72
  32. package/dist/core/global/globalControl.d.ts +0 -17
  33. package/dist/core/global/globalControl.js +0 -62
  34. package/dist/core/group.d.ts +0 -57
  35. package/dist/core/group.js +0 -157
  36. package/dist/core/line.d.ts +0 -13
  37. package/dist/core/line.js +0 -83
  38. package/dist/core/mesh.d.ts +0 -59
  39. package/dist/core/mesh.js +0 -180
  40. package/dist/core/model.d.ts +0 -30
  41. package/dist/core/model.js +0 -109
  42. package/dist/core/scene.d.ts +0 -175
  43. package/dist/core/scene.js +0 -381
  44. package/dist/core/use/useScene.d.ts +0 -10
  45. package/dist/core/use/useScene.js +0 -14
  46. package/dist/core/use/useframe.d.ts +0 -6
  47. package/dist/core/use/useframe.js +0 -11
  48. package/dist/export.d.ts +0 -40
  49. package/dist/export.js +0 -36
  50. package/dist/threeCell.d.ts +0 -8
  51. package/dist/threeCell.js +0 -16
  52. package/dist/type.d.ts +0 -3
  53. package/dist/type.js +0 -1
  54. package/dist/utils/createElement.d.ts +0 -103
  55. package/dist/utils/createElement.js +0 -145
  56. package/dist/utils/createLabel.d.ts +0 -2
  57. package/dist/utils/createLabel.js +0 -4
  58. package/dist/utils/line.d.ts +0 -0
  59. package/dist/utils/line.js +0 -0
  60. package/dist/utils/move.d.ts +0 -48
  61. package/dist/utils/move.js +0 -149
  62. package/examples/fonts/LICENSE +0 -13
  63. package/examples/fonts/README.md +0 -11
  64. package/examples/fonts/droid/NOTICE +0 -190
  65. package/examples/fonts/droid/README.txt +0 -18
  66. package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
  67. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
  68. package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
  69. package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
  70. package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
  71. package/examples/fonts/gentilis_bold.typeface.json +0 -1
  72. package/examples/fonts/gentilis_regular.typeface.json +0 -1
  73. package/examples/fonts/helvetiker_bold.typeface.json +0 -1
  74. package/examples/fonts/helvetiker_regular.typeface.json +0 -1
  75. package/examples/fonts/optimer_bold.typeface.json +0 -1
  76. package/examples/fonts/optimer_regular.typeface.json +0 -1
  77. package/examples/fonts/ttf/README.md +0 -9
  78. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  79. package/examples/jsm/animation/AnimationClipCreator.js +0 -116
  80. package/examples/jsm/animation/CCDIKSolver.js +0 -482
  81. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  82. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  83. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  84. package/examples/jsm/capabilities/WebGL.js +0 -91
  85. package/examples/jsm/capabilities/WebGPU.js +0 -53
  86. package/examples/jsm/controls/ArcballControls.js +0 -3224
  87. package/examples/jsm/controls/DragControls.js +0 -220
  88. package/examples/jsm/controls/FirstPersonControls.js +0 -325
  89. package/examples/jsm/controls/FlyControls.js +0 -300
  90. package/examples/jsm/controls/MapControls.js +0 -28
  91. package/examples/jsm/controls/OrbitControls.js +0 -1388
  92. package/examples/jsm/controls/PointerLockControls.js +0 -162
  93. package/examples/jsm/controls/TrackballControls.js +0 -828
  94. package/examples/jsm/controls/TransformControls.js +0 -1557
  95. package/examples/jsm/csm/CSM.js +0 -384
  96. package/examples/jsm/csm/CSMFrustum.js +0 -152
  97. package/examples/jsm/csm/CSMHelper.js +0 -193
  98. package/examples/jsm/csm/CSMShader.js +0 -252
  99. package/examples/jsm/curves/CurveExtras.js +0 -422
  100. package/examples/jsm/curves/NURBSCurve.js +0 -80
  101. package/examples/jsm/curves/NURBSSurface.js +0 -52
  102. package/examples/jsm/curves/NURBSUtils.js +0 -487
  103. package/examples/jsm/effects/AnaglyphEffect.js +0 -154
  104. package/examples/jsm/effects/AsciiEffect.js +0 -263
  105. package/examples/jsm/effects/OutlineEffect.js +0 -539
  106. package/examples/jsm/effects/ParallaxBarrierEffect.js +0 -119
  107. package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
  108. package/examples/jsm/effects/StereoEffect.js +0 -55
  109. package/examples/jsm/environments/DebugEnvironment.js +0 -52
  110. package/examples/jsm/environments/RoomEnvironment.js +0 -148
  111. package/examples/jsm/exporters/DRACOExporter.js +0 -267
  112. package/examples/jsm/exporters/EXRExporter.js +0 -501
  113. package/examples/jsm/exporters/GLTFExporter.js +0 -3161
  114. package/examples/jsm/exporters/KTX2Exporter.js +0 -292
  115. package/examples/jsm/exporters/MMDExporter.js +0 -217
  116. package/examples/jsm/exporters/OBJExporter.js +0 -284
  117. package/examples/jsm/exporters/PLYExporter.js +0 -528
  118. package/examples/jsm/exporters/STLExporter.js +0 -199
  119. package/examples/jsm/exporters/USDZExporter.js +0 -711
  120. package/examples/jsm/geometries/BoxLineGeometry.js +0 -69
  121. package/examples/jsm/geometries/ConvexGeometry.js +0 -53
  122. package/examples/jsm/geometries/DecalGeometry.js +0 -356
  123. package/examples/jsm/geometries/ParametricGeometries.js +0 -254
  124. package/examples/jsm/geometries/ParametricGeometry.js +0 -139
  125. package/examples/jsm/geometries/RoundedBoxGeometry.js +0 -155
  126. package/examples/jsm/geometries/TeapotGeometry.js +0 -704
  127. package/examples/jsm/geometries/TextGeometry.js +0 -57
  128. package/examples/jsm/helpers/LightProbeHelper.js +0 -130
  129. package/examples/jsm/helpers/OctreeHelper.js +0 -73
  130. package/examples/jsm/helpers/PositionalAudioHelper.js +0 -109
  131. package/examples/jsm/helpers/RectAreaLightHelper.js +0 -85
  132. package/examples/jsm/helpers/VertexNormalsHelper.js +0 -96
  133. package/examples/jsm/helpers/VertexTangentsHelper.js +0 -88
  134. package/examples/jsm/helpers/ViewHelper.js +0 -333
  135. package/examples/jsm/interactive/HTMLMesh.js +0 -565
  136. package/examples/jsm/interactive/InteractiveGroup.js +0 -116
  137. package/examples/jsm/interactive/SelectionBox.js +0 -227
  138. package/examples/jsm/interactive/SelectionHelper.js +0 -104
  139. package/examples/jsm/libs/ammo.wasm.js +0 -822
  140. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  141. package/examples/jsm/libs/basis/README.md +0 -46
  142. package/examples/jsm/libs/basis/basis_transcoder.js +0 -21
  143. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  144. package/examples/jsm/libs/chevrotain.module.min.js +0 -141
  145. package/examples/jsm/libs/draco/README.md +0 -32
  146. package/examples/jsm/libs/draco/draco_decoder.js +0 -34
  147. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  148. package/examples/jsm/libs/draco/draco_encoder.js +0 -33
  149. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +0 -117
  150. package/examples/jsm/libs/draco/gltf/draco_decoder.js +0 -33
  151. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  152. package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
  153. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +0 -116
  154. package/examples/jsm/libs/ecsy.module.js +0 -1792
  155. package/examples/jsm/libs/fflate.module.js +0 -2474
  156. package/examples/jsm/libs/ktx-parse.module.js +0 -1
  157. package/examples/jsm/libs/lil-gui.module.min.js +0 -8
  158. package/examples/jsm/libs/lottie_canvas.module.js +0 -14844
  159. package/examples/jsm/libs/meshopt_decoder.module.js +0 -178
  160. package/examples/jsm/libs/mikktspace.module.js +0 -128
  161. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  162. package/examples/jsm/libs/motion-controllers.module.js +0 -397
  163. package/examples/jsm/libs/opentype.module.js +0 -14568
  164. package/examples/jsm/libs/potpack.module.js +0 -125
  165. package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
  166. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
  167. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  168. package/examples/jsm/libs/stats.module.js +0 -167
  169. package/examples/jsm/libs/tween.module.js +0 -803
  170. package/examples/jsm/libs/utif.module.js +0 -1579
  171. package/examples/jsm/libs/zstddec.module.js +0 -1
  172. package/examples/jsm/lights/IESSpotLight.js +0 -25
  173. package/examples/jsm/lights/LightProbeGenerator.js +0 -252
  174. package/examples/jsm/lights/RectAreaLightUniformsLib.js +0 -79
  175. package/examples/jsm/lines/Line2.js +0 -19
  176. package/examples/jsm/lines/LineGeometry.js +0 -79
  177. package/examples/jsm/lines/LineMaterial.js +0 -702
  178. package/examples/jsm/lines/LineSegments2.js +0 -361
  179. package/examples/jsm/lines/LineSegmentsGeometry.js +0 -241
  180. package/examples/jsm/lines/Wireframe.js +0 -56
  181. package/examples/jsm/lines/WireframeGeometry2.js +0 -24
  182. package/examples/jsm/loaders/3DMLoader.js +0 -1497
  183. package/examples/jsm/loaders/3MFLoader.js +0 -1478
  184. package/examples/jsm/loaders/AMFLoader.js +0 -521
  185. package/examples/jsm/loaders/BVHLoader.js +0 -437
  186. package/examples/jsm/loaders/ColladaLoader.js +0 -4122
  187. package/examples/jsm/loaders/DDSLoader.js +0 -274
  188. package/examples/jsm/loaders/DRACOLoader.js +0 -612
  189. package/examples/jsm/loaders/EXRLoader.js +0 -2309
  190. package/examples/jsm/loaders/FBXLoader.js +0 -4142
  191. package/examples/jsm/loaders/FontLoader.js +0 -183
  192. package/examples/jsm/loaders/GCodeLoader.js +0 -261
  193. package/examples/jsm/loaders/GLTFLoader.js +0 -4576
  194. package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -115
  195. package/examples/jsm/loaders/IESLoader.js +0 -337
  196. package/examples/jsm/loaders/KMZLoader.js +0 -130
  197. package/examples/jsm/loaders/KTX2Loader.js +0 -868
  198. package/examples/jsm/loaders/KTXLoader.js +0 -176
  199. package/examples/jsm/loaders/LDrawLoader.js +0 -2464
  200. package/examples/jsm/loaders/LUT3dlLoader.js +0 -151
  201. package/examples/jsm/loaders/LUTCubeLoader.js +0 -153
  202. package/examples/jsm/loaders/LWOLoader.js +0 -1052
  203. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  204. package/examples/jsm/loaders/LottieLoader.js +0 -77
  205. package/examples/jsm/loaders/MD2Loader.js +0 -399
  206. package/examples/jsm/loaders/MDDLoader.js +0 -102
  207. package/examples/jsm/loaders/MMDLoader.js +0 -2273
  208. package/examples/jsm/loaders/MTLLoader.js +0 -567
  209. package/examples/jsm/loaders/MaterialXLoader.js +0 -734
  210. package/examples/jsm/loaders/NRRDLoader.js +0 -699
  211. package/examples/jsm/loaders/OBJLoader.js +0 -905
  212. package/examples/jsm/loaders/PCDLoader.js +0 -467
  213. package/examples/jsm/loaders/PDBLoader.js +0 -232
  214. package/examples/jsm/loaders/PLYLoader.js +0 -771
  215. package/examples/jsm/loaders/PVRLoader.js +0 -251
  216. package/examples/jsm/loaders/RGBELoader.js +0 -468
  217. package/examples/jsm/loaders/RGBMLoader.js +0 -1065
  218. package/examples/jsm/loaders/STLLoader.js +0 -403
  219. package/examples/jsm/loaders/SVGLoader.js +0 -3172
  220. package/examples/jsm/loaders/TDSLoader.js +0 -1124
  221. package/examples/jsm/loaders/TGALoader.js +0 -517
  222. package/examples/jsm/loaders/TIFFLoader.js +0 -36
  223. package/examples/jsm/loaders/TTFLoader.js +0 -214
  224. package/examples/jsm/loaders/TiltLoader.js +0 -520
  225. package/examples/jsm/loaders/USDZLoader.js +0 -633
  226. package/examples/jsm/loaders/VOXLoader.js +0 -311
  227. package/examples/jsm/loaders/VRMLLoader.js +0 -3533
  228. package/examples/jsm/loaders/VTKLoader.js +0 -1163
  229. package/examples/jsm/loaders/XYZLoader.js +0 -106
  230. package/examples/jsm/loaders/lwo/IFFParser.js +0 -1218
  231. package/examples/jsm/loaders/lwo/LWO2Parser.js +0 -414
  232. package/examples/jsm/loaders/lwo/LWO3Parser.js +0 -373
  233. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -420
  234. package/examples/jsm/math/Capsule.js +0 -137
  235. package/examples/jsm/math/ColorConverter.js +0 -36
  236. package/examples/jsm/math/ConvexHull.js +0 -1271
  237. package/examples/jsm/math/ImprovedNoise.js +0 -71
  238. package/examples/jsm/math/Lut.js +0 -204
  239. package/examples/jsm/math/MeshSurfaceSampler.js +0 -250
  240. package/examples/jsm/math/OBB.js +0 -423
  241. package/examples/jsm/math/Octree.js +0 -462
  242. package/examples/jsm/math/SimplexNoise.js +0 -444
  243. package/examples/jsm/misc/ConvexObjectBreaker.js +0 -519
  244. package/examples/jsm/misc/GPUComputationRenderer.js +0 -446
  245. package/examples/jsm/misc/Gyroscope.js +0 -66
  246. package/examples/jsm/misc/MD2Character.js +0 -276
  247. package/examples/jsm/misc/MD2CharacterComplex.js +0 -576
  248. package/examples/jsm/misc/MorphAnimMesh.js +0 -75
  249. package/examples/jsm/misc/MorphBlendMesh.js +0 -322
  250. package/examples/jsm/misc/ProgressiveLightMap.js +0 -323
  251. package/examples/jsm/misc/RollerCoaster.js +0 -566
  252. package/examples/jsm/misc/TubePainter.js +0 -205
  253. package/examples/jsm/misc/Volume.js +0 -473
  254. package/examples/jsm/misc/VolumeSlice.js +0 -229
  255. package/examples/jsm/modifiers/CurveModifier.js +0 -326
  256. package/examples/jsm/modifiers/EdgeSplitModifier.js +0 -279
  257. package/examples/jsm/modifiers/SimplifyModifier.js +0 -525
  258. package/examples/jsm/modifiers/TessellateModifier.js +0 -307
  259. package/examples/jsm/nodes/Nodes.js +0 -171
  260. package/examples/jsm/nodes/accessors/BitangentNode.js +0 -89
  261. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +0 -99
  262. package/examples/jsm/nodes/accessors/BufferNode.js +0 -30
  263. package/examples/jsm/nodes/accessors/CameraNode.js +0 -98
  264. package/examples/jsm/nodes/accessors/CubeTextureNode.js +0 -103
  265. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -77
  266. package/examples/jsm/nodes/accessors/InstanceNode.js +0 -71
  267. package/examples/jsm/nodes/accessors/MaterialNode.js +0 -267
  268. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +0 -39
  269. package/examples/jsm/nodes/accessors/ModelNode.js +0 -34
  270. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +0 -29
  271. package/examples/jsm/nodes/accessors/MorphNode.js +0 -70
  272. package/examples/jsm/nodes/accessors/NormalNode.js +0 -96
  273. package/examples/jsm/nodes/accessors/Object3DNode.js +0 -150
  274. package/examples/jsm/nodes/accessors/PointUVNode.js +0 -26
  275. package/examples/jsm/nodes/accessors/PositionNode.js +0 -104
  276. package/examples/jsm/nodes/accessors/ReferenceNode.js +0 -72
  277. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +0 -35
  278. package/examples/jsm/nodes/accessors/SceneNode.js +0 -52
  279. package/examples/jsm/nodes/accessors/SkinningNode.js +0 -93
  280. package/examples/jsm/nodes/accessors/StorageBufferNode.js +0 -27
  281. package/examples/jsm/nodes/accessors/TangentNode.js +0 -103
  282. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +0 -94
  283. package/examples/jsm/nodes/accessors/TextureNode.js +0 -271
  284. package/examples/jsm/nodes/accessors/TextureSizeNode.js +0 -35
  285. package/examples/jsm/nodes/accessors/UVNode.js +0 -47
  286. package/examples/jsm/nodes/accessors/UserDataNode.js +0 -29
  287. package/examples/jsm/nodes/code/CodeNode.js +0 -78
  288. package/examples/jsm/nodes/code/ExpressionNode.js +0 -37
  289. package/examples/jsm/nodes/code/FunctionCallNode.js +0 -96
  290. package/examples/jsm/nodes/code/FunctionNode.js +0 -127
  291. package/examples/jsm/nodes/code/ScriptableNode.js +0 -488
  292. package/examples/jsm/nodes/code/ScriptableValueNode.js +0 -167
  293. package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
  294. package/examples/jsm/nodes/core/AttributeNode.js +0 -102
  295. package/examples/jsm/nodes/core/BypassNode.js +0 -45
  296. package/examples/jsm/nodes/core/CacheNode.js +0 -46
  297. package/examples/jsm/nodes/core/ConstNode.js +0 -32
  298. package/examples/jsm/nodes/core/ContextNode.js +0 -61
  299. package/examples/jsm/nodes/core/IndexNode.js +0 -66
  300. package/examples/jsm/nodes/core/InputNode.js +0 -83
  301. package/examples/jsm/nodes/core/LightingModel.js +0 -15
  302. package/examples/jsm/nodes/core/Node.js +0 -454
  303. package/examples/jsm/nodes/core/NodeAttribute.js +0 -15
  304. package/examples/jsm/nodes/core/NodeBuilder.js +0 -1016
  305. package/examples/jsm/nodes/core/NodeCache.js +0 -26
  306. package/examples/jsm/nodes/core/NodeCode.js +0 -15
  307. package/examples/jsm/nodes/core/NodeFrame.js +0 -110
  308. package/examples/jsm/nodes/core/NodeFunction.js +0 -22
  309. package/examples/jsm/nodes/core/NodeFunctionInput.js +0 -17
  310. package/examples/jsm/nodes/core/NodeKeywords.js +0 -80
  311. package/examples/jsm/nodes/core/NodeParser.js +0 -11
  312. package/examples/jsm/nodes/core/NodeUniform.js +0 -28
  313. package/examples/jsm/nodes/core/NodeUtils.js +0 -212
  314. package/examples/jsm/nodes/core/NodeVar.js +0 -14
  315. package/examples/jsm/nodes/core/NodeVarying.js +0 -17
  316. package/examples/jsm/nodes/core/PropertyNode.js +0 -61
  317. package/examples/jsm/nodes/core/StackNode.js +0 -99
  318. package/examples/jsm/nodes/core/TempNode.js +0 -58
  319. package/examples/jsm/nodes/core/UniformNode.js +0 -61
  320. package/examples/jsm/nodes/core/VarNode.js +0 -87
  321. package/examples/jsm/nodes/core/VaryingNode.js +0 -69
  322. package/examples/jsm/nodes/core/constants.js +0 -27
  323. package/examples/jsm/nodes/display/BlendModeNode.js +0 -99
  324. package/examples/jsm/nodes/display/BumpMapNode.js +0 -77
  325. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +0 -100
  326. package/examples/jsm/nodes/display/ColorSpaceNode.js +0 -108
  327. package/examples/jsm/nodes/display/FrontFacingNode.js +0 -27
  328. package/examples/jsm/nodes/display/NormalMapNode.js +0 -106
  329. package/examples/jsm/nodes/display/PosterizeNode.js +0 -32
  330. package/examples/jsm/nodes/display/ToneMappingNode.js +0 -141
  331. package/examples/jsm/nodes/display/ViewportDepthNode.js +0 -69
  332. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +0 -34
  333. package/examples/jsm/nodes/display/ViewportNode.js +0 -115
  334. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +0 -31
  335. package/examples/jsm/nodes/display/ViewportTextureNode.js +0 -75
  336. package/examples/jsm/nodes/fog/FogExp2Node.js +0 -35
  337. package/examples/jsm/nodes/fog/FogNode.js +0 -37
  338. package/examples/jsm/nodes/fog/FogRangeNode.js +0 -34
  339. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +0 -40
  340. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +0 -9
  341. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +0 -43
  342. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +0 -29
  343. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +0 -18
  344. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +0 -13
  345. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +0 -16
  346. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +0 -13
  347. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +0 -20
  348. package/examples/jsm/nodes/functions/PhongLightingModel.js +0 -67
  349. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +0 -343
  350. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +0 -13
  351. package/examples/jsm/nodes/functions/material/getRoughness.js +0 -18
  352. package/examples/jsm/nodes/geometry/RangeNode.js +0 -104
  353. package/examples/jsm/nodes/gpgpu/ComputeNode.js +0 -85
  354. package/examples/jsm/nodes/lighting/AONode.js +0 -27
  355. package/examples/jsm/nodes/lighting/AmbientLightNode.js +0 -27
  356. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +0 -184
  357. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +0 -40
  358. package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -191
  359. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +0 -55
  360. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +0 -39
  361. package/examples/jsm/nodes/lighting/LightNode.js +0 -57
  362. package/examples/jsm/nodes/lighting/LightUtils.js +0 -17
  363. package/examples/jsm/nodes/lighting/LightingContextNode.js +0 -102
  364. package/examples/jsm/nodes/lighting/LightingNode.js +0 -21
  365. package/examples/jsm/nodes/lighting/LightsNode.js +0 -128
  366. package/examples/jsm/nodes/lighting/PointLightNode.js +0 -68
  367. package/examples/jsm/nodes/lighting/SpotLightNode.js +0 -89
  368. package/examples/jsm/nodes/loaders/NodeLoader.js +0 -108
  369. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +0 -59
  370. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +0 -70
  371. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -28
  372. package/examples/jsm/nodes/materials/Materials.js +0 -12
  373. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -27
  374. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +0 -34
  375. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  376. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -65
  377. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +0 -128
  378. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +0 -80
  379. package/examples/jsm/nodes/materials/NodeMaterial.js +0 -536
  380. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -49
  381. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -103
  382. package/examples/jsm/nodes/materialx/DISCLAIMER.md +0 -199
  383. package/examples/jsm/nodes/materialx/MaterialXNodes.js +0 -68
  384. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +0 -56
  385. package/examples/jsm/nodes/materialx/lib/mx_noise.js +0 -618
  386. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +0 -19
  387. package/examples/jsm/nodes/math/CondNode.js +0 -86
  388. package/examples/jsm/nodes/math/MathNode.js +0 -359
  389. package/examples/jsm/nodes/math/OperatorNode.js +0 -269
  390. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +0 -152
  391. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +0 -14
  392. package/examples/jsm/nodes/procedural/CheckerNode.js +0 -42
  393. package/examples/jsm/nodes/shadernode/ShaderNode.js +0 -420
  394. package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -33
  395. package/examples/jsm/nodes/utils/ConvertNode.js +0 -65
  396. package/examples/jsm/nodes/utils/DiscardNode.js +0 -26
  397. package/examples/jsm/nodes/utils/EquirectUVNode.js +0 -33
  398. package/examples/jsm/nodes/utils/JoinNode.js +0 -51
  399. package/examples/jsm/nodes/utils/LoopNode.js +0 -186
  400. package/examples/jsm/nodes/utils/MatcapUVNode.js +0 -30
  401. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +0 -46
  402. package/examples/jsm/nodes/utils/OscNode.js +0 -81
  403. package/examples/jsm/nodes/utils/PackingNode.js +0 -55
  404. package/examples/jsm/nodes/utils/RemapNode.js +0 -42
  405. package/examples/jsm/nodes/utils/RotateUVNode.js +0 -43
  406. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  407. package/examples/jsm/nodes/utils/SplitNode.js +0 -104
  408. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +0 -41
  409. package/examples/jsm/nodes/utils/TimerNode.js +0 -94
  410. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +0 -62
  411. package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
  412. package/examples/jsm/objects/Lensflare.js +0 -377
  413. package/examples/jsm/objects/MarchingCubes.js +0 -1176
  414. package/examples/jsm/objects/Reflector.js +0 -264
  415. package/examples/jsm/objects/ReflectorForSSRPass.js +0 -349
  416. package/examples/jsm/objects/Refractor.js +0 -324
  417. package/examples/jsm/objects/ShadowMesh.js +0 -80
  418. package/examples/jsm/objects/Sky.js +0 -219
  419. package/examples/jsm/objects/Water.js +0 -330
  420. package/examples/jsm/objects/Water2.js +0 -358
  421. package/examples/jsm/offscreen/jank.js +0 -45
  422. package/examples/jsm/offscreen/offscreen.js +0 -8
  423. package/examples/jsm/offscreen/scene.js +0 -86
  424. package/examples/jsm/physics/AmmoPhysics.js +0 -285
  425. package/examples/jsm/physics/RapierPhysics.js +0 -199
  426. package/examples/jsm/postprocessing/AfterimagePass.js +0 -104
  427. package/examples/jsm/postprocessing/BloomPass.js +0 -172
  428. package/examples/jsm/postprocessing/BokehPass.js +0 -140
  429. package/examples/jsm/postprocessing/ClearPass.js +0 -46
  430. package/examples/jsm/postprocessing/CubeTexturePass.js +0 -85
  431. package/examples/jsm/postprocessing/DotScreenPass.js +0 -65
  432. package/examples/jsm/postprocessing/EffectComposer.js +0 -231
  433. package/examples/jsm/postprocessing/FilmPass.js +0 -66
  434. package/examples/jsm/postprocessing/GlitchPass.js +0 -128
  435. package/examples/jsm/postprocessing/HalftonePass.js +0 -79
  436. package/examples/jsm/postprocessing/LUTPass.js +0 -173
  437. package/examples/jsm/postprocessing/MaskPass.js +0 -104
  438. package/examples/jsm/postprocessing/OutlinePass.js +0 -654
  439. package/examples/jsm/postprocessing/OutputPass.js +0 -91
  440. package/examples/jsm/postprocessing/Pass.js +0 -84
  441. package/examples/jsm/postprocessing/RenderPass.js +0 -81
  442. package/examples/jsm/postprocessing/RenderPixelatedPass.js +0 -235
  443. package/examples/jsm/postprocessing/SAOPass.js +0 -411
  444. package/examples/jsm/postprocessing/SMAAPass.js +0 -201
  445. package/examples/jsm/postprocessing/SSAARenderPass.js +0 -228
  446. package/examples/jsm/postprocessing/SSAOPass.js +0 -440
  447. package/examples/jsm/postprocessing/SSRPass.js +0 -641
  448. package/examples/jsm/postprocessing/SavePass.js +0 -79
  449. package/examples/jsm/postprocessing/ShaderPass.js +0 -77
  450. package/examples/jsm/postprocessing/TAARenderPass.js +0 -189
  451. package/examples/jsm/postprocessing/TexturePass.js +0 -67
  452. package/examples/jsm/postprocessing/UnrealBloomPass.js +0 -415
  453. package/examples/jsm/renderers/CSS2DRenderer.js +0 -215
  454. package/examples/jsm/renderers/CSS3DRenderer.js +0 -335
  455. package/examples/jsm/renderers/Projector.js +0 -918
  456. package/examples/jsm/renderers/SVGRenderer.js +0 -553
  457. package/examples/jsm/renderers/common/Animation.js +0 -58
  458. package/examples/jsm/renderers/common/Attributes.js +0 -75
  459. package/examples/jsm/renderers/common/Backend.js +0 -162
  460. package/examples/jsm/renderers/common/Background.js +0 -136
  461. package/examples/jsm/renderers/common/Binding.js +0 -19
  462. package/examples/jsm/renderers/common/Bindings.js +0 -165
  463. package/examples/jsm/renderers/common/Buffer.js +0 -38
  464. package/examples/jsm/renderers/common/BufferUtils.js +0 -33
  465. package/examples/jsm/renderers/common/ChainMap.js +0 -89
  466. package/examples/jsm/renderers/common/ComputePipeline.js +0 -17
  467. package/examples/jsm/renderers/common/Constants.js +0 -14
  468. package/examples/jsm/renderers/common/CubeRenderTarget.js +0 -65
  469. package/examples/jsm/renderers/common/DataMap.js +0 -54
  470. package/examples/jsm/renderers/common/Geometries.js +0 -215
  471. package/examples/jsm/renderers/common/Info.js +0 -73
  472. package/examples/jsm/renderers/common/Pipeline.js +0 -13
  473. package/examples/jsm/renderers/common/Pipelines.js +0 -370
  474. package/examples/jsm/renderers/common/ProgrammableStage.js +0 -18
  475. package/examples/jsm/renderers/common/RenderContext.js +0 -38
  476. package/examples/jsm/renderers/common/RenderContexts.js +0 -49
  477. package/examples/jsm/renderers/common/RenderList.js +0 -178
  478. package/examples/jsm/renderers/common/RenderLists.js +0 -38
  479. package/examples/jsm/renderers/common/RenderObject.js +0 -129
  480. package/examples/jsm/renderers/common/RenderObjects.js +0 -95
  481. package/examples/jsm/renderers/common/RenderPipeline.js +0 -16
  482. package/examples/jsm/renderers/common/Renderer.js +0 -895
  483. package/examples/jsm/renderers/common/SampledTexture.js +0 -80
  484. package/examples/jsm/renderers/common/Sampler.js +0 -18
  485. package/examples/jsm/renderers/common/StorageBuffer.js +0 -17
  486. package/examples/jsm/renderers/common/Textures.js +0 -218
  487. package/examples/jsm/renderers/common/Uniform.js +0 -140
  488. package/examples/jsm/renderers/common/UniformBuffer.js +0 -15
  489. package/examples/jsm/renderers/common/UniformsGroup.js +0 -299
  490. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +0 -39
  491. package/examples/jsm/renderers/common/nodes/NodeSampler.js +0 -21
  492. package/examples/jsm/renderers/common/nodes/NodeUniform.js +0 -135
  493. package/examples/jsm/renderers/common/nodes/Nodes.js +0 -330
  494. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +0 -340
  495. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +0 -26
  496. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +0 -764
  497. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +0 -49
  498. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +0 -844
  499. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +0 -32
  500. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +0 -902
  501. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +0 -104
  502. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +0 -14
  503. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +0 -274
  504. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +0 -223
  505. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +0 -324
  506. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +0 -533
  507. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
  508. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +0 -964
  509. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +0 -92
  510. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +0 -87
  511. package/examples/jsm/shaders/AfterimageShader.js +0 -56
  512. package/examples/jsm/shaders/BasicShader.js +0 -27
  513. package/examples/jsm/shaders/BleachBypassShader.js +0 -62
  514. package/examples/jsm/shaders/BlendShader.js +0 -47
  515. package/examples/jsm/shaders/BokehShader.js +0 -143
  516. package/examples/jsm/shaders/BokehShader2.js +0 -393
  517. package/examples/jsm/shaders/BrightnessContrastShader.js +0 -54
  518. package/examples/jsm/shaders/ColorCorrectionShader.js +0 -50
  519. package/examples/jsm/shaders/ColorifyShader.js +0 -51
  520. package/examples/jsm/shaders/ConvolutionShader.js +0 -103
  521. package/examples/jsm/shaders/CopyShader.js +0 -45
  522. package/examples/jsm/shaders/DOFMipMapShader.js +0 -54
  523. package/examples/jsm/shaders/DepthLimitedBlurShader.js +0 -166
  524. package/examples/jsm/shaders/DigitalGlitch.js +0 -101
  525. package/examples/jsm/shaders/DotScreenShader.js +0 -70
  526. package/examples/jsm/shaders/ExposureShader.js +0 -44
  527. package/examples/jsm/shaders/FXAAShader.js +0 -286
  528. package/examples/jsm/shaders/FilmShader.js +0 -102
  529. package/examples/jsm/shaders/FocusShader.js +0 -87
  530. package/examples/jsm/shaders/FreiChenShader.js +0 -94
  531. package/examples/jsm/shaders/GammaCorrectionShader.js +0 -43
  532. package/examples/jsm/shaders/GodRaysShader.js +0 -313
  533. package/examples/jsm/shaders/HalftoneShader.js +0 -310
  534. package/examples/jsm/shaders/HorizontalBlurShader.js +0 -59
  535. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +0 -61
  536. package/examples/jsm/shaders/HueSaturationShader.js +0 -65
  537. package/examples/jsm/shaders/KaleidoShader.js +0 -56
  538. package/examples/jsm/shaders/LuminosityHighPassShader.js +0 -64
  539. package/examples/jsm/shaders/LuminosityShader.js +0 -46
  540. package/examples/jsm/shaders/MMDToonShader.js +0 -132
  541. package/examples/jsm/shaders/MirrorShader.js +0 -54
  542. package/examples/jsm/shaders/NormalMapShader.js +0 -53
  543. package/examples/jsm/shaders/OutputShader.js +0 -78
  544. package/examples/jsm/shaders/RGBShiftShader.js +0 -54
  545. package/examples/jsm/shaders/SAOShader.js +0 -188
  546. package/examples/jsm/shaders/SMAAShader.js +0 -460
  547. package/examples/jsm/shaders/SSAOShader.js +0 -288
  548. package/examples/jsm/shaders/SSRShader.js +0 -364
  549. package/examples/jsm/shaders/SepiaShader.js +0 -52
  550. package/examples/jsm/shaders/SobelOperatorShader.js +0 -90
  551. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +0 -88
  552. package/examples/jsm/shaders/TechnicolorShader.js +0 -43
  553. package/examples/jsm/shaders/ToonShader.js +0 -326
  554. package/examples/jsm/shaders/TriangleBlurShader.js +0 -72
  555. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +0 -45
  556. package/examples/jsm/shaders/VelocityShader.js +0 -128
  557. package/examples/jsm/shaders/VerticalBlurShader.js +0 -59
  558. package/examples/jsm/shaders/VerticalTiltShiftShader.js +0 -61
  559. package/examples/jsm/shaders/VignetteShader.js +0 -51
  560. package/examples/jsm/shaders/VolumeShader.js +0 -289
  561. package/examples/jsm/shaders/WaterRefractionShader.js +0 -93
  562. package/examples/jsm/textures/FlakesTexture.js +0 -40
  563. package/examples/jsm/utils/BufferGeometryUtils.js +0 -1373
  564. package/examples/jsm/utils/CameraUtils.js +0 -73
  565. package/examples/jsm/utils/GPUStatsPanel.js +0 -128
  566. package/examples/jsm/utils/GeometryCompressionUtils.js +0 -639
  567. package/examples/jsm/utils/GeometryUtils.js +0 -221
  568. package/examples/jsm/utils/LDrawUtils.js +0 -202
  569. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  570. package/examples/jsm/utils/SceneUtils.js +0 -254
  571. package/examples/jsm/utils/ShadowMapViewer.js +0 -210
  572. package/examples/jsm/utils/SkeletonUtils.js +0 -413
  573. package/examples/jsm/utils/TextureUtils.js +0 -86
  574. package/examples/jsm/utils/UVsDebug.js +0 -165
  575. package/examples/jsm/utils/WorkerPool.js +0 -102
  576. package/examples/jsm/webxr/ARButton.js +0 -208
  577. package/examples/jsm/webxr/OculusHandModel.js +0 -109
  578. package/examples/jsm/webxr/OculusHandPointerModel.js +0 -413
  579. package/examples/jsm/webxr/Text2D.js +0 -38
  580. package/examples/jsm/webxr/VRButton.js +0 -200
  581. package/examples/jsm/webxr/XRButton.js +0 -198
  582. package/examples/jsm/webxr/XRControllerModelFactory.js +0 -299
  583. package/examples/jsm/webxr/XREstimatedLight.js +0 -223
  584. package/examples/jsm/webxr/XRHandMeshModel.js +0 -112
  585. package/examples/jsm/webxr/XRHandModelFactory.js +0 -105
  586. package/examples/jsm/webxr/XRHandPrimitiveModel.js +0 -103
  587. package/examples/jsm/webxr/XRPlanes.js +0 -100
  588. package/lib/3d.min.js +0 -1
@@ -1,3172 +0,0 @@
1
- import {
2
- Box2,
3
- BufferGeometry,
4
- FileLoader,
5
- Float32BufferAttribute,
6
- Loader,
7
- Matrix3,
8
- Path,
9
- Shape,
10
- ShapePath,
11
- ShapeUtils,
12
- SRGBColorSpace,
13
- Vector2,
14
- Vector3
15
- } from 'three';
16
-
17
- const COLOR_SPACE_SVG = SRGBColorSpace;
18
-
19
- class SVGLoader extends Loader {
20
-
21
- constructor( manager ) {
22
-
23
- super( manager );
24
-
25
- // Default dots per inch
26
- this.defaultDPI = 90;
27
-
28
- // Accepted units: 'mm', 'cm', 'in', 'pt', 'pc', 'px'
29
- this.defaultUnit = 'px';
30
-
31
- }
32
-
33
- load( url, onLoad, onProgress, onError ) {
34
-
35
- const scope = this;
36
-
37
- const loader = new FileLoader( scope.manager );
38
- loader.setPath( scope.path );
39
- loader.setRequestHeader( scope.requestHeader );
40
- loader.setWithCredentials( scope.withCredentials );
41
- loader.load( url, function ( text ) {
42
-
43
- try {
44
-
45
- onLoad( scope.parse( text ) );
46
-
47
- } catch ( e ) {
48
-
49
- if ( onError ) {
50
-
51
- onError( e );
52
-
53
- } else {
54
-
55
- console.error( e );
56
-
57
- }
58
-
59
- scope.manager.itemError( url );
60
-
61
- }
62
-
63
- }, onProgress, onError );
64
-
65
- }
66
-
67
- parse( text ) {
68
-
69
- const scope = this;
70
-
71
- function parseNode( node, style ) {
72
-
73
- if ( node.nodeType !== 1 ) return;
74
-
75
- const transform = getNodeTransform( node );
76
-
77
- let isDefsNode = false;
78
-
79
- let path = null;
80
-
81
- switch ( node.nodeName ) {
82
-
83
- case 'svg':
84
- style = parseStyle( node, style );
85
- break;
86
-
87
- case 'style':
88
- parseCSSStylesheet( node );
89
- break;
90
-
91
- case 'g':
92
- style = parseStyle( node, style );
93
- break;
94
-
95
- case 'path':
96
- style = parseStyle( node, style );
97
- if ( node.hasAttribute( 'd' ) ) path = parsePathNode( node );
98
- break;
99
-
100
- case 'rect':
101
- style = parseStyle( node, style );
102
- path = parseRectNode( node );
103
- break;
104
-
105
- case 'polygon':
106
- style = parseStyle( node, style );
107
- path = parsePolygonNode( node );
108
- break;
109
-
110
- case 'polyline':
111
- style = parseStyle( node, style );
112
- path = parsePolylineNode( node );
113
- break;
114
-
115
- case 'circle':
116
- style = parseStyle( node, style );
117
- path = parseCircleNode( node );
118
- break;
119
-
120
- case 'ellipse':
121
- style = parseStyle( node, style );
122
- path = parseEllipseNode( node );
123
- break;
124
-
125
- case 'line':
126
- style = parseStyle( node, style );
127
- path = parseLineNode( node );
128
- break;
129
-
130
- case 'defs':
131
- isDefsNode = true;
132
- break;
133
-
134
- case 'use':
135
- style = parseStyle( node, style );
136
-
137
- const href = node.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || '';
138
- const usedNodeId = href.substring( 1 );
139
- const usedNode = node.viewportElement.getElementById( usedNodeId );
140
- if ( usedNode ) {
141
-
142
- parseNode( usedNode, style );
143
-
144
- } else {
145
-
146
- console.warn( 'SVGLoader: \'use node\' references non-existent node id: ' + usedNodeId );
147
-
148
- }
149
-
150
- break;
151
-
152
- default:
153
- // console.log( node );
154
-
155
- }
156
-
157
- if ( path ) {
158
-
159
- if ( style.fill !== undefined && style.fill !== 'none' ) {
160
-
161
- path.color.setStyle( style.fill, COLOR_SPACE_SVG );
162
-
163
- }
164
-
165
- transformPath( path, currentTransform );
166
-
167
- paths.push( path );
168
-
169
- path.userData = { node: node, style: style };
170
-
171
- }
172
-
173
- const childNodes = node.childNodes;
174
-
175
- for ( let i = 0; i < childNodes.length; i ++ ) {
176
-
177
- const node = childNodes[ i ];
178
-
179
- if ( isDefsNode && node.nodeName !== 'style' && node.nodeName !== 'defs' ) {
180
-
181
- // Ignore everything in defs except CSS style definitions
182
- // and nested defs, because it is OK by the standard to have
183
- // <style/> there.
184
- continue;
185
-
186
- }
187
-
188
- parseNode( node, style );
189
-
190
- }
191
-
192
-
193
- if ( transform ) {
194
-
195
- transformStack.pop();
196
-
197
- if ( transformStack.length > 0 ) {
198
-
199
- currentTransform.copy( transformStack[ transformStack.length - 1 ] );
200
-
201
- } else {
202
-
203
- currentTransform.identity();
204
-
205
- }
206
-
207
- }
208
-
209
- }
210
-
211
- function parsePathNode( node ) {
212
-
213
- const path = new ShapePath();
214
-
215
- const point = new Vector2();
216
- const control = new Vector2();
217
-
218
- const firstPoint = new Vector2();
219
- let isFirstPoint = true;
220
- let doSetFirstPoint = false;
221
-
222
- const d = node.getAttribute( 'd' );
223
-
224
- if ( d === '' || d === 'none' ) return null;
225
-
226
- // console.log( d );
227
-
228
- const commands = d.match( /[a-df-z][^a-df-z]*/ig );
229
-
230
- for ( let i = 0, l = commands.length; i < l; i ++ ) {
231
-
232
- const command = commands[ i ];
233
-
234
- const type = command.charAt( 0 );
235
- const data = command.slice( 1 ).trim();
236
-
237
- if ( isFirstPoint === true ) {
238
-
239
- doSetFirstPoint = true;
240
- isFirstPoint = false;
241
-
242
- }
243
-
244
- let numbers;
245
-
246
- switch ( type ) {
247
-
248
- case 'M':
249
- numbers = parseFloats( data );
250
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
251
-
252
- point.x = numbers[ j + 0 ];
253
- point.y = numbers[ j + 1 ];
254
- control.x = point.x;
255
- control.y = point.y;
256
-
257
- if ( j === 0 ) {
258
-
259
- path.moveTo( point.x, point.y );
260
-
261
- } else {
262
-
263
- path.lineTo( point.x, point.y );
264
-
265
- }
266
-
267
- if ( j === 0 ) firstPoint.copy( point );
268
-
269
- }
270
-
271
- break;
272
-
273
- case 'H':
274
- numbers = parseFloats( data );
275
-
276
- for ( let j = 0, jl = numbers.length; j < jl; j ++ ) {
277
-
278
- point.x = numbers[ j ];
279
- control.x = point.x;
280
- control.y = point.y;
281
- path.lineTo( point.x, point.y );
282
-
283
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
284
-
285
- }
286
-
287
- break;
288
-
289
- case 'V':
290
- numbers = parseFloats( data );
291
-
292
- for ( let j = 0, jl = numbers.length; j < jl; j ++ ) {
293
-
294
- point.y = numbers[ j ];
295
- control.x = point.x;
296
- control.y = point.y;
297
- path.lineTo( point.x, point.y );
298
-
299
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
300
-
301
- }
302
-
303
- break;
304
-
305
- case 'L':
306
- numbers = parseFloats( data );
307
-
308
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
309
-
310
- point.x = numbers[ j + 0 ];
311
- point.y = numbers[ j + 1 ];
312
- control.x = point.x;
313
- control.y = point.y;
314
- path.lineTo( point.x, point.y );
315
-
316
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
317
-
318
- }
319
-
320
- break;
321
-
322
- case 'C':
323
- numbers = parseFloats( data );
324
-
325
- for ( let j = 0, jl = numbers.length; j < jl; j += 6 ) {
326
-
327
- path.bezierCurveTo(
328
- numbers[ j + 0 ],
329
- numbers[ j + 1 ],
330
- numbers[ j + 2 ],
331
- numbers[ j + 3 ],
332
- numbers[ j + 4 ],
333
- numbers[ j + 5 ]
334
- );
335
- control.x = numbers[ j + 2 ];
336
- control.y = numbers[ j + 3 ];
337
- point.x = numbers[ j + 4 ];
338
- point.y = numbers[ j + 5 ];
339
-
340
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
341
-
342
- }
343
-
344
- break;
345
-
346
- case 'S':
347
- numbers = parseFloats( data );
348
-
349
- for ( let j = 0, jl = numbers.length; j < jl; j += 4 ) {
350
-
351
- path.bezierCurveTo(
352
- getReflection( point.x, control.x ),
353
- getReflection( point.y, control.y ),
354
- numbers[ j + 0 ],
355
- numbers[ j + 1 ],
356
- numbers[ j + 2 ],
357
- numbers[ j + 3 ]
358
- );
359
- control.x = numbers[ j + 0 ];
360
- control.y = numbers[ j + 1 ];
361
- point.x = numbers[ j + 2 ];
362
- point.y = numbers[ j + 3 ];
363
-
364
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
365
-
366
- }
367
-
368
- break;
369
-
370
- case 'Q':
371
- numbers = parseFloats( data );
372
-
373
- for ( let j = 0, jl = numbers.length; j < jl; j += 4 ) {
374
-
375
- path.quadraticCurveTo(
376
- numbers[ j + 0 ],
377
- numbers[ j + 1 ],
378
- numbers[ j + 2 ],
379
- numbers[ j + 3 ]
380
- );
381
- control.x = numbers[ j + 0 ];
382
- control.y = numbers[ j + 1 ];
383
- point.x = numbers[ j + 2 ];
384
- point.y = numbers[ j + 3 ];
385
-
386
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
387
-
388
- }
389
-
390
- break;
391
-
392
- case 'T':
393
- numbers = parseFloats( data );
394
-
395
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
396
-
397
- const rx = getReflection( point.x, control.x );
398
- const ry = getReflection( point.y, control.y );
399
- path.quadraticCurveTo(
400
- rx,
401
- ry,
402
- numbers[ j + 0 ],
403
- numbers[ j + 1 ]
404
- );
405
- control.x = rx;
406
- control.y = ry;
407
- point.x = numbers[ j + 0 ];
408
- point.y = numbers[ j + 1 ];
409
-
410
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
411
-
412
- }
413
-
414
- break;
415
-
416
- case 'A':
417
- numbers = parseFloats( data, [ 3, 4 ], 7 );
418
-
419
- for ( let j = 0, jl = numbers.length; j < jl; j += 7 ) {
420
-
421
- // skip command if start point == end point
422
- if ( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue;
423
-
424
- const start = point.clone();
425
- point.x = numbers[ j + 5 ];
426
- point.y = numbers[ j + 6 ];
427
- control.x = point.x;
428
- control.y = point.y;
429
- parseArcCommand(
430
- path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
431
- );
432
-
433
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
434
-
435
- }
436
-
437
- break;
438
-
439
- case 'm':
440
- numbers = parseFloats( data );
441
-
442
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
443
-
444
- point.x += numbers[ j + 0 ];
445
- point.y += numbers[ j + 1 ];
446
- control.x = point.x;
447
- control.y = point.y;
448
-
449
- if ( j === 0 ) {
450
-
451
- path.moveTo( point.x, point.y );
452
-
453
- } else {
454
-
455
- path.lineTo( point.x, point.y );
456
-
457
- }
458
-
459
- if ( j === 0 ) firstPoint.copy( point );
460
-
461
- }
462
-
463
- break;
464
-
465
- case 'h':
466
- numbers = parseFloats( data );
467
-
468
- for ( let j = 0, jl = numbers.length; j < jl; j ++ ) {
469
-
470
- point.x += numbers[ j ];
471
- control.x = point.x;
472
- control.y = point.y;
473
- path.lineTo( point.x, point.y );
474
-
475
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
476
-
477
- }
478
-
479
- break;
480
-
481
- case 'v':
482
- numbers = parseFloats( data );
483
-
484
- for ( let j = 0, jl = numbers.length; j < jl; j ++ ) {
485
-
486
- point.y += numbers[ j ];
487
- control.x = point.x;
488
- control.y = point.y;
489
- path.lineTo( point.x, point.y );
490
-
491
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
492
-
493
- }
494
-
495
- break;
496
-
497
- case 'l':
498
- numbers = parseFloats( data );
499
-
500
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
501
-
502
- point.x += numbers[ j + 0 ];
503
- point.y += numbers[ j + 1 ];
504
- control.x = point.x;
505
- control.y = point.y;
506
- path.lineTo( point.x, point.y );
507
-
508
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
509
-
510
- }
511
-
512
- break;
513
-
514
- case 'c':
515
- numbers = parseFloats( data );
516
-
517
- for ( let j = 0, jl = numbers.length; j < jl; j += 6 ) {
518
-
519
- path.bezierCurveTo(
520
- point.x + numbers[ j + 0 ],
521
- point.y + numbers[ j + 1 ],
522
- point.x + numbers[ j + 2 ],
523
- point.y + numbers[ j + 3 ],
524
- point.x + numbers[ j + 4 ],
525
- point.y + numbers[ j + 5 ]
526
- );
527
- control.x = point.x + numbers[ j + 2 ];
528
- control.y = point.y + numbers[ j + 3 ];
529
- point.x += numbers[ j + 4 ];
530
- point.y += numbers[ j + 5 ];
531
-
532
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
533
-
534
- }
535
-
536
- break;
537
-
538
- case 's':
539
- numbers = parseFloats( data );
540
-
541
- for ( let j = 0, jl = numbers.length; j < jl; j += 4 ) {
542
-
543
- path.bezierCurveTo(
544
- getReflection( point.x, control.x ),
545
- getReflection( point.y, control.y ),
546
- point.x + numbers[ j + 0 ],
547
- point.y + numbers[ j + 1 ],
548
- point.x + numbers[ j + 2 ],
549
- point.y + numbers[ j + 3 ]
550
- );
551
- control.x = point.x + numbers[ j + 0 ];
552
- control.y = point.y + numbers[ j + 1 ];
553
- point.x += numbers[ j + 2 ];
554
- point.y += numbers[ j + 3 ];
555
-
556
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
557
-
558
- }
559
-
560
- break;
561
-
562
- case 'q':
563
- numbers = parseFloats( data );
564
-
565
- for ( let j = 0, jl = numbers.length; j < jl; j += 4 ) {
566
-
567
- path.quadraticCurveTo(
568
- point.x + numbers[ j + 0 ],
569
- point.y + numbers[ j + 1 ],
570
- point.x + numbers[ j + 2 ],
571
- point.y + numbers[ j + 3 ]
572
- );
573
- control.x = point.x + numbers[ j + 0 ];
574
- control.y = point.y + numbers[ j + 1 ];
575
- point.x += numbers[ j + 2 ];
576
- point.y += numbers[ j + 3 ];
577
-
578
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
579
-
580
- }
581
-
582
- break;
583
-
584
- case 't':
585
- numbers = parseFloats( data );
586
-
587
- for ( let j = 0, jl = numbers.length; j < jl; j += 2 ) {
588
-
589
- const rx = getReflection( point.x, control.x );
590
- const ry = getReflection( point.y, control.y );
591
- path.quadraticCurveTo(
592
- rx,
593
- ry,
594
- point.x + numbers[ j + 0 ],
595
- point.y + numbers[ j + 1 ]
596
- );
597
- control.x = rx;
598
- control.y = ry;
599
- point.x = point.x + numbers[ j + 0 ];
600
- point.y = point.y + numbers[ j + 1 ];
601
-
602
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
603
-
604
- }
605
-
606
- break;
607
-
608
- case 'a':
609
- numbers = parseFloats( data, [ 3, 4 ], 7 );
610
-
611
- for ( let j = 0, jl = numbers.length; j < jl; j += 7 ) {
612
-
613
- // skip command if no displacement
614
- if ( numbers[ j + 5 ] == 0 && numbers[ j + 6 ] == 0 ) continue;
615
-
616
- const start = point.clone();
617
- point.x += numbers[ j + 5 ];
618
- point.y += numbers[ j + 6 ];
619
- control.x = point.x;
620
- control.y = point.y;
621
- parseArcCommand(
622
- path, numbers[ j ], numbers[ j + 1 ], numbers[ j + 2 ], numbers[ j + 3 ], numbers[ j + 4 ], start, point
623
- );
624
-
625
- if ( j === 0 && doSetFirstPoint === true ) firstPoint.copy( point );
626
-
627
- }
628
-
629
- break;
630
-
631
- case 'Z':
632
- case 'z':
633
- path.currentPath.autoClose = true;
634
-
635
- if ( path.currentPath.curves.length > 0 ) {
636
-
637
- // Reset point to beginning of Path
638
- point.copy( firstPoint );
639
- path.currentPath.currentPoint.copy( point );
640
- isFirstPoint = true;
641
-
642
- }
643
-
644
- break;
645
-
646
- default:
647
- console.warn( command );
648
-
649
- }
650
-
651
- // console.log( type, parseFloats( data ), parseFloats( data ).length )
652
-
653
- doSetFirstPoint = false;
654
-
655
- }
656
-
657
- return path;
658
-
659
- }
660
-
661
- function parseCSSStylesheet( node ) {
662
-
663
- if ( ! node.sheet || ! node.sheet.cssRules || ! node.sheet.cssRules.length ) return;
664
-
665
- for ( let i = 0; i < node.sheet.cssRules.length; i ++ ) {
666
-
667
- const stylesheet = node.sheet.cssRules[ i ];
668
-
669
- if ( stylesheet.type !== 1 ) continue;
670
-
671
- const selectorList = stylesheet.selectorText
672
- .split( /,/gm )
673
- .filter( Boolean )
674
- .map( i => i.trim() );
675
-
676
- for ( let j = 0; j < selectorList.length; j ++ ) {
677
-
678
- // Remove empty rules
679
- const definitions = Object.fromEntries(
680
- Object.entries( stylesheet.style ).filter( ( [ , v ] ) => v !== '' )
681
- );
682
-
683
- stylesheets[ selectorList[ j ] ] = Object.assign(
684
- stylesheets[ selectorList[ j ] ] || {},
685
- definitions
686
- );
687
-
688
- }
689
-
690
- }
691
-
692
- }
693
-
694
- /**
695
- * https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
696
- * https://mortoray.com/2017/02/16/rendering-an-svg-elliptical-arc-as-bezier-curves/ Appendix: Endpoint to center arc conversion
697
- * From
698
- * rx ry x-axis-rotation large-arc-flag sweep-flag x y
699
- * To
700
- * aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation
701
- */
702
-
703
- function parseArcCommand( path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end ) {
704
-
705
- if ( rx == 0 || ry == 0 ) {
706
-
707
- // draw a line if either of the radii == 0
708
- path.lineTo( end.x, end.y );
709
- return;
710
-
711
- }
712
-
713
- x_axis_rotation = x_axis_rotation * Math.PI / 180;
714
-
715
- // Ensure radii are positive
716
- rx = Math.abs( rx );
717
- ry = Math.abs( ry );
718
-
719
- // Compute (x1', y1')
720
- const dx2 = ( start.x - end.x ) / 2.0;
721
- const dy2 = ( start.y - end.y ) / 2.0;
722
- const x1p = Math.cos( x_axis_rotation ) * dx2 + Math.sin( x_axis_rotation ) * dy2;
723
- const y1p = - Math.sin( x_axis_rotation ) * dx2 + Math.cos( x_axis_rotation ) * dy2;
724
-
725
- // Compute (cx', cy')
726
- let rxs = rx * rx;
727
- let rys = ry * ry;
728
- const x1ps = x1p * x1p;
729
- const y1ps = y1p * y1p;
730
-
731
- // Ensure radii are large enough
732
- const cr = x1ps / rxs + y1ps / rys;
733
-
734
- if ( cr > 1 ) {
735
-
736
- // scale up rx,ry equally so cr == 1
737
- const s = Math.sqrt( cr );
738
- rx = s * rx;
739
- ry = s * ry;
740
- rxs = rx * rx;
741
- rys = ry * ry;
742
-
743
- }
744
-
745
- const dq = ( rxs * y1ps + rys * x1ps );
746
- const pq = ( rxs * rys - dq ) / dq;
747
- let q = Math.sqrt( Math.max( 0, pq ) );
748
- if ( large_arc_flag === sweep_flag ) q = - q;
749
- const cxp = q * rx * y1p / ry;
750
- const cyp = - q * ry * x1p / rx;
751
-
752
- // Step 3: Compute (cx, cy) from (cx', cy')
753
- const cx = Math.cos( x_axis_rotation ) * cxp - Math.sin( x_axis_rotation ) * cyp + ( start.x + end.x ) / 2;
754
- const cy = Math.sin( x_axis_rotation ) * cxp + Math.cos( x_axis_rotation ) * cyp + ( start.y + end.y ) / 2;
755
-
756
- // Step 4: Compute θ1 and Δθ
757
- const theta = svgAngle( 1, 0, ( x1p - cxp ) / rx, ( y1p - cyp ) / ry );
758
- const delta = svgAngle( ( x1p - cxp ) / rx, ( y1p - cyp ) / ry, ( - x1p - cxp ) / rx, ( - y1p - cyp ) / ry ) % ( Math.PI * 2 );
759
-
760
- path.currentPath.absellipse( cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation );
761
-
762
- }
763
-
764
- function svgAngle( ux, uy, vx, vy ) {
765
-
766
- const dot = ux * vx + uy * vy;
767
- const len = Math.sqrt( ux * ux + uy * uy ) * Math.sqrt( vx * vx + vy * vy );
768
- let ang = Math.acos( Math.max( - 1, Math.min( 1, dot / len ) ) ); // floating point precision, slightly over values appear
769
- if ( ( ux * vy - uy * vx ) < 0 ) ang = - ang;
770
- return ang;
771
-
772
- }
773
-
774
- /*
775
- * According to https://www.w3.org/TR/SVG/shapes.html#RectElementRXAttribute
776
- * rounded corner should be rendered to elliptical arc, but bezier curve does the job well enough
777
- */
778
- function parseRectNode( node ) {
779
-
780
- const x = parseFloatWithUnits( node.getAttribute( 'x' ) || 0 );
781
- const y = parseFloatWithUnits( node.getAttribute( 'y' ) || 0 );
782
- const rx = parseFloatWithUnits( node.getAttribute( 'rx' ) || node.getAttribute( 'ry' ) || 0 );
783
- const ry = parseFloatWithUnits( node.getAttribute( 'ry' ) || node.getAttribute( 'rx' ) || 0 );
784
- const w = parseFloatWithUnits( node.getAttribute( 'width' ) );
785
- const h = parseFloatWithUnits( node.getAttribute( 'height' ) );
786
-
787
- // Ellipse arc to Bezier approximation Coefficient (Inversed). See:
788
- // https://spencermortensen.com/articles/bezier-circle/
789
- const bci = 1 - 0.551915024494;
790
-
791
- const path = new ShapePath();
792
-
793
- // top left
794
- path.moveTo( x + rx, y );
795
-
796
- // top right
797
- path.lineTo( x + w - rx, y );
798
- if ( rx !== 0 || ry !== 0 ) {
799
-
800
- path.bezierCurveTo(
801
- x + w - rx * bci,
802
- y,
803
- x + w,
804
- y + ry * bci,
805
- x + w,
806
- y + ry
807
- );
808
-
809
- }
810
-
811
- // bottom right
812
- path.lineTo( x + w, y + h - ry );
813
- if ( rx !== 0 || ry !== 0 ) {
814
-
815
- path.bezierCurveTo(
816
- x + w,
817
- y + h - ry * bci,
818
- x + w - rx * bci,
819
- y + h,
820
- x + w - rx,
821
- y + h
822
- );
823
-
824
- }
825
-
826
- // bottom left
827
- path.lineTo( x + rx, y + h );
828
- if ( rx !== 0 || ry !== 0 ) {
829
-
830
- path.bezierCurveTo(
831
- x + rx * bci,
832
- y + h,
833
- x,
834
- y + h - ry * bci,
835
- x,
836
- y + h - ry
837
- );
838
-
839
- }
840
-
841
- // back to top left
842
- path.lineTo( x, y + ry );
843
- if ( rx !== 0 || ry !== 0 ) {
844
-
845
- path.bezierCurveTo( x, y + ry * bci, x + rx * bci, y, x + rx, y );
846
-
847
- }
848
-
849
- return path;
850
-
851
- }
852
-
853
- function parsePolygonNode( node ) {
854
-
855
- function iterator( match, a, b ) {
856
-
857
- const x = parseFloatWithUnits( a );
858
- const y = parseFloatWithUnits( b );
859
-
860
- if ( index === 0 ) {
861
-
862
- path.moveTo( x, y );
863
-
864
- } else {
865
-
866
- path.lineTo( x, y );
867
-
868
- }
869
-
870
- index ++;
871
-
872
- }
873
-
874
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
875
-
876
- const path = new ShapePath();
877
-
878
- let index = 0;
879
-
880
- node.getAttribute( 'points' ).replace( regex, iterator );
881
-
882
- path.currentPath.autoClose = true;
883
-
884
- return path;
885
-
886
- }
887
-
888
- function parsePolylineNode( node ) {
889
-
890
- function iterator( match, a, b ) {
891
-
892
- const x = parseFloatWithUnits( a );
893
- const y = parseFloatWithUnits( b );
894
-
895
- if ( index === 0 ) {
896
-
897
- path.moveTo( x, y );
898
-
899
- } else {
900
-
901
- path.lineTo( x, y );
902
-
903
- }
904
-
905
- index ++;
906
-
907
- }
908
-
909
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
910
-
911
- const path = new ShapePath();
912
-
913
- let index = 0;
914
-
915
- node.getAttribute( 'points' ).replace( regex, iterator );
916
-
917
- path.currentPath.autoClose = false;
918
-
919
- return path;
920
-
921
- }
922
-
923
- function parseCircleNode( node ) {
924
-
925
- const x = parseFloatWithUnits( node.getAttribute( 'cx' ) || 0 );
926
- const y = parseFloatWithUnits( node.getAttribute( 'cy' ) || 0 );
927
- const r = parseFloatWithUnits( node.getAttribute( 'r' ) || 0 );
928
-
929
- const subpath = new Path();
930
- subpath.absarc( x, y, r, 0, Math.PI * 2 );
931
-
932
- const path = new ShapePath();
933
- path.subPaths.push( subpath );
934
-
935
- return path;
936
-
937
- }
938
-
939
- function parseEllipseNode( node ) {
940
-
941
- const x = parseFloatWithUnits( node.getAttribute( 'cx' ) || 0 );
942
- const y = parseFloatWithUnits( node.getAttribute( 'cy' ) || 0 );
943
- const rx = parseFloatWithUnits( node.getAttribute( 'rx' ) || 0 );
944
- const ry = parseFloatWithUnits( node.getAttribute( 'ry' ) || 0 );
945
-
946
- const subpath = new Path();
947
- subpath.absellipse( x, y, rx, ry, 0, Math.PI * 2 );
948
-
949
- const path = new ShapePath();
950
- path.subPaths.push( subpath );
951
-
952
- return path;
953
-
954
- }
955
-
956
- function parseLineNode( node ) {
957
-
958
- const x1 = parseFloatWithUnits( node.getAttribute( 'x1' ) || 0 );
959
- const y1 = parseFloatWithUnits( node.getAttribute( 'y1' ) || 0 );
960
- const x2 = parseFloatWithUnits( node.getAttribute( 'x2' ) || 0 );
961
- const y2 = parseFloatWithUnits( node.getAttribute( 'y2' ) || 0 );
962
-
963
- const path = new ShapePath();
964
- path.moveTo( x1, y1 );
965
- path.lineTo( x2, y2 );
966
- path.currentPath.autoClose = false;
967
-
968
- return path;
969
-
970
- }
971
-
972
- //
973
-
974
- function parseStyle( node, style ) {
975
-
976
- style = Object.assign( {}, style ); // clone style
977
-
978
- let stylesheetStyles = {};
979
-
980
- if ( node.hasAttribute( 'class' ) ) {
981
-
982
- const classSelectors = node.getAttribute( 'class' )
983
- .split( /\s/ )
984
- .filter( Boolean )
985
- .map( i => i.trim() );
986
-
987
- for ( let i = 0; i < classSelectors.length; i ++ ) {
988
-
989
- stylesheetStyles = Object.assign( stylesheetStyles, stylesheets[ '.' + classSelectors[ i ] ] );
990
-
991
- }
992
-
993
- }
994
-
995
- if ( node.hasAttribute( 'id' ) ) {
996
-
997
- stylesheetStyles = Object.assign( stylesheetStyles, stylesheets[ '#' + node.getAttribute( 'id' ) ] );
998
-
999
- }
1000
-
1001
- function addStyle( svgName, jsName, adjustFunction ) {
1002
-
1003
- if ( adjustFunction === undefined ) adjustFunction = function copy( v ) {
1004
-
1005
- if ( v.startsWith( 'url' ) ) console.warn( 'SVGLoader: url access in attributes is not implemented.' );
1006
-
1007
- return v;
1008
-
1009
- };
1010
-
1011
- if ( node.hasAttribute( svgName ) ) style[ jsName ] = adjustFunction( node.getAttribute( svgName ) );
1012
- if ( stylesheetStyles[ svgName ] ) style[ jsName ] = adjustFunction( stylesheetStyles[ svgName ] );
1013
- if ( node.style && node.style[ svgName ] !== '' ) style[ jsName ] = adjustFunction( node.style[ svgName ] );
1014
-
1015
- }
1016
-
1017
- function clamp( v ) {
1018
-
1019
- return Math.max( 0, Math.min( 1, parseFloatWithUnits( v ) ) );
1020
-
1021
- }
1022
-
1023
- function positive( v ) {
1024
-
1025
- return Math.max( 0, parseFloatWithUnits( v ) );
1026
-
1027
- }
1028
-
1029
- addStyle( 'fill', 'fill' );
1030
- addStyle( 'fill-opacity', 'fillOpacity', clamp );
1031
- addStyle( 'fill-rule', 'fillRule' );
1032
- addStyle( 'opacity', 'opacity', clamp );
1033
- addStyle( 'stroke', 'stroke' );
1034
- addStyle( 'stroke-opacity', 'strokeOpacity', clamp );
1035
- addStyle( 'stroke-width', 'strokeWidth', positive );
1036
- addStyle( 'stroke-linejoin', 'strokeLineJoin' );
1037
- addStyle( 'stroke-linecap', 'strokeLineCap' );
1038
- addStyle( 'stroke-miterlimit', 'strokeMiterLimit', positive );
1039
- addStyle( 'visibility', 'visibility' );
1040
-
1041
- return style;
1042
-
1043
- }
1044
-
1045
- // http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes
1046
-
1047
- function getReflection( a, b ) {
1048
-
1049
- return a - ( b - a );
1050
-
1051
- }
1052
-
1053
- // from https://github.com/ppvg/svg-numbers (MIT License)
1054
-
1055
- function parseFloats( input, flags, stride ) {
1056
-
1057
- if ( typeof input !== 'string' ) {
1058
-
1059
- throw new TypeError( 'Invalid input: ' + typeof input );
1060
-
1061
- }
1062
-
1063
- // Character groups
1064
- const RE = {
1065
- SEPARATOR: /[ \t\r\n\,.\-+]/,
1066
- WHITESPACE: /[ \t\r\n]/,
1067
- DIGIT: /[\d]/,
1068
- SIGN: /[-+]/,
1069
- POINT: /\./,
1070
- COMMA: /,/,
1071
- EXP: /e/i,
1072
- FLAGS: /[01]/
1073
- };
1074
-
1075
- // States
1076
- const SEP = 0;
1077
- const INT = 1;
1078
- const FLOAT = 2;
1079
- const EXP = 3;
1080
-
1081
- let state = SEP;
1082
- let seenComma = true;
1083
- let number = '', exponent = '';
1084
- const result = [];
1085
-
1086
- function throwSyntaxError( current, i, partial ) {
1087
-
1088
- const error = new SyntaxError( 'Unexpected character "' + current + '" at index ' + i + '.' );
1089
- error.partial = partial;
1090
- throw error;
1091
-
1092
- }
1093
-
1094
- function newNumber() {
1095
-
1096
- if ( number !== '' ) {
1097
-
1098
- if ( exponent === '' ) result.push( Number( number ) );
1099
- else result.push( Number( number ) * Math.pow( 10, Number( exponent ) ) );
1100
-
1101
- }
1102
-
1103
- number = '';
1104
- exponent = '';
1105
-
1106
- }
1107
-
1108
- let current;
1109
- const length = input.length;
1110
-
1111
- for ( let i = 0; i < length; i ++ ) {
1112
-
1113
- current = input[ i ];
1114
-
1115
- // check for flags
1116
- if ( Array.isArray( flags ) && flags.includes( result.length % stride ) && RE.FLAGS.test( current ) ) {
1117
-
1118
- state = INT;
1119
- number = current;
1120
- newNumber();
1121
- continue;
1122
-
1123
- }
1124
-
1125
- // parse until next number
1126
- if ( state === SEP ) {
1127
-
1128
- // eat whitespace
1129
- if ( RE.WHITESPACE.test( current ) ) {
1130
-
1131
- continue;
1132
-
1133
- }
1134
-
1135
- // start new number
1136
- if ( RE.DIGIT.test( current ) || RE.SIGN.test( current ) ) {
1137
-
1138
- state = INT;
1139
- number = current;
1140
- continue;
1141
-
1142
- }
1143
-
1144
- if ( RE.POINT.test( current ) ) {
1145
-
1146
- state = FLOAT;
1147
- number = current;
1148
- continue;
1149
-
1150
- }
1151
-
1152
- // throw on double commas (e.g. "1, , 2")
1153
- if ( RE.COMMA.test( current ) ) {
1154
-
1155
- if ( seenComma ) {
1156
-
1157
- throwSyntaxError( current, i, result );
1158
-
1159
- }
1160
-
1161
- seenComma = true;
1162
-
1163
- }
1164
-
1165
- }
1166
-
1167
- // parse integer part
1168
- if ( state === INT ) {
1169
-
1170
- if ( RE.DIGIT.test( current ) ) {
1171
-
1172
- number += current;
1173
- continue;
1174
-
1175
- }
1176
-
1177
- if ( RE.POINT.test( current ) ) {
1178
-
1179
- number += current;
1180
- state = FLOAT;
1181
- continue;
1182
-
1183
- }
1184
-
1185
- if ( RE.EXP.test( current ) ) {
1186
-
1187
- state = EXP;
1188
- continue;
1189
-
1190
- }
1191
-
1192
- // throw on double signs ("-+1"), but not on sign as separator ("-1-2")
1193
- if ( RE.SIGN.test( current )
1194
- && number.length === 1
1195
- && RE.SIGN.test( number[ 0 ] ) ) {
1196
-
1197
- throwSyntaxError( current, i, result );
1198
-
1199
- }
1200
-
1201
- }
1202
-
1203
- // parse decimal part
1204
- if ( state === FLOAT ) {
1205
-
1206
- if ( RE.DIGIT.test( current ) ) {
1207
-
1208
- number += current;
1209
- continue;
1210
-
1211
- }
1212
-
1213
- if ( RE.EXP.test( current ) ) {
1214
-
1215
- state = EXP;
1216
- continue;
1217
-
1218
- }
1219
-
1220
- // throw on double decimal points (e.g. "1..2")
1221
- if ( RE.POINT.test( current ) && number[ number.length - 1 ] === '.' ) {
1222
-
1223
- throwSyntaxError( current, i, result );
1224
-
1225
- }
1226
-
1227
- }
1228
-
1229
- // parse exponent part
1230
- if ( state === EXP ) {
1231
-
1232
- if ( RE.DIGIT.test( current ) ) {
1233
-
1234
- exponent += current;
1235
- continue;
1236
-
1237
- }
1238
-
1239
- if ( RE.SIGN.test( current ) ) {
1240
-
1241
- if ( exponent === '' ) {
1242
-
1243
- exponent += current;
1244
- continue;
1245
-
1246
- }
1247
-
1248
- if ( exponent.length === 1 && RE.SIGN.test( exponent ) ) {
1249
-
1250
- throwSyntaxError( current, i, result );
1251
-
1252
- }
1253
-
1254
- }
1255
-
1256
- }
1257
-
1258
-
1259
- // end of number
1260
- if ( RE.WHITESPACE.test( current ) ) {
1261
-
1262
- newNumber();
1263
- state = SEP;
1264
- seenComma = false;
1265
-
1266
- } else if ( RE.COMMA.test( current ) ) {
1267
-
1268
- newNumber();
1269
- state = SEP;
1270
- seenComma = true;
1271
-
1272
- } else if ( RE.SIGN.test( current ) ) {
1273
-
1274
- newNumber();
1275
- state = INT;
1276
- number = current;
1277
-
1278
- } else if ( RE.POINT.test( current ) ) {
1279
-
1280
- newNumber();
1281
- state = FLOAT;
1282
- number = current;
1283
-
1284
- } else {
1285
-
1286
- throwSyntaxError( current, i, result );
1287
-
1288
- }
1289
-
1290
- }
1291
-
1292
- // add the last number found (if any)
1293
- newNumber();
1294
-
1295
- return result;
1296
-
1297
- }
1298
-
1299
- // Units
1300
-
1301
- const units = [ 'mm', 'cm', 'in', 'pt', 'pc', 'px' ];
1302
-
1303
- // Conversion: [ fromUnit ][ toUnit ] (-1 means dpi dependent)
1304
- const unitConversion = {
1305
-
1306
- 'mm': {
1307
- 'mm': 1,
1308
- 'cm': 0.1,
1309
- 'in': 1 / 25.4,
1310
- 'pt': 72 / 25.4,
1311
- 'pc': 6 / 25.4,
1312
- 'px': - 1
1313
- },
1314
- 'cm': {
1315
- 'mm': 10,
1316
- 'cm': 1,
1317
- 'in': 1 / 2.54,
1318
- 'pt': 72 / 2.54,
1319
- 'pc': 6 / 2.54,
1320
- 'px': - 1
1321
- },
1322
- 'in': {
1323
- 'mm': 25.4,
1324
- 'cm': 2.54,
1325
- 'in': 1,
1326
- 'pt': 72,
1327
- 'pc': 6,
1328
- 'px': - 1
1329
- },
1330
- 'pt': {
1331
- 'mm': 25.4 / 72,
1332
- 'cm': 2.54 / 72,
1333
- 'in': 1 / 72,
1334
- 'pt': 1,
1335
- 'pc': 6 / 72,
1336
- 'px': - 1
1337
- },
1338
- 'pc': {
1339
- 'mm': 25.4 / 6,
1340
- 'cm': 2.54 / 6,
1341
- 'in': 1 / 6,
1342
- 'pt': 72 / 6,
1343
- 'pc': 1,
1344
- 'px': - 1
1345
- },
1346
- 'px': {
1347
- 'px': 1
1348
- }
1349
-
1350
- };
1351
-
1352
- function parseFloatWithUnits( string ) {
1353
-
1354
- let theUnit = 'px';
1355
-
1356
- if ( typeof string === 'string' || string instanceof String ) {
1357
-
1358
- for ( let i = 0, n = units.length; i < n; i ++ ) {
1359
-
1360
- const u = units[ i ];
1361
-
1362
- if ( string.endsWith( u ) ) {
1363
-
1364
- theUnit = u;
1365
- string = string.substring( 0, string.length - u.length );
1366
- break;
1367
-
1368
- }
1369
-
1370
- }
1371
-
1372
- }
1373
-
1374
- let scale = undefined;
1375
-
1376
- if ( theUnit === 'px' && scope.defaultUnit !== 'px' ) {
1377
-
1378
- // Conversion scale from pixels to inches, then to default units
1379
-
1380
- scale = unitConversion[ 'in' ][ scope.defaultUnit ] / scope.defaultDPI;
1381
-
1382
- } else {
1383
-
1384
- scale = unitConversion[ theUnit ][ scope.defaultUnit ];
1385
-
1386
- if ( scale < 0 ) {
1387
-
1388
- // Conversion scale to pixels
1389
-
1390
- scale = unitConversion[ theUnit ][ 'in' ] * scope.defaultDPI;
1391
-
1392
- }
1393
-
1394
- }
1395
-
1396
- return scale * parseFloat( string );
1397
-
1398
- }
1399
-
1400
- // Transforms
1401
-
1402
- function getNodeTransform( node ) {
1403
-
1404
- if ( ! ( node.hasAttribute( 'transform' ) || ( node.nodeName === 'use' && ( node.hasAttribute( 'x' ) || node.hasAttribute( 'y' ) ) ) ) ) {
1405
-
1406
- return null;
1407
-
1408
- }
1409
-
1410
- const transform = parseNodeTransform( node );
1411
-
1412
- if ( transformStack.length > 0 ) {
1413
-
1414
- transform.premultiply( transformStack[ transformStack.length - 1 ] );
1415
-
1416
- }
1417
-
1418
- currentTransform.copy( transform );
1419
- transformStack.push( transform );
1420
-
1421
- return transform;
1422
-
1423
- }
1424
-
1425
- function parseNodeTransform( node ) {
1426
-
1427
- const transform = new Matrix3();
1428
- const currentTransform = tempTransform0;
1429
-
1430
- if ( node.nodeName === 'use' && ( node.hasAttribute( 'x' ) || node.hasAttribute( 'y' ) ) ) {
1431
-
1432
- const tx = parseFloatWithUnits( node.getAttribute( 'x' ) );
1433
- const ty = parseFloatWithUnits( node.getAttribute( 'y' ) );
1434
-
1435
- transform.translate( tx, ty );
1436
-
1437
- }
1438
-
1439
- if ( node.hasAttribute( 'transform' ) ) {
1440
-
1441
- const transformsTexts = node.getAttribute( 'transform' ).split( ')' );
1442
-
1443
- for ( let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex -- ) {
1444
-
1445
- const transformText = transformsTexts[ tIndex ].trim();
1446
-
1447
- if ( transformText === '' ) continue;
1448
-
1449
- const openParPos = transformText.indexOf( '(' );
1450
- const closeParPos = transformText.length;
1451
-
1452
- if ( openParPos > 0 && openParPos < closeParPos ) {
1453
-
1454
- const transformType = transformText.slice( 0, openParPos );
1455
-
1456
- const array = parseFloats( transformText.slice( openParPos + 1 ) );
1457
-
1458
- currentTransform.identity();
1459
-
1460
- switch ( transformType ) {
1461
-
1462
- case 'translate':
1463
-
1464
- if ( array.length >= 1 ) {
1465
-
1466
- const tx = array[ 0 ];
1467
- let ty = 0;
1468
-
1469
- if ( array.length >= 2 ) {
1470
-
1471
- ty = array[ 1 ];
1472
-
1473
- }
1474
-
1475
- currentTransform.translate( tx, ty );
1476
-
1477
- }
1478
-
1479
- break;
1480
-
1481
- case 'rotate':
1482
-
1483
- if ( array.length >= 1 ) {
1484
-
1485
- let angle = 0;
1486
- let cx = 0;
1487
- let cy = 0;
1488
-
1489
- // Angle
1490
- angle = array[ 0 ] * Math.PI / 180;
1491
-
1492
- if ( array.length >= 3 ) {
1493
-
1494
- // Center x, y
1495
- cx = array[ 1 ];
1496
- cy = array[ 2 ];
1497
-
1498
- }
1499
-
1500
- // Rotate around center (cx, cy)
1501
- tempTransform1.makeTranslation( - cx, - cy );
1502
- tempTransform2.makeRotation( angle );
1503
- tempTransform3.multiplyMatrices( tempTransform2, tempTransform1 );
1504
- tempTransform1.makeTranslation( cx, cy );
1505
- currentTransform.multiplyMatrices( tempTransform1, tempTransform3 );
1506
-
1507
- }
1508
-
1509
- break;
1510
-
1511
- case 'scale':
1512
-
1513
- if ( array.length >= 1 ) {
1514
-
1515
- const scaleX = array[ 0 ];
1516
- let scaleY = scaleX;
1517
-
1518
- if ( array.length >= 2 ) {
1519
-
1520
- scaleY = array[ 1 ];
1521
-
1522
- }
1523
-
1524
- currentTransform.scale( scaleX, scaleY );
1525
-
1526
- }
1527
-
1528
- break;
1529
-
1530
- case 'skewX':
1531
-
1532
- if ( array.length === 1 ) {
1533
-
1534
- currentTransform.set(
1535
- 1, Math.tan( array[ 0 ] * Math.PI / 180 ), 0,
1536
- 0, 1, 0,
1537
- 0, 0, 1
1538
- );
1539
-
1540
- }
1541
-
1542
- break;
1543
-
1544
- case 'skewY':
1545
-
1546
- if ( array.length === 1 ) {
1547
-
1548
- currentTransform.set(
1549
- 1, 0, 0,
1550
- Math.tan( array[ 0 ] * Math.PI / 180 ), 1, 0,
1551
- 0, 0, 1
1552
- );
1553
-
1554
- }
1555
-
1556
- break;
1557
-
1558
- case 'matrix':
1559
-
1560
- if ( array.length === 6 ) {
1561
-
1562
- currentTransform.set(
1563
- array[ 0 ], array[ 2 ], array[ 4 ],
1564
- array[ 1 ], array[ 3 ], array[ 5 ],
1565
- 0, 0, 1
1566
- );
1567
-
1568
- }
1569
-
1570
- break;
1571
-
1572
- }
1573
-
1574
- }
1575
-
1576
- transform.premultiply( currentTransform );
1577
-
1578
- }
1579
-
1580
- }
1581
-
1582
- return transform;
1583
-
1584
- }
1585
-
1586
- function transformPath( path, m ) {
1587
-
1588
- function transfVec2( v2 ) {
1589
-
1590
- tempV3.set( v2.x, v2.y, 1 ).applyMatrix3( m );
1591
-
1592
- v2.set( tempV3.x, tempV3.y );
1593
-
1594
- }
1595
-
1596
- function transfEllipseGeneric( curve ) {
1597
-
1598
- // For math description see:
1599
- // https://math.stackexchange.com/questions/4544164
1600
-
1601
- const a = curve.xRadius;
1602
- const b = curve.yRadius;
1603
-
1604
- const cosTheta = Math.cos( curve.aRotation );
1605
- const sinTheta = Math.sin( curve.aRotation );
1606
-
1607
- const v1 = new Vector3( a * cosTheta, a * sinTheta, 0 );
1608
- const v2 = new Vector3( - b * sinTheta, b * cosTheta, 0 );
1609
-
1610
- const f1 = v1.applyMatrix3( m );
1611
- const f2 = v2.applyMatrix3( m );
1612
-
1613
- const mF = tempTransform0.set(
1614
- f1.x, f2.x, 0,
1615
- f1.y, f2.y, 0,
1616
- 0, 0, 1,
1617
- );
1618
-
1619
- const mFInv = tempTransform1.copy( mF ).invert();
1620
- const mFInvT = tempTransform2.copy( mFInv ).transpose();
1621
- const mQ = mFInvT.multiply( mFInv );
1622
- const mQe = mQ.elements;
1623
-
1624
- const ed = eigenDecomposition( mQe[ 0 ], mQe[ 1 ], mQe[ 4 ] );
1625
- const rt1sqrt = Math.sqrt( ed.rt1 );
1626
- const rt2sqrt = Math.sqrt( ed.rt2 );
1627
-
1628
- curve.xRadius = 1 / rt1sqrt;
1629
- curve.yRadius = 1 / rt2sqrt;
1630
- curve.aRotation = Math.atan2( ed.sn, ed.cs );
1631
-
1632
- const isFullEllipse =
1633
- ( curve.aEndAngle - curve.aStartAngle ) % ( 2 * Math.PI ) < Number.EPSILON;
1634
-
1635
- // Do not touch angles of a full ellipse because after transformation they
1636
- // would converge to a sinle value effectively removing the whole curve
1637
-
1638
- if ( ! isFullEllipse ) {
1639
-
1640
- const mDsqrt = tempTransform1.set(
1641
- rt1sqrt, 0, 0,
1642
- 0, rt2sqrt, 0,
1643
- 0, 0, 1,
1644
- );
1645
-
1646
- const mRT = tempTransform2.set(
1647
- ed.cs, ed.sn, 0,
1648
- - ed.sn, ed.cs, 0,
1649
- 0, 0, 1,
1650
- );
1651
-
1652
- const mDRF = mDsqrt.multiply( mRT ).multiply( mF );
1653
-
1654
- const transformAngle = phi => {
1655
-
1656
- const { x: cosR, y: sinR } =
1657
- new Vector3( Math.cos( phi ), Math.sin( phi ), 0 ).applyMatrix3( mDRF );
1658
-
1659
- return Math.atan2( sinR, cosR );
1660
-
1661
- };
1662
-
1663
- curve.aStartAngle = transformAngle( curve.aStartAngle );
1664
- curve.aEndAngle = transformAngle( curve.aEndAngle );
1665
-
1666
- if ( isTransformFlipped( m ) ) {
1667
-
1668
- curve.aClockwise = ! curve.aClockwise;
1669
-
1670
- }
1671
-
1672
- }
1673
-
1674
- }
1675
-
1676
- function transfEllipseNoSkew( curve ) {
1677
-
1678
- // Faster shortcut if no skew is applied
1679
- // (e.g, a euclidean transform of a group containing the ellipse)
1680
-
1681
- const sx = getTransformScaleX( m );
1682
- const sy = getTransformScaleY( m );
1683
-
1684
- curve.xRadius *= sx;
1685
- curve.yRadius *= sy;
1686
-
1687
- // Extract rotation angle from the matrix of form:
1688
- //
1689
- // | cosθ sx -sinθ sy |
1690
- // | sinθ sx cosθ sy |
1691
- //
1692
- // Remembering that tanθ = sinθ / cosθ; and that
1693
- // `sx`, `sy`, or both might be zero.
1694
- const theta =
1695
- sx > Number.EPSILON
1696
- ? Math.atan2( m.elements[ 1 ], m.elements[ 0 ] )
1697
- : Math.atan2( - m.elements[ 3 ], m.elements[ 4 ] );
1698
-
1699
- curve.aRotation += theta;
1700
-
1701
- if ( isTransformFlipped( m ) ) {
1702
-
1703
- curve.aStartAngle *= - 1;
1704
- curve.aEndAngle *= - 1;
1705
- curve.aClockwise = ! curve.aClockwise;
1706
-
1707
- }
1708
-
1709
- }
1710
-
1711
- const subPaths = path.subPaths;
1712
-
1713
- for ( let i = 0, n = subPaths.length; i < n; i ++ ) {
1714
-
1715
- const subPath = subPaths[ i ];
1716
- const curves = subPath.curves;
1717
-
1718
- for ( let j = 0; j < curves.length; j ++ ) {
1719
-
1720
- const curve = curves[ j ];
1721
-
1722
- if ( curve.isLineCurve ) {
1723
-
1724
- transfVec2( curve.v1 );
1725
- transfVec2( curve.v2 );
1726
-
1727
- } else if ( curve.isCubicBezierCurve ) {
1728
-
1729
- transfVec2( curve.v0 );
1730
- transfVec2( curve.v1 );
1731
- transfVec2( curve.v2 );
1732
- transfVec2( curve.v3 );
1733
-
1734
- } else if ( curve.isQuadraticBezierCurve ) {
1735
-
1736
- transfVec2( curve.v0 );
1737
- transfVec2( curve.v1 );
1738
- transfVec2( curve.v2 );
1739
-
1740
- } else if ( curve.isEllipseCurve ) {
1741
-
1742
- // Transform ellipse center point
1743
-
1744
- tempV2.set( curve.aX, curve.aY );
1745
- transfVec2( tempV2 );
1746
- curve.aX = tempV2.x;
1747
- curve.aY = tempV2.y;
1748
-
1749
- // Transform ellipse shape parameters
1750
-
1751
- if ( isTransformSkewed( m ) ) {
1752
-
1753
- transfEllipseGeneric( curve );
1754
-
1755
- } else {
1756
-
1757
- transfEllipseNoSkew( curve );
1758
-
1759
- }
1760
-
1761
- }
1762
-
1763
- }
1764
-
1765
- }
1766
-
1767
- }
1768
-
1769
- function isTransformFlipped( m ) {
1770
-
1771
- const te = m.elements;
1772
- return te[ 0 ] * te[ 4 ] - te[ 1 ] * te[ 3 ] < 0;
1773
-
1774
- }
1775
-
1776
- function isTransformSkewed( m ) {
1777
-
1778
- const te = m.elements;
1779
- const basisDot = te[ 0 ] * te[ 3 ] + te[ 1 ] * te[ 4 ];
1780
-
1781
- // Shortcut for trivial rotations and transformations
1782
- if ( basisDot === 0 ) return false;
1783
-
1784
- const sx = getTransformScaleX( m );
1785
- const sy = getTransformScaleY( m );
1786
-
1787
- return Math.abs( basisDot / ( sx * sy ) ) > Number.EPSILON;
1788
-
1789
- }
1790
-
1791
- function getTransformScaleX( m ) {
1792
-
1793
- const te = m.elements;
1794
- return Math.sqrt( te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] );
1795
-
1796
- }
1797
-
1798
- function getTransformScaleY( m ) {
1799
-
1800
- const te = m.elements;
1801
- return Math.sqrt( te[ 3 ] * te[ 3 ] + te[ 4 ] * te[ 4 ] );
1802
-
1803
- }
1804
-
1805
- // Calculates the eigensystem of a real symmetric 2x2 matrix
1806
- // [ A B ]
1807
- // [ B C ]
1808
- // in the form
1809
- // [ A B ] = [ cs -sn ] [ rt1 0 ] [ cs sn ]
1810
- // [ B C ] [ sn cs ] [ 0 rt2 ] [ -sn cs ]
1811
- // where rt1 >= rt2.
1812
- //
1813
- // Adapted from: https://www.mpi-hd.mpg.de/personalhomes/globes/3x3/index.html
1814
- // -> Algorithms for real symmetric matrices -> Analytical (2x2 symmetric)
1815
- function eigenDecomposition( A, B, C ) {
1816
-
1817
- let rt1, rt2, cs, sn, t;
1818
- const sm = A + C;
1819
- const df = A - C;
1820
- const rt = Math.sqrt( df * df + 4 * B * B );
1821
-
1822
- if ( sm > 0 ) {
1823
-
1824
- rt1 = 0.5 * ( sm + rt );
1825
- t = 1 / rt1;
1826
- rt2 = A * t * C - B * t * B;
1827
-
1828
- } else if ( sm < 0 ) {
1829
-
1830
- rt2 = 0.5 * ( sm - rt );
1831
-
1832
- } else {
1833
-
1834
- // This case needs to be treated separately to avoid div by 0
1835
-
1836
- rt1 = 0.5 * rt;
1837
- rt2 = - 0.5 * rt;
1838
-
1839
- }
1840
-
1841
- // Calculate eigenvectors
1842
-
1843
- if ( df > 0 ) {
1844
-
1845
- cs = df + rt;
1846
-
1847
- } else {
1848
-
1849
- cs = df - rt;
1850
-
1851
- }
1852
-
1853
- if ( Math.abs( cs ) > 2 * Math.abs( B ) ) {
1854
-
1855
- t = - 2 * B / cs;
1856
- sn = 1 / Math.sqrt( 1 + t * t );
1857
- cs = t * sn;
1858
-
1859
- } else if ( Math.abs( B ) === 0 ) {
1860
-
1861
- cs = 1;
1862
- sn = 0;
1863
-
1864
- } else {
1865
-
1866
- t = - 0.5 * cs / B;
1867
- cs = 1 / Math.sqrt( 1 + t * t );
1868
- sn = t * cs;
1869
-
1870
- }
1871
-
1872
- if ( df > 0 ) {
1873
-
1874
- t = cs;
1875
- cs = - sn;
1876
- sn = t;
1877
-
1878
- }
1879
-
1880
- return { rt1, rt2, cs, sn };
1881
-
1882
- }
1883
-
1884
- //
1885
-
1886
- const paths = [];
1887
- const stylesheets = {};
1888
-
1889
- const transformStack = [];
1890
-
1891
- const tempTransform0 = new Matrix3();
1892
- const tempTransform1 = new Matrix3();
1893
- const tempTransform2 = new Matrix3();
1894
- const tempTransform3 = new Matrix3();
1895
- const tempV2 = new Vector2();
1896
- const tempV3 = new Vector3();
1897
-
1898
- const currentTransform = new Matrix3();
1899
-
1900
- const xml = new DOMParser().parseFromString( text, 'image/svg+xml' ); // application/xml
1901
-
1902
- parseNode( xml.documentElement, {
1903
- fill: '#000',
1904
- fillOpacity: 1,
1905
- strokeOpacity: 1,
1906
- strokeWidth: 1,
1907
- strokeLineJoin: 'miter',
1908
- strokeLineCap: 'butt',
1909
- strokeMiterLimit: 4
1910
- } );
1911
-
1912
- const data = { paths: paths, xml: xml.documentElement };
1913
-
1914
- // console.log( paths );
1915
- return data;
1916
-
1917
- }
1918
-
1919
- static createShapes( shapePath ) {
1920
-
1921
- // Param shapePath: a shapepath as returned by the parse function of this class
1922
- // Returns Shape object
1923
-
1924
- const BIGNUMBER = 999999999;
1925
-
1926
- const IntersectionLocationType = {
1927
- ORIGIN: 0,
1928
- DESTINATION: 1,
1929
- BETWEEN: 2,
1930
- LEFT: 3,
1931
- RIGHT: 4,
1932
- BEHIND: 5,
1933
- BEYOND: 6
1934
- };
1935
-
1936
- const classifyResult = {
1937
- loc: IntersectionLocationType.ORIGIN,
1938
- t: 0
1939
- };
1940
-
1941
- function findEdgeIntersection( a0, a1, b0, b1 ) {
1942
-
1943
- const x1 = a0.x;
1944
- const x2 = a1.x;
1945
- const x3 = b0.x;
1946
- const x4 = b1.x;
1947
- const y1 = a0.y;
1948
- const y2 = a1.y;
1949
- const y3 = b0.y;
1950
- const y4 = b1.y;
1951
- const nom1 = ( x4 - x3 ) * ( y1 - y3 ) - ( y4 - y3 ) * ( x1 - x3 );
1952
- const nom2 = ( x2 - x1 ) * ( y1 - y3 ) - ( y2 - y1 ) * ( x1 - x3 );
1953
- const denom = ( y4 - y3 ) * ( x2 - x1 ) - ( x4 - x3 ) * ( y2 - y1 );
1954
- const t1 = nom1 / denom;
1955
- const t2 = nom2 / denom;
1956
-
1957
- if ( ( ( denom === 0 ) && ( nom1 !== 0 ) ) || ( t1 <= 0 ) || ( t1 >= 1 ) || ( t2 < 0 ) || ( t2 > 1 ) ) {
1958
-
1959
- //1. lines are parallel or edges don't intersect
1960
-
1961
- return null;
1962
-
1963
- } else if ( ( nom1 === 0 ) && ( denom === 0 ) ) {
1964
-
1965
- //2. lines are colinear
1966
-
1967
- //check if endpoints of edge2 (b0-b1) lies on edge1 (a0-a1)
1968
- for ( let i = 0; i < 2; i ++ ) {
1969
-
1970
- classifyPoint( i === 0 ? b0 : b1, a0, a1 );
1971
- //find position of this endpoints relatively to edge1
1972
- if ( classifyResult.loc == IntersectionLocationType.ORIGIN ) {
1973
-
1974
- const point = ( i === 0 ? b0 : b1 );
1975
- return { x: point.x, y: point.y, t: classifyResult.t };
1976
-
1977
- } else if ( classifyResult.loc == IntersectionLocationType.BETWEEN ) {
1978
-
1979
- const x = + ( ( x1 + classifyResult.t * ( x2 - x1 ) ).toPrecision( 10 ) );
1980
- const y = + ( ( y1 + classifyResult.t * ( y2 - y1 ) ).toPrecision( 10 ) );
1981
- return { x: x, y: y, t: classifyResult.t, };
1982
-
1983
- }
1984
-
1985
- }
1986
-
1987
- return null;
1988
-
1989
- } else {
1990
-
1991
- //3. edges intersect
1992
-
1993
- for ( let i = 0; i < 2; i ++ ) {
1994
-
1995
- classifyPoint( i === 0 ? b0 : b1, a0, a1 );
1996
-
1997
- if ( classifyResult.loc == IntersectionLocationType.ORIGIN ) {
1998
-
1999
- const point = ( i === 0 ? b0 : b1 );
2000
- return { x: point.x, y: point.y, t: classifyResult.t };
2001
-
2002
- }
2003
-
2004
- }
2005
-
2006
- const x = + ( ( x1 + t1 * ( x2 - x1 ) ).toPrecision( 10 ) );
2007
- const y = + ( ( y1 + t1 * ( y2 - y1 ) ).toPrecision( 10 ) );
2008
- return { x: x, y: y, t: t1 };
2009
-
2010
- }
2011
-
2012
- }
2013
-
2014
- function classifyPoint( p, edgeStart, edgeEnd ) {
2015
-
2016
- const ax = edgeEnd.x - edgeStart.x;
2017
- const ay = edgeEnd.y - edgeStart.y;
2018
- const bx = p.x - edgeStart.x;
2019
- const by = p.y - edgeStart.y;
2020
- const sa = ax * by - bx * ay;
2021
-
2022
- if ( ( p.x === edgeStart.x ) && ( p.y === edgeStart.y ) ) {
2023
-
2024
- classifyResult.loc = IntersectionLocationType.ORIGIN;
2025
- classifyResult.t = 0;
2026
- return;
2027
-
2028
- }
2029
-
2030
- if ( ( p.x === edgeEnd.x ) && ( p.y === edgeEnd.y ) ) {
2031
-
2032
- classifyResult.loc = IntersectionLocationType.DESTINATION;
2033
- classifyResult.t = 1;
2034
- return;
2035
-
2036
- }
2037
-
2038
- if ( sa < - Number.EPSILON ) {
2039
-
2040
- classifyResult.loc = IntersectionLocationType.LEFT;
2041
- return;
2042
-
2043
- }
2044
-
2045
- if ( sa > Number.EPSILON ) {
2046
-
2047
- classifyResult.loc = IntersectionLocationType.RIGHT;
2048
- return;
2049
-
2050
-
2051
- }
2052
-
2053
- if ( ( ( ax * bx ) < 0 ) || ( ( ay * by ) < 0 ) ) {
2054
-
2055
- classifyResult.loc = IntersectionLocationType.BEHIND;
2056
- return;
2057
-
2058
- }
2059
-
2060
- if ( ( Math.sqrt( ax * ax + ay * ay ) ) < ( Math.sqrt( bx * bx + by * by ) ) ) {
2061
-
2062
- classifyResult.loc = IntersectionLocationType.BEYOND;
2063
- return;
2064
-
2065
- }
2066
-
2067
- let t;
2068
-
2069
- if ( ax !== 0 ) {
2070
-
2071
- t = bx / ax;
2072
-
2073
- } else {
2074
-
2075
- t = by / ay;
2076
-
2077
- }
2078
-
2079
- classifyResult.loc = IntersectionLocationType.BETWEEN;
2080
- classifyResult.t = t;
2081
-
2082
- }
2083
-
2084
- function getIntersections( path1, path2 ) {
2085
-
2086
- const intersectionsRaw = [];
2087
- const intersections = [];
2088
-
2089
- for ( let index = 1; index < path1.length; index ++ ) {
2090
-
2091
- const path1EdgeStart = path1[ index - 1 ];
2092
- const path1EdgeEnd = path1[ index ];
2093
-
2094
- for ( let index2 = 1; index2 < path2.length; index2 ++ ) {
2095
-
2096
- const path2EdgeStart = path2[ index2 - 1 ];
2097
- const path2EdgeEnd = path2[ index2 ];
2098
-
2099
- const intersection = findEdgeIntersection( path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd );
2100
-
2101
- if ( intersection !== null && intersectionsRaw.find( i => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON ) === undefined ) {
2102
-
2103
- intersectionsRaw.push( intersection );
2104
- intersections.push( new Vector2( intersection.x, intersection.y ) );
2105
-
2106
- }
2107
-
2108
- }
2109
-
2110
- }
2111
-
2112
- return intersections;
2113
-
2114
- }
2115
-
2116
- function getScanlineIntersections( scanline, boundingBox, paths ) {
2117
-
2118
- const center = new Vector2();
2119
- boundingBox.getCenter( center );
2120
-
2121
- const allIntersections = [];
2122
-
2123
- paths.forEach( path => {
2124
-
2125
- // check if the center of the bounding box is in the bounding box of the paths.
2126
- // this is a pruning method to limit the search of intersections in paths that can't envelop of the current path.
2127
- // if a path envelops another path. The center of that oter path, has to be inside the bounding box of the enveloping path.
2128
- if ( path.boundingBox.containsPoint( center ) ) {
2129
-
2130
- const intersections = getIntersections( scanline, path.points );
2131
-
2132
- intersections.forEach( p => {
2133
-
2134
- allIntersections.push( { identifier: path.identifier, isCW: path.isCW, point: p } );
2135
-
2136
- } );
2137
-
2138
- }
2139
-
2140
- } );
2141
-
2142
- allIntersections.sort( ( i1, i2 ) => {
2143
-
2144
- return i1.point.x - i2.point.x;
2145
-
2146
- } );
2147
-
2148
- return allIntersections;
2149
-
2150
- }
2151
-
2152
- function isHoleTo( simplePath, allPaths, scanlineMinX, scanlineMaxX, _fillRule ) {
2153
-
2154
- if ( _fillRule === null || _fillRule === undefined || _fillRule === '' ) {
2155
-
2156
- _fillRule = 'nonzero';
2157
-
2158
- }
2159
-
2160
- const centerBoundingBox = new Vector2();
2161
- simplePath.boundingBox.getCenter( centerBoundingBox );
2162
-
2163
- const scanline = [ new Vector2( scanlineMinX, centerBoundingBox.y ), new Vector2( scanlineMaxX, centerBoundingBox.y ) ];
2164
-
2165
- const scanlineIntersections = getScanlineIntersections( scanline, simplePath.boundingBox, allPaths );
2166
-
2167
- scanlineIntersections.sort( ( i1, i2 ) => {
2168
-
2169
- return i1.point.x - i2.point.x;
2170
-
2171
- } );
2172
-
2173
- const baseIntersections = [];
2174
- const otherIntersections = [];
2175
-
2176
- scanlineIntersections.forEach( i => {
2177
-
2178
- if ( i.identifier === simplePath.identifier ) {
2179
-
2180
- baseIntersections.push( i );
2181
-
2182
- } else {
2183
-
2184
- otherIntersections.push( i );
2185
-
2186
- }
2187
-
2188
- } );
2189
-
2190
- const firstXOfPath = baseIntersections[ 0 ].point.x;
2191
-
2192
- // build up the path hierarchy
2193
- const stack = [];
2194
- let i = 0;
2195
-
2196
- while ( i < otherIntersections.length && otherIntersections[ i ].point.x < firstXOfPath ) {
2197
-
2198
- if ( stack.length > 0 && stack[ stack.length - 1 ] === otherIntersections[ i ].identifier ) {
2199
-
2200
- stack.pop();
2201
-
2202
- } else {
2203
-
2204
- stack.push( otherIntersections[ i ].identifier );
2205
-
2206
- }
2207
-
2208
- i ++;
2209
-
2210
- }
2211
-
2212
- stack.push( simplePath.identifier );
2213
-
2214
- if ( _fillRule === 'evenodd' ) {
2215
-
2216
- const isHole = stack.length % 2 === 0 ? true : false;
2217
- const isHoleFor = stack[ stack.length - 2 ];
2218
-
2219
- return { identifier: simplePath.identifier, isHole: isHole, for: isHoleFor };
2220
-
2221
- } else if ( _fillRule === 'nonzero' ) {
2222
-
2223
- // check if path is a hole by counting the amount of paths with alternating rotations it has to cross.
2224
- let isHole = true;
2225
- let isHoleFor = null;
2226
- let lastCWValue = null;
2227
-
2228
- for ( let i = 0; i < stack.length; i ++ ) {
2229
-
2230
- const identifier = stack[ i ];
2231
- if ( isHole ) {
2232
-
2233
- lastCWValue = allPaths[ identifier ].isCW;
2234
- isHole = false;
2235
- isHoleFor = identifier;
2236
-
2237
- } else if ( lastCWValue !== allPaths[ identifier ].isCW ) {
2238
-
2239
- lastCWValue = allPaths[ identifier ].isCW;
2240
- isHole = true;
2241
-
2242
- }
2243
-
2244
- }
2245
-
2246
- return { identifier: simplePath.identifier, isHole: isHole, for: isHoleFor };
2247
-
2248
- } else {
2249
-
2250
- console.warn( 'fill-rule: "' + _fillRule + '" is currently not implemented.' );
2251
-
2252
- }
2253
-
2254
- }
2255
-
2256
- // check for self intersecting paths
2257
- // TODO
2258
-
2259
- // check intersecting paths
2260
- // TODO
2261
-
2262
- // prepare paths for hole detection
2263
- let scanlineMinX = BIGNUMBER;
2264
- let scanlineMaxX = - BIGNUMBER;
2265
-
2266
- let simplePaths = shapePath.subPaths.map( p => {
2267
-
2268
- const points = p.getPoints();
2269
- let maxY = - BIGNUMBER;
2270
- let minY = BIGNUMBER;
2271
- let maxX = - BIGNUMBER;
2272
- let minX = BIGNUMBER;
2273
-
2274
- //points.forEach(p => p.y *= -1);
2275
-
2276
- for ( let i = 0; i < points.length; i ++ ) {
2277
-
2278
- const p = points[ i ];
2279
-
2280
- if ( p.y > maxY ) {
2281
-
2282
- maxY = p.y;
2283
-
2284
- }
2285
-
2286
- if ( p.y < minY ) {
2287
-
2288
- minY = p.y;
2289
-
2290
- }
2291
-
2292
- if ( p.x > maxX ) {
2293
-
2294
- maxX = p.x;
2295
-
2296
- }
2297
-
2298
- if ( p.x < minX ) {
2299
-
2300
- minX = p.x;
2301
-
2302
- }
2303
-
2304
- }
2305
-
2306
- //
2307
- if ( scanlineMaxX <= maxX ) {
2308
-
2309
- scanlineMaxX = maxX + 1;
2310
-
2311
- }
2312
-
2313
- if ( scanlineMinX >= minX ) {
2314
-
2315
- scanlineMinX = minX - 1;
2316
-
2317
- }
2318
-
2319
- return { curves: p.curves, points: points, isCW: ShapeUtils.isClockWise( points ), identifier: - 1, boundingBox: new Box2( new Vector2( minX, minY ), new Vector2( maxX, maxY ) ) };
2320
-
2321
- } );
2322
-
2323
- simplePaths = simplePaths.filter( sp => sp.points.length > 1 );
2324
-
2325
- for ( let identifier = 0; identifier < simplePaths.length; identifier ++ ) {
2326
-
2327
- simplePaths[ identifier ].identifier = identifier;
2328
-
2329
- }
2330
-
2331
- // check if path is solid or a hole
2332
- const isAHole = simplePaths.map( p => isHoleTo( p, simplePaths, scanlineMinX, scanlineMaxX, ( shapePath.userData ? shapePath.userData.style.fillRule : undefined ) ) );
2333
-
2334
-
2335
- const shapesToReturn = [];
2336
- simplePaths.forEach( p => {
2337
-
2338
- const amIAHole = isAHole[ p.identifier ];
2339
-
2340
- if ( ! amIAHole.isHole ) {
2341
-
2342
- const shape = new Shape();
2343
- shape.curves = p.curves;
2344
- const holes = isAHole.filter( h => h.isHole && h.for === p.identifier );
2345
- holes.forEach( h => {
2346
-
2347
- const hole = simplePaths[ h.identifier ];
2348
- const path = new Path();
2349
- path.curves = hole.curves;
2350
- shape.holes.push( path );
2351
-
2352
- } );
2353
- shapesToReturn.push( shape );
2354
-
2355
- }
2356
-
2357
- } );
2358
-
2359
- return shapesToReturn;
2360
-
2361
- }
2362
-
2363
- static getStrokeStyle( width, color, lineJoin, lineCap, miterLimit ) {
2364
-
2365
- // Param width: Stroke width
2366
- // Param color: As returned by THREE.Color.getStyle()
2367
- // Param lineJoin: One of "round", "bevel", "miter" or "miter-limit"
2368
- // Param lineCap: One of "round", "square" or "butt"
2369
- // Param miterLimit: Maximum join length, in multiples of the "width" parameter (join is truncated if it exceeds that distance)
2370
- // Returns style object
2371
-
2372
- width = width !== undefined ? width : 1;
2373
- color = color !== undefined ? color : '#000';
2374
- lineJoin = lineJoin !== undefined ? lineJoin : 'miter';
2375
- lineCap = lineCap !== undefined ? lineCap : 'butt';
2376
- miterLimit = miterLimit !== undefined ? miterLimit : 4;
2377
-
2378
- return {
2379
- strokeColor: color,
2380
- strokeWidth: width,
2381
- strokeLineJoin: lineJoin,
2382
- strokeLineCap: lineCap,
2383
- strokeMiterLimit: miterLimit
2384
- };
2385
-
2386
- }
2387
-
2388
- static pointsToStroke( points, style, arcDivisions, minDistance ) {
2389
-
2390
- // Generates a stroke with some width around the given path.
2391
- // The path can be open or closed (last point equals to first point)
2392
- // Param points: Array of Vector2D (the path). Minimum 2 points.
2393
- // Param style: Object with SVG properties as returned by SVGLoader.getStrokeStyle(), or SVGLoader.parse() in the path.userData.style object
2394
- // Params arcDivisions: Arc divisions for round joins and endcaps. (Optional)
2395
- // Param minDistance: Points closer to this distance will be merged. (Optional)
2396
- // Returns BufferGeometry with stroke triangles (In plane z = 0). UV coordinates are generated ('u' along path. 'v' across it, from left to right)
2397
-
2398
- const vertices = [];
2399
- const normals = [];
2400
- const uvs = [];
2401
-
2402
- if ( SVGLoader.pointsToStrokeWithBuffers( points, style, arcDivisions, minDistance, vertices, normals, uvs ) === 0 ) {
2403
-
2404
- return null;
2405
-
2406
- }
2407
-
2408
- const geometry = new BufferGeometry();
2409
- geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
2410
- geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
2411
- geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
2412
-
2413
- return geometry;
2414
-
2415
- }
2416
-
2417
- static pointsToStrokeWithBuffers( points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset ) {
2418
-
2419
- // This function can be called to update existing arrays or buffers.
2420
- // Accepts same parameters as pointsToStroke, plus the buffers and optional offset.
2421
- // Param vertexOffset: Offset vertices to start writing in the buffers (3 elements/vertex for vertices and normals, and 2 elements/vertex for uvs)
2422
- // Returns number of written vertices / normals / uvs pairs
2423
- // if 'vertices' parameter is undefined no triangles will be generated, but the returned vertices count will still be valid (useful to preallocate the buffers)
2424
- // 'normals' and 'uvs' buffers are optional
2425
-
2426
- const tempV2_1 = new Vector2();
2427
- const tempV2_2 = new Vector2();
2428
- const tempV2_3 = new Vector2();
2429
- const tempV2_4 = new Vector2();
2430
- const tempV2_5 = new Vector2();
2431
- const tempV2_6 = new Vector2();
2432
- const tempV2_7 = new Vector2();
2433
- const lastPointL = new Vector2();
2434
- const lastPointR = new Vector2();
2435
- const point0L = new Vector2();
2436
- const point0R = new Vector2();
2437
- const currentPointL = new Vector2();
2438
- const currentPointR = new Vector2();
2439
- const nextPointL = new Vector2();
2440
- const nextPointR = new Vector2();
2441
- const innerPoint = new Vector2();
2442
- const outerPoint = new Vector2();
2443
-
2444
- arcDivisions = arcDivisions !== undefined ? arcDivisions : 12;
2445
- minDistance = minDistance !== undefined ? minDistance : 0.001;
2446
- vertexOffset = vertexOffset !== undefined ? vertexOffset : 0;
2447
-
2448
- // First ensure there are no duplicated points
2449
- points = removeDuplicatedPoints( points );
2450
-
2451
- const numPoints = points.length;
2452
-
2453
- if ( numPoints < 2 ) return 0;
2454
-
2455
- const isClosed = points[ 0 ].equals( points[ numPoints - 1 ] );
2456
-
2457
- let currentPoint;
2458
- let previousPoint = points[ 0 ];
2459
- let nextPoint;
2460
-
2461
- const strokeWidth2 = style.strokeWidth / 2;
2462
-
2463
- const deltaU = 1 / ( numPoints - 1 );
2464
- let u0 = 0, u1;
2465
-
2466
- let innerSideModified;
2467
- let joinIsOnLeftSide;
2468
- let isMiter;
2469
- let initialJoinIsOnLeftSide = false;
2470
-
2471
- let numVertices = 0;
2472
- let currentCoordinate = vertexOffset * 3;
2473
- let currentCoordinateUV = vertexOffset * 2;
2474
-
2475
- // Get initial left and right stroke points
2476
- getNormal( points[ 0 ], points[ 1 ], tempV2_1 ).multiplyScalar( strokeWidth2 );
2477
- lastPointL.copy( points[ 0 ] ).sub( tempV2_1 );
2478
- lastPointR.copy( points[ 0 ] ).add( tempV2_1 );
2479
- point0L.copy( lastPointL );
2480
- point0R.copy( lastPointR );
2481
-
2482
- for ( let iPoint = 1; iPoint < numPoints; iPoint ++ ) {
2483
-
2484
- currentPoint = points[ iPoint ];
2485
-
2486
- // Get next point
2487
- if ( iPoint === numPoints - 1 ) {
2488
-
2489
- if ( isClosed ) {
2490
-
2491
- // Skip duplicated initial point
2492
- nextPoint = points[ 1 ];
2493
-
2494
- } else nextPoint = undefined;
2495
-
2496
- } else {
2497
-
2498
- nextPoint = points[ iPoint + 1 ];
2499
-
2500
- }
2501
-
2502
- // Normal of previous segment in tempV2_1
2503
- const normal1 = tempV2_1;
2504
- getNormal( previousPoint, currentPoint, normal1 );
2505
-
2506
- tempV2_3.copy( normal1 ).multiplyScalar( strokeWidth2 );
2507
- currentPointL.copy( currentPoint ).sub( tempV2_3 );
2508
- currentPointR.copy( currentPoint ).add( tempV2_3 );
2509
-
2510
- u1 = u0 + deltaU;
2511
-
2512
- innerSideModified = false;
2513
-
2514
- if ( nextPoint !== undefined ) {
2515
-
2516
- // Normal of next segment in tempV2_2
2517
- getNormal( currentPoint, nextPoint, tempV2_2 );
2518
-
2519
- tempV2_3.copy( tempV2_2 ).multiplyScalar( strokeWidth2 );
2520
- nextPointL.copy( currentPoint ).sub( tempV2_3 );
2521
- nextPointR.copy( currentPoint ).add( tempV2_3 );
2522
-
2523
- joinIsOnLeftSide = true;
2524
- tempV2_3.subVectors( nextPoint, previousPoint );
2525
- if ( normal1.dot( tempV2_3 ) < 0 ) {
2526
-
2527
- joinIsOnLeftSide = false;
2528
-
2529
- }
2530
-
2531
- if ( iPoint === 1 ) initialJoinIsOnLeftSide = joinIsOnLeftSide;
2532
-
2533
- tempV2_3.subVectors( nextPoint, currentPoint );
2534
- tempV2_3.normalize();
2535
- const dot = Math.abs( normal1.dot( tempV2_3 ) );
2536
-
2537
- // If path is straight, don't create join
2538
- if ( dot > Number.EPSILON ) {
2539
-
2540
- // Compute inner and outer segment intersections
2541
- const miterSide = strokeWidth2 / dot;
2542
- tempV2_3.multiplyScalar( - miterSide );
2543
- tempV2_4.subVectors( currentPoint, previousPoint );
2544
- tempV2_5.copy( tempV2_4 ).setLength( miterSide ).add( tempV2_3 );
2545
- innerPoint.copy( tempV2_5 ).negate();
2546
- const miterLength2 = tempV2_5.length();
2547
- const segmentLengthPrev = tempV2_4.length();
2548
- tempV2_4.divideScalar( segmentLengthPrev );
2549
- tempV2_6.subVectors( nextPoint, currentPoint );
2550
- const segmentLengthNext = tempV2_6.length();
2551
- tempV2_6.divideScalar( segmentLengthNext );
2552
- // Check that previous and next segments doesn't overlap with the innerPoint of intersection
2553
- if ( tempV2_4.dot( innerPoint ) < segmentLengthPrev && tempV2_6.dot( innerPoint ) < segmentLengthNext ) {
2554
-
2555
- innerSideModified = true;
2556
-
2557
- }
2558
-
2559
- outerPoint.copy( tempV2_5 ).add( currentPoint );
2560
- innerPoint.add( currentPoint );
2561
-
2562
- isMiter = false;
2563
-
2564
- if ( innerSideModified ) {
2565
-
2566
- if ( joinIsOnLeftSide ) {
2567
-
2568
- nextPointR.copy( innerPoint );
2569
- currentPointR.copy( innerPoint );
2570
-
2571
- } else {
2572
-
2573
- nextPointL.copy( innerPoint );
2574
- currentPointL.copy( innerPoint );
2575
-
2576
- }
2577
-
2578
- } else {
2579
-
2580
- // The segment triangles are generated here if there was overlapping
2581
-
2582
- makeSegmentTriangles();
2583
-
2584
- }
2585
-
2586
- switch ( style.strokeLineJoin ) {
2587
-
2588
- case 'bevel':
2589
-
2590
- makeSegmentWithBevelJoin( joinIsOnLeftSide, innerSideModified, u1 );
2591
-
2592
- break;
2593
-
2594
- case 'round':
2595
-
2596
- // Segment triangles
2597
-
2598
- createSegmentTrianglesWithMiddleSection( joinIsOnLeftSide, innerSideModified );
2599
-
2600
- // Join triangles
2601
-
2602
- if ( joinIsOnLeftSide ) {
2603
-
2604
- makeCircularSector( currentPoint, currentPointL, nextPointL, u1, 0 );
2605
-
2606
- } else {
2607
-
2608
- makeCircularSector( currentPoint, nextPointR, currentPointR, u1, 1 );
2609
-
2610
- }
2611
-
2612
- break;
2613
-
2614
- case 'miter':
2615
- case 'miter-clip':
2616
- default:
2617
-
2618
- const miterFraction = ( strokeWidth2 * style.strokeMiterLimit ) / miterLength2;
2619
-
2620
- if ( miterFraction < 1 ) {
2621
-
2622
- // The join miter length exceeds the miter limit
2623
-
2624
- if ( style.strokeLineJoin !== 'miter-clip' ) {
2625
-
2626
- makeSegmentWithBevelJoin( joinIsOnLeftSide, innerSideModified, u1 );
2627
- break;
2628
-
2629
- } else {
2630
-
2631
- // Segment triangles
2632
-
2633
- createSegmentTrianglesWithMiddleSection( joinIsOnLeftSide, innerSideModified );
2634
-
2635
- // Miter-clip join triangles
2636
-
2637
- if ( joinIsOnLeftSide ) {
2638
-
2639
- tempV2_6.subVectors( outerPoint, currentPointL ).multiplyScalar( miterFraction ).add( currentPointL );
2640
- tempV2_7.subVectors( outerPoint, nextPointL ).multiplyScalar( miterFraction ).add( nextPointL );
2641
-
2642
- addVertex( currentPointL, u1, 0 );
2643
- addVertex( tempV2_6, u1, 0 );
2644
- addVertex( currentPoint, u1, 0.5 );
2645
-
2646
- addVertex( currentPoint, u1, 0.5 );
2647
- addVertex( tempV2_6, u1, 0 );
2648
- addVertex( tempV2_7, u1, 0 );
2649
-
2650
- addVertex( currentPoint, u1, 0.5 );
2651
- addVertex( tempV2_7, u1, 0 );
2652
- addVertex( nextPointL, u1, 0 );
2653
-
2654
- } else {
2655
-
2656
- tempV2_6.subVectors( outerPoint, currentPointR ).multiplyScalar( miterFraction ).add( currentPointR );
2657
- tempV2_7.subVectors( outerPoint, nextPointR ).multiplyScalar( miterFraction ).add( nextPointR );
2658
-
2659
- addVertex( currentPointR, u1, 1 );
2660
- addVertex( tempV2_6, u1, 1 );
2661
- addVertex( currentPoint, u1, 0.5 );
2662
-
2663
- addVertex( currentPoint, u1, 0.5 );
2664
- addVertex( tempV2_6, u1, 1 );
2665
- addVertex( tempV2_7, u1, 1 );
2666
-
2667
- addVertex( currentPoint, u1, 0.5 );
2668
- addVertex( tempV2_7, u1, 1 );
2669
- addVertex( nextPointR, u1, 1 );
2670
-
2671
- }
2672
-
2673
- }
2674
-
2675
- } else {
2676
-
2677
- // Miter join segment triangles
2678
-
2679
- if ( innerSideModified ) {
2680
-
2681
- // Optimized segment + join triangles
2682
-
2683
- if ( joinIsOnLeftSide ) {
2684
-
2685
- addVertex( lastPointR, u0, 1 );
2686
- addVertex( lastPointL, u0, 0 );
2687
- addVertex( outerPoint, u1, 0 );
2688
-
2689
- addVertex( lastPointR, u0, 1 );
2690
- addVertex( outerPoint, u1, 0 );
2691
- addVertex( innerPoint, u1, 1 );
2692
-
2693
- } else {
2694
-
2695
- addVertex( lastPointR, u0, 1 );
2696
- addVertex( lastPointL, u0, 0 );
2697
- addVertex( outerPoint, u1, 1 );
2698
-
2699
- addVertex( lastPointL, u0, 0 );
2700
- addVertex( innerPoint, u1, 0 );
2701
- addVertex( outerPoint, u1, 1 );
2702
-
2703
- }
2704
-
2705
-
2706
- if ( joinIsOnLeftSide ) {
2707
-
2708
- nextPointL.copy( outerPoint );
2709
-
2710
- } else {
2711
-
2712
- nextPointR.copy( outerPoint );
2713
-
2714
- }
2715
-
2716
-
2717
- } else {
2718
-
2719
- // Add extra miter join triangles
2720
-
2721
- if ( joinIsOnLeftSide ) {
2722
-
2723
- addVertex( currentPointL, u1, 0 );
2724
- addVertex( outerPoint, u1, 0 );
2725
- addVertex( currentPoint, u1, 0.5 );
2726
-
2727
- addVertex( currentPoint, u1, 0.5 );
2728
- addVertex( outerPoint, u1, 0 );
2729
- addVertex( nextPointL, u1, 0 );
2730
-
2731
- } else {
2732
-
2733
- addVertex( currentPointR, u1, 1 );
2734
- addVertex( outerPoint, u1, 1 );
2735
- addVertex( currentPoint, u1, 0.5 );
2736
-
2737
- addVertex( currentPoint, u1, 0.5 );
2738
- addVertex( outerPoint, u1, 1 );
2739
- addVertex( nextPointR, u1, 1 );
2740
-
2741
- }
2742
-
2743
- }
2744
-
2745
- isMiter = true;
2746
-
2747
- }
2748
-
2749
- break;
2750
-
2751
- }
2752
-
2753
- } else {
2754
-
2755
- // The segment triangles are generated here when two consecutive points are collinear
2756
-
2757
- makeSegmentTriangles();
2758
-
2759
- }
2760
-
2761
- } else {
2762
-
2763
- // The segment triangles are generated here if it is the ending segment
2764
-
2765
- makeSegmentTriangles();
2766
-
2767
- }
2768
-
2769
- if ( ! isClosed && iPoint === numPoints - 1 ) {
2770
-
2771
- // Start line endcap
2772
- addCapGeometry( points[ 0 ], point0L, point0R, joinIsOnLeftSide, true, u0 );
2773
-
2774
- }
2775
-
2776
- // Increment loop variables
2777
-
2778
- u0 = u1;
2779
-
2780
- previousPoint = currentPoint;
2781
-
2782
- lastPointL.copy( nextPointL );
2783
- lastPointR.copy( nextPointR );
2784
-
2785
- }
2786
-
2787
- if ( ! isClosed ) {
2788
-
2789
- // Ending line endcap
2790
- addCapGeometry( currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1 );
2791
-
2792
- } else if ( innerSideModified && vertices ) {
2793
-
2794
- // Modify path first segment vertices to adjust to the segments inner and outer intersections
2795
-
2796
- let lastOuter = outerPoint;
2797
- let lastInner = innerPoint;
2798
-
2799
- if ( initialJoinIsOnLeftSide !== joinIsOnLeftSide ) {
2800
-
2801
- lastOuter = innerPoint;
2802
- lastInner = outerPoint;
2803
-
2804
- }
2805
-
2806
- if ( joinIsOnLeftSide ) {
2807
-
2808
- if ( isMiter || initialJoinIsOnLeftSide ) {
2809
-
2810
- lastInner.toArray( vertices, 0 * 3 );
2811
- lastInner.toArray( vertices, 3 * 3 );
2812
-
2813
- if ( isMiter ) {
2814
-
2815
- lastOuter.toArray( vertices, 1 * 3 );
2816
-
2817
- }
2818
-
2819
- }
2820
-
2821
- } else {
2822
-
2823
- if ( isMiter || ! initialJoinIsOnLeftSide ) {
2824
-
2825
- lastInner.toArray( vertices, 1 * 3 );
2826
- lastInner.toArray( vertices, 3 * 3 );
2827
-
2828
- if ( isMiter ) {
2829
-
2830
- lastOuter.toArray( vertices, 0 * 3 );
2831
-
2832
- }
2833
-
2834
- }
2835
-
2836
- }
2837
-
2838
- }
2839
-
2840
- return numVertices;
2841
-
2842
- // -- End of algorithm
2843
-
2844
- // -- Functions
2845
-
2846
- function getNormal( p1, p2, result ) {
2847
-
2848
- result.subVectors( p2, p1 );
2849
- return result.set( - result.y, result.x ).normalize();
2850
-
2851
- }
2852
-
2853
- function addVertex( position, u, v ) {
2854
-
2855
- if ( vertices ) {
2856
-
2857
- vertices[ currentCoordinate ] = position.x;
2858
- vertices[ currentCoordinate + 1 ] = position.y;
2859
- vertices[ currentCoordinate + 2 ] = 0;
2860
-
2861
- if ( normals ) {
2862
-
2863
- normals[ currentCoordinate ] = 0;
2864
- normals[ currentCoordinate + 1 ] = 0;
2865
- normals[ currentCoordinate + 2 ] = 1;
2866
-
2867
- }
2868
-
2869
- currentCoordinate += 3;
2870
-
2871
- if ( uvs ) {
2872
-
2873
- uvs[ currentCoordinateUV ] = u;
2874
- uvs[ currentCoordinateUV + 1 ] = v;
2875
-
2876
- currentCoordinateUV += 2;
2877
-
2878
- }
2879
-
2880
- }
2881
-
2882
- numVertices += 3;
2883
-
2884
- }
2885
-
2886
- function makeCircularSector( center, p1, p2, u, v ) {
2887
-
2888
- // param p1, p2: Points in the circle arc.
2889
- // p1 and p2 are in clockwise direction.
2890
-
2891
- tempV2_1.copy( p1 ).sub( center ).normalize();
2892
- tempV2_2.copy( p2 ).sub( center ).normalize();
2893
-
2894
- let angle = Math.PI;
2895
- const dot = tempV2_1.dot( tempV2_2 );
2896
- if ( Math.abs( dot ) < 1 ) angle = Math.abs( Math.acos( dot ) );
2897
-
2898
- angle /= arcDivisions;
2899
-
2900
- tempV2_3.copy( p1 );
2901
-
2902
- for ( let i = 0, il = arcDivisions - 1; i < il; i ++ ) {
2903
-
2904
- tempV2_4.copy( tempV2_3 ).rotateAround( center, angle );
2905
-
2906
- addVertex( tempV2_3, u, v );
2907
- addVertex( tempV2_4, u, v );
2908
- addVertex( center, u, 0.5 );
2909
-
2910
- tempV2_3.copy( tempV2_4 );
2911
-
2912
- }
2913
-
2914
- addVertex( tempV2_4, u, v );
2915
- addVertex( p2, u, v );
2916
- addVertex( center, u, 0.5 );
2917
-
2918
- }
2919
-
2920
- function makeSegmentTriangles() {
2921
-
2922
- addVertex( lastPointR, u0, 1 );
2923
- addVertex( lastPointL, u0, 0 );
2924
- addVertex( currentPointL, u1, 0 );
2925
-
2926
- addVertex( lastPointR, u0, 1 );
2927
- addVertex( currentPointL, u1, 1 );
2928
- addVertex( currentPointR, u1, 0 );
2929
-
2930
- }
2931
-
2932
- function makeSegmentWithBevelJoin( joinIsOnLeftSide, innerSideModified, u ) {
2933
-
2934
- if ( innerSideModified ) {
2935
-
2936
- // Optimized segment + bevel triangles
2937
-
2938
- if ( joinIsOnLeftSide ) {
2939
-
2940
- // Path segments triangles
2941
-
2942
- addVertex( lastPointR, u0, 1 );
2943
- addVertex( lastPointL, u0, 0 );
2944
- addVertex( currentPointL, u1, 0 );
2945
-
2946
- addVertex( lastPointR, u0, 1 );
2947
- addVertex( currentPointL, u1, 0 );
2948
- addVertex( innerPoint, u1, 1 );
2949
-
2950
- // Bevel join triangle
2951
-
2952
- addVertex( currentPointL, u, 0 );
2953
- addVertex( nextPointL, u, 0 );
2954
- addVertex( innerPoint, u, 0.5 );
2955
-
2956
- } else {
2957
-
2958
- // Path segments triangles
2959
-
2960
- addVertex( lastPointR, u0, 1 );
2961
- addVertex( lastPointL, u0, 0 );
2962
- addVertex( currentPointR, u1, 1 );
2963
-
2964
- addVertex( lastPointL, u0, 0 );
2965
- addVertex( innerPoint, u1, 0 );
2966
- addVertex( currentPointR, u1, 1 );
2967
-
2968
- // Bevel join triangle
2969
-
2970
- addVertex( currentPointR, u, 1 );
2971
- addVertex( nextPointR, u, 0 );
2972
- addVertex( innerPoint, u, 0.5 );
2973
-
2974
- }
2975
-
2976
- } else {
2977
-
2978
- // Bevel join triangle. The segment triangles are done in the main loop
2979
-
2980
- if ( joinIsOnLeftSide ) {
2981
-
2982
- addVertex( currentPointL, u, 0 );
2983
- addVertex( nextPointL, u, 0 );
2984
- addVertex( currentPoint, u, 0.5 );
2985
-
2986
- } else {
2987
-
2988
- addVertex( currentPointR, u, 1 );
2989
- addVertex( nextPointR, u, 0 );
2990
- addVertex( currentPoint, u, 0.5 );
2991
-
2992
- }
2993
-
2994
- }
2995
-
2996
- }
2997
-
2998
- function createSegmentTrianglesWithMiddleSection( joinIsOnLeftSide, innerSideModified ) {
2999
-
3000
- if ( innerSideModified ) {
3001
-
3002
- if ( joinIsOnLeftSide ) {
3003
-
3004
- addVertex( lastPointR, u0, 1 );
3005
- addVertex( lastPointL, u0, 0 );
3006
- addVertex( currentPointL, u1, 0 );
3007
-
3008
- addVertex( lastPointR, u0, 1 );
3009
- addVertex( currentPointL, u1, 0 );
3010
- addVertex( innerPoint, u1, 1 );
3011
-
3012
- addVertex( currentPointL, u0, 0 );
3013
- addVertex( currentPoint, u1, 0.5 );
3014
- addVertex( innerPoint, u1, 1 );
3015
-
3016
- addVertex( currentPoint, u1, 0.5 );
3017
- addVertex( nextPointL, u0, 0 );
3018
- addVertex( innerPoint, u1, 1 );
3019
-
3020
- } else {
3021
-
3022
- addVertex( lastPointR, u0, 1 );
3023
- addVertex( lastPointL, u0, 0 );
3024
- addVertex( currentPointR, u1, 1 );
3025
-
3026
- addVertex( lastPointL, u0, 0 );
3027
- addVertex( innerPoint, u1, 0 );
3028
- addVertex( currentPointR, u1, 1 );
3029
-
3030
- addVertex( currentPointR, u0, 1 );
3031
- addVertex( innerPoint, u1, 0 );
3032
- addVertex( currentPoint, u1, 0.5 );
3033
-
3034
- addVertex( currentPoint, u1, 0.5 );
3035
- addVertex( innerPoint, u1, 0 );
3036
- addVertex( nextPointR, u0, 1 );
3037
-
3038
- }
3039
-
3040
- }
3041
-
3042
- }
3043
-
3044
- function addCapGeometry( center, p1, p2, joinIsOnLeftSide, start, u ) {
3045
-
3046
- // param center: End point of the path
3047
- // param p1, p2: Left and right cap points
3048
-
3049
- switch ( style.strokeLineCap ) {
3050
-
3051
- case 'round':
3052
-
3053
- if ( start ) {
3054
-
3055
- makeCircularSector( center, p2, p1, u, 0.5 );
3056
-
3057
- } else {
3058
-
3059
- makeCircularSector( center, p1, p2, u, 0.5 );
3060
-
3061
- }
3062
-
3063
- break;
3064
-
3065
- case 'square':
3066
-
3067
- if ( start ) {
3068
-
3069
- tempV2_1.subVectors( p1, center );
3070
- tempV2_2.set( tempV2_1.y, - tempV2_1.x );
3071
-
3072
- tempV2_3.addVectors( tempV2_1, tempV2_2 ).add( center );
3073
- tempV2_4.subVectors( tempV2_2, tempV2_1 ).add( center );
3074
-
3075
- // Modify already existing vertices
3076
- if ( joinIsOnLeftSide ) {
3077
-
3078
- tempV2_3.toArray( vertices, 1 * 3 );
3079
- tempV2_4.toArray( vertices, 0 * 3 );
3080
- tempV2_4.toArray( vertices, 3 * 3 );
3081
-
3082
- } else {
3083
-
3084
- tempV2_3.toArray( vertices, 1 * 3 );
3085
- tempV2_3.toArray( vertices, 3 * 3 );
3086
- tempV2_4.toArray( vertices, 0 * 3 );
3087
-
3088
- }
3089
-
3090
- } else {
3091
-
3092
- tempV2_1.subVectors( p2, center );
3093
- tempV2_2.set( tempV2_1.y, - tempV2_1.x );
3094
-
3095
- tempV2_3.addVectors( tempV2_1, tempV2_2 ).add( center );
3096
- tempV2_4.subVectors( tempV2_2, tempV2_1 ).add( center );
3097
-
3098
- const vl = vertices.length;
3099
-
3100
- // Modify already existing vertices
3101
- if ( joinIsOnLeftSide ) {
3102
-
3103
- tempV2_3.toArray( vertices, vl - 1 * 3 );
3104
- tempV2_4.toArray( vertices, vl - 2 * 3 );
3105
- tempV2_4.toArray( vertices, vl - 4 * 3 );
3106
-
3107
- } else {
3108
-
3109
- tempV2_3.toArray( vertices, vl - 2 * 3 );
3110
- tempV2_4.toArray( vertices, vl - 1 * 3 );
3111
- tempV2_4.toArray( vertices, vl - 4 * 3 );
3112
-
3113
- }
3114
-
3115
- }
3116
-
3117
- break;
3118
-
3119
- case 'butt':
3120
- default:
3121
-
3122
- // Nothing to do here
3123
- break;
3124
-
3125
- }
3126
-
3127
- }
3128
-
3129
- function removeDuplicatedPoints( points ) {
3130
-
3131
- // Creates a new array if necessary with duplicated points removed.
3132
- // This does not remove duplicated initial and ending points of a closed path.
3133
-
3134
- let dupPoints = false;
3135
- for ( let i = 1, n = points.length - 1; i < n; i ++ ) {
3136
-
3137
- if ( points[ i ].distanceTo( points[ i + 1 ] ) < minDistance ) {
3138
-
3139
- dupPoints = true;
3140
- break;
3141
-
3142
- }
3143
-
3144
- }
3145
-
3146
- if ( ! dupPoints ) return points;
3147
-
3148
- const newPoints = [];
3149
- newPoints.push( points[ 0 ] );
3150
-
3151
- for ( let i = 1, n = points.length - 1; i < n; i ++ ) {
3152
-
3153
- if ( points[ i ].distanceTo( points[ i + 1 ] ) >= minDistance ) {
3154
-
3155
- newPoints.push( points[ i ] );
3156
-
3157
- }
3158
-
3159
- }
3160
-
3161
- newPoints.push( points[ points.length - 1 ] );
3162
-
3163
- return newPoints;
3164
-
3165
- }
3166
-
3167
- }
3168
-
3169
-
3170
- }
3171
-
3172
- export { SVGLoader };