@needle-tools/three 0.145.2 → 0.146.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/README.md +1 -1
- package/build/three.cjs +3559 -6924
- package/build/three.js +3559 -6924
- package/build/three.min.js +1 -2
- package/build/three.module.js +732 -339
- package/examples/js/animation/AnimationClipCreator.js +0 -8
- package/examples/js/animation/CCDIKSolver.js +49 -66
- package/examples/js/animation/MMDAnimationHelper.js +66 -137
- package/examples/js/animation/MMDPhysics.js +70 -134
- package/examples/js/cameras/CinematicCamera.js +33 -22
- package/examples/js/controls/ArcballControls.js +138 -405
- package/examples/js/controls/DragControls.js +8 -33
- package/examples/js/controls/FirstPersonControls.js +32 -54
- package/examples/js/controls/FlyControls.js +29 -55
- package/examples/js/controls/OrbitControls.js +85 -95
- package/examples/js/controls/PointerLockControls.js +5 -14
- package/examples/js/controls/TrackballControls.js +33 -86
- package/examples/js/controls/TransformControls.js +84 -169
- package/examples/js/csm/CSM.js +4 -39
- package/examples/js/csm/CSMFrustum.js +3 -9
- package/examples/js/csm/CSMHelper.js +24 -4
- package/examples/js/csm/CSMShader.js +2 -6
- package/examples/js/curves/CurveExtras.js +27 -27
- package/examples/js/curves/NURBSCurve.js +4 -16
- package/examples/js/curves/NURBSSurface.js +3 -9
- package/examples/js/curves/NURBSUtils.js +8 -45
- package/examples/js/effects/AnaglyphEffect.js +4 -18
- package/examples/js/effects/AsciiEffect.js +32 -31
- package/examples/js/effects/OutlineEffect.js +26 -30
- package/examples/js/effects/ParallaxBarrierEffect.js +0 -13
- package/examples/js/effects/PeppersGhostEffect.js +12 -39
- package/examples/js/effects/StereoEffect.js +0 -4
- package/examples/js/environments/RoomEnvironment.js +12 -10
- package/examples/js/exporters/ColladaExporter.js +48 -65
- package/examples/js/exporters/DRACOExporter.js +22 -22
- package/examples/js/exporters/EXRExporter.js +15 -18
- package/examples/js/exporters/GLTFExporter.js +143 -261
- package/examples/js/exporters/MMDExporter.js +5 -12
- package/examples/js/exporters/OBJExporter.js +42 -33
- package/examples/js/exporters/PLYExporter.js +38 -33
- package/examples/js/exporters/STLExporter.js +5 -7
- package/examples/js/exporters/USDZExporter.js +110 -25
- package/examples/js/geometries/BoxLineGeometry.js +0 -1
- package/examples/js/geometries/ConvexGeometry.js +11 -6
- package/examples/js/geometries/DecalGeometry.js +53 -20
- package/examples/js/geometries/LightningStrike.js +54 -67
- package/examples/js/geometries/ParametricGeometries.js +8 -7
- package/examples/js/geometries/ParametricGeometry.js +25 -12
- package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
- package/examples/js/geometries/TeapotGeometry.js +54 -50
- package/examples/js/geometries/TextGeometry.js +6 -4
- package/examples/js/helpers/LightProbeHelper.js +1 -2
- package/examples/js/helpers/OctreeHelper.js +22 -20
- package/examples/js/helpers/PositionalAudioHelper.js +8 -6
- package/examples/js/helpers/RectAreaLightHelper.js +6 -7
- package/examples/js/helpers/VertexNormalsHelper.js +15 -13
- package/examples/js/helpers/VertexTangentsHelper.js +15 -9
- package/examples/js/helpers/ViewHelper.js +31 -16
- package/examples/js/interactive/HTMLMesh.js +22 -33
- package/examples/js/interactive/InteractiveGroup.js +6 -12
- package/examples/js/interactive/SelectionBox.js +3 -70
- package/examples/js/interactive/SelectionHelper.js +0 -8
- package/examples/js/lights/LightProbeGenerator.js +32 -39
- package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
- package/examples/js/lines/LineGeometry.js +3 -5
- package/examples/js/lines/LineMaterial.js +4 -11
- package/examples/js/lines/LineSegments2.js +38 -89
- package/examples/js/lines/LineSegmentsGeometry.js +7 -28
- package/examples/js/lines/Wireframe.js +2 -7
- package/examples/js/lines/WireframeGeometry2.js +3 -1
- package/examples/js/loaders/3DMLoader.js +58 -155
- package/examples/js/loaders/3MFLoader.js +72 -106
- package/examples/js/loaders/AMFLoader.js +0 -25
- package/examples/js/loaders/BVHLoader.js +44 -43
- package/examples/js/loaders/BasisTextureLoader.js +16 -46
- package/examples/js/loaders/ColladaLoader.js +201 -359
- package/examples/js/loaders/DDSLoader.js +24 -25
- package/examples/js/loaders/DRACOLoader.js +29 -66
- package/examples/js/loaders/EXRLoader.js +67 -164
- package/examples/js/loaders/FBXLoader.js +286 -441
- package/examples/js/loaders/FontLoader.js +6 -15
- package/examples/js/loaders/GCodeLoader.js +15 -16
- package/examples/js/loaders/GLTFLoader.js +354 -405
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -6
- package/examples/js/loaders/KMZLoader.js +3 -7
- package/examples/js/loaders/KTXLoader.js +12 -30
- package/examples/js/loaders/LDrawLoader.js +178 -289
- package/examples/js/loaders/LUT3dlLoader.js +7 -11
- package/examples/js/loaders/LUTCubeLoader.js +0 -8
- package/examples/js/loaders/LWOLoader.js +59 -124
- package/examples/js/loaders/LogLuvLoader.js +27 -77
- package/examples/js/loaders/LottieLoader.js +4 -4
- package/examples/js/loaders/MD2Loader.js +26 -27
- package/examples/js/loaders/MDDLoader.js +6 -10
- package/examples/js/loaders/MMDLoader.js +180 -189
- package/examples/js/loaders/MTLLoader.js +18 -47
- package/examples/js/loaders/MaterialXLoader.js +392 -0
- package/examples/js/loaders/NRRDLoader.js +44 -84
- package/examples/js/loaders/OBJLoader.js +50 -65
- package/examples/js/loaders/PCDLoader.js +34 -29
- package/examples/js/loaders/PDBLoader.js +17 -13
- package/examples/js/loaders/PLYLoader.js +9 -39
- package/examples/js/loaders/PRWMLoader.js +11 -22
- package/examples/js/loaders/PVRLoader.js +7 -16
- package/examples/js/loaders/RGBELoader.js +36 -61
- package/examples/js/loaders/RGBMLoader.js +26 -87
- package/examples/js/loaders/STLLoader.js +20 -27
- package/examples/js/loaders/SVGLoader.js +361 -233
- package/examples/js/loaders/TDSLoader.js +81 -118
- package/examples/js/loaders/TGALoader.js +39 -41
- package/examples/js/loaders/TIFFLoader.js +0 -1
- package/examples/js/loaders/TTFLoader.js +0 -8
- package/examples/js/loaders/TiltLoader.js +14 -15
- package/examples/js/loaders/VOXLoader.js +8 -16
- package/examples/js/loaders/VRMLLoader.js +243 -340
- package/examples/js/loaders/VTKLoader.js +101 -118
- package/examples/js/loaders/XYZLoader.js +2 -4
- package/examples/js/loaders/lwo/IFFParser.js +55 -136
- package/examples/js/loaders/lwo/LWO2Parser.js +32 -83
- package/examples/js/loaders/lwo/LWO3Parser.js +31 -73
- package/examples/js/materials/MeshGouraudMaterial.js +15 -13
- package/examples/js/math/Capsule.js +0 -17
- package/examples/js/math/ColorConverter.js +3 -3
- package/examples/js/math/ConvexHull.js +183 -139
- package/examples/js/math/ImprovedNoise.js +1 -1
- package/examples/js/math/Lut.js +8 -15
- package/examples/js/math/MeshSurfaceSampler.js +6 -28
- package/examples/js/math/OBB.js +90 -49
- package/examples/js/math/Octree.js +2 -57
- package/examples/js/math/SimplexNoise.js +74 -88
- package/examples/js/misc/ConvexObjectBreaker.js +37 -48
- package/examples/js/misc/GPUComputationRenderer.js +14 -18
- package/examples/js/misc/Gyroscope.js +5 -9
- package/examples/js/misc/MD2Character.js +14 -23
- package/examples/js/misc/MD2CharacterComplex.js +73 -54
- package/examples/js/misc/MorphAnimMesh.js +0 -6
- package/examples/js/misc/MorphBlendMesh.js +3 -30
- package/examples/js/misc/ProgressiveLightMap.js +47 -43
- package/examples/js/misc/RollerCoaster.js +17 -24
- package/examples/js/misc/TubePainter.js +18 -12
- package/examples/js/misc/Volume.js +16 -45
- package/examples/js/misc/VolumeSlice.js +14 -24
- package/examples/js/modifiers/CurveModifier.js +19 -21
- package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
- package/examples/js/modifiers/SimplifyModifier.js +56 -59
- package/examples/js/modifiers/TessellateModifier.js +2 -9
- package/examples/js/objects/GroundProjectedEnv.js +2 -14
- package/examples/js/objects/Lensflare.js +47 -38
- package/examples/js/objects/LightningStorm.js +10 -13
- package/examples/js/objects/MarchingCubes.js +80 -59
- package/examples/js/objects/Reflector.js +22 -20
- package/examples/js/objects/ReflectorForSSRPass.js +19 -23
- package/examples/js/objects/Refractor.js +52 -30
- package/examples/js/objects/ShadowMesh.js +1 -2
- package/examples/js/objects/Sky.js +2 -7
- package/examples/js/objects/Water.js +23 -18
- package/examples/js/objects/Water2.js +20 -19
- package/examples/js/physics/AmmoPhysics.js +23 -20
- package/examples/js/physics/OimoPhysics.js +19 -17
- package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
- package/examples/js/postprocessing/AfterimagePass.js +19 -12
- package/examples/js/postprocessing/BloomPass.js +38 -17
- package/examples/js/postprocessing/BokehPass.js +29 -12
- package/examples/js/postprocessing/ClearPass.js +1 -6
- package/examples/js/postprocessing/CubeTexturePass.js +12 -9
- package/examples/js/postprocessing/DotScreenPass.js +7 -5
- package/examples/js/postprocessing/EffectComposer.js +25 -32
- package/examples/js/postprocessing/FilmPass.js +7 -5
- package/examples/js/postprocessing/GlitchPass.js +10 -11
- package/examples/js/postprocessing/HalftonePass.js +9 -9
- package/examples/js/postprocessing/LUTPass.js +2 -15
- package/examples/js/postprocessing/MaskPass.js +20 -17
- package/examples/js/postprocessing/OutlinePass.js +45 -36
- package/examples/js/postprocessing/Pass.js +11 -14
- package/examples/js/postprocessing/RenderPass.js +3 -7
- package/examples/js/postprocessing/SAOPass.js +40 -32
- package/examples/js/postprocessing/SMAAPass.js +34 -17
- package/examples/js/postprocessing/SSAARenderPass.js +14 -14
- package/examples/js/postprocessing/SSAOPass.js +56 -42
- package/examples/js/postprocessing/SSRPass.js +78 -61
- package/examples/js/postprocessing/SavePass.js +14 -6
- package/examples/js/postprocessing/ShaderPass.js +9 -8
- package/examples/js/postprocessing/TAARenderPass.js +11 -9
- package/examples/js/postprocessing/TexturePass.js +7 -4
- package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
- package/examples/js/renderers/CSS2DRenderer.js +2 -21
- package/examples/js/renderers/CSS3DRenderer.js +3 -24
- package/examples/js/renderers/Projector.js +29 -85
- package/examples/js/renderers/SVGRenderer.js +4 -50
- package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
- package/examples/js/shaders/AfterimageShader.js +3 -6
- package/examples/js/shaders/BasicShader.js +3 -6
- package/examples/js/shaders/BleachBypassShader.js +3 -6
- package/examples/js/shaders/BlendShader.js +3 -6
- package/examples/js/shaders/BokehShader.js +3 -6
- package/examples/js/shaders/BokehShader2.js +4 -13
- package/examples/js/shaders/BrightnessContrastShader.js +3 -6
- package/examples/js/shaders/ColorCorrectionShader.js +2 -6
- package/examples/js/shaders/ColorifyShader.js +2 -6
- package/examples/js/shaders/ConvolutionShader.js +5 -10
- package/examples/js/shaders/CopyShader.js +3 -6
- package/examples/js/shaders/DOFMipMapShader.js +3 -6
- package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
- package/examples/js/shaders/DigitalGlitch.js +3 -6
- package/examples/js/shaders/DotScreenShader.js +2 -6
- package/examples/js/shaders/FXAAShader.js +1 -3
- package/examples/js/shaders/FilmShader.js +3 -6
- package/examples/js/shaders/FocusShader.js +3 -6
- package/examples/js/shaders/FreiChenShader.js +2 -6
- package/examples/js/shaders/GammaCorrectionShader.js +3 -6
- package/examples/js/shaders/GodRaysShader.js +11 -24
- package/examples/js/shaders/HalftoneShader.js +3 -6
- package/examples/js/shaders/HorizontalBlurShader.js +3 -6
- package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
- package/examples/js/shaders/HueSaturationShader.js +3 -6
- package/examples/js/shaders/KaleidoShader.js +3 -6
- package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
- package/examples/js/shaders/LuminosityShader.js +3 -6
- package/examples/js/shaders/MMDToonShader.js +2 -6
- package/examples/js/shaders/MirrorShader.js +3 -6
- package/examples/js/shaders/NormalMapShader.js +2 -6
- package/examples/js/shaders/RGBShiftShader.js +3 -6
- package/examples/js/shaders/SAOShader.js +2 -6
- package/examples/js/shaders/SMAAShader.js +6 -18
- package/examples/js/shaders/SSAOShader.js +2 -6
- package/examples/js/shaders/SSRShader.js +6 -18
- package/examples/js/shaders/SepiaShader.js +3 -6
- package/examples/js/shaders/SobelOperatorShader.js +2 -6
- package/examples/js/shaders/TechnicolorShader.js +3 -6
- package/examples/js/shaders/ToneMapShader.js +3 -6
- package/examples/js/shaders/ToonShader.js +8 -24
- package/examples/js/shaders/TriangleBlurShader.js +2 -6
- package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
- package/examples/js/shaders/VelocityShader.js +126 -0
- package/examples/js/shaders/VerticalBlurShader.js +3 -6
- package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
- package/examples/js/shaders/VignetteShader.js +3 -6
- package/examples/js/shaders/VolumeShader.js +2 -6
- package/examples/js/shaders/WaterRefractionShader.js +2 -6
- package/examples/js/textures/FlakesTexture.js +0 -1
- package/examples/js/utils/BufferGeometryUtils.js +234 -168
- package/examples/js/utils/CameraUtils.js +5 -20
- package/examples/js/utils/GPUStatsPanel.js +3 -12
- package/examples/js/utils/GeometryCompressionUtils.js +19 -44
- package/examples/js/utils/GeometryUtils.js +13 -18
- package/examples/js/utils/LDrawUtils.js +8 -11
- package/examples/js/utils/PackedPhongMaterial.js +6 -4
- package/examples/js/utils/SceneUtils.js +117 -6
- package/examples/js/utils/ShadowMapViewer.js +17 -14
- package/examples/js/utils/SkeletonUtils.js +13 -27
- package/examples/js/utils/UVsDebug.js +20 -12
- package/examples/js/utils/WorkerPool.js +1 -11
- package/examples/jsm/animation/CCDIKSolver.js +1 -1
- package/examples/jsm/capabilities/WebGPU.js +3 -1
- package/examples/jsm/controls/OrbitControls.js +44 -4
- package/examples/jsm/exporters/GLTFExporter.js +17 -131
- package/examples/jsm/exporters/USDZExporter.js +94 -28
- package/examples/jsm/interactive/HTMLMesh.js +2 -0
- package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -2
- package/examples/jsm/loaders/ColladaLoader.js +28 -0
- package/examples/jsm/loaders/FBXLoader.js +16 -2
- package/examples/jsm/loaders/GLTFLoader.js +204 -377
- package/examples/jsm/loaders/KTX2Loader.js +68 -29
- package/examples/jsm/loaders/LDrawLoader.js +14 -13
- package/examples/jsm/loaders/LottieLoader.js +4 -2
- package/examples/jsm/loaders/MaterialXLoader.js +728 -0
- package/examples/jsm/loaders/PCDLoader.js +1 -1
- package/examples/jsm/loaders/PLYLoader.js +68 -16
- package/examples/jsm/loaders/SVGLoader.js +227 -14
- package/examples/jsm/loaders/USDZLoader.js +31 -16
- package/examples/jsm/nodes/Nodes.js +14 -2
- package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
- package/examples/jsm/nodes/accessors/PositionNode.js +6 -0
- package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
- package/examples/jsm/nodes/accessors/SkinningNode.js +1 -1
- package/examples/jsm/nodes/core/Node.js +1 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +36 -4
- package/examples/jsm/nodes/core/NodeFrame.js +2 -2
- package/examples/jsm/nodes/core/NodeVarying.js +7 -4
- package/examples/jsm/nodes/core/VaryingNode.js +6 -4
- package/examples/jsm/nodes/core/constants.js +13 -13
- package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
- package/examples/jsm/nodes/display/ViewportNode.js +106 -0
- package/examples/jsm/nodes/gpgpu/ComputeNode.js +1 -1
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
- package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +3 -1
- package/examples/jsm/nodes/materials/Materials.js +9 -7
- package/examples/jsm/nodes/materials/NodeMaterial.js +9 -1
- package/examples/jsm/nodes/materialx/MaterialXNodes.js +6 -2
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
- package/examples/jsm/nodes/math/MathNode.js +5 -0
- package/examples/jsm/nodes/math/OperatorNode.js +6 -1
- package/examples/jsm/nodes/shadernode/ShaderNode.js +26 -13
- package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +2 -0
- package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +18 -0
- package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
- package/examples/jsm/nodes/utils/JoinNode.js +8 -2
- package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
- package/examples/jsm/nodes/utils/MaxMipLevelNode.js +1 -1
- package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
- package/examples/jsm/nodes/utils/TimerNode.js +1 -1
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
- package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
- package/examples/jsm/postprocessing/BloomPass.js +22 -3
- package/examples/jsm/postprocessing/BokehPass.js +18 -4
- package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
- package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
- package/examples/jsm/postprocessing/EffectComposer.js +9 -0
- package/examples/jsm/postprocessing/FilmPass.js +8 -0
- package/examples/jsm/postprocessing/GlitchPass.js +13 -1
- package/examples/jsm/postprocessing/HalftonePass.js +8 -0
- package/examples/jsm/postprocessing/OutlinePass.js +10 -0
- package/examples/jsm/postprocessing/Pass.js +2 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
- package/examples/jsm/postprocessing/SAOPass.js +20 -0
- package/examples/jsm/postprocessing/SMAAPass.js +16 -0
- package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
- package/examples/jsm/postprocessing/SavePass.js +17 -1
- package/examples/jsm/postprocessing/ShaderPass.js +8 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
- package/examples/jsm/postprocessing/TexturePass.js +8 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +39 -16
- package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
- package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +36 -7
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +47 -12
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +35 -5
- package/examples/jsm/shaders/MMDToonShader.js +0 -2
- package/examples/jsm/shaders/VelocityShader.js +128 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +130 -6
- package/examples/jsm/utils/SceneUtils.js +129 -4
- package/examples/jsm/utils/TextureUtils.js +85 -0
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/examples/jsm/webxr/XRHandMeshModel.js +6 -3
- package/package.json +11 -12
- package/src/Three.js +1 -0
- package/src/audio/AudioContext.js +5 -5
- package/src/cameras/CubeCamera.js +14 -14
- package/src/constants.js +1 -1
- package/src/core/InstancedBufferGeometry.js +1 -7
- package/src/extras/Earcut.js +67 -67
- package/src/helpers/DirectionalLightHelper.js +5 -1
- package/src/helpers/HemisphereLightHelper.js +4 -1
- package/src/helpers/PointLightHelper.js +2 -1
- package/src/helpers/SpotLightHelper.js +4 -2
- package/src/lights/PointLight.js +2 -2
- package/src/lights/SpotLight.js +2 -2
- package/src/loaders/FileLoader.js +4 -1
- package/src/loaders/ObjectLoader.js +5 -1
- package/src/materials/Material.js +1 -1
- package/src/math/Color.js +5 -5
- package/src/math/Matrix3.js +53 -18
- package/src/math/Ray.js +2 -5
- package/src/math/Sphere.js +19 -26
- package/src/objects/InstancedMesh.js +7 -0
- package/src/objects/LOD.js +25 -6
- package/src/renderers/WebGL3DRenderTarget.js +1 -1
- package/src/renderers/WebGLArrayRenderTarget.js +1 -1
- package/src/renderers/WebGLCubeRenderTarget.js +1 -1
- package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
- package/src/renderers/WebGLRenderTarget.js +1 -1
- package/src/renderers/WebGLRenderer.js +36 -62
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk.js +3 -0
- package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +20 -6
- package/src/renderers/shaders/UniformsLib.js +1 -1
- package/src/renderers/shaders/UniformsUtils.js +15 -0
- package/src/renderers/webgl/WebGLAttributes.js +2 -0
- package/src/renderers/webgl/WebGLBackground.js +15 -7
- package/src/renderers/webgl/WebGLCubeUVMaps.js +1 -1
- package/src/renderers/webgl/WebGLLights.js +0 -4
- package/src/renderers/webgl/WebGLMaterials.js +2 -1
- package/src/renderers/webgl/WebGLShadowMap.js +3 -1
- package/src/renderers/webgl/WebGLState.js +31 -1
- package/src/renderers/webgl/WebGLTextures.js +71 -18
- package/src/renderers/webgl/WebGLUniforms.js +116 -20
- package/src/renderers/webgl/WebGLUtils.js +1 -1
- package/src/renderers/webxr/WebXRController.js +46 -13
- package/src/renderers/webxr/WebXRManager.js +85 -3
- package/src/scenes/Scene.js +8 -0
- package/src/textures/CompressedArrayTexture.js +18 -0
- package/examples/js/libs/lottie_canvas.js +0 -12751
- package/examples/js/shaders/PixelShader.js +0 -51
- package/examples/jsm/shaders/PixelShader.js +0 -44
|
@@ -24,17 +24,14 @@
|
|
|
24
24
|
|
|
25
25
|
if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {
|
|
26
26
|
|
|
27
|
-
const srcArray = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
|
|
28
27
|
const dstArray = new Float32Array( attribute.getCount() * attribute.itemSize );
|
|
29
|
-
|
|
30
28
|
for ( let i = 0, j = 0; i < attribute.getCount(); i ++ ) {
|
|
31
29
|
|
|
32
|
-
dstArray[ j ++ ] =
|
|
33
|
-
dstArray[ j ++ ] =
|
|
34
|
-
|
|
30
|
+
dstArray[ j ++ ] = attribute.getX( i );
|
|
31
|
+
dstArray[ j ++ ] = attribute.getY( i );
|
|
35
32
|
if ( attribute.itemSize > 2 ) {
|
|
36
33
|
|
|
37
|
-
dstArray[ j ++ ] =
|
|
34
|
+
dstArray[ j ++ ] = attribute.getZ( i );
|
|
38
35
|
|
|
39
36
|
}
|
|
40
37
|
|
|
@@ -52,13 +49,17 @@
|
|
|
52
49
|
|
|
53
50
|
return new Float32Array( attribute.array );
|
|
54
51
|
|
|
55
|
-
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// MikkTSpace algorithm requires non-indexed input.
|
|
56
55
|
|
|
56
|
+
const _geometry = geometry.index ? geometry.toNonIndexed() : geometry;
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// Compute vertex tangents.
|
|
59
59
|
|
|
60
|
+
const tangents = MikkTSpace.generateTangents( getAttributeArray( _geometry.attributes.position ), getAttributeArray( _geometry.attributes.normal ), getAttributeArray( _geometry.attributes.uv ) );
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
// Texture coordinate convention of glTF differs from the apparent
|
|
62
63
|
// default of the MikkTSpace library; .w component must be flipped.
|
|
63
64
|
|
|
64
65
|
if ( negateSign ) {
|
|
@@ -69,11 +70,11 @@
|
|
|
69
70
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
}
|
|
73
|
+
}
|
|
73
74
|
|
|
75
|
+
//
|
|
74
76
|
|
|
75
77
|
_geometry.setAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ) );
|
|
76
|
-
|
|
77
78
|
if ( geometry !== _geometry ) {
|
|
78
79
|
|
|
79
80
|
geometry.copy( _geometry );
|
|
@@ -83,13 +84,12 @@
|
|
|
83
84
|
return geometry;
|
|
84
85
|
|
|
85
86
|
}
|
|
87
|
+
|
|
86
88
|
/**
|
|
87
89
|
* @param {Array<BufferGeometry>} geometries
|
|
88
90
|
* @param {Boolean} useGroups
|
|
89
91
|
* @return {BufferGeometry}
|
|
90
92
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
93
|
function mergeBufferGeometries( geometries, useGroups = false ) {
|
|
94
94
|
|
|
95
95
|
const isIndexed = geometries[ 0 ].index !== null;
|
|
@@ -100,19 +100,21 @@
|
|
|
100
100
|
const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
|
|
101
101
|
const mergedGeometry = new THREE.BufferGeometry();
|
|
102
102
|
let offset = 0;
|
|
103
|
-
|
|
104
103
|
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
105
104
|
|
|
106
105
|
const geometry = geometries[ i ];
|
|
107
|
-
let attributesCount = 0;
|
|
106
|
+
let attributesCount = 0;
|
|
107
|
+
|
|
108
|
+
// ensure that all geometries are indexed, or none
|
|
108
109
|
|
|
109
110
|
if ( isIndexed !== ( geometry.index !== null ) ) {
|
|
110
111
|
|
|
111
112
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
|
|
112
113
|
return null;
|
|
113
114
|
|
|
114
|
-
}
|
|
115
|
+
}
|
|
115
116
|
|
|
117
|
+
// gather attributes, exit early if they're different
|
|
116
118
|
|
|
117
119
|
for ( const name in geometry.attributes ) {
|
|
118
120
|
|
|
@@ -127,16 +129,18 @@
|
|
|
127
129
|
attributes[ name ].push( geometry.attributes[ name ] );
|
|
128
130
|
attributesCount ++;
|
|
129
131
|
|
|
130
|
-
}
|
|
132
|
+
}
|
|
131
133
|
|
|
134
|
+
// ensure geometries have the same number of attributes
|
|
132
135
|
|
|
133
136
|
if ( attributesCount !== attributesUsed.size ) {
|
|
134
137
|
|
|
135
138
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
|
|
136
139
|
return null;
|
|
137
140
|
|
|
138
|
-
}
|
|
141
|
+
}
|
|
139
142
|
|
|
143
|
+
// gather morph attributes, exit early if they're different
|
|
140
144
|
|
|
141
145
|
if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
|
|
142
146
|
|
|
@@ -157,16 +161,11 @@
|
|
|
157
161
|
if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
|
|
158
162
|
morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
|
|
159
163
|
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
mergedGeometry.userData.mergedUserData = mergedGeometry.userData.mergedUserData || [];
|
|
164
|
-
mergedGeometry.userData.mergedUserData.push( geometry.userData );
|
|
164
|
+
}
|
|
165
165
|
|
|
166
166
|
if ( useGroups ) {
|
|
167
167
|
|
|
168
168
|
let count;
|
|
169
|
-
|
|
170
169
|
if ( isIndexed ) {
|
|
171
170
|
|
|
172
171
|
count = geometry.index.count;
|
|
@@ -187,18 +186,17 @@
|
|
|
187
186
|
|
|
188
187
|
}
|
|
189
188
|
|
|
190
|
-
}
|
|
189
|
+
}
|
|
191
190
|
|
|
191
|
+
// merge indices
|
|
192
192
|
|
|
193
193
|
if ( isIndexed ) {
|
|
194
194
|
|
|
195
195
|
let indexOffset = 0;
|
|
196
196
|
const mergedIndex = [];
|
|
197
|
-
|
|
198
197
|
for ( let i = 0; i < geometries.length; ++ i ) {
|
|
199
198
|
|
|
200
199
|
const index = geometries[ i ].index;
|
|
201
|
-
|
|
202
200
|
for ( let j = 0; j < index.count; ++ j ) {
|
|
203
201
|
|
|
204
202
|
mergedIndex.push( index.getX( j ) + indexOffset );
|
|
@@ -211,13 +209,13 @@
|
|
|
211
209
|
|
|
212
210
|
mergedGeometry.setIndex( mergedIndex );
|
|
213
211
|
|
|
214
|
-
}
|
|
212
|
+
}
|
|
215
213
|
|
|
214
|
+
// merge attributes
|
|
216
215
|
|
|
217
216
|
for ( const name in attributes ) {
|
|
218
217
|
|
|
219
218
|
const mergedAttribute = mergeBufferAttributes( attributes[ name ] );
|
|
220
|
-
|
|
221
219
|
if ( ! mergedAttribute ) {
|
|
222
220
|
|
|
223
221
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' attribute.' );
|
|
@@ -227,8 +225,9 @@
|
|
|
227
225
|
|
|
228
226
|
mergedGeometry.setAttribute( name, mergedAttribute );
|
|
229
227
|
|
|
230
|
-
}
|
|
228
|
+
}
|
|
231
229
|
|
|
230
|
+
// merge morph attributes
|
|
232
231
|
|
|
233
232
|
for ( const name in morphAttributes ) {
|
|
234
233
|
|
|
@@ -236,11 +235,9 @@
|
|
|
236
235
|
if ( numMorphTargets === 0 ) break;
|
|
237
236
|
mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
|
|
238
237
|
mergedGeometry.morphAttributes[ name ] = [];
|
|
239
|
-
|
|
240
238
|
for ( let i = 0; i < numMorphTargets; ++ i ) {
|
|
241
239
|
|
|
242
240
|
const morphAttributesToMerge = [];
|
|
243
|
-
|
|
244
241
|
for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
|
|
245
242
|
|
|
246
243
|
morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
|
|
@@ -248,7 +245,6 @@
|
|
|
248
245
|
}
|
|
249
246
|
|
|
250
247
|
const mergedMorphAttribute = mergeBufferAttributes( morphAttributesToMerge );
|
|
251
|
-
|
|
252
248
|
if ( ! mergedMorphAttribute ) {
|
|
253
249
|
|
|
254
250
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
|
|
@@ -265,23 +261,20 @@
|
|
|
265
261
|
return mergedGeometry;
|
|
266
262
|
|
|
267
263
|
}
|
|
264
|
+
|
|
268
265
|
/**
|
|
269
266
|
* @param {Array<BufferAttribute>} attributes
|
|
270
267
|
* @return {BufferAttribute}
|
|
271
268
|
*/
|
|
272
|
-
|
|
273
|
-
|
|
274
269
|
function mergeBufferAttributes( attributes ) {
|
|
275
270
|
|
|
276
271
|
let TypedArray;
|
|
277
272
|
let itemSize;
|
|
278
273
|
let normalized;
|
|
279
274
|
let arrayLength = 0;
|
|
280
|
-
|
|
281
275
|
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
282
276
|
|
|
283
277
|
const attribute = attributes[ i ];
|
|
284
|
-
|
|
285
278
|
if ( attribute.isInterleavedBufferAttribute ) {
|
|
286
279
|
|
|
287
280
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported.' );
|
|
@@ -290,7 +283,6 @@
|
|
|
290
283
|
}
|
|
291
284
|
|
|
292
285
|
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
293
|
-
|
|
294
286
|
if ( TypedArray !== attribute.array.constructor ) {
|
|
295
287
|
|
|
296
288
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes.' );
|
|
@@ -299,7 +291,6 @@
|
|
|
299
291
|
}
|
|
300
292
|
|
|
301
293
|
if ( itemSize === undefined ) itemSize = attribute.itemSize;
|
|
302
|
-
|
|
303
294
|
if ( itemSize !== attribute.itemSize ) {
|
|
304
295
|
|
|
305
296
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes.' );
|
|
@@ -308,7 +299,6 @@
|
|
|
308
299
|
}
|
|
309
300
|
|
|
310
301
|
if ( normalized === undefined ) normalized = attribute.normalized;
|
|
311
|
-
|
|
312
302
|
if ( normalized !== attribute.normalized ) {
|
|
313
303
|
|
|
314
304
|
console.error( 'THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes.' );
|
|
@@ -322,7 +312,6 @@
|
|
|
322
312
|
|
|
323
313
|
const array = new TypedArray( arrayLength );
|
|
324
314
|
let offset = 0;
|
|
325
|
-
|
|
326
315
|
for ( let i = 0; i < attributes.length; ++ i ) {
|
|
327
316
|
|
|
328
317
|
array.set( attributes[ i ].array, offset );
|
|
@@ -333,25 +322,46 @@
|
|
|
333
322
|
return new THREE.BufferAttribute( array, itemSize, normalized );
|
|
334
323
|
|
|
335
324
|
}
|
|
325
|
+
|
|
336
326
|
/**
|
|
337
|
-
* @param {
|
|
338
|
-
* @return {
|
|
327
|
+
* @param {BufferAttribute}
|
|
328
|
+
* @return {BufferAttribute}
|
|
339
329
|
*/
|
|
330
|
+
function deepCloneAttribute( attribute ) {
|
|
331
|
+
|
|
332
|
+
if ( attribute.isInstancedInterleavedBufferAttribute || attribute.isInterleavedBufferAttribute ) {
|
|
333
|
+
|
|
334
|
+
return deinterleaveAttribute( attribute );
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if ( attribute.isInstancedBufferAttribute ) {
|
|
340
339
|
|
|
340
|
+
return new THREE.InstancedBufferAttribute().copy( attribute );
|
|
341
341
|
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return new THREE.BufferAttribute().copy( attribute );
|
|
345
|
+
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* @param {Array<BufferAttribute>} attributes
|
|
350
|
+
* @return {Array<InterleavedBufferAttribute>}
|
|
351
|
+
*/
|
|
342
352
|
function interleaveAttributes( attributes ) {
|
|
343
353
|
|
|
344
354
|
// Interleaves the provided attributes into an THREE.InterleavedBuffer and returns
|
|
345
355
|
// a set of InterleavedBufferAttributes for each attribute
|
|
346
356
|
let TypedArray;
|
|
347
357
|
let arrayLength = 0;
|
|
348
|
-
let stride = 0;
|
|
358
|
+
let stride = 0;
|
|
349
359
|
|
|
360
|
+
// calculate the length and type of the interleavedBuffer
|
|
350
361
|
for ( let i = 0, l = attributes.length; i < l; ++ i ) {
|
|
351
362
|
|
|
352
363
|
const attribute = attributes[ i ];
|
|
353
364
|
if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
|
|
354
|
-
|
|
355
365
|
if ( TypedArray !== attribute.array.constructor ) {
|
|
356
366
|
|
|
357
367
|
console.error( 'AttributeBuffers of different types cannot be interleaved' );
|
|
@@ -362,15 +372,14 @@
|
|
|
362
372
|
arrayLength += attribute.array.length;
|
|
363
373
|
stride += attribute.itemSize;
|
|
364
374
|
|
|
365
|
-
}
|
|
366
|
-
|
|
375
|
+
}
|
|
367
376
|
|
|
377
|
+
// Create the set of buffer attributes
|
|
368
378
|
const interleavedBuffer = new THREE.InterleavedBuffer( new TypedArray( arrayLength ), stride );
|
|
369
379
|
let offset = 0;
|
|
370
380
|
const res = [];
|
|
371
381
|
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
372
382
|
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
|
|
373
|
-
|
|
374
383
|
for ( let j = 0, l = attributes.length; j < l; j ++ ) {
|
|
375
384
|
|
|
376
385
|
const attribute = attributes[ j ];
|
|
@@ -378,9 +387,10 @@
|
|
|
378
387
|
const count = attribute.count;
|
|
379
388
|
const iba = new THREE.InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, attribute.normalized );
|
|
380
389
|
res.push( iba );
|
|
381
|
-
offset += itemSize;
|
|
382
|
-
// at the appropriate offset
|
|
390
|
+
offset += itemSize;
|
|
383
391
|
|
|
392
|
+
// Move the data for each attribute into the new interleavedBuffer
|
|
393
|
+
// at the appropriate offset
|
|
384
394
|
for ( let c = 0; c < count; c ++ ) {
|
|
385
395
|
|
|
386
396
|
for ( let k = 0; k < itemSize; k ++ ) {
|
|
@@ -395,9 +405,9 @@
|
|
|
395
405
|
|
|
396
406
|
return res;
|
|
397
407
|
|
|
398
|
-
}
|
|
399
|
-
|
|
408
|
+
}
|
|
400
409
|
|
|
410
|
+
// returns a new, non-interleaved version of the provided attribute
|
|
401
411
|
function deinterleaveAttribute( attribute ) {
|
|
402
412
|
|
|
403
413
|
const cons = attribute.data.array.constructor;
|
|
@@ -406,7 +416,6 @@
|
|
|
406
416
|
const normalized = attribute.normalized;
|
|
407
417
|
const array = new cons( count * itemSize );
|
|
408
418
|
let newAttribute;
|
|
409
|
-
|
|
410
419
|
if ( attribute.isInstancedInterleavedBufferAttribute ) {
|
|
411
420
|
|
|
412
421
|
newAttribute = new THREE.InstancedBufferAttribute( array, itemSize, normalized, attribute.meshPerAttribute );
|
|
@@ -420,7 +429,6 @@
|
|
|
420
429
|
for ( let i = 0; i < count; i ++ ) {
|
|
421
430
|
|
|
422
431
|
newAttribute.setX( i, attribute.getX( i ) );
|
|
423
|
-
|
|
424
432
|
if ( itemSize >= 2 ) {
|
|
425
433
|
|
|
426
434
|
newAttribute.setY( i, attribute.getY( i ) );
|
|
@@ -443,18 +451,17 @@
|
|
|
443
451
|
|
|
444
452
|
return newAttribute;
|
|
445
453
|
|
|
446
|
-
}
|
|
454
|
+
}
|
|
447
455
|
|
|
456
|
+
// deinterleaves all attributes on the geometry
|
|
448
457
|
function deinterleaveGeometry( geometry ) {
|
|
449
458
|
|
|
450
459
|
const attributes = geometry.attributes;
|
|
451
460
|
const morphTargets = geometry.morphTargets;
|
|
452
461
|
const attrMap = new Map();
|
|
453
|
-
|
|
454
462
|
for ( const key in attributes ) {
|
|
455
463
|
|
|
456
464
|
const attr = attributes[ key ];
|
|
457
|
-
|
|
458
465
|
if ( attr.isInterleavedBufferAttribute ) {
|
|
459
466
|
|
|
460
467
|
if ( ! attrMap.has( attr ) ) {
|
|
@@ -472,7 +479,6 @@
|
|
|
472
479
|
for ( const key in morphTargets ) {
|
|
473
480
|
|
|
474
481
|
const attr = morphTargets[ key ];
|
|
475
|
-
|
|
476
482
|
if ( attr.isInterleavedBufferAttribute ) {
|
|
477
483
|
|
|
478
484
|
if ( ! attrMap.has( attr ) ) {
|
|
@@ -488,18 +494,17 @@
|
|
|
488
494
|
}
|
|
489
495
|
|
|
490
496
|
}
|
|
497
|
+
|
|
491
498
|
/**
|
|
492
499
|
* @param {Array<BufferGeometry>} geometry
|
|
493
500
|
* @return {number}
|
|
494
501
|
*/
|
|
495
|
-
|
|
496
502
|
function estimateBytesUsed( geometry ) {
|
|
497
503
|
|
|
498
504
|
// Return the estimated memory used by this geometry in bytes
|
|
499
505
|
// Calculate using itemSize, count, and BYTES_PER_ELEMENT to account
|
|
500
506
|
// for InterleavedBufferAttributes.
|
|
501
507
|
let mem = 0;
|
|
502
|
-
|
|
503
508
|
for ( const name in geometry.attributes ) {
|
|
504
509
|
|
|
505
510
|
const attr = geometry.getAttribute( name );
|
|
@@ -512,61 +517,64 @@
|
|
|
512
517
|
return mem;
|
|
513
518
|
|
|
514
519
|
}
|
|
520
|
+
|
|
515
521
|
/**
|
|
516
522
|
* @param {BufferGeometry} geometry
|
|
517
523
|
* @param {number} tolerance
|
|
518
524
|
* @return {BufferGeometry}
|
|
519
525
|
*/
|
|
520
|
-
|
|
521
|
-
|
|
522
526
|
function mergeVertices( geometry, tolerance = 1e-4 ) {
|
|
523
527
|
|
|
524
|
-
tolerance = Math.max( tolerance, Number.EPSILON );
|
|
525
|
-
// if it's already available.
|
|
528
|
+
tolerance = Math.max( tolerance, Number.EPSILON );
|
|
526
529
|
|
|
530
|
+
// Generate an index buffer if the geometry doesn't have one, or optimize it
|
|
531
|
+
// if it's already available.
|
|
527
532
|
const hashToIndex = {};
|
|
528
533
|
const indices = geometry.getIndex();
|
|
529
534
|
const positions = geometry.getAttribute( 'position' );
|
|
530
|
-
const vertexCount = indices ? indices.count : positions.count;
|
|
535
|
+
const vertexCount = indices ? indices.count : positions.count;
|
|
531
536
|
|
|
532
|
-
|
|
537
|
+
// next value for triangle indices
|
|
538
|
+
let nextIndex = 0;
|
|
533
539
|
|
|
540
|
+
// attributes and new attribute arrays
|
|
534
541
|
const attributeNames = Object.keys( geometry.attributes );
|
|
535
|
-
const
|
|
536
|
-
const
|
|
542
|
+
const tmpAttributes = {};
|
|
543
|
+
const tmpMorphAttributes = {};
|
|
537
544
|
const newIndices = [];
|
|
538
|
-
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
545
|
+
const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
|
|
546
|
+
const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
|
|
539
547
|
|
|
548
|
+
// Initialize the arrays, allocating space conservatively. Extra
|
|
549
|
+
// space will be trimmed in the last step.
|
|
540
550
|
for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
|
|
541
551
|
|
|
542
552
|
const name = attributeNames[ i ];
|
|
543
|
-
|
|
553
|
+
const attr = geometry.attributes[ name ];
|
|
554
|
+
tmpAttributes[ name ] = new THREE.BufferAttribute( new attr.array.constructor( attr.count * attr.itemSize ), attr.itemSize, attr.normalized );
|
|
544
555
|
const morphAttr = geometry.morphAttributes[ name ];
|
|
545
|
-
|
|
546
556
|
if ( morphAttr ) {
|
|
547
557
|
|
|
548
|
-
|
|
558
|
+
tmpMorphAttributes[ name ] = new THREE.BufferAttribute( new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ), morphAttr.itemSize, morphAttr.normalized );
|
|
549
559
|
|
|
550
560
|
}
|
|
551
561
|
|
|
552
|
-
}
|
|
553
|
-
|
|
562
|
+
}
|
|
554
563
|
|
|
564
|
+
// convert the error tolerance to an amount of decimal places to truncate to
|
|
555
565
|
const decimalShift = Math.log10( 1 / tolerance );
|
|
556
566
|
const shiftMultiplier = Math.pow( 10, decimalShift );
|
|
557
|
-
|
|
558
567
|
for ( let i = 0; i < vertexCount; i ++ ) {
|
|
559
568
|
|
|
560
|
-
const index = indices ? indices.getX( i ) : i;
|
|
569
|
+
const index = indices ? indices.getX( i ) : i;
|
|
561
570
|
|
|
571
|
+
// Generate a hash for the vertex attributes at the current index 'i'
|
|
562
572
|
let hash = '';
|
|
563
|
-
|
|
564
573
|
for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
565
574
|
|
|
566
575
|
const name = attributeNames[ j ];
|
|
567
576
|
const attribute = geometry.getAttribute( name );
|
|
568
577
|
const itemSize = attribute.itemSize;
|
|
569
|
-
|
|
570
578
|
for ( let k = 0; k < itemSize; k ++ ) {
|
|
571
579
|
|
|
572
580
|
// double tilde truncates the decimal value
|
|
@@ -574,36 +582,35 @@
|
|
|
574
582
|
|
|
575
583
|
}
|
|
576
584
|
|
|
577
|
-
}
|
|
578
|
-
// used by another index
|
|
579
|
-
|
|
585
|
+
}
|
|
580
586
|
|
|
587
|
+
// Add another reference to the vertex if it's already
|
|
588
|
+
// used by another index
|
|
581
589
|
if ( hash in hashToIndex ) {
|
|
582
590
|
|
|
583
591
|
newIndices.push( hashToIndex[ hash ] );
|
|
584
592
|
|
|
585
593
|
} else {
|
|
586
594
|
|
|
587
|
-
// copy data to the new index in the
|
|
595
|
+
// copy data to the new index in the temporary attributes
|
|
588
596
|
for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
|
|
589
597
|
|
|
590
598
|
const name = attributeNames[ j ];
|
|
591
599
|
const attribute = geometry.getAttribute( name );
|
|
592
600
|
const morphAttr = geometry.morphAttributes[ name ];
|
|
593
601
|
const itemSize = attribute.itemSize;
|
|
594
|
-
const newarray =
|
|
595
|
-
const newMorphArrays =
|
|
596
|
-
|
|
602
|
+
const newarray = tmpAttributes[ name ];
|
|
603
|
+
const newMorphArrays = tmpMorphAttributes[ name ];
|
|
597
604
|
for ( let k = 0; k < itemSize; k ++ ) {
|
|
598
605
|
|
|
599
606
|
const getterFunc = getters[ k ];
|
|
600
|
-
|
|
601
|
-
|
|
607
|
+
const setterFunc = setters[ k ];
|
|
608
|
+
newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
|
|
602
609
|
if ( morphAttr ) {
|
|
603
610
|
|
|
604
611
|
for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
|
|
605
612
|
|
|
606
|
-
newMorphArrays[ m ]
|
|
613
|
+
newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );
|
|
607
614
|
|
|
608
615
|
}
|
|
609
616
|
|
|
@@ -619,47 +626,36 @@
|
|
|
619
626
|
|
|
620
627
|
}
|
|
621
628
|
|
|
622
|
-
}
|
|
623
|
-
// the attributeBuffers
|
|
624
|
-
|
|
629
|
+
}
|
|
625
630
|
|
|
631
|
+
// generate result THREE.BufferGeometry
|
|
626
632
|
const result = geometry.clone();
|
|
633
|
+
for ( const name in geometry.attributes ) {
|
|
627
634
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
|
|
633
|
-
const attribute = new THREE.BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
|
|
634
|
-
result.setAttribute( name, attribute ); // Update the attribute arrays
|
|
635
|
-
|
|
636
|
-
if ( name in morphAttrsArrays ) {
|
|
637
|
-
|
|
638
|
-
for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
|
|
639
|
-
|
|
640
|
-
const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
|
|
641
|
-
const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
|
|
642
|
-
const morphAttribute = new THREE.BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
|
|
643
|
-
result.morphAttributes[ name ][ j ] = morphAttribute;
|
|
635
|
+
const tmpAttribute = tmpAttributes[ name ];
|
|
636
|
+
result.setAttribute( name, new THREE.BufferAttribute( tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ), tmpAttribute.itemSize, tmpAttribute.normalized ) );
|
|
637
|
+
if ( ! ( name in tmpMorphAttributes ) ) continue;
|
|
638
|
+
for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {
|
|
644
639
|
|
|
645
|
-
|
|
640
|
+
const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
|
|
641
|
+
result.morphAttributes[ name ][ j ] = new THREE.BufferAttribute( tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ), tmpMorphAttribute.itemSize, tmpMorphAttribute.normalized );
|
|
646
642
|
|
|
647
643
|
}
|
|
648
644
|
|
|
649
|
-
}
|
|
645
|
+
}
|
|
650
646
|
|
|
647
|
+
// indices
|
|
651
648
|
|
|
652
649
|
result.setIndex( newIndices );
|
|
653
650
|
return result;
|
|
654
651
|
|
|
655
652
|
}
|
|
653
|
+
|
|
656
654
|
/**
|
|
657
655
|
* @param {BufferGeometry} geometry
|
|
658
656
|
* @param {number} drawMode
|
|
659
657
|
* @return {BufferGeometry}
|
|
660
658
|
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
659
|
function toTrianglesDrawMode( geometry, drawMode ) {
|
|
664
660
|
|
|
665
661
|
if ( drawMode === THREE.TrianglesDrawMode ) {
|
|
@@ -671,13 +667,14 @@
|
|
|
671
667
|
|
|
672
668
|
if ( drawMode === THREE.TriangleFanDrawMode || drawMode === THREE.TriangleStripDrawMode ) {
|
|
673
669
|
|
|
674
|
-
let index = geometry.getIndex();
|
|
670
|
+
let index = geometry.getIndex();
|
|
671
|
+
|
|
672
|
+
// generate index if not present
|
|
675
673
|
|
|
676
674
|
if ( index === null ) {
|
|
677
675
|
|
|
678
676
|
const indices = [];
|
|
679
677
|
const position = geometry.getAttribute( 'position' );
|
|
680
|
-
|
|
681
678
|
if ( position !== undefined ) {
|
|
682
679
|
|
|
683
680
|
for ( let i = 0; i < position.count; i ++ ) {
|
|
@@ -696,15 +693,16 @@
|
|
|
696
693
|
|
|
697
694
|
}
|
|
698
695
|
|
|
699
|
-
}
|
|
696
|
+
}
|
|
700
697
|
|
|
698
|
+
//
|
|
701
699
|
|
|
702
700
|
const numberOfTriangles = index.count - 2;
|
|
703
701
|
const newIndices = [];
|
|
704
|
-
|
|
705
702
|
if ( drawMode === THREE.TriangleFanDrawMode ) {
|
|
706
703
|
|
|
707
704
|
// gl.TRIANGLE_FAN
|
|
705
|
+
|
|
708
706
|
for ( let i = 1; i <= numberOfTriangles; i ++ ) {
|
|
709
707
|
|
|
710
708
|
newIndices.push( index.getX( 0 ) );
|
|
@@ -716,6 +714,7 @@
|
|
|
716
714
|
} else {
|
|
717
715
|
|
|
718
716
|
// gl.TRIANGLE_STRIP
|
|
717
|
+
|
|
719
718
|
for ( let i = 0; i < numberOfTriangles; i ++ ) {
|
|
720
719
|
|
|
721
720
|
if ( i % 2 === 0 ) {
|
|
@@ -740,8 +739,9 @@
|
|
|
740
739
|
|
|
741
740
|
console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
|
|
742
741
|
|
|
743
|
-
}
|
|
742
|
+
}
|
|
744
743
|
|
|
744
|
+
// build final geometry
|
|
745
745
|
|
|
746
746
|
const newGeometry = geometry.clone();
|
|
747
747
|
newGeometry.setIndex( newIndices );
|
|
@@ -756,14 +756,13 @@
|
|
|
756
756
|
}
|
|
757
757
|
|
|
758
758
|
}
|
|
759
|
+
|
|
759
760
|
/**
|
|
760
761
|
* Calculates the morphed attributes of a morphed/skinned THREE.BufferGeometry.
|
|
761
762
|
* Helpful for Raytracing or Decals.
|
|
762
763
|
* @param {Mesh | Line | Points} object An instance of Mesh, Line or Points.
|
|
763
764
|
* @return {Object} An Object with original position/normal attributes and morphed ones.
|
|
764
765
|
*/
|
|
765
|
-
|
|
766
|
-
|
|
767
766
|
function computeMorphedAttributes( object ) {
|
|
768
767
|
|
|
769
768
|
if ( object.geometry.isBufferGeometry !== true ) {
|
|
@@ -774,67 +773,43 @@
|
|
|
774
773
|
}
|
|
775
774
|
|
|
776
775
|
const _vA = new THREE.Vector3();
|
|
777
|
-
|
|
778
776
|
const _vB = new THREE.Vector3();
|
|
779
|
-
|
|
780
777
|
const _vC = new THREE.Vector3();
|
|
781
|
-
|
|
782
778
|
const _tempA = new THREE.Vector3();
|
|
783
|
-
|
|
784
779
|
const _tempB = new THREE.Vector3();
|
|
785
|
-
|
|
786
780
|
const _tempC = new THREE.Vector3();
|
|
787
|
-
|
|
788
781
|
const _morphA = new THREE.Vector3();
|
|
789
|
-
|
|
790
782
|
const _morphB = new THREE.Vector3();
|
|
791
|
-
|
|
792
783
|
const _morphC = new THREE.Vector3();
|
|
793
|
-
|
|
794
784
|
function _calculateMorphedAttributeData( object, attribute, morphAttribute, morphTargetsRelative, a, b, c, modifiedAttributeArray ) {
|
|
795
785
|
|
|
796
786
|
_vA.fromBufferAttribute( attribute, a );
|
|
797
|
-
|
|
798
787
|
_vB.fromBufferAttribute( attribute, b );
|
|
799
|
-
|
|
800
788
|
_vC.fromBufferAttribute( attribute, c );
|
|
801
|
-
|
|
802
789
|
const morphInfluences = object.morphTargetInfluences;
|
|
803
|
-
|
|
804
790
|
if ( morphAttribute && morphInfluences ) {
|
|
805
791
|
|
|
806
792
|
_morphA.set( 0, 0, 0 );
|
|
807
|
-
|
|
808
793
|
_morphB.set( 0, 0, 0 );
|
|
809
|
-
|
|
810
794
|
_morphC.set( 0, 0, 0 );
|
|
811
|
-
|
|
812
795
|
for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
|
|
813
796
|
|
|
814
797
|
const influence = morphInfluences[ i ];
|
|
815
798
|
const morph = morphAttribute[ i ];
|
|
816
799
|
if ( influence === 0 ) continue;
|
|
817
|
-
|
|
818
800
|
_tempA.fromBufferAttribute( morph, a );
|
|
819
|
-
|
|
820
801
|
_tempB.fromBufferAttribute( morph, b );
|
|
821
|
-
|
|
822
802
|
_tempC.fromBufferAttribute( morph, c );
|
|
823
|
-
|
|
824
803
|
if ( morphTargetsRelative ) {
|
|
825
804
|
|
|
826
805
|
_morphA.addScaledVector( _tempA, influence );
|
|
827
|
-
|
|
828
806
|
_morphB.addScaledVector( _tempB, influence );
|
|
829
|
-
|
|
830
807
|
_morphC.addScaledVector( _tempC, influence );
|
|
831
808
|
|
|
832
809
|
} else {
|
|
833
810
|
|
|
834
811
|
_morphA.addScaledVector( _tempA.sub( _vA ), influence );
|
|
835
|
-
|
|
836
812
|
_morphB.addScaledVector( _tempB.sub( _vB ), influence );
|
|
837
|
-
|
|
838
813
|
_morphC.addScaledVector( _tempC.sub( _vC ), influence );
|
|
839
814
|
|
|
840
815
|
}
|
|
@@ -842,9 +817,7 @@
|
|
|
842
817
|
}
|
|
843
818
|
|
|
844
819
|
_vA.add( _morphA );
|
|
845
|
-
|
|
846
820
|
_vB.add( _morphB );
|
|
847
|
-
|
|
848
821
|
_vC.add( _morphC );
|
|
849
822
|
|
|
850
823
|
}
|
|
@@ -885,10 +858,10 @@
|
|
|
885
858
|
let start, end;
|
|
886
859
|
const modifiedPosition = new Float32Array( positionAttribute.count * positionAttribute.itemSize );
|
|
887
860
|
const modifiedNormal = new Float32Array( normalAttribute.count * normalAttribute.itemSize );
|
|
888
|
-
|
|
889
861
|
if ( index !== null ) {
|
|
890
862
|
|
|
891
863
|
// indexed buffer geometry
|
|
864
|
+
|
|
892
865
|
if ( Array.isArray( material ) ) {
|
|
893
866
|
|
|
894
867
|
for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
@@ -896,15 +869,12 @@
|
|
|
896
869
|
group = groups[ i ];
|
|
897
870
|
start = Math.max( group.start, drawRange.start );
|
|
898
871
|
end = Math.min( group.start + group.count, drawRange.start + drawRange.count );
|
|
899
|
-
|
|
900
872
|
for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
901
873
|
|
|
902
874
|
a = index.getX( j );
|
|
903
875
|
b = index.getX( j + 1 );
|
|
904
876
|
c = index.getX( j + 2 );
|
|
905
|
-
|
|
906
877
|
_calculateMorphedAttributeData( object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
|
|
907
|
-
|
|
908
878
|
_calculateMorphedAttributeData( object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
|
|
909
879
|
|
|
910
880
|
}
|
|
@@ -915,15 +885,12 @@
|
|
|
915
885
|
|
|
916
886
|
start = Math.max( 0, drawRange.start );
|
|
917
887
|
end = Math.min( index.count, drawRange.start + drawRange.count );
|
|
918
|
-
|
|
919
888
|
for ( i = start, il = end; i < il; i += 3 ) {
|
|
920
889
|
|
|
921
890
|
a = index.getX( i );
|
|
922
891
|
b = index.getX( i + 1 );
|
|
923
892
|
c = index.getX( i + 2 );
|
|
924
|
-
|
|
925
893
|
_calculateMorphedAttributeData( object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
|
|
926
|
-
|
|
927
894
|
_calculateMorphedAttributeData( object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
|
|
928
895
|
|
|
929
896
|
}
|
|
@@ -933,6 +900,7 @@
|
|
|
933
900
|
} else {
|
|
934
901
|
|
|
935
902
|
// non-indexed buffer geometry
|
|
903
|
+
|
|
936
904
|
if ( Array.isArray( material ) ) {
|
|
937
905
|
|
|
938
906
|
for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
@@ -940,15 +908,12 @@
|
|
|
940
908
|
group = groups[ i ];
|
|
941
909
|
start = Math.max( group.start, drawRange.start );
|
|
942
910
|
end = Math.min( group.start + group.count, drawRange.start + drawRange.count );
|
|
943
|
-
|
|
944
911
|
for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
945
912
|
|
|
946
913
|
a = j;
|
|
947
914
|
b = j + 1;
|
|
948
915
|
c = j + 2;
|
|
949
|
-
|
|
950
916
|
_calculateMorphedAttributeData( object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
|
|
951
|
-
|
|
952
917
|
_calculateMorphedAttributeData( object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
|
|
953
918
|
|
|
954
919
|
}
|
|
@@ -959,15 +924,12 @@
|
|
|
959
924
|
|
|
960
925
|
start = Math.max( 0, drawRange.start );
|
|
961
926
|
end = Math.min( positionAttribute.count, drawRange.start + drawRange.count );
|
|
962
|
-
|
|
963
927
|
for ( i = start, il = end; i < il; i += 3 ) {
|
|
964
928
|
|
|
965
929
|
a = i;
|
|
966
930
|
b = i + 1;
|
|
967
931
|
c = i + 2;
|
|
968
|
-
|
|
969
932
|
_calculateMorphedAttributeData( object, positionAttribute, morphPosition, morphTargetsRelative, a, b, c, modifiedPosition );
|
|
970
|
-
|
|
971
933
|
_calculateMorphedAttributeData( object, normalAttribute, morphNormal, morphTargetsRelative, a, b, c, modifiedNormal );
|
|
972
934
|
|
|
973
935
|
}
|
|
@@ -996,20 +958,23 @@
|
|
|
996
958
|
|
|
997
959
|
}
|
|
998
960
|
|
|
999
|
-
let groups = geometry.groups;
|
|
961
|
+
let groups = geometry.groups;
|
|
962
|
+
|
|
963
|
+
// sort groups by material index
|
|
1000
964
|
|
|
1001
965
|
groups = groups.sort( ( a, b ) => {
|
|
1002
966
|
|
|
1003
967
|
if ( a.materialIndex !== b.materialIndex ) return a.materialIndex - b.materialIndex;
|
|
1004
968
|
return a.start - b.start;
|
|
1005
969
|
|
|
1006
|
-
} );
|
|
970
|
+
} );
|
|
971
|
+
|
|
972
|
+
// create index for non-indexed geometries
|
|
1007
973
|
|
|
1008
974
|
if ( geometry.getIndex() === null ) {
|
|
1009
975
|
|
|
1010
976
|
const positionAttribute = geometry.getAttribute( 'position' );
|
|
1011
977
|
const indices = [];
|
|
1012
|
-
|
|
1013
978
|
for ( let i = 0; i < positionAttribute.count; i += 3 ) {
|
|
1014
979
|
|
|
1015
980
|
indices.push( i, i + 1, i + 2 );
|
|
@@ -1018,18 +983,17 @@
|
|
|
1018
983
|
|
|
1019
984
|
geometry.setIndex( indices );
|
|
1020
985
|
|
|
1021
|
-
}
|
|
986
|
+
}
|
|
1022
987
|
|
|
988
|
+
// sort index
|
|
1023
989
|
|
|
1024
990
|
const index = geometry.getIndex();
|
|
1025
991
|
const newIndices = [];
|
|
1026
|
-
|
|
1027
992
|
for ( let i = 0; i < groups.length; i ++ ) {
|
|
1028
993
|
|
|
1029
994
|
const group = groups[ i ];
|
|
1030
995
|
const groupStart = group.start;
|
|
1031
996
|
const groupLength = groupStart + group.count;
|
|
1032
|
-
|
|
1033
997
|
for ( let j = groupStart; j < groupLength; j ++ ) {
|
|
1034
998
|
|
|
1035
999
|
newIndices.push( index.getX( j ) );
|
|
@@ -1039,27 +1003,26 @@
|
|
|
1039
1003
|
}
|
|
1040
1004
|
|
|
1041
1005
|
geometry.dispose(); // Required to force buffer recreation
|
|
1006
|
+
geometry.setIndex( newIndices );
|
|
1042
1007
|
|
|
1043
|
-
|
|
1008
|
+
// update groups indices
|
|
1044
1009
|
|
|
1045
1010
|
let start = 0;
|
|
1046
|
-
|
|
1047
1011
|
for ( let i = 0; i < groups.length; i ++ ) {
|
|
1048
1012
|
|
|
1049
1013
|
const group = groups[ i ];
|
|
1050
1014
|
group.start = start;
|
|
1051
1015
|
start += group.count;
|
|
1052
1016
|
|
|
1053
|
-
}
|
|
1017
|
+
}
|
|
1054
1018
|
|
|
1019
|
+
// merge groups
|
|
1055
1020
|
|
|
1056
1021
|
let currentGroup = groups[ 0 ];
|
|
1057
1022
|
geometry.groups = [ currentGroup ];
|
|
1058
|
-
|
|
1059
1023
|
for ( let i = 1; i < groups.length; i ++ ) {
|
|
1060
1024
|
|
|
1061
1025
|
const group = groups[ i ];
|
|
1062
|
-
|
|
1063
1026
|
if ( currentGroup.materialIndex === group.materialIndex ) {
|
|
1064
1027
|
|
|
1065
1028
|
currentGroup.count += group.count;
|
|
@@ -1077,10 +1040,112 @@
|
|
|
1077
1040
|
|
|
1078
1041
|
}
|
|
1079
1042
|
|
|
1043
|
+
// Creates a new, non-indexed geometry with smooth normals everywhere except faces that meet at
|
|
1044
|
+
// an angle greater than the crease angle.
|
|
1045
|
+
function toCreasedNormals( geometry, creaseAngle = Math.PI / 3 /* 60 degrees */ ) {
|
|
1046
|
+
|
|
1047
|
+
const creaseDot = Math.cos( creaseAngle );
|
|
1048
|
+
const hashMultiplier = ( 1 + 1e-10 ) * 1e2;
|
|
1049
|
+
|
|
1050
|
+
// reusable vertors
|
|
1051
|
+
const verts = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
|
|
1052
|
+
const tempVec1 = new THREE.Vector3();
|
|
1053
|
+
const tempVec2 = new THREE.Vector3();
|
|
1054
|
+
const tempNorm = new THREE.Vector3();
|
|
1055
|
+
const tempNorm2 = new THREE.Vector3();
|
|
1056
|
+
|
|
1057
|
+
// hashes a vector
|
|
1058
|
+
function hashVertex( v ) {
|
|
1059
|
+
|
|
1060
|
+
const x = ~ ~ ( v.x * hashMultiplier );
|
|
1061
|
+
const y = ~ ~ ( v.y * hashMultiplier );
|
|
1062
|
+
const z = ~ ~ ( v.z * hashMultiplier );
|
|
1063
|
+
return `${x},${y},${z}`;
|
|
1064
|
+
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
const resultGeometry = geometry.toNonIndexed();
|
|
1068
|
+
const posAttr = resultGeometry.attributes.position;
|
|
1069
|
+
const vertexMap = {};
|
|
1070
|
+
|
|
1071
|
+
// find all the normals shared by commonly located vertices
|
|
1072
|
+
for ( let i = 0, l = posAttr.count / 3; i < l; i ++ ) {
|
|
1073
|
+
|
|
1074
|
+
const i3 = 3 * i;
|
|
1075
|
+
const a = verts[ 0 ].fromBufferAttribute( posAttr, i3 + 0 );
|
|
1076
|
+
const b = verts[ 1 ].fromBufferAttribute( posAttr, i3 + 1 );
|
|
1077
|
+
const c = verts[ 2 ].fromBufferAttribute( posAttr, i3 + 2 );
|
|
1078
|
+
tempVec1.subVectors( c, b );
|
|
1079
|
+
tempVec2.subVectors( a, b );
|
|
1080
|
+
|
|
1081
|
+
// add the normal to the map for all vertices
|
|
1082
|
+
const normal = new THREE.Vector3().crossVectors( tempVec1, tempVec2 ).normalize();
|
|
1083
|
+
for ( let n = 0; n < 3; n ++ ) {
|
|
1084
|
+
|
|
1085
|
+
const vert = verts[ n ];
|
|
1086
|
+
const hash = hashVertex( vert );
|
|
1087
|
+
if ( ! ( hash in vertexMap ) ) {
|
|
1088
|
+
|
|
1089
|
+
vertexMap[ hash ] = [];
|
|
1090
|
+
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
vertexMap[ hash ].push( normal );
|
|
1094
|
+
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// average normals from all vertices that share a common location if they are within the
|
|
1100
|
+
// provided crease threshold
|
|
1101
|
+
const normalArray = new Float32Array( posAttr.count * 3 );
|
|
1102
|
+
const normAttr = new THREE.BufferAttribute( normalArray, 3, false );
|
|
1103
|
+
for ( let i = 0, l = posAttr.count / 3; i < l; i ++ ) {
|
|
1104
|
+
|
|
1105
|
+
// get the face normal for this vertex
|
|
1106
|
+
const i3 = 3 * i;
|
|
1107
|
+
const a = verts[ 0 ].fromBufferAttribute( posAttr, i3 + 0 );
|
|
1108
|
+
const b = verts[ 1 ].fromBufferAttribute( posAttr, i3 + 1 );
|
|
1109
|
+
const c = verts[ 2 ].fromBufferAttribute( posAttr, i3 + 2 );
|
|
1110
|
+
tempVec1.subVectors( c, b );
|
|
1111
|
+
tempVec2.subVectors( a, b );
|
|
1112
|
+
tempNorm.crossVectors( tempVec1, tempVec2 ).normalize();
|
|
1113
|
+
|
|
1114
|
+
// average all normals that meet the threshold and set the normal value
|
|
1115
|
+
for ( let n = 0; n < 3; n ++ ) {
|
|
1116
|
+
|
|
1117
|
+
const vert = verts[ n ];
|
|
1118
|
+
const hash = hashVertex( vert );
|
|
1119
|
+
const otherNormals = vertexMap[ hash ];
|
|
1120
|
+
tempNorm2.set( 0, 0, 0 );
|
|
1121
|
+
for ( let k = 0, lk = otherNormals.length; k < lk; k ++ ) {
|
|
1122
|
+
|
|
1123
|
+
const otherNorm = otherNormals[ k ];
|
|
1124
|
+
if ( tempNorm.dot( otherNorm ) > creaseDot ) {
|
|
1125
|
+
|
|
1126
|
+
tempNorm2.add( otherNorm );
|
|
1127
|
+
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
tempNorm2.normalize();
|
|
1133
|
+
normAttr.setXYZ( i3 + n, tempNorm2.x, tempNorm2.y, tempNorm2.z );
|
|
1134
|
+
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
resultGeometry.setAttribute( 'normal', normAttr );
|
|
1140
|
+
return resultGeometry;
|
|
1141
|
+
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1080
1144
|
THREE.BufferGeometryUtils = {};
|
|
1081
1145
|
THREE.BufferGeometryUtils.computeMikkTSpaceTangents = computeMikkTSpaceTangents;
|
|
1082
1146
|
THREE.BufferGeometryUtils.computeMorphedAttributes = computeMorphedAttributes;
|
|
1083
1147
|
THREE.BufferGeometryUtils.computeTangents = computeTangents;
|
|
1148
|
+
THREE.BufferGeometryUtils.deepCloneAttribute = deepCloneAttribute;
|
|
1084
1149
|
THREE.BufferGeometryUtils.deinterleaveAttribute = deinterleaveAttribute;
|
|
1085
1150
|
THREE.BufferGeometryUtils.deinterleaveGeometry = deinterleaveGeometry;
|
|
1086
1151
|
THREE.BufferGeometryUtils.estimateBytesUsed = estimateBytesUsed;
|
|
@@ -1089,6 +1154,7 @@
|
|
|
1089
1154
|
THREE.BufferGeometryUtils.mergeBufferGeometries = mergeBufferGeometries;
|
|
1090
1155
|
THREE.BufferGeometryUtils.mergeGroups = mergeGroups;
|
|
1091
1156
|
THREE.BufferGeometryUtils.mergeVertices = mergeVertices;
|
|
1157
|
+
THREE.BufferGeometryUtils.toCreasedNormals = toCreasedNormals;
|
|
1092
1158
|
THREE.BufferGeometryUtils.toTrianglesDrawMode = toTrianglesDrawMode;
|
|
1093
1159
|
|
|
1094
1160
|
} )();
|