three-stdlib 2.35.4 → 2.35.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (514) hide show
  1. package/_polyfill/CapsuleGeometry.cjs +17 -20
  2. package/_polyfill/CapsuleGeometry.cjs.map +1 -1
  3. package/_polyfill/CapsuleGeometry.js +17 -20
  4. package/_polyfill/CapsuleGeometry.js.map +1 -1
  5. package/_polyfill/constants.cjs +1 -1
  6. package/_polyfill/constants.cjs.map +1 -1
  7. package/_polyfill/constants.js +1 -1
  8. package/_polyfill/constants.js.map +1 -1
  9. package/animation/AnimationClipCreator.cjs +13 -13
  10. package/animation/AnimationClipCreator.cjs.map +1 -1
  11. package/animation/AnimationClipCreator.js +13 -13
  12. package/animation/AnimationClipCreator.js.map +1 -1
  13. package/animation/CCDIKSolver.cjs +11 -11
  14. package/animation/CCDIKSolver.cjs.map +1 -1
  15. package/animation/CCDIKSolver.js +12 -12
  16. package/animation/CCDIKSolver.js.map +1 -1
  17. package/animation/MMDAnimationHelper.cjs +1 -1
  18. package/animation/MMDAnimationHelper.cjs.map +1 -1
  19. package/animation/MMDAnimationHelper.js +1 -1
  20. package/animation/MMDAnimationHelper.js.map +1 -1
  21. package/animation/MMDPhysics.cjs +4 -4
  22. package/animation/MMDPhysics.cjs.map +1 -1
  23. package/animation/MMDPhysics.js +4 -4
  24. package/animation/MMDPhysics.js.map +1 -1
  25. package/controls/ArcballControls.cjs +2 -2
  26. package/controls/ArcballControls.cjs.map +1 -1
  27. package/controls/ArcballControls.js +3 -3
  28. package/controls/ArcballControls.js.map +1 -1
  29. package/controls/FirstPersonControls.cjs +1 -1
  30. package/controls/FirstPersonControls.cjs.map +1 -1
  31. package/controls/FirstPersonControls.js +1 -1
  32. package/controls/FirstPersonControls.js.map +1 -1
  33. package/controls/OrbitControls.cjs +2 -2
  34. package/controls/OrbitControls.cjs.map +1 -1
  35. package/controls/OrbitControls.js +3 -3
  36. package/controls/OrbitControls.js.map +1 -1
  37. package/controls/PointerLockControls.cjs +2 -2
  38. package/controls/PointerLockControls.cjs.map +1 -1
  39. package/controls/PointerLockControls.js +3 -3
  40. package/controls/PointerLockControls.js.map +1 -1
  41. package/csm/CSM.cjs +4 -4
  42. package/csm/CSM.cjs.map +1 -1
  43. package/csm/CSM.js +5 -5
  44. package/csm/CSM.js.map +1 -1
  45. package/csm/CSMFrustum.cjs +1 -1
  46. package/csm/CSMFrustum.cjs.map +1 -1
  47. package/csm/CSMFrustum.js +2 -2
  48. package/csm/CSMFrustum.js.map +1 -1
  49. package/deprecated/Geometry.cjs +715 -722
  50. package/deprecated/Geometry.cjs.map +1 -1
  51. package/deprecated/Geometry.js +716 -723
  52. package/deprecated/Geometry.js.map +1 -1
  53. package/effects/AnaglyphEffect.cjs +1 -2
  54. package/effects/AnaglyphEffect.cjs.map +1 -1
  55. package/effects/AnaglyphEffect.js +2 -3
  56. package/effects/AnaglyphEffect.js.map +1 -1
  57. package/effects/OutlineEffect.cjs +1 -2
  58. package/effects/OutlineEffect.cjs.map +1 -1
  59. package/effects/OutlineEffect.js +2 -3
  60. package/effects/OutlineEffect.js.map +1 -1
  61. package/effects/ParallaxBarrierEffect.cjs +1 -2
  62. package/effects/ParallaxBarrierEffect.cjs.map +1 -1
  63. package/effects/ParallaxBarrierEffect.js +2 -3
  64. package/effects/ParallaxBarrierEffect.js.map +1 -1
  65. package/exporters/DRACOExporter.cjs +122 -133
  66. package/exporters/DRACOExporter.cjs.map +1 -1
  67. package/exporters/DRACOExporter.d.ts +21 -23
  68. package/exporters/DRACOExporter.js +122 -133
  69. package/exporters/DRACOExporter.js.map +1 -1
  70. package/exporters/GLTFExporter.cjs +167 -170
  71. package/exporters/GLTFExporter.cjs.map +1 -1
  72. package/exporters/GLTFExporter.js +167 -170
  73. package/exporters/GLTFExporter.js.map +1 -1
  74. package/geometries/LightningStrike.cjs +515 -524
  75. package/geometries/LightningStrike.cjs.map +1 -1
  76. package/geometries/LightningStrike.js +515 -524
  77. package/geometries/LightningStrike.js.map +1 -1
  78. package/geometries/RoundedBoxGeometry.cjs +1 -1
  79. package/geometries/RoundedBoxGeometry.cjs.map +1 -1
  80. package/geometries/RoundedBoxGeometry.js +2 -2
  81. package/geometries/RoundedBoxGeometry.js.map +1 -1
  82. package/helpers/RaycasterHelper.cjs +2 -2
  83. package/helpers/RaycasterHelper.cjs.map +1 -1
  84. package/helpers/RaycasterHelper.js +3 -3
  85. package/helpers/RaycasterHelper.js.map +1 -1
  86. package/helpers/VertexNormalsHelper.cjs +3 -3
  87. package/helpers/VertexNormalsHelper.cjs.map +1 -1
  88. package/helpers/VertexNormalsHelper.js +4 -4
  89. package/helpers/VertexNormalsHelper.js.map +1 -1
  90. package/helpers/VertexTangentsHelper.cjs +2 -2
  91. package/helpers/VertexTangentsHelper.cjs.map +1 -1
  92. package/helpers/VertexTangentsHelper.js +3 -3
  93. package/helpers/VertexTangentsHelper.js.map +1 -1
  94. package/interactive/InteractiveGroup.cjs +1 -1
  95. package/interactive/InteractiveGroup.cjs.map +1 -1
  96. package/interactive/InteractiveGroup.js +2 -2
  97. package/interactive/InteractiveGroup.js.map +1 -1
  98. package/interactive/SelectionBox.cjs +15 -15
  99. package/interactive/SelectionBox.cjs.map +1 -1
  100. package/interactive/SelectionBox.js +16 -16
  101. package/interactive/SelectionBox.js.map +1 -1
  102. package/libs/chevrotain.cjs +1 -1
  103. package/libs/chevrotain.cjs.map +1 -1
  104. package/libs/chevrotain.js +1 -1
  105. package/libs/chevrotain.js.map +1 -1
  106. package/libs/lottie.cjs +1 -1
  107. package/libs/lottie.cjs.map +1 -1
  108. package/libs/lottie.js +1 -1
  109. package/libs/lottie.js.map +1 -1
  110. package/libs/opentype.cjs +1 -1
  111. package/libs/opentype.cjs.map +1 -1
  112. package/libs/opentype.js +1 -1
  113. package/libs/opentype.js.map +1 -1
  114. package/lights/LightProbeGenerator.cjs +5 -5
  115. package/lights/LightProbeGenerator.cjs.map +1 -1
  116. package/lights/LightProbeGenerator.js +5 -5
  117. package/lights/LightProbeGenerator.js.map +1 -1
  118. package/lights/RectAreaLightUniformsLib.cjs +3 -3
  119. package/lights/RectAreaLightUniformsLib.cjs.map +1 -1
  120. package/lights/RectAreaLightUniformsLib.js +3 -3
  121. package/lights/RectAreaLightUniformsLib.js.map +1 -1
  122. package/lines/LineMaterial.cjs +1 -2
  123. package/lines/LineMaterial.cjs.map +1 -1
  124. package/lines/LineMaterial.js +2 -3
  125. package/lines/LineMaterial.js.map +1 -1
  126. package/lines/LineSegments2.cjs +13 -13
  127. package/lines/LineSegments2.cjs.map +1 -1
  128. package/lines/LineSegments2.js +14 -14
  129. package/lines/LineSegments2.js.map +1 -1
  130. package/lines/LineSegmentsGeometry.cjs +2 -2
  131. package/lines/LineSegmentsGeometry.cjs.map +1 -1
  132. package/lines/LineSegmentsGeometry.js +3 -3
  133. package/lines/LineSegmentsGeometry.js.map +1 -1
  134. package/lines/Wireframe.cjs +3 -3
  135. package/lines/Wireframe.cjs.map +1 -1
  136. package/lines/Wireframe.js +4 -4
  137. package/lines/Wireframe.js.map +1 -1
  138. package/loaders/BasisTextureLoader.cjs +435 -441
  139. package/loaders/BasisTextureLoader.cjs.map +1 -1
  140. package/loaders/BasisTextureLoader.js +435 -441
  141. package/loaders/BasisTextureLoader.js.map +1 -1
  142. package/loaders/EXRLoader.cjs +1 -2
  143. package/loaders/EXRLoader.cjs.map +1 -1
  144. package/loaders/EXRLoader.js +2 -3
  145. package/loaders/EXRLoader.js.map +1 -1
  146. package/loaders/FBXLoader.cjs +2 -2
  147. package/loaders/FBXLoader.cjs.map +1 -1
  148. package/loaders/FBXLoader.js +2 -2
  149. package/loaders/FBXLoader.js.map +1 -1
  150. package/loaders/FontLoader.cjs +2 -2
  151. package/loaders/FontLoader.cjs.map +1 -1
  152. package/loaders/FontLoader.d.ts +2 -2
  153. package/loaders/FontLoader.js +2 -2
  154. package/loaders/FontLoader.js.map +1 -1
  155. package/loaders/GLTFLoader.cjs +2 -2
  156. package/loaders/GLTFLoader.cjs.map +1 -1
  157. package/loaders/GLTFLoader.js +2 -2
  158. package/loaders/GLTFLoader.js.map +1 -1
  159. package/loaders/KTX2Loader.cjs +374 -377
  160. package/loaders/KTX2Loader.cjs.map +1 -1
  161. package/loaders/KTX2Loader.js +374 -377
  162. package/loaders/KTX2Loader.js.map +1 -1
  163. package/loaders/LDrawLoader.cjs +4 -5
  164. package/loaders/LDrawLoader.cjs.map +1 -1
  165. package/loaders/LDrawLoader.js +5 -6
  166. package/loaders/LDrawLoader.js.map +1 -1
  167. package/loaders/OBJLoader.cjs +5 -5
  168. package/loaders/OBJLoader.cjs.map +1 -1
  169. package/loaders/OBJLoader.js +6 -6
  170. package/loaders/OBJLoader.js.map +1 -1
  171. package/loaders/PRWMLoader.cjs +43 -46
  172. package/loaders/PRWMLoader.cjs.map +1 -1
  173. package/loaders/PRWMLoader.js +43 -46
  174. package/loaders/PRWMLoader.js.map +1 -1
  175. package/loaders/SVGLoader.cjs +1688 -1694
  176. package/loaders/SVGLoader.cjs.map +1 -1
  177. package/loaders/SVGLoader.js +1688 -1694
  178. package/loaders/SVGLoader.js.map +1 -1
  179. package/loaders/XLoader.cjs +1 -1
  180. package/loaders/XLoader.cjs.map +1 -1
  181. package/loaders/XLoader.js +1 -1
  182. package/loaders/XLoader.js.map +1 -1
  183. package/math/Capsule.cjs +3 -3
  184. package/math/Capsule.cjs.map +1 -1
  185. package/math/Capsule.js +3 -3
  186. package/math/Capsule.js.map +1 -1
  187. package/math/ColorConverter.cjs +9 -9
  188. package/math/ColorConverter.cjs.map +1 -1
  189. package/math/ColorConverter.js +9 -9
  190. package/math/ColorConverter.js.map +1 -1
  191. package/math/ConvexHull.cjs +50 -53
  192. package/math/ConvexHull.cjs.map +1 -1
  193. package/math/ConvexHull.js +50 -53
  194. package/math/ConvexHull.js.map +1 -1
  195. package/math/ImprovedNoise.cjs +1 -1
  196. package/math/ImprovedNoise.cjs.map +1 -1
  197. package/math/ImprovedNoise.js +1 -1
  198. package/math/ImprovedNoise.js.map +1 -1
  199. package/math/MeshSurfaceSampler.cjs +2 -2
  200. package/math/MeshSurfaceSampler.cjs.map +1 -1
  201. package/math/MeshSurfaceSampler.js +2 -2
  202. package/math/MeshSurfaceSampler.js.map +1 -1
  203. package/math/OBB.cjs +14 -14
  204. package/math/OBB.cjs.map +1 -1
  205. package/math/OBB.js +15 -15
  206. package/math/OBB.js.map +1 -1
  207. package/math/Octree.cjs +7 -7
  208. package/math/Octree.cjs.map +1 -1
  209. package/math/Octree.js +8 -8
  210. package/math/Octree.js.map +1 -1
  211. package/misc/ConvexObjectBreaker.cjs +268 -271
  212. package/misc/ConvexObjectBreaker.cjs.map +1 -1
  213. package/misc/ConvexObjectBreaker.js +269 -272
  214. package/misc/ConvexObjectBreaker.js.map +1 -1
  215. package/misc/Gyroscope.cjs +6 -6
  216. package/misc/Gyroscope.cjs.map +1 -1
  217. package/misc/Gyroscope.js +7 -7
  218. package/misc/Gyroscope.js.map +1 -1
  219. package/modifiers/CurveModifier.cjs +1 -1
  220. package/modifiers/CurveModifier.cjs.map +1 -1
  221. package/modifiers/CurveModifier.js +2 -2
  222. package/modifiers/CurveModifier.js.map +1 -1
  223. package/modifiers/SimplifyModifier.cjs +2 -2
  224. package/modifiers/SimplifyModifier.cjs.map +1 -1
  225. package/modifiers/SimplifyModifier.js +2 -2
  226. package/modifiers/SimplifyModifier.js.map +1 -1
  227. package/objects/BatchedMesh.cjs +2 -2
  228. package/objects/BatchedMesh.cjs.map +1 -1
  229. package/objects/BatchedMesh.js +3 -3
  230. package/objects/BatchedMesh.js.map +1 -1
  231. package/objects/GroundProjectedEnv.cjs +1 -2
  232. package/objects/GroundProjectedEnv.cjs.map +1 -1
  233. package/objects/GroundProjectedEnv.js +2 -3
  234. package/objects/GroundProjectedEnv.js.map +1 -1
  235. package/objects/Lensflare.cjs +206 -209
  236. package/objects/Lensflare.cjs.map +1 -1
  237. package/objects/Lensflare.js +206 -209
  238. package/objects/Lensflare.js.map +1 -1
  239. package/objects/Reflector.cjs +146 -154
  240. package/objects/Reflector.cjs.map +1 -1
  241. package/objects/Reflector.js +146 -154
  242. package/objects/Reflector.js.map +1 -1
  243. package/objects/ReflectorForSSRPass.cjs +180 -183
  244. package/objects/ReflectorForSSRPass.cjs.map +1 -1
  245. package/objects/ReflectorForSSRPass.js +180 -183
  246. package/objects/ReflectorForSSRPass.js.map +1 -1
  247. package/objects/Refractor.cjs +161 -164
  248. package/objects/Refractor.cjs.map +1 -1
  249. package/objects/Refractor.js +161 -164
  250. package/objects/Refractor.js.map +1 -1
  251. package/objects/ShadowMesh.cjs +1 -1
  252. package/objects/ShadowMesh.cjs.map +1 -1
  253. package/objects/ShadowMesh.js +2 -2
  254. package/objects/ShadowMesh.js.map +1 -1
  255. package/objects/Sky.cjs +32 -35
  256. package/objects/Sky.cjs.map +1 -1
  257. package/objects/Sky.d.ts +6 -100
  258. package/objects/Sky.js +32 -35
  259. package/objects/Sky.js.map +1 -1
  260. package/objects/Water.cjs +1 -2
  261. package/objects/Water.cjs.map +1 -1
  262. package/objects/Water.js +2 -3
  263. package/objects/Water.js.map +1 -1
  264. package/objects/Water2.cjs +140 -143
  265. package/objects/Water2.cjs.map +1 -1
  266. package/objects/Water2.js +140 -143
  267. package/objects/Water2.js.map +1 -1
  268. package/package.json +1 -1
  269. package/postprocessing/SAOPass.cjs +264 -267
  270. package/postprocessing/SAOPass.cjs.map +1 -1
  271. package/postprocessing/SAOPass.js +264 -267
  272. package/postprocessing/SAOPass.js.map +1 -1
  273. package/postprocessing/SSAOPass.cjs +250 -253
  274. package/postprocessing/SSAOPass.cjs.map +1 -1
  275. package/postprocessing/SSAOPass.js +250 -253
  276. package/postprocessing/SSAOPass.js.map +1 -1
  277. package/postprocessing/SSRPass.cjs +376 -379
  278. package/postprocessing/SSRPass.cjs.map +1 -1
  279. package/postprocessing/SSRPass.js +376 -379
  280. package/postprocessing/SSRPass.js.map +1 -1
  281. package/postprocessing/UnrealBloomPass.cjs +202 -205
  282. package/postprocessing/UnrealBloomPass.cjs.map +1 -1
  283. package/postprocessing/UnrealBloomPass.js +202 -205
  284. package/postprocessing/UnrealBloomPass.js.map +1 -1
  285. package/renderers/CSS2DRenderer.cjs +5 -5
  286. package/renderers/CSS2DRenderer.cjs.map +1 -1
  287. package/renderers/CSS2DRenderer.js +5 -5
  288. package/renderers/CSS2DRenderer.js.map +1 -1
  289. package/renderers/CSS3DRenderer.cjs +5 -5
  290. package/renderers/CSS3DRenderer.cjs.map +1 -1
  291. package/renderers/CSS3DRenderer.js +6 -6
  292. package/renderers/CSS3DRenderer.js.map +1 -1
  293. package/shaders/ACESFilmicToneMappingShader.cjs +46 -71
  294. package/shaders/ACESFilmicToneMappingShader.cjs.map +1 -1
  295. package/shaders/ACESFilmicToneMappingShader.js +46 -71
  296. package/shaders/ACESFilmicToneMappingShader.js.map +1 -1
  297. package/shaders/AfterimageShader.cjs +22 -41
  298. package/shaders/AfterimageShader.cjs.map +1 -1
  299. package/shaders/AfterimageShader.js +22 -41
  300. package/shaders/AfterimageShader.js.map +1 -1
  301. package/shaders/BasicShader.cjs +6 -20
  302. package/shaders/BasicShader.cjs.map +1 -1
  303. package/shaders/BasicShader.js +6 -20
  304. package/shaders/BasicShader.js.map +1 -1
  305. package/shaders/BleachBypassShader.cjs +26 -46
  306. package/shaders/BleachBypassShader.cjs.map +1 -1
  307. package/shaders/BleachBypassShader.js +26 -46
  308. package/shaders/BleachBypassShader.js.map +1 -1
  309. package/shaders/BlendShader.cjs +19 -33
  310. package/shaders/BlendShader.cjs.map +1 -1
  311. package/shaders/BlendShader.js +19 -33
  312. package/shaders/BlendShader.js.map +1 -1
  313. package/shaders/BokehShader.cjs +90 -117
  314. package/shaders/BokehShader.cjs.map +1 -1
  315. package/shaders/BokehShader.js +90 -117
  316. package/shaders/BokehShader.js.map +1 -1
  317. package/shaders/BokehShader2.cjs +232 -333
  318. package/shaders/BokehShader2.cjs.map +1 -1
  319. package/shaders/BokehShader2.js +232 -333
  320. package/shaders/BokehShader2.js.map +1 -1
  321. package/shaders/BrightnessContrastShader.cjs +22 -38
  322. package/shaders/BrightnessContrastShader.cjs.map +1 -1
  323. package/shaders/BrightnessContrastShader.js +22 -38
  324. package/shaders/BrightnessContrastShader.js.map +1 -1
  325. package/shaders/ColorCorrectionShader.cjs +21 -35
  326. package/shaders/ColorCorrectionShader.cjs.map +1 -1
  327. package/shaders/ColorCorrectionShader.js +21 -35
  328. package/shaders/ColorCorrectionShader.js.map +1 -1
  329. package/shaders/ColorifyShader.cjs +19 -34
  330. package/shaders/ColorifyShader.cjs.map +1 -1
  331. package/shaders/ColorifyShader.js +19 -34
  332. package/shaders/ColorifyShader.js.map +1 -1
  333. package/shaders/ConvolutionShader.cjs +24 -43
  334. package/shaders/ConvolutionShader.cjs.map +1 -1
  335. package/shaders/ConvolutionShader.js +24 -43
  336. package/shaders/ConvolutionShader.js.map +1 -1
  337. package/shaders/CopyShader.cjs +16 -30
  338. package/shaders/CopyShader.cjs.map +1 -1
  339. package/shaders/CopyShader.js +16 -30
  340. package/shaders/CopyShader.js.map +1 -1
  341. package/shaders/DOFMipMapShader.cjs +21 -38
  342. package/shaders/DOFMipMapShader.cjs.map +1 -1
  343. package/shaders/DOFMipMapShader.js +21 -38
  344. package/shaders/DOFMipMapShader.js.map +1 -1
  345. package/shaders/DepthLimitedBlurShader.cjs +69 -98
  346. package/shaders/DepthLimitedBlurShader.cjs.map +1 -1
  347. package/shaders/DepthLimitedBlurShader.js +69 -98
  348. package/shaders/DepthLimitedBlurShader.js.map +1 -1
  349. package/shaders/DigitalGlitch.cjs +59 -70
  350. package/shaders/DigitalGlitch.cjs.map +1 -1
  351. package/shaders/DigitalGlitch.js +59 -70
  352. package/shaders/DigitalGlitch.js.map +1 -1
  353. package/shaders/DotScreenShader.cjs +28 -49
  354. package/shaders/DotScreenShader.cjs.map +1 -1
  355. package/shaders/DotScreenShader.js +28 -49
  356. package/shaders/DotScreenShader.js.map +1 -1
  357. package/shaders/FXAAShader.cjs +1089 -1098
  358. package/shaders/FXAAShader.cjs.map +1 -1
  359. package/shaders/FXAAShader.js +1089 -1098
  360. package/shaders/FXAAShader.js.map +1 -1
  361. package/shaders/FilmShader.cjs +29 -57
  362. package/shaders/FilmShader.cjs.map +1 -1
  363. package/shaders/FilmShader.js +29 -57
  364. package/shaders/FilmShader.js.map +1 -1
  365. package/shaders/FocusShader.cjs +43 -70
  366. package/shaders/FocusShader.cjs.map +1 -1
  367. package/shaders/FocusShader.js +43 -70
  368. package/shaders/FocusShader.js.map +1 -1
  369. package/shaders/FreiChenShader.cjs +53 -74
  370. package/shaders/FreiChenShader.cjs.map +1 -1
  371. package/shaders/FreiChenShader.js +53 -74
  372. package/shaders/FreiChenShader.js.map +1 -1
  373. package/shaders/FresnelShader.cjs +35 -55
  374. package/shaders/FresnelShader.cjs.map +1 -1
  375. package/shaders/FresnelShader.js +35 -55
  376. package/shaders/FresnelShader.js.map +1 -1
  377. package/shaders/GammaCorrectionShader.cjs +19 -33
  378. package/shaders/GammaCorrectionShader.cjs.map +1 -1
  379. package/shaders/GammaCorrectionShader.js +19 -33
  380. package/shaders/GammaCorrectionShader.js.map +1 -1
  381. package/shaders/GodRaysShader.cjs +116 -193
  382. package/shaders/GodRaysShader.cjs.map +1 -1
  383. package/shaders/GodRaysShader.js +116 -193
  384. package/shaders/GodRaysShader.js.map +1 -1
  385. package/shaders/HalftoneShader.cjs +192 -270
  386. package/shaders/HalftoneShader.cjs.map +1 -1
  387. package/shaders/HalftoneShader.js +192 -270
  388. package/shaders/HalftoneShader.js.map +1 -1
  389. package/shaders/HorizontalTiltShiftShader.cjs +27 -43
  390. package/shaders/HorizontalTiltShiftShader.cjs.map +1 -1
  391. package/shaders/HorizontalTiltShiftShader.js +27 -43
  392. package/shaders/HorizontalTiltShiftShader.js.map +1 -1
  393. package/shaders/HueSaturationShader.cjs +31 -47
  394. package/shaders/HueSaturationShader.cjs.map +1 -1
  395. package/shaders/HueSaturationShader.js +31 -47
  396. package/shaders/HueSaturationShader.js.map +1 -1
  397. package/shaders/KaleidoShader.cjs +24 -37
  398. package/shaders/KaleidoShader.cjs.map +1 -1
  399. package/shaders/KaleidoShader.js +24 -37
  400. package/shaders/KaleidoShader.js.map +1 -1
  401. package/shaders/LuminosityHighPassShader.cjs +24 -43
  402. package/shaders/LuminosityHighPassShader.cjs.map +1 -1
  403. package/shaders/LuminosityHighPassShader.js +24 -43
  404. package/shaders/LuminosityHighPassShader.js.map +1 -1
  405. package/shaders/LuminosityShader.cjs +17 -34
  406. package/shaders/LuminosityShader.cjs.map +1 -1
  407. package/shaders/LuminosityShader.js +17 -34
  408. package/shaders/LuminosityShader.js.map +1 -1
  409. package/shaders/MirrorShader.cjs +26 -39
  410. package/shaders/MirrorShader.cjs.map +1 -1
  411. package/shaders/MirrorShader.js +26 -39
  412. package/shaders/MirrorShader.js.map +1 -1
  413. package/shaders/NormalMapShader.cjs +21 -36
  414. package/shaders/NormalMapShader.cjs.map +1 -1
  415. package/shaders/NormalMapShader.js +21 -36
  416. package/shaders/NormalMapShader.js.map +1 -1
  417. package/shaders/ParallaxShader.cjs +97 -147
  418. package/shaders/ParallaxShader.cjs.map +1 -1
  419. package/shaders/ParallaxShader.js +97 -147
  420. package/shaders/ParallaxShader.js.map +1 -1
  421. package/shaders/PixelShader.cjs +18 -31
  422. package/shaders/PixelShader.cjs.map +1 -1
  423. package/shaders/PixelShader.js +18 -31
  424. package/shaders/PixelShader.js.map +1 -1
  425. package/shaders/RGBShiftShader.cjs +20 -33
  426. package/shaders/RGBShiftShader.cjs.map +1 -1
  427. package/shaders/RGBShiftShader.js +20 -33
  428. package/shaders/RGBShiftShader.js.map +1 -1
  429. package/shaders/SAOShader.cjs +117 -154
  430. package/shaders/SAOShader.cjs.map +1 -1
  431. package/shaders/SAOShader.js +117 -154
  432. package/shaders/SAOShader.js.map +1 -1
  433. package/shaders/SMAAShader.cjs +270 -358
  434. package/shaders/SMAAShader.cjs.map +1 -1
  435. package/shaders/SMAAShader.js +270 -358
  436. package/shaders/SMAAShader.js.map +1 -1
  437. package/shaders/SSAOShader.cjs +142 -236
  438. package/shaders/SSAOShader.cjs.map +1 -1
  439. package/shaders/SSAOShader.js +142 -236
  440. package/shaders/SSAOShader.js.map +1 -1
  441. package/shaders/SSRShader.cjs +4 -4
  442. package/shaders/SSRShader.cjs.map +1 -1
  443. package/shaders/SSRShader.js +4 -4
  444. package/shaders/SSRShader.js.map +1 -1
  445. package/shaders/SepiaShader.cjs +20 -36
  446. package/shaders/SepiaShader.cjs.map +1 -1
  447. package/shaders/SepiaShader.js +20 -36
  448. package/shaders/SepiaShader.js.map +1 -1
  449. package/shaders/SobelOperatorShader.cjs +37 -64
  450. package/shaders/SobelOperatorShader.cjs.map +1 -1
  451. package/shaders/SobelOperatorShader.js +37 -64
  452. package/shaders/SobelOperatorShader.js.map +1 -1
  453. package/shaders/TechnicolorShader.cjs +16 -29
  454. package/shaders/TechnicolorShader.cjs.map +1 -1
  455. package/shaders/TechnicolorShader.js +16 -29
  456. package/shaders/TechnicolorShader.js.map +1 -1
  457. package/shaders/ToneMapShader.cjs +35 -55
  458. package/shaders/ToneMapShader.cjs.map +1 -1
  459. package/shaders/ToneMapShader.js +35 -55
  460. package/shaders/ToneMapShader.js.map +1 -1
  461. package/shaders/ToonShader.cjs +165 -275
  462. package/shaders/ToonShader.cjs.map +1 -1
  463. package/shaders/ToonShader.js +165 -275
  464. package/shaders/ToonShader.js.map +1 -1
  465. package/shaders/TriangleBlurShader.cjs +27 -50
  466. package/shaders/TriangleBlurShader.cjs.map +1 -1
  467. package/shaders/TriangleBlurShader.js +27 -50
  468. package/shaders/TriangleBlurShader.js.map +1 -1
  469. package/shaders/UnpackDepthRGBAShader.cjs +17 -32
  470. package/shaders/UnpackDepthRGBAShader.cjs.map +1 -1
  471. package/shaders/UnpackDepthRGBAShader.js +17 -32
  472. package/shaders/UnpackDepthRGBAShader.js.map +1 -1
  473. package/shaders/VerticalTiltShiftShader.cjs +27 -43
  474. package/shaders/VerticalTiltShiftShader.cjs.map +1 -1
  475. package/shaders/VerticalTiltShiftShader.js +27 -43
  476. package/shaders/VerticalTiltShiftShader.js.map +1 -1
  477. package/shaders/VignetteShader.cjs +27 -43
  478. package/shaders/VignetteShader.cjs.map +1 -1
  479. package/shaders/VignetteShader.js +27 -43
  480. package/shaders/VignetteShader.js.map +1 -1
  481. package/shaders/VolumeShader.cjs +213 -264
  482. package/shaders/VolumeShader.cjs.map +1 -1
  483. package/shaders/VolumeShader.js +213 -264
  484. package/shaders/VolumeShader.js.map +1 -1
  485. package/shaders/WaterRefractionShader.cjs +35 -63
  486. package/shaders/WaterRefractionShader.cjs.map +1 -1
  487. package/shaders/WaterRefractionShader.js +35 -63
  488. package/shaders/WaterRefractionShader.js.map +1 -1
  489. package/utils/GeometryCompressionUtils.cjs +1 -2
  490. package/utils/GeometryCompressionUtils.cjs.map +1 -1
  491. package/utils/GeometryCompressionUtils.js +2 -3
  492. package/utils/GeometryCompressionUtils.js.map +1 -1
  493. package/utils/RoughnessMipmapper.cjs +3 -3
  494. package/utils/RoughnessMipmapper.cjs.map +1 -1
  495. package/utils/RoughnessMipmapper.js +4 -4
  496. package/utils/RoughnessMipmapper.js.map +1 -1
  497. package/webxr/ARButton.cjs +106 -109
  498. package/webxr/ARButton.cjs.map +1 -1
  499. package/webxr/ARButton.d.ts +3 -4
  500. package/webxr/ARButton.js +106 -109
  501. package/webxr/ARButton.js.map +1 -1
  502. package/webxr/OculusHandPointerModel.cjs +2 -2
  503. package/webxr/OculusHandPointerModel.cjs.map +1 -1
  504. package/webxr/OculusHandPointerModel.js +2 -2
  505. package/webxr/OculusHandPointerModel.js.map +1 -1
  506. package/webxr/VRButton.cjs +95 -98
  507. package/webxr/VRButton.cjs.map +1 -1
  508. package/webxr/VRButton.d.ts +5 -6
  509. package/webxr/VRButton.js +95 -98
  510. package/webxr/VRButton.js.map +1 -1
  511. package/webxr/XRHandPrimitiveModel.cjs +2 -2
  512. package/webxr/XRHandPrimitiveModel.cjs.map +1 -1
  513. package/webxr/XRHandPrimitiveModel.js +3 -3
  514. package/webxr/XRHandPrimitiveModel.js.map +1 -1
@@ -2,1822 +2,1816 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const THREE = require("three");
4
4
  const COLOR_SPACE_SVG = "srgb";
5
- const SVGLoader = /* @__PURE__ */ (() => {
6
- class SVGLoader2 extends THREE.Loader {
7
- constructor(manager) {
8
- super(manager);
9
- this.defaultDPI = 90;
10
- this.defaultUnit = "px";
11
- }
12
- load(url, onLoad, onProgress, onError) {
13
- const scope = this;
14
- const loader = new THREE.FileLoader(scope.manager);
15
- loader.setPath(scope.path);
16
- loader.setRequestHeader(scope.requestHeader);
17
- loader.setWithCredentials(scope.withCredentials);
18
- loader.load(
19
- url,
20
- function(text) {
21
- try {
22
- onLoad(scope.parse(text));
23
- } catch (e) {
24
- if (onError) {
25
- onError(e);
26
- } else {
27
- console.error(e);
28
- }
29
- scope.manager.itemError(url);
5
+ class SVGLoader extends THREE.Loader {
6
+ constructor(manager) {
7
+ super(manager);
8
+ this.defaultDPI = 90;
9
+ this.defaultUnit = "px";
10
+ }
11
+ load(url, onLoad, onProgress, onError) {
12
+ const scope = this;
13
+ const loader = new THREE.FileLoader(scope.manager);
14
+ loader.setPath(scope.path);
15
+ loader.setRequestHeader(scope.requestHeader);
16
+ loader.setWithCredentials(scope.withCredentials);
17
+ loader.load(
18
+ url,
19
+ function(text) {
20
+ try {
21
+ onLoad(scope.parse(text));
22
+ } catch (e) {
23
+ if (onError) {
24
+ onError(e);
25
+ } else {
26
+ console.error(e);
27
+ }
28
+ scope.manager.itemError(url);
29
+ }
30
+ },
31
+ onProgress,
32
+ onError
33
+ );
34
+ }
35
+ parse(text) {
36
+ const scope = this;
37
+ function parseNode(node, style) {
38
+ if (node.nodeType !== 1)
39
+ return;
40
+ const transform = getNodeTransform(node);
41
+ let isDefsNode = false;
42
+ let path = null;
43
+ switch (node.nodeName) {
44
+ case "svg":
45
+ style = parseStyle(node, style);
46
+ break;
47
+ case "style":
48
+ parseCSSStylesheet(node);
49
+ break;
50
+ case "g":
51
+ style = parseStyle(node, style);
52
+ break;
53
+ case "path":
54
+ style = parseStyle(node, style);
55
+ if (node.hasAttribute("d"))
56
+ path = parsePathNode(node);
57
+ break;
58
+ case "rect":
59
+ style = parseStyle(node, style);
60
+ path = parseRectNode(node);
61
+ break;
62
+ case "polygon":
63
+ style = parseStyle(node, style);
64
+ path = parsePolygonNode(node);
65
+ break;
66
+ case "polyline":
67
+ style = parseStyle(node, style);
68
+ path = parsePolylineNode(node);
69
+ break;
70
+ case "circle":
71
+ style = parseStyle(node, style);
72
+ path = parseCircleNode(node);
73
+ break;
74
+ case "ellipse":
75
+ style = parseStyle(node, style);
76
+ path = parseEllipseNode(node);
77
+ break;
78
+ case "line":
79
+ style = parseStyle(node, style);
80
+ path = parseLineNode(node);
81
+ break;
82
+ case "defs":
83
+ isDefsNode = true;
84
+ break;
85
+ case "use":
86
+ style = parseStyle(node, style);
87
+ const href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "";
88
+ const usedNodeId = href.substring(1);
89
+ const usedNode = node.viewportElement.getElementById(usedNodeId);
90
+ if (usedNode) {
91
+ parseNode(usedNode, style);
92
+ } else {
93
+ console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
30
94
  }
31
- },
32
- onProgress,
33
- onError
34
- );
95
+ break;
96
+ }
97
+ if (path) {
98
+ if (style.fill !== void 0 && style.fill !== "none") {
99
+ path.color.setStyle(style.fill, COLOR_SPACE_SVG);
100
+ }
101
+ transformPath(path, currentTransform);
102
+ paths.push(path);
103
+ path.userData = { node, style };
104
+ }
105
+ const childNodes = node.childNodes;
106
+ for (let i = 0; i < childNodes.length; i++) {
107
+ const node2 = childNodes[i];
108
+ if (isDefsNode && node2.nodeName !== "style" && node2.nodeName !== "defs") {
109
+ continue;
110
+ }
111
+ parseNode(node2, style);
112
+ }
113
+ if (transform) {
114
+ transformStack.pop();
115
+ if (transformStack.length > 0) {
116
+ currentTransform.copy(transformStack[transformStack.length - 1]);
117
+ } else {
118
+ currentTransform.identity();
119
+ }
120
+ }
35
121
  }
36
- parse(text) {
37
- const scope = this;
38
- function parseNode(node, style) {
39
- if (node.nodeType !== 1)
40
- return;
41
- const transform = getNodeTransform(node);
42
- let isDefsNode = false;
43
- let path = null;
44
- switch (node.nodeName) {
45
- case "svg":
46
- style = parseStyle(node, style);
122
+ function parsePathNode(node) {
123
+ const path = new THREE.ShapePath();
124
+ const point = new THREE.Vector2();
125
+ const control = new THREE.Vector2();
126
+ const firstPoint = new THREE.Vector2();
127
+ let isFirstPoint = true;
128
+ let doSetFirstPoint = false;
129
+ const d = node.getAttribute("d");
130
+ if (d === "" || d === "none")
131
+ return null;
132
+ const commands = d.match(/[a-df-z][^a-df-z]*/gi);
133
+ for (let i = 0, l = commands.length; i < l; i++) {
134
+ const command = commands[i];
135
+ const type = command.charAt(0);
136
+ const data2 = command.slice(1).trim();
137
+ if (isFirstPoint === true) {
138
+ doSetFirstPoint = true;
139
+ isFirstPoint = false;
140
+ }
141
+ let numbers;
142
+ switch (type) {
143
+ case "M":
144
+ numbers = parseFloats(data2);
145
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
146
+ point.x = numbers[j + 0];
147
+ point.y = numbers[j + 1];
148
+ control.x = point.x;
149
+ control.y = point.y;
150
+ if (j === 0) {
151
+ path.moveTo(point.x, point.y);
152
+ } else {
153
+ path.lineTo(point.x, point.y);
154
+ }
155
+ if (j === 0)
156
+ firstPoint.copy(point);
157
+ }
158
+ break;
159
+ case "H":
160
+ numbers = parseFloats(data2);
161
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
162
+ point.x = numbers[j];
163
+ control.x = point.x;
164
+ control.y = point.y;
165
+ path.lineTo(point.x, point.y);
166
+ if (j === 0 && doSetFirstPoint === true)
167
+ firstPoint.copy(point);
168
+ }
169
+ break;
170
+ case "V":
171
+ numbers = parseFloats(data2);
172
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
173
+ point.y = numbers[j];
174
+ control.x = point.x;
175
+ control.y = point.y;
176
+ path.lineTo(point.x, point.y);
177
+ if (j === 0 && doSetFirstPoint === true)
178
+ firstPoint.copy(point);
179
+ }
47
180
  break;
48
- case "style":
49
- parseCSSStylesheet(node);
181
+ case "L":
182
+ numbers = parseFloats(data2);
183
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
184
+ point.x = numbers[j + 0];
185
+ point.y = numbers[j + 1];
186
+ control.x = point.x;
187
+ control.y = point.y;
188
+ path.lineTo(point.x, point.y);
189
+ if (j === 0 && doSetFirstPoint === true)
190
+ firstPoint.copy(point);
191
+ }
50
192
  break;
51
- case "g":
52
- style = parseStyle(node, style);
193
+ case "C":
194
+ numbers = parseFloats(data2);
195
+ for (let j = 0, jl = numbers.length; j < jl; j += 6) {
196
+ path.bezierCurveTo(
197
+ numbers[j + 0],
198
+ numbers[j + 1],
199
+ numbers[j + 2],
200
+ numbers[j + 3],
201
+ numbers[j + 4],
202
+ numbers[j + 5]
203
+ );
204
+ control.x = numbers[j + 2];
205
+ control.y = numbers[j + 3];
206
+ point.x = numbers[j + 4];
207
+ point.y = numbers[j + 5];
208
+ if (j === 0 && doSetFirstPoint === true)
209
+ firstPoint.copy(point);
210
+ }
53
211
  break;
54
- case "path":
55
- style = parseStyle(node, style);
56
- if (node.hasAttribute("d"))
57
- path = parsePathNode(node);
212
+ case "S":
213
+ numbers = parseFloats(data2);
214
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
215
+ path.bezierCurveTo(
216
+ getReflection(point.x, control.x),
217
+ getReflection(point.y, control.y),
218
+ numbers[j + 0],
219
+ numbers[j + 1],
220
+ numbers[j + 2],
221
+ numbers[j + 3]
222
+ );
223
+ control.x = numbers[j + 0];
224
+ control.y = numbers[j + 1];
225
+ point.x = numbers[j + 2];
226
+ point.y = numbers[j + 3];
227
+ if (j === 0 && doSetFirstPoint === true)
228
+ firstPoint.copy(point);
229
+ }
58
230
  break;
59
- case "rect":
60
- style = parseStyle(node, style);
61
- path = parseRectNode(node);
231
+ case "Q":
232
+ numbers = parseFloats(data2);
233
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
234
+ path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
235
+ control.x = numbers[j + 0];
236
+ control.y = numbers[j + 1];
237
+ point.x = numbers[j + 2];
238
+ point.y = numbers[j + 3];
239
+ if (j === 0 && doSetFirstPoint === true)
240
+ firstPoint.copy(point);
241
+ }
62
242
  break;
63
- case "polygon":
64
- style = parseStyle(node, style);
65
- path = parsePolygonNode(node);
243
+ case "T":
244
+ numbers = parseFloats(data2);
245
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
246
+ const rx = getReflection(point.x, control.x);
247
+ const ry = getReflection(point.y, control.y);
248
+ path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
249
+ control.x = rx;
250
+ control.y = ry;
251
+ point.x = numbers[j + 0];
252
+ point.y = numbers[j + 1];
253
+ if (j === 0 && doSetFirstPoint === true)
254
+ firstPoint.copy(point);
255
+ }
66
256
  break;
67
- case "polyline":
68
- style = parseStyle(node, style);
69
- path = parsePolylineNode(node);
257
+ case "A":
258
+ numbers = parseFloats(data2, [3, 4], 7);
259
+ for (let j = 0, jl = numbers.length; j < jl; j += 7) {
260
+ if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
261
+ continue;
262
+ const start = point.clone();
263
+ point.x = numbers[j + 5];
264
+ point.y = numbers[j + 6];
265
+ control.x = point.x;
266
+ control.y = point.y;
267
+ parseArcCommand(
268
+ path,
269
+ numbers[j],
270
+ numbers[j + 1],
271
+ numbers[j + 2],
272
+ numbers[j + 3],
273
+ numbers[j + 4],
274
+ start,
275
+ point
276
+ );
277
+ if (j === 0 && doSetFirstPoint === true)
278
+ firstPoint.copy(point);
279
+ }
70
280
  break;
71
- case "circle":
72
- style = parseStyle(node, style);
73
- path = parseCircleNode(node);
281
+ case "m":
282
+ numbers = parseFloats(data2);
283
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
284
+ point.x += numbers[j + 0];
285
+ point.y += numbers[j + 1];
286
+ control.x = point.x;
287
+ control.y = point.y;
288
+ if (j === 0) {
289
+ path.moveTo(point.x, point.y);
290
+ } else {
291
+ path.lineTo(point.x, point.y);
292
+ }
293
+ if (j === 0)
294
+ firstPoint.copy(point);
295
+ }
74
296
  break;
75
- case "ellipse":
76
- style = parseStyle(node, style);
77
- path = parseEllipseNode(node);
297
+ case "h":
298
+ numbers = parseFloats(data2);
299
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
300
+ point.x += numbers[j];
301
+ control.x = point.x;
302
+ control.y = point.y;
303
+ path.lineTo(point.x, point.y);
304
+ if (j === 0 && doSetFirstPoint === true)
305
+ firstPoint.copy(point);
306
+ }
78
307
  break;
79
- case "line":
80
- style = parseStyle(node, style);
81
- path = parseLineNode(node);
308
+ case "v":
309
+ numbers = parseFloats(data2);
310
+ for (let j = 0, jl = numbers.length; j < jl; j++) {
311
+ point.y += numbers[j];
312
+ control.x = point.x;
313
+ control.y = point.y;
314
+ path.lineTo(point.x, point.y);
315
+ if (j === 0 && doSetFirstPoint === true)
316
+ firstPoint.copy(point);
317
+ }
82
318
  break;
83
- case "defs":
84
- isDefsNode = true;
319
+ case "l":
320
+ numbers = parseFloats(data2);
321
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
322
+ point.x += numbers[j + 0];
323
+ point.y += numbers[j + 1];
324
+ control.x = point.x;
325
+ control.y = point.y;
326
+ path.lineTo(point.x, point.y);
327
+ if (j === 0 && doSetFirstPoint === true)
328
+ firstPoint.copy(point);
329
+ }
85
330
  break;
86
- case "use":
87
- style = parseStyle(node, style);
88
- const href = node.getAttributeNS("http://www.w3.org/1999/xlink", "href") || "";
89
- const usedNodeId = href.substring(1);
90
- const usedNode = node.viewportElement.getElementById(usedNodeId);
91
- if (usedNode) {
92
- parseNode(usedNode, style);
93
- } else {
94
- console.warn("SVGLoader: 'use node' references non-existent node id: " + usedNodeId);
331
+ case "c":
332
+ numbers = parseFloats(data2);
333
+ for (let j = 0, jl = numbers.length; j < jl; j += 6) {
334
+ path.bezierCurveTo(
335
+ point.x + numbers[j + 0],
336
+ point.y + numbers[j + 1],
337
+ point.x + numbers[j + 2],
338
+ point.y + numbers[j + 3],
339
+ point.x + numbers[j + 4],
340
+ point.y + numbers[j + 5]
341
+ );
342
+ control.x = point.x + numbers[j + 2];
343
+ control.y = point.y + numbers[j + 3];
344
+ point.x += numbers[j + 4];
345
+ point.y += numbers[j + 5];
346
+ if (j === 0 && doSetFirstPoint === true)
347
+ firstPoint.copy(point);
348
+ }
349
+ break;
350
+ case "s":
351
+ numbers = parseFloats(data2);
352
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
353
+ path.bezierCurveTo(
354
+ getReflection(point.x, control.x),
355
+ getReflection(point.y, control.y),
356
+ point.x + numbers[j + 0],
357
+ point.y + numbers[j + 1],
358
+ point.x + numbers[j + 2],
359
+ point.y + numbers[j + 3]
360
+ );
361
+ control.x = point.x + numbers[j + 0];
362
+ control.y = point.y + numbers[j + 1];
363
+ point.x += numbers[j + 2];
364
+ point.y += numbers[j + 3];
365
+ if (j === 0 && doSetFirstPoint === true)
366
+ firstPoint.copy(point);
367
+ }
368
+ break;
369
+ case "q":
370
+ numbers = parseFloats(data2);
371
+ for (let j = 0, jl = numbers.length; j < jl; j += 4) {
372
+ path.quadraticCurveTo(
373
+ point.x + numbers[j + 0],
374
+ point.y + numbers[j + 1],
375
+ point.x + numbers[j + 2],
376
+ point.y + numbers[j + 3]
377
+ );
378
+ control.x = point.x + numbers[j + 0];
379
+ control.y = point.y + numbers[j + 1];
380
+ point.x += numbers[j + 2];
381
+ point.y += numbers[j + 3];
382
+ if (j === 0 && doSetFirstPoint === true)
383
+ firstPoint.copy(point);
384
+ }
385
+ break;
386
+ case "t":
387
+ numbers = parseFloats(data2);
388
+ for (let j = 0, jl = numbers.length; j < jl; j += 2) {
389
+ const rx = getReflection(point.x, control.x);
390
+ const ry = getReflection(point.y, control.y);
391
+ path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
392
+ control.x = rx;
393
+ control.y = ry;
394
+ point.x = point.x + numbers[j + 0];
395
+ point.y = point.y + numbers[j + 1];
396
+ if (j === 0 && doSetFirstPoint === true)
397
+ firstPoint.copy(point);
95
398
  }
96
399
  break;
400
+ case "a":
401
+ numbers = parseFloats(data2, [3, 4], 7);
402
+ for (let j = 0, jl = numbers.length; j < jl; j += 7) {
403
+ if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
404
+ continue;
405
+ const start = point.clone();
406
+ point.x += numbers[j + 5];
407
+ point.y += numbers[j + 6];
408
+ control.x = point.x;
409
+ control.y = point.y;
410
+ parseArcCommand(
411
+ path,
412
+ numbers[j],
413
+ numbers[j + 1],
414
+ numbers[j + 2],
415
+ numbers[j + 3],
416
+ numbers[j + 4],
417
+ start,
418
+ point
419
+ );
420
+ if (j === 0 && doSetFirstPoint === true)
421
+ firstPoint.copy(point);
422
+ }
423
+ break;
424
+ case "Z":
425
+ case "z":
426
+ path.currentPath.autoClose = true;
427
+ if (path.currentPath.curves.length > 0) {
428
+ point.copy(firstPoint);
429
+ path.currentPath.currentPoint.copy(point);
430
+ isFirstPoint = true;
431
+ }
432
+ break;
433
+ default:
434
+ console.warn(command);
97
435
  }
98
- if (path) {
99
- if (style.fill !== void 0 && style.fill !== "none") {
100
- path.color.setStyle(style.fill, COLOR_SPACE_SVG);
101
- }
102
- transformPath(path, currentTransform);
103
- paths.push(path);
104
- path.userData = { node, style };
436
+ doSetFirstPoint = false;
437
+ }
438
+ return path;
439
+ }
440
+ function parseCSSStylesheet(node) {
441
+ if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
442
+ return;
443
+ for (let i = 0; i < node.sheet.cssRules.length; i++) {
444
+ const stylesheet = node.sheet.cssRules[i];
445
+ if (stylesheet.type !== 1)
446
+ continue;
447
+ const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
448
+ for (let j = 0; j < selectorList.length; j++) {
449
+ const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
450
+ stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
105
451
  }
106
- const childNodes = node.childNodes;
107
- for (let i = 0; i < childNodes.length; i++) {
108
- const node2 = childNodes[i];
109
- if (isDefsNode && node2.nodeName !== "style" && node2.nodeName !== "defs") {
110
- continue;
111
- }
112
- parseNode(node2, style);
452
+ }
453
+ }
454
+ function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
455
+ if (rx == 0 || ry == 0) {
456
+ path.lineTo(end.x, end.y);
457
+ return;
458
+ }
459
+ x_axis_rotation = x_axis_rotation * Math.PI / 180;
460
+ rx = Math.abs(rx);
461
+ ry = Math.abs(ry);
462
+ const dx2 = (start.x - end.x) / 2;
463
+ const dy2 = (start.y - end.y) / 2;
464
+ const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
465
+ const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
466
+ let rxs = rx * rx;
467
+ let rys = ry * ry;
468
+ const x1ps = x1p * x1p;
469
+ const y1ps = y1p * y1p;
470
+ const cr = x1ps / rxs + y1ps / rys;
471
+ if (cr > 1) {
472
+ const s = Math.sqrt(cr);
473
+ rx = s * rx;
474
+ ry = s * ry;
475
+ rxs = rx * rx;
476
+ rys = ry * ry;
477
+ }
478
+ const dq = rxs * y1ps + rys * x1ps;
479
+ const pq = (rxs * rys - dq) / dq;
480
+ let q = Math.sqrt(Math.max(0, pq));
481
+ if (large_arc_flag === sweep_flag)
482
+ q = -q;
483
+ const cxp = q * rx * y1p / ry;
484
+ const cyp = -q * ry * x1p / rx;
485
+ const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
486
+ const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
487
+ const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
488
+ const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
489
+ path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
490
+ }
491
+ function svgAngle(ux, uy, vx, vy) {
492
+ const dot = ux * vx + uy * vy;
493
+ const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
494
+ let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
495
+ if (ux * vy - uy * vx < 0)
496
+ ang = -ang;
497
+ return ang;
498
+ }
499
+ function parseRectNode(node) {
500
+ const x = parseFloatWithUnits(node.getAttribute("x") || 0);
501
+ const y = parseFloatWithUnits(node.getAttribute("y") || 0);
502
+ const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
503
+ const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
504
+ const w = parseFloatWithUnits(node.getAttribute("width"));
505
+ const h = parseFloatWithUnits(node.getAttribute("height"));
506
+ const bci = 1 - 0.551915024494;
507
+ const path = new THREE.ShapePath();
508
+ path.moveTo(x + rx, y);
509
+ path.lineTo(x + w - rx, y);
510
+ if (rx !== 0 || ry !== 0) {
511
+ path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
512
+ }
513
+ path.lineTo(x + w, y + h - ry);
514
+ if (rx !== 0 || ry !== 0) {
515
+ path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
516
+ }
517
+ path.lineTo(x + rx, y + h);
518
+ if (rx !== 0 || ry !== 0) {
519
+ path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
520
+ }
521
+ path.lineTo(x, y + ry);
522
+ if (rx !== 0 || ry !== 0) {
523
+ path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
524
+ }
525
+ return path;
526
+ }
527
+ function parsePolygonNode(node) {
528
+ function iterator(match, a, b) {
529
+ const x = parseFloatWithUnits(a);
530
+ const y = parseFloatWithUnits(b);
531
+ if (index === 0) {
532
+ path.moveTo(x, y);
533
+ } else {
534
+ path.lineTo(x, y);
113
535
  }
114
- if (transform) {
115
- transformStack.pop();
116
- if (transformStack.length > 0) {
117
- currentTransform.copy(transformStack[transformStack.length - 1]);
118
- } else {
119
- currentTransform.identity();
120
- }
536
+ index++;
537
+ }
538
+ const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
539
+ const path = new THREE.ShapePath();
540
+ let index = 0;
541
+ node.getAttribute("points").replace(regex, iterator);
542
+ path.currentPath.autoClose = true;
543
+ return path;
544
+ }
545
+ function parsePolylineNode(node) {
546
+ function iterator(match, a, b) {
547
+ const x = parseFloatWithUnits(a);
548
+ const y = parseFloatWithUnits(b);
549
+ if (index === 0) {
550
+ path.moveTo(x, y);
551
+ } else {
552
+ path.lineTo(x, y);
553
+ }
554
+ index++;
555
+ }
556
+ const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
557
+ const path = new THREE.ShapePath();
558
+ let index = 0;
559
+ node.getAttribute("points").replace(regex, iterator);
560
+ path.currentPath.autoClose = false;
561
+ return path;
562
+ }
563
+ function parseCircleNode(node) {
564
+ const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
565
+ const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
566
+ const r = parseFloatWithUnits(node.getAttribute("r") || 0);
567
+ const subpath = new THREE.Path();
568
+ subpath.absarc(x, y, r, 0, Math.PI * 2);
569
+ const path = new THREE.ShapePath();
570
+ path.subPaths.push(subpath);
571
+ return path;
572
+ }
573
+ function parseEllipseNode(node) {
574
+ const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
575
+ const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
576
+ const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
577
+ const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
578
+ const subpath = new THREE.Path();
579
+ subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
580
+ const path = new THREE.ShapePath();
581
+ path.subPaths.push(subpath);
582
+ return path;
583
+ }
584
+ function parseLineNode(node) {
585
+ const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
586
+ const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
587
+ const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
588
+ const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
589
+ const path = new THREE.ShapePath();
590
+ path.moveTo(x1, y1);
591
+ path.lineTo(x2, y2);
592
+ path.currentPath.autoClose = false;
593
+ return path;
594
+ }
595
+ function parseStyle(node, style) {
596
+ style = Object.assign({}, style);
597
+ let stylesheetStyles = {};
598
+ if (node.hasAttribute("class")) {
599
+ const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
600
+ for (let i = 0; i < classSelectors.length; i++) {
601
+ stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
121
602
  }
122
603
  }
123
- function parsePathNode(node) {
124
- const path = new THREE.ShapePath();
125
- const point = new THREE.Vector2();
126
- const control = new THREE.Vector2();
127
- const firstPoint = new THREE.Vector2();
128
- let isFirstPoint = true;
129
- let doSetFirstPoint = false;
130
- const d = node.getAttribute("d");
131
- if (d === "" || d === "none")
132
- return null;
133
- const commands = d.match(/[a-df-z][^a-df-z]*/gi);
134
- for (let i = 0, l = commands.length; i < l; i++) {
135
- const command = commands[i];
136
- const type = command.charAt(0);
137
- const data2 = command.slice(1).trim();
138
- if (isFirstPoint === true) {
139
- doSetFirstPoint = true;
140
- isFirstPoint = false;
604
+ if (node.hasAttribute("id")) {
605
+ stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["#" + node.getAttribute("id")]);
606
+ }
607
+ function addStyle(svgName, jsName, adjustFunction) {
608
+ if (adjustFunction === void 0)
609
+ adjustFunction = function copy(v) {
610
+ if (v.startsWith("url"))
611
+ console.warn("SVGLoader: url access in attributes is not implemented.");
612
+ return v;
613
+ };
614
+ if (node.hasAttribute(svgName))
615
+ style[jsName] = adjustFunction(node.getAttribute(svgName));
616
+ if (stylesheetStyles[svgName])
617
+ style[jsName] = adjustFunction(stylesheetStyles[svgName]);
618
+ if (node.style && node.style[svgName] !== "")
619
+ style[jsName] = adjustFunction(node.style[svgName]);
620
+ }
621
+ function clamp(v) {
622
+ return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
623
+ }
624
+ function positive(v) {
625
+ return Math.max(0, parseFloatWithUnits(v));
626
+ }
627
+ addStyle("fill", "fill");
628
+ addStyle("fill-opacity", "fillOpacity", clamp);
629
+ addStyle("fill-rule", "fillRule");
630
+ addStyle("opacity", "opacity", clamp);
631
+ addStyle("stroke", "stroke");
632
+ addStyle("stroke-opacity", "strokeOpacity", clamp);
633
+ addStyle("stroke-width", "strokeWidth", positive);
634
+ addStyle("stroke-linejoin", "strokeLineJoin");
635
+ addStyle("stroke-linecap", "strokeLineCap");
636
+ addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
637
+ addStyle("visibility", "visibility");
638
+ return style;
639
+ }
640
+ function getReflection(a, b) {
641
+ return a - (b - a);
642
+ }
643
+ function parseFloats(input, flags, stride) {
644
+ if (typeof input !== "string") {
645
+ throw new TypeError("Invalid input: " + typeof input);
646
+ }
647
+ const RE = {
648
+ SEPARATOR: /[ \t\r\n\,.\-+]/,
649
+ WHITESPACE: /[ \t\r\n]/,
650
+ DIGIT: /[\d]/,
651
+ SIGN: /[-+]/,
652
+ POINT: /\./,
653
+ COMMA: /,/,
654
+ EXP: /e/i,
655
+ FLAGS: /[01]/
656
+ };
657
+ const SEP = 0;
658
+ const INT = 1;
659
+ const FLOAT = 2;
660
+ const EXP = 3;
661
+ let state = SEP;
662
+ let seenComma = true;
663
+ let number = "", exponent = "";
664
+ const result = [];
665
+ function throwSyntaxError(current2, i, partial) {
666
+ const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
667
+ error.partial = partial;
668
+ throw error;
669
+ }
670
+ function newNumber() {
671
+ if (number !== "") {
672
+ if (exponent === "")
673
+ result.push(Number(number));
674
+ else
675
+ result.push(Number(number) * Math.pow(10, Number(exponent)));
676
+ }
677
+ number = "";
678
+ exponent = "";
679
+ }
680
+ let current;
681
+ const length = input.length;
682
+ for (let i = 0; i < length; i++) {
683
+ current = input[i];
684
+ if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
685
+ state = INT;
686
+ number = current;
687
+ newNumber();
688
+ continue;
689
+ }
690
+ if (state === SEP) {
691
+ if (RE.WHITESPACE.test(current)) {
692
+ continue;
141
693
  }
142
- let numbers;
143
- switch (type) {
144
- case "M":
145
- numbers = parseFloats(data2);
146
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
147
- point.x = numbers[j + 0];
148
- point.y = numbers[j + 1];
149
- control.x = point.x;
150
- control.y = point.y;
151
- if (j === 0) {
152
- path.moveTo(point.x, point.y);
153
- } else {
154
- path.lineTo(point.x, point.y);
155
- }
156
- if (j === 0)
157
- firstPoint.copy(point);
158
- }
159
- break;
160
- case "H":
161
- numbers = parseFloats(data2);
162
- for (let j = 0, jl = numbers.length; j < jl; j++) {
163
- point.x = numbers[j];
164
- control.x = point.x;
165
- control.y = point.y;
166
- path.lineTo(point.x, point.y);
167
- if (j === 0 && doSetFirstPoint === true)
168
- firstPoint.copy(point);
169
- }
170
- break;
171
- case "V":
172
- numbers = parseFloats(data2);
173
- for (let j = 0, jl = numbers.length; j < jl; j++) {
174
- point.y = numbers[j];
175
- control.x = point.x;
176
- control.y = point.y;
177
- path.lineTo(point.x, point.y);
178
- if (j === 0 && doSetFirstPoint === true)
179
- firstPoint.copy(point);
180
- }
181
- break;
182
- case "L":
183
- numbers = parseFloats(data2);
184
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
185
- point.x = numbers[j + 0];
186
- point.y = numbers[j + 1];
187
- control.x = point.x;
188
- control.y = point.y;
189
- path.lineTo(point.x, point.y);
190
- if (j === 0 && doSetFirstPoint === true)
191
- firstPoint.copy(point);
192
- }
193
- break;
194
- case "C":
195
- numbers = parseFloats(data2);
196
- for (let j = 0, jl = numbers.length; j < jl; j += 6) {
197
- path.bezierCurveTo(
198
- numbers[j + 0],
199
- numbers[j + 1],
200
- numbers[j + 2],
201
- numbers[j + 3],
202
- numbers[j + 4],
203
- numbers[j + 5]
204
- );
205
- control.x = numbers[j + 2];
206
- control.y = numbers[j + 3];
207
- point.x = numbers[j + 4];
208
- point.y = numbers[j + 5];
209
- if (j === 0 && doSetFirstPoint === true)
210
- firstPoint.copy(point);
211
- }
212
- break;
213
- case "S":
214
- numbers = parseFloats(data2);
215
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
216
- path.bezierCurveTo(
217
- getReflection(point.x, control.x),
218
- getReflection(point.y, control.y),
219
- numbers[j + 0],
220
- numbers[j + 1],
221
- numbers[j + 2],
222
- numbers[j + 3]
223
- );
224
- control.x = numbers[j + 0];
225
- control.y = numbers[j + 1];
226
- point.x = numbers[j + 2];
227
- point.y = numbers[j + 3];
228
- if (j === 0 && doSetFirstPoint === true)
229
- firstPoint.copy(point);
230
- }
231
- break;
232
- case "Q":
233
- numbers = parseFloats(data2);
234
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
235
- path.quadraticCurveTo(numbers[j + 0], numbers[j + 1], numbers[j + 2], numbers[j + 3]);
236
- control.x = numbers[j + 0];
237
- control.y = numbers[j + 1];
238
- point.x = numbers[j + 2];
239
- point.y = numbers[j + 3];
240
- if (j === 0 && doSetFirstPoint === true)
241
- firstPoint.copy(point);
242
- }
243
- break;
244
- case "T":
245
- numbers = parseFloats(data2);
246
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
247
- const rx = getReflection(point.x, control.x);
248
- const ry = getReflection(point.y, control.y);
249
- path.quadraticCurveTo(rx, ry, numbers[j + 0], numbers[j + 1]);
250
- control.x = rx;
251
- control.y = ry;
252
- point.x = numbers[j + 0];
253
- point.y = numbers[j + 1];
254
- if (j === 0 && doSetFirstPoint === true)
255
- firstPoint.copy(point);
256
- }
257
- break;
258
- case "A":
259
- numbers = parseFloats(data2, [3, 4], 7);
260
- for (let j = 0, jl = numbers.length; j < jl; j += 7) {
261
- if (numbers[j + 5] == point.x && numbers[j + 6] == point.y)
262
- continue;
263
- const start = point.clone();
264
- point.x = numbers[j + 5];
265
- point.y = numbers[j + 6];
266
- control.x = point.x;
267
- control.y = point.y;
268
- parseArcCommand(
269
- path,
270
- numbers[j],
271
- numbers[j + 1],
272
- numbers[j + 2],
273
- numbers[j + 3],
274
- numbers[j + 4],
275
- start,
276
- point
277
- );
278
- if (j === 0 && doSetFirstPoint === true)
279
- firstPoint.copy(point);
280
- }
281
- break;
282
- case "m":
283
- numbers = parseFloats(data2);
284
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
285
- point.x += numbers[j + 0];
286
- point.y += numbers[j + 1];
287
- control.x = point.x;
288
- control.y = point.y;
289
- if (j === 0) {
290
- path.moveTo(point.x, point.y);
291
- } else {
292
- path.lineTo(point.x, point.y);
293
- }
294
- if (j === 0)
295
- firstPoint.copy(point);
296
- }
297
- break;
298
- case "h":
299
- numbers = parseFloats(data2);
300
- for (let j = 0, jl = numbers.length; j < jl; j++) {
301
- point.x += numbers[j];
302
- control.x = point.x;
303
- control.y = point.y;
304
- path.lineTo(point.x, point.y);
305
- if (j === 0 && doSetFirstPoint === true)
306
- firstPoint.copy(point);
307
- }
308
- break;
309
- case "v":
310
- numbers = parseFloats(data2);
311
- for (let j = 0, jl = numbers.length; j < jl; j++) {
312
- point.y += numbers[j];
313
- control.x = point.x;
314
- control.y = point.y;
315
- path.lineTo(point.x, point.y);
316
- if (j === 0 && doSetFirstPoint === true)
317
- firstPoint.copy(point);
318
- }
319
- break;
320
- case "l":
321
- numbers = parseFloats(data2);
322
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
323
- point.x += numbers[j + 0];
324
- point.y += numbers[j + 1];
325
- control.x = point.x;
326
- control.y = point.y;
327
- path.lineTo(point.x, point.y);
328
- if (j === 0 && doSetFirstPoint === true)
329
- firstPoint.copy(point);
330
- }
331
- break;
332
- case "c":
333
- numbers = parseFloats(data2);
334
- for (let j = 0, jl = numbers.length; j < jl; j += 6) {
335
- path.bezierCurveTo(
336
- point.x + numbers[j + 0],
337
- point.y + numbers[j + 1],
338
- point.x + numbers[j + 2],
339
- point.y + numbers[j + 3],
340
- point.x + numbers[j + 4],
341
- point.y + numbers[j + 5]
342
- );
343
- control.x = point.x + numbers[j + 2];
344
- control.y = point.y + numbers[j + 3];
345
- point.x += numbers[j + 4];
346
- point.y += numbers[j + 5];
347
- if (j === 0 && doSetFirstPoint === true)
348
- firstPoint.copy(point);
349
- }
350
- break;
351
- case "s":
352
- numbers = parseFloats(data2);
353
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
354
- path.bezierCurveTo(
355
- getReflection(point.x, control.x),
356
- getReflection(point.y, control.y),
357
- point.x + numbers[j + 0],
358
- point.y + numbers[j + 1],
359
- point.x + numbers[j + 2],
360
- point.y + numbers[j + 3]
361
- );
362
- control.x = point.x + numbers[j + 0];
363
- control.y = point.y + numbers[j + 1];
364
- point.x += numbers[j + 2];
365
- point.y += numbers[j + 3];
366
- if (j === 0 && doSetFirstPoint === true)
367
- firstPoint.copy(point);
368
- }
369
- break;
370
- case "q":
371
- numbers = parseFloats(data2);
372
- for (let j = 0, jl = numbers.length; j < jl; j += 4) {
373
- path.quadraticCurveTo(
374
- point.x + numbers[j + 0],
375
- point.y + numbers[j + 1],
376
- point.x + numbers[j + 2],
377
- point.y + numbers[j + 3]
378
- );
379
- control.x = point.x + numbers[j + 0];
380
- control.y = point.y + numbers[j + 1];
381
- point.x += numbers[j + 2];
382
- point.y += numbers[j + 3];
383
- if (j === 0 && doSetFirstPoint === true)
384
- firstPoint.copy(point);
385
- }
386
- break;
387
- case "t":
388
- numbers = parseFloats(data2);
389
- for (let j = 0, jl = numbers.length; j < jl; j += 2) {
390
- const rx = getReflection(point.x, control.x);
391
- const ry = getReflection(point.y, control.y);
392
- path.quadraticCurveTo(rx, ry, point.x + numbers[j + 0], point.y + numbers[j + 1]);
393
- control.x = rx;
394
- control.y = ry;
395
- point.x = point.x + numbers[j + 0];
396
- point.y = point.y + numbers[j + 1];
397
- if (j === 0 && doSetFirstPoint === true)
398
- firstPoint.copy(point);
399
- }
400
- break;
401
- case "a":
402
- numbers = parseFloats(data2, [3, 4], 7);
403
- for (let j = 0, jl = numbers.length; j < jl; j += 7) {
404
- if (numbers[j + 5] == 0 && numbers[j + 6] == 0)
405
- continue;
406
- const start = point.clone();
407
- point.x += numbers[j + 5];
408
- point.y += numbers[j + 6];
409
- control.x = point.x;
410
- control.y = point.y;
411
- parseArcCommand(
412
- path,
413
- numbers[j],
414
- numbers[j + 1],
415
- numbers[j + 2],
416
- numbers[j + 3],
417
- numbers[j + 4],
418
- start,
419
- point
420
- );
421
- if (j === 0 && doSetFirstPoint === true)
422
- firstPoint.copy(point);
423
- }
424
- break;
425
- case "Z":
426
- case "z":
427
- path.currentPath.autoClose = true;
428
- if (path.currentPath.curves.length > 0) {
429
- point.copy(firstPoint);
430
- path.currentPath.currentPoint.copy(point);
431
- isFirstPoint = true;
432
- }
433
- break;
434
- default:
435
- console.warn(command);
694
+ if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
695
+ state = INT;
696
+ number = current;
697
+ continue;
436
698
  }
437
- doSetFirstPoint = false;
438
- }
439
- return path;
440
- }
441
- function parseCSSStylesheet(node) {
442
- if (!node.sheet || !node.sheet.cssRules || !node.sheet.cssRules.length)
443
- return;
444
- for (let i = 0; i < node.sheet.cssRules.length; i++) {
445
- const stylesheet = node.sheet.cssRules[i];
446
- if (stylesheet.type !== 1)
699
+ if (RE.POINT.test(current)) {
700
+ state = FLOAT;
701
+ number = current;
447
702
  continue;
448
- const selectorList = stylesheet.selectorText.split(/,/gm).filter(Boolean).map((i2) => i2.trim());
449
- for (let j = 0; j < selectorList.length; j++) {
450
- const definitions = Object.fromEntries(Object.entries(stylesheet.style).filter(([, v]) => v !== ""));
451
- stylesheets[selectorList[j]] = Object.assign(stylesheets[selectorList[j]] || {}, definitions);
452
703
  }
453
- }
454
- }
455
- function parseArcCommand(path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end) {
456
- if (rx == 0 || ry == 0) {
457
- path.lineTo(end.x, end.y);
458
- return;
459
- }
460
- x_axis_rotation = x_axis_rotation * Math.PI / 180;
461
- rx = Math.abs(rx);
462
- ry = Math.abs(ry);
463
- const dx2 = (start.x - end.x) / 2;
464
- const dy2 = (start.y - end.y) / 2;
465
- const x1p = Math.cos(x_axis_rotation) * dx2 + Math.sin(x_axis_rotation) * dy2;
466
- const y1p = -Math.sin(x_axis_rotation) * dx2 + Math.cos(x_axis_rotation) * dy2;
467
- let rxs = rx * rx;
468
- let rys = ry * ry;
469
- const x1ps = x1p * x1p;
470
- const y1ps = y1p * y1p;
471
- const cr = x1ps / rxs + y1ps / rys;
472
- if (cr > 1) {
473
- const s = Math.sqrt(cr);
474
- rx = s * rx;
475
- ry = s * ry;
476
- rxs = rx * rx;
477
- rys = ry * ry;
478
- }
479
- const dq = rxs * y1ps + rys * x1ps;
480
- const pq = (rxs * rys - dq) / dq;
481
- let q = Math.sqrt(Math.max(0, pq));
482
- if (large_arc_flag === sweep_flag)
483
- q = -q;
484
- const cxp = q * rx * y1p / ry;
485
- const cyp = -q * ry * x1p / rx;
486
- const cx = Math.cos(x_axis_rotation) * cxp - Math.sin(x_axis_rotation) * cyp + (start.x + end.x) / 2;
487
- const cy = Math.sin(x_axis_rotation) * cxp + Math.cos(x_axis_rotation) * cyp + (start.y + end.y) / 2;
488
- const theta = svgAngle(1, 0, (x1p - cxp) / rx, (y1p - cyp) / ry);
489
- const delta = svgAngle((x1p - cxp) / rx, (y1p - cyp) / ry, (-x1p - cxp) / rx, (-y1p - cyp) / ry) % (Math.PI * 2);
490
- path.currentPath.absellipse(cx, cy, rx, ry, theta, theta + delta, sweep_flag === 0, x_axis_rotation);
491
- }
492
- function svgAngle(ux, uy, vx, vy) {
493
- const dot = ux * vx + uy * vy;
494
- const len = Math.sqrt(ux * ux + uy * uy) * Math.sqrt(vx * vx + vy * vy);
495
- let ang = Math.acos(Math.max(-1, Math.min(1, dot / len)));
496
- if (ux * vy - uy * vx < 0)
497
- ang = -ang;
498
- return ang;
499
- }
500
- function parseRectNode(node) {
501
- const x = parseFloatWithUnits(node.getAttribute("x") || 0);
502
- const y = parseFloatWithUnits(node.getAttribute("y") || 0);
503
- const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
504
- const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
505
- const w = parseFloatWithUnits(node.getAttribute("width"));
506
- const h = parseFloatWithUnits(node.getAttribute("height"));
507
- const bci = 1 - 0.551915024494;
508
- const path = new THREE.ShapePath();
509
- path.moveTo(x + rx, y);
510
- path.lineTo(x + w - rx, y);
511
- if (rx !== 0 || ry !== 0) {
512
- path.bezierCurveTo(x + w - rx * bci, y, x + w, y + ry * bci, x + w, y + ry);
513
- }
514
- path.lineTo(x + w, y + h - ry);
515
- if (rx !== 0 || ry !== 0) {
516
- path.bezierCurveTo(x + w, y + h - ry * bci, x + w - rx * bci, y + h, x + w - rx, y + h);
517
- }
518
- path.lineTo(x + rx, y + h);
519
- if (rx !== 0 || ry !== 0) {
520
- path.bezierCurveTo(x + rx * bci, y + h, x, y + h - ry * bci, x, y + h - ry);
521
- }
522
- path.lineTo(x, y + ry);
523
- if (rx !== 0 || ry !== 0) {
524
- path.bezierCurveTo(x, y + ry * bci, x + rx * bci, y, x + rx, y);
525
- }
526
- return path;
527
- }
528
- function parsePolygonNode(node) {
529
- function iterator(match, a, b) {
530
- const x = parseFloatWithUnits(a);
531
- const y = parseFloatWithUnits(b);
532
- if (index === 0) {
533
- path.moveTo(x, y);
534
- } else {
535
- path.lineTo(x, y);
704
+ if (RE.COMMA.test(current)) {
705
+ if (seenComma) {
706
+ throwSyntaxError(current, i, result);
707
+ }
708
+ seenComma = true;
536
709
  }
537
- index++;
538
710
  }
539
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
540
- const path = new THREE.ShapePath();
541
- let index = 0;
542
- node.getAttribute("points").replace(regex, iterator);
543
- path.currentPath.autoClose = true;
544
- return path;
545
- }
546
- function parsePolylineNode(node) {
547
- function iterator(match, a, b) {
548
- const x = parseFloatWithUnits(a);
549
- const y = parseFloatWithUnits(b);
550
- if (index === 0) {
551
- path.moveTo(x, y);
552
- } else {
553
- path.lineTo(x, y);
711
+ if (state === INT) {
712
+ if (RE.DIGIT.test(current)) {
713
+ number += current;
714
+ continue;
554
715
  }
555
- index++;
556
- }
557
- const regex = /([+-]?\d*\.?\d+(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;
558
- const path = new THREE.ShapePath();
559
- let index = 0;
560
- node.getAttribute("points").replace(regex, iterator);
561
- path.currentPath.autoClose = false;
562
- return path;
563
- }
564
- function parseCircleNode(node) {
565
- const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
566
- const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
567
- const r = parseFloatWithUnits(node.getAttribute("r") || 0);
568
- const subpath = new THREE.Path();
569
- subpath.absarc(x, y, r, 0, Math.PI * 2);
570
- const path = new THREE.ShapePath();
571
- path.subPaths.push(subpath);
572
- return path;
573
- }
574
- function parseEllipseNode(node) {
575
- const x = parseFloatWithUnits(node.getAttribute("cx") || 0);
576
- const y = parseFloatWithUnits(node.getAttribute("cy") || 0);
577
- const rx = parseFloatWithUnits(node.getAttribute("rx") || 0);
578
- const ry = parseFloatWithUnits(node.getAttribute("ry") || 0);
579
- const subpath = new THREE.Path();
580
- subpath.absellipse(x, y, rx, ry, 0, Math.PI * 2);
581
- const path = new THREE.ShapePath();
582
- path.subPaths.push(subpath);
583
- return path;
584
- }
585
- function parseLineNode(node) {
586
- const x1 = parseFloatWithUnits(node.getAttribute("x1") || 0);
587
- const y1 = parseFloatWithUnits(node.getAttribute("y1") || 0);
588
- const x2 = parseFloatWithUnits(node.getAttribute("x2") || 0);
589
- const y2 = parseFloatWithUnits(node.getAttribute("y2") || 0);
590
- const path = new THREE.ShapePath();
591
- path.moveTo(x1, y1);
592
- path.lineTo(x2, y2);
593
- path.currentPath.autoClose = false;
594
- return path;
595
- }
596
- function parseStyle(node, style) {
597
- style = Object.assign({}, style);
598
- let stylesheetStyles = {};
599
- if (node.hasAttribute("class")) {
600
- const classSelectors = node.getAttribute("class").split(/\s/).filter(Boolean).map((i) => i.trim());
601
- for (let i = 0; i < classSelectors.length; i++) {
602
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["." + classSelectors[i]]);
716
+ if (RE.POINT.test(current)) {
717
+ number += current;
718
+ state = FLOAT;
719
+ continue;
603
720
  }
604
- }
605
- if (node.hasAttribute("id")) {
606
- stylesheetStyles = Object.assign(stylesheetStyles, stylesheets["#" + node.getAttribute("id")]);
607
- }
608
- function addStyle(svgName, jsName, adjustFunction) {
609
- if (adjustFunction === void 0)
610
- adjustFunction = function copy(v) {
611
- if (v.startsWith("url"))
612
- console.warn("SVGLoader: url access in attributes is not implemented.");
613
- return v;
614
- };
615
- if (node.hasAttribute(svgName))
616
- style[jsName] = adjustFunction(node.getAttribute(svgName));
617
- if (stylesheetStyles[svgName])
618
- style[jsName] = adjustFunction(stylesheetStyles[svgName]);
619
- if (node.style && node.style[svgName] !== "")
620
- style[jsName] = adjustFunction(node.style[svgName]);
621
- }
622
- function clamp(v) {
623
- return Math.max(0, Math.min(1, parseFloatWithUnits(v)));
624
- }
625
- function positive(v) {
626
- return Math.max(0, parseFloatWithUnits(v));
627
- }
628
- addStyle("fill", "fill");
629
- addStyle("fill-opacity", "fillOpacity", clamp);
630
- addStyle("fill-rule", "fillRule");
631
- addStyle("opacity", "opacity", clamp);
632
- addStyle("stroke", "stroke");
633
- addStyle("stroke-opacity", "strokeOpacity", clamp);
634
- addStyle("stroke-width", "strokeWidth", positive);
635
- addStyle("stroke-linejoin", "strokeLineJoin");
636
- addStyle("stroke-linecap", "strokeLineCap");
637
- addStyle("stroke-miterlimit", "strokeMiterLimit", positive);
638
- addStyle("visibility", "visibility");
639
- return style;
640
- }
641
- function getReflection(a, b) {
642
- return a - (b - a);
643
- }
644
- function parseFloats(input, flags, stride) {
645
- if (typeof input !== "string") {
646
- throw new TypeError("Invalid input: " + typeof input);
647
- }
648
- const RE = {
649
- SEPARATOR: /[ \t\r\n\,.\-+]/,
650
- WHITESPACE: /[ \t\r\n]/,
651
- DIGIT: /[\d]/,
652
- SIGN: /[-+]/,
653
- POINT: /\./,
654
- COMMA: /,/,
655
- EXP: /e/i,
656
- FLAGS: /[01]/
657
- };
658
- const SEP = 0;
659
- const INT = 1;
660
- const FLOAT = 2;
661
- const EXP = 3;
662
- let state = SEP;
663
- let seenComma = true;
664
- let number = "", exponent = "";
665
- const result = [];
666
- function throwSyntaxError(current2, i, partial) {
667
- const error = new SyntaxError('Unexpected character "' + current2 + '" at index ' + i + ".");
668
- error.partial = partial;
669
- throw error;
670
- }
671
- function newNumber() {
672
- if (number !== "") {
673
- if (exponent === "")
674
- result.push(Number(number));
675
- else
676
- result.push(Number(number) * Math.pow(10, Number(exponent)));
721
+ if (RE.EXP.test(current)) {
722
+ state = EXP;
723
+ continue;
724
+ }
725
+ if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
726
+ throwSyntaxError(current, i, result);
677
727
  }
678
- number = "";
679
- exponent = "";
680
728
  }
681
- let current;
682
- const length = input.length;
683
- for (let i = 0; i < length; i++) {
684
- current = input[i];
685
- if (Array.isArray(flags) && flags.includes(result.length % stride) && RE.FLAGS.test(current)) {
686
- state = INT;
687
- number = current;
688
- newNumber();
729
+ if (state === FLOAT) {
730
+ if (RE.DIGIT.test(current)) {
731
+ number += current;
689
732
  continue;
690
733
  }
691
- if (state === SEP) {
692
- if (RE.WHITESPACE.test(current)) {
693
- continue;
694
- }
695
- if (RE.DIGIT.test(current) || RE.SIGN.test(current)) {
696
- state = INT;
697
- number = current;
698
- continue;
699
- }
700
- if (RE.POINT.test(current)) {
701
- state = FLOAT;
702
- number = current;
703
- continue;
704
- }
705
- if (RE.COMMA.test(current)) {
706
- if (seenComma) {
707
- throwSyntaxError(current, i, result);
708
- }
709
- seenComma = true;
710
- }
734
+ if (RE.EXP.test(current)) {
735
+ state = EXP;
736
+ continue;
711
737
  }
712
- if (state === INT) {
713
- if (RE.DIGIT.test(current)) {
714
- number += current;
715
- continue;
716
- }
717
- if (RE.POINT.test(current)) {
718
- number += current;
719
- state = FLOAT;
720
- continue;
721
- }
722
- if (RE.EXP.test(current)) {
723
- state = EXP;
724
- continue;
725
- }
726
- if (RE.SIGN.test(current) && number.length === 1 && RE.SIGN.test(number[0])) {
727
- throwSyntaxError(current, i, result);
728
- }
738
+ if (RE.POINT.test(current) && number[number.length - 1] === ".") {
739
+ throwSyntaxError(current, i, result);
729
740
  }
730
- if (state === FLOAT) {
731
- if (RE.DIGIT.test(current)) {
732
- number += current;
733
- continue;
734
- }
735
- if (RE.EXP.test(current)) {
736
- state = EXP;
737
- continue;
738
- }
739
- if (RE.POINT.test(current) && number[number.length - 1] === ".") {
740
- throwSyntaxError(current, i, result);
741
- }
741
+ }
742
+ if (state === EXP) {
743
+ if (RE.DIGIT.test(current)) {
744
+ exponent += current;
745
+ continue;
742
746
  }
743
- if (state === EXP) {
744
- if (RE.DIGIT.test(current)) {
747
+ if (RE.SIGN.test(current)) {
748
+ if (exponent === "") {
745
749
  exponent += current;
746
750
  continue;
747
751
  }
748
- if (RE.SIGN.test(current)) {
749
- if (exponent === "") {
750
- exponent += current;
751
- continue;
752
- }
753
- if (exponent.length === 1 && RE.SIGN.test(exponent)) {
754
- throwSyntaxError(current, i, result);
755
- }
756
- }
757
- }
758
- if (RE.WHITESPACE.test(current)) {
759
- newNumber();
760
- state = SEP;
761
- seenComma = false;
762
- } else if (RE.COMMA.test(current)) {
763
- newNumber();
764
- state = SEP;
765
- seenComma = true;
766
- } else if (RE.SIGN.test(current)) {
767
- newNumber();
768
- state = INT;
769
- number = current;
770
- } else if (RE.POINT.test(current)) {
771
- newNumber();
772
- state = FLOAT;
773
- number = current;
774
- } else {
775
- throwSyntaxError(current, i, result);
776
- }
777
- }
778
- newNumber();
779
- return result;
780
- }
781
- const units = ["mm", "cm", "in", "pt", "pc", "px"];
782
- const unitConversion = {
783
- mm: {
784
- mm: 1,
785
- cm: 0.1,
786
- in: 1 / 25.4,
787
- pt: 72 / 25.4,
788
- pc: 6 / 25.4,
789
- px: -1
790
- },
791
- cm: {
792
- mm: 10,
793
- cm: 1,
794
- in: 1 / 2.54,
795
- pt: 72 / 2.54,
796
- pc: 6 / 2.54,
797
- px: -1
798
- },
799
- in: {
800
- mm: 25.4,
801
- cm: 2.54,
802
- in: 1,
803
- pt: 72,
804
- pc: 6,
805
- px: -1
806
- },
807
- pt: {
808
- mm: 25.4 / 72,
809
- cm: 2.54 / 72,
810
- in: 1 / 72,
811
- pt: 1,
812
- pc: 6 / 72,
813
- px: -1
814
- },
815
- pc: {
816
- mm: 25.4 / 6,
817
- cm: 2.54 / 6,
818
- in: 1 / 6,
819
- pt: 72 / 6,
820
- pc: 1,
821
- px: -1
822
- },
823
- px: {
824
- px: 1
825
- }
826
- };
827
- function parseFloatWithUnits(string) {
828
- let theUnit = "px";
829
- if (typeof string === "string" || string instanceof String) {
830
- for (let i = 0, n = units.length; i < n; i++) {
831
- const u = units[i];
832
- if (string.endsWith(u)) {
833
- theUnit = u;
834
- string = string.substring(0, string.length - u.length);
835
- break;
752
+ if (exponent.length === 1 && RE.SIGN.test(exponent)) {
753
+ throwSyntaxError(current, i, result);
836
754
  }
837
755
  }
838
756
  }
839
- let scale = void 0;
840
- if (theUnit === "px" && scope.defaultUnit !== "px") {
841
- scale = unitConversion["in"][scope.defaultUnit] / scope.defaultDPI;
757
+ if (RE.WHITESPACE.test(current)) {
758
+ newNumber();
759
+ state = SEP;
760
+ seenComma = false;
761
+ } else if (RE.COMMA.test(current)) {
762
+ newNumber();
763
+ state = SEP;
764
+ seenComma = true;
765
+ } else if (RE.SIGN.test(current)) {
766
+ newNumber();
767
+ state = INT;
768
+ number = current;
769
+ } else if (RE.POINT.test(current)) {
770
+ newNumber();
771
+ state = FLOAT;
772
+ number = current;
842
773
  } else {
843
- scale = unitConversion[theUnit][scope.defaultUnit];
844
- if (scale < 0) {
845
- scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
846
- }
774
+ throwSyntaxError(current, i, result);
847
775
  }
848
- return scale * parseFloat(string);
849
776
  }
850
- function getNodeTransform(node) {
851
- if (!(node.hasAttribute("transform") || node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y")))) {
852
- return null;
853
- }
854
- const transform = parseNodeTransform(node);
855
- if (transformStack.length > 0) {
856
- transform.premultiply(transformStack[transformStack.length - 1]);
777
+ newNumber();
778
+ return result;
779
+ }
780
+ const units = ["mm", "cm", "in", "pt", "pc", "px"];
781
+ const unitConversion = {
782
+ mm: {
783
+ mm: 1,
784
+ cm: 0.1,
785
+ in: 1 / 25.4,
786
+ pt: 72 / 25.4,
787
+ pc: 6 / 25.4,
788
+ px: -1
789
+ },
790
+ cm: {
791
+ mm: 10,
792
+ cm: 1,
793
+ in: 1 / 2.54,
794
+ pt: 72 / 2.54,
795
+ pc: 6 / 2.54,
796
+ px: -1
797
+ },
798
+ in: {
799
+ mm: 25.4,
800
+ cm: 2.54,
801
+ in: 1,
802
+ pt: 72,
803
+ pc: 6,
804
+ px: -1
805
+ },
806
+ pt: {
807
+ mm: 25.4 / 72,
808
+ cm: 2.54 / 72,
809
+ in: 1 / 72,
810
+ pt: 1,
811
+ pc: 6 / 72,
812
+ px: -1
813
+ },
814
+ pc: {
815
+ mm: 25.4 / 6,
816
+ cm: 2.54 / 6,
817
+ in: 1 / 6,
818
+ pt: 72 / 6,
819
+ pc: 1,
820
+ px: -1
821
+ },
822
+ px: {
823
+ px: 1
824
+ }
825
+ };
826
+ function parseFloatWithUnits(string) {
827
+ let theUnit = "px";
828
+ if (typeof string === "string" || string instanceof String) {
829
+ for (let i = 0, n = units.length; i < n; i++) {
830
+ const u = units[i];
831
+ if (string.endsWith(u)) {
832
+ theUnit = u;
833
+ string = string.substring(0, string.length - u.length);
834
+ break;
835
+ }
857
836
  }
858
- currentTransform.copy(transform);
859
- transformStack.push(transform);
860
- return transform;
861
- }
862
- function parseNodeTransform(node) {
863
- const transform = new THREE.Matrix3();
864
- const currentTransform2 = tempTransform0;
865
- if (node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y"))) {
866
- const tx = parseFloatWithUnits(node.getAttribute("x"));
867
- const ty = parseFloatWithUnits(node.getAttribute("y"));
868
- transform.translate(tx, ty);
837
+ }
838
+ let scale = void 0;
839
+ if (theUnit === "px" && scope.defaultUnit !== "px") {
840
+ scale = unitConversion["in"][scope.defaultUnit] / scope.defaultDPI;
841
+ } else {
842
+ scale = unitConversion[theUnit][scope.defaultUnit];
843
+ if (scale < 0) {
844
+ scale = unitConversion[theUnit]["in"] * scope.defaultDPI;
869
845
  }
870
- if (node.hasAttribute("transform")) {
871
- const transformsTexts = node.getAttribute("transform").split(")");
872
- for (let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
873
- const transformText = transformsTexts[tIndex].trim();
874
- if (transformText === "")
875
- continue;
876
- const openParPos = transformText.indexOf("(");
877
- const closeParPos = transformText.length;
878
- if (openParPos > 0 && openParPos < closeParPos) {
879
- const transformType = transformText.slice(0, openParPos);
880
- const array = parseFloats(transformText.slice(openParPos + 1));
881
- currentTransform2.identity();
882
- switch (transformType) {
883
- case "translate":
884
- if (array.length >= 1) {
885
- const tx = array[0];
886
- let ty = 0;
887
- if (array.length >= 2) {
888
- ty = array[1];
889
- }
890
- currentTransform2.translate(tx, ty);
891
- }
892
- break;
893
- case "rotate":
894
- if (array.length >= 1) {
895
- let angle = 0;
896
- let cx = 0;
897
- let cy = 0;
898
- angle = array[0] * Math.PI / 180;
899
- if (array.length >= 3) {
900
- cx = array[1];
901
- cy = array[2];
902
- }
903
- tempTransform1.makeTranslation(-cx, -cy);
904
- tempTransform2.makeRotation(angle);
905
- tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
906
- tempTransform1.makeTranslation(cx, cy);
907
- currentTransform2.multiplyMatrices(tempTransform1, tempTransform3);
908
- }
909
- break;
910
- case "scale":
911
- if (array.length >= 1) {
912
- const scaleX = array[0];
913
- let scaleY = scaleX;
914
- if (array.length >= 2) {
915
- scaleY = array[1];
916
- }
917
- currentTransform2.scale(scaleX, scaleY);
918
- }
919
- break;
920
- case "skewX":
921
- if (array.length === 1) {
922
- currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
846
+ }
847
+ return scale * parseFloat(string);
848
+ }
849
+ function getNodeTransform(node) {
850
+ if (!(node.hasAttribute("transform") || node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y")))) {
851
+ return null;
852
+ }
853
+ const transform = parseNodeTransform(node);
854
+ if (transformStack.length > 0) {
855
+ transform.premultiply(transformStack[transformStack.length - 1]);
856
+ }
857
+ currentTransform.copy(transform);
858
+ transformStack.push(transform);
859
+ return transform;
860
+ }
861
+ function parseNodeTransform(node) {
862
+ const transform = new THREE.Matrix3();
863
+ const currentTransform2 = tempTransform0;
864
+ if (node.nodeName === "use" && (node.hasAttribute("x") || node.hasAttribute("y"))) {
865
+ const tx = parseFloatWithUnits(node.getAttribute("x"));
866
+ const ty = parseFloatWithUnits(node.getAttribute("y"));
867
+ transform.translate(tx, ty);
868
+ }
869
+ if (node.hasAttribute("transform")) {
870
+ const transformsTexts = node.getAttribute("transform").split(")");
871
+ for (let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex--) {
872
+ const transformText = transformsTexts[tIndex].trim();
873
+ if (transformText === "")
874
+ continue;
875
+ const openParPos = transformText.indexOf("(");
876
+ const closeParPos = transformText.length;
877
+ if (openParPos > 0 && openParPos < closeParPos) {
878
+ const transformType = transformText.slice(0, openParPos);
879
+ const array = parseFloats(transformText.slice(openParPos + 1));
880
+ currentTransform2.identity();
881
+ switch (transformType) {
882
+ case "translate":
883
+ if (array.length >= 1) {
884
+ const tx = array[0];
885
+ let ty = 0;
886
+ if (array.length >= 2) {
887
+ ty = array[1];
923
888
  }
924
- break;
925
- case "skewY":
926
- if (array.length === 1) {
927
- currentTransform2.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
889
+ currentTransform2.translate(tx, ty);
890
+ }
891
+ break;
892
+ case "rotate":
893
+ if (array.length >= 1) {
894
+ let angle = 0;
895
+ let cx = 0;
896
+ let cy = 0;
897
+ angle = array[0] * Math.PI / 180;
898
+ if (array.length >= 3) {
899
+ cx = array[1];
900
+ cy = array[2];
928
901
  }
929
- break;
930
- case "matrix":
931
- if (array.length === 6) {
932
- currentTransform2.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
902
+ tempTransform1.makeTranslation(-cx, -cy);
903
+ tempTransform2.makeRotation(angle);
904
+ tempTransform3.multiplyMatrices(tempTransform2, tempTransform1);
905
+ tempTransform1.makeTranslation(cx, cy);
906
+ currentTransform2.multiplyMatrices(tempTransform1, tempTransform3);
907
+ }
908
+ break;
909
+ case "scale":
910
+ if (array.length >= 1) {
911
+ const scaleX = array[0];
912
+ let scaleY = scaleX;
913
+ if (array.length >= 2) {
914
+ scaleY = array[1];
933
915
  }
934
- break;
935
- }
916
+ currentTransform2.scale(scaleX, scaleY);
917
+ }
918
+ break;
919
+ case "skewX":
920
+ if (array.length === 1) {
921
+ currentTransform2.set(1, Math.tan(array[0] * Math.PI / 180), 0, 0, 1, 0, 0, 0, 1);
922
+ }
923
+ break;
924
+ case "skewY":
925
+ if (array.length === 1) {
926
+ currentTransform2.set(1, 0, 0, Math.tan(array[0] * Math.PI / 180), 1, 0, 0, 0, 1);
927
+ }
928
+ break;
929
+ case "matrix":
930
+ if (array.length === 6) {
931
+ currentTransform2.set(array[0], array[2], array[4], array[1], array[3], array[5], 0, 0, 1);
932
+ }
933
+ break;
936
934
  }
937
- transform.premultiply(currentTransform2);
938
935
  }
936
+ transform.premultiply(currentTransform2);
939
937
  }
940
- return transform;
941
938
  }
942
- function transformPath(path, m) {
943
- function transfVec2(v2) {
944
- tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
945
- v2.set(tempV3.x, tempV3.y);
946
- }
947
- function transfEllipseGeneric(curve) {
948
- const a = curve.xRadius;
949
- const b = curve.yRadius;
950
- const cosTheta = Math.cos(curve.aRotation);
951
- const sinTheta = Math.sin(curve.aRotation);
952
- const v1 = new THREE.Vector3(a * cosTheta, a * sinTheta, 0);
953
- const v2 = new THREE.Vector3(-b * sinTheta, b * cosTheta, 0);
954
- const f1 = v1.applyMatrix3(m);
955
- const f2 = v2.applyMatrix3(m);
956
- const mF = tempTransform0.set(f1.x, f2.x, 0, f1.y, f2.y, 0, 0, 0, 1);
957
- const mFInv = tempTransform1.copy(mF).invert();
958
- const mFInvT = tempTransform2.copy(mFInv).transpose();
959
- const mQ = mFInvT.multiply(mFInv);
960
- const mQe = mQ.elements;
961
- const ed = eigenDecomposition(mQe[0], mQe[1], mQe[4]);
962
- const rt1sqrt = Math.sqrt(ed.rt1);
963
- const rt2sqrt = Math.sqrt(ed.rt2);
964
- curve.xRadius = 1 / rt1sqrt;
965
- curve.yRadius = 1 / rt2sqrt;
966
- curve.aRotation = Math.atan2(ed.sn, ed.cs);
967
- const isFullEllipse = (curve.aEndAngle - curve.aStartAngle) % (2 * Math.PI) < Number.EPSILON;
968
- if (!isFullEllipse) {
969
- const mDsqrt = tempTransform1.set(rt1sqrt, 0, 0, 0, rt2sqrt, 0, 0, 0, 1);
970
- const mRT = tempTransform2.set(ed.cs, ed.sn, 0, -ed.sn, ed.cs, 0, 0, 0, 1);
971
- const mDRF = mDsqrt.multiply(mRT).multiply(mF);
972
- const transformAngle = (phi) => {
973
- const { x: cosR, y: sinR } = new THREE.Vector3(Math.cos(phi), Math.sin(phi), 0).applyMatrix3(mDRF);
974
- return Math.atan2(sinR, cosR);
975
- };
976
- curve.aStartAngle = transformAngle(curve.aStartAngle);
977
- curve.aEndAngle = transformAngle(curve.aEndAngle);
978
- if (isTransformFlipped(m)) {
979
- curve.aClockwise = !curve.aClockwise;
980
- }
981
- }
982
- }
983
- function transfEllipseNoSkew(curve) {
984
- const sx = getTransformScaleX(m);
985
- const sy = getTransformScaleY(m);
986
- curve.xRadius *= sx;
987
- curve.yRadius *= sy;
988
- const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
989
- curve.aRotation += theta;
939
+ return transform;
940
+ }
941
+ function transformPath(path, m) {
942
+ function transfVec2(v2) {
943
+ tempV3.set(v2.x, v2.y, 1).applyMatrix3(m);
944
+ v2.set(tempV3.x, tempV3.y);
945
+ }
946
+ function transfEllipseGeneric(curve) {
947
+ const a = curve.xRadius;
948
+ const b = curve.yRadius;
949
+ const cosTheta = Math.cos(curve.aRotation);
950
+ const sinTheta = Math.sin(curve.aRotation);
951
+ const v1 = new THREE.Vector3(a * cosTheta, a * sinTheta, 0);
952
+ const v2 = new THREE.Vector3(-b * sinTheta, b * cosTheta, 0);
953
+ const f1 = v1.applyMatrix3(m);
954
+ const f2 = v2.applyMatrix3(m);
955
+ const mF = tempTransform0.set(f1.x, f2.x, 0, f1.y, f2.y, 0, 0, 0, 1);
956
+ const mFInv = tempTransform1.copy(mF).invert();
957
+ const mFInvT = tempTransform2.copy(mFInv).transpose();
958
+ const mQ = mFInvT.multiply(mFInv);
959
+ const mQe = mQ.elements;
960
+ const ed = eigenDecomposition(mQe[0], mQe[1], mQe[4]);
961
+ const rt1sqrt = Math.sqrt(ed.rt1);
962
+ const rt2sqrt = Math.sqrt(ed.rt2);
963
+ curve.xRadius = 1 / rt1sqrt;
964
+ curve.yRadius = 1 / rt2sqrt;
965
+ curve.aRotation = Math.atan2(ed.sn, ed.cs);
966
+ const isFullEllipse = (curve.aEndAngle - curve.aStartAngle) % (2 * Math.PI) < Number.EPSILON;
967
+ if (!isFullEllipse) {
968
+ const mDsqrt = tempTransform1.set(rt1sqrt, 0, 0, 0, rt2sqrt, 0, 0, 0, 1);
969
+ const mRT = tempTransform2.set(ed.cs, ed.sn, 0, -ed.sn, ed.cs, 0, 0, 0, 1);
970
+ const mDRF = mDsqrt.multiply(mRT).multiply(mF);
971
+ const transformAngle = (phi) => {
972
+ const { x: cosR, y: sinR } = new THREE.Vector3(Math.cos(phi), Math.sin(phi), 0).applyMatrix3(mDRF);
973
+ return Math.atan2(sinR, cosR);
974
+ };
975
+ curve.aStartAngle = transformAngle(curve.aStartAngle);
976
+ curve.aEndAngle = transformAngle(curve.aEndAngle);
990
977
  if (isTransformFlipped(m)) {
991
- curve.aStartAngle *= -1;
992
- curve.aEndAngle *= -1;
993
978
  curve.aClockwise = !curve.aClockwise;
994
979
  }
995
980
  }
996
- const subPaths = path.subPaths;
997
- for (let i = 0, n = subPaths.length; i < n; i++) {
998
- const subPath = subPaths[i];
999
- const curves = subPath.curves;
1000
- for (let j = 0; j < curves.length; j++) {
1001
- const curve = curves[j];
1002
- if (curve.isLineCurve) {
1003
- transfVec2(curve.v1);
1004
- transfVec2(curve.v2);
1005
- } else if (curve.isCubicBezierCurve) {
1006
- transfVec2(curve.v0);
1007
- transfVec2(curve.v1);
1008
- transfVec2(curve.v2);
1009
- transfVec2(curve.v3);
1010
- } else if (curve.isQuadraticBezierCurve) {
1011
- transfVec2(curve.v0);
1012
- transfVec2(curve.v1);
1013
- transfVec2(curve.v2);
1014
- } else if (curve.isEllipseCurve) {
1015
- tempV2.set(curve.aX, curve.aY);
1016
- transfVec2(tempV2);
1017
- curve.aX = tempV2.x;
1018
- curve.aY = tempV2.y;
1019
- if (isTransformSkewed(m)) {
1020
- transfEllipseGeneric(curve);
1021
- } else {
1022
- transfEllipseNoSkew(curve);
1023
- }
1024
- }
1025
- }
1026
- }
1027
- }
1028
- function isTransformFlipped(m) {
1029
- const te = m.elements;
1030
- return te[0] * te[4] - te[1] * te[3] < 0;
1031
981
  }
1032
- function isTransformSkewed(m) {
1033
- const te = m.elements;
1034
- const basisDot = te[0] * te[3] + te[1] * te[4];
1035
- if (basisDot === 0)
1036
- return false;
982
+ function transfEllipseNoSkew(curve) {
1037
983
  const sx = getTransformScaleX(m);
1038
984
  const sy = getTransformScaleY(m);
1039
- return Math.abs(basisDot / (sx * sy)) > Number.EPSILON;
1040
- }
1041
- function getTransformScaleX(m) {
1042
- const te = m.elements;
1043
- return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
1044
- }
1045
- function getTransformScaleY(m) {
1046
- const te = m.elements;
1047
- return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
1048
- }
1049
- function eigenDecomposition(A, B, C) {
1050
- let rt1, rt2, cs, sn, t;
1051
- const sm = A + C;
1052
- const df = A - C;
1053
- const rt = Math.sqrt(df * df + 4 * B * B);
1054
- if (sm > 0) {
1055
- rt1 = 0.5 * (sm + rt);
1056
- t = 1 / rt1;
1057
- rt2 = A * t * C - B * t * B;
1058
- } else if (sm < 0) {
1059
- rt2 = 0.5 * (sm - rt);
1060
- } else {
1061
- rt1 = 0.5 * rt;
1062
- rt2 = -0.5 * rt;
1063
- }
1064
- if (df > 0) {
1065
- cs = df + rt;
1066
- } else {
1067
- cs = df - rt;
1068
- }
1069
- if (Math.abs(cs) > 2 * Math.abs(B)) {
1070
- t = -2 * B / cs;
1071
- sn = 1 / Math.sqrt(1 + t * t);
1072
- cs = t * sn;
1073
- } else if (Math.abs(B) === 0) {
1074
- cs = 1;
1075
- sn = 0;
1076
- } else {
1077
- t = -0.5 * cs / B;
1078
- cs = 1 / Math.sqrt(1 + t * t);
1079
- sn = t * cs;
1080
- }
1081
- if (df > 0) {
1082
- t = cs;
1083
- cs = -sn;
1084
- sn = t;
1085
- }
1086
- return { rt1, rt2, cs, sn };
1087
- }
1088
- const paths = [];
1089
- const stylesheets = {};
1090
- const transformStack = [];
1091
- const tempTransform0 = new THREE.Matrix3();
1092
- const tempTransform1 = new THREE.Matrix3();
1093
- const tempTransform2 = new THREE.Matrix3();
1094
- const tempTransform3 = new THREE.Matrix3();
1095
- const tempV2 = new THREE.Vector2();
1096
- const tempV3 = new THREE.Vector3();
1097
- const currentTransform = new THREE.Matrix3();
1098
- const xml = new DOMParser().parseFromString(text, "image/svg+xml");
1099
- parseNode(xml.documentElement, {
1100
- fill: "#000",
1101
- fillOpacity: 1,
1102
- strokeOpacity: 1,
1103
- strokeWidth: 1,
1104
- strokeLineJoin: "miter",
1105
- strokeLineCap: "butt",
1106
- strokeMiterLimit: 4
1107
- });
1108
- const data = { paths, xml: xml.documentElement };
1109
- return data;
1110
- }
1111
- static createShapes(shapePath) {
1112
- const BIGNUMBER = 999999999;
1113
- const IntersectionLocationType = {
1114
- ORIGIN: 0,
1115
- DESTINATION: 1,
1116
- BETWEEN: 2,
1117
- LEFT: 3,
1118
- RIGHT: 4,
1119
- BEHIND: 5,
1120
- BEYOND: 6
1121
- };
1122
- const classifyResult = {
1123
- loc: IntersectionLocationType.ORIGIN,
1124
- t: 0
1125
- };
1126
- function findEdgeIntersection(a0, a1, b0, b1) {
1127
- const x1 = a0.x;
1128
- const x2 = a1.x;
1129
- const x3 = b0.x;
1130
- const x4 = b1.x;
1131
- const y1 = a0.y;
1132
- const y2 = a1.y;
1133
- const y3 = b0.y;
1134
- const y4 = b1.y;
1135
- const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
1136
- const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
1137
- const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
1138
- const t1 = nom1 / denom;
1139
- const t2 = nom2 / denom;
1140
- if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
1141
- return null;
1142
- } else if (nom1 === 0 && denom === 0) {
1143
- for (let i = 0; i < 2; i++) {
1144
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1145
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1146
- const point = i === 0 ? b0 : b1;
1147
- return { x: point.x, y: point.y, t: classifyResult.t };
1148
- } else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
1149
- const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
1150
- const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
1151
- return { x, y, t: classifyResult.t };
1152
- }
1153
- }
1154
- return null;
1155
- } else {
1156
- for (let i = 0; i < 2; i++) {
1157
- classifyPoint(i === 0 ? b0 : b1, a0, a1);
1158
- if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1159
- const point = i === 0 ? b0 : b1;
1160
- return { x: point.x, y: point.y, t: classifyResult.t };
1161
- }
1162
- }
1163
- const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
1164
- const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
1165
- return { x, y, t: t1 };
985
+ curve.xRadius *= sx;
986
+ curve.yRadius *= sy;
987
+ const theta = sx > Number.EPSILON ? Math.atan2(m.elements[1], m.elements[0]) : Math.atan2(-m.elements[3], m.elements[4]);
988
+ curve.aRotation += theta;
989
+ if (isTransformFlipped(m)) {
990
+ curve.aStartAngle *= -1;
991
+ curve.aEndAngle *= -1;
992
+ curve.aClockwise = !curve.aClockwise;
1166
993
  }
1167
994
  }
1168
- function classifyPoint(p, edgeStart, edgeEnd) {
1169
- const ax = edgeEnd.x - edgeStart.x;
1170
- const ay = edgeEnd.y - edgeStart.y;
1171
- const bx = p.x - edgeStart.x;
1172
- const by = p.y - edgeStart.y;
1173
- const sa = ax * by - bx * ay;
1174
- if (p.x === edgeStart.x && p.y === edgeStart.y) {
1175
- classifyResult.loc = IntersectionLocationType.ORIGIN;
1176
- classifyResult.t = 0;
1177
- return;
1178
- }
1179
- if (p.x === edgeEnd.x && p.y === edgeEnd.y) {
1180
- classifyResult.loc = IntersectionLocationType.DESTINATION;
1181
- classifyResult.t = 1;
1182
- return;
1183
- }
1184
- if (sa < -Number.EPSILON) {
1185
- classifyResult.loc = IntersectionLocationType.LEFT;
1186
- return;
1187
- }
1188
- if (sa > Number.EPSILON) {
1189
- classifyResult.loc = IntersectionLocationType.RIGHT;
1190
- return;
1191
- }
1192
- if (ax * bx < 0 || ay * by < 0) {
1193
- classifyResult.loc = IntersectionLocationType.BEHIND;
1194
- return;
1195
- }
1196
- if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
1197
- classifyResult.loc = IntersectionLocationType.BEYOND;
1198
- return;
1199
- }
1200
- let t;
1201
- if (ax !== 0) {
1202
- t = bx / ax;
1203
- } else {
1204
- t = by / ay;
1205
- }
1206
- classifyResult.loc = IntersectionLocationType.BETWEEN;
1207
- classifyResult.t = t;
1208
- }
1209
- function getIntersections(path1, path2) {
1210
- const intersectionsRaw = [];
1211
- const intersections = [];
1212
- for (let index = 1; index < path1.length; index++) {
1213
- const path1EdgeStart = path1[index - 1];
1214
- const path1EdgeEnd = path1[index];
1215
- for (let index2 = 1; index2 < path2.length; index2++) {
1216
- const path2EdgeStart = path2[index2 - 1];
1217
- const path2EdgeEnd = path2[index2];
1218
- const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
1219
- if (intersection !== null && intersectionsRaw.find(
1220
- (i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
1221
- ) === void 0) {
1222
- intersectionsRaw.push(intersection);
1223
- intersections.push(new THREE.Vector2(intersection.x, intersection.y));
995
+ const subPaths = path.subPaths;
996
+ for (let i = 0, n = subPaths.length; i < n; i++) {
997
+ const subPath = subPaths[i];
998
+ const curves = subPath.curves;
999
+ for (let j = 0; j < curves.length; j++) {
1000
+ const curve = curves[j];
1001
+ if (curve.isLineCurve) {
1002
+ transfVec2(curve.v1);
1003
+ transfVec2(curve.v2);
1004
+ } else if (curve.isCubicBezierCurve) {
1005
+ transfVec2(curve.v0);
1006
+ transfVec2(curve.v1);
1007
+ transfVec2(curve.v2);
1008
+ transfVec2(curve.v3);
1009
+ } else if (curve.isQuadraticBezierCurve) {
1010
+ transfVec2(curve.v0);
1011
+ transfVec2(curve.v1);
1012
+ transfVec2(curve.v2);
1013
+ } else if (curve.isEllipseCurve) {
1014
+ tempV2.set(curve.aX, curve.aY);
1015
+ transfVec2(tempV2);
1016
+ curve.aX = tempV2.x;
1017
+ curve.aY = tempV2.y;
1018
+ if (isTransformSkewed(m)) {
1019
+ transfEllipseGeneric(curve);
1020
+ } else {
1021
+ transfEllipseNoSkew(curve);
1224
1022
  }
1225
1023
  }
1226
1024
  }
1227
- return intersections;
1228
- }
1229
- function getScanlineIntersections(scanline, boundingBox, paths) {
1230
- const center = new THREE.Vector2();
1231
- boundingBox.getCenter(center);
1232
- const allIntersections = [];
1233
- paths.forEach((path) => {
1234
- if (path.boundingBox.containsPoint(center)) {
1235
- const intersections = getIntersections(scanline, path.points);
1236
- intersections.forEach((p) => {
1237
- allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
1238
- });
1239
- }
1240
- });
1241
- allIntersections.sort((i1, i2) => {
1242
- return i1.point.x - i2.point.x;
1243
- });
1244
- return allIntersections;
1245
1025
  }
1246
- function isHoleTo(simplePath, allPaths, scanlineMinX2, scanlineMaxX2, _fillRule) {
1247
- if (_fillRule === null || _fillRule === void 0 || _fillRule === "") {
1248
- _fillRule = "nonzero";
1249
- }
1250
- const centerBoundingBox = new THREE.Vector2();
1251
- simplePath.boundingBox.getCenter(centerBoundingBox);
1252
- const scanline = [
1253
- new THREE.Vector2(scanlineMinX2, centerBoundingBox.y),
1254
- new THREE.Vector2(scanlineMaxX2, centerBoundingBox.y)
1255
- ];
1256
- const scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
1257
- scanlineIntersections.sort((i1, i2) => {
1258
- return i1.point.x - i2.point.x;
1259
- });
1260
- const baseIntersections = [];
1261
- const otherIntersections = [];
1262
- scanlineIntersections.forEach((i2) => {
1263
- if (i2.identifier === simplePath.identifier) {
1264
- baseIntersections.push(i2);
1265
- } else {
1266
- otherIntersections.push(i2);
1267
- }
1268
- });
1269
- const firstXOfPath = baseIntersections[0].point.x;
1270
- const stack = [];
1271
- let i = 0;
1272
- while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
1273
- if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
1274
- stack.pop();
1275
- } else {
1276
- stack.push(otherIntersections[i].identifier);
1026
+ }
1027
+ function isTransformFlipped(m) {
1028
+ const te = m.elements;
1029
+ return te[0] * te[4] - te[1] * te[3] < 0;
1030
+ }
1031
+ function isTransformSkewed(m) {
1032
+ const te = m.elements;
1033
+ const basisDot = te[0] * te[3] + te[1] * te[4];
1034
+ if (basisDot === 0)
1035
+ return false;
1036
+ const sx = getTransformScaleX(m);
1037
+ const sy = getTransformScaleY(m);
1038
+ return Math.abs(basisDot / (sx * sy)) > Number.EPSILON;
1039
+ }
1040
+ function getTransformScaleX(m) {
1041
+ const te = m.elements;
1042
+ return Math.sqrt(te[0] * te[0] + te[1] * te[1]);
1043
+ }
1044
+ function getTransformScaleY(m) {
1045
+ const te = m.elements;
1046
+ return Math.sqrt(te[3] * te[3] + te[4] * te[4]);
1047
+ }
1048
+ function eigenDecomposition(A, B, C) {
1049
+ let rt1, rt2, cs, sn, t;
1050
+ const sm = A + C;
1051
+ const df = A - C;
1052
+ const rt = Math.sqrt(df * df + 4 * B * B);
1053
+ if (sm > 0) {
1054
+ rt1 = 0.5 * (sm + rt);
1055
+ t = 1 / rt1;
1056
+ rt2 = A * t * C - B * t * B;
1057
+ } else if (sm < 0) {
1058
+ rt2 = 0.5 * (sm - rt);
1059
+ } else {
1060
+ rt1 = 0.5 * rt;
1061
+ rt2 = -0.5 * rt;
1062
+ }
1063
+ if (df > 0) {
1064
+ cs = df + rt;
1065
+ } else {
1066
+ cs = df - rt;
1067
+ }
1068
+ if (Math.abs(cs) > 2 * Math.abs(B)) {
1069
+ t = -2 * B / cs;
1070
+ sn = 1 / Math.sqrt(1 + t * t);
1071
+ cs = t * sn;
1072
+ } else if (Math.abs(B) === 0) {
1073
+ cs = 1;
1074
+ sn = 0;
1075
+ } else {
1076
+ t = -0.5 * cs / B;
1077
+ cs = 1 / Math.sqrt(1 + t * t);
1078
+ sn = t * cs;
1079
+ }
1080
+ if (df > 0) {
1081
+ t = cs;
1082
+ cs = -sn;
1083
+ sn = t;
1084
+ }
1085
+ return { rt1, rt2, cs, sn };
1086
+ }
1087
+ const paths = [];
1088
+ const stylesheets = {};
1089
+ const transformStack = [];
1090
+ const tempTransform0 = new THREE.Matrix3();
1091
+ const tempTransform1 = new THREE.Matrix3();
1092
+ const tempTransform2 = new THREE.Matrix3();
1093
+ const tempTransform3 = new THREE.Matrix3();
1094
+ const tempV2 = new THREE.Vector2();
1095
+ const tempV3 = new THREE.Vector3();
1096
+ const currentTransform = new THREE.Matrix3();
1097
+ const xml = new DOMParser().parseFromString(text, "image/svg+xml");
1098
+ parseNode(xml.documentElement, {
1099
+ fill: "#000",
1100
+ fillOpacity: 1,
1101
+ strokeOpacity: 1,
1102
+ strokeWidth: 1,
1103
+ strokeLineJoin: "miter",
1104
+ strokeLineCap: "butt",
1105
+ strokeMiterLimit: 4
1106
+ });
1107
+ const data = { paths, xml: xml.documentElement };
1108
+ return data;
1109
+ }
1110
+ static createShapes(shapePath) {
1111
+ const BIGNUMBER = 999999999;
1112
+ const IntersectionLocationType = {
1113
+ ORIGIN: 0,
1114
+ DESTINATION: 1,
1115
+ BETWEEN: 2,
1116
+ LEFT: 3,
1117
+ RIGHT: 4,
1118
+ BEHIND: 5,
1119
+ BEYOND: 6
1120
+ };
1121
+ const classifyResult = {
1122
+ loc: IntersectionLocationType.ORIGIN,
1123
+ t: 0
1124
+ };
1125
+ function findEdgeIntersection(a0, a1, b0, b1) {
1126
+ const x1 = a0.x;
1127
+ const x2 = a1.x;
1128
+ const x3 = b0.x;
1129
+ const x4 = b1.x;
1130
+ const y1 = a0.y;
1131
+ const y2 = a1.y;
1132
+ const y3 = b0.y;
1133
+ const y4 = b1.y;
1134
+ const nom1 = (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3);
1135
+ const nom2 = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
1136
+ const denom = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
1137
+ const t1 = nom1 / denom;
1138
+ const t2 = nom2 / denom;
1139
+ if (denom === 0 && nom1 !== 0 || t1 <= 0 || t1 >= 1 || t2 < 0 || t2 > 1) {
1140
+ return null;
1141
+ } else if (nom1 === 0 && denom === 0) {
1142
+ for (let i = 0; i < 2; i++) {
1143
+ classifyPoint(i === 0 ? b0 : b1, a0, a1);
1144
+ if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1145
+ const point = i === 0 ? b0 : b1;
1146
+ return { x: point.x, y: point.y, t: classifyResult.t };
1147
+ } else if (classifyResult.loc == IntersectionLocationType.BETWEEN) {
1148
+ const x = +(x1 + classifyResult.t * (x2 - x1)).toPrecision(10);
1149
+ const y = +(y1 + classifyResult.t * (y2 - y1)).toPrecision(10);
1150
+ return { x, y, t: classifyResult.t };
1277
1151
  }
1278
- i++;
1279
1152
  }
1280
- stack.push(simplePath.identifier);
1281
- if (_fillRule === "evenodd") {
1282
- const isHole = stack.length % 2 === 0 ? true : false;
1283
- const isHoleFor = stack[stack.length - 2];
1284
- return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1285
- } else if (_fillRule === "nonzero") {
1286
- let isHole = true;
1287
- let isHoleFor = null;
1288
- let lastCWValue = null;
1289
- for (let i2 = 0; i2 < stack.length; i2++) {
1290
- const identifier = stack[i2];
1291
- if (isHole) {
1292
- lastCWValue = allPaths[identifier].isCW;
1293
- isHole = false;
1294
- isHoleFor = identifier;
1295
- } else if (lastCWValue !== allPaths[identifier].isCW) {
1296
- lastCWValue = allPaths[identifier].isCW;
1297
- isHole = true;
1298
- }
1153
+ return null;
1154
+ } else {
1155
+ for (let i = 0; i < 2; i++) {
1156
+ classifyPoint(i === 0 ? b0 : b1, a0, a1);
1157
+ if (classifyResult.loc == IntersectionLocationType.ORIGIN) {
1158
+ const point = i === 0 ? b0 : b1;
1159
+ return { x: point.x, y: point.y, t: classifyResult.t };
1299
1160
  }
1300
- return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1301
- } else {
1302
- console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
1303
1161
  }
1162
+ const x = +(x1 + t1 * (x2 - x1)).toPrecision(10);
1163
+ const y = +(y1 + t1 * (y2 - y1)).toPrecision(10);
1164
+ return { x, y, t: t1 };
1304
1165
  }
1305
- let scanlineMinX = BIGNUMBER;
1306
- let scanlineMaxX = -BIGNUMBER;
1307
- let simplePaths = shapePath.subPaths.map((p) => {
1308
- const points = p.getPoints();
1309
- let maxY = -BIGNUMBER;
1310
- let minY = BIGNUMBER;
1311
- let maxX = -BIGNUMBER;
1312
- let minX = BIGNUMBER;
1313
- for (let i = 0; i < points.length; i++) {
1314
- const p2 = points[i];
1315
- if (p2.y > maxY) {
1316
- maxY = p2.y;
1317
- }
1318
- if (p2.y < minY) {
1319
- minY = p2.y;
1320
- }
1321
- if (p2.x > maxX) {
1322
- maxX = p2.x;
1323
- }
1324
- if (p2.x < minX) {
1325
- minX = p2.x;
1166
+ }
1167
+ function classifyPoint(p, edgeStart, edgeEnd) {
1168
+ const ax = edgeEnd.x - edgeStart.x;
1169
+ const ay = edgeEnd.y - edgeStart.y;
1170
+ const bx = p.x - edgeStart.x;
1171
+ const by = p.y - edgeStart.y;
1172
+ const sa = ax * by - bx * ay;
1173
+ if (p.x === edgeStart.x && p.y === edgeStart.y) {
1174
+ classifyResult.loc = IntersectionLocationType.ORIGIN;
1175
+ classifyResult.t = 0;
1176
+ return;
1177
+ }
1178
+ if (p.x === edgeEnd.x && p.y === edgeEnd.y) {
1179
+ classifyResult.loc = IntersectionLocationType.DESTINATION;
1180
+ classifyResult.t = 1;
1181
+ return;
1182
+ }
1183
+ if (sa < -Number.EPSILON) {
1184
+ classifyResult.loc = IntersectionLocationType.LEFT;
1185
+ return;
1186
+ }
1187
+ if (sa > Number.EPSILON) {
1188
+ classifyResult.loc = IntersectionLocationType.RIGHT;
1189
+ return;
1190
+ }
1191
+ if (ax * bx < 0 || ay * by < 0) {
1192
+ classifyResult.loc = IntersectionLocationType.BEHIND;
1193
+ return;
1194
+ }
1195
+ if (Math.sqrt(ax * ax + ay * ay) < Math.sqrt(bx * bx + by * by)) {
1196
+ classifyResult.loc = IntersectionLocationType.BEYOND;
1197
+ return;
1198
+ }
1199
+ let t;
1200
+ if (ax !== 0) {
1201
+ t = bx / ax;
1202
+ } else {
1203
+ t = by / ay;
1204
+ }
1205
+ classifyResult.loc = IntersectionLocationType.BETWEEN;
1206
+ classifyResult.t = t;
1207
+ }
1208
+ function getIntersections(path1, path2) {
1209
+ const intersectionsRaw = [];
1210
+ const intersections = [];
1211
+ for (let index = 1; index < path1.length; index++) {
1212
+ const path1EdgeStart = path1[index - 1];
1213
+ const path1EdgeEnd = path1[index];
1214
+ for (let index2 = 1; index2 < path2.length; index2++) {
1215
+ const path2EdgeStart = path2[index2 - 1];
1216
+ const path2EdgeEnd = path2[index2];
1217
+ const intersection = findEdgeIntersection(path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd);
1218
+ if (intersection !== null && intersectionsRaw.find(
1219
+ (i) => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON
1220
+ ) === void 0) {
1221
+ intersectionsRaw.push(intersection);
1222
+ intersections.push(new THREE.Vector2(intersection.x, intersection.y));
1326
1223
  }
1327
1224
  }
1328
- if (scanlineMaxX <= maxX) {
1329
- scanlineMaxX = maxX + 1;
1330
- }
1331
- if (scanlineMinX >= minX) {
1332
- scanlineMinX = minX - 1;
1225
+ }
1226
+ return intersections;
1227
+ }
1228
+ function getScanlineIntersections(scanline, boundingBox, paths) {
1229
+ const center = new THREE.Vector2();
1230
+ boundingBox.getCenter(center);
1231
+ const allIntersections = [];
1232
+ paths.forEach((path) => {
1233
+ if (path.boundingBox.containsPoint(center)) {
1234
+ const intersections = getIntersections(scanline, path.points);
1235
+ intersections.forEach((p) => {
1236
+ allIntersections.push({ identifier: path.identifier, isCW: path.isCW, point: p });
1237
+ });
1333
1238
  }
1334
- return {
1335
- curves: p.curves,
1336
- points,
1337
- isCW: THREE.ShapeUtils.isClockWise(points),
1338
- identifier: -1,
1339
- boundingBox: new THREE.Box2(new THREE.Vector2(minX, minY), new THREE.Vector2(maxX, maxY))
1340
- };
1341
1239
  });
1342
- simplePaths = simplePaths.filter((sp) => sp.points.length > 1);
1343
- for (let identifier = 0; identifier < simplePaths.length; identifier++) {
1344
- simplePaths[identifier].identifier = identifier;
1345
- }
1346
- const isAHole = simplePaths.map(
1347
- (p) => isHoleTo(
1348
- p,
1349
- simplePaths,
1350
- scanlineMinX,
1351
- scanlineMaxX,
1352
- shapePath.userData ? shapePath.userData.style.fillRule : void 0
1353
- )
1354
- );
1355
- const shapesToReturn = [];
1356
- simplePaths.forEach((p) => {
1357
- const amIAHole = isAHole[p.identifier];
1358
- if (!amIAHole.isHole) {
1359
- const shape = new THREE.Shape();
1360
- shape.curves = p.curves;
1361
- const holes = isAHole.filter((h) => h.isHole && h.for === p.identifier);
1362
- holes.forEach((h) => {
1363
- const hole = simplePaths[h.identifier];
1364
- const path = new THREE.Path();
1365
- path.curves = hole.curves;
1366
- shape.holes.push(path);
1367
- });
1368
- shapesToReturn.push(shape);
1240
+ allIntersections.sort((i1, i2) => {
1241
+ return i1.point.x - i2.point.x;
1242
+ });
1243
+ return allIntersections;
1244
+ }
1245
+ function isHoleTo(simplePath, allPaths, scanlineMinX2, scanlineMaxX2, _fillRule) {
1246
+ if (_fillRule === null || _fillRule === void 0 || _fillRule === "") {
1247
+ _fillRule = "nonzero";
1248
+ }
1249
+ const centerBoundingBox = new THREE.Vector2();
1250
+ simplePath.boundingBox.getCenter(centerBoundingBox);
1251
+ const scanline = [new THREE.Vector2(scanlineMinX2, centerBoundingBox.y), new THREE.Vector2(scanlineMaxX2, centerBoundingBox.y)];
1252
+ const scanlineIntersections = getScanlineIntersections(scanline, simplePath.boundingBox, allPaths);
1253
+ scanlineIntersections.sort((i1, i2) => {
1254
+ return i1.point.x - i2.point.x;
1255
+ });
1256
+ const baseIntersections = [];
1257
+ const otherIntersections = [];
1258
+ scanlineIntersections.forEach((i2) => {
1259
+ if (i2.identifier === simplePath.identifier) {
1260
+ baseIntersections.push(i2);
1261
+ } else {
1262
+ otherIntersections.push(i2);
1369
1263
  }
1370
1264
  });
1371
- return shapesToReturn;
1265
+ const firstXOfPath = baseIntersections[0].point.x;
1266
+ const stack = [];
1267
+ let i = 0;
1268
+ while (i < otherIntersections.length && otherIntersections[i].point.x < firstXOfPath) {
1269
+ if (stack.length > 0 && stack[stack.length - 1] === otherIntersections[i].identifier) {
1270
+ stack.pop();
1271
+ } else {
1272
+ stack.push(otherIntersections[i].identifier);
1273
+ }
1274
+ i++;
1275
+ }
1276
+ stack.push(simplePath.identifier);
1277
+ if (_fillRule === "evenodd") {
1278
+ const isHole = stack.length % 2 === 0 ? true : false;
1279
+ const isHoleFor = stack[stack.length - 2];
1280
+ return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1281
+ } else if (_fillRule === "nonzero") {
1282
+ let isHole = true;
1283
+ let isHoleFor = null;
1284
+ let lastCWValue = null;
1285
+ for (let i2 = 0; i2 < stack.length; i2++) {
1286
+ const identifier = stack[i2];
1287
+ if (isHole) {
1288
+ lastCWValue = allPaths[identifier].isCW;
1289
+ isHole = false;
1290
+ isHoleFor = identifier;
1291
+ } else if (lastCWValue !== allPaths[identifier].isCW) {
1292
+ lastCWValue = allPaths[identifier].isCW;
1293
+ isHole = true;
1294
+ }
1295
+ }
1296
+ return { identifier: simplePath.identifier, isHole, for: isHoleFor };
1297
+ } else {
1298
+ console.warn('fill-rule: "' + _fillRule + '" is currently not implemented.');
1299
+ }
1372
1300
  }
1373
- static getStrokeStyle(width, color, lineJoin, lineCap, miterLimit) {
1374
- width = width !== void 0 ? width : 1;
1375
- color = color !== void 0 ? color : "#000";
1376
- lineJoin = lineJoin !== void 0 ? lineJoin : "miter";
1377
- lineCap = lineCap !== void 0 ? lineCap : "butt";
1378
- miterLimit = miterLimit !== void 0 ? miterLimit : 4;
1301
+ let scanlineMinX = BIGNUMBER;
1302
+ let scanlineMaxX = -BIGNUMBER;
1303
+ let simplePaths = shapePath.subPaths.map((p) => {
1304
+ const points = p.getPoints();
1305
+ let maxY = -BIGNUMBER;
1306
+ let minY = BIGNUMBER;
1307
+ let maxX = -BIGNUMBER;
1308
+ let minX = BIGNUMBER;
1309
+ for (let i = 0; i < points.length; i++) {
1310
+ const p2 = points[i];
1311
+ if (p2.y > maxY) {
1312
+ maxY = p2.y;
1313
+ }
1314
+ if (p2.y < minY) {
1315
+ minY = p2.y;
1316
+ }
1317
+ if (p2.x > maxX) {
1318
+ maxX = p2.x;
1319
+ }
1320
+ if (p2.x < minX) {
1321
+ minX = p2.x;
1322
+ }
1323
+ }
1324
+ if (scanlineMaxX <= maxX) {
1325
+ scanlineMaxX = maxX + 1;
1326
+ }
1327
+ if (scanlineMinX >= minX) {
1328
+ scanlineMinX = minX - 1;
1329
+ }
1379
1330
  return {
1380
- strokeColor: color,
1381
- strokeWidth: width,
1382
- strokeLineJoin: lineJoin,
1383
- strokeLineCap: lineCap,
1384
- strokeMiterLimit: miterLimit
1331
+ curves: p.curves,
1332
+ points,
1333
+ isCW: THREE.ShapeUtils.isClockWise(points),
1334
+ identifier: -1,
1335
+ boundingBox: new THREE.Box2(new THREE.Vector2(minX, minY), new THREE.Vector2(maxX, maxY))
1385
1336
  };
1337
+ });
1338
+ simplePaths = simplePaths.filter((sp) => sp.points.length > 1);
1339
+ for (let identifier = 0; identifier < simplePaths.length; identifier++) {
1340
+ simplePaths[identifier].identifier = identifier;
1386
1341
  }
1387
- static pointsToStroke(points, style, arcDivisions, minDistance) {
1388
- const vertices = [];
1389
- const normals = [];
1390
- const uvs = [];
1391
- if (SVGLoader2.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
1392
- return null;
1342
+ const isAHole = simplePaths.map(
1343
+ (p) => isHoleTo(
1344
+ p,
1345
+ simplePaths,
1346
+ scanlineMinX,
1347
+ scanlineMaxX,
1348
+ shapePath.userData ? shapePath.userData.style.fillRule : void 0
1349
+ )
1350
+ );
1351
+ const shapesToReturn = [];
1352
+ simplePaths.forEach((p) => {
1353
+ const amIAHole = isAHole[p.identifier];
1354
+ if (!amIAHole.isHole) {
1355
+ const shape = new THREE.Shape();
1356
+ shape.curves = p.curves;
1357
+ const holes = isAHole.filter((h) => h.isHole && h.for === p.identifier);
1358
+ holes.forEach((h) => {
1359
+ const hole = simplePaths[h.identifier];
1360
+ const path = new THREE.Path();
1361
+ path.curves = hole.curves;
1362
+ shape.holes.push(path);
1363
+ });
1364
+ shapesToReturn.push(shape);
1393
1365
  }
1394
- const geometry = new THREE.BufferGeometry();
1395
- geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
1396
- geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
1397
- geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
1398
- return geometry;
1366
+ });
1367
+ return shapesToReturn;
1368
+ }
1369
+ static getStrokeStyle(width, color, lineJoin, lineCap, miterLimit) {
1370
+ width = width !== void 0 ? width : 1;
1371
+ color = color !== void 0 ? color : "#000";
1372
+ lineJoin = lineJoin !== void 0 ? lineJoin : "miter";
1373
+ lineCap = lineCap !== void 0 ? lineCap : "butt";
1374
+ miterLimit = miterLimit !== void 0 ? miterLimit : 4;
1375
+ return {
1376
+ strokeColor: color,
1377
+ strokeWidth: width,
1378
+ strokeLineJoin: lineJoin,
1379
+ strokeLineCap: lineCap,
1380
+ strokeMiterLimit: miterLimit
1381
+ };
1382
+ }
1383
+ static pointsToStroke(points, style, arcDivisions, minDistance) {
1384
+ const vertices = [];
1385
+ const normals = [];
1386
+ const uvs = [];
1387
+ if (SVGLoader.pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs) === 0) {
1388
+ return null;
1399
1389
  }
1400
- static pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
1401
- const tempV2_1 = new THREE.Vector2();
1402
- const tempV2_2 = new THREE.Vector2();
1403
- const tempV2_3 = new THREE.Vector2();
1404
- const tempV2_4 = new THREE.Vector2();
1405
- const tempV2_5 = new THREE.Vector2();
1406
- const tempV2_6 = new THREE.Vector2();
1407
- const tempV2_7 = new THREE.Vector2();
1408
- const lastPointL = new THREE.Vector2();
1409
- const lastPointR = new THREE.Vector2();
1410
- const point0L = new THREE.Vector2();
1411
- const point0R = new THREE.Vector2();
1412
- const currentPointL = new THREE.Vector2();
1413
- const currentPointR = new THREE.Vector2();
1414
- const nextPointL = new THREE.Vector2();
1415
- const nextPointR = new THREE.Vector2();
1416
- const innerPoint = new THREE.Vector2();
1417
- const outerPoint = new THREE.Vector2();
1418
- arcDivisions = arcDivisions !== void 0 ? arcDivisions : 12;
1419
- minDistance = minDistance !== void 0 ? minDistance : 1e-3;
1420
- vertexOffset = vertexOffset !== void 0 ? vertexOffset : 0;
1421
- points = removeDuplicatedPoints(points);
1422
- const numPoints = points.length;
1423
- if (numPoints < 2)
1424
- return 0;
1425
- const isClosed = points[0].equals(points[numPoints - 1]);
1426
- let currentPoint;
1427
- let previousPoint = points[0];
1428
- let nextPoint;
1429
- const strokeWidth2 = style.strokeWidth / 2;
1430
- const deltaU = 1 / (numPoints - 1);
1431
- let u0 = 0, u1;
1432
- let innerSideModified;
1433
- let joinIsOnLeftSide;
1434
- let isMiter;
1435
- let initialJoinIsOnLeftSide = false;
1436
- let numVertices = 0;
1437
- let currentCoordinate = vertexOffset * 3;
1438
- let currentCoordinateUV = vertexOffset * 2;
1439
- getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
1440
- lastPointL.copy(points[0]).sub(tempV2_1);
1441
- lastPointR.copy(points[0]).add(tempV2_1);
1442
- point0L.copy(lastPointL);
1443
- point0R.copy(lastPointR);
1444
- for (let iPoint = 1; iPoint < numPoints; iPoint++) {
1445
- currentPoint = points[iPoint];
1446
- if (iPoint === numPoints - 1) {
1447
- if (isClosed) {
1448
- nextPoint = points[1];
1449
- } else
1450
- nextPoint = void 0;
1451
- } else {
1452
- nextPoint = points[iPoint + 1];
1453
- }
1454
- const normal1 = tempV2_1;
1455
- getNormal(previousPoint, currentPoint, normal1);
1456
- tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
1457
- currentPointL.copy(currentPoint).sub(tempV2_3);
1458
- currentPointR.copy(currentPoint).add(tempV2_3);
1459
- u1 = u0 + deltaU;
1460
- innerSideModified = false;
1461
- if (nextPoint !== void 0) {
1462
- getNormal(currentPoint, nextPoint, tempV2_2);
1463
- tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
1464
- nextPointL.copy(currentPoint).sub(tempV2_3);
1465
- nextPointR.copy(currentPoint).add(tempV2_3);
1466
- joinIsOnLeftSide = true;
1467
- tempV2_3.subVectors(nextPoint, previousPoint);
1468
- if (normal1.dot(tempV2_3) < 0) {
1469
- joinIsOnLeftSide = false;
1390
+ const geometry = new THREE.BufferGeometry();
1391
+ geometry.setAttribute("position", new THREE.Float32BufferAttribute(vertices, 3));
1392
+ geometry.setAttribute("normal", new THREE.Float32BufferAttribute(normals, 3));
1393
+ geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
1394
+ return geometry;
1395
+ }
1396
+ static pointsToStrokeWithBuffers(points, style, arcDivisions, minDistance, vertices, normals, uvs, vertexOffset) {
1397
+ const tempV2_1 = new THREE.Vector2();
1398
+ const tempV2_2 = new THREE.Vector2();
1399
+ const tempV2_3 = new THREE.Vector2();
1400
+ const tempV2_4 = new THREE.Vector2();
1401
+ const tempV2_5 = new THREE.Vector2();
1402
+ const tempV2_6 = new THREE.Vector2();
1403
+ const tempV2_7 = new THREE.Vector2();
1404
+ const lastPointL = new THREE.Vector2();
1405
+ const lastPointR = new THREE.Vector2();
1406
+ const point0L = new THREE.Vector2();
1407
+ const point0R = new THREE.Vector2();
1408
+ const currentPointL = new THREE.Vector2();
1409
+ const currentPointR = new THREE.Vector2();
1410
+ const nextPointL = new THREE.Vector2();
1411
+ const nextPointR = new THREE.Vector2();
1412
+ const innerPoint = new THREE.Vector2();
1413
+ const outerPoint = new THREE.Vector2();
1414
+ arcDivisions = arcDivisions !== void 0 ? arcDivisions : 12;
1415
+ minDistance = minDistance !== void 0 ? minDistance : 1e-3;
1416
+ vertexOffset = vertexOffset !== void 0 ? vertexOffset : 0;
1417
+ points = removeDuplicatedPoints(points);
1418
+ const numPoints = points.length;
1419
+ if (numPoints < 2)
1420
+ return 0;
1421
+ const isClosed = points[0].equals(points[numPoints - 1]);
1422
+ let currentPoint;
1423
+ let previousPoint = points[0];
1424
+ let nextPoint;
1425
+ const strokeWidth2 = style.strokeWidth / 2;
1426
+ const deltaU = 1 / (numPoints - 1);
1427
+ let u0 = 0, u1;
1428
+ let innerSideModified;
1429
+ let joinIsOnLeftSide;
1430
+ let isMiter;
1431
+ let initialJoinIsOnLeftSide = false;
1432
+ let numVertices = 0;
1433
+ let currentCoordinate = vertexOffset * 3;
1434
+ let currentCoordinateUV = vertexOffset * 2;
1435
+ getNormal(points[0], points[1], tempV2_1).multiplyScalar(strokeWidth2);
1436
+ lastPointL.copy(points[0]).sub(tempV2_1);
1437
+ lastPointR.copy(points[0]).add(tempV2_1);
1438
+ point0L.copy(lastPointL);
1439
+ point0R.copy(lastPointR);
1440
+ for (let iPoint = 1; iPoint < numPoints; iPoint++) {
1441
+ currentPoint = points[iPoint];
1442
+ if (iPoint === numPoints - 1) {
1443
+ if (isClosed) {
1444
+ nextPoint = points[1];
1445
+ } else
1446
+ nextPoint = void 0;
1447
+ } else {
1448
+ nextPoint = points[iPoint + 1];
1449
+ }
1450
+ const normal1 = tempV2_1;
1451
+ getNormal(previousPoint, currentPoint, normal1);
1452
+ tempV2_3.copy(normal1).multiplyScalar(strokeWidth2);
1453
+ currentPointL.copy(currentPoint).sub(tempV2_3);
1454
+ currentPointR.copy(currentPoint).add(tempV2_3);
1455
+ u1 = u0 + deltaU;
1456
+ innerSideModified = false;
1457
+ if (nextPoint !== void 0) {
1458
+ getNormal(currentPoint, nextPoint, tempV2_2);
1459
+ tempV2_3.copy(tempV2_2).multiplyScalar(strokeWidth2);
1460
+ nextPointL.copy(currentPoint).sub(tempV2_3);
1461
+ nextPointR.copy(currentPoint).add(tempV2_3);
1462
+ joinIsOnLeftSide = true;
1463
+ tempV2_3.subVectors(nextPoint, previousPoint);
1464
+ if (normal1.dot(tempV2_3) < 0) {
1465
+ joinIsOnLeftSide = false;
1466
+ }
1467
+ if (iPoint === 1)
1468
+ initialJoinIsOnLeftSide = joinIsOnLeftSide;
1469
+ tempV2_3.subVectors(nextPoint, currentPoint);
1470
+ tempV2_3.normalize();
1471
+ const dot = Math.abs(normal1.dot(tempV2_3));
1472
+ if (dot > Number.EPSILON) {
1473
+ const miterSide = strokeWidth2 / dot;
1474
+ tempV2_3.multiplyScalar(-miterSide);
1475
+ tempV2_4.subVectors(currentPoint, previousPoint);
1476
+ tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1477
+ innerPoint.copy(tempV2_5).negate();
1478
+ const miterLength2 = tempV2_5.length();
1479
+ const segmentLengthPrev = tempV2_4.length();
1480
+ tempV2_4.divideScalar(segmentLengthPrev);
1481
+ tempV2_6.subVectors(nextPoint, currentPoint);
1482
+ const segmentLengthNext = tempV2_6.length();
1483
+ tempV2_6.divideScalar(segmentLengthNext);
1484
+ if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1485
+ innerSideModified = true;
1470
1486
  }
1471
- if (iPoint === 1)
1472
- initialJoinIsOnLeftSide = joinIsOnLeftSide;
1473
- tempV2_3.subVectors(nextPoint, currentPoint);
1474
- tempV2_3.normalize();
1475
- const dot = Math.abs(normal1.dot(tempV2_3));
1476
- if (dot > Number.EPSILON) {
1477
- const miterSide = strokeWidth2 / dot;
1478
- tempV2_3.multiplyScalar(-miterSide);
1479
- tempV2_4.subVectors(currentPoint, previousPoint);
1480
- tempV2_5.copy(tempV2_4).setLength(miterSide).add(tempV2_3);
1481
- innerPoint.copy(tempV2_5).negate();
1482
- const miterLength2 = tempV2_5.length();
1483
- const segmentLengthPrev = tempV2_4.length();
1484
- tempV2_4.divideScalar(segmentLengthPrev);
1485
- tempV2_6.subVectors(nextPoint, currentPoint);
1486
- const segmentLengthNext = tempV2_6.length();
1487
- tempV2_6.divideScalar(segmentLengthNext);
1488
- if (tempV2_4.dot(innerPoint) < segmentLengthPrev && tempV2_6.dot(innerPoint) < segmentLengthNext) {
1489
- innerSideModified = true;
1487
+ outerPoint.copy(tempV2_5).add(currentPoint);
1488
+ innerPoint.add(currentPoint);
1489
+ isMiter = false;
1490
+ if (innerSideModified) {
1491
+ if (joinIsOnLeftSide) {
1492
+ nextPointR.copy(innerPoint);
1493
+ currentPointR.copy(innerPoint);
1494
+ } else {
1495
+ nextPointL.copy(innerPoint);
1496
+ currentPointL.copy(innerPoint);
1490
1497
  }
1491
- outerPoint.copy(tempV2_5).add(currentPoint);
1492
- innerPoint.add(currentPoint);
1493
- isMiter = false;
1494
- if (innerSideModified) {
1498
+ } else {
1499
+ makeSegmentTriangles();
1500
+ }
1501
+ switch (style.strokeLineJoin) {
1502
+ case "bevel":
1503
+ makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1504
+ break;
1505
+ case "round":
1506
+ createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1495
1507
  if (joinIsOnLeftSide) {
1496
- nextPointR.copy(innerPoint);
1497
- currentPointR.copy(innerPoint);
1508
+ makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1498
1509
  } else {
1499
- nextPointL.copy(innerPoint);
1500
- currentPointL.copy(innerPoint);
1510
+ makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1501
1511
  }
1502
- } else {
1503
- makeSegmentTriangles();
1504
- }
1505
- switch (style.strokeLineJoin) {
1506
- case "bevel":
1507
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1508
- break;
1509
- case "round":
1510
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1511
- if (joinIsOnLeftSide) {
1512
- makeCircularSector(currentPoint, currentPointL, nextPointL, u1, 0);
1512
+ break;
1513
+ case "miter":
1514
+ case "miter-clip":
1515
+ default:
1516
+ const miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
1517
+ if (miterFraction < 1) {
1518
+ if (style.strokeLineJoin !== "miter-clip") {
1519
+ makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1520
+ break;
1513
1521
  } else {
1514
- makeCircularSector(currentPoint, nextPointR, currentPointR, u1, 1);
1522
+ createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1523
+ if (joinIsOnLeftSide) {
1524
+ tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1525
+ tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1526
+ addVertex(currentPointL, u1, 0);
1527
+ addVertex(tempV2_6, u1, 0);
1528
+ addVertex(currentPoint, u1, 0.5);
1529
+ addVertex(currentPoint, u1, 0.5);
1530
+ addVertex(tempV2_6, u1, 0);
1531
+ addVertex(tempV2_7, u1, 0);
1532
+ addVertex(currentPoint, u1, 0.5);
1533
+ addVertex(tempV2_7, u1, 0);
1534
+ addVertex(nextPointL, u1, 0);
1535
+ } else {
1536
+ tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1537
+ tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1538
+ addVertex(currentPointR, u1, 1);
1539
+ addVertex(tempV2_6, u1, 1);
1540
+ addVertex(currentPoint, u1, 0.5);
1541
+ addVertex(currentPoint, u1, 0.5);
1542
+ addVertex(tempV2_6, u1, 1);
1543
+ addVertex(tempV2_7, u1, 1);
1544
+ addVertex(currentPoint, u1, 0.5);
1545
+ addVertex(tempV2_7, u1, 1);
1546
+ addVertex(nextPointR, u1, 1);
1547
+ }
1515
1548
  }
1516
- break;
1517
- case "miter":
1518
- case "miter-clip":
1519
- default:
1520
- const miterFraction = strokeWidth2 * style.strokeMiterLimit / miterLength2;
1521
- if (miterFraction < 1) {
1522
- if (style.strokeLineJoin !== "miter-clip") {
1523
- makeSegmentWithBevelJoin(joinIsOnLeftSide, innerSideModified, u1);
1524
- break;
1549
+ } else {
1550
+ if (innerSideModified) {
1551
+ if (joinIsOnLeftSide) {
1552
+ addVertex(lastPointR, u0, 1);
1553
+ addVertex(lastPointL, u0, 0);
1554
+ addVertex(outerPoint, u1, 0);
1555
+ addVertex(lastPointR, u0, 1);
1556
+ addVertex(outerPoint, u1, 0);
1557
+ addVertex(innerPoint, u1, 1);
1525
1558
  } else {
1526
- createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide, innerSideModified);
1527
- if (joinIsOnLeftSide) {
1528
- tempV2_6.subVectors(outerPoint, currentPointL).multiplyScalar(miterFraction).add(currentPointL);
1529
- tempV2_7.subVectors(outerPoint, nextPointL).multiplyScalar(miterFraction).add(nextPointL);
1530
- addVertex(currentPointL, u1, 0);
1531
- addVertex(tempV2_6, u1, 0);
1532
- addVertex(currentPoint, u1, 0.5);
1533
- addVertex(currentPoint, u1, 0.5);
1534
- addVertex(tempV2_6, u1, 0);
1535
- addVertex(tempV2_7, u1, 0);
1536
- addVertex(currentPoint, u1, 0.5);
1537
- addVertex(tempV2_7, u1, 0);
1538
- addVertex(nextPointL, u1, 0);
1539
- } else {
1540
- tempV2_6.subVectors(outerPoint, currentPointR).multiplyScalar(miterFraction).add(currentPointR);
1541
- tempV2_7.subVectors(outerPoint, nextPointR).multiplyScalar(miterFraction).add(nextPointR);
1542
- addVertex(currentPointR, u1, 1);
1543
- addVertex(tempV2_6, u1, 1);
1544
- addVertex(currentPoint, u1, 0.5);
1545
- addVertex(currentPoint, u1, 0.5);
1546
- addVertex(tempV2_6, u1, 1);
1547
- addVertex(tempV2_7, u1, 1);
1548
- addVertex(currentPoint, u1, 0.5);
1549
- addVertex(tempV2_7, u1, 1);
1550
- addVertex(nextPointR, u1, 1);
1551
- }
1559
+ addVertex(lastPointR, u0, 1);
1560
+ addVertex(lastPointL, u0, 0);
1561
+ addVertex(outerPoint, u1, 1);
1562
+ addVertex(lastPointL, u0, 0);
1563
+ addVertex(innerPoint, u1, 0);
1564
+ addVertex(outerPoint, u1, 1);
1565
+ }
1566
+ if (joinIsOnLeftSide) {
1567
+ nextPointL.copy(outerPoint);
1568
+ } else {
1569
+ nextPointR.copy(outerPoint);
1552
1570
  }
1553
1571
  } else {
1554
- if (innerSideModified) {
1555
- if (joinIsOnLeftSide) {
1556
- addVertex(lastPointR, u0, 1);
1557
- addVertex(lastPointL, u0, 0);
1558
- addVertex(outerPoint, u1, 0);
1559
- addVertex(lastPointR, u0, 1);
1560
- addVertex(outerPoint, u1, 0);
1561
- addVertex(innerPoint, u1, 1);
1562
- } else {
1563
- addVertex(lastPointR, u0, 1);
1564
- addVertex(lastPointL, u0, 0);
1565
- addVertex(outerPoint, u1, 1);
1566
- addVertex(lastPointL, u0, 0);
1567
- addVertex(innerPoint, u1, 0);
1568
- addVertex(outerPoint, u1, 1);
1569
- }
1570
- if (joinIsOnLeftSide) {
1571
- nextPointL.copy(outerPoint);
1572
- } else {
1573
- nextPointR.copy(outerPoint);
1574
- }
1572
+ if (joinIsOnLeftSide) {
1573
+ addVertex(currentPointL, u1, 0);
1574
+ addVertex(outerPoint, u1, 0);
1575
+ addVertex(currentPoint, u1, 0.5);
1576
+ addVertex(currentPoint, u1, 0.5);
1577
+ addVertex(outerPoint, u1, 0);
1578
+ addVertex(nextPointL, u1, 0);
1575
1579
  } else {
1576
- if (joinIsOnLeftSide) {
1577
- addVertex(currentPointL, u1, 0);
1578
- addVertex(outerPoint, u1, 0);
1579
- addVertex(currentPoint, u1, 0.5);
1580
- addVertex(currentPoint, u1, 0.5);
1581
- addVertex(outerPoint, u1, 0);
1582
- addVertex(nextPointL, u1, 0);
1583
- } else {
1584
- addVertex(currentPointR, u1, 1);
1585
- addVertex(outerPoint, u1, 1);
1586
- addVertex(currentPoint, u1, 0.5);
1587
- addVertex(currentPoint, u1, 0.5);
1588
- addVertex(outerPoint, u1, 1);
1589
- addVertex(nextPointR, u1, 1);
1590
- }
1580
+ addVertex(currentPointR, u1, 1);
1581
+ addVertex(outerPoint, u1, 1);
1582
+ addVertex(currentPoint, u1, 0.5);
1583
+ addVertex(currentPoint, u1, 0.5);
1584
+ addVertex(outerPoint, u1, 1);
1585
+ addVertex(nextPointR, u1, 1);
1591
1586
  }
1592
- isMiter = true;
1593
1587
  }
1594
- break;
1595
- }
1596
- } else {
1597
- makeSegmentTriangles();
1588
+ isMiter = true;
1589
+ }
1590
+ break;
1598
1591
  }
1599
1592
  } else {
1600
1593
  makeSegmentTriangles();
1601
1594
  }
1602
- if (!isClosed && iPoint === numPoints - 1) {
1603
- addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1604
- }
1605
- u0 = u1;
1606
- previousPoint = currentPoint;
1607
- lastPointL.copy(nextPointL);
1608
- lastPointR.copy(nextPointR);
1609
- }
1610
- if (!isClosed) {
1611
- addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1612
- } else if (innerSideModified && vertices) {
1613
- let lastOuter = outerPoint;
1614
- let lastInner = innerPoint;
1615
- if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1616
- lastOuter = innerPoint;
1617
- lastInner = outerPoint;
1618
- }
1619
- if (joinIsOnLeftSide) {
1620
- if (isMiter || initialJoinIsOnLeftSide) {
1621
- lastInner.toArray(vertices, 0 * 3);
1622
- lastInner.toArray(vertices, 3 * 3);
1623
- if (isMiter) {
1624
- lastOuter.toArray(vertices, 1 * 3);
1625
- }
1626
- }
1627
- } else {
1628
- if (isMiter || !initialJoinIsOnLeftSide) {
1629
- lastInner.toArray(vertices, 1 * 3);
1630
- lastInner.toArray(vertices, 3 * 3);
1631
- if (isMiter) {
1632
- lastOuter.toArray(vertices, 0 * 3);
1633
- }
1634
- }
1635
- }
1595
+ } else {
1596
+ makeSegmentTriangles();
1636
1597
  }
1637
- return numVertices;
1638
- function getNormal(p1, p2, result) {
1639
- result.subVectors(p2, p1);
1640
- return result.set(-result.y, result.x).normalize();
1641
- }
1642
- function addVertex(position, u, v) {
1643
- if (vertices) {
1644
- vertices[currentCoordinate] = position.x;
1645
- vertices[currentCoordinate + 1] = position.y;
1646
- vertices[currentCoordinate + 2] = 0;
1647
- if (normals) {
1648
- normals[currentCoordinate] = 0;
1649
- normals[currentCoordinate + 1] = 0;
1650
- normals[currentCoordinate + 2] = 1;
1598
+ if (!isClosed && iPoint === numPoints - 1) {
1599
+ addCapGeometry(points[0], point0L, point0R, joinIsOnLeftSide, true, u0);
1600
+ }
1601
+ u0 = u1;
1602
+ previousPoint = currentPoint;
1603
+ lastPointL.copy(nextPointL);
1604
+ lastPointR.copy(nextPointR);
1605
+ }
1606
+ if (!isClosed) {
1607
+ addCapGeometry(currentPoint, currentPointL, currentPointR, joinIsOnLeftSide, false, u1);
1608
+ } else if (innerSideModified && vertices) {
1609
+ let lastOuter = outerPoint;
1610
+ let lastInner = innerPoint;
1611
+ if (initialJoinIsOnLeftSide !== joinIsOnLeftSide) {
1612
+ lastOuter = innerPoint;
1613
+ lastInner = outerPoint;
1614
+ }
1615
+ if (joinIsOnLeftSide) {
1616
+ if (isMiter || initialJoinIsOnLeftSide) {
1617
+ lastInner.toArray(vertices, 0 * 3);
1618
+ lastInner.toArray(vertices, 3 * 3);
1619
+ if (isMiter) {
1620
+ lastOuter.toArray(vertices, 1 * 3);
1651
1621
  }
1652
- currentCoordinate += 3;
1653
- if (uvs) {
1654
- uvs[currentCoordinateUV] = u;
1655
- uvs[currentCoordinateUV + 1] = v;
1656
- currentCoordinateUV += 2;
1622
+ }
1623
+ } else {
1624
+ if (isMiter || !initialJoinIsOnLeftSide) {
1625
+ lastInner.toArray(vertices, 1 * 3);
1626
+ lastInner.toArray(vertices, 3 * 3);
1627
+ if (isMiter) {
1628
+ lastOuter.toArray(vertices, 0 * 3);
1657
1629
  }
1658
1630
  }
1659
- numVertices += 3;
1660
- }
1661
- function makeCircularSector(center, p1, p2, u, v) {
1662
- tempV2_1.copy(p1).sub(center).normalize();
1663
- tempV2_2.copy(p2).sub(center).normalize();
1664
- let angle = Math.PI;
1665
- const dot = tempV2_1.dot(tempV2_2);
1666
- if (Math.abs(dot) < 1)
1667
- angle = Math.abs(Math.acos(dot));
1668
- angle /= arcDivisions;
1669
- tempV2_3.copy(p1);
1670
- for (let i = 0, il = arcDivisions - 1; i < il; i++) {
1671
- tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1672
- addVertex(tempV2_3, u, v);
1673
- addVertex(tempV2_4, u, v);
1674
- addVertex(center, u, 0.5);
1675
- tempV2_3.copy(tempV2_4);
1631
+ }
1632
+ }
1633
+ return numVertices;
1634
+ function getNormal(p1, p2, result) {
1635
+ result.subVectors(p2, p1);
1636
+ return result.set(-result.y, result.x).normalize();
1637
+ }
1638
+ function addVertex(position, u, v) {
1639
+ if (vertices) {
1640
+ vertices[currentCoordinate] = position.x;
1641
+ vertices[currentCoordinate + 1] = position.y;
1642
+ vertices[currentCoordinate + 2] = 0;
1643
+ if (normals) {
1644
+ normals[currentCoordinate] = 0;
1645
+ normals[currentCoordinate + 1] = 0;
1646
+ normals[currentCoordinate + 2] = 1;
1647
+ }
1648
+ currentCoordinate += 3;
1649
+ if (uvs) {
1650
+ uvs[currentCoordinateUV] = u;
1651
+ uvs[currentCoordinateUV + 1] = v;
1652
+ currentCoordinateUV += 2;
1676
1653
  }
1654
+ }
1655
+ numVertices += 3;
1656
+ }
1657
+ function makeCircularSector(center, p1, p2, u, v) {
1658
+ tempV2_1.copy(p1).sub(center).normalize();
1659
+ tempV2_2.copy(p2).sub(center).normalize();
1660
+ let angle = Math.PI;
1661
+ const dot = tempV2_1.dot(tempV2_2);
1662
+ if (Math.abs(dot) < 1)
1663
+ angle = Math.abs(Math.acos(dot));
1664
+ angle /= arcDivisions;
1665
+ tempV2_3.copy(p1);
1666
+ for (let i = 0, il = arcDivisions - 1; i < il; i++) {
1667
+ tempV2_4.copy(tempV2_3).rotateAround(center, angle);
1668
+ addVertex(tempV2_3, u, v);
1677
1669
  addVertex(tempV2_4, u, v);
1678
- addVertex(p2, u, v);
1679
1670
  addVertex(center, u, 0.5);
1671
+ tempV2_3.copy(tempV2_4);
1680
1672
  }
1681
- function makeSegmentTriangles() {
1682
- addVertex(lastPointR, u0, 1);
1683
- addVertex(lastPointL, u0, 0);
1684
- addVertex(currentPointL, u1, 0);
1685
- addVertex(lastPointR, u0, 1);
1686
- addVertex(currentPointL, u1, 0);
1687
- addVertex(currentPointR, u1, 1);
1688
- }
1689
- function makeSegmentWithBevelJoin(joinIsOnLeftSide2, innerSideModified2, u) {
1690
- if (innerSideModified2) {
1691
- if (joinIsOnLeftSide2) {
1692
- addVertex(lastPointR, u0, 1);
1693
- addVertex(lastPointL, u0, 0);
1694
- addVertex(currentPointL, u1, 0);
1695
- addVertex(lastPointR, u0, 1);
1696
- addVertex(currentPointL, u1, 0);
1697
- addVertex(innerPoint, u1, 1);
1698
- addVertex(currentPointL, u, 0);
1699
- addVertex(nextPointL, u, 0);
1700
- addVertex(innerPoint, u, 0.5);
1701
- } else {
1702
- addVertex(lastPointR, u0, 1);
1703
- addVertex(lastPointL, u0, 0);
1704
- addVertex(currentPointR, u1, 1);
1705
- addVertex(lastPointL, u0, 0);
1706
- addVertex(innerPoint, u1, 0);
1707
- addVertex(currentPointR, u1, 1);
1708
- addVertex(currentPointR, u, 1);
1709
- addVertex(innerPoint, u, 0);
1710
- addVertex(nextPointR, u, 1);
1711
- }
1673
+ addVertex(tempV2_4, u, v);
1674
+ addVertex(p2, u, v);
1675
+ addVertex(center, u, 0.5);
1676
+ }
1677
+ function makeSegmentTriangles() {
1678
+ addVertex(lastPointR, u0, 1);
1679
+ addVertex(lastPointL, u0, 0);
1680
+ addVertex(currentPointL, u1, 0);
1681
+ addVertex(lastPointR, u0, 1);
1682
+ addVertex(currentPointL, u1, 0);
1683
+ addVertex(currentPointR, u1, 1);
1684
+ }
1685
+ function makeSegmentWithBevelJoin(joinIsOnLeftSide2, innerSideModified2, u) {
1686
+ if (innerSideModified2) {
1687
+ if (joinIsOnLeftSide2) {
1688
+ addVertex(lastPointR, u0, 1);
1689
+ addVertex(lastPointL, u0, 0);
1690
+ addVertex(currentPointL, u1, 0);
1691
+ addVertex(lastPointR, u0, 1);
1692
+ addVertex(currentPointL, u1, 0);
1693
+ addVertex(innerPoint, u1, 1);
1694
+ addVertex(currentPointL, u, 0);
1695
+ addVertex(nextPointL, u, 0);
1696
+ addVertex(innerPoint, u, 0.5);
1712
1697
  } else {
1713
- if (joinIsOnLeftSide2) {
1714
- addVertex(currentPointL, u, 0);
1715
- addVertex(nextPointL, u, 0);
1716
- addVertex(currentPoint, u, 0.5);
1717
- } else {
1718
- addVertex(currentPointR, u, 1);
1719
- addVertex(nextPointR, u, 0);
1720
- addVertex(currentPoint, u, 0.5);
1721
- }
1698
+ addVertex(lastPointR, u0, 1);
1699
+ addVertex(lastPointL, u0, 0);
1700
+ addVertex(currentPointR, u1, 1);
1701
+ addVertex(lastPointL, u0, 0);
1702
+ addVertex(innerPoint, u1, 0);
1703
+ addVertex(currentPointR, u1, 1);
1704
+ addVertex(currentPointR, u, 1);
1705
+ addVertex(innerPoint, u, 0);
1706
+ addVertex(nextPointR, u, 1);
1707
+ }
1708
+ } else {
1709
+ if (joinIsOnLeftSide2) {
1710
+ addVertex(currentPointL, u, 0);
1711
+ addVertex(nextPointL, u, 0);
1712
+ addVertex(currentPoint, u, 0.5);
1713
+ } else {
1714
+ addVertex(currentPointR, u, 1);
1715
+ addVertex(nextPointR, u, 0);
1716
+ addVertex(currentPoint, u, 0.5);
1722
1717
  }
1723
1718
  }
1724
- function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide2, innerSideModified2) {
1725
- if (innerSideModified2) {
1726
- if (joinIsOnLeftSide2) {
1727
- addVertex(lastPointR, u0, 1);
1728
- addVertex(lastPointL, u0, 0);
1729
- addVertex(currentPointL, u1, 0);
1730
- addVertex(lastPointR, u0, 1);
1731
- addVertex(currentPointL, u1, 0);
1732
- addVertex(innerPoint, u1, 1);
1733
- addVertex(currentPointL, u0, 0);
1734
- addVertex(currentPoint, u1, 0.5);
1735
- addVertex(innerPoint, u1, 1);
1736
- addVertex(currentPoint, u1, 0.5);
1737
- addVertex(nextPointL, u0, 0);
1738
- addVertex(innerPoint, u1, 1);
1739
- } else {
1740
- addVertex(lastPointR, u0, 1);
1741
- addVertex(lastPointL, u0, 0);
1742
- addVertex(currentPointR, u1, 1);
1743
- addVertex(lastPointL, u0, 0);
1744
- addVertex(innerPoint, u1, 0);
1745
- addVertex(currentPointR, u1, 1);
1746
- addVertex(currentPointR, u0, 1);
1747
- addVertex(innerPoint, u1, 0);
1748
- addVertex(currentPoint, u1, 0.5);
1749
- addVertex(currentPoint, u1, 0.5);
1750
- addVertex(innerPoint, u1, 0);
1751
- addVertex(nextPointR, u0, 1);
1752
- }
1719
+ }
1720
+ function createSegmentTrianglesWithMiddleSection(joinIsOnLeftSide2, innerSideModified2) {
1721
+ if (innerSideModified2) {
1722
+ if (joinIsOnLeftSide2) {
1723
+ addVertex(lastPointR, u0, 1);
1724
+ addVertex(lastPointL, u0, 0);
1725
+ addVertex(currentPointL, u1, 0);
1726
+ addVertex(lastPointR, u0, 1);
1727
+ addVertex(currentPointL, u1, 0);
1728
+ addVertex(innerPoint, u1, 1);
1729
+ addVertex(currentPointL, u0, 0);
1730
+ addVertex(currentPoint, u1, 0.5);
1731
+ addVertex(innerPoint, u1, 1);
1732
+ addVertex(currentPoint, u1, 0.5);
1733
+ addVertex(nextPointL, u0, 0);
1734
+ addVertex(innerPoint, u1, 1);
1735
+ } else {
1736
+ addVertex(lastPointR, u0, 1);
1737
+ addVertex(lastPointL, u0, 0);
1738
+ addVertex(currentPointR, u1, 1);
1739
+ addVertex(lastPointL, u0, 0);
1740
+ addVertex(innerPoint, u1, 0);
1741
+ addVertex(currentPointR, u1, 1);
1742
+ addVertex(currentPointR, u0, 1);
1743
+ addVertex(innerPoint, u1, 0);
1744
+ addVertex(currentPoint, u1, 0.5);
1745
+ addVertex(currentPoint, u1, 0.5);
1746
+ addVertex(innerPoint, u1, 0);
1747
+ addVertex(nextPointR, u0, 1);
1753
1748
  }
1754
1749
  }
1755
- function addCapGeometry(center, p1, p2, joinIsOnLeftSide2, start, u) {
1756
- switch (style.strokeLineCap) {
1757
- case "round":
1758
- if (start) {
1759
- makeCircularSector(center, p2, p1, u, 0.5);
1750
+ }
1751
+ function addCapGeometry(center, p1, p2, joinIsOnLeftSide2, start, u) {
1752
+ switch (style.strokeLineCap) {
1753
+ case "round":
1754
+ if (start) {
1755
+ makeCircularSector(center, p2, p1, u, 0.5);
1756
+ } else {
1757
+ makeCircularSector(center, p1, p2, u, 0.5);
1758
+ }
1759
+ break;
1760
+ case "square":
1761
+ if (start) {
1762
+ tempV2_1.subVectors(p1, center);
1763
+ tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1764
+ tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1765
+ tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1766
+ if (joinIsOnLeftSide2) {
1767
+ tempV2_3.toArray(vertices, 1 * 3);
1768
+ tempV2_4.toArray(vertices, 0 * 3);
1769
+ tempV2_4.toArray(vertices, 3 * 3);
1760
1770
  } else {
1761
- makeCircularSector(center, p1, p2, u, 0.5);
1771
+ tempV2_3.toArray(vertices, 1 * 3);
1772
+ uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
1773
+ tempV2_4.toArray(vertices, 0 * 3);
1762
1774
  }
1763
- break;
1764
- case "square":
1765
- if (start) {
1766
- tempV2_1.subVectors(p1, center);
1767
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1768
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1769
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1770
- if (joinIsOnLeftSide2) {
1771
- tempV2_3.toArray(vertices, 1 * 3);
1772
- tempV2_4.toArray(vertices, 0 * 3);
1773
- tempV2_4.toArray(vertices, 3 * 3);
1774
- } else {
1775
- tempV2_3.toArray(vertices, 1 * 3);
1776
- uvs[3 * 2 + 1] === 1 ? tempV2_4.toArray(vertices, 3 * 3) : tempV2_3.toArray(vertices, 3 * 3);
1777
- tempV2_4.toArray(vertices, 0 * 3);
1778
- }
1775
+ } else {
1776
+ tempV2_1.subVectors(p2, center);
1777
+ tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1778
+ tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1779
+ tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1780
+ const vl = vertices.length;
1781
+ if (joinIsOnLeftSide2) {
1782
+ tempV2_3.toArray(vertices, vl - 1 * 3);
1783
+ tempV2_4.toArray(vertices, vl - 2 * 3);
1784
+ tempV2_4.toArray(vertices, vl - 4 * 3);
1779
1785
  } else {
1780
- tempV2_1.subVectors(p2, center);
1781
- tempV2_2.set(tempV2_1.y, -tempV2_1.x);
1782
- tempV2_3.addVectors(tempV2_1, tempV2_2).add(center);
1783
- tempV2_4.subVectors(tempV2_2, tempV2_1).add(center);
1784
- const vl = vertices.length;
1785
- if (joinIsOnLeftSide2) {
1786
- tempV2_3.toArray(vertices, vl - 1 * 3);
1787
- tempV2_4.toArray(vertices, vl - 2 * 3);
1788
- tempV2_4.toArray(vertices, vl - 4 * 3);
1789
- } else {
1790
- tempV2_4.toArray(vertices, vl - 2 * 3);
1791
- tempV2_3.toArray(vertices, vl - 1 * 3);
1792
- tempV2_4.toArray(vertices, vl - 4 * 3);
1793
- }
1786
+ tempV2_4.toArray(vertices, vl - 2 * 3);
1787
+ tempV2_3.toArray(vertices, vl - 1 * 3);
1788
+ tempV2_4.toArray(vertices, vl - 4 * 3);
1794
1789
  }
1795
- break;
1796
- }
1797
- }
1798
- function removeDuplicatedPoints(points2) {
1799
- let dupPoints = false;
1800
- for (let i = 1, n = points2.length - 1; i < n; i++) {
1801
- if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
1802
- dupPoints = true;
1803
- break;
1804
1790
  }
1791
+ break;
1792
+ }
1793
+ }
1794
+ function removeDuplicatedPoints(points2) {
1795
+ let dupPoints = false;
1796
+ for (let i = 1, n = points2.length - 1; i < n; i++) {
1797
+ if (points2[i].distanceTo(points2[i + 1]) < minDistance) {
1798
+ dupPoints = true;
1799
+ break;
1805
1800
  }
1806
- if (!dupPoints)
1807
- return points2;
1808
- const newPoints = [];
1809
- newPoints.push(points2[0]);
1810
- for (let i = 1, n = points2.length - 1; i < n; i++) {
1811
- if (points2[i].distanceTo(points2[i + 1]) >= minDistance) {
1812
- newPoints.push(points2[i]);
1813
- }
1801
+ }
1802
+ if (!dupPoints)
1803
+ return points2;
1804
+ const newPoints = [];
1805
+ newPoints.push(points2[0]);
1806
+ for (let i = 1, n = points2.length - 1; i < n; i++) {
1807
+ if (points2[i].distanceTo(points2[i + 1]) >= minDistance) {
1808
+ newPoints.push(points2[i]);
1814
1809
  }
1815
- newPoints.push(points2[points2.length - 1]);
1816
- return newPoints;
1817
1810
  }
1811
+ newPoints.push(points2[points2.length - 1]);
1812
+ return newPoints;
1818
1813
  }
1819
1814
  }
1820
- return SVGLoader2;
1821
- })();
1815
+ }
1822
1816
  exports.SVGLoader = SVGLoader;
1823
1817
  //# sourceMappingURL=SVGLoader.cjs.map