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