super-three 0.181.0 → 0.185.0
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/README.md +3 -4
- package/build/three.cjs +21332 -19201
- package/build/three.core.js +20908 -19853
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +1947 -862
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +37 -16
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +33628 -25197
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +33394 -25000
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +14 -3
- package/examples/jsm/animation/CCDIKSolver.js +7 -3
- package/examples/jsm/controls/ArcballControls.js +13 -6
- package/examples/jsm/controls/DragControls.js +2 -2
- package/examples/jsm/controls/FirstPersonControls.js +127 -86
- package/examples/jsm/controls/FlyControls.js +4 -0
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +111 -8
- package/examples/jsm/controls/TrackballControls.js +8 -8
- package/examples/jsm/controls/TransformControls.js +102 -17
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/csm/CSMFrustum.js +31 -6
- package/examples/jsm/csm/CSMShadowNode.js +10 -3
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/effects/AsciiEffect.js +14 -1
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +3 -0
- package/examples/jsm/exporters/DRACOExporter.js +27 -6
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +266 -21
- package/examples/jsm/exporters/PLYExporter.js +286 -73
- package/examples/jsm/exporters/USDZExporter.js +353 -99
- package/examples/jsm/generators/CityGenerator.js +346 -0
- package/examples/jsm/generators/ForestGenerator.js +347 -0
- package/examples/jsm/generators/TerrainGenerator.js +504 -0
- package/examples/jsm/generators/TreeGenerator.js +377 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +253 -0
- package/examples/jsm/generators/city/SkyscraperGenerator.js +1357 -0
- package/examples/jsm/geometries/DecalGeometry.js +1 -1
- package/examples/jsm/geometries/LoftGeometry.js +355 -0
- package/examples/jsm/geometries/TextGeometry.js +18 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
- package/examples/jsm/helpers/LightProbeHelper.js +5 -4
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/helpers/ViewHelper.js +83 -14
- package/examples/jsm/inspector/Extension.js +13 -0
- package/examples/jsm/inspector/Inspector.js +244 -91
- package/examples/jsm/inspector/RendererInspector.js +165 -39
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
- package/examples/jsm/inspector/tabs/Console.js +241 -25
- package/examples/jsm/inspector/tabs/Memory.js +136 -0
- package/examples/jsm/inspector/tabs/Parameters.js +115 -7
- package/examples/jsm/inspector/tabs/Performance.js +24 -9
- package/examples/jsm/inspector/tabs/Settings.js +306 -0
- package/examples/jsm/inspector/tabs/Timeline.js +1696 -0
- package/examples/jsm/inspector/tabs/Viewer.js +723 -9
- package/examples/jsm/inspector/ui/Graph.js +162 -25
- package/examples/jsm/inspector/ui/Item.js +92 -13
- package/examples/jsm/inspector/ui/List.js +2 -2
- package/examples/jsm/inspector/ui/Profiler.js +1991 -44
- package/examples/jsm/inspector/ui/Style.js +1943 -543
- package/examples/jsm/inspector/ui/Tab.js +226 -5
- package/examples/jsm/inspector/ui/Values.js +126 -8
- package/examples/jsm/inspector/ui/utils.js +143 -10
- package/examples/jsm/interaction/InteractionManager.js +226 -0
- package/examples/jsm/libs/basis/README.md +0 -1
- package/examples/jsm/libs/demuxer_mp4.js +3 -3
- package/examples/jsm/libs/draco/README.md +0 -1
- package/examples/jsm/libs/meshopt_clusterizer.module.js +421 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +9 -8
- package/examples/jsm/libs/meshopt_simplifier.module.js +627 -0
- package/examples/jsm/libs/mikktspace.module.js +34 -9
- package/examples/jsm/lighting/ClusteredLighting.js +55 -0
- package/examples/jsm/lighting/DynamicLighting.js +82 -0
- package/examples/jsm/lighting/LightProbeGrid.js +681 -0
- package/examples/jsm/lines/LineMaterial.js +45 -16
- package/examples/jsm/lines/LineSegments2.js +8 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
- package/examples/jsm/loaders/3DMLoader.js +6 -5
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/AMFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +24 -4026
- package/examples/jsm/loaders/DRACOLoader.js +51 -18
- package/examples/jsm/loaders/EXRLoader.js +701 -90
- package/examples/jsm/loaders/FBXLoader.js +235 -37
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +146 -178
- package/examples/jsm/loaders/HDRLoader.js +7 -30
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +58 -17
- package/examples/jsm/loaders/LDrawLoader.js +49 -58
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
- package/examples/jsm/loaders/LWOLoader.js +11 -39
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MaterialXLoader.js +31 -9
- package/examples/jsm/loaders/NRRDLoader.js +5 -5
- package/examples/jsm/loaders/PCDLoader.js +11 -9
- package/examples/jsm/loaders/PLYLoader.js +218 -55
- package/examples/jsm/loaders/SVGLoader.js +549 -497
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/TTFLoader.js +1 -1
- package/examples/jsm/loaders/USDLoader.js +127 -43
- package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +80 -3
- package/examples/jsm/loaders/VTKLoader.js +42 -25
- package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
- package/examples/jsm/loaders/usd/USDAParser.js +504 -344
- package/examples/jsm/loaders/usd/USDCParser.js +1867 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4627 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
- package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
- package/examples/jsm/math/Octree.js +131 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +42 -4
- package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
- package/examples/jsm/misc/Volume.js +2 -3
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/modifiers/TessellateModifier.js +1 -1
- package/examples/jsm/objects/GroundedSkybox.js +1 -1
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Reflector.js +72 -25
- package/examples/jsm/objects/Sky.js +90 -6
- package/examples/jsm/objects/SkyMesh.js +150 -16
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +1 -1
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/AmmoPhysics.js +27 -15
- package/examples/jsm/physics/JoltPhysics.js +10 -6
- package/examples/jsm/physics/RapierPhysics.js +36 -7
- package/examples/jsm/postprocessing/EffectComposer.js +7 -5
- package/examples/jsm/postprocessing/OutputPass.js +9 -0
- package/examples/jsm/postprocessing/RenderPass.js +10 -0
- package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
- package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
- package/examples/jsm/renderers/Projector.js +246 -28
- package/examples/jsm/renderers/SVGRenderer.js +174 -60
- package/examples/jsm/shaders/GTAOShader.js +19 -6
- package/examples/jsm/shaders/HalftoneShader.js +12 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
- package/examples/jsm/shaders/SAOShader.js +17 -4
- package/examples/jsm/shaders/SSAOShader.js +11 -1
- package/examples/jsm/shaders/SSRShader.js +6 -5
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
- package/examples/jsm/shaders/VignetteShader.js +1 -1
- package/examples/jsm/shaders/VolumeShader.js +31 -44
- package/examples/jsm/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +65 -8
- package/examples/jsm/transpiler/Linker.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
- package/examples/jsm/transpiler/TSLEncoder.js +46 -3
- package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
- package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
- package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +11 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
- package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
- package/examples/jsm/tsl/display/BloomNode.js +75 -25
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +3 -3
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FSR1Node.js +477 -0
- package/examples/jsm/tsl/display/FXAANode.js +13 -14
- package/examples/jsm/tsl/display/GTAONode.js +40 -17
- package/examples/jsm/tsl/display/GaussianBlurNode.js +21 -2
- package/examples/jsm/tsl/display/GodraysNode.js +615 -0
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
- package/examples/jsm/tsl/display/LensflareNode.js +1 -1
- package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
- package/examples/jsm/tsl/display/OutlineNode.js +69 -19
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +9 -8
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +2 -2
- package/examples/jsm/tsl/display/SSAAPassNode.js +15 -27
- package/examples/jsm/tsl/display/SSGINode.js +96 -62
- package/examples/jsm/tsl/display/SSRNode.js +831 -134
- package/examples/jsm/tsl/display/SSSNode.js +8 -6
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/examples/jsm/tsl/display/SharpenNode.js +283 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
- package/examples/jsm/tsl/display/TAAUNode.js +835 -0
- package/examples/jsm/tsl/display/TRAANode.js +315 -126
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
- package/examples/jsm/tsl/display/TransitionNode.js +1 -1
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
- package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
- package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
- package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
- package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
- package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
- package/examples/jsm/tsl/math/Bayer.js +53 -3
- package/examples/jsm/tsl/math/curlNoise.js +107 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +1 -1
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +3 -3
- package/examples/jsm/tsl/utils/GroundedSkybox.js +62 -0
- package/examples/jsm/tsl/utils/RNoise.js +51 -0
- package/examples/jsm/tsl/utils/SpecularHelpers.js +325 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +128 -62
- package/examples/jsm/utils/ColorUtils.js +76 -0
- package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/examples/jsm/utils/SceneOptimizer.js +1 -1
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/SkeletonUtils.js +14 -8
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/examples/jsm/webxr/ARButton.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +89 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +2 -2
- package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
- package/package.json +28 -34
- package/src/Three.Core.js +3 -1
- package/src/Three.TSL.js +35 -14
- package/src/Three.WebGPU.Nodes.js +5 -0
- package/src/Three.WebGPU.js +13 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +18 -4
- package/src/animation/AnimationClip.js +0 -139
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +47 -8
- package/src/animation/PropertyBinding.js +2 -2
- package/src/animation/PropertyMixer.js +4 -4
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
- package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
- package/src/audio/Audio.js +1 -1
- package/src/audio/AudioContext.js +2 -2
- package/src/audio/AudioListener.js +5 -3
- package/src/cameras/Camera.js +34 -4
- package/src/cameras/CubeCamera.js +20 -0
- package/src/cameras/StereoCamera.js +5 -2
- package/src/constants.js +90 -5
- package/src/core/BufferAttribute.js +13 -1
- package/src/core/BufferGeometry.js +43 -9
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +69 -11
- package/src/core/Raycaster.js +3 -3
- package/src/core/RenderTarget.js +19 -6
- package/src/extras/PMREMGenerator.js +13 -22
- package/src/extras/TextureUtils.js +6 -2
- package/src/extras/core/ShapePath.js +149 -160
- package/src/extras/curves/CatmullRomCurve3.js +3 -2
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/geometries/SphereGeometry.js +8 -3
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +6 -1
- package/src/helpers/HemisphereLightHelper.js +5 -0
- package/src/helpers/PointLightHelper.js +3 -25
- package/src/helpers/SpotLightHelper.js +4 -1
- package/src/lights/DirectionalLight.js +13 -0
- package/src/lights/HemisphereLight.js +10 -0
- package/src/lights/Light.js +1 -11
- package/src/lights/LightProbe.js +0 -15
- package/src/lights/LightShadow.js +15 -6
- package/src/lights/PointLight.js +15 -0
- package/src/lights/PointLightShadow.js +0 -86
- package/src/lights/SpotLight.js +22 -1
- package/src/lights/webgpu/IESSpotLight.js +2 -1
- package/src/loaders/AudioLoader.js +11 -1
- package/src/loaders/Cache.js +28 -0
- package/src/loaders/DataTextureLoader.js +75 -42
- package/src/loaders/FileLoader.js +2 -3
- package/src/loaders/ImageBitmapLoader.js +12 -9
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/LoadingManager.js +5 -0
- package/src/loaders/MaterialLoader.js +37 -266
- package/src/loaders/ObjectLoader.js +48 -6
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/loaders/nodes/NodeObjectLoader.js +18 -0
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +198 -1
- package/src/materials/MeshBasicMaterial.js +24 -0
- package/src/materials/MeshDepthMaterial.js +10 -0
- package/src/materials/MeshDistanceMaterial.js +10 -0
- package/src/materials/MeshLambertMaterial.js +49 -1
- package/src/materials/MeshMatcapMaterial.js +25 -1
- package/src/materials/MeshNormalMaterial.js +9 -1
- package/src/materials/MeshPhongMaterial.js +49 -1
- package/src/materials/MeshPhysicalMaterial.js +38 -0
- package/src/materials/MeshStandardMaterial.js +42 -1
- package/src/materials/MeshToonMaterial.js +35 -2
- package/src/materials/PointsMaterial.js +7 -0
- package/src/materials/ShaderMaterial.js +106 -1
- package/src/materials/SpriteMaterial.js +7 -0
- package/src/materials/nodes/Line2NodeMaterial.js +380 -297
- package/src/materials/nodes/MeshBasicNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhongNodeMaterial.js +0 -9
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -30
- package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -15
- package/src/materials/nodes/NodeMaterial.js +153 -89
- package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
- package/src/materials/nodes/manager/NodeMaterialObserver.js +234 -100
- package/src/math/Box3.js +5 -0
- package/src/math/FrustumArray.js +103 -133
- package/src/math/Interpolant.js +1 -1
- package/src/math/Line3.js +6 -5
- package/src/math/MathUtils.js +12 -12
- package/src/math/Matrix2.js +13 -9
- package/src/math/Matrix3.js +24 -9
- package/src/math/Matrix4.js +112 -74
- package/src/math/Plane.js +4 -3
- package/src/math/Quaternion.js +3 -29
- package/src/math/Sphere.js +1 -1
- package/src/math/Triangle.js +1 -1
- package/src/math/Vector2.js +13 -9
- package/src/math/Vector3.js +17 -15
- package/src/math/Vector4.js +15 -11
- package/src/math/interpolants/BezierInterpolant.js +106 -0
- package/src/nodes/Nodes.js +86 -71
- package/src/nodes/TSL.js +15 -13
- package/src/nodes/accessors/Arrays.js +5 -5
- package/src/nodes/accessors/Batch.js +108 -0
- package/src/nodes/accessors/Bitangent.js +7 -7
- package/src/nodes/accessors/BufferAttributeNode.js +120 -17
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/ClippingNode.js +5 -5
- package/src/nodes/accessors/CubeTextureNode.js +27 -2
- package/src/nodes/accessors/Instance.js +264 -0
- package/src/nodes/accessors/MaterialNode.js +27 -3
- package/src/nodes/accessors/MaterialProperties.js +6 -8
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
- package/src/nodes/accessors/Normal.js +24 -24
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/Position.js +39 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +6 -6
- package/src/nodes/accessors/ReferenceNode.js +9 -8
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SceneProperties.js +47 -0
- package/src/nodes/accessors/Skinning.js +263 -0
- package/src/nodes/accessors/StorageBufferNode.js +16 -27
- package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
- package/src/nodes/accessors/StorageTextureNode.js +74 -11
- package/src/nodes/accessors/Tangent.js +8 -18
- package/src/nodes/accessors/Texture3DNode.js +32 -35
- package/src/nodes/accessors/TextureNode.js +124 -25
- package/src/nodes/accessors/UniformArrayNode.js +6 -4
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionCallNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +4 -19
- package/src/nodes/core/ArrayNode.js +21 -2
- package/src/nodes/core/AssignNode.js +3 -3
- package/src/nodes/core/AttributeNode.js +3 -3
- package/src/nodes/core/BypassNode.js +1 -1
- package/src/nodes/core/ContextNode.js +104 -5
- package/src/nodes/core/IndexNode.js +2 -1
- package/src/nodes/core/InputNode.js +1 -1
- package/src/nodes/core/InspectorNode.js +1 -1
- package/src/nodes/core/IsolateNode.js +1 -1
- package/src/nodes/core/MRTNode.js +55 -4
- package/src/nodes/core/Node.js +151 -17
- package/src/nodes/core/NodeBuilder.js +479 -101
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +20 -18
- package/src/nodes/core/OutputStructNode.js +13 -11
- package/src/nodes/core/OverrideContextNode.js +153 -0
- package/src/nodes/core/ParameterNode.js +4 -4
- package/src/nodes/core/PropertyNode.js +66 -4
- package/src/nodes/core/StackNode.js +91 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +20 -8
- package/src/nodes/core/StructTypeNode.js +17 -23
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformGroupNode.js +36 -6
- package/src/nodes/core/UniformNode.js +21 -5
- package/src/nodes/core/VarNode.js +56 -23
- package/src/nodes/core/VaryingNode.js +14 -21
- package/src/nodes/display/BlendModes.js +1 -105
- package/src/nodes/display/BumpMapNode.js +6 -1
- package/src/nodes/display/ColorAdjustment.js +27 -9
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/FrontFacingNode.js +38 -9
- package/src/nodes/display/NormalMapNode.js +41 -6
- package/src/nodes/display/PassNode.js +157 -56
- package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
- package/src/nodes/display/RenderOutputNode.js +19 -10
- package/src/nodes/display/ScreenNode.js +4 -2
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +2 -2
- package/src/nodes/display/ViewportDepthNode.js +52 -4
- package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
- package/src/nodes/display/ViewportTextureNode.js +39 -11
- package/src/nodes/fog/Fog.js +18 -35
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/PhysicalLightingModel.js +126 -45
- package/src/nodes/functions/VolumetricLightingModel.js +40 -7
- package/src/nodes/geometry/RangeNode.js +5 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/BarrierNode.js +9 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +2 -3
- package/src/nodes/gpgpu/ComputeNode.js +74 -48
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +2 -2
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +5 -5
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/EnvironmentNode.js +30 -5
- package/src/nodes/lighting/IESSpotLightNode.js +40 -2
- package/src/nodes/lighting/LightingContextNode.js +10 -2
- package/src/nodes/lighting/LightsNode.js +97 -65
- package/src/nodes/lighting/PointShadowNode.js +166 -148
- package/src/nodes/lighting/ShadowFilterNode.js +74 -117
- package/src/nodes/lighting/ShadowNode.js +149 -51
- package/src/nodes/materialx/lib/mx_noise.js +2 -2
- package/src/nodes/math/BitcastNode.js +1 -1
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +6 -6
- package/src/nodes/math/MathNode.js +115 -52
- package/src/nodes/math/OperatorNode.js +24 -23
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +34 -3
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLBase.js +1 -1
- package/src/nodes/tsl/TSLCore.js +99 -33
- package/src/nodes/utils/ArrayElementNode.js +14 -1
- package/src/nodes/utils/ConvertNode.js +1 -1
- package/src/nodes/utils/DebugNode.js +12 -12
- package/src/nodes/utils/EquirectUV.js +30 -5
- package/src/nodes/utils/EventNode.js +31 -2
- package/src/nodes/utils/FlipNode.js +1 -1
- package/src/nodes/utils/FunctionOverloadingNode.js +2 -2
- package/src/nodes/utils/JoinNode.js +3 -3
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +2 -2
- package/src/nodes/utils/Packing.js +48 -5
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/RTTNode.js +41 -25
- package/src/nodes/utils/ReflectorNode.js +4 -4
- package/src/nodes/utils/Remap.js +48 -0
- package/src/nodes/utils/RotateNode.js +1 -1
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/SetNode.js +1 -1
- package/src/nodes/utils/SplitNode.js +1 -1
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/StorageArrayElementNode.js +1 -1
- package/src/nodes/utils/UVUtils.js +28 -0
- package/src/objects/BatchedMesh.js +66 -30
- package/src/objects/InstancedMesh.js +19 -3
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/SkinnedMesh.js +26 -9
- package/src/renderers/WebGLRenderer.js +344 -156
- package/src/renderers/common/Animation.js +3 -3
- package/src/renderers/common/Attributes.js +15 -1
- package/src/renderers/common/Backend.js +78 -13
- package/src/renderers/common/Background.js +26 -13
- package/src/renderers/common/BindGroup.js +1 -16
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +141 -57
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/ClippingContext.js +10 -2
- package/src/renderers/common/ComputePipeline.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +51 -7
- package/src/renderers/common/Geometries.js +29 -3
- package/src/renderers/common/Info.js +374 -4
- package/src/renderers/common/InspectorBase.js +6 -1
- package/src/renderers/common/Lighting.js +51 -19
- package/src/renderers/common/Pipelines.js +40 -7
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/ReadbackBuffer.js +78 -0
- package/src/renderers/common/RenderBundle.js +3 -1
- package/src/renderers/common/RenderBundles.js +7 -3
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -49
- package/src/renderers/common/RenderList.js +41 -4
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +88 -16
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +21 -5
- package/src/renderers/common/RenderPipeline.js +232 -17
- package/src/renderers/common/Renderer.js +700 -163
- package/src/renderers/common/Sampler.js +16 -48
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +121 -9
- package/src/renderers/common/TimestampQueryPool.js +6 -4
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +84 -1
- package/src/renderers/common/XRManager.js +377 -51
- package/src/renderers/common/extras/PMREMGenerator.js +40 -61
- package/src/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/src/renderers/common/nodes/NodeLibrary.js +4 -4
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +298 -106
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +65 -0
- package/src/renderers/shaders/DFGLUTData.js +19 -34
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +13 -4
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +0 -6
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +9 -13
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +13 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +3 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -53
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk.js +5 -3
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +2 -3
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -6
- package/src/renderers/shaders/UniformsLib.js +7 -5
- package/src/renderers/shaders/UniformsUtils.js +27 -5
- package/src/renderers/webgl/WebGLAnimation.js +2 -1
- package/src/renderers/webgl/WebGLBackground.js +15 -15
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLCapabilities.js +9 -4
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +24 -13
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +271 -0
- package/src/renderers/webgl/WebGLProgram.js +54 -113
- package/src/renderers/webgl/WebGLPrograms.js +74 -55
- package/src/renderers/webgl/WebGLRenderLists.js +24 -1
- package/src/renderers/webgl/WebGLRenderStates.js +13 -2
- package/src/renderers/webgl/WebGLShaderCache.js +5 -11
- package/src/renderers/webgl/WebGLShadowMap.js +188 -24
- package/src/renderers/webgl/WebGLState.js +75 -37
- package/src/renderers/webgl/WebGLTextures.js +230 -56
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +82 -35
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +322 -92
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +295 -66
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +223 -6
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +118 -73
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +10 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +9 -3
- package/src/renderers/webgpu/WebGPUBackend.js +733 -302
- package/src/renderers/webgpu/WebGPURenderer.js +2 -1
- package/src/renderers/webgpu/descriptors/GPUBindGroupDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUBufferDescriptor.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUCommandEncoderDescriptor.js +30 -0
- package/src/renderers/webgpu/descriptors/GPUComputePassDescriptor.js +38 -0
- package/src/renderers/webgpu/descriptors/GPUComputePipelineDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageDestInfo.js +47 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageSourceInfo.js +50 -0
- package/src/renderers/webgpu/descriptors/GPUExtent3D.js +51 -0
- package/src/renderers/webgpu/descriptors/GPUPipelineLayoutDescriptor.js +39 -0
- package/src/renderers/webgpu/descriptors/GPUQuerySetDescriptor.js +47 -0
- package/src/renderers/webgpu/descriptors/GPURenderBundleEncoderDescriptor.js +74 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassColorAttachment.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDepthStencilAttachment.js +99 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDescriptor.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassTimestampWrites.js +49 -0
- package/src/renderers/webgpu/descriptors/GPURenderPipelineDescriptor.js +130 -0
- package/src/renderers/webgpu/descriptors/GPUSamplerDescriptor.js +119 -0
- package/src/renderers/webgpu/descriptors/GPUShaderModuleDescriptor.js +46 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferInfo.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferLayout.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyTextureInfo.js +61 -0
- package/src/renderers/webgpu/descriptors/GPUTextureDescriptor.js +99 -0
- package/src/renderers/webgpu/descriptors/GPUTextureViewDescriptor.js +108 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +526 -93
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +194 -61
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +395 -234
- package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
- package/src/renderers/webgpu/utils/WebGPUConstants.js +10 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +224 -91
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +228 -213
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +428 -175
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +40 -25
- package/src/renderers/webgpu/utils/WebGPUUtils.js +70 -13
- package/src/renderers/webxr/WebXRController.js +12 -0
- package/src/renderers/webxr/WebXRManager.js +4 -2
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/DepthTexture.js +1 -1
- package/src/textures/ExternalTexture.js +0 -3
- package/src/textures/HTMLTexture.js +74 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +16 -5
- package/src/utils.js +280 -3
- package/examples/fonts/LICENSE +0 -13
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +0 -91
- package/examples/fonts/README.md +0 -11
- package/examples/fonts/droid/NOTICE +0 -190
- package/examples/fonts/droid/README.txt +0 -18
- package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
- package/examples/fonts/gentilis_bold.typeface.json +0 -1
- package/examples/fonts/gentilis_regular.typeface.json +0 -1
- package/examples/fonts/helvetiker_bold.typeface.json +0 -1
- package/examples/fonts/helvetiker_regular.typeface.json +0 -1
- package/examples/fonts/optimer_bold.typeface.json +0 -1
- package/examples/fonts/optimer_regular.typeface.json +0 -1
- package/examples/fonts/ttf/README.md +0 -9
- package/examples/fonts/ttf/kenpixel.ttf +0 -0
- package/examples/jsm/libs/ammo.wasm.js +0 -822
- package/examples/jsm/libs/ammo.wasm.wasm +0 -0
- package/examples/jsm/libs/draco/draco_encoder.js +0 -33
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
- package/examples/jsm/libs/lottie_canvas.module.js +0 -14849
- package/examples/jsm/libs/opentype.module.js +0 -14506
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/lighting/TiledLighting.js +0 -42
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -434
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
- package/examples/jsm/shaders/GodRaysShader.js +0 -333
- package/examples/jsm/tsl/display/AnamorphicNode.js +0 -282
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
- package/src/nodes/accessors/BatchNode.js +0 -163
- package/src/nodes/accessors/InstanceNode.js +0 -244
- package/src/nodes/accessors/InstancedMeshNode.js +0 -50
- package/src/nodes/accessors/SceneNode.js +0 -145
- package/src/nodes/accessors/SkinningNode.js +0 -327
- package/src/nodes/code/ScriptableNode.js +0 -726
- package/src/nodes/code/ScriptableValueNode.js +0 -253
- package/src/nodes/display/PosterizeNode.js +0 -65
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
- package/src/nodes/utils/RemapNode.js +0 -125
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Box2,
|
|
3
3
|
BufferGeometry,
|
|
4
|
+
CanvasTexture,
|
|
5
|
+
ClampToEdgeWrapping,
|
|
6
|
+
Color,
|
|
7
|
+
DoubleSide,
|
|
4
8
|
FileLoader,
|
|
5
9
|
Float32BufferAttribute,
|
|
6
10
|
Loader,
|
|
7
11
|
Matrix3,
|
|
12
|
+
MeshBasicMaterial,
|
|
13
|
+
MirroredRepeatWrapping,
|
|
8
14
|
Path,
|
|
9
|
-
|
|
15
|
+
RepeatWrapping,
|
|
10
16
|
ShapePath,
|
|
11
17
|
ShapeUtils,
|
|
12
18
|
SRGBColorSpace,
|
|
@@ -144,6 +150,12 @@ class SVGLoader extends Loader {
|
|
|
144
150
|
|
|
145
151
|
if ( node.nodeType !== 1 ) return;
|
|
146
152
|
|
|
153
|
+
if ( node.hasAttribute( 'filter' ) ) {
|
|
154
|
+
|
|
155
|
+
console.warn( 'THREE.SVGLoader: Filters are not supported.' );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
147
159
|
const transform = getNodeTransform( node );
|
|
148
160
|
|
|
149
161
|
let isDefsNode = false;
|
|
@@ -228,7 +240,7 @@ class SVGLoader extends Loader {
|
|
|
228
240
|
|
|
229
241
|
if ( path ) {
|
|
230
242
|
|
|
231
|
-
if ( style.fill !== undefined && style.fill !== 'none' ) {
|
|
243
|
+
if ( style.fill !== undefined && style.fill !== 'none' && ! style.fill.startsWith( 'url' ) ) {
|
|
232
244
|
|
|
233
245
|
path.color.setStyle( style.fill, COLOR_SPACE_SVG );
|
|
234
246
|
|
|
@@ -238,7 +250,10 @@ class SVGLoader extends Loader {
|
|
|
238
250
|
|
|
239
251
|
paths.push( path );
|
|
240
252
|
|
|
241
|
-
|
|
253
|
+
const pathStyle = Object.assign( {}, style );
|
|
254
|
+
pathStyle.strokeWidth = style.strokeWidth * getTransformScale( currentTransform );
|
|
255
|
+
|
|
256
|
+
path.userData = { node: node, style: pathStyle, transform: currentTransform.clone(), gradients: gradients };
|
|
242
257
|
|
|
243
258
|
}
|
|
244
259
|
|
|
@@ -1044,6 +1059,146 @@ class SVGLoader extends Loader {
|
|
|
1044
1059
|
|
|
1045
1060
|
//
|
|
1046
1061
|
|
|
1062
|
+
function parseGradients( xml ) {
|
|
1063
|
+
|
|
1064
|
+
const HREF_NS = 'http://www.w3.org/1999/xlink';
|
|
1065
|
+
const gradientNodes = xml.querySelectorAll( 'linearGradient, radialGradient' );
|
|
1066
|
+
const ATTRS = [ 'x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'r', 'fx', 'fy', 'gradientUnits', 'gradientTransform', 'spreadMethod' ];
|
|
1067
|
+
|
|
1068
|
+
const parsed = {};
|
|
1069
|
+
|
|
1070
|
+
for ( const node of gradientNodes ) {
|
|
1071
|
+
|
|
1072
|
+
const id = node.getAttribute( 'id' );
|
|
1073
|
+
if ( ! id ) continue;
|
|
1074
|
+
|
|
1075
|
+
const entry = {
|
|
1076
|
+
type: node.nodeName === 'radialGradient' ? 'radialGradient' : 'linearGradient',
|
|
1077
|
+
attrs: {},
|
|
1078
|
+
stops: null,
|
|
1079
|
+
href: null,
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
const href = node.getAttributeNS( HREF_NS, 'href' ) || node.getAttribute( 'href' ) || '';
|
|
1083
|
+
if ( href.startsWith( '#' ) ) entry.href = href.substring( 1 );
|
|
1084
|
+
|
|
1085
|
+
for ( const name of ATTRS ) {
|
|
1086
|
+
|
|
1087
|
+
if ( node.hasAttribute( name ) ) entry.attrs[ name ] = node.getAttribute( name );
|
|
1088
|
+
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
const stopNodes = node.querySelectorAll( 'stop' );
|
|
1092
|
+
if ( stopNodes.length > 0 ) {
|
|
1093
|
+
|
|
1094
|
+
entry.stops = [];
|
|
1095
|
+
for ( const s of stopNodes ) {
|
|
1096
|
+
|
|
1097
|
+
let color = s.getAttribute( 'stop-color' );
|
|
1098
|
+
if ( ! color && s.style ) color = s.style[ 'stop-color' ];
|
|
1099
|
+
if ( ! color ) color = '#000';
|
|
1100
|
+
|
|
1101
|
+
let opacity = s.getAttribute( 'stop-opacity' );
|
|
1102
|
+
if ( ( opacity === null || opacity === '' ) && s.style ) opacity = s.style[ 'stop-opacity' ];
|
|
1103
|
+
opacity = ( opacity === null || opacity === '' || opacity === undefined )
|
|
1104
|
+
? 1
|
|
1105
|
+
: Math.max( 0, Math.min( 1, parseFloat( opacity ) ) );
|
|
1106
|
+
|
|
1107
|
+
const offset = Math.max( 0, Math.min( 1, parseFloat( s.getAttribute( 'offset' ) || '0' ) ) );
|
|
1108
|
+
entry.stops.push( { offset, color, opacity } );
|
|
1109
|
+
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
parsed[ id ] = entry;
|
|
1115
|
+
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function inherit( id, visited ) {
|
|
1119
|
+
|
|
1120
|
+
const entry = parsed[ id ];
|
|
1121
|
+
if ( ! entry || visited.has( id ) ) return entry;
|
|
1122
|
+
visited.add( id );
|
|
1123
|
+
|
|
1124
|
+
if ( entry.href && parsed[ entry.href ] ) {
|
|
1125
|
+
|
|
1126
|
+
const parent = inherit( entry.href, visited );
|
|
1127
|
+
if ( parent ) {
|
|
1128
|
+
|
|
1129
|
+
if ( ! entry.stops ) entry.stops = parent.stops;
|
|
1130
|
+
for ( const key in parent.attrs ) {
|
|
1131
|
+
|
|
1132
|
+
if ( ! ( key in entry.attrs ) ) entry.attrs[ key ] = parent.attrs[ key ];
|
|
1133
|
+
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
return entry;
|
|
1141
|
+
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
for ( const id in parsed ) inherit( id, new Set() );
|
|
1145
|
+
|
|
1146
|
+
for ( const id in parsed ) {
|
|
1147
|
+
|
|
1148
|
+
const entry = parsed[ id ];
|
|
1149
|
+
const a = entry.attrs;
|
|
1150
|
+
const units = a.gradientUnits === 'userSpaceOnUse' ? 'userSpaceOnUse' : 'objectBoundingBox';
|
|
1151
|
+
|
|
1152
|
+
const gradient = {
|
|
1153
|
+
type: entry.type,
|
|
1154
|
+
gradientUnits: units,
|
|
1155
|
+
spreadMethod: a.spreadMethod === 'reflect' || a.spreadMethod === 'repeat' ? a.spreadMethod : 'pad',
|
|
1156
|
+
gradientTransform: null,
|
|
1157
|
+
stops: ( entry.stops || [] ).slice().sort( ( x, y ) => x.offset - y.offset ),
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
if ( a.gradientTransform ) {
|
|
1161
|
+
|
|
1162
|
+
gradient.gradientTransform = new Matrix3();
|
|
1163
|
+
parseTransformString( a.gradientTransform, gradient.gradientTransform );
|
|
1164
|
+
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
function coord( str ) {
|
|
1168
|
+
|
|
1169
|
+
if ( typeof str !== 'string' ) return 0;
|
|
1170
|
+
if ( str.endsWith( '%' ) ) return parseFloat( str ) / 100;
|
|
1171
|
+
return parseFloatWithUnits( str );
|
|
1172
|
+
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if ( entry.type === 'linearGradient' ) {
|
|
1176
|
+
|
|
1177
|
+
gradient.x1 = a.x1 !== undefined ? coord( a.x1 ) : 0;
|
|
1178
|
+
gradient.y1 = a.y1 !== undefined ? coord( a.y1 ) : 0;
|
|
1179
|
+
gradient.x2 = a.x2 !== undefined ? coord( a.x2 ) : ( units === 'objectBoundingBox' ? 1 : 0 );
|
|
1180
|
+
gradient.y2 = a.y2 !== undefined ? coord( a.y2 ) : 0;
|
|
1181
|
+
|
|
1182
|
+
} else {
|
|
1183
|
+
|
|
1184
|
+
const defCenter = units === 'objectBoundingBox' ? 0.5 : 0;
|
|
1185
|
+
const defR = units === 'objectBoundingBox' ? 0.5 : 0;
|
|
1186
|
+
gradient.cx = a.cx !== undefined ? coord( a.cx ) : defCenter;
|
|
1187
|
+
gradient.cy = a.cy !== undefined ? coord( a.cy ) : defCenter;
|
|
1188
|
+
gradient.r = a.r !== undefined ? coord( a.r ) : defR;
|
|
1189
|
+
gradient.fx = a.fx !== undefined ? coord( a.fx ) : gradient.cx;
|
|
1190
|
+
gradient.fy = a.fy !== undefined ? coord( a.fy ) : gradient.cy;
|
|
1191
|
+
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
gradients[ id ] = gradient;
|
|
1195
|
+
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
//
|
|
1201
|
+
|
|
1047
1202
|
function parseStyle( node, style ) {
|
|
1048
1203
|
|
|
1049
1204
|
style = Object.assign( {}, style ); // clone style
|
|
@@ -1075,14 +1230,12 @@ class SVGLoader extends Loader {
|
|
|
1075
1230
|
|
|
1076
1231
|
if ( adjustFunction === undefined ) adjustFunction = function copy( v ) {
|
|
1077
1232
|
|
|
1078
|
-
if ( v.startsWith( 'url' ) ) console.warn( 'SVGLoader: url access in attributes is not implemented.' );
|
|
1079
|
-
|
|
1080
1233
|
return v;
|
|
1081
1234
|
|
|
1082
1235
|
};
|
|
1083
1236
|
|
|
1084
1237
|
if ( node.hasAttribute( svgName ) ) style[ jsName ] = adjustFunction( node.getAttribute( svgName ) );
|
|
1085
|
-
if ( stylesheetStyles[
|
|
1238
|
+
if ( stylesheetStyles[ jsName ] ) style[ jsName ] = adjustFunction( stylesheetStyles[ jsName ] );
|
|
1086
1239
|
if ( node.style && node.style[ svgName ] !== '' ) style[ jsName ] = adjustFunction( node.style[ svgName ] );
|
|
1087
1240
|
|
|
1088
1241
|
}
|
|
@@ -1498,151 +1651,160 @@ class SVGLoader extends Loader {
|
|
|
1498
1651
|
function parseNodeTransform( node ) {
|
|
1499
1652
|
|
|
1500
1653
|
const transform = new Matrix3();
|
|
1501
|
-
const currentTransform = tempTransform0;
|
|
1502
1654
|
|
|
1503
1655
|
if ( node.nodeName === 'use' && ( node.hasAttribute( 'x' ) || node.hasAttribute( 'y' ) ) ) {
|
|
1504
1656
|
|
|
1505
1657
|
const tx = parseFloatWithUnits( node.getAttribute( 'x' ) || 0 );
|
|
1506
1658
|
const ty = parseFloatWithUnits( node.getAttribute( 'y' ) || 0 );
|
|
1507
1659
|
|
|
1508
|
-
transform.
|
|
1660
|
+
transform.makeTranslation( tx, ty );
|
|
1509
1661
|
|
|
1510
1662
|
}
|
|
1511
1663
|
|
|
1512
1664
|
if ( node.hasAttribute( 'transform' ) ) {
|
|
1513
1665
|
|
|
1514
|
-
|
|
1666
|
+
parseTransformString( node.getAttribute( 'transform' ), transform );
|
|
1515
1667
|
|
|
1516
|
-
|
|
1668
|
+
}
|
|
1517
1669
|
|
|
1518
|
-
|
|
1670
|
+
return transform;
|
|
1519
1671
|
|
|
1520
|
-
|
|
1672
|
+
}
|
|
1521
1673
|
|
|
1522
|
-
|
|
1523
|
-
const closeParPos = transformText.length;
|
|
1674
|
+
function parseTransformString( text, transform ) {
|
|
1524
1675
|
|
|
1525
|
-
|
|
1676
|
+
const currentTransform = tempTransform0;
|
|
1526
1677
|
|
|
1527
|
-
|
|
1678
|
+
const transformsTexts = text.split( ')' );
|
|
1528
1679
|
|
|
1529
|
-
|
|
1680
|
+
for ( let tIndex = transformsTexts.length - 1; tIndex >= 0; tIndex -- ) {
|
|
1530
1681
|
|
|
1531
|
-
|
|
1682
|
+
const transformText = transformsTexts[ tIndex ].trim();
|
|
1532
1683
|
|
|
1533
|
-
|
|
1684
|
+
if ( transformText === '' ) continue;
|
|
1534
1685
|
|
|
1535
|
-
|
|
1686
|
+
const openParPos = transformText.indexOf( '(' );
|
|
1687
|
+
const closeParPos = transformText.length;
|
|
1536
1688
|
|
|
1537
|
-
|
|
1689
|
+
if ( openParPos > 0 && openParPos < closeParPos ) {
|
|
1538
1690
|
|
|
1539
|
-
|
|
1540
|
-
let ty = 0;
|
|
1691
|
+
const transformType = transformText.slice( 0, openParPos );
|
|
1541
1692
|
|
|
1542
|
-
|
|
1693
|
+
const array = parseFloats( transformText.slice( openParPos + 1 ) );
|
|
1543
1694
|
|
|
1544
|
-
|
|
1695
|
+
currentTransform.identity();
|
|
1545
1696
|
|
|
1546
|
-
|
|
1697
|
+
switch ( transformType ) {
|
|
1698
|
+
|
|
1699
|
+
case 'translate':
|
|
1700
|
+
|
|
1701
|
+
if ( array.length >= 1 ) {
|
|
1547
1702
|
|
|
1548
|
-
|
|
1703
|
+
const tx = array[ 0 ];
|
|
1704
|
+
let ty = 0;
|
|
1705
|
+
|
|
1706
|
+
if ( array.length >= 2 ) {
|
|
1707
|
+
|
|
1708
|
+
ty = array[ 1 ];
|
|
1549
1709
|
|
|
1550
1710
|
}
|
|
1551
1711
|
|
|
1552
|
-
|
|
1712
|
+
currentTransform.makeTranslation( tx, ty );
|
|
1553
1713
|
|
|
1554
|
-
|
|
1714
|
+
}
|
|
1555
1715
|
|
|
1556
|
-
|
|
1716
|
+
break;
|
|
1557
1717
|
|
|
1558
|
-
|
|
1559
|
-
let cx = 0;
|
|
1560
|
-
let cy = 0;
|
|
1718
|
+
case 'rotate':
|
|
1561
1719
|
|
|
1562
|
-
|
|
1563
|
-
angle = array[ 0 ] * Math.PI / 180;
|
|
1720
|
+
if ( array.length >= 1 ) {
|
|
1564
1721
|
|
|
1565
|
-
|
|
1722
|
+
let angle = 0;
|
|
1723
|
+
let cx = 0;
|
|
1724
|
+
let cy = 0;
|
|
1566
1725
|
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
cy = array[ 2 ];
|
|
1726
|
+
// Angle
|
|
1727
|
+
angle = array[ 0 ] * Math.PI / 180;
|
|
1570
1728
|
|
|
1571
|
-
|
|
1729
|
+
if ( array.length >= 3 ) {
|
|
1572
1730
|
|
|
1573
|
-
//
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
tempTransform3.multiplyMatrices( tempTransform2, tempTransform1 );
|
|
1577
|
-
tempTransform1.makeTranslation( cx, cy );
|
|
1578
|
-
currentTransform.multiplyMatrices( tempTransform1, tempTransform3 );
|
|
1731
|
+
// Center x, y
|
|
1732
|
+
cx = array[ 1 ];
|
|
1733
|
+
cy = array[ 2 ];
|
|
1579
1734
|
|
|
1580
1735
|
}
|
|
1581
1736
|
|
|
1582
|
-
|
|
1737
|
+
// Rotate around center (cx, cy)
|
|
1738
|
+
tempTransform1.makeTranslation( - cx, - cy );
|
|
1739
|
+
tempTransform2.makeRotation( angle );
|
|
1740
|
+
tempTransform3.multiplyMatrices( tempTransform2, tempTransform1 );
|
|
1741
|
+
tempTransform1.makeTranslation( cx, cy );
|
|
1742
|
+
currentTransform.multiplyMatrices( tempTransform1, tempTransform3 );
|
|
1583
1743
|
|
|
1584
|
-
|
|
1744
|
+
}
|
|
1585
1745
|
|
|
1586
|
-
|
|
1746
|
+
break;
|
|
1587
1747
|
|
|
1588
|
-
|
|
1589
|
-
let scaleY = scaleX;
|
|
1748
|
+
case 'scale':
|
|
1590
1749
|
|
|
1591
|
-
|
|
1750
|
+
if ( array.length >= 1 ) {
|
|
1592
1751
|
|
|
1593
|
-
|
|
1752
|
+
const scaleX = array[ 0 ];
|
|
1753
|
+
let scaleY = scaleX;
|
|
1594
1754
|
|
|
1595
|
-
|
|
1755
|
+
if ( array.length >= 2 ) {
|
|
1596
1756
|
|
|
1597
|
-
|
|
1757
|
+
scaleY = array[ 1 ];
|
|
1598
1758
|
|
|
1599
1759
|
}
|
|
1600
1760
|
|
|
1601
|
-
|
|
1761
|
+
currentTransform.makeScale( scaleX, scaleY );
|
|
1602
1762
|
|
|
1603
|
-
|
|
1763
|
+
}
|
|
1604
1764
|
|
|
1605
|
-
|
|
1765
|
+
break;
|
|
1606
1766
|
|
|
1607
|
-
|
|
1608
|
-
1, Math.tan( array[ 0 ] * Math.PI / 180 ), 0,
|
|
1609
|
-
0, 1, 0,
|
|
1610
|
-
0, 0, 1
|
|
1611
|
-
);
|
|
1767
|
+
case 'skewX':
|
|
1612
1768
|
|
|
1613
|
-
|
|
1769
|
+
if ( array.length === 1 ) {
|
|
1770
|
+
|
|
1771
|
+
currentTransform.set(
|
|
1772
|
+
1, Math.tan( array[ 0 ] * Math.PI / 180 ), 0,
|
|
1773
|
+
0, 1, 0,
|
|
1774
|
+
0, 0, 1
|
|
1775
|
+
);
|
|
1614
1776
|
|
|
1615
|
-
|
|
1777
|
+
}
|
|
1616
1778
|
|
|
1617
|
-
|
|
1779
|
+
break;
|
|
1618
1780
|
|
|
1619
|
-
|
|
1781
|
+
case 'skewY':
|
|
1620
1782
|
|
|
1621
|
-
|
|
1622
|
-
1, 0, 0,
|
|
1623
|
-
Math.tan( array[ 0 ] * Math.PI / 180 ), 1, 0,
|
|
1624
|
-
0, 0, 1
|
|
1625
|
-
);
|
|
1783
|
+
if ( array.length === 1 ) {
|
|
1626
1784
|
|
|
1627
|
-
|
|
1785
|
+
currentTransform.set(
|
|
1786
|
+
1, 0, 0,
|
|
1787
|
+
Math.tan( array[ 0 ] * Math.PI / 180 ), 1, 0,
|
|
1788
|
+
0, 0, 1
|
|
1789
|
+
);
|
|
1628
1790
|
|
|
1629
|
-
|
|
1791
|
+
}
|
|
1630
1792
|
|
|
1631
|
-
|
|
1793
|
+
break;
|
|
1632
1794
|
|
|
1633
|
-
|
|
1795
|
+
case 'matrix':
|
|
1634
1796
|
|
|
1635
|
-
|
|
1636
|
-
array[ 0 ], array[ 2 ], array[ 4 ],
|
|
1637
|
-
array[ 1 ], array[ 3 ], array[ 5 ],
|
|
1638
|
-
0, 0, 1
|
|
1639
|
-
);
|
|
1797
|
+
if ( array.length === 6 ) {
|
|
1640
1798
|
|
|
1641
|
-
|
|
1799
|
+
currentTransform.set(
|
|
1800
|
+
array[ 0 ], array[ 2 ], array[ 4 ],
|
|
1801
|
+
array[ 1 ], array[ 3 ], array[ 5 ],
|
|
1802
|
+
0, 0, 1
|
|
1803
|
+
);
|
|
1642
1804
|
|
|
1643
|
-
|
|
1805
|
+
}
|
|
1644
1806
|
|
|
1645
|
-
|
|
1807
|
+
break;
|
|
1646
1808
|
|
|
1647
1809
|
}
|
|
1648
1810
|
|
|
@@ -1875,6 +2037,14 @@ class SVGLoader extends Loader {
|
|
|
1875
2037
|
|
|
1876
2038
|
}
|
|
1877
2039
|
|
|
2040
|
+
function getTransformScale( m ) {
|
|
2041
|
+
|
|
2042
|
+
const te = m.elements;
|
|
2043
|
+
const det = te[ 0 ] * te[ 4 ] - te[ 1 ] * te[ 3 ];
|
|
2044
|
+
return Math.sqrt( Math.abs( det ) );
|
|
2045
|
+
|
|
2046
|
+
}
|
|
2047
|
+
|
|
1878
2048
|
// Calculates the eigensystem of a real symmetric 2x2 matrix
|
|
1879
2049
|
// [ A B ]
|
|
1880
2050
|
// [ B C ]
|
|
@@ -1958,6 +2128,7 @@ class SVGLoader extends Loader {
|
|
|
1958
2128
|
|
|
1959
2129
|
const paths = [];
|
|
1960
2130
|
const stylesheets = {};
|
|
2131
|
+
const gradients = {};
|
|
1961
2132
|
|
|
1962
2133
|
const transformStack = [];
|
|
1963
2134
|
|
|
@@ -1972,6 +2143,8 @@ class SVGLoader extends Loader {
|
|
|
1972
2143
|
|
|
1973
2144
|
const xml = new DOMParser().parseFromString( text, 'image/svg+xml' ); // application/xml
|
|
1974
2145
|
|
|
2146
|
+
parseGradients( xml );
|
|
2147
|
+
|
|
1975
2148
|
parseNode( xml.documentElement, {
|
|
1976
2149
|
fill: '#000',
|
|
1977
2150
|
fillOpacity: 1,
|
|
@@ -1982,7 +2155,7 @@ class SVGLoader extends Loader {
|
|
|
1982
2155
|
strokeMiterLimit: 4
|
|
1983
2156
|
} );
|
|
1984
2157
|
|
|
1985
|
-
const data = { paths: paths, xml: xml.documentElement };
|
|
2158
|
+
const data = { paths: paths, gradients: gradients, xml: xml.documentElement };
|
|
1986
2159
|
|
|
1987
2160
|
// console.log( paths );
|
|
1988
2161
|
return data;
|
|
@@ -1990,449 +2163,89 @@ class SVGLoader extends Loader {
|
|
|
1990
2163
|
}
|
|
1991
2164
|
|
|
1992
2165
|
/**
|
|
1993
|
-
* Creates
|
|
2166
|
+
* Creates a material for rendering the fill of the given path.
|
|
1994
2167
|
*
|
|
1995
2168
|
* @param {ShapePath} shapePath - The shape path.
|
|
1996
|
-
* @return {
|
|
2169
|
+
* @return {?MeshBasicMaterial} The fill material. `null` if the path has no fill.
|
|
1997
2170
|
*/
|
|
1998
|
-
static
|
|
1999
|
-
|
|
2000
|
-
const BIGNUMBER = 999999999;
|
|
2001
|
-
|
|
2002
|
-
const IntersectionLocationType = {
|
|
2003
|
-
ORIGIN: 0,
|
|
2004
|
-
DESTINATION: 1,
|
|
2005
|
-
BETWEEN: 2,
|
|
2006
|
-
LEFT: 3,
|
|
2007
|
-
RIGHT: 4,
|
|
2008
|
-
BEHIND: 5,
|
|
2009
|
-
BEYOND: 6
|
|
2010
|
-
};
|
|
2011
|
-
|
|
2012
|
-
const classifyResult = {
|
|
2013
|
-
loc: IntersectionLocationType.ORIGIN,
|
|
2014
|
-
t: 0
|
|
2015
|
-
};
|
|
2016
|
-
|
|
2017
|
-
function findEdgeIntersection( a0, a1, b0, b1 ) {
|
|
2018
|
-
|
|
2019
|
-
const x1 = a0.x;
|
|
2020
|
-
const x2 = a1.x;
|
|
2021
|
-
const x3 = b0.x;
|
|
2022
|
-
const x4 = b1.x;
|
|
2023
|
-
const y1 = a0.y;
|
|
2024
|
-
const y2 = a1.y;
|
|
2025
|
-
const y3 = b0.y;
|
|
2026
|
-
const y4 = b1.y;
|
|
2027
|
-
const nom1 = ( x4 - x3 ) * ( y1 - y3 ) - ( y4 - y3 ) * ( x1 - x3 );
|
|
2028
|
-
const nom2 = ( x2 - x1 ) * ( y1 - y3 ) - ( y2 - y1 ) * ( x1 - x3 );
|
|
2029
|
-
const denom = ( y4 - y3 ) * ( x2 - x1 ) - ( x4 - x3 ) * ( y2 - y1 );
|
|
2030
|
-
const t1 = nom1 / denom;
|
|
2031
|
-
const t2 = nom2 / denom;
|
|
2032
|
-
|
|
2033
|
-
if ( ( ( denom === 0 ) && ( nom1 !== 0 ) ) || ( t1 <= 0 ) || ( t1 >= 1 ) || ( t2 < 0 ) || ( t2 > 1 ) ) {
|
|
2034
|
-
|
|
2035
|
-
//1. lines are parallel or edges don't intersect
|
|
2036
|
-
|
|
2037
|
-
return null;
|
|
2038
|
-
|
|
2039
|
-
} else if ( ( nom1 === 0 ) && ( denom === 0 ) ) {
|
|
2040
|
-
|
|
2041
|
-
//2. lines are colinear
|
|
2042
|
-
|
|
2043
|
-
//check if endpoints of edge2 (b0-b1) lies on edge1 (a0-a1)
|
|
2044
|
-
for ( let i = 0; i < 2; i ++ ) {
|
|
2045
|
-
|
|
2046
|
-
classifyPoint( i === 0 ? b0 : b1, a0, a1 );
|
|
2047
|
-
//find position of this endpoints relatively to edge1
|
|
2048
|
-
if ( classifyResult.loc == IntersectionLocationType.ORIGIN ) {
|
|
2049
|
-
|
|
2050
|
-
const point = ( i === 0 ? b0 : b1 );
|
|
2051
|
-
return { x: point.x, y: point.y, t: classifyResult.t };
|
|
2052
|
-
|
|
2053
|
-
} else if ( classifyResult.loc == IntersectionLocationType.BETWEEN ) {
|
|
2054
|
-
|
|
2055
|
-
const x = + ( ( x1 + classifyResult.t * ( x2 - x1 ) ).toPrecision( 10 ) );
|
|
2056
|
-
const y = + ( ( y1 + classifyResult.t * ( y2 - y1 ) ).toPrecision( 10 ) );
|
|
2057
|
-
return { x: x, y: y, t: classifyResult.t, };
|
|
2058
|
-
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
return null;
|
|
2064
|
-
|
|
2065
|
-
} else {
|
|
2066
|
-
|
|
2067
|
-
//3. edges intersect
|
|
2068
|
-
|
|
2069
|
-
for ( let i = 0; i < 2; i ++ ) {
|
|
2070
|
-
|
|
2071
|
-
classifyPoint( i === 0 ? b0 : b1, a0, a1 );
|
|
2072
|
-
|
|
2073
|
-
if ( classifyResult.loc == IntersectionLocationType.ORIGIN ) {
|
|
2074
|
-
|
|
2075
|
-
const point = ( i === 0 ? b0 : b1 );
|
|
2076
|
-
return { x: point.x, y: point.y, t: classifyResult.t };
|
|
2077
|
-
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2081
|
-
|
|
2082
|
-
const x = + ( ( x1 + t1 * ( x2 - x1 ) ).toPrecision( 10 ) );
|
|
2083
|
-
const y = + ( ( y1 + t1 * ( y2 - y1 ) ).toPrecision( 10 ) );
|
|
2084
|
-
return { x: x, y: y, t: t1 };
|
|
2085
|
-
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
function classifyPoint( p, edgeStart, edgeEnd ) {
|
|
2091
|
-
|
|
2092
|
-
const ax = edgeEnd.x - edgeStart.x;
|
|
2093
|
-
const ay = edgeEnd.y - edgeStart.y;
|
|
2094
|
-
const bx = p.x - edgeStart.x;
|
|
2095
|
-
const by = p.y - edgeStart.y;
|
|
2096
|
-
const sa = ax * by - bx * ay;
|
|
2097
|
-
|
|
2098
|
-
if ( ( p.x === edgeStart.x ) && ( p.y === edgeStart.y ) ) {
|
|
2099
|
-
|
|
2100
|
-
classifyResult.loc = IntersectionLocationType.ORIGIN;
|
|
2101
|
-
classifyResult.t = 0;
|
|
2102
|
-
return;
|
|
2103
|
-
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
if ( ( p.x === edgeEnd.x ) && ( p.y === edgeEnd.y ) ) {
|
|
2107
|
-
|
|
2108
|
-
classifyResult.loc = IntersectionLocationType.DESTINATION;
|
|
2109
|
-
classifyResult.t = 1;
|
|
2110
|
-
return;
|
|
2111
|
-
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
if ( sa < - Number.EPSILON ) {
|
|
2115
|
-
|
|
2116
|
-
classifyResult.loc = IntersectionLocationType.LEFT;
|
|
2117
|
-
return;
|
|
2118
|
-
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
if ( sa > Number.EPSILON ) {
|
|
2122
|
-
|
|
2123
|
-
classifyResult.loc = IntersectionLocationType.RIGHT;
|
|
2124
|
-
return;
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
if ( ( ( ax * bx ) < 0 ) || ( ( ay * by ) < 0 ) ) {
|
|
2130
|
-
|
|
2131
|
-
classifyResult.loc = IntersectionLocationType.BEHIND;
|
|
2132
|
-
return;
|
|
2133
|
-
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
|
-
if ( ( Math.sqrt( ax * ax + ay * ay ) ) < ( Math.sqrt( bx * bx + by * by ) ) ) {
|
|
2137
|
-
|
|
2138
|
-
classifyResult.loc = IntersectionLocationType.BEYOND;
|
|
2139
|
-
return;
|
|
2140
|
-
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
let t;
|
|
2144
|
-
|
|
2145
|
-
if ( ax !== 0 ) {
|
|
2146
|
-
|
|
2147
|
-
t = bx / ax;
|
|
2148
|
-
|
|
2149
|
-
} else {
|
|
2150
|
-
|
|
2151
|
-
t = by / ay;
|
|
2152
|
-
|
|
2153
|
-
}
|
|
2154
|
-
|
|
2155
|
-
classifyResult.loc = IntersectionLocationType.BETWEEN;
|
|
2156
|
-
classifyResult.t = t;
|
|
2157
|
-
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
function getIntersections( path1, path2 ) {
|
|
2161
|
-
|
|
2162
|
-
const intersectionsRaw = [];
|
|
2163
|
-
const intersections = [];
|
|
2164
|
-
|
|
2165
|
-
for ( let index = 1; index < path1.length; index ++ ) {
|
|
2166
|
-
|
|
2167
|
-
const path1EdgeStart = path1[ index - 1 ];
|
|
2168
|
-
const path1EdgeEnd = path1[ index ];
|
|
2169
|
-
|
|
2170
|
-
for ( let index2 = 1; index2 < path2.length; index2 ++ ) {
|
|
2171
|
-
|
|
2172
|
-
const path2EdgeStart = path2[ index2 - 1 ];
|
|
2173
|
-
const path2EdgeEnd = path2[ index2 ];
|
|
2174
|
-
|
|
2175
|
-
const intersection = findEdgeIntersection( path1EdgeStart, path1EdgeEnd, path2EdgeStart, path2EdgeEnd );
|
|
2176
|
-
|
|
2177
|
-
if ( intersection !== null && intersectionsRaw.find( i => i.t <= intersection.t + Number.EPSILON && i.t >= intersection.t - Number.EPSILON ) === undefined ) {
|
|
2171
|
+
static createFillMaterial( shapePath ) {
|
|
2178
2172
|
|
|
2179
|
-
|
|
2180
|
-
|
|
2173
|
+
const style = shapePath.userData.style;
|
|
2174
|
+
if ( style.fill === undefined || style.fill === 'none' ) return null;
|
|
2181
2175
|
|
|
2182
|
-
|
|
2176
|
+
const color = shapePath.color;
|
|
2177
|
+
let texture = null;
|
|
2183
2178
|
|
|
2184
|
-
|
|
2179
|
+
const urlMatch = GRADIENT_URL_RE.exec( style.fill );
|
|
2185
2180
|
|
|
2186
|
-
|
|
2181
|
+
if ( urlMatch ) {
|
|
2187
2182
|
|
|
2188
|
-
|
|
2183
|
+
const gradient = shapePath.userData.gradients && shapePath.userData.gradients[ urlMatch[ 1 ] ];
|
|
2184
|
+
texture = buildGradientTexture( gradient, shapePath );
|
|
2189
2185
|
|
|
2190
2186
|
}
|
|
2191
2187
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
paths.forEach( path => {
|
|
2200
|
-
|
|
2201
|
-
// check if the center of the bounding box is in the bounding box of the paths.
|
|
2202
|
-
// this is a pruning method to limit the search of intersections in paths that can't envelop of the current path.
|
|
2203
|
-
// if a path envelops another path. The center of that other path, has to be inside the bounding box of the enveloping path.
|
|
2204
|
-
if ( path.boundingBox.containsPoint( center ) ) {
|
|
2205
|
-
|
|
2206
|
-
const intersections = getIntersections( scanline, path.points );
|
|
2207
|
-
|
|
2208
|
-
intersections.forEach( p => {
|
|
2209
|
-
|
|
2210
|
-
allIntersections.push( { identifier: path.identifier, isCW: path.isCW, point: p } );
|
|
2211
|
-
|
|
2212
|
-
} );
|
|
2213
|
-
|
|
2214
|
-
}
|
|
2215
|
-
|
|
2216
|
-
} );
|
|
2188
|
+
const material = new MeshBasicMaterial( {
|
|
2189
|
+
opacity: style.fillOpacity * ( style.opacity || 1 ),
|
|
2190
|
+
transparent: true,
|
|
2191
|
+
side: DoubleSide,
|
|
2192
|
+
depthWrite: false,
|
|
2193
|
+
} );
|
|
2217
2194
|
|
|
2218
|
-
|
|
2195
|
+
if ( texture !== null ) {
|
|
2219
2196
|
|
|
2220
|
-
|
|
2197
|
+
material.map = texture;
|
|
2221
2198
|
|
|
2222
|
-
|
|
2199
|
+
} else {
|
|
2223
2200
|
|
|
2224
|
-
|
|
2201
|
+
material.color = color;
|
|
2225
2202
|
|
|
2226
2203
|
}
|
|
2227
2204
|
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
if ( _fillRule === null || _fillRule === undefined || _fillRule === '' ) {
|
|
2231
|
-
|
|
2232
|
-
_fillRule = 'nonzero';
|
|
2233
|
-
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
const centerBoundingBox = new Vector2();
|
|
2237
|
-
simplePath.boundingBox.getCenter( centerBoundingBox );
|
|
2238
|
-
|
|
2239
|
-
const scanline = [ new Vector2( scanlineMinX, centerBoundingBox.y ), new Vector2( scanlineMaxX, centerBoundingBox.y ) ];
|
|
2240
|
-
|
|
2241
|
-
const scanlineIntersections = getScanlineIntersections( scanline, simplePath.boundingBox, allPaths );
|
|
2242
|
-
|
|
2243
|
-
scanlineIntersections.sort( ( i1, i2 ) => {
|
|
2244
|
-
|
|
2245
|
-
return i1.point.x - i2.point.x;
|
|
2246
|
-
|
|
2247
|
-
} );
|
|
2248
|
-
|
|
2249
|
-
const baseIntersections = [];
|
|
2250
|
-
const otherIntersections = [];
|
|
2251
|
-
|
|
2252
|
-
scanlineIntersections.forEach( i => {
|
|
2253
|
-
|
|
2254
|
-
if ( i.identifier === simplePath.identifier ) {
|
|
2255
|
-
|
|
2256
|
-
baseIntersections.push( i );
|
|
2257
|
-
|
|
2258
|
-
} else {
|
|
2259
|
-
|
|
2260
|
-
otherIntersections.push( i );
|
|
2261
|
-
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
|
-
} );
|
|
2265
|
-
|
|
2266
|
-
const firstXOfPath = baseIntersections[ 0 ].point.x;
|
|
2267
|
-
|
|
2268
|
-
// build up the path hierarchy
|
|
2269
|
-
const stack = [];
|
|
2270
|
-
let i = 0;
|
|
2271
|
-
|
|
2272
|
-
while ( i < otherIntersections.length && otherIntersections[ i ].point.x < firstXOfPath ) {
|
|
2273
|
-
|
|
2274
|
-
if ( stack.length > 0 && stack[ stack.length - 1 ] === otherIntersections[ i ].identifier ) {
|
|
2275
|
-
|
|
2276
|
-
stack.pop();
|
|
2277
|
-
|
|
2278
|
-
} else {
|
|
2279
|
-
|
|
2280
|
-
stack.push( otherIntersections[ i ].identifier );
|
|
2281
|
-
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
i ++;
|
|
2285
|
-
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
stack.push( simplePath.identifier );
|
|
2289
|
-
|
|
2290
|
-
if ( _fillRule === 'evenodd' ) {
|
|
2291
|
-
|
|
2292
|
-
const isHole = stack.length % 2 === 0 ? true : false;
|
|
2293
|
-
const isHoleFor = stack[ stack.length - 2 ];
|
|
2205
|
+
return material;
|
|
2294
2206
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
} else if ( _fillRule === 'nonzero' ) {
|
|
2298
|
-
|
|
2299
|
-
// check if path is a hole by counting the amount of paths with alternating rotations it has to cross.
|
|
2300
|
-
let isHole = true;
|
|
2301
|
-
let isHoleFor = null;
|
|
2302
|
-
let lastCWValue = null;
|
|
2303
|
-
|
|
2304
|
-
for ( let i = 0; i < stack.length; i ++ ) {
|
|
2305
|
-
|
|
2306
|
-
const identifier = stack[ i ];
|
|
2307
|
-
if ( isHole ) {
|
|
2308
|
-
|
|
2309
|
-
lastCWValue = allPaths[ identifier ].isCW;
|
|
2310
|
-
isHole = false;
|
|
2311
|
-
isHoleFor = identifier;
|
|
2312
|
-
|
|
2313
|
-
} else if ( lastCWValue !== allPaths[ identifier ].isCW ) {
|
|
2314
|
-
|
|
2315
|
-
lastCWValue = allPaths[ identifier ].isCW;
|
|
2316
|
-
isHole = true;
|
|
2317
|
-
|
|
2318
|
-
}
|
|
2207
|
+
}
|
|
2319
2208
|
|
|
2320
|
-
|
|
2209
|
+
/**
|
|
2210
|
+
* Creates a material for rendering the stroke of the given path.
|
|
2211
|
+
*
|
|
2212
|
+
* @param {ShapePath} shapePath - The shape path.
|
|
2213
|
+
* @return {?MeshBasicMaterial} The stroke material. `null` if the path has no stroke.
|
|
2214
|
+
*/
|
|
2215
|
+
static createStrokeMaterial( shapePath ) {
|
|
2321
2216
|
|
|
2322
|
-
|
|
2217
|
+
const style = shapePath.userData.style;
|
|
2323
2218
|
|
|
2324
|
-
|
|
2219
|
+
if ( style.stroke === undefined || style.stroke === 'none' ) return null;
|
|
2325
2220
|
|
|
2326
|
-
|
|
2221
|
+
if ( GRADIENT_URL_RE.test( style.stroke ) ) {
|
|
2327
2222
|
|
|
2328
|
-
|
|
2223
|
+
console.warn( 'THREE.SVGLoader: Gradient strokes are not supported.' );
|
|
2329
2224
|
|
|
2330
2225
|
}
|
|
2331
2226
|
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
// prepare paths for hole detection
|
|
2339
|
-
let scanlineMinX = BIGNUMBER;
|
|
2340
|
-
let scanlineMaxX = - BIGNUMBER;
|
|
2341
|
-
|
|
2342
|
-
let simplePaths = shapePath.subPaths.map( p => {
|
|
2343
|
-
|
|
2344
|
-
const points = p.getPoints();
|
|
2345
|
-
let maxY = - BIGNUMBER;
|
|
2346
|
-
let minY = BIGNUMBER;
|
|
2347
|
-
let maxX = - BIGNUMBER;
|
|
2348
|
-
let minX = BIGNUMBER;
|
|
2349
|
-
|
|
2350
|
-
//points.forEach(p => p.y *= -1);
|
|
2351
|
-
|
|
2352
|
-
for ( let i = 0; i < points.length; i ++ ) {
|
|
2353
|
-
|
|
2354
|
-
const p = points[ i ];
|
|
2355
|
-
|
|
2356
|
-
if ( p.y > maxY ) {
|
|
2357
|
-
|
|
2358
|
-
maxY = p.y;
|
|
2359
|
-
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
if ( p.y < minY ) {
|
|
2363
|
-
|
|
2364
|
-
minY = p.y;
|
|
2365
|
-
|
|
2366
|
-
}
|
|
2367
|
-
|
|
2368
|
-
if ( p.x > maxX ) {
|
|
2369
|
-
|
|
2370
|
-
maxX = p.x;
|
|
2371
|
-
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
if ( p.x < minX ) {
|
|
2375
|
-
|
|
2376
|
-
minX = p.x;
|
|
2377
|
-
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
//
|
|
2383
|
-
if ( scanlineMaxX <= maxX ) {
|
|
2384
|
-
|
|
2385
|
-
scanlineMaxX = maxX + 1;
|
|
2386
|
-
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
if ( scanlineMinX >= minX ) {
|
|
2390
|
-
|
|
2391
|
-
scanlineMinX = minX - 1;
|
|
2392
|
-
|
|
2393
|
-
}
|
|
2394
|
-
|
|
2395
|
-
return { curves: p.curves, points: points, isCW: ShapeUtils.isClockWise( points ), identifier: - 1, boundingBox: new Box2( new Vector2( minX, minY ), new Vector2( maxX, maxY ) ) };
|
|
2396
|
-
|
|
2227
|
+
return new MeshBasicMaterial( {
|
|
2228
|
+
color: new Color().setStyle( style.stroke, COLOR_SPACE_SVG ),
|
|
2229
|
+
opacity: style.strokeOpacity * ( style.opacity || 1 ),
|
|
2230
|
+
transparent: true,
|
|
2231
|
+
side: DoubleSide,
|
|
2232
|
+
depthWrite: false,
|
|
2397
2233
|
} );
|
|
2398
2234
|
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
for ( let identifier = 0; identifier < simplePaths.length; identifier ++ ) {
|
|
2402
|
-
|
|
2403
|
-
simplePaths[ identifier ].identifier = identifier;
|
|
2404
|
-
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
// check if path is solid or a hole
|
|
2408
|
-
const isAHole = simplePaths.map( p => isHoleTo( p, simplePaths, scanlineMinX, scanlineMaxX, ( shapePath.userData ? shapePath.userData.style.fillRule : undefined ) ) );
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
const shapesToReturn = [];
|
|
2412
|
-
simplePaths.forEach( p => {
|
|
2413
|
-
|
|
2414
|
-
const amIAHole = isAHole[ p.identifier ];
|
|
2415
|
-
|
|
2416
|
-
if ( ! amIAHole.isHole ) {
|
|
2417
|
-
|
|
2418
|
-
const shape = new Shape();
|
|
2419
|
-
shape.curves = p.curves;
|
|
2420
|
-
const holes = isAHole.filter( h => h.isHole && h.for === p.identifier );
|
|
2421
|
-
holes.forEach( h => {
|
|
2422
|
-
|
|
2423
|
-
const hole = simplePaths[ h.identifier ];
|
|
2424
|
-
const path = new Path();
|
|
2425
|
-
path.curves = hole.curves;
|
|
2426
|
-
shape.holes.push( path );
|
|
2427
|
-
|
|
2428
|
-
} );
|
|
2429
|
-
shapesToReturn.push( shape );
|
|
2235
|
+
}
|
|
2430
2236
|
|
|
2431
|
-
|
|
2237
|
+
/**
|
|
2238
|
+
* Creates from the given shape path and array of shapes.
|
|
2239
|
+
*
|
|
2240
|
+
* @deprecated since 185.
|
|
2241
|
+
* @param {ShapePath} shapePath - The shape path.
|
|
2242
|
+
* @return {Array<Shape>} An array of shapes.
|
|
2243
|
+
*/
|
|
2244
|
+
static createShapes( shapePath ) {
|
|
2432
2245
|
|
|
2433
|
-
|
|
2246
|
+
console.warn( 'SVGLoader: createShapes() is deprecated. Use shapePath.toShapes() instead.' ); // @deprecated, r185
|
|
2434
2247
|
|
|
2435
|
-
return
|
|
2248
|
+
return shapePath.toShapes();
|
|
2436
2249
|
|
|
2437
2250
|
}
|
|
2438
2251
|
|
|
@@ -2653,6 +2466,22 @@ class SVGLoader extends Loader {
|
|
|
2653
2466
|
outerPoint.copy( tempV2_5 ).add( currentPoint );
|
|
2654
2467
|
innerPoint.add( currentPoint );
|
|
2655
2468
|
|
|
2469
|
+
// in-loop fold detection to mitigate #25326
|
|
2470
|
+
if ( innerSideModified ) {
|
|
2471
|
+
|
|
2472
|
+
// when the second triangle's signed area would flip, snap innerPoint to the previous inner-side vertex
|
|
2473
|
+
|
|
2474
|
+
const refPt = joinIsOnLeftSide ? lastPointR : lastPointL;
|
|
2475
|
+
const foldCross = ( outerPoint.x - refPt.x ) * ( innerPoint.y - refPt.y )
|
|
2476
|
+
- ( outerPoint.y - refPt.y ) * ( innerPoint.x - refPt.x );
|
|
2477
|
+
if ( ( joinIsOnLeftSide && foldCross < 0 ) || ( ! joinIsOnLeftSide && foldCross > 0 ) ) {
|
|
2478
|
+
|
|
2479
|
+
innerPoint.copy( refPt );
|
|
2480
|
+
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2656
2485
|
isMiter = false;
|
|
2657
2486
|
|
|
2658
2487
|
if ( innerSideModified ) {
|
|
@@ -2931,6 +2760,32 @@ class SVGLoader extends Loader {
|
|
|
2931
2760
|
|
|
2932
2761
|
}
|
|
2933
2762
|
|
|
2763
|
+
// Second fix for #25326: Scan for reamining flipped (CW) triangles and collapse them to
|
|
2764
|
+
// degenerated ones. This is safe and leaves no "holes" in the stroke because the flipped
|
|
2765
|
+
// triangle's area is covered by neighbouring (CCW) triangles.
|
|
2766
|
+
|
|
2767
|
+
if ( vertices ) {
|
|
2768
|
+
|
|
2769
|
+
const tri = [ new Vector2(), new Vector2(), new Vector2() ];
|
|
2770
|
+
const startFloat = vertexOffset * 3;
|
|
2771
|
+
|
|
2772
|
+
for ( let t = startFloat; t < currentCoordinate; t += 9 ) {
|
|
2773
|
+
|
|
2774
|
+
tri[ 0 ].set( vertices[ t ], vertices[ t + 1 ] );
|
|
2775
|
+
tri[ 1 ].set( vertices[ t + 3 ], vertices[ t + 4 ] );
|
|
2776
|
+
tri[ 2 ].set( vertices[ t + 6 ], vertices[ t + 7 ] );
|
|
2777
|
+
|
|
2778
|
+
if ( ShapeUtils.area( tri ) < 0 ) {
|
|
2779
|
+
|
|
2780
|
+
vertices[ t + 3 ] = tri[ 0 ].x;
|
|
2781
|
+
vertices[ t + 4 ] = tri[ 0 ].y;
|
|
2782
|
+
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2934
2789
|
return numVertices;
|
|
2935
2790
|
|
|
2936
2791
|
// -- End of algorithm
|
|
@@ -3005,7 +2860,7 @@ class SVGLoader extends Loader {
|
|
|
3005
2860
|
|
|
3006
2861
|
}
|
|
3007
2862
|
|
|
3008
|
-
addVertex(
|
|
2863
|
+
addVertex( tempV2_3, u, v );
|
|
3009
2864
|
addVertex( p2, u, v );
|
|
3010
2865
|
addVertex( center, u, 0.5 );
|
|
3011
2866
|
|
|
@@ -3261,6 +3116,203 @@ class SVGLoader extends Loader {
|
|
|
3261
3116
|
|
|
3262
3117
|
}
|
|
3263
3118
|
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
const GRADIENT_URL_RE = /^\s*url\(\s*(?:["']\s*)?#([^)'"\s]+)(?:\s*["'])?\s*\)\s*$/;
|
|
3122
|
+
|
|
3123
|
+
// Bakes a gradient into a CanvasTexture in its own local frame and configures
|
|
3124
|
+
// `texture.matrix` (with `matrixAutoUpdate = false`) so that shape-space UVs —
|
|
3125
|
+
// which, because transformPath bakes the world matrix into geometry vertex
|
|
3126
|
+
// positions, equal world xy — sample the correct gradient color. The caller
|
|
3127
|
+
// just sets `material.map = texture`; no bounding box, no geometry, no
|
|
3128
|
+
// per-vertex UV work required.
|
|
3129
|
+
function buildGradientTexture( gradient, shapePath, resolution = 256 ) {
|
|
3130
|
+
|
|
3131
|
+
if ( ! gradient || ! Array.isArray( gradient.stops ) || gradient.stops.length === 0 ) return null;
|
|
3132
|
+
|
|
3133
|
+
const worldTransform = shapePath.userData.transform;
|
|
3134
|
+
const isBBoxUnits = gradient.gradientUnits === 'objectBoundingBox';
|
|
3135
|
+
|
|
3136
|
+
// For objectBoundingBox gradients we need the element's local bounding
|
|
3137
|
+
// box. Path points are in world space (transformPath already applied the
|
|
3138
|
+
// world transform), so invert that first.
|
|
3139
|
+
let localBBox = null;
|
|
3140
|
+
|
|
3141
|
+
if ( isBBoxUnits ) {
|
|
3142
|
+
|
|
3143
|
+
localBBox = computeLocalBBox( shapePath, worldTransform );
|
|
3144
|
+
if ( localBBox === null ) return null;
|
|
3145
|
+
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
// Resolves a gradient-space point to the geometry's (world) coordinate
|
|
3149
|
+
// space: gradient coord → gradientTransform → target coord → (for
|
|
3150
|
+
// objectBoundingBox: bbox → local) → worldTransform → world.
|
|
3151
|
+
function resolvePoint( x, y, out ) {
|
|
3152
|
+
|
|
3153
|
+
out.set( x, y, 1 );
|
|
3154
|
+
if ( gradient.gradientTransform ) out.applyMatrix3( gradient.gradientTransform );
|
|
3155
|
+
if ( isBBoxUnits ) out.set(
|
|
3156
|
+
localBBox.minX + out.x * localBBox.width,
|
|
3157
|
+
localBBox.minY + out.y * localBBox.height,
|
|
3158
|
+
1,
|
|
3159
|
+
);
|
|
3160
|
+
if ( worldTransform ) out.applyMatrix3( worldTransform );
|
|
3161
|
+
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
const canvas = document.createElement( 'canvas' );
|
|
3165
|
+
let textureMatrix;
|
|
3166
|
+
|
|
3167
|
+
if ( gradient.type === 'linearGradient' ) {
|
|
3168
|
+
|
|
3169
|
+
// 1D bake along the gradient vector.
|
|
3170
|
+
canvas.width = resolution;
|
|
3171
|
+
canvas.height = 1;
|
|
3172
|
+
const ctx = canvas.getContext( '2d' );
|
|
3173
|
+
|
|
3174
|
+
const grad = ctx.createLinearGradient( 0, 0, resolution, 0 );
|
|
3175
|
+
addStops( grad, gradient.stops );
|
|
3176
|
+
ctx.fillStyle = grad;
|
|
3177
|
+
ctx.fillRect( 0, 0, resolution, 1 );
|
|
3178
|
+
|
|
3179
|
+
const p1 = new Vector3();
|
|
3180
|
+
const p2 = new Vector3();
|
|
3181
|
+
resolvePoint( gradient.x1, gradient.y1, p1 );
|
|
3182
|
+
resolvePoint( gradient.x2, gradient.y2, p2 );
|
|
3183
|
+
|
|
3184
|
+
const dx = p2.x - p1.x;
|
|
3185
|
+
const dy = p2.y - p1.y;
|
|
3186
|
+
const len2 = dx * dx + dy * dy || 1e-20;
|
|
3187
|
+
const a = dx / len2;
|
|
3188
|
+
const b = dy / len2;
|
|
3189
|
+
const c = - ( a * p1.x + b * p1.y );
|
|
3190
|
+
|
|
3191
|
+
// M * (vx, vy, 1) = (t, 0.5, 1)
|
|
3192
|
+
textureMatrix = new Matrix3().set(
|
|
3193
|
+
a, b, c,
|
|
3194
|
+
0, 0, 0.5,
|
|
3195
|
+
0, 0, 1,
|
|
3196
|
+
);
|
|
3197
|
+
|
|
3198
|
+
} else {
|
|
3199
|
+
|
|
3200
|
+
// Resolve cx/cy/fx/fy into local space and scale r per the SVG spec
|
|
3201
|
+
// (objectBoundingBox scales lengths by sqrt((w² + h²) / 2)). The canvas
|
|
3202
|
+
// only draws circular radial gradients, so any ellipticity induced by
|
|
3203
|
+
// a non-uniform world transform is picked up later via the UV matrix.
|
|
3204
|
+
let cx = gradient.cx, cy = gradient.cy;
|
|
3205
|
+
let fx = gradient.fx, fy = gradient.fy;
|
|
3206
|
+
let r = gradient.r;
|
|
3207
|
+
|
|
3208
|
+
if ( gradient.gradientTransform ) {
|
|
3209
|
+
|
|
3210
|
+
const tmp = new Vector3();
|
|
3211
|
+
tmp.set( cx, cy, 1 ).applyMatrix3( gradient.gradientTransform );
|
|
3212
|
+
cx = tmp.x; cy = tmp.y;
|
|
3213
|
+
tmp.set( fx, fy, 1 ).applyMatrix3( gradient.gradientTransform );
|
|
3214
|
+
fx = tmp.x; fy = tmp.y;
|
|
3215
|
+
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
if ( isBBoxUnits ) {
|
|
3219
|
+
|
|
3220
|
+
cx = localBBox.minX + cx * localBBox.width;
|
|
3221
|
+
cy = localBBox.minY + cy * localBBox.height;
|
|
3222
|
+
fx = localBBox.minX + fx * localBBox.width;
|
|
3223
|
+
fy = localBBox.minY + fy * localBBox.height;
|
|
3224
|
+
r = r * Math.sqrt( ( localBBox.width * localBBox.width + localBBox.height * localBBox.height ) / 2 );
|
|
3225
|
+
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
if ( r <= 0 ) return null;
|
|
3229
|
+
|
|
3230
|
+
// 2D bake in the gradient's local frame, covering [cx-r, cx+r]².
|
|
3231
|
+
canvas.width = resolution;
|
|
3232
|
+
canvas.height = resolution;
|
|
3233
|
+
const ctx = canvas.getContext( '2d' );
|
|
3234
|
+
|
|
3235
|
+
const localMinX = cx - r;
|
|
3236
|
+
const localMinY = cy - r;
|
|
3237
|
+
const localSpan = 2 * r;
|
|
3238
|
+
const scale = resolution / localSpan;
|
|
3239
|
+
|
|
3240
|
+
// Canvas pixel = (local - localMin) * scale.
|
|
3241
|
+
ctx.setTransform( scale, 0, 0, scale, - localMinX * scale, - localMinY * scale );
|
|
3242
|
+
|
|
3243
|
+
const grad = ctx.createRadialGradient( fx, fy, 0, cx, cy, r );
|
|
3244
|
+
addStops( grad, gradient.stops );
|
|
3245
|
+
ctx.fillStyle = grad;
|
|
3246
|
+
ctx.fillRect( localMinX, localMinY, localSpan, localSpan );
|
|
3247
|
+
|
|
3248
|
+
// UV matrix: world → local (via worldTransform⁻¹) → normalized canvas UV.
|
|
3249
|
+
const inv = worldTransform ? worldTransform.clone().invert() : new Matrix3();
|
|
3250
|
+
const norm = new Matrix3().set(
|
|
3251
|
+
1 / localSpan, 0, - localMinX / localSpan,
|
|
3252
|
+
0, 1 / localSpan, - localMinY / localSpan,
|
|
3253
|
+
0, 0, 1,
|
|
3254
|
+
);
|
|
3255
|
+
textureMatrix = norm.multiply( inv );
|
|
3256
|
+
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
const texture = new CanvasTexture( canvas );
|
|
3260
|
+
texture.colorSpace = COLOR_SPACE_SVG;
|
|
3261
|
+
texture.flipY = false;
|
|
3262
|
+
texture.matrixAutoUpdate = false;
|
|
3263
|
+
texture.matrix = textureMatrix;
|
|
3264
|
+
|
|
3265
|
+
const wrap = gradient.spreadMethod === 'reflect' ? MirroredRepeatWrapping
|
|
3266
|
+
: gradient.spreadMethod === 'repeat' ? RepeatWrapping
|
|
3267
|
+
: ClampToEdgeWrapping;
|
|
3268
|
+
texture.wrapS = wrap;
|
|
3269
|
+
texture.wrapT = wrap;
|
|
3270
|
+
|
|
3271
|
+
return texture;
|
|
3272
|
+
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
function computeLocalBBox( shapePath, worldTransform ) {
|
|
3276
|
+
|
|
3277
|
+
const inv = worldTransform ? worldTransform.clone().invert() : null;
|
|
3278
|
+
const tmp = new Vector2();
|
|
3279
|
+
const box = new Box2();
|
|
3280
|
+
|
|
3281
|
+
for ( const subPath of shapePath.subPaths ) {
|
|
3282
|
+
|
|
3283
|
+
for ( const p of subPath.getPoints() ) {
|
|
3284
|
+
|
|
3285
|
+
tmp.copy( p );
|
|
3286
|
+
if ( inv ) tmp.applyMatrix3( inv );
|
|
3287
|
+
box.expandByPoint( tmp );
|
|
3288
|
+
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
if ( box.isEmpty() ) return null;
|
|
3294
|
+
|
|
3295
|
+
return { minX: box.min.x, minY: box.min.y, width: box.max.x - box.min.x, height: box.max.y - box.min.y };
|
|
3296
|
+
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
function addStops( canvasGradient, stops ) {
|
|
3300
|
+
|
|
3301
|
+
const tmpColor = new Color();
|
|
3302
|
+
for ( const stop of stops ) {
|
|
3303
|
+
|
|
3304
|
+
let css = stop.color;
|
|
3305
|
+
if ( stop.opacity < 1 ) {
|
|
3306
|
+
|
|
3307
|
+
tmpColor.setStyle( stop.color, COLOR_SPACE_SVG );
|
|
3308
|
+
const m = /rgb\(([^)]+)\)/.exec( tmpColor.getStyle( COLOR_SPACE_SVG ) );
|
|
3309
|
+
if ( m ) css = `rgba(${m[ 1 ]},${stop.opacity})`;
|
|
3310
|
+
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
canvasGradient.addColorStop( Math.max( 0, Math.min( 1, stop.offset ) ), css );
|
|
3314
|
+
|
|
3315
|
+
}
|
|
3264
3316
|
|
|
3265
3317
|
}
|
|
3266
3318
|
|